Compare commits
1080
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7617dda5f6 | ||
|
|
13db05ce60 | ||
|
|
334bc54767 | ||
|
|
92196dde3a | ||
|
|
16feb56fd4 | ||
|
|
78adc23d70 | ||
|
|
79bca88c8a | ||
|
|
1751bff172 | ||
|
|
2e03fcb875 | ||
|
|
b3e52ecdef | ||
|
|
1eec825926 | ||
|
|
04500fa29d | ||
|
|
900316e4bd | ||
|
|
233824eeeb | ||
|
|
6d6caf20e1 | ||
|
|
00b452e57b | ||
|
|
e952ab721b | ||
|
|
33143527f2 | ||
|
|
1dd16bc783 | ||
|
|
7ba0eddd92 | ||
|
|
37dd3dac13 | ||
|
|
533a9e4ca9 | ||
|
|
efd8c7b34f | ||
|
|
80cfaa175f | ||
|
|
16b795af70 | ||
|
|
59ca36e55b | ||
|
|
09be0bc27f | ||
|
|
3a47cccbee | ||
|
|
ea106ea8b9 | ||
|
|
d006132c2a | ||
|
|
763d6a107a | ||
|
|
a79b811113 | ||
|
|
40b6ced375 | ||
|
|
9768d0b67d | ||
|
|
0adcfbbbdb | ||
|
|
109a3e1e49 | ||
|
|
a66583236a | ||
|
|
80a7061efa | ||
|
|
10d87dcc77 | ||
|
|
1cd984a4c7 | ||
|
|
b31924a2f5 | ||
|
|
7654838182 | ||
|
|
3f51d83147 | ||
|
|
0be2b3d01a | ||
|
|
871f75acd3 | ||
|
|
4b75791d3d | ||
|
|
4205f63786 | ||
|
|
2438f4a108 | ||
|
|
9081966682 | ||
|
|
16cb874ccc | ||
|
|
20d6a68bfb | ||
|
|
21bef6c044 | ||
|
|
ae105b4631 | ||
|
|
b58a8b2e7f | ||
|
|
533a076eb3 | ||
|
|
4e33533bd0 | ||
|
|
1f344bd47c | ||
|
|
5b8fa23a8d | ||
|
|
ed78003b23 | ||
|
|
20e966b9cd | ||
|
|
7697ef5988 | ||
|
|
768213b816 | ||
|
|
f9dd20e86d | ||
|
|
a96f873e21 | ||
|
|
ab9d9604b4 | ||
|
|
2a90323af3 | ||
|
|
00e1588ef9 | ||
|
|
a439b8da47 | ||
|
|
a2f4e8b499 | ||
|
|
8e95c2486f | ||
|
|
1878607208 | ||
|
|
930a407a3a | ||
|
|
eadfcd4cf8 | ||
|
|
19fbc076d6 | ||
|
|
1a924f2ca7 | ||
|
|
ebe49b9bdd | ||
|
|
7923ab63b1 | ||
|
|
09224d2cdf | ||
|
|
167a9f2818 | ||
|
|
ad40520e89 | ||
|
|
2b3a9e4a6a | ||
|
|
72ebb4deb6 | ||
|
|
d957a60286 | ||
|
|
ba11ff58dd | ||
|
|
97f68b04ea | ||
|
|
61a11f8c15 | ||
|
|
cd08f1e1c2 | ||
|
|
afa95fd0df | ||
|
|
ef5e5d13e0 | ||
|
|
5388bbce43 | ||
|
|
185fe0ae1d | ||
|
|
8fa1b8aee7 | ||
|
|
c17ccd3070 | ||
|
|
9849c49920 | ||
|
|
4cdf14680e | ||
|
|
bf5f794553 | ||
|
|
34da4fe001 | ||
|
|
2406bb4000 | ||
|
|
db62653472 | ||
|
|
6bb6452603 | ||
|
|
8d93c3ff9f | ||
|
|
f93e8b9750 | ||
|
|
9a8609f770 | ||
|
|
39162a4435 | ||
|
|
1ccde6fc3e | ||
|
|
45f7bf8e01 | ||
|
|
eed0833a29 | ||
|
|
223b096295 | ||
|
|
1987a3915e | ||
|
|
250a0f1b12 | ||
|
|
61843f823d | ||
|
|
44bdbbcbed | ||
|
|
482a618d1e | ||
|
|
1a187445a5 | ||
|
|
8ab75bb727 | ||
|
|
8c4489fb3d | ||
|
|
a2bcb23f0e | ||
|
|
43050bf20a | ||
|
|
8710148ce0 | ||
|
|
6618925841 | ||
|
|
1eb090d407 | ||
|
|
f373cf4ae6 | ||
|
|
e040cc5fc2 | ||
|
|
38f1c2f10a | ||
|
|
bece2421f1 | ||
|
|
fb257f549b | ||
|
|
b9c50ef0c5 | ||
|
|
f7e0619b24 | ||
|
|
d351ec5932 | ||
|
|
4eef3e6c4d | ||
|
|
92c87aac6c | ||
|
|
34310504b5 | ||
|
|
5188d36a5c | ||
|
|
bfea3d36ad | ||
|
|
592278441c | ||
|
|
48ba977270 | ||
|
|
8671d1062b | ||
|
|
7c3b6211b0 | ||
|
|
cd6a452c08 | ||
|
|
7b71766ab4 | ||
|
|
a90c4bfbf5 | ||
|
|
cdcab2370d | ||
|
|
30f67f0471 | ||
|
|
28b5724871 | ||
|
|
298f4de168 | ||
|
|
bf2962dc29 | ||
|
|
c1fc670af4 | ||
|
|
91b65d0180 | ||
|
|
ac0befa9b9 | ||
|
|
4fabf9d26c | ||
|
|
3d5ea26605 | ||
|
|
10b879bc31 | ||
|
|
00de5a7f43 | ||
|
|
0ee747cf1b | ||
|
|
d69ee47321 | ||
|
|
05c765e36d | ||
|
|
7c0b835ce3 | ||
|
|
c44a42fc16 | ||
|
|
5632924c4f | ||
|
|
bbcad0845a | ||
|
|
d0efbee65b | ||
|
|
c5799d2f9b | ||
|
|
19758f44cf | ||
|
|
f5880d449b | ||
|
|
d0e7dee951 | ||
|
|
a5a5d9a16f | ||
|
|
41821c841a | ||
|
|
017451762d | ||
|
|
e7c05c5370 | ||
|
|
070a5dd35b | ||
|
|
57025ccb3b | ||
|
|
fb588e85c0 | ||
|
|
bfb80605c3 | ||
|
|
e4302579ce | ||
|
|
2979bc3b84 | ||
|
|
8f20ca8fdc | ||
|
|
e67f77f8e6 | ||
|
|
7c338230de | ||
|
|
7548314b95 | ||
|
|
e78b3eea0a | ||
|
|
7989ddc227 | ||
|
|
4abb853400 | ||
|
|
bda4abb13e | ||
|
|
63dff99f11 | ||
|
|
e1476cfdf9 | ||
|
|
7c33a2cf4c | ||
|
|
2682a623de | ||
|
|
7d97516c3b | ||
|
|
485c2f10b1 | ||
|
|
bb164bb2b8 | ||
|
|
479b5b5521 | ||
|
|
7d6eeed8ae | ||
|
|
16517579b2 | ||
|
|
4289d5583b | ||
|
|
773f89e9de | ||
|
|
fe3bdb5d10 | ||
|
|
6b5099c8d7 | ||
|
|
901c800c62 | ||
|
|
6a02d80072 | ||
|
|
ba2a7d73b7 | ||
|
|
f1231fccb0 | ||
|
|
310d4817ca | ||
|
|
5126d83722 | ||
|
|
40771c41ab | ||
|
|
7507a250c7 | ||
|
|
260dab75d5 | ||
|
|
f0e7631d11 | ||
|
|
98875eba70 | ||
|
|
c62f8e07fd | ||
|
|
d1ed5fd555 | ||
|
|
ba0d2eeacc | ||
|
|
e0f12c8c37 | ||
|
|
d57fa43bcc | ||
|
|
e0f0a56630 | ||
|
|
0fe5f0aaaf | ||
|
|
9bb02a2cb2 | ||
|
|
d4ed5ae13f | ||
|
|
21523a449f | ||
|
|
ad3d73d9bd | ||
|
|
9be15fe393 | ||
|
|
1f1126d4ec | ||
|
|
af61faf706 | ||
|
|
06ff2dc2c6 | ||
|
|
b0242f68fe | ||
|
|
240015c814 | ||
|
|
61fff7da67 | ||
|
|
c677534e11 | ||
|
|
8e3b44c6fc | ||
|
|
ce839ba602 | ||
|
|
2beb39c371 | ||
|
|
e84e2adff0 | ||
|
|
2394dec1c5 | ||
|
|
e75112baec | ||
|
|
f89f34ce7b | ||
|
|
1506507f21 | ||
|
|
8a340b5297 | ||
|
|
e0632b2c0e | ||
|
|
69c24b5270 | ||
|
|
9496c57d41 | ||
|
|
84e640b7d2 | ||
|
|
c636642864 | ||
|
|
9eb143ab6c | ||
|
|
598125a1d5 | ||
|
|
218d5cb67f | ||
|
|
c625733a33 | ||
|
|
da82c2cf80 | ||
|
|
0071181fb1 | ||
|
|
1b3cc20127 | ||
|
|
5b0925ce3a | ||
|
|
c9f70c9287 | ||
|
|
7ce4720854 | ||
|
|
9a3a6bd3ba | ||
|
|
3cdd4943f0 | ||
|
|
4ee5b45cb8 | ||
|
|
ddee3bf9af | ||
|
|
4a83418c02 | ||
|
|
5f7f6b3e40 | ||
|
|
5b4c454ca2 | ||
|
|
b0756f8b45 | ||
|
|
1695075836 | ||
|
|
306534fdf0 | ||
|
|
0933144535 | ||
|
|
86fb18afb7 | ||
|
|
a6ab2e54cd | ||
|
|
5255ffa0c4 | ||
|
|
b0d263c336 | ||
|
|
ba50db813a | ||
|
|
3303e9170c | ||
|
|
6a91fa15f6 | ||
|
|
7e4c9b9992 | ||
|
|
34e1938df1 | ||
|
|
990f6c6598 | ||
|
|
e5bb4fa9bc | ||
|
|
acb12fea95 | ||
|
|
c37426f64b | ||
|
|
6edb9ab526 | ||
|
|
dc4f1dff39 | ||
|
|
6c47ffcf8f | ||
|
|
0259d77d11 | ||
|
|
1ed86db4aa | ||
|
|
21b53f5dfb | ||
|
|
fa5df62e97 | ||
|
|
54a19f3f64 | ||
|
|
6edfe1da8d | ||
|
|
89e36241cb | ||
|
|
14901e8723 | ||
|
|
66ae3cd918 | ||
|
|
c3fd353abe | ||
|
|
968e1b7493 | ||
|
|
0ad09c7382 | ||
|
|
8604d121eb | ||
|
|
d6d6bd1891 | ||
|
|
e2eb99fc19 | ||
|
|
fc51bf4832 | ||
|
|
3c929d518c | ||
|
|
e383004afc | ||
|
|
27072735e9 | ||
|
|
30f8e7407b | ||
|
|
6458b72062 | ||
|
|
49fbb17db9 | ||
|
|
ff8b27c89b | ||
|
|
7f3aeedfc0 | ||
|
|
eaa903a8ec | ||
|
|
72aba8c415 | ||
|
|
a118867b43 | ||
|
|
69b6fa7393 | ||
|
|
b2bddecde2 | ||
|
|
bac26c8a28 | ||
|
|
536c573223 | ||
|
|
ec58535ca0 | ||
|
|
359c37d17f | ||
|
|
a015b5ed24 | ||
|
|
4c112de4d5 | ||
|
|
21eaa55b27 | ||
|
|
541eaa20fe | ||
|
|
93e222a8a8 | ||
|
|
bc8126efef | ||
|
|
8d40d90950 | ||
|
|
ff9f089dd8 | ||
|
|
e70754ef56 | ||
|
|
4b29e43ca1 | ||
|
|
1a16fb55da | ||
|
|
b30232298c | ||
|
|
771471c83b | ||
|
|
cee3102568 | ||
|
|
3543e7818b | ||
|
|
4ce2d82645 | ||
|
|
8899b62cd4 | ||
|
|
7044bf5024 | ||
|
|
48c7d8252e | ||
|
|
7c0492b06c | ||
|
|
9e98b28844 | ||
|
|
bf852f27aa | ||
|
|
d827d1abf0 | ||
|
|
8af822e3fd | ||
|
|
59b46be0d2 | ||
|
|
78cf4e7666 | ||
|
|
8ef266ad6f | ||
|
|
36be6f31df | ||
|
|
c68d51b8b5 | ||
|
|
a90412c7a6 | ||
|
|
e557168e6e | ||
|
|
c2e2ac82fa | ||
|
|
df02ee40fd | ||
|
|
73582f92e1 | ||
|
|
ab31847d4e | ||
|
|
5812a2f97d | ||
|
|
ad7e580918 | ||
|
|
3aca67b9d0 | ||
|
|
e1db8701b5 | ||
|
|
e9eac06e5d | ||
|
|
ff76ee95ad | ||
|
|
27c3b9a860 | ||
|
|
7221a1e5cd | ||
|
|
2ab74991b8 | ||
|
|
b6e61fe63d | ||
|
|
63f944b525 | ||
|
|
ec7e672c1f | ||
|
|
8e06b6af65 | ||
|
|
09e736a687 | ||
|
|
0fffea89b1 | ||
|
|
1db4728081 | ||
|
|
07c13b0b9c | ||
|
|
33991dafa9 | ||
|
|
6f03ceac26 | ||
|
|
df766ca1db | ||
|
|
b707508d1e | ||
|
|
1ce48944c7 | ||
|
|
81cb2d7ab8 | ||
|
|
56be952060 | ||
|
|
b289c0d361 | ||
|
|
cd9a373067 | ||
|
|
058b2458fb | ||
|
|
9af3540d28 | ||
|
|
54b9b2ce85 | ||
|
|
bc8d3e1499 | ||
|
|
de24c7f07c | ||
|
|
3d058af14c | ||
|
|
1883e6e3e4 | ||
|
|
d7b53bf2f1 | ||
|
|
2a85e55d4e | ||
|
|
39db267630 | ||
|
|
2271b805bb | ||
|
|
d2ba93abcd | ||
|
|
4ba52d9ab7 | ||
|
|
b056f32c13 | ||
|
|
406e17446f | ||
|
|
7b9904b1fe | ||
|
|
f468aa75e8 | ||
|
|
3ac9947dc8 | ||
|
|
29517d702c | ||
|
|
43f6b57ab2 | ||
|
|
cd8afa47d9 | ||
|
|
04bfc92d3d | ||
|
|
2165b3b296 | ||
|
|
8fa8289a6a | ||
|
|
c3fd29a64c | ||
|
|
1bac48e84e | ||
|
|
cf93d30150 | ||
|
|
0de534c692 | ||
|
|
e8d1bf96be | ||
|
|
4938fb2d73 | ||
|
|
5943cd87a1 | ||
|
|
03b7b6ed24 | ||
|
|
c529ca259f | ||
|
|
13edd34daa | ||
|
|
d29e1426d0 | ||
|
|
4851475773 | ||
|
|
93ecfc7f1f | ||
|
|
386095bd53 | ||
|
|
9fdd8a76c2 | ||
|
|
e313248b5f | ||
|
|
4332246f79 | ||
|
|
1550131792 | ||
|
|
c4e8b51694 | ||
|
|
a5d7108631 | ||
|
|
6e16742446 | ||
|
|
24d9c6cdf8 | ||
|
|
ee338479ad | ||
|
|
5fbc366f1b | ||
|
|
01fb2e13ca | ||
|
|
e82e5a57ad | ||
|
|
af772096d7 | ||
|
|
76db40eb6b | ||
|
|
299f0b56e0 | ||
|
|
347db8d4fd | ||
|
|
104909817b | ||
|
|
339964920b | ||
|
|
c663b27848 | ||
|
|
daa7737392 | ||
|
|
99c21957de | ||
|
|
778bcd0eee | ||
|
|
24d0bae793 | ||
|
|
8e50fab811 | ||
|
|
bec5278a89 | ||
|
|
cdc6e1f521 | ||
|
|
4194e93a67 | ||
|
|
4f076c6cc3 | ||
|
|
a59e40c02f | ||
|
|
af96eeba86 | ||
|
|
8f7fd39e21 | ||
|
|
db3f07d277 | ||
|
|
7c461a96ae | ||
|
|
ef142bb8c0 | ||
|
|
983c46e257 | ||
|
|
2242ae3c46 | ||
|
|
bc78e01b6f | ||
|
|
9ff6d98820 | ||
|
|
b83c546831 | ||
|
|
f28c49a976 | ||
|
|
e12f4b608f | ||
|
|
a3306361ee | ||
|
|
3ec05dda1f | ||
|
|
43de6790af | ||
|
|
a1fbd5dfa7 | ||
|
|
6457cf1eba | ||
|
|
31662c2af9 | ||
|
|
66fc450ae8 | ||
|
|
08d38f651b | ||
|
|
4e67d7e99f | ||
|
|
967b636b74 | ||
|
|
644aa8b46c | ||
|
|
9fae9009c5 | ||
|
|
9433140931 | ||
|
|
4c2d8f034c | ||
|
|
c28d12330e | ||
|
|
d89a6bacc6 | ||
|
|
5db642e161 | ||
|
|
4aaa805f2a | ||
|
|
2bb1b273fe | ||
|
|
2551d13cf3 | ||
|
|
1e00430eef | ||
|
|
cfa02ea26e | ||
|
|
88285ad5e2 | ||
|
|
5355f4826a | ||
|
|
b58b3a9f6a | ||
|
|
0d98108bc4 | ||
|
|
4f7206702f | ||
|
|
bacb663469 | ||
|
|
fb62b14512 | ||
|
|
722d3a03b7 | ||
|
|
cd51fec81a | ||
|
|
12c213eb4c | ||
|
|
9a83736411 | ||
|
|
bf36f84445 | ||
|
|
5094abded9 | ||
|
|
7125a9f92f | ||
|
|
63a35b8817 | ||
|
|
f06c9cf5fd | ||
|
|
1e48d04077 | ||
|
|
0930d57546 | ||
|
|
103174e44c | ||
|
|
36b893c523 | ||
|
|
6cbaa84c52 | ||
|
|
86af4c29c4 | ||
|
|
fea9de98eb | ||
|
|
b29d7b89c2 | ||
|
|
87edff67ee | ||
|
|
8597083493 | ||
|
|
c8e1c8b40d | ||
|
|
b316489b93 | ||
|
|
42c3db1d5b | ||
|
|
ad561e485f | ||
|
|
b05502fa9a | ||
|
|
ffc4b88859 | ||
|
|
2aed3151af | ||
|
|
c4ba9eb23e | ||
|
|
a600090fcd | ||
|
|
06e5980898 | ||
|
|
9e4ced8274 | ||
|
|
2879e78481 | ||
|
|
f0c4d564d2 | ||
|
|
9e02d6234b | ||
|
|
316af50da3 | ||
|
|
3cc4cb9392 | ||
|
|
1448f85b15 | ||
|
|
dce4d01a58 | ||
|
|
d5676ee4b3 | ||
|
|
ccbefc5653 | ||
|
|
c8d842b924 | ||
|
|
b7e251a463 | ||
|
|
c76d8ef381 | ||
|
|
e586c0a05c | ||
|
|
ff2f90ec18 | ||
|
|
da8384d10e | ||
|
|
019a7ab9f7 | ||
|
|
611fafb58e | ||
|
|
642a0ad2f9 | ||
|
|
bff7b402e7 | ||
|
|
7bc4836eb0 | ||
|
|
ef28ac17f4 | ||
|
|
8e7b8ab1d1 | ||
|
|
dcb7ba016c | ||
|
|
b925457262 | ||
|
|
121d6f24a9 | ||
|
|
cbb678f42e | ||
|
|
0cd1ab79e4 | ||
|
|
5a7747f2bf | ||
|
|
a8314676c9 | ||
|
|
248d09ec14 | ||
|
|
d9dcb3ef36 | ||
|
|
5125feabe6 | ||
|
|
50f3dde9f5 | ||
|
|
298f26bb4c | ||
|
|
d9a9da921a | ||
|
|
12e1fd4403 | ||
|
|
2e9bd2bd7b | ||
|
|
a5cafab0e8 | ||
|
|
9fed8edb50 | ||
|
|
eb45c3c67c | ||
|
|
84db958110 | ||
|
|
00cc0f8ff2 | ||
|
|
d3e555e2f4 | ||
|
|
bbd872f519 | ||
|
|
2940df27b1 | ||
|
|
144f05a099 | ||
|
|
0892f112bc | ||
|
|
03ee0930e1 | ||
|
|
ca4aa88583 | ||
|
|
a4fcf3de51 | ||
|
|
9fd2066711 | ||
|
|
de06949121 | ||
|
|
d44c45c9b9 | ||
|
|
56c45eb7d6 | ||
|
|
6ce46884d5 | ||
|
|
6635dda18f | ||
|
|
e163aab3d1 | ||
|
|
2a46134d14 | ||
|
|
41ecd473da | ||
|
|
3eb07835f7 | ||
|
|
edc8bbd9ab | ||
|
|
e0b4f73c9e | ||
|
|
3eca094c5c | ||
|
|
6182730923 | ||
|
|
c2950e332f | ||
|
|
e053605e82 | ||
|
|
d68e6b877d | ||
|
|
161d6e6451 | ||
|
|
f8bae4bee8 | ||
|
|
0c6c5d20d6 | ||
|
|
1abc5ae6d9 | ||
|
|
f86ccc378c | ||
|
|
5b13cc7ab1 | ||
|
|
faec6b5333 | ||
|
|
267bd0a9cb | ||
|
|
6676b42dab | ||
|
|
9cd38f59ff | ||
|
|
0f4a33ce48 | ||
|
|
524fbb02ef | ||
|
|
e5c864c246 | ||
|
|
00c888546a | ||
|
|
8953adad88 | ||
|
|
0772e6dc23 | ||
|
|
0fba15e32c | ||
|
|
62de8d0bb8 | ||
|
|
f3c35722d9 | ||
|
|
464206d2de | ||
|
|
3c38f9c468 | ||
|
|
58e4a737d5 | ||
|
|
5788fbb5d6 | ||
|
|
558a93c25b | ||
|
|
b90e767529 | ||
|
|
7033d5e80d | ||
|
|
8f43d0ecdf | ||
|
|
d6c1e27259 | ||
|
|
4b47e88369 | ||
|
|
cbfea2f961 | ||
|
|
0178fc86a8 | ||
|
|
459c03933c | ||
|
|
9199bb20f4 | ||
|
|
893f425c56 | ||
|
|
7ce80ce590 | ||
|
|
05b0385805 | ||
|
|
cce99f2802 | ||
|
|
8f09aa223b | ||
|
|
f913d85e66 | ||
|
|
7ba95ac07f | ||
|
|
820f7c2351 | ||
|
|
a489c738b3 | ||
|
|
fc4ce1cd79 | ||
|
|
00b52e3c1f | ||
|
|
69a0004fe6 | ||
|
|
9a28de8ab0 | ||
|
|
54a9159b25 | ||
|
|
b4155cc5a2 | ||
|
|
e6ae282b88 | ||
|
|
3e61b70517 | ||
|
|
71a35a6376 | ||
|
|
7f53665beb | ||
|
|
b57281f5a4 | ||
|
|
cf2db47e57 | ||
|
|
4d1e4e6e6e | ||
|
|
f39572c878 | ||
|
|
512bb3c75c | ||
|
|
9b3cc53db9 | ||
|
|
6563094d20 | ||
|
|
21540afaac | ||
|
|
b5074699da | ||
|
|
fd3788c517 | ||
|
|
5f3410cd24 | ||
|
|
e6f91ed349 | ||
|
|
91b1719af9 | ||
|
|
ac153497f6 | ||
|
|
bce3c96acb | ||
|
|
4ed1f4c451 | ||
|
|
fed8acb376 | ||
|
|
f684304ca1 | ||
|
|
0655c45a27 | ||
|
|
529729f21b | ||
|
|
7428711d94 | ||
|
|
6d9a7b8aae | ||
|
|
9a3af4a44b | ||
|
|
565a90c71d | ||
|
|
316cf8a3be | ||
|
|
9757688f56 | ||
|
|
bd20ba5b8f | ||
|
|
f299a1a8b9 | ||
|
|
a5bb2ba5b5 | ||
|
|
6034559dc2 | ||
|
|
89bbd20b5a | ||
|
|
418bf4f54f | ||
|
|
e69f55468c | ||
|
|
fba07cba40 | ||
|
|
ce8ab8b4aa | ||
|
|
af8de82d59 | ||
|
|
bc1857ec73 | ||
|
|
1eb481ccc8 | ||
|
|
fd8f019751 | ||
|
|
b8abf3ed3b | ||
|
|
8fc1997b1b | ||
|
|
90718ba7a3 | ||
|
|
46b5d409bf | ||
|
|
eaa578a4b9 | ||
|
|
13c5433c0d | ||
|
|
b3f7054345 | ||
|
|
62e56af786 | ||
|
|
a8601f5a5c | ||
|
|
e1bf32b9fb | ||
|
|
9c70fa6599 | ||
|
|
d260113d51 | ||
|
|
1e2091fcba | ||
|
|
6d94262f8c | ||
|
|
6d423fb3dc | ||
|
|
3a2b6f4a9c | ||
|
|
938531cb10 | ||
|
|
fcd849be7a | ||
|
|
f79ef33b4b | ||
|
|
26eb65e0a2 | ||
|
|
bf610ec08a | ||
|
|
4f056485f2 | ||
|
|
3524c880ea | ||
|
|
150acc753e | ||
|
|
d4e82c8aff | ||
|
|
ef6eb0023a | ||
|
|
56cfbb757a | ||
|
|
a2dfbec30d | ||
|
|
8160dc8d26 | ||
|
|
009c4c6e73 | ||
|
|
84bcdb687a | ||
|
|
5bed0cd831 | ||
|
|
224d57fbcf | ||
|
|
88699377d2 | ||
|
|
960c8e104a | ||
|
|
160961a1f4 | ||
|
|
db942e9204 | ||
|
|
f067f2cdb0 | ||
|
|
53db5c8dd9 | ||
|
|
977b69ce07 | ||
|
|
92ce8c777c | ||
|
|
dc024ae552 | ||
|
|
6bd156e4a6 | ||
|
|
6c852a8eea | ||
|
|
b3cd0ef661 | ||
|
|
fdf7387b8e | ||
|
|
d1357239e2 | ||
|
|
8ea78f709a | ||
|
|
cdd1169bd4 | ||
|
|
088f55f94c | ||
|
|
12e3f2dc48 | ||
|
|
5524cfa8d8 | ||
|
|
457b08ce15 | ||
|
|
56a6c64586 | ||
|
|
7ee394b7d9 | ||
|
|
50cca4309f | ||
|
|
e27160571a | ||
|
|
31792235e6 | ||
|
|
a245c2f1e9 | ||
|
|
13550328a6 | ||
|
|
2c8dff86b5 | ||
|
|
64def921ea | ||
|
|
2339eb60b8 | ||
|
|
bdc9a61524 | ||
|
|
381b55ef53 | ||
|
|
c6af94fe58 | ||
|
|
5b6175714b | ||
|
|
260a16181c | ||
|
|
bec5e063bc | ||
|
|
efcc8125af | ||
|
|
d9066aa1c6 | ||
|
|
1a234ccea9 | ||
|
|
ee30209040 | ||
|
|
2992b08a11 | ||
|
|
626a824e65 | ||
|
|
844a2443a5 | ||
|
|
e9d2997760 | ||
|
|
5d33692d7f | ||
|
|
676d4bace4 | ||
|
|
60b1479e8a | ||
|
|
a2ac794e7a | ||
|
|
e85432c9f6 | ||
|
|
5bbd78ad66 | ||
|
|
9f65ca98d3 | ||
|
|
d2441d5fcc | ||
|
|
86bae053b6 | ||
|
|
5906cecf19 | ||
|
|
c2a3f3553f | ||
|
|
940889c2a2 | ||
|
|
9493d0d289 | ||
|
|
c0e2621bba | ||
|
|
6cec46cc77 | ||
|
|
0f62358fb0 | ||
|
|
e089fd9c3c | ||
|
|
00ec7af34e | ||
|
|
aa34cd20dd | ||
|
|
661b735060 | ||
|
|
6530702037 | ||
|
|
28cb212030 | ||
|
|
2b37238b30 | ||
|
|
48dfe36084 | ||
|
|
b46da94f50 | ||
|
|
78825dc580 | ||
|
|
efce28c996 | ||
|
|
0dec003660 | ||
|
|
dcaf4d4084 | ||
|
|
df82ca5959 | ||
|
|
1dcb310184 | ||
|
|
395c53e63f | ||
|
|
81d6d548aa | ||
|
|
24d8e4e987 | ||
|
|
1cad83bad7 | ||
|
|
9e762ec638 | ||
|
|
0def1a70d7 | ||
|
|
52241e7a17 | ||
|
|
c8fb62c3ad | ||
|
|
598359ff36 | ||
|
|
b815b54bff | ||
|
|
00f5c1b821 | ||
|
|
84d1a5b156 | ||
|
|
99b05bbb2e | ||
|
|
813963a35a | ||
|
|
77772056bd | ||
|
|
f531d5524d | ||
|
|
08fcdac0f8 | ||
|
|
0fdf56f4bb | ||
|
|
7310af36e6 | ||
|
|
8cbb86dfbd | ||
|
|
c87fc4e6cf | ||
|
|
8e4039a618 | ||
|
|
cd6e0ef317 | ||
|
|
67cec41b9c | ||
|
|
8b41346466 | ||
|
|
95e2427553 | ||
|
|
c1a1b027b3 | ||
|
|
9c68e42c44 | ||
|
|
e635f7ba8f | ||
|
|
7574848c5f | ||
|
|
d637a89b5e | ||
|
|
7024df820a | ||
|
|
0c28d6a716 | ||
|
|
847ab4e1fb | ||
|
|
97e990c8f8 | ||
|
|
aac39f1326 | ||
|
|
cad384d483 | ||
|
|
0b81504139 | ||
|
|
33c6fc4f7f | ||
|
|
92d938dd8c | ||
|
|
f0d041b8dc | ||
|
|
f9df426396 | ||
|
|
f8e509ce56 | ||
|
|
4dc67a98fa | ||
|
|
497f87176b | ||
|
|
57a4397c90 | ||
|
|
02f3d8c208 | ||
|
|
ad0282d5e9 | ||
|
|
21c97051c8 | ||
|
|
b584af3f61 | ||
|
|
18f978e852 | ||
|
|
1aeccdfb01 | ||
|
|
69524c6489 | ||
|
|
f5b11e1aa0 | ||
|
|
1ddc26087d | ||
|
|
0e67e56c7c | ||
|
|
bd3727a900 | ||
|
|
01be023d26 | ||
|
|
78c680ce1e | ||
|
|
28da5e08c3 | ||
|
|
02a4ef3497 | ||
|
|
9b6f886577 | ||
|
|
848c2b035e | ||
|
|
7ecae5a6dd | ||
|
|
c7ad2477f0 | ||
|
|
996b15cb45 | ||
|
|
7fca7f0ac8 | ||
|
|
2312b05bb5 | ||
|
|
268d2be034 | ||
|
|
2c8d3f5b40 | ||
|
|
689947bec5 | ||
|
|
fdc482d512 | ||
|
|
a3d4e0d8ad | ||
|
|
e7ef3f3a78 | ||
|
|
f366225135 | ||
|
|
fe025a3b73 | ||
|
|
0b7cec27e8 | ||
|
|
99e35b74e6 | ||
|
|
c48c7e723a | ||
|
|
f288270513 | ||
|
|
05494e7bb9 | ||
|
|
ac2c4d3e20 | ||
|
|
58b3b030db | ||
|
|
9efc402a06 | ||
|
|
4a61381ff1 | ||
|
|
28ebd45863 | ||
|
|
c4a8590671 | ||
|
|
5d3c2c680e | ||
|
|
c16e07ba0e | ||
|
|
1dd48d81a0 | ||
|
|
371b1a98f6 | ||
|
|
7a7b504836 | ||
|
|
941af88086 | ||
|
|
86d13a41a3 | ||
|
|
91791fdabd | ||
|
|
42785f6fa2 | ||
|
|
2f1b60f2a2 | ||
|
|
b4a512e627 | ||
|
|
7db5b0dfe4 | ||
|
|
3cdecff518 | ||
|
|
5009bb9256 | ||
|
|
83b5275fe2 | ||
|
|
1425374d27 | ||
|
|
ad6c793a2f | ||
|
|
ae8a6f1a6d | ||
|
|
bcca6028db | ||
|
|
6a14c1c0af | ||
|
|
5f64c25935 | ||
|
|
ca9aad9757 | ||
|
|
f30c54faa1 | ||
|
|
3442b7af37 | ||
|
|
cb6dc7c320 | ||
|
|
aa1ebee3cc | ||
|
|
73d15c08f2 | ||
|
|
83ff5c747d | ||
|
|
fbe34bcf07 | ||
|
|
276412d7ff | ||
|
|
9f43e927e4 | ||
|
|
9d79964487 | ||
|
|
33d9e942f2 | ||
|
|
846340c553 | ||
|
|
38a2492394 | ||
|
|
68c10c5664 | ||
|
|
7fcf1ce9ee | ||
|
|
2b052791da | ||
|
|
8688e62cd8 | ||
|
|
e1499f0617 | ||
|
|
de66361014 | ||
|
|
2c1f5a4033 | ||
|
|
940d42c659 | ||
|
|
ce286795e0 | ||
|
|
dd8c4d405a | ||
|
|
5e0c04c3cf | ||
|
|
8cfc24fc2e | ||
|
|
1ec1e0a224 | ||
|
|
5fc1dbd264 | ||
|
|
c3068b15e1 | ||
|
|
21195a06be | ||
|
|
190fdef8b3 | ||
|
|
60937e2526 | ||
|
|
ec14823429 | ||
|
|
fdc2cec328 | ||
|
|
cbbb971d35 | ||
|
|
7d1ce3296d | ||
|
|
b1fcabcebe | ||
|
|
5fcd76a9f9 | ||
|
|
51e34d5369 | ||
|
|
4866f7097a | ||
|
|
91a9c41290 | ||
|
|
0b597eb417 | ||
|
|
d7c8fdd0ed | ||
|
|
1778888acc | ||
|
|
a227e061ec | ||
|
|
ee34487126 | ||
|
|
61277b6b9b | ||
|
|
55d8e9e73d | ||
|
|
3b31e6df05 | ||
|
|
43bebef626 | ||
|
|
e7bd54e67b | ||
|
|
799241364f | ||
|
|
69aeb817e2 | ||
|
|
07832b1a2c | ||
|
|
a217a44f05 | ||
|
|
0f618f1998 | ||
|
|
3a4768ab43 | ||
|
|
9b9e9f68bb | ||
|
|
b2b449c913 | ||
|
|
deb88b17b9 | ||
|
|
5595403215 | ||
|
|
64afa00457 | ||
|
|
a732cb0cb2 | ||
|
|
66dd7b3a3f | ||
|
|
80bc3a4084 | ||
|
|
e0d5488138 | ||
|
|
9ab20f14f8 | ||
|
|
735724899b | ||
|
|
18c954ddcd | ||
|
|
04c260bb22 | ||
|
|
154505f451 | ||
|
|
6ff7aeb5cf | ||
|
|
6d53c3987a | ||
|
|
d813ce7e39 | ||
|
|
bd067ae779 | ||
|
|
f0b51bfc29 | ||
|
|
ab87109ec5 | ||
|
|
e00232dcfb | ||
|
|
74da8116db | ||
|
|
839bc4a6e5 | ||
|
|
0d24af4e5b | ||
|
|
496989ccfb | ||
|
|
bcd0888928 | ||
|
|
042800cb2a | ||
|
|
fc0cb1873a | ||
|
|
8f5cbce468 | ||
|
|
5b0f155116 | ||
|
|
cafff10266 | ||
|
|
1ba1c487c7 | ||
|
|
540b88a946 | ||
|
|
337e620cf1 | ||
|
|
eca4320d1c | ||
|
|
0ae849b1df | ||
|
|
ab9b8d3471 | ||
|
|
bc77fabdad | ||
|
|
6b85c9045e | ||
|
|
6bbbceb55f | ||
|
|
86eb29f243 | ||
|
|
8501968154 | ||
|
|
c77e747f4e | ||
|
|
349a3519ef | ||
|
|
e1df6af536 | ||
|
|
20af25ea40 | ||
|
|
3883667254 | ||
|
|
90b8ba6461 | ||
|
|
72ac9b09cb | ||
|
|
15c065d2bb | ||
|
|
71afa10f4d | ||
|
|
0c37cd6402 | ||
|
|
cbaa9a35e9 | ||
|
|
17517b9f4e | ||
|
|
6acad9425d | ||
|
|
94f8d3a48c | ||
|
|
c8b11baf04 | ||
|
|
7f0fbf15ae | ||
|
|
04270ef754 | ||
|
|
fcfaa41348 | ||
|
|
532e4d740f | ||
|
|
e82da39d29 | ||
|
|
3ed2a3dd33 | ||
|
|
393f69f766 | ||
|
|
c2e466e16c | ||
|
|
a6bba2af80 | ||
|
|
1a6144aa35 | ||
|
|
7ba8449ff6 | ||
|
|
3841a95068 | ||
|
|
1d654b286d | ||
|
|
ee3906bb19 | ||
|
|
262d21c431 | ||
|
|
98ffc1fb80 | ||
|
|
8e426b236d | ||
|
|
0f52bb80ad | ||
|
|
00e84bb977 | ||
|
|
23ddaa8bed | ||
|
|
8f50f22622 | ||
|
|
cddaf14cd0 | ||
|
|
bd39747c22 | ||
|
|
17dd41696c | ||
|
|
7b3f213ae8 | ||
|
|
b48e9ca6ce | ||
|
|
9296db5538 | ||
|
|
d3f68c5372 | ||
|
|
e4dabdbc7a | ||
|
|
0d16381b28 | ||
|
|
3076aabbe0 | ||
|
|
f02a740b10 | ||
|
|
c3b240bdfa | ||
|
|
3f2482716b | ||
|
|
7bdc41c0d3 | ||
|
|
416e270899 | ||
|
|
1fad9c8855 | ||
|
|
8d9683d844 | ||
|
|
77f5ec7d4f | ||
|
|
46badf078e | ||
|
|
b39b0771a0 | ||
|
|
b1343147e8 | ||
|
|
8b03cc036e | ||
|
|
7e0634205a | ||
|
|
a8c8f8fb5a | ||
|
|
9e00300860 | ||
|
|
68fedded8c | ||
|
|
82f0f6a134 | ||
|
|
fe6552ba7c | ||
|
|
c072a271e5 | ||
|
|
8195da08e8 | ||
|
|
10066c5ec0 | ||
|
|
1e21adfde2 | ||
|
|
e22f75ac7a | ||
|
|
c09d0f9c6d | ||
|
|
cc1c0c5d94 | ||
|
|
bfc73581ec | ||
|
|
397d2d120a | ||
|
|
eed1738d8f | ||
|
|
85cf4712fc | ||
|
|
8596b9abf5 | ||
|
|
bfbdaf34ea | ||
|
|
440d02afb3 | ||
|
|
5ab0d8ca88 | ||
|
|
2469531c2f | ||
|
|
47026d5ebb | ||
|
|
29e491e715 | ||
|
|
e7415c1812 | ||
|
|
460f3caf38 | ||
|
|
38031571c1 | ||
|
|
05e21fd8a3 | ||
|
|
b71358e2cc | ||
|
|
fc21f2d1bd | ||
|
|
bf7540cd9e | ||
|
|
173c49fc87 | ||
|
|
3f1d9cecba | ||
|
|
a072d60cae | ||
|
|
efdfe1f755 | ||
|
|
9073190646 | ||
|
|
3a63813b3d | ||
|
|
03164e853e | ||
|
|
2819b05838 |
@@ -2,3 +2,9 @@ vendor/
|
|||||||
# A compiled program never enters a commit (issue 1577): `go build .` in a command directory leaves one there.
|
# A compiled program never enters a commit (issue 1577): `go build .` in a command directory leaves one there.
|
||||||
modules/*/cmd/*/mesh-*
|
modules/*/cmd/*/mesh-*
|
||||||
!modules/*/cmd/*/mesh-*.go
|
!modules/*/cmd/*/mesh-*.go
|
||||||
|
# `go build .` at a module's root leaves its program there too (the view's, met a second time).
|
||||||
|
modules/*/mesh-*
|
||||||
|
# The delivery SDK's commands (design 47 G §464), built in their own directory or at the SDK's root.
|
||||||
|
/modules/mesh-delivery-sdk/cmd/seatgen/seatgen
|
||||||
|
/modules/mesh-delivery-sdk/seatgen/seatgen
|
||||||
|
/modules/mesh-delivery-sdk/mesh-pack
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const (
|
|||||||
VerbCurrent = "current"
|
VerbCurrent = "current"
|
||||||
VerbPause = "pause"
|
VerbPause = "pause"
|
||||||
VerbResume = "resume"
|
VerbResume = "resume"
|
||||||
|
VerbDrop = "drop"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -28,7 +29,7 @@ const (
|
|||||||
|
|
||||||
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
|
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
|
||||||
func Verbs() []string {
|
func Verbs() []string {
|
||||||
return []string{VerbCurrent, VerbPause, VerbResume}
|
return []string{VerbCurrent, VerbPause, VerbResume, VerbDrop}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptSubjectDelivery is where delivery is sent.
|
// AcceptSubjectDelivery is where delivery is sent.
|
||||||
@@ -117,6 +118,41 @@ func DecodePausesByPausedNodeValue(raw []byte) (PausesByPausedNodeValue, error)
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PausesByDroppedIDKey is the key of one value of the state pauses under the form "dropped.<id>".
|
||||||
|
func PausesByDroppedIDKey(id string) string { return "dropped." + id }
|
||||||
|
|
||||||
|
// ParsePausesByDroppedIDKey reads the parts of a key of the form "dropped.<id>", in the order of the form; the last result is false for a key of another form.
|
||||||
|
func ParsePausesByDroppedIDKey(key string) (string, bool) {
|
||||||
|
rest := key
|
||||||
|
if !strings.HasPrefix(rest, "dropped.") {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
rest = rest[8:]
|
||||||
|
if rest == "" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
v1 := rest
|
||||||
|
rest = ""
|
||||||
|
if rest != "" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return v1, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecodePausesByDroppedIDValue reads one value of the state pauses under the form "dropped.<id>", refusing a field PausesByDroppedIDValue does not know and any text after the value.
|
||||||
|
func DecodePausesByDroppedIDValue(raw []byte) (PausesByDroppedIDValue, error) {
|
||||||
|
var v PausesByDroppedIDValue
|
||||||
|
dec := json.NewDecoder(bytes.NewReader(raw))
|
||||||
|
dec.DisallowUnknownFields()
|
||||||
|
if err := dec.Decode(&v); err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
if dec.More() {
|
||||||
|
return v, errors.New("text after the value")
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
// PausesByCapacityNodeKey is the key of one value of the state pauses under the form "capacity.<node>".
|
// PausesByCapacityNodeKey is the key of one value of the state pauses under the form "capacity.<node>".
|
||||||
func PausesByCapacityNodeKey(node string) string { return "capacity." + node }
|
func PausesByCapacityNodeKey(node string) string { return "capacity." + node }
|
||||||
|
|
||||||
@@ -245,6 +281,16 @@ type ComposeAnswer struct {
|
|||||||
Verdict any `json:"verdict,omitempty"`
|
Verdict any `json:"verdict,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop is an ask a caller no longer waits for.
|
||||||
|
type Drop struct {
|
||||||
|
// when (RFC 3339 time)
|
||||||
|
At *time.Time `json:"at,omitempty"`
|
||||||
|
By string `json:"by,omitempty"`
|
||||||
|
// the layout version
|
||||||
|
V int64 `json:"v,omitempty"`
|
||||||
|
Why string `json:"why"`
|
||||||
|
}
|
||||||
|
|
||||||
// FetchBesideItem is a type of the contract.
|
// FetchBesideItem is a type of the contract.
|
||||||
type FetchBesideItem struct {
|
type FetchBesideItem struct {
|
||||||
Commit string `json:"commit"`
|
Commit string `json:"commit"`
|
||||||
@@ -433,19 +479,25 @@ type RunProgram struct {
|
|||||||
|
|
||||||
// Step is one step a build module runs on a node.
|
// Step is one step a build module runs on a node.
|
||||||
type Step struct {
|
type Step struct {
|
||||||
|
// when the bus gives the ask again, for the state again (RFC 3339 time)
|
||||||
|
AgainAt *time.Time `json:"again-at,omitempty"`
|
||||||
// when (RFC 3339 time)
|
// when (RFC 3339 time)
|
||||||
Ended *time.Time `json:"ended,omitempty"`
|
Ended *time.Time `json:"ended,omitempty"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Node string `json:"node"`
|
Node string `json:"node"`
|
||||||
Owner string `json:"owner,omitempty"`
|
Owner string `json:"owner,omitempty"`
|
||||||
Phase string `json:"phase,omitempty"`
|
// true when the step ended on a fault that passes (a transport fault), so a failed end after the last run says so
|
||||||
|
Passing bool `json:"passing,omitempty"`
|
||||||
|
Phase string `json:"phase,omitempty"`
|
||||||
// when (RFC 3339 time)
|
// when (RFC 3339 time)
|
||||||
PhaseAt *time.Time `json:"phase-at,omitempty"`
|
PhaseAt *time.Time `json:"phase-at,omitempty"`
|
||||||
Reason string `json:"reason,omitempty"`
|
Reason string `json:"reason,omitempty"`
|
||||||
Result *StepResult `json:"result,omitempty"`
|
Result *StepResult `json:"result,omitempty"`
|
||||||
|
// which run of the ask this is, counted by the bus's delivery count (1 for the first)
|
||||||
|
Run int64 `json:"run,omitempty"`
|
||||||
// when (RFC 3339 time)
|
// when (RFC 3339 time)
|
||||||
Started time.Time `json:"started"`
|
Started time.Time `json:"started"`
|
||||||
// running, passed, failed or refused
|
// running, again (ended on a transport fault, to be given again by the bus after again-at), passed, failed, refused or dropped (ended by the verb drop, its cause the reason)
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Tool string `json:"tool"`
|
Tool string `json:"tool"`
|
||||||
// the layout version
|
// the layout version
|
||||||
@@ -485,7 +537,7 @@ type StepAskCompose struct {
|
|||||||
Fetch Fetch `json:"fetch"`
|
Fetch Fetch `json:"fetch"`
|
||||||
Package string `json:"package"`
|
Package string `json:"package"`
|
||||||
Reader string `json:"reader,omitempty"`
|
Reader string `json:"reader,omitempty"`
|
||||||
// the compose-candidate request
|
// the compose-candidate request, in one of two forms: the request as a JSON object, or, for one near the bus's message limit, a JSON string "gzip+base64:" followed by the base64 of the request object gzip-compressed; a holder that does not know the packed form refuses it, naming that it holds no request object
|
||||||
Request any `json:"request"`
|
Request any `json:"request"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,6 +640,19 @@ type ResumeInput struct {
|
|||||||
// ResumeAnswer is what resume answers.
|
// ResumeAnswer is what resume answers.
|
||||||
type ResumeAnswer = map[string]any
|
type ResumeAnswer = map[string]any
|
||||||
|
|
||||||
|
// DropInput is what drop takes.
|
||||||
|
type DropInput struct {
|
||||||
|
// who drops it
|
||||||
|
By string `json:"by,omitempty"`
|
||||||
|
// the ask's id
|
||||||
|
ID string `json:"id"`
|
||||||
|
// why the caller no longer waits
|
||||||
|
Why string `json:"why"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DropAnswer is what drop answers.
|
||||||
|
type DropAnswer = map[string]any
|
||||||
|
|
||||||
// DeliveryAccept is the body of delivery.
|
// DeliveryAccept is the body of delivery.
|
||||||
type DeliveryAccept = StepAsk
|
type DeliveryAccept = StepAsk
|
||||||
|
|
||||||
@@ -603,6 +668,9 @@ type StepsByNodeIDValue = Step
|
|||||||
// PausesByPausedNodeValue is one value of the state pauses under the key paused.<node>.
|
// PausesByPausedNodeValue is one value of the state pauses under the key paused.<node>.
|
||||||
type PausesByPausedNodeValue = Pause
|
type PausesByPausedNodeValue = Pause
|
||||||
|
|
||||||
|
// PausesByDroppedIDValue is one value of the state pauses under the key dropped.<id>.
|
||||||
|
type PausesByDroppedIDValue = Drop
|
||||||
|
|
||||||
// PausesByCapacityNodeValue is one value of the state pauses under the key capacity.<node>.
|
// PausesByCapacityNodeValue is one value of the state pauses under the key capacity.<node>.
|
||||||
type PausesByCapacityNodeValue = Capacity
|
type PausesByCapacityNodeValue = Capacity
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ func TestFixtures(t *testing.T) {
|
|||||||
decode: func(b []byte) (any, error) { var v CheckAccept; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.node-build-go\\.accept\\.check$")},
|
decode: func(b []byte) (any, error) { var v CheckAccept; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.node-build-go\\.accept\\.check$")},
|
||||||
{name: "a finished run step whose program exited non-zero", subject: "", given: "{\"ended\":\"2026-11-05T10:01:00Z\",\"id\":\"r5e6\",\"node\":\"ace\",\"result\":{\"built\":true,\"exit\":2,\"key\":\"program-0123456789abcdef\",\"said\":\"the facts name no head\"},\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"failed\",\"tool\":\"check\",\"v\":1}", wire: "{\"ended\":\"2026-11-05T10:01:00Z\",\"id\":\"r5e6\",\"node\":\"ace\",\"result\":{\"built\":true,\"exit\":2,\"key\":\"program-0123456789abcdef\",\"said\":\"the facts name no head\"},\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"failed\",\"tool\":\"check\",\"v\":1}",
|
{name: "a finished run step whose program exited non-zero", subject: "", given: "{\"ended\":\"2026-11-05T10:01:00Z\",\"id\":\"r5e6\",\"node\":\"ace\",\"result\":{\"built\":true,\"exit\":2,\"key\":\"program-0123456789abcdef\",\"said\":\"the facts name no head\"},\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"failed\",\"tool\":\"check\",\"v\":1}", wire: "{\"ended\":\"2026-11-05T10:01:00Z\",\"id\":\"r5e6\",\"node\":\"ace\",\"result\":{\"built\":true,\"exit\":2,\"key\":\"program-0123456789abcdef\",\"said\":\"the facts name no head\"},\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"failed\",\"tool\":\"check\",\"v\":1}",
|
||||||
decode: func(b []byte) (any, error) { var v StepsByNodeIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
decode: func(b []byte) (any, error) { var v StepsByNodeIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
|
{name: "a step ended on a transport fault, given again by the bus", subject: "", given: "{\"again-at\":\"2026-11-05T10:01:30Z\",\"ended\":\"2026-11-05T10:00:30Z\",\"id\":\"a1b2\",\"node\":\"ace\",\"passing\":true,\"reason\":\"fetching the commit: kex_exchange_identification: read: Connection reset by peer\",\"run\":1,\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"again\",\"tool\":\"build\",\"v\":1}", wire: "{\"again-at\":\"2026-11-05T10:01:30Z\",\"ended\":\"2026-11-05T10:00:30Z\",\"id\":\"a1b2\",\"node\":\"ace\",\"passing\":true,\"reason\":\"fetching the commit: kex_exchange_identification: read: Connection reset by peer\",\"run\":1,\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"again\",\"tool\":\"build\",\"v\":1}",
|
||||||
|
decode: func(b []byte) (any, error) { var v StepsByNodeIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
|
{name: "an ask dropped by the caller that no longer waits", subject: "", given: "{\"at\":\"2026-11-05T10:00:00Z\",\"by\":\"mesh-delivery-builder\",\"v\":1,\"why\":\"a newer fingerprint supersedes it\"}", wire: "{\"at\":\"2026-11-05T10:00:00Z\",\"by\":\"mesh-delivery-builder\",\"v\":1,\"why\":\"a newer fingerprint supersedes it\"}",
|
||||||
|
decode: func(b []byte) (any, error) { var v PausesByDroppedIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
|
{name: "drop names the ask and why", subject: "", given: "{\"by\":\"mesh-delivery-builder\",\"id\":\"a1b2\",\"why\":\"a newer fingerprint supersedes it\"}", wire: "{\"by\":\"mesh-delivery-builder\",\"id\":\"a1b2\",\"why\":\"a newer fingerprint supersedes it\"}",
|
||||||
|
decode: func(b []byte) (any, error) { var v DropInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
v, err := c.decode([]byte(c.given))
|
v, err := c.decode([]byte(c.given))
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const (
|
|||||||
VerbCurrent = "current"
|
VerbCurrent = "current"
|
||||||
VerbPause = "pause"
|
VerbPause = "pause"
|
||||||
VerbResume = "resume"
|
VerbResume = "resume"
|
||||||
|
VerbDrop = "drop"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -28,7 +29,7 @@ const (
|
|||||||
|
|
||||||
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
|
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
|
||||||
func Verbs() []string {
|
func Verbs() []string {
|
||||||
return []string{VerbCurrent, VerbPause, VerbResume}
|
return []string{VerbCurrent, VerbPause, VerbResume, VerbDrop}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptSubjectDelivery is where delivery is sent.
|
// AcceptSubjectDelivery is where delivery is sent.
|
||||||
@@ -117,6 +118,41 @@ func DecodePausesByPausedNodeValue(raw []byte) (PausesByPausedNodeValue, error)
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PausesByDroppedIDKey is the key of one value of the state pauses under the form "dropped.<id>".
|
||||||
|
func PausesByDroppedIDKey(id string) string { return "dropped." + id }
|
||||||
|
|
||||||
|
// ParsePausesByDroppedIDKey reads the parts of a key of the form "dropped.<id>", in the order of the form; the last result is false for a key of another form.
|
||||||
|
func ParsePausesByDroppedIDKey(key string) (string, bool) {
|
||||||
|
rest := key
|
||||||
|
if !strings.HasPrefix(rest, "dropped.") {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
rest = rest[8:]
|
||||||
|
if rest == "" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
v1 := rest
|
||||||
|
rest = ""
|
||||||
|
if rest != "" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return v1, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecodePausesByDroppedIDValue reads one value of the state pauses under the form "dropped.<id>", refusing a field PausesByDroppedIDValue does not know and any text after the value.
|
||||||
|
func DecodePausesByDroppedIDValue(raw []byte) (PausesByDroppedIDValue, error) {
|
||||||
|
var v PausesByDroppedIDValue
|
||||||
|
dec := json.NewDecoder(bytes.NewReader(raw))
|
||||||
|
dec.DisallowUnknownFields()
|
||||||
|
if err := dec.Decode(&v); err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
if dec.More() {
|
||||||
|
return v, errors.New("text after the value")
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
// PausesByCapacityNodeKey is the key of one value of the state pauses under the form "capacity.<node>".
|
// PausesByCapacityNodeKey is the key of one value of the state pauses under the form "capacity.<node>".
|
||||||
func PausesByCapacityNodeKey(node string) string { return "capacity." + node }
|
func PausesByCapacityNodeKey(node string) string { return "capacity." + node }
|
||||||
|
|
||||||
@@ -245,6 +281,16 @@ type ComposeAnswer struct {
|
|||||||
Verdict any `json:"verdict,omitempty"`
|
Verdict any `json:"verdict,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop is an ask a caller no longer waits for.
|
||||||
|
type Drop struct {
|
||||||
|
// when (RFC 3339 time)
|
||||||
|
At *time.Time `json:"at,omitempty"`
|
||||||
|
By string `json:"by,omitempty"`
|
||||||
|
// the layout version
|
||||||
|
V int64 `json:"v,omitempty"`
|
||||||
|
Why string `json:"why"`
|
||||||
|
}
|
||||||
|
|
||||||
// FetchBesideItem is a type of the contract.
|
// FetchBesideItem is a type of the contract.
|
||||||
type FetchBesideItem struct {
|
type FetchBesideItem struct {
|
||||||
Commit string `json:"commit"`
|
Commit string `json:"commit"`
|
||||||
@@ -433,19 +479,25 @@ type RunProgram struct {
|
|||||||
|
|
||||||
// Step is one step a build module runs on a node.
|
// Step is one step a build module runs on a node.
|
||||||
type Step struct {
|
type Step struct {
|
||||||
|
// when the bus gives the ask again, for the state again (RFC 3339 time)
|
||||||
|
AgainAt *time.Time `json:"again-at,omitempty"`
|
||||||
// when (RFC 3339 time)
|
// when (RFC 3339 time)
|
||||||
Ended *time.Time `json:"ended,omitempty"`
|
Ended *time.Time `json:"ended,omitempty"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Node string `json:"node"`
|
Node string `json:"node"`
|
||||||
Owner string `json:"owner,omitempty"`
|
Owner string `json:"owner,omitempty"`
|
||||||
Phase string `json:"phase,omitempty"`
|
// true when the step ended on a fault that passes (a transport fault), so a failed end after the last run says so
|
||||||
|
Passing bool `json:"passing,omitempty"`
|
||||||
|
Phase string `json:"phase,omitempty"`
|
||||||
// when (RFC 3339 time)
|
// when (RFC 3339 time)
|
||||||
PhaseAt *time.Time `json:"phase-at,omitempty"`
|
PhaseAt *time.Time `json:"phase-at,omitempty"`
|
||||||
Reason string `json:"reason,omitempty"`
|
Reason string `json:"reason,omitempty"`
|
||||||
Result *StepResult `json:"result,omitempty"`
|
Result *StepResult `json:"result,omitempty"`
|
||||||
|
// which run of the ask this is, counted by the bus's delivery count (1 for the first)
|
||||||
|
Run int64 `json:"run,omitempty"`
|
||||||
// when (RFC 3339 time)
|
// when (RFC 3339 time)
|
||||||
Started time.Time `json:"started"`
|
Started time.Time `json:"started"`
|
||||||
// running, passed, failed or refused
|
// running, again (ended on a transport fault, to be given again by the bus after again-at), passed, failed, refused or dropped (ended by the verb drop, its cause the reason)
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Tool string `json:"tool"`
|
Tool string `json:"tool"`
|
||||||
// the layout version
|
// the layout version
|
||||||
@@ -485,7 +537,7 @@ type StepAskCompose struct {
|
|||||||
Fetch Fetch `json:"fetch"`
|
Fetch Fetch `json:"fetch"`
|
||||||
Package string `json:"package"`
|
Package string `json:"package"`
|
||||||
Reader string `json:"reader,omitempty"`
|
Reader string `json:"reader,omitempty"`
|
||||||
// the compose-candidate request
|
// the compose-candidate request, in one of two forms: the request as a JSON object, or, for one near the bus's message limit, a JSON string "gzip+base64:" followed by the base64 of the request object gzip-compressed; a holder that does not know the packed form refuses it, naming that it holds no request object
|
||||||
Request any `json:"request"`
|
Request any `json:"request"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,6 +640,19 @@ type ResumeInput struct {
|
|||||||
// ResumeAnswer is what resume answers.
|
// ResumeAnswer is what resume answers.
|
||||||
type ResumeAnswer = map[string]any
|
type ResumeAnswer = map[string]any
|
||||||
|
|
||||||
|
// DropInput is what drop takes.
|
||||||
|
type DropInput struct {
|
||||||
|
// who drops it
|
||||||
|
By string `json:"by,omitempty"`
|
||||||
|
// the ask's id
|
||||||
|
ID string `json:"id"`
|
||||||
|
// why the caller no longer waits
|
||||||
|
Why string `json:"why"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DropAnswer is what drop answers.
|
||||||
|
type DropAnswer = map[string]any
|
||||||
|
|
||||||
// DeliveryAccept is the body of delivery.
|
// DeliveryAccept is the body of delivery.
|
||||||
type DeliveryAccept = StepAsk
|
type DeliveryAccept = StepAsk
|
||||||
|
|
||||||
@@ -603,6 +668,9 @@ type StepsByNodeIDValue = Step
|
|||||||
// PausesByPausedNodeValue is one value of the state pauses under the key paused.<node>.
|
// PausesByPausedNodeValue is one value of the state pauses under the key paused.<node>.
|
||||||
type PausesByPausedNodeValue = Pause
|
type PausesByPausedNodeValue = Pause
|
||||||
|
|
||||||
|
// PausesByDroppedIDValue is one value of the state pauses under the key dropped.<id>.
|
||||||
|
type PausesByDroppedIDValue = Drop
|
||||||
|
|
||||||
// PausesByCapacityNodeValue is one value of the state pauses under the key capacity.<node>.
|
// PausesByCapacityNodeValue is one value of the state pauses under the key capacity.<node>.
|
||||||
type PausesByCapacityNodeValue = Capacity
|
type PausesByCapacityNodeValue = Capacity
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ func TestFixtures(t *testing.T) {
|
|||||||
}, subjectIs: nil},
|
}, subjectIs: nil},
|
||||||
{name: "a build ask", subject: "mesh.seat.node-build-image.accept.delivery", given: "{\"asker\":\"mesh-delivery-builder\",\"build\":{\"artifacts\":[{\"artifact\":\"go\"}],\"module\":\"nats\"},\"id\":\"a1b2\",\"kind\":\"build\",\"language\":\"go\"}", wire: "{\"asker\":\"mesh-delivery-builder\",\"build\":{\"artifacts\":[{\"artifact\":\"go\"}],\"module\":\"nats\"},\"id\":\"a1b2\",\"kind\":\"build\",\"language\":\"go\"}",
|
{name: "a build ask", subject: "mesh.seat.node-build-image.accept.delivery", given: "{\"asker\":\"mesh-delivery-builder\",\"build\":{\"artifacts\":[{\"artifact\":\"go\"}],\"module\":\"nats\"},\"id\":\"a1b2\",\"kind\":\"build\",\"language\":\"go\"}", wire: "{\"asker\":\"mesh-delivery-builder\",\"build\":{\"artifacts\":[{\"artifact\":\"go\"}],\"module\":\"nats\"},\"id\":\"a1b2\",\"kind\":\"build\",\"language\":\"go\"}",
|
||||||
decode: func(b []byte) (any, error) { var v DeliveryAccept; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.node-build-image\\.accept\\.delivery$")},
|
decode: func(b []byte) (any, error) { var v DeliveryAccept; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.node-build-image\\.accept\\.delivery$")},
|
||||||
|
{name: "a step ended on a transport fault, given again by the bus", subject: "", given: "{\"again-at\":\"2026-11-05T10:01:30Z\",\"ended\":\"2026-11-05T10:00:30Z\",\"id\":\"a1b2\",\"node\":\"ace\",\"passing\":true,\"reason\":\"fetching the commit: kex_exchange_identification: read: Connection reset by peer\",\"run\":1,\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"again\",\"tool\":\"build\",\"v\":1}", wire: "{\"again-at\":\"2026-11-05T10:01:30Z\",\"ended\":\"2026-11-05T10:00:30Z\",\"id\":\"a1b2\",\"node\":\"ace\",\"passing\":true,\"reason\":\"fetching the commit: kex_exchange_identification: read: Connection reset by peer\",\"run\":1,\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"again\",\"tool\":\"build\",\"v\":1}",
|
||||||
|
decode: func(b []byte) (any, error) { var v StepsByNodeIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
|
{name: "an ask dropped by the caller that no longer waits", subject: "", given: "{\"at\":\"2026-11-05T10:00:00Z\",\"by\":\"mesh-delivery-builder\",\"v\":1,\"why\":\"a newer fingerprint supersedes it\"}", wire: "{\"at\":\"2026-11-05T10:00:00Z\",\"by\":\"mesh-delivery-builder\",\"v\":1,\"why\":\"a newer fingerprint supersedes it\"}",
|
||||||
|
decode: func(b []byte) (any, error) { var v PausesByDroppedIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
|
{name: "drop names the ask and why", subject: "", given: "{\"by\":\"mesh-delivery-builder\",\"id\":\"a1b2\",\"why\":\"a newer fingerprint supersedes it\"}", wire: "{\"by\":\"mesh-delivery-builder\",\"id\":\"a1b2\",\"why\":\"a newer fingerprint supersedes it\"}",
|
||||||
|
decode: func(b []byte) (any, error) { var v DropInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
v, err := c.decode([]byte(c.given))
|
v, err := c.decode([]byte(c.given))
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const (
|
|||||||
VerbCurrent = "current"
|
VerbCurrent = "current"
|
||||||
VerbPause = "pause"
|
VerbPause = "pause"
|
||||||
VerbResume = "resume"
|
VerbResume = "resume"
|
||||||
|
VerbDrop = "drop"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -28,7 +29,7 @@ const (
|
|||||||
|
|
||||||
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
|
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
|
||||||
func Verbs() []string {
|
func Verbs() []string {
|
||||||
return []string{VerbCurrent, VerbPause, VerbResume}
|
return []string{VerbCurrent, VerbPause, VerbResume, VerbDrop}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptSubjectDelivery is where delivery is sent.
|
// AcceptSubjectDelivery is where delivery is sent.
|
||||||
@@ -117,6 +118,41 @@ func DecodePausesByPausedNodeValue(raw []byte) (PausesByPausedNodeValue, error)
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PausesByDroppedIDKey is the key of one value of the state pauses under the form "dropped.<id>".
|
||||||
|
func PausesByDroppedIDKey(id string) string { return "dropped." + id }
|
||||||
|
|
||||||
|
// ParsePausesByDroppedIDKey reads the parts of a key of the form "dropped.<id>", in the order of the form; the last result is false for a key of another form.
|
||||||
|
func ParsePausesByDroppedIDKey(key string) (string, bool) {
|
||||||
|
rest := key
|
||||||
|
if !strings.HasPrefix(rest, "dropped.") {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
rest = rest[8:]
|
||||||
|
if rest == "" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
v1 := rest
|
||||||
|
rest = ""
|
||||||
|
if rest != "" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return v1, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecodePausesByDroppedIDValue reads one value of the state pauses under the form "dropped.<id>", refusing a field PausesByDroppedIDValue does not know and any text after the value.
|
||||||
|
func DecodePausesByDroppedIDValue(raw []byte) (PausesByDroppedIDValue, error) {
|
||||||
|
var v PausesByDroppedIDValue
|
||||||
|
dec := json.NewDecoder(bytes.NewReader(raw))
|
||||||
|
dec.DisallowUnknownFields()
|
||||||
|
if err := dec.Decode(&v); err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
if dec.More() {
|
||||||
|
return v, errors.New("text after the value")
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
// PausesByCapacityNodeKey is the key of one value of the state pauses under the form "capacity.<node>".
|
// PausesByCapacityNodeKey is the key of one value of the state pauses under the form "capacity.<node>".
|
||||||
func PausesByCapacityNodeKey(node string) string { return "capacity." + node }
|
func PausesByCapacityNodeKey(node string) string { return "capacity." + node }
|
||||||
|
|
||||||
@@ -245,6 +281,16 @@ type ComposeAnswer struct {
|
|||||||
Verdict any `json:"verdict,omitempty"`
|
Verdict any `json:"verdict,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop is an ask a caller no longer waits for.
|
||||||
|
type Drop struct {
|
||||||
|
// when (RFC 3339 time)
|
||||||
|
At *time.Time `json:"at,omitempty"`
|
||||||
|
By string `json:"by,omitempty"`
|
||||||
|
// the layout version
|
||||||
|
V int64 `json:"v,omitempty"`
|
||||||
|
Why string `json:"why"`
|
||||||
|
}
|
||||||
|
|
||||||
// FetchBesideItem is a type of the contract.
|
// FetchBesideItem is a type of the contract.
|
||||||
type FetchBesideItem struct {
|
type FetchBesideItem struct {
|
||||||
Commit string `json:"commit"`
|
Commit string `json:"commit"`
|
||||||
@@ -433,19 +479,25 @@ type RunProgram struct {
|
|||||||
|
|
||||||
// Step is one step a build module runs on a node.
|
// Step is one step a build module runs on a node.
|
||||||
type Step struct {
|
type Step struct {
|
||||||
|
// when the bus gives the ask again, for the state again (RFC 3339 time)
|
||||||
|
AgainAt *time.Time `json:"again-at,omitempty"`
|
||||||
// when (RFC 3339 time)
|
// when (RFC 3339 time)
|
||||||
Ended *time.Time `json:"ended,omitempty"`
|
Ended *time.Time `json:"ended,omitempty"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Node string `json:"node"`
|
Node string `json:"node"`
|
||||||
Owner string `json:"owner,omitempty"`
|
Owner string `json:"owner,omitempty"`
|
||||||
Phase string `json:"phase,omitempty"`
|
// true when the step ended on a fault that passes (a transport fault), so a failed end after the last run says so
|
||||||
|
Passing bool `json:"passing,omitempty"`
|
||||||
|
Phase string `json:"phase,omitempty"`
|
||||||
// when (RFC 3339 time)
|
// when (RFC 3339 time)
|
||||||
PhaseAt *time.Time `json:"phase-at,omitempty"`
|
PhaseAt *time.Time `json:"phase-at,omitempty"`
|
||||||
Reason string `json:"reason,omitempty"`
|
Reason string `json:"reason,omitempty"`
|
||||||
Result *StepResult `json:"result,omitempty"`
|
Result *StepResult `json:"result,omitempty"`
|
||||||
|
// which run of the ask this is, counted by the bus's delivery count (1 for the first)
|
||||||
|
Run int64 `json:"run,omitempty"`
|
||||||
// when (RFC 3339 time)
|
// when (RFC 3339 time)
|
||||||
Started time.Time `json:"started"`
|
Started time.Time `json:"started"`
|
||||||
// running, passed, failed or refused
|
// running, again (ended on a transport fault, to be given again by the bus after again-at), passed, failed, refused or dropped (ended by the verb drop, its cause the reason)
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Tool string `json:"tool"`
|
Tool string `json:"tool"`
|
||||||
// the layout version
|
// the layout version
|
||||||
@@ -485,7 +537,7 @@ type StepAskCompose struct {
|
|||||||
Fetch Fetch `json:"fetch"`
|
Fetch Fetch `json:"fetch"`
|
||||||
Package string `json:"package"`
|
Package string `json:"package"`
|
||||||
Reader string `json:"reader,omitempty"`
|
Reader string `json:"reader,omitempty"`
|
||||||
// the compose-candidate request
|
// the compose-candidate request, in one of two forms: the request as a JSON object, or, for one near the bus's message limit, a JSON string "gzip+base64:" followed by the base64 of the request object gzip-compressed; a holder that does not know the packed form refuses it, naming that it holds no request object
|
||||||
Request any `json:"request"`
|
Request any `json:"request"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,6 +640,19 @@ type ResumeInput struct {
|
|||||||
// ResumeAnswer is what resume answers.
|
// ResumeAnswer is what resume answers.
|
||||||
type ResumeAnswer = map[string]any
|
type ResumeAnswer = map[string]any
|
||||||
|
|
||||||
|
// DropInput is what drop takes.
|
||||||
|
type DropInput struct {
|
||||||
|
// who drops it
|
||||||
|
By string `json:"by,omitempty"`
|
||||||
|
// the ask's id
|
||||||
|
ID string `json:"id"`
|
||||||
|
// why the caller no longer waits
|
||||||
|
Why string `json:"why"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DropAnswer is what drop answers.
|
||||||
|
type DropAnswer = map[string]any
|
||||||
|
|
||||||
// DeliveryAccept is the body of delivery.
|
// DeliveryAccept is the body of delivery.
|
||||||
type DeliveryAccept = StepAsk
|
type DeliveryAccept = StepAsk
|
||||||
|
|
||||||
@@ -603,6 +668,9 @@ type StepsByNodeIDValue = Step
|
|||||||
// PausesByPausedNodeValue is one value of the state pauses under the key paused.<node>.
|
// PausesByPausedNodeValue is one value of the state pauses under the key paused.<node>.
|
||||||
type PausesByPausedNodeValue = Pause
|
type PausesByPausedNodeValue = Pause
|
||||||
|
|
||||||
|
// PausesByDroppedIDValue is one value of the state pauses under the key dropped.<id>.
|
||||||
|
type PausesByDroppedIDValue = Drop
|
||||||
|
|
||||||
// PausesByCapacityNodeValue is one value of the state pauses under the key capacity.<node>.
|
// PausesByCapacityNodeValue is one value of the state pauses under the key capacity.<node>.
|
||||||
type PausesByCapacityNodeValue = Capacity
|
type PausesByCapacityNodeValue = Capacity
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ func TestFixtures(t *testing.T) {
|
|||||||
decode: func(b []byte) (any, error) { var v CheckAccept; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.node-build-node\\.accept\\.check$")},
|
decode: func(b []byte) (any, error) { var v CheckAccept; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.node-build-node\\.accept\\.check$")},
|
||||||
{name: "a finished check step of a TypeScript merge preview", subject: "", given: "{\"ended\":\"2026-11-05T10:01:00Z\",\"id\":\"c3d6\",\"node\":\"ace\",\"result\":{\"fetch\":{\"base\":\"abcdef0123456789abcdef0123456789abcdef01\",\"changed\":[\"modules/m/package.json\"],\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"merge\":\"0123456789abcdef0123456789abcdef01234567\",\"modules\":[\"modules/m\"],\"trees\":{\"modules/m\":{\"manifest\":\"0581b699d9d05517e69b21f5cedbeb2eee8aba2b205280b561be731594d7feef\",\"tree\":\"0123456789abcdef0123456789abcdef01234567\"}},\"workspace\":\"mvii1sxt979f67\"}},\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"passed\",\"tool\":\"check\",\"v\":1}", wire: "{\"ended\":\"2026-11-05T10:01:00Z\",\"id\":\"c3d6\",\"node\":\"ace\",\"result\":{\"fetch\":{\"base\":\"abcdef0123456789abcdef0123456789abcdef01\",\"changed\":[\"modules/m/package.json\"],\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"merge\":\"0123456789abcdef0123456789abcdef01234567\",\"modules\":[\"modules/m\"],\"trees\":{\"modules/m\":{\"manifest\":\"0581b699d9d05517e69b21f5cedbeb2eee8aba2b205280b561be731594d7feef\",\"tree\":\"0123456789abcdef0123456789abcdef01234567\"}},\"workspace\":\"mvii1sxt979f67\"}},\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"passed\",\"tool\":\"check\",\"v\":1}",
|
{name: "a finished check step of a TypeScript merge preview", subject: "", given: "{\"ended\":\"2026-11-05T10:01:00Z\",\"id\":\"c3d6\",\"node\":\"ace\",\"result\":{\"fetch\":{\"base\":\"abcdef0123456789abcdef0123456789abcdef01\",\"changed\":[\"modules/m/package.json\"],\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"merge\":\"0123456789abcdef0123456789abcdef01234567\",\"modules\":[\"modules/m\"],\"trees\":{\"modules/m\":{\"manifest\":\"0581b699d9d05517e69b21f5cedbeb2eee8aba2b205280b561be731594d7feef\",\"tree\":\"0123456789abcdef0123456789abcdef01234567\"}},\"workspace\":\"mvii1sxt979f67\"}},\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"passed\",\"tool\":\"check\",\"v\":1}", wire: "{\"ended\":\"2026-11-05T10:01:00Z\",\"id\":\"c3d6\",\"node\":\"ace\",\"result\":{\"fetch\":{\"base\":\"abcdef0123456789abcdef0123456789abcdef01\",\"changed\":[\"modules/m/package.json\"],\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"merge\":\"0123456789abcdef0123456789abcdef01234567\",\"modules\":[\"modules/m\"],\"trees\":{\"modules/m\":{\"manifest\":\"0581b699d9d05517e69b21f5cedbeb2eee8aba2b205280b561be731594d7feef\",\"tree\":\"0123456789abcdef0123456789abcdef01234567\"}},\"workspace\":\"mvii1sxt979f67\"}},\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"passed\",\"tool\":\"check\",\"v\":1}",
|
||||||
decode: func(b []byte) (any, error) { var v StepsByNodeIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
decode: func(b []byte) (any, error) { var v StepsByNodeIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
|
{name: "a step ended on a transport fault, given again by the bus", subject: "", given: "{\"again-at\":\"2026-11-05T10:01:30Z\",\"ended\":\"2026-11-05T10:00:30Z\",\"id\":\"a1b2\",\"node\":\"ace\",\"passing\":true,\"reason\":\"fetching the commit: kex_exchange_identification: read: Connection reset by peer\",\"run\":1,\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"again\",\"tool\":\"build\",\"v\":1}", wire: "{\"again-at\":\"2026-11-05T10:01:30Z\",\"ended\":\"2026-11-05T10:00:30Z\",\"id\":\"a1b2\",\"node\":\"ace\",\"passing\":true,\"reason\":\"fetching the commit: kex_exchange_identification: read: Connection reset by peer\",\"run\":1,\"started\":\"2026-11-05T10:00:00Z\",\"state\":\"again\",\"tool\":\"build\",\"v\":1}",
|
||||||
|
decode: func(b []byte) (any, error) { var v StepsByNodeIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
|
{name: "an ask dropped by the caller that no longer waits", subject: "", given: "{\"at\":\"2026-11-05T10:00:00Z\",\"by\":\"mesh-delivery-builder\",\"v\":1,\"why\":\"a newer fingerprint supersedes it\"}", wire: "{\"at\":\"2026-11-05T10:00:00Z\",\"by\":\"mesh-delivery-builder\",\"v\":1,\"why\":\"a newer fingerprint supersedes it\"}",
|
||||||
|
decode: func(b []byte) (any, error) { var v PausesByDroppedIDValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
|
{name: "drop names the ask and why", subject: "", given: "{\"by\":\"mesh-delivery-builder\",\"id\":\"a1b2\",\"why\":\"a newer fingerprint supersedes it\"}", wire: "{\"by\":\"mesh-delivery-builder\",\"id\":\"a1b2\",\"why\":\"a newer fingerprint supersedes it\"}",
|
||||||
|
decode: func(b []byte) (any, error) { var v DropInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
v, err := c.decode([]byte(c.given))
|
v, err := c.decode([]byte(c.given))
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"format": 1,
|
|
||||||
"seat": "git",
|
|
||||||
"scope": "mesh",
|
|
||||||
"grain": "seat-list",
|
|
||||||
"domain": "Delivery",
|
|
||||||
"decision": "novox/hq ADR 0111",
|
|
||||||
"delivers": "git"
|
|
||||||
}
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"name": "a manifest (xclip, read through mesh-catalog.module)",
|
|
||||||
"of": "state:manifests/<digest>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"module": "xclip",
|
|
||||||
"manifest": "{\"build\":{\"artifacts\":[{\"binary\":\"xclip-tools\",\"from\":\"cmd/xclip-tools\",\"kind\":\"bundle\",\"language\":\"go\",\"loads\":[\"xclip-tools\"],\"name\":\"tools\",\"system\":\"arch\"}]},\"capabilities\":[\"package-manager\"],\"module\":\"xclip\",\"resources\":[{\"id\":\"package\",\"package\":\"xclip\",\"type\":\"package\"}],\"tools\":[\"xclip_copy\",\"xclip_paste\",\"xclip_targets\",\"xclip_session\"],\"version\":\"1\"}"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a module (xclip, read through mesh-catalog.modules; the inputs and toolchains no tool reads are not here)",
|
|
||||||
"of": "state:modules/<module>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"repository": "novox/mesh-catalog",
|
|
||||||
"commit": "f469eb387a3015569d9b16c66ed418e9dd098f64",
|
|
||||||
"path": "modules/xclip",
|
|
||||||
"fp2": "src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a candidate",
|
|
||||||
"of": "state:candidates/<group>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"group": "feat/registry",
|
|
||||||
"base": 3,
|
|
||||||
"heads": "0123456789ab",
|
|
||||||
"pulls": [
|
|
||||||
{
|
|
||||||
"repository": "novox/mesh-sdk",
|
|
||||||
"number": 1,
|
|
||||||
"head": "cccccccccccccccccccccccccccccccccccccccc",
|
|
||||||
"modules": [
|
|
||||||
"nats"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a refused verdict (nats, read through the indexer's verdicts tool)",
|
|
||||||
"of": "state:verdicts/<digest>",
|
|
||||||
"given": {
|
|
||||||
"module": "nats",
|
|
||||||
"state": "refused",
|
|
||||||
"problems": [
|
|
||||||
"this is not a module manifest: a state is either a name or {name, history, ttl-seconds, per-machine, key-ttl}: json: unknown field \"read-only\" (read without state[2].read-only)"
|
|
||||||
],
|
|
||||||
"judge": "exe:661e6fb424d7ffea",
|
|
||||||
"at": "2026-11-04T18:51:12.614583047+01:00"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "the predefined list",
|
|
||||||
"of": "state:predefined/list",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"commit": "cccccccccccccccccccccccccccccccccccccccc",
|
|
||||||
"list": {
|
|
||||||
"streams": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a pull request's configuration",
|
|
||||||
"of": "state:config-candidates/<pull>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"pull": "novox/mesh-catalog#1",
|
|
||||||
"head": "cccccccccccccccccccccccccccccccccccccccc",
|
|
||||||
"declares": {
|
|
||||||
"nats": {
|
|
||||||
"limit": {
|
|
||||||
"kind": "setting",
|
|
||||||
"default": 1,
|
|
||||||
"why": "a bound"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a pull request's configuration state whose bounds are declared 0 (a zero is a bound, not none)",
|
|
||||||
"of": "state:config-candidates/<pull>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"pull": "novox/mesh-catalog#1",
|
|
||||||
"head": "cccccccccccccccccccccccccccccccccccccccc",
|
|
||||||
"declares": {
|
|
||||||
"nats": {
|
|
||||||
"limit": {
|
|
||||||
"kind": "setting",
|
|
||||||
"default": 0,
|
|
||||||
"why": "a bound",
|
|
||||||
"minimum": 0,
|
|
||||||
"maximum": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a published Go module",
|
|
||||||
"of": "state:packages/<module>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"module": "git.novox.be/novox/mesh-sdk/go",
|
|
||||||
"repository": "novox/mesh-sdk",
|
|
||||||
"commit": "cccccccccccccccccccccccccccccccccccccccc",
|
|
||||||
"packages": [
|
|
||||||
{
|
|
||||||
"package": "git.novox.be/novox/mesh-sdk/go/keys",
|
|
||||||
"digest": "ab"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a package series",
|
|
||||||
"of": "state:packages/<package>.<series>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"name": "go-keys",
|
|
||||||
"series": "0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a module with its toolchain",
|
|
||||||
"of": "state:modules/<module>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"repository": "novox/mesh-catalog",
|
|
||||||
"commit": "f469eb387a3015569d9b16c66ed418e9dd098f64",
|
|
||||||
"fp2": "src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56",
|
|
||||||
"toolchains": {
|
|
||||||
"go": {
|
|
||||||
"language": "go",
|
|
||||||
"version": "1.26.0",
|
|
||||||
"recipe": "1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "the modules verb (captured: the first three modules)",
|
|
||||||
"of": "verb:modules.answer",
|
|
||||||
"given": {
|
|
||||||
"modules": [
|
|
||||||
{
|
|
||||||
"commit": "f469eb387a3015569d9b16c66ed418e9dd098f64",
|
|
||||||
"fp": "src2:5e4a1b4ad4ea6175c05e4655ce58aeb957547149d4c9805eb27636efd50c1c87",
|
|
||||||
"module": "adwaita",
|
|
||||||
"path": "modules/adwaita",
|
|
||||||
"repository": "novox/mesh-catalog"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "b112adcecc41d18f54190cbd2fc864199b70c518",
|
|
||||||
"fp": "src2:7dd0db8e98224f46121a5ae05c0b9c5a430eff531a5120aa40b1a59237853a3f",
|
|
||||||
"module": "amqp-email-forwarder",
|
|
||||||
"path": ".",
|
|
||||||
"repository": "jschoubben/amqp-email-forwarder"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "dd458cb155f5f5fa3ed824a23728e444be5b156a",
|
|
||||||
"fp": "src2:a98f8152f0a837dd5ba883a15efaf110ba88100193157e4bdb1a93ba55209371",
|
|
||||||
"module": "artifact-store-tools",
|
|
||||||
"path": "modules/artifact-store-tools",
|
|
||||||
"repository": "novox/mesh-catalog"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "the module verb (captured: xclip)",
|
|
||||||
"of": "verb:module.answer",
|
|
||||||
"given": {
|
|
||||||
"module": {
|
|
||||||
"commit": "f469eb387a3015569d9b16c66ed418e9dd098f64",
|
|
||||||
"fp": "src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56",
|
|
||||||
"manifest": {
|
|
||||||
"build": {
|
|
||||||
"artifacts": [
|
|
||||||
{
|
|
||||||
"binary": "xclip-tools",
|
|
||||||
"from": "cmd/xclip-tools",
|
|
||||||
"kind": "bundle",
|
|
||||||
"language": "go",
|
|
||||||
"loads": [
|
|
||||||
"xclip-tools"
|
|
||||||
],
|
|
||||||
"name": "tools",
|
|
||||||
"system": "arch"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"capabilities": [
|
|
||||||
"package-manager"
|
|
||||||
],
|
|
||||||
"module": "xclip",
|
|
||||||
"resources": [
|
|
||||||
{
|
|
||||||
"id": "package",
|
|
||||||
"package": "xclip",
|
|
||||||
"type": "package"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tools": [
|
|
||||||
"xclip_copy",
|
|
||||||
"xclip_paste",
|
|
||||||
"xclip_targets",
|
|
||||||
"xclip_session"
|
|
||||||
],
|
|
||||||
"version": "1"
|
|
||||||
},
|
|
||||||
"module": "xclip",
|
|
||||||
"path": "modules/xclip",
|
|
||||||
"repository": "novox/mesh-catalog"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"name": "verdict on the checker's own family",
|
|
||||||
"of": "holder-event:verdict",
|
|
||||||
"subject": "mesh.stream.mesh-delivery-checker.event.verdict",
|
|
||||||
"given": {
|
|
||||||
"repository": "novox/mesh-contracts",
|
|
||||||
"pull": 3,
|
|
||||||
"head": "cccccccccccccccccccccccccccccccccccccccc",
|
|
||||||
"verdict": "fail",
|
|
||||||
"out-of-step": [
|
|
||||||
"go/seats/meshbroker/contract.go"
|
|
||||||
],
|
|
||||||
"series": [
|
|
||||||
{
|
|
||||||
"module": "mesh-contracts",
|
|
||||||
"artifact": "go",
|
|
||||||
"from": "0.1",
|
|
||||||
"to": "0.2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "tag-wanted on the checker's own family",
|
|
||||||
"of": "holder-event:tag-wanted",
|
|
||||||
"subject": "mesh.stream.mesh-delivery-checker.event.tag-wanted",
|
|
||||||
"given": {
|
|
||||||
"repository": "novox/mesh-sdk",
|
|
||||||
"pull": 170,
|
|
||||||
"head": "cccccccccccccccccccccccccccccccccccccccc",
|
|
||||||
"branch": "feat/registry",
|
|
||||||
"module": "mesh-sdk",
|
|
||||||
"package": "go",
|
|
||||||
"tag": "registry-1966"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "preview.written on the checker's stream",
|
|
||||||
"of": "holder-event:preview.written",
|
|
||||||
"subject": "mesh.stream.mesh-delivery-checker.event.preview.written",
|
|
||||||
"given": {}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,574 +0,0 @@
|
|||||||
{
|
|
||||||
"format": 1,
|
|
||||||
"seat": "mesh-delivery",
|
|
||||||
"scope": "mesh",
|
|
||||||
"grain": "whole",
|
|
||||||
"domain": "Delivery",
|
|
||||||
"decision": "novox/hq ADR 0239",
|
|
||||||
"verbs": [
|
|
||||||
{
|
|
||||||
"name": "deliveries",
|
|
||||||
"description": "Every delivery not final, and those that ended in the last day, one line each: its id (owner/repository@commit), its state, its group, what it waits for and since when. Narrowed by state, repository or group.",
|
|
||||||
"input": {
|
|
||||||
"properties": {
|
|
||||||
"all": {
|
|
||||||
"description": "\"true\": the final ones of the last thirty days too",
|
|
||||||
"enum": [
|
|
||||||
"true",
|
|
||||||
"false"
|
|
||||||
],
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"description": "a group's id (its branch name)",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"description": "owner/repository",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"state": {
|
|
||||||
"description": "one state, e.g. delivering or held",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what deliveries answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "times",
|
|
||||||
"description": "Removed in R6 (ADR 0539): refused by name, naming its replacement: the delivery view (nox-delivery): each machine's want and have, and since when",
|
|
||||||
"optional": true,
|
|
||||||
"input": {
|
|
||||||
"properties": {},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what times answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "show",
|
|
||||||
"description": "One delivery or group whole: its delivery plan (what it builds, what each machine receives, what is not an ordinary send), every transition with when and why, the machine steps of its walk, its group and its order.",
|
|
||||||
"input": {
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"description": "a delivery's id, or a group's",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what show answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "groups",
|
|
||||||
"description": "Every delivery group: its members in order, why each pair is ordered (declared, built by, version skew, engine before controller, by name), its composed check and its state, derived from its members.",
|
|
||||||
"input": {
|
|
||||||
"properties": {
|
|
||||||
"all": {
|
|
||||||
"description": "\"true\": the groups that ended too",
|
|
||||||
"enum": [
|
|
||||||
"true",
|
|
||||||
"false"
|
|
||||||
],
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what groups answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "what-if",
|
|
||||||
"description": "Removed in R6 (ADR 0539): refused by name, naming its replacement: the merge check's composition, which composes every machine a change touches",
|
|
||||||
"optional": true,
|
|
||||||
"input": {
|
|
||||||
"properties": {},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what what-if answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "checks",
|
|
||||||
"description": "What the mesh's checks said of a pull request's head or of one commit: each of the commit's mesh statuses (mesh/check, the one a main requires from R4e, hq's mesh/repo-check, mesh/delivery, …) with its state, description and when it was set; the merge check's full verdict as the controller said it — each layer's summary, the machine that ran it, when, its build id and its report; and whether the branch's protection would let it merge, every required status being success.",
|
|
||||||
"optional": true,
|
|
||||||
"input": {
|
|
||||||
"properties": {
|
|
||||||
"commit": {
|
|
||||||
"description": "a commit's sha, or the start of one, instead of a pull request",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"number": {
|
|
||||||
"description": "a pull request's number: its head is read",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"description": "owner/repository",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"repository"
|
|
||||||
],
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what checks answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "table",
|
|
||||||
"description": "The state table every delivery runs by: each transition with its guard, each state's bound and what healer H2 may do once it has passed; and the machine steps' table.",
|
|
||||||
"input": {
|
|
||||||
"properties": {},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what table answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stalled",
|
|
||||||
"description": "Every delivery held past its state's bound, with the transition the table lets healer H2 take for it, or none.",
|
|
||||||
"input": {
|
|
||||||
"properties": {},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what stalled answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "recheck",
|
|
||||||
"description": "Check a rejected or ready delivery again: it goes back to proposed and the controller is asked for its check. With why.",
|
|
||||||
"input": {
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"description": "the delivery's id",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"why": {
|
|
||||||
"description": "why, kept with the transition",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"id",
|
|
||||||
"why"
|
|
||||||
],
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what recheck answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release",
|
|
||||||
"description": "Removed in R6 (ADR 0539): refused by name, naming its replacement: the assigner's asks (hold, restore, backup, record), answered on the phone or in the delivery view",
|
|
||||||
"optional": true,
|
|
||||||
"input": {
|
|
||||||
"properties": {},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what release answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stop",
|
|
||||||
"description": "Removed in R6 (ADR 0539): refused by name, naming its replacement: a bad fingerprint is held and its canary set back by the assigner (ADR 0429 §6, ADR 0539 clause 18)",
|
|
||||||
"optional": true,
|
|
||||||
"input": {
|
|
||||||
"properties": {},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what stop answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "close",
|
|
||||||
"description": "Healer H2's verb: take the one transition the table names for a delivery held past its bound. Refused for any other.",
|
|
||||||
"input": {
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"description": "the delivery's id",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"why": {
|
|
||||||
"description": "the condition it answers",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"id",
|
|
||||||
"why"
|
|
||||||
],
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what close answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "retire-history",
|
|
||||||
"description": "Removed in R6 (ADR 0539): refused by name, naming its replacement: nothing to retire: the gate keeps no delivery after its merge",
|
|
||||||
"optional": true,
|
|
||||||
"input": {
|
|
||||||
"properties": {},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what retire-history answers, as its description says"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "settle",
|
|
||||||
"description": "Ask the operator to settle deliveries held because their merge reached the trunk without a passing check: one ask on the operator's channel for all of them, as an Approve is asked. The verb moves nothing; on the operator's answer each goes to merged, and whether it is on the machines is derived as for any merge (novox/hq ADR 0556). Refused for a delivery not held, or held for another reason, naming why.",
|
|
||||||
"optional": true,
|
|
||||||
"input": {
|
|
||||||
"additionalProperties": false,
|
|
||||||
"properties": {
|
|
||||||
"ids": {
|
|
||||||
"description": "the held deliveries' ids (owner/repository@commit)",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"minItems": 1,
|
|
||||||
"type": "array"
|
|
||||||
},
|
|
||||||
"why": {
|
|
||||||
"description": "why they may be settled, shown to the operator",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"ids",
|
|
||||||
"why"
|
|
||||||
],
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what settle answers, as its description says"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "The delivery gate: reads and steers deliveries, merges and the checks that decide them; the merge is made on the operator's Approve once both checks passed.",
|
|
||||||
"states": [
|
|
||||||
{
|
|
||||||
"name": "source",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "main",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "the layout version"
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "the group that moved it"
|
|
||||||
},
|
|
||||||
"heads": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"description": "repository to the merged head, a full commit"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"group",
|
|
||||||
"heads"
|
|
||||||
],
|
|
||||||
"description": "every repository's merged head; its revision is the mesh's source revision"
|
|
||||||
},
|
|
||||||
"description": "the one key, written by the holder alone by compare-and-set"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "the mesh's source revision",
|
|
||||||
"history": 64
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "merges",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "<group>",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "the layout version"
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"ask": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "the ask key"
|
|
||||||
},
|
|
||||||
"approved": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"description": "<repository>@<number> to the approved head"
|
|
||||||
},
|
|
||||||
"pulls": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"repository": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"number": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"head": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"state": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "merging, merged or refused"
|
|
||||||
},
|
|
||||||
"commit": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"words": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"repository",
|
|
||||||
"number",
|
|
||||||
"head",
|
|
||||||
"state"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"group",
|
|
||||||
"ask",
|
|
||||||
"pulls"
|
|
||||||
],
|
|
||||||
"description": "one group's merge and how far each pull request is"
|
|
||||||
},
|
|
||||||
"description": "a group's merge"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "the merges",
|
|
||||||
"history": 10
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "asks",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "merge.<group>.<heads>",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "the layout version"
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"heads": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"repository": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "<owner>/<name>"
|
|
||||||
},
|
|
||||||
"number": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"head": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "the full commit"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"repository",
|
|
||||||
"number",
|
|
||||||
"head"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ask": {
|
|
||||||
"description": "the operator-channel ask as raised"
|
|
||||||
},
|
|
||||||
"asking": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "the number of times it was asked"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"group",
|
|
||||||
"heads",
|
|
||||||
"ask"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"description": "the ask of the operator for one group at one set of heads"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "the asks of the operator for a merge",
|
|
||||||
"history": 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "owed",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "<repository>.<number>.<head>.<act>",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "the layout version"
|
|
||||||
},
|
|
||||||
"act": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "status=<context>, view, note or comment.<seq>"
|
|
||||||
},
|
|
||||||
"context": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"target": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"state": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"text": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"ref": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"act"
|
|
||||||
],
|
|
||||||
"description": "one act owed to the forge, written by its owner and done by the forge bridge"
|
|
||||||
},
|
|
||||||
"description": "one act owed to the forge"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "the acts the gate owes the forge",
|
|
||||||
"history": 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "turns",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "<repository>",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "the layout version"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"waiting": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"group": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"heads": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"ask": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"approved": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time",
|
|
||||||
"description": "when (RFC 3339 time)"
|
|
||||||
},
|
|
||||||
"since": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time",
|
|
||||||
"description": "when (RFC 3339 time)"
|
|
||||||
},
|
|
||||||
"waits-for": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"waits-since": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time",
|
|
||||||
"description": "when (RFC 3339 time)"
|
|
||||||
},
|
|
||||||
"step": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"group",
|
|
||||||
"heads",
|
|
||||||
"approved",
|
|
||||||
"since"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"repository",
|
|
||||||
"waiting"
|
|
||||||
],
|
|
||||||
"description": "the merges of a repository in the order they wait for their turn"
|
|
||||||
},
|
|
||||||
"description": "the merges waiting on a repository"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "which merge waits for which",
|
|
||||||
"history": 5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"name": "a want",
|
|
||||||
"of": "state:wants/want.<node>.<module>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"fp": "ab12",
|
|
||||||
"rule": 3
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a node's own want",
|
|
||||||
"of": "state:wants/want.<node>.node",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"composed": "sha256:aa",
|
|
||||||
"self": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a held fingerprint",
|
|
||||||
"of": "state:wants/held.<module>.<fingerprint>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"node": "ace"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a difference",
|
|
||||||
"of": "state:differences/<node>.<module>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"want": "ab12",
|
|
||||||
"unexplained": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a composition",
|
|
||||||
"of": "state:compositions/<group>.<heads>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"group": "g1",
|
|
||||||
"heads": "0123456789ab",
|
|
||||||
"state": "pass"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,284 +0,0 @@
|
|||||||
{
|
|
||||||
"format": 1,
|
|
||||||
"seat": "mesh-wants",
|
|
||||||
"scope": "mesh",
|
|
||||||
"grain": "whole",
|
|
||||||
"domain": "Delivery",
|
|
||||||
"decision": "novox/hq ADR 0565, ADR 0634, ADR 0635",
|
|
||||||
"description": "The seat that says what each node should run and whether each module's new builds wait for a person (ADR 0565, ADR 0539).",
|
|
||||||
"verbs": [
|
|
||||||
{
|
|
||||||
"name": "upgrade",
|
|
||||||
"description": "Whether each module's new builds wait for a person: its policy (roll, together or record) and where it comes from (a person, the module, the bus, its irreplaceable data, the default); the bus is never rolled. With module, that one; with module, policy and why, a person's choice for it, recorded as a hand act; with policy default, the choice taken back. With compare, each node's own composition and the assigner's findings.",
|
|
||||||
"input": {
|
|
||||||
"properties": {
|
|
||||||
"compare": {
|
|
||||||
"description": "\"true\": each node's own composition, by its digest, and the assigner's findings",
|
|
||||||
"enum": [
|
|
||||||
"true",
|
|
||||||
"false"
|
|
||||||
],
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"module": {
|
|
||||||
"description": "one module",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"policy": {
|
|
||||||
"description": "with module: roll, together, record, or default to take a person's choice back",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"why": {
|
|
||||||
"description": "with policy: why, required and kept",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "each module's policy, or the one chosen, or the comparison"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "bus",
|
|
||||||
"description": "What a bus upgrade would do: the fingerprint of the bus module each node runs against the indexer's newest, and the last bus steps from the hand-act log and the assigner's puts of the bus. Read-only: the step itself is the put on the operator's warrant.",
|
|
||||||
"input": {
|
|
||||||
"properties": {},
|
|
||||||
"type": "object"
|
|
||||||
},
|
|
||||||
"answer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "what a bus upgrade would do, read only"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"name": "policy-changed",
|
|
||||||
"body": {
|
|
||||||
"type": "object"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"family": {
|
|
||||||
"name": "mesh-wants.events",
|
|
||||||
"max-age-days": 7
|
|
||||||
},
|
|
||||||
"states": [
|
|
||||||
{
|
|
||||||
"name": "wants",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "want.<node>.<module>",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "a node's want for a module",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"fp": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"composed": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"removed": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"newest": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"rule": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "the rule that holds the node back, 1 to 10"
|
|
||||||
},
|
|
||||||
"backup": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "again or skip",
|
|
||||||
"enum": [
|
|
||||||
"again",
|
|
||||||
"skip"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"words": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"put": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"hold": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"yes": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"release": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"self": {
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"description": "a node's want for a module"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "want.<node>.node",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "a node's own want",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"composed": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"words": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"self": {
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"composed"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"description": "a node's own want, naming the digest of its own composition"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "held.<module>.<fingerprint>",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "a fingerprint the assigner holds",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"node": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"words": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"node"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"description": "a module's fingerprint the assigner holds"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"history": 20,
|
|
||||||
"description": "what each node should run, and the fingerprints held back"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "differences",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "<node>.<module>",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "the difference between a want and what is sent",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"want": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"want-removed": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"sent": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"sent-build": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"rule": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"unexplained": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"words": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"description": "a module on a node"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"history": 64,
|
|
||||||
"description": "differences between a want and what the node-engine is sent"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "compositions",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "<group>.<heads>",
|
|
||||||
"value": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "the composition verdict of a group's check at its heads",
|
|
||||||
"properties": {
|
|
||||||
"v": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"heads": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "12 lowercase hex digits"
|
|
||||||
},
|
|
||||||
"state": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "pass, fail or waits"
|
|
||||||
},
|
|
||||||
"words": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"sdk": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"machines": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"machine": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"warnings": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"took": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "milliseconds"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"group",
|
|
||||||
"heads",
|
|
||||||
"state"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"description": "a group's check at its heads"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"history": 5,
|
|
||||||
"description": "composition verdicts of a group's check; the checker reads them"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
{
|
|
||||||
"format": 1,
|
|
||||||
"seat": "node-build-go",
|
|
||||||
"scope": "node",
|
|
||||||
"grain": "whole",
|
|
||||||
"domain": "Delivery",
|
|
||||||
"decision": "novox/hq ADR 0525, ADR 0536, ADR 0553",
|
|
||||||
"pulled-by-kind": true,
|
|
||||||
"yields": true,
|
|
||||||
"accepts": [
|
|
||||||
{
|
|
||||||
"name": "delivery",
|
|
||||||
"body": {
|
|
||||||
"$ref": "#/defs/StepAsk"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "check",
|
|
||||||
"body": {
|
|
||||||
"$ref": "#/defs/StepAsk"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "recheck",
|
|
||||||
"body": {
|
|
||||||
"$ref": "#/defs/StepAsk"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "The Go build module on a node: it takes the asks of the builder and the checker, runs them as steps and answers.",
|
|
||||||
"includes": [
|
|
||||||
"build-step"
|
|
||||||
],
|
|
||||||
"states": [
|
|
||||||
{
|
|
||||||
"name": "steps",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "<node>.<id>",
|
|
||||||
"value": {
|
|
||||||
"$ref": "#/defs/Step"
|
|
||||||
},
|
|
||||||
"description": "a step on a node"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "the steps this module runs",
|
|
||||||
"history": 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "pauses",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "paused.<node>",
|
|
||||||
"value": {
|
|
||||||
"$ref": "#/defs/Pause"
|
|
||||||
},
|
|
||||||
"description": "whether a node is paused"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "capacity.<node>",
|
|
||||||
"value": {
|
|
||||||
"$ref": "#/defs/Capacity"
|
|
||||||
},
|
|
||||||
"description": "a node's capacity"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "the pause and the capacity of each node",
|
|
||||||
"history": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "toolchains",
|
|
||||||
"template": "state",
|
|
||||||
"key-forms": [
|
|
||||||
{
|
|
||||||
"key": "<node>.<language>",
|
|
||||||
"value": {
|
|
||||||
"$ref": "#/defs/Toolchain"
|
|
||||||
},
|
|
||||||
"description": "the toolchain a node reports"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "the toolchains the nodes report",
|
|
||||||
"history": 1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"name": "a running step",
|
|
||||||
"of": "state:steps/<node>.<id>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"id": "a1b2",
|
|
||||||
"tool": "build",
|
|
||||||
"node": "ace",
|
|
||||||
"state": "running",
|
|
||||||
"started": "2026-11-05T10:00:00Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a paused node",
|
|
||||||
"of": "state:pauses/paused.<node>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"paused": true,
|
|
||||||
"by": "operator@shanks",
|
|
||||||
"at": "2026-11-05T10:00:00Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a node's capacity",
|
|
||||||
"of": "state:pauses/capacity.<node>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"effective": 2,
|
|
||||||
"configured": 2,
|
|
||||||
"why": "the configured steps fit the cores"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a node's toolchain",
|
|
||||||
"of": "state:toolchains/<node>.<language>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"language": "go",
|
|
||||||
"version": "1.26.0",
|
|
||||||
"recipe": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a build ask",
|
|
||||||
"of": "accept:delivery",
|
|
||||||
"subject": "mesh.seat.node-build-image.accept.delivery",
|
|
||||||
"given": {
|
|
||||||
"id": "a1b2",
|
|
||||||
"kind": "build",
|
|
||||||
"language": "go",
|
|
||||||
"asker": "mesh-delivery-builder",
|
|
||||||
"build": {
|
|
||||||
"module": "nats",
|
|
||||||
"artifacts": [
|
|
||||||
{
|
|
||||||
"artifact": "go"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"name": "a running step",
|
|
||||||
"of": "state:steps/<node>.<id>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"id": "a1b2",
|
|
||||||
"tool": "build",
|
|
||||||
"node": "ace",
|
|
||||||
"state": "running",
|
|
||||||
"started": "2026-11-05T10:00:00Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a paused node",
|
|
||||||
"of": "state:pauses/paused.<node>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"paused": true,
|
|
||||||
"by": "operator@shanks",
|
|
||||||
"at": "2026-11-05T10:00:00Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a node's capacity",
|
|
||||||
"of": "state:pauses/capacity.<node>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"effective": 2,
|
|
||||||
"configured": 2,
|
|
||||||
"why": "the configured steps fit the cores"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a node's toolchain",
|
|
||||||
"of": "state:toolchains/<node>.<language>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"language": "go",
|
|
||||||
"version": "1.26.0",
|
|
||||||
"recipe": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a build ask",
|
|
||||||
"of": "accept:delivery",
|
|
||||||
"subject": "mesh.seat.node-build-node.accept.delivery",
|
|
||||||
"given": {
|
|
||||||
"id": "a1b2",
|
|
||||||
"kind": "build",
|
|
||||||
"language": "go",
|
|
||||||
"asker": "mesh-delivery-builder",
|
|
||||||
"build": {
|
|
||||||
"module": "nats",
|
|
||||||
"artifacts": [
|
|
||||||
{
|
|
||||||
"artifact": "go"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a check ask with the group's tagged package",
|
|
||||||
"of": "accept:check",
|
|
||||||
"subject": "mesh.seat.node-build-node.accept.check",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"id": "c3d5",
|
|
||||||
"kind": "check",
|
|
||||||
"language": "typescript",
|
|
||||||
"asker": "mesh-delivery-checker",
|
|
||||||
"at": "2026-11-05T10:00:00Z",
|
|
||||||
"check": {
|
|
||||||
"fetch": {
|
|
||||||
"repository": "novox/mesh-delivery",
|
|
||||||
"commit": "0123456789abcdef0123456789abcdef01234567",
|
|
||||||
"ref": "refs/pull/7/head",
|
|
||||||
"base": "89abcdef0123456789abcdef0123456789abcdef",
|
|
||||||
"package": {
|
|
||||||
"name": "@novox/mesh-sdk",
|
|
||||||
"version": "0.1.15-feat-x.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"levels": [
|
|
||||||
"unit",
|
|
||||||
"integration"
|
|
||||||
],
|
|
||||||
"kept": true,
|
|
||||||
"toolchain": {
|
|
||||||
"language": "typescript",
|
|
||||||
"version": "26.12.0",
|
|
||||||
"recipe": "1"
|
|
||||||
},
|
|
||||||
"node-names": [
|
|
||||||
"ace",
|
|
||||||
"g14"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "a finished check step of a TypeScript merge preview",
|
|
||||||
"of": "state:steps/<node>.<id>",
|
|
||||||
"given": {
|
|
||||||
"v": 1,
|
|
||||||
"id": "c3d6",
|
|
||||||
"tool": "check",
|
|
||||||
"node": "ace",
|
|
||||||
"state": "passed",
|
|
||||||
"started": "2026-11-05T10:00:00Z",
|
|
||||||
"ended": "2026-11-05T10:01:00Z",
|
|
||||||
"result": {
|
|
||||||
"fetch": {
|
|
||||||
"workspace": "mvii1sxt979f67",
|
|
||||||
"commit": "0123456789abcdef0123456789abcdef01234567",
|
|
||||||
"modules": [
|
|
||||||
"modules/m"
|
|
||||||
],
|
|
||||||
"base": "abcdef0123456789abcdef0123456789abcdef01",
|
|
||||||
"merge": "0123456789abcdef0123456789abcdef01234567",
|
|
||||||
"changed": [
|
|
||||||
"modules/m/package.json"
|
|
||||||
],
|
|
||||||
"trees": {
|
|
||||||
"modules/m": {
|
|
||||||
"tree": "0123456789abcdef0123456789abcdef01234567",
|
|
||||||
"manifest": "0581b699d9d05517e69b21f5cedbeb2eee8aba2b205280b561be731594d7feef"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,545 +0,0 @@
|
|||||||
// Code generated by seatgen from the seat definitions; DO NOT EDIT.
|
|
||||||
|
|
||||||
// The contract of the seat "mesh-catalog", defined whole (seats/mesh-catalog/seat.json): The catalog of the mesh: every module the trunk holds with its manifest, fingerprint and verdict, the packages published, and the seat list (ADR 0636 §1, §4).
|
|
||||||
|
|
||||||
export const seat = "mesh-catalog";
|
|
||||||
|
|
||||||
export const verbs = {
|
|
||||||
modules: "modules",
|
|
||||||
module: "module",
|
|
||||||
provides: "provides",
|
|
||||||
dependents: "dependents",
|
|
||||||
seatDefinitions: "seat-definitions",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const events = {
|
|
||||||
seatDefinitionChanged: "seat-definition-changed",
|
|
||||||
seatDefinitionRemoved: "seat-definition-removed",
|
|
||||||
manifestAccepted: "manifest-accepted",
|
|
||||||
manifestRefused: "manifest-refused",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const family = { name: "mesh-catalog.events", maxAgeDays: 7 } as const;
|
|
||||||
|
|
||||||
export const seatDefinitionChangedSubject = "mesh.seat.mesh-catalog.event.seat-definition-changed";
|
|
||||||
|
|
||||||
export const seatDefinitionRemovedSubject = "mesh.seat.mesh-catalog.event.seat-definition-removed";
|
|
||||||
|
|
||||||
export const manifestAcceptedSubject = "mesh.seat.mesh-catalog.event.manifest-accepted";
|
|
||||||
|
|
||||||
export const manifestRefusedSubject = "mesh.seat.mesh-catalog.event.manifest-refused";
|
|
||||||
|
|
||||||
export const states = {
|
|
||||||
manifests: "manifests",
|
|
||||||
modules: "modules",
|
|
||||||
candidates: "candidates",
|
|
||||||
verdicts: "verdicts",
|
|
||||||
predefined: "predefined",
|
|
||||||
configCandidates: "config-candidates",
|
|
||||||
packages: "packages",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/** The key of one value of the state manifests under the form "<digest>". */
|
|
||||||
export function manifestsByDigestKey(digest: string): string {
|
|
||||||
return digest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<digest>", or undefined for a key of another form. */
|
|
||||||
export function parseManifestsByDigestKey(_key: string): { digest: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const digest = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { digest };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state modules under the form "<module>". */
|
|
||||||
export function modulesByModuleKey(module: string): string {
|
|
||||||
return module;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<module>", or undefined for a key of another form. */
|
|
||||||
export function parseModulesByModuleKey(_key: string): { module: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const module = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { module };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state candidates under the form "<group>". */
|
|
||||||
export function candidatesByGroupKey(group: string): string {
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<group>", or undefined for a key of another form. */
|
|
||||||
export function parseCandidatesByGroupKey(_key: string): { group: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const group = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { group };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state verdicts under the form "<digest>". */
|
|
||||||
export function verdictsByDigestKey(digest: string): string {
|
|
||||||
return digest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<digest>", or undefined for a key of another form. */
|
|
||||||
export function parseVerdictsByDigestKey(_key: string): { digest: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const digest = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { digest };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state predefined under the form "list". */
|
|
||||||
export function predefinedByListKey(): string {
|
|
||||||
return "list";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "list", or undefined for a key of another form. */
|
|
||||||
export function parsePredefinedByListKey(_key: string): { } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("list")) return undefined;
|
|
||||||
_rest = _rest.slice(4);
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state config-candidates under the form "<pull>". */
|
|
||||||
export function configCandidatesByPullKey(pull: string): string {
|
|
||||||
return pull;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<pull>", or undefined for a key of another form. */
|
|
||||||
export function parseConfigCandidatesByPullKey(_key: string): { pull: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const pull = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { pull };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state packages under the form "<module>". */
|
|
||||||
export function packagesByModuleKey(module: string): string {
|
|
||||||
return module;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<module>", or undefined for a key of another form. */
|
|
||||||
export function parsePackagesByModuleKey(_key: string): { module: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const module = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { module };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state packages under the form "<package>.<series>". */
|
|
||||||
export function packagesByPackageSeriesKey(packagePart: string, series: string): string {
|
|
||||||
return packagePart + "." + series;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<package>.<series>", or undefined for a key of another form. */
|
|
||||||
export function parsePackagesByPackageSeriesKey(_key: string): { packagePart: string; series: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const packagePart = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const series = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { packagePart, series };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a toolchain a fingerprint was computed with (ADR 0405 clause 7) */
|
|
||||||
export interface ToolchainUsed {
|
|
||||||
"language": string;
|
|
||||||
/** the build module's recipe version */
|
|
||||||
"recipe": string;
|
|
||||||
/** the installed toolchain's version */
|
|
||||||
"version": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what modules takes. */
|
|
||||||
export interface ModulesInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ModulesAnswerModulesItem {
|
|
||||||
/** the merge commit it was last changed at */
|
|
||||||
"commit": string;
|
|
||||||
/** its fingerprint (src2: and 64 hex digits); absent when it has none */
|
|
||||||
"fp"?: string;
|
|
||||||
"module": string;
|
|
||||||
/** why it has none */
|
|
||||||
"none"?: string;
|
|
||||||
/** the module's directory in its repository, '.' for a root */
|
|
||||||
"path"?: string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what modules answers. */
|
|
||||||
export interface ModulesAnswer {
|
|
||||||
"modules": ModulesAnswerModulesItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what module takes. */
|
|
||||||
export interface ModuleInput {
|
|
||||||
/** the module's name */
|
|
||||||
"module": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ModuleAnswerModule {
|
|
||||||
/** the merge commit it was last changed at */
|
|
||||||
"commit": string;
|
|
||||||
/** its fingerprint (src2: and 64 hex digits); absent when it has none */
|
|
||||||
"fp"?: string;
|
|
||||||
/** the module's manifest as the trunk holds it */
|
|
||||||
"manifest"?: Record<string, unknown>;
|
|
||||||
"module": string;
|
|
||||||
/** why it has none */
|
|
||||||
"none"?: string;
|
|
||||||
/** the module's directory in its repository, '.' for a root */
|
|
||||||
"path"?: string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what module answers. */
|
|
||||||
export interface ModuleAnswer {
|
|
||||||
"module": ModuleAnswerModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what provides takes. */
|
|
||||||
export interface ProvidesInput {
|
|
||||||
/** the provision, such as postgres-database */
|
|
||||||
"provision": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what provides answers. */
|
|
||||||
export type ProvidesAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what dependents takes. */
|
|
||||||
export interface DependentsInput {
|
|
||||||
/** the module's name */
|
|
||||||
"module": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what dependents answers. */
|
|
||||||
export type DependentsAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what seat-definitions takes. */
|
|
||||||
export interface SeatDefinitionsInput {
|
|
||||||
/** the seat's name; none lists every trunk seat */
|
|
||||||
"seat"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SeatDefinitionsAnswerEntry {
|
|
||||||
/** the definition, resolved with the parts it includes */
|
|
||||||
"definition"?: Record<string, unknown>;
|
|
||||||
"digest": string;
|
|
||||||
"seat": string;
|
|
||||||
/** trunk */
|
|
||||||
"source": string;
|
|
||||||
/** why the definition could not be read, when it could not */
|
|
||||||
"unparsed"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SeatDefinitionsAnswerSeatsItem {
|
|
||||||
"digest": string;
|
|
||||||
"seat": string;
|
|
||||||
/** trunk */
|
|
||||||
"source": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what seat-definitions answers. */
|
|
||||||
export interface SeatDefinitionsAnswer {
|
|
||||||
"entry"?: SeatDefinitionsAnswerEntry;
|
|
||||||
"found"?: boolean;
|
|
||||||
"revision"?: number;
|
|
||||||
"seat"?: string;
|
|
||||||
"seats"?: SeatDefinitionsAnswerSeatsItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is the body of the event seat-definition-changed. */
|
|
||||||
export interface SeatDefinitionChangedEvent {
|
|
||||||
"digest": string;
|
|
||||||
"seat": string;
|
|
||||||
/** trunk */
|
|
||||||
"source": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is the body of the event seat-definition-removed. */
|
|
||||||
export interface SeatDefinitionRemovedEvent {
|
|
||||||
"seat": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ManifestAcceptedEventBusStateItem {
|
|
||||||
"configuration"?: Record<string, unknown>;
|
|
||||||
"name": string;
|
|
||||||
"options"?: Record<string, unknown>;
|
|
||||||
"storage": string;
|
|
||||||
"template"?: string;
|
|
||||||
"types"?: Record<string, unknown>[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is the body of the event manifest-accepted. */
|
|
||||||
export interface ManifestAcceptedEvent {
|
|
||||||
"bus-state": ManifestAcceptedEventBusStateItem[];
|
|
||||||
"digest": string;
|
|
||||||
"judge": string;
|
|
||||||
"module": string;
|
|
||||||
/** the indexer's revision of the verdict it says; a reader asks its first view again on a gap in it; zero from an indexer that does not say it */
|
|
||||||
"revision"?: number;
|
|
||||||
"v": number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is the body of the event manifest-refused. */
|
|
||||||
export interface ManifestRefusedEvent {
|
|
||||||
"digest": string;
|
|
||||||
"judge": string;
|
|
||||||
"module": string;
|
|
||||||
"problems": string[];
|
|
||||||
/** the indexer's revision of the verdict it says; a reader asks its first view again on a gap in it; zero from an indexer that does not say it */
|
|
||||||
"revision"?: number;
|
|
||||||
"v": number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state manifests under the key <digest>. */
|
|
||||||
export interface ManifestsByDigestValue {
|
|
||||||
/** the manifest, UTF-8 JSON text */
|
|
||||||
"manifest": string;
|
|
||||||
"module": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ModulesByModuleValueInputs2 {
|
|
||||||
"bases"?: string[];
|
|
||||||
"builder"?: string;
|
|
||||||
"contexts"?: Record<string, string>;
|
|
||||||
"import-form"?: string;
|
|
||||||
"imports"?: string[];
|
|
||||||
"locks"?: Record<string, string>;
|
|
||||||
"packages"?: string[];
|
|
||||||
"paths"?: Record<string, string>;
|
|
||||||
"tree": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state modules under the key <module>. */
|
|
||||||
export interface ModulesByModuleValue {
|
|
||||||
"commit": string;
|
|
||||||
/** the old-form fingerprint */
|
|
||||||
"fp"?: string;
|
|
||||||
"fp-src"?: number;
|
|
||||||
/** src2: fingerprint */
|
|
||||||
"fp2"?: string;
|
|
||||||
"inputs2"?: ModulesByModuleValueInputs2;
|
|
||||||
/** manifest digest */
|
|
||||||
"manifest"?: string;
|
|
||||||
"needs"?: string[];
|
|
||||||
"none"?: string;
|
|
||||||
/** why it has none */
|
|
||||||
"none2"?: string;
|
|
||||||
"packages"?: Record<string, string>;
|
|
||||||
"path"?: string;
|
|
||||||
"paths"?: Record<string, string[]>;
|
|
||||||
"problems"?: string[];
|
|
||||||
"repository": string;
|
|
||||||
/** the source revision */
|
|
||||||
"src"?: number;
|
|
||||||
/** by language: the toolchain FP2 was computed with */
|
|
||||||
"toolchains"?: Record<string, ToolchainUsed>;
|
|
||||||
"unknown"?: string[];
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"verdict"?: string;
|
|
||||||
"warnings"?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CandidatesByGroupValuePullsItemFpsValue {
|
|
||||||
"fp2"?: string;
|
|
||||||
"manifest"?: string;
|
|
||||||
"none2"?: string;
|
|
||||||
"packages"?: Record<string, string>;
|
|
||||||
"paths"?: Record<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CandidatesByGroupValuePullsItem {
|
|
||||||
"fps"?: Record<string, CandidatesByGroupValuePullsItemFpsValue>;
|
|
||||||
"head": string;
|
|
||||||
"modules": string[];
|
|
||||||
"number": number;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state candidates under the key <group>. */
|
|
||||||
export interface CandidatesByGroupValue {
|
|
||||||
/** the source revision it is read on */
|
|
||||||
"base": number;
|
|
||||||
"fpset"?: string;
|
|
||||||
"group": string;
|
|
||||||
"heads": string;
|
|
||||||
"pulls": CandidatesByGroupValuePullsItem[];
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state verdicts under the key <digest>. */
|
|
||||||
export interface VerdictsByDigestValue {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"judge"?: string;
|
|
||||||
"module": string;
|
|
||||||
"problems"?: string[];
|
|
||||||
"state": string;
|
|
||||||
"unknown"?: string[];
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"warnings"?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state predefined under the key list. */
|
|
||||||
export interface PredefinedByListValue {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"commit": string;
|
|
||||||
/** the foundation's predefined list as kept */
|
|
||||||
"list": unknown;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ConfigCandidatesByPullValueDeclaresValueValue {
|
|
||||||
/** the default */
|
|
||||||
"default": unknown;
|
|
||||||
"description"?: string;
|
|
||||||
/** the allowed values */
|
|
||||||
"enum"?: unknown;
|
|
||||||
"kind": string;
|
|
||||||
/** a declared bound; 0 is a bound, absent is none */
|
|
||||||
"maximum"?: number | null;
|
|
||||||
/** a declared bound; 0 is a bound, absent is none */
|
|
||||||
"minimum"?: number | null;
|
|
||||||
"pattern"?: string;
|
|
||||||
"predefined"?: string;
|
|
||||||
"required"?: boolean;
|
|
||||||
"runtime"?: boolean;
|
|
||||||
"trusted"?: boolean;
|
|
||||||
"type"?: string;
|
|
||||||
"why": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state config-candidates under the key <pull>. */
|
|
||||||
export interface ConfigCandidatesByPullValue {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
/** module to key to declaration */
|
|
||||||
"declares": Record<string, Record<string, ConfigCandidatesByPullValueDeclaresValueValue>>;
|
|
||||||
"head": string;
|
|
||||||
"pull": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PackagesByModuleValuePackagesItem {
|
|
||||||
"digest": string;
|
|
||||||
"package": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state packages under the key <module>. */
|
|
||||||
export interface PackagesByModuleValue {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"commit": string;
|
|
||||||
"dir"?: string;
|
|
||||||
/** the Go module path */
|
|
||||||
"module": string;
|
|
||||||
"packages": PackagesByModuleValuePackagesItem[];
|
|
||||||
"repository": string;
|
|
||||||
/** digest of go.mod and go.sum */
|
|
||||||
"requires"?: string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PackagesByPackageSeriesValueNewestContentsPackagesItem {
|
|
||||||
"digest": string;
|
|
||||||
"package": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PackagesByPackageSeriesValueNewestContents {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"commit": string;
|
|
||||||
"dir"?: string;
|
|
||||||
/** the Go module path */
|
|
||||||
"module": string;
|
|
||||||
"packages": PackagesByPackageSeriesValueNewestContentsPackagesItem[];
|
|
||||||
"repository": string;
|
|
||||||
/** digest of go.mod and go.sum */
|
|
||||||
"requires"?: string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PackagesByPackageSeriesValueNewest {
|
|
||||||
"commit"?: string;
|
|
||||||
"contents"?: PackagesByPackageSeriesValueNewestContents;
|
|
||||||
"digest"?: string;
|
|
||||||
"fingerprint"?: string;
|
|
||||||
"version": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PackagesByPackageSeriesValueNumberedContentsPackagesItem {
|
|
||||||
"digest": string;
|
|
||||||
"package": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PackagesByPackageSeriesValueNumberedContents {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"commit": string;
|
|
||||||
"dir"?: string;
|
|
||||||
/** the Go module path */
|
|
||||||
"module": string;
|
|
||||||
"packages": PackagesByPackageSeriesValueNumberedContentsPackagesItem[];
|
|
||||||
"repository": string;
|
|
||||||
/** digest of go.mod and go.sum */
|
|
||||||
"requires"?: string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PackagesByPackageSeriesValueNumbered {
|
|
||||||
"commit"?: string;
|
|
||||||
"contents"?: PackagesByPackageSeriesValueNumberedContents;
|
|
||||||
"digest"?: string;
|
|
||||||
"fingerprint"?: string;
|
|
||||||
"version": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state packages under the key <package>.<series>. */
|
|
||||||
export interface PackagesByPackageSeriesValue {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"go-module"?: string;
|
|
||||||
"name": string;
|
|
||||||
"newest"?: PackagesByPackageSeriesValueNewest;
|
|
||||||
"numbered"?: PackagesByPackageSeriesValueNumbered;
|
|
||||||
"package"?: string;
|
|
||||||
"seat"?: string;
|
|
||||||
"series": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,338 +0,0 @@
|
|||||||
// Code generated by seatgen from the seat definitions; DO NOT EDIT.
|
|
||||||
|
|
||||||
// The contract of the seat "mesh-delivery", defined whole (seats/mesh-delivery/seat.json): The delivery gate: reads and steers deliveries, merges and the checks that decide them; the merge is made on the operator's Approve once both checks passed.
|
|
||||||
|
|
||||||
export const seat = "mesh-delivery";
|
|
||||||
|
|
||||||
export const verbs = {
|
|
||||||
deliveries: "deliveries",
|
|
||||||
times: "times",
|
|
||||||
show: "show",
|
|
||||||
groups: "groups",
|
|
||||||
whatIf: "what-if",
|
|
||||||
checks: "checks",
|
|
||||||
table: "table",
|
|
||||||
stalled: "stalled",
|
|
||||||
recheck: "recheck",
|
|
||||||
release: "release",
|
|
||||||
stop: "stop",
|
|
||||||
close: "close",
|
|
||||||
retireHistory: "retire-history",
|
|
||||||
settle: "settle",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const states = {
|
|
||||||
source: "source",
|
|
||||||
merges: "merges",
|
|
||||||
asks: "asks",
|
|
||||||
owed: "owed",
|
|
||||||
turns: "turns",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/** The key of one value of the state source under the form "main". */
|
|
||||||
export function sourceByMainKey(): string {
|
|
||||||
return "main";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "main", or undefined for a key of another form. */
|
|
||||||
export function parseSourceByMainKey(_key: string): { } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("main")) return undefined;
|
|
||||||
_rest = _rest.slice(4);
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state merges under the form "<group>". */
|
|
||||||
export function mergesByGroupKey(group: string): string {
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<group>", or undefined for a key of another form. */
|
|
||||||
export function parseMergesByGroupKey(_key: string): { group: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const group = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { group };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state asks under the form "merge.<group>.<heads>". */
|
|
||||||
export function asksByMergeGroupHeadsKey(group: string, heads: string): string {
|
|
||||||
return "merge." + group + "." + heads;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "merge.<group>.<heads>", or undefined for a key of another form. */
|
|
||||||
export function parseAsksByMergeGroupHeadsKey(_key: string): { group: string; heads: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("merge.")) return undefined;
|
|
||||||
_rest = _rest.slice(6);
|
|
||||||
const _at1 = _rest.indexOf(".");
|
|
||||||
if (_at1 <= 0) return undefined;
|
|
||||||
const group = _rest.slice(0, _at1);
|
|
||||||
_rest = _rest.slice(_at1 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const heads = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { group, heads };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state owed under the form "<repository>.<number>.<head>.<act>". */
|
|
||||||
export function owedByRepositoryNumberHeadActKey(repository: string, number: string, head: string, act: string): string {
|
|
||||||
return repository + "." + number + "." + head + "." + act;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<repository>.<number>.<head>.<act>", or undefined for a key of another form. */
|
|
||||||
export function parseOwedByRepositoryNumberHeadActKey(_key: string): { repository: string; number: string; head: string; act: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const repository = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
const _at2 = _rest.indexOf(".");
|
|
||||||
if (_at2 <= 0) return undefined;
|
|
||||||
const number = _rest.slice(0, _at2);
|
|
||||||
_rest = _rest.slice(_at2 + 1);
|
|
||||||
const _at4 = _rest.indexOf(".");
|
|
||||||
if (_at4 <= 0) return undefined;
|
|
||||||
const head = _rest.slice(0, _at4);
|
|
||||||
_rest = _rest.slice(_at4 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const act = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { repository, number, head, act };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state turns under the form "<repository>". */
|
|
||||||
export function turnsByRepositoryKey(repository: string): string {
|
|
||||||
return repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<repository>", or undefined for a key of another form. */
|
|
||||||
export function parseTurnsByRepositoryKey(_key: string): { repository: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const repository = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { repository };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what deliveries takes. */
|
|
||||||
export interface DeliveriesInput {
|
|
||||||
/** "true": the final ones of the last thirty days too */
|
|
||||||
"all"?: "true" | "false";
|
|
||||||
/** a group's id (its branch name) */
|
|
||||||
"group"?: string;
|
|
||||||
/** owner/repository */
|
|
||||||
"repository"?: string;
|
|
||||||
/** one state, e.g. delivering or held */
|
|
||||||
"state"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what deliveries answers. */
|
|
||||||
export type DeliveriesAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what times takes. */
|
|
||||||
export interface TimesInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what times answers. */
|
|
||||||
export type TimesAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what show takes. */
|
|
||||||
export interface ShowInput {
|
|
||||||
/** a delivery's id, or a group's */
|
|
||||||
"id": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what show answers. */
|
|
||||||
export type ShowAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what groups takes. */
|
|
||||||
export interface GroupsInput {
|
|
||||||
/** "true": the groups that ended too */
|
|
||||||
"all"?: "true" | "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what groups answers. */
|
|
||||||
export type GroupsAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what what-if takes. */
|
|
||||||
export interface WhatIfInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what what-if answers. */
|
|
||||||
export type WhatIfAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what checks takes. */
|
|
||||||
export interface ChecksInput {
|
|
||||||
/** a commit's sha, or the start of one, instead of a pull request */
|
|
||||||
"commit"?: string;
|
|
||||||
/** a pull request's number: its head is read */
|
|
||||||
"number"?: string;
|
|
||||||
/** owner/repository */
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what checks answers. */
|
|
||||||
export type ChecksAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what table takes. */
|
|
||||||
export interface TableInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what table answers. */
|
|
||||||
export type TableAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what stalled takes. */
|
|
||||||
export interface StalledInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what stalled answers. */
|
|
||||||
export type StalledAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what recheck takes. */
|
|
||||||
export interface RecheckInput {
|
|
||||||
/** the delivery's id */
|
|
||||||
"id": string;
|
|
||||||
/** why, kept with the transition */
|
|
||||||
"why": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what recheck answers. */
|
|
||||||
export type RecheckAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what release takes. */
|
|
||||||
export interface ReleaseInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what release answers. */
|
|
||||||
export type ReleaseAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what stop takes. */
|
|
||||||
export interface StopInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what stop answers. */
|
|
||||||
export type StopAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what close takes. */
|
|
||||||
export interface CloseInput {
|
|
||||||
/** the delivery's id */
|
|
||||||
"id": string;
|
|
||||||
/** the condition it answers */
|
|
||||||
"why": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what close answers. */
|
|
||||||
export type CloseAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what retire-history takes. */
|
|
||||||
export interface RetireHistoryInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what retire-history answers. */
|
|
||||||
export type RetireHistoryAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what settle takes. */
|
|
||||||
export interface SettleInput {
|
|
||||||
/** the held deliveries' ids (owner/repository@commit) */
|
|
||||||
"ids": string[];
|
|
||||||
/** why they may be settled, shown to the operator */
|
|
||||||
"why": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what settle answers. */
|
|
||||||
export type SettleAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is one value of the state source under the key main. */
|
|
||||||
export interface SourceByMainValue {
|
|
||||||
/** the group that moved it */
|
|
||||||
"group": string;
|
|
||||||
/** repository to the merged head, a full commit */
|
|
||||||
"heads": Record<string, string>;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MergesByGroupValuePullsItem {
|
|
||||||
"commit"?: string;
|
|
||||||
"head": string;
|
|
||||||
"number": number;
|
|
||||||
"repository": string;
|
|
||||||
/** merging, merged or refused */
|
|
||||||
"state": string;
|
|
||||||
"words"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state merges under the key <group>. */
|
|
||||||
export interface MergesByGroupValue {
|
|
||||||
/** <repository>@<number> to the approved head */
|
|
||||||
"approved"?: Record<string, string>;
|
|
||||||
/** the ask key */
|
|
||||||
"ask": string;
|
|
||||||
"group": string;
|
|
||||||
"pulls": MergesByGroupValuePullsItem[];
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AsksByMergeGroupHeadsValueHeadsItem {
|
|
||||||
/** the full commit */
|
|
||||||
"head": string;
|
|
||||||
"number": number;
|
|
||||||
/** <owner>/<name> */
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state asks under the key merge.<group>.<heads>. */
|
|
||||||
export interface AsksByMergeGroupHeadsValue {
|
|
||||||
/** the operator-channel ask as raised */
|
|
||||||
"ask": unknown;
|
|
||||||
/** the number of times it was asked */
|
|
||||||
"asking"?: number;
|
|
||||||
"group": string;
|
|
||||||
"heads": AsksByMergeGroupHeadsValueHeadsItem[];
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state owed under the key <repository>.<number>.<head>.<act>. */
|
|
||||||
export interface OwedByRepositoryNumberHeadActValue {
|
|
||||||
/** status=<context>, view, note or comment.<seq> */
|
|
||||||
"act": string;
|
|
||||||
"context"?: string;
|
|
||||||
"ref"?: string;
|
|
||||||
"state"?: string;
|
|
||||||
"target"?: string;
|
|
||||||
"text"?: string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TurnsByRepositoryValueWaitingItem {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"approved": string;
|
|
||||||
"ask"?: string;
|
|
||||||
"group": string;
|
|
||||||
"heads": string;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"since": string;
|
|
||||||
"step"?: string;
|
|
||||||
"waits-for"?: string;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"waits-since"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state turns under the key <repository>. */
|
|
||||||
export interface TurnsByRepositoryValue {
|
|
||||||
"repository": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"waiting": TurnsByRepositoryValueWaitingItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,211 +0,0 @@
|
|||||||
// Code generated by seatgen from the seat definitions; DO NOT EDIT.
|
|
||||||
|
|
||||||
// The contract of the seat "mesh-wants", defined whole (seats/mesh-wants/seat.json): The seat that says what each node should run and whether each module's new builds wait for a person (ADR 0565, ADR 0539).
|
|
||||||
|
|
||||||
export const seat = "mesh-wants";
|
|
||||||
|
|
||||||
export const verbs = {
|
|
||||||
upgrade: "upgrade",
|
|
||||||
bus: "bus",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const events = {
|
|
||||||
policyChanged: "policy-changed",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const family = { name: "mesh-wants.events", maxAgeDays: 7 } as const;
|
|
||||||
|
|
||||||
export const policyChangedSubject = "mesh.seat.mesh-wants.event.policy-changed";
|
|
||||||
|
|
||||||
export const states = {
|
|
||||||
wants: "wants",
|
|
||||||
differences: "differences",
|
|
||||||
compositions: "compositions",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/** The key of one value of the state wants under the form "want.<node>.<module>". */
|
|
||||||
export function wantsByWantNodeModuleKey(node: string, module: string): string {
|
|
||||||
return "want." + node + "." + module;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "want.<node>.<module>", or undefined for a key of another form. */
|
|
||||||
export function parseWantsByWantNodeModuleKey(_key: string): { node: string; module: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("want.")) return undefined;
|
|
||||||
_rest = _rest.slice(5);
|
|
||||||
const _at1 = _rest.indexOf(".");
|
|
||||||
if (_at1 <= 0) return undefined;
|
|
||||||
const node = _rest.slice(0, _at1);
|
|
||||||
_rest = _rest.slice(_at1 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const module = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node, module };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state wants under the form "want.<node>.node". */
|
|
||||||
export function wantsByWantNodeNodeKey(node: string): string {
|
|
||||||
return "want." + node + ".node";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "want.<node>.node", or undefined for a key of another form. */
|
|
||||||
export function parseWantsByWantNodeNodeKey(_key: string): { node: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("want.")) return undefined;
|
|
||||||
_rest = _rest.slice(5);
|
|
||||||
const _at1 = _rest.indexOf(".node");
|
|
||||||
if (_at1 <= 0) return undefined;
|
|
||||||
const node = _rest.slice(0, _at1);
|
|
||||||
_rest = _rest.slice(_at1 + 5);
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state wants under the form "held.<module>.<fingerprint>". */
|
|
||||||
export function wantsByHeldModuleFingerprintKey(module: string, fingerprint: string): string {
|
|
||||||
return "held." + module + "." + fingerprint;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "held.<module>.<fingerprint>", or undefined for a key of another form. */
|
|
||||||
export function parseWantsByHeldModuleFingerprintKey(_key: string): { module: string; fingerprint: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("held.")) return undefined;
|
|
||||||
_rest = _rest.slice(5);
|
|
||||||
const _at1 = _rest.indexOf(".");
|
|
||||||
if (_at1 <= 0) return undefined;
|
|
||||||
const module = _rest.slice(0, _at1);
|
|
||||||
_rest = _rest.slice(_at1 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const fingerprint = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { module, fingerprint };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state differences under the form "<node>.<module>". */
|
|
||||||
export function differencesByNodeModuleKey(node: string, module: string): string {
|
|
||||||
return node + "." + module;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<node>.<module>", or undefined for a key of another form. */
|
|
||||||
export function parseDifferencesByNodeModuleKey(_key: string): { node: string; module: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const node = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const module = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node, module };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state compositions under the form "<group>.<heads>". */
|
|
||||||
export function compositionsByGroupHeadsKey(group: string, heads: string): string {
|
|
||||||
return group + "." + heads;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<group>.<heads>", or undefined for a key of another form. */
|
|
||||||
export function parseCompositionsByGroupHeadsKey(_key: string): { group: string; heads: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const group = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const heads = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { group, heads };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what upgrade takes. */
|
|
||||||
export interface UpgradeInput {
|
|
||||||
/** "true": each node's own composition, by its digest, and the assigner's findings */
|
|
||||||
"compare"?: "true" | "false";
|
|
||||||
/** one module */
|
|
||||||
"module"?: string;
|
|
||||||
/** with module: roll, together, record, or default to take a person's choice back */
|
|
||||||
"policy"?: string;
|
|
||||||
/** with policy: why, required and kept */
|
|
||||||
"why"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what upgrade answers. */
|
|
||||||
export type UpgradeAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what bus takes. */
|
|
||||||
export interface BusInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what bus answers. */
|
|
||||||
export type BusAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is the body of the event policy-changed. */
|
|
||||||
export type PolicyChangedEvent = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is one value of the state wants under the key want.<node>.<module>. */
|
|
||||||
export interface WantsByWantNodeModuleValue {
|
|
||||||
/** again or skip */
|
|
||||||
"backup"?: "again" | "skip";
|
|
||||||
"composed"?: string;
|
|
||||||
"fp"?: string;
|
|
||||||
"hold"?: boolean;
|
|
||||||
"newest"?: string;
|
|
||||||
"put"?: boolean;
|
|
||||||
"release"?: string;
|
|
||||||
"removed"?: boolean;
|
|
||||||
/** the rule that holds the node back, 1 to 10 */
|
|
||||||
"rule"?: number;
|
|
||||||
"self"?: boolean;
|
|
||||||
"v"?: number;
|
|
||||||
"words"?: string;
|
|
||||||
"yes"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state wants under the key want.<node>.node. */
|
|
||||||
export interface WantsByWantNodeNodeValue {
|
|
||||||
"composed": string;
|
|
||||||
"self"?: boolean;
|
|
||||||
"v"?: number;
|
|
||||||
"words"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state wants under the key held.<module>.<fingerprint>. */
|
|
||||||
export interface WantsByHeldModuleFingerprintValue {
|
|
||||||
"node": string;
|
|
||||||
"v"?: number;
|
|
||||||
"words"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state differences under the key <node>.<module>. */
|
|
||||||
export interface DifferencesByNodeModuleValue {
|
|
||||||
"rule"?: number;
|
|
||||||
"sent"?: string;
|
|
||||||
"sent-build"?: string;
|
|
||||||
"unexplained"?: boolean;
|
|
||||||
"v"?: number;
|
|
||||||
"want"?: string;
|
|
||||||
"want-removed"?: boolean;
|
|
||||||
"words"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is one value of the state compositions under the key <group>.<heads>. */
|
|
||||||
export interface CompositionsByGroupHeadsValue {
|
|
||||||
"group": string;
|
|
||||||
/** 12 lowercase hex digits */
|
|
||||||
"heads": string;
|
|
||||||
"machine"?: string;
|
|
||||||
"machines"?: string[];
|
|
||||||
"sdk"?: string;
|
|
||||||
/** pass, fail or waits */
|
|
||||||
"state": string;
|
|
||||||
/** milliseconds */
|
|
||||||
"took"?: number;
|
|
||||||
"v"?: number;
|
|
||||||
"warnings"?: string[];
|
|
||||||
"words"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
// Code generated by seatgen from the seat definitions; DO NOT EDIT.
|
|
||||||
|
|
||||||
// The contract of the seat "node-build-go", defined whole (seats/node-build-go/seat.json): The Go build module on a node: it takes the asks of the builder and the checker, runs them as steps and answers.
|
|
||||||
|
|
||||||
import type * as buildStep from "./parts/build-step.js";
|
|
||||||
|
|
||||||
export const seat = "node-build-go";
|
|
||||||
|
|
||||||
export const verbs = {
|
|
||||||
current: "current",
|
|
||||||
pause: "pause",
|
|
||||||
resume: "resume",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const accepts = {
|
|
||||||
delivery: "delivery",
|
|
||||||
check: "check",
|
|
||||||
recheck: "recheck",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const deliverySubject = "mesh.seat.node-build-go.accept.delivery";
|
|
||||||
|
|
||||||
export const checkSubject = "mesh.seat.node-build-go.accept.check";
|
|
||||||
|
|
||||||
export const recheckSubject = "mesh.seat.node-build-go.accept.recheck";
|
|
||||||
|
|
||||||
export const states = {
|
|
||||||
steps: "steps",
|
|
||||||
pauses: "pauses",
|
|
||||||
toolchains: "toolchains",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/** The key of one value of the state steps under the form "<node>.<id>". */
|
|
||||||
export function stepsByNodeIDKey(node: string, id: string): string {
|
|
||||||
return node + "." + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<node>.<id>", or undefined for a key of another form. */
|
|
||||||
export function parseStepsByNodeIDKey(_key: string): { node: string; id: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const node = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const id = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node, id };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state pauses under the form "paused.<node>". */
|
|
||||||
export function pausesByPausedNodeKey(node: string): string {
|
|
||||||
return "paused." + node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "paused.<node>", or undefined for a key of another form. */
|
|
||||||
export function parsePausesByPausedNodeKey(_key: string): { node: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("paused.")) return undefined;
|
|
||||||
_rest = _rest.slice(7);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const node = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state pauses under the form "capacity.<node>". */
|
|
||||||
export function pausesByCapacityNodeKey(node: string): string {
|
|
||||||
return "capacity." + node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "capacity.<node>", or undefined for a key of another form. */
|
|
||||||
export function parsePausesByCapacityNodeKey(_key: string): { node: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("capacity.")) return undefined;
|
|
||||||
_rest = _rest.slice(9);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const node = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state toolchains under the form "<node>.<language>". */
|
|
||||||
export function toolchainsByNodeLanguageKey(node: string, language: string): string {
|
|
||||||
return node + "." + language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<node>.<language>", or undefined for a key of another form. */
|
|
||||||
export function parseToolchainsByNodeLanguageKey(_key: string): { node: string; language: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const node = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const language = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node, language };
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AskArtifact = buildStep.AskArtifact;
|
|
||||||
export type BuildAnswer = buildStep.BuildAnswer;
|
|
||||||
export type BuiltArtifact = buildStep.BuiltArtifact;
|
|
||||||
export type Capacity = buildStep.Capacity;
|
|
||||||
export type CheckAnswer = buildStep.CheckAnswer;
|
|
||||||
export type ComposeAnswer = buildStep.ComposeAnswer;
|
|
||||||
export type CurrentAnswer = buildStep.CurrentAnswer;
|
|
||||||
export type CurrentInput = buildStep.CurrentInput;
|
|
||||||
export type Fetch = buildStep.Fetch;
|
|
||||||
export type FetchAnswer = buildStep.FetchAnswer;
|
|
||||||
export type FetchBesideItem = buildStep.FetchBesideItem;
|
|
||||||
export type FetchPackage = buildStep.FetchPackage;
|
|
||||||
export type FetchRefusal = buildStep.FetchRefusal;
|
|
||||||
export type LevelAnswer = buildStep.LevelAnswer;
|
|
||||||
export type LevelAnswerDigest = buildStep.LevelAnswerDigest;
|
|
||||||
export type LevelAnswerDigestNeedsItem = buildStep.LevelAnswerDigestNeedsItem;
|
|
||||||
export type LevelAnswerDigestPackagesItem = buildStep.LevelAnswerDigestPackagesItem;
|
|
||||||
export type LevelAnswerKeptItem = buildStep.LevelAnswerKeptItem;
|
|
||||||
export type LevelAnswerUnmetItem = buildStep.LevelAnswerUnmetItem;
|
|
||||||
export type ModuleTree = buildStep.ModuleTree;
|
|
||||||
export type Pause = buildStep.Pause;
|
|
||||||
export type PauseAnswer = buildStep.PauseAnswer;
|
|
||||||
export type PauseInput = buildStep.PauseInput;
|
|
||||||
export type PlacedBeside = buildStep.PlacedBeside;
|
|
||||||
export type Program = buildStep.Program;
|
|
||||||
export type ResumeAnswer = buildStep.ResumeAnswer;
|
|
||||||
export type ResumeInput = buildStep.ResumeInput;
|
|
||||||
export type RunAnswer = buildStep.RunAnswer;
|
|
||||||
export type RunHead = buildStep.RunHead;
|
|
||||||
export type RunInput = buildStep.RunInput;
|
|
||||||
export type RunJob = buildStep.RunJob;
|
|
||||||
export type RunProgram = buildStep.RunProgram;
|
|
||||||
export type Step = buildStep.Step;
|
|
||||||
export type StepAsk = buildStep.StepAsk;
|
|
||||||
export type StepAskBuild = buildStep.StepAskBuild;
|
|
||||||
export type StepAskCheck = buildStep.StepAskCheck;
|
|
||||||
export type StepAskCompose = buildStep.StepAskCompose;
|
|
||||||
export type StepResult = buildStep.StepResult;
|
|
||||||
export type TakenVersion = buildStep.TakenVersion;
|
|
||||||
export type Toolchain = buildStep.Toolchain;
|
|
||||||
export type ToolchainUsed = buildStep.ToolchainUsed;
|
|
||||||
|
|
||||||
/** is the body of delivery. */
|
|
||||||
export type DeliveryAccept = StepAsk;
|
|
||||||
|
|
||||||
/** is the body of check. */
|
|
||||||
export type CheckAccept = StepAsk;
|
|
||||||
|
|
||||||
/** is the body of recheck. */
|
|
||||||
export type RecheckAccept = StepAsk;
|
|
||||||
|
|
||||||
/** is one value of the state steps under the key <node>.<id>. */
|
|
||||||
export type StepsByNodeIDValue = Step;
|
|
||||||
|
|
||||||
/** is one value of the state pauses under the key paused.<node>. */
|
|
||||||
export type PausesByPausedNodeValue = Pause;
|
|
||||||
|
|
||||||
/** is one value of the state pauses under the key capacity.<node>. */
|
|
||||||
export type PausesByCapacityNodeValue = Capacity;
|
|
||||||
|
|
||||||
/** is one value of the state toolchains under the key <node>.<language>. */
|
|
||||||
export type ToolchainsByNodeLanguageValue = Toolchain;
|
|
||||||
|
|
||||||
@@ -1,398 +0,0 @@
|
|||||||
// Code generated by seatgen from the seat definitions; DO NOT EDIT.
|
|
||||||
|
|
||||||
// The part "build-step" several seats include whole: What the three build seats share: the verbs that read and steer a node's builds, and the layouts of the asks they accept and the steps they keep. A seat lists its states against these (a part carries no states).
|
|
||||||
|
|
||||||
export const verbs = {
|
|
||||||
current: "current",
|
|
||||||
pause: "pause",
|
|
||||||
resume: "resume",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/** one artifact of a build ask: built from the fetched tree, or copied from an upstream pin */
|
|
||||||
export interface AskArtifact {
|
|
||||||
"artifact": string;
|
|
||||||
"from"?: string;
|
|
||||||
"seat"?: string;
|
|
||||||
"version"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BuildAnswer {
|
|
||||||
"artifacts": BuiltArtifact[];
|
|
||||||
"imports"?: string[];
|
|
||||||
"out-of-step"?: string[];
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one artifact a build made: its digest and the reference it was published under */
|
|
||||||
export interface BuiltArtifact {
|
|
||||||
"artifact": string;
|
|
||||||
"digest": string;
|
|
||||||
"reference"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** how many steps the node runs at once */
|
|
||||||
export interface Capacity {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"build-hours"?: string;
|
|
||||||
"build-hours-fault"?: string;
|
|
||||||
"by-cpu"?: number;
|
|
||||||
"configured": number;
|
|
||||||
"configured-from"?: string;
|
|
||||||
"cores-per-step"?: number;
|
|
||||||
"effective": number;
|
|
||||||
"ineligible"?: string;
|
|
||||||
"outside-hours"?: boolean;
|
|
||||||
"quota-cores"?: number;
|
|
||||||
"quota-from"?: string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"why": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CheckAnswer {
|
|
||||||
"fetch": FetchAnswer;
|
|
||||||
"levels"?: LevelAnswer[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ComposeAnswer {
|
|
||||||
"built": boolean;
|
|
||||||
"key"?: string;
|
|
||||||
/** the compose-candidate verdict */
|
|
||||||
"verdict"?: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FetchBesideItem {
|
|
||||||
"commit": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the TypeScript module's group package: the group's tagged version of the SDK ({name, version}), placed from the registry in each member whatever its lock names, or the group's package member ({repository, commit, ref}), packed by the fetch and served to the members in place of the registry's */
|
|
||||||
export interface FetchPackage {
|
|
||||||
"commit"?: string;
|
|
||||||
"name"?: string;
|
|
||||||
"ref"?: string;
|
|
||||||
"repository"?: string;
|
|
||||||
"version"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a build module's fetch tool is asked: the repository and the full commit, the pull request's ref when only its head carries the commit, the trunk commit to merge onto for a merge preview, the module's directory and named paths, the mesh packages to build against, and the sibling repositories placed beside */
|
|
||||||
export interface Fetch {
|
|
||||||
/** the trunk commit a merge preview merges onto */
|
|
||||||
"base"?: string;
|
|
||||||
/** the sibling repositories placed beside the fetched tree */
|
|
||||||
"beside"?: FetchBesideItem[];
|
|
||||||
/** the full commit */
|
|
||||||
"commit": string;
|
|
||||||
/** the module's directory in the repository ("." for its root), with paths */
|
|
||||||
"dir"?: string;
|
|
||||||
/** the TypeScript module's group package: the group's tagged version of the SDK ({name, version}), placed from the registry in each member whatever its lock names, or the group's package member ({repository, commit, ref}), packed by the fetch and served to the members in place of the registry's */
|
|
||||||
"package"?: FetchPackage;
|
|
||||||
/** the version (a full commit) of each mesh package to build against, by its module path */
|
|
||||||
"packages"?: Record<string, string>;
|
|
||||||
/** the paths the module names, relative to dir */
|
|
||||||
"paths"?: string[];
|
|
||||||
/** the pull request's ref, when only its head carries the commit */
|
|
||||||
"ref"?: string;
|
|
||||||
/** <owner>/<name> */
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a build module's fetch tool answers, whole: the workspace it made, the commit in it, the module directories found; and, when the call gave a base, the merge preview (the trunk commit, the merge commit, the files that conflict, the paths the merge changes, the compiled programs among them, the tree of each module directory). A head that does not merge cleanly is an answer, not an error: merge is empty and conflicts names the files. The Go module adds the sibling repositories placed and the package versions taken; the TypeScript module the directories installed and refused and the group's package */
|
|
||||||
export interface FetchAnswer {
|
|
||||||
"base"?: string;
|
|
||||||
"beside"?: PlacedBeside[];
|
|
||||||
"changed"?: string[];
|
|
||||||
"commit": string;
|
|
||||||
"conflicts"?: string[];
|
|
||||||
"group"?: string;
|
|
||||||
"installed"?: string[];
|
|
||||||
"merge"?: string;
|
|
||||||
"modules": string[];
|
|
||||||
"packages"?: TakenVersion[];
|
|
||||||
"programs"?: Program[];
|
|
||||||
"refused"?: FetchRefusal[];
|
|
||||||
"trees"?: Record<string, ModuleTree>;
|
|
||||||
"workspace": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a TypeScript module whose packages the fetch did not install, with why */
|
|
||||||
export interface FetchRefusal {
|
|
||||||
"module": string;
|
|
||||||
"reason": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerDigestNeedsItem {
|
|
||||||
"needs"?: string[];
|
|
||||||
"package"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerDigestPackagesItem {
|
|
||||||
"digest": string;
|
|
||||||
"package": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerDigest {
|
|
||||||
"beside"?: string[];
|
|
||||||
"judged_by"?: string;
|
|
||||||
"level"?: string;
|
|
||||||
"needs"?: LevelAnswerDigestNeedsItem[];
|
|
||||||
"packages"?: LevelAnswerDigestPackagesItem[];
|
|
||||||
"without_tests"?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerKeptItem {
|
|
||||||
"digest"?: string;
|
|
||||||
"package"?: string;
|
|
||||||
"tests"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerUnmetItem {
|
|
||||||
"needs"?: string[];
|
|
||||||
"package"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one level of a check ask: the digest's answer, the kept verdicts taken, one test result per test step run, and the packages the node could not test */
|
|
||||||
export interface LevelAnswer {
|
|
||||||
"digest"?: LevelAnswerDigest;
|
|
||||||
"judged"?: string;
|
|
||||||
"kept"?: LevelAnswerKeptItem[];
|
|
||||||
"level": string;
|
|
||||||
"tests"?: unknown[];
|
|
||||||
"unmet"?: LevelAnswerUnmetItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the tree of one module directory in a merge preview: its git tree, the digest of its manifest, the lock files' digests and the digests of the named paths */
|
|
||||||
export interface ModuleTree {
|
|
||||||
"locks"?: Record<string, string>;
|
|
||||||
"manifest": string;
|
|
||||||
/** no longer filled (ADR 0593 section 2); kept so a preview written before still reads */
|
|
||||||
"packages"?: string[];
|
|
||||||
"paths"?: Record<string, string>;
|
|
||||||
"tree": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** whether the node takes no new ask */
|
|
||||||
export interface Pause {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"by"?: string;
|
|
||||||
"paused": boolean;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a sibling repository placed as a plain directory under the workspace's beside directory */
|
|
||||||
export interface PlacedBeside {
|
|
||||||
"commit": string;
|
|
||||||
"dir": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a changed file that is a compiled program (issue 1577): its path, its executable format, and the commit of the branch that added it when the merge's tree no longer holds it */
|
|
||||||
export interface Program {
|
|
||||||
"commit"?: string;
|
|
||||||
/** ELF, Mach-O or PE */
|
|
||||||
"kind": string;
|
|
||||||
"path": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a run ask's step answers: whether this run built the program or took the one kept under its key, the key, the program's exit, the last line of its standard output and the first of its standard error */
|
|
||||||
export interface RunAnswer {
|
|
||||||
"built": boolean;
|
|
||||||
"exit": number;
|
|
||||||
"key": string;
|
|
||||||
/** raw when it is JSON, else a JSON string */
|
|
||||||
"output"?: unknown;
|
|
||||||
"said"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one commit a run's program reads */
|
|
||||||
export interface RunHead {
|
|
||||||
"commit": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a run's input by reference: the seat verb the asker serves it on (seat:<seat>.<verb>), the sha256 of its bytes and its size, at most 256 KiB */
|
|
||||||
export interface RunInput {
|
|
||||||
/** 64 lowercase hex digits */
|
|
||||||
"digest": string;
|
|
||||||
/** bytes */
|
|
||||||
"size": number;
|
|
||||||
"verb": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a run ask's job: where its program is built, the heads it reads (each laid read-only at its repository's path), its input by reference, its arguments and what it is for */
|
|
||||||
export interface RunJob {
|
|
||||||
/** the program's arguments, each a word or a flag */
|
|
||||||
"args"?: string[];
|
|
||||||
/** the commits the program reads, a repository at most once */
|
|
||||||
"heads": RunHead[];
|
|
||||||
"input": RunInput;
|
|
||||||
"program": RunProgram;
|
|
||||||
/** what the run is for, for a reader of the ask */
|
|
||||||
"reader"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** where a run's program is built: the repository and full commit fetched, the Go module's directory in it and the program's import path */
|
|
||||||
export interface RunProgram {
|
|
||||||
"commit": string;
|
|
||||||
"dir": string;
|
|
||||||
"package": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one step a build module runs on a node */
|
|
||||||
export interface Step {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"ended"?: string;
|
|
||||||
"id": string;
|
|
||||||
"node": string;
|
|
||||||
"owner"?: string;
|
|
||||||
"phase"?: string;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"phase-at"?: string;
|
|
||||||
"reason"?: string;
|
|
||||||
"result"?: StepResult;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"started": string;
|
|
||||||
/** running, passed, failed or refused */
|
|
||||||
"state": string;
|
|
||||||
"tool": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"what"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StepAskBuild {
|
|
||||||
"artifacts": AskArtifact[];
|
|
||||||
"fetch"?: Fetch;
|
|
||||||
"fp"?: string;
|
|
||||||
"module": string;
|
|
||||||
"path"?: string;
|
|
||||||
"publish"?: boolean;
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StepAskCheck {
|
|
||||||
"fetch": Fetch;
|
|
||||||
"kept"?: boolean;
|
|
||||||
"levels": string[];
|
|
||||||
/** the node names the check's tests run against */
|
|
||||||
"node-names"?: string[];
|
|
||||||
"packages"?: string[];
|
|
||||||
"run"?: string;
|
|
||||||
"runner"?: string;
|
|
||||||
"runner_when"?: string;
|
|
||||||
/** the toolchain the checker agreed for the language (ADR 0584 clause 2): a node on another declines the check */
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StepAskCompose {
|
|
||||||
"dir": string;
|
|
||||||
"fetch": Fetch;
|
|
||||||
"package": string;
|
|
||||||
"reader"?: string;
|
|
||||||
/** the compose-candidate request */
|
|
||||||
"request": unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one ask of a build module */
|
|
||||||
export interface StepAsk {
|
|
||||||
"asker": string;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"build"?: StepAskBuild;
|
|
||||||
"check"?: StepAskCheck;
|
|
||||||
"compose"?: StepAskCompose;
|
|
||||||
"id": string;
|
|
||||||
/** build, check or compose */
|
|
||||||
"kind": string;
|
|
||||||
/** go, typescript or image */
|
|
||||||
"language": string;
|
|
||||||
"needs"?: string[];
|
|
||||||
/** package to the tagged version a build pins */
|
|
||||||
"packages"?: Record<string, string>;
|
|
||||||
/** a run: a program built from a change and run in the build seat's sandbox over the heads, its input asked of a verb of the asker's seat; the Go seat's check stream alone carries it, as a compose */
|
|
||||||
"run"?: RunJob;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a step answered, by the kind of ask: a build's artifacts, toolchain, imports and out-of-step modules; a check's fetch and levels; a compose's built, key and verdict; a run's built, key, exit, output and said; a declined ask's declined, needs and lacks. The fields of the kinds do not meet, so one layout holds the five */
|
|
||||||
export interface StepResult {
|
|
||||||
"artifacts"?: BuiltArtifact[];
|
|
||||||
"built"?: boolean;
|
|
||||||
/** the holder declined the ask: its node lacks what the ask needs */
|
|
||||||
"declined"?: boolean;
|
|
||||||
/** a run's program's exit status */
|
|
||||||
"exit"?: number;
|
|
||||||
"fetch"?: FetchAnswer;
|
|
||||||
"imports"?: string[];
|
|
||||||
"key"?: string;
|
|
||||||
/** what the holder's node lacks of it */
|
|
||||||
"lacks"?: string[];
|
|
||||||
"levels"?: LevelAnswer[];
|
|
||||||
/** what the declined ask needs */
|
|
||||||
"needs"?: string[];
|
|
||||||
"out-of-step"?: string[];
|
|
||||||
/** a run's program's last line of standard output: raw when it is JSON, else a JSON string */
|
|
||||||
"output"?: unknown;
|
|
||||||
/** a run's program's first line of standard error, or why the step could not run it */
|
|
||||||
"said"?: string;
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
/** the compose-candidate verdict (the composer's own layout) */
|
|
||||||
"verdict"?: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** of a directory whose go.mod requires an asked mesh package, the version it is built against: the asked one, or go.mod's when it names a newer one, said */
|
|
||||||
export interface TakenVersion {
|
|
||||||
"asked": string;
|
|
||||||
"built": string;
|
|
||||||
"dir": string;
|
|
||||||
"named": string;
|
|
||||||
"package": string;
|
|
||||||
"said"?: string;
|
|
||||||
"sum"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the toolchain a node reports */
|
|
||||||
export interface Toolchain {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
/** go or typescript */
|
|
||||||
"language": string;
|
|
||||||
"recipe": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"version": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the toolchain a build was made with: the language, the installed version and the build module's recipe */
|
|
||||||
export interface ToolchainUsed {
|
|
||||||
"language": string;
|
|
||||||
"recipe": string;
|
|
||||||
"version": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what current takes. */
|
|
||||||
export interface CurrentInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what current answers. */
|
|
||||||
export type CurrentAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what pause takes. */
|
|
||||||
export interface PauseInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what pause answers. */
|
|
||||||
export type PauseAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what resume takes. */
|
|
||||||
export interface ResumeInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what resume answers. */
|
|
||||||
export type ResumeAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
// Code generated by seatgen from the seat definitions; DO NOT EDIT.
|
|
||||||
|
|
||||||
// The contract of the seat "node-build-image", defined whole (seats/node-build-image/seat.json): The image build module on a node: it takes the asks of the builder and the checker, runs them as steps and answers.
|
|
||||||
|
|
||||||
import type * as buildStep from "./parts/build-step.js";
|
|
||||||
|
|
||||||
export const seat = "node-build-image";
|
|
||||||
|
|
||||||
export const verbs = {
|
|
||||||
current: "current",
|
|
||||||
pause: "pause",
|
|
||||||
resume: "resume",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const accepts = {
|
|
||||||
delivery: "delivery",
|
|
||||||
check: "check",
|
|
||||||
recheck: "recheck",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const deliverySubject = "mesh.seat.node-build-image.accept.delivery";
|
|
||||||
|
|
||||||
export const checkSubject = "mesh.seat.node-build-image.accept.check";
|
|
||||||
|
|
||||||
export const recheckSubject = "mesh.seat.node-build-image.accept.recheck";
|
|
||||||
|
|
||||||
export const states = {
|
|
||||||
steps: "steps",
|
|
||||||
pauses: "pauses",
|
|
||||||
toolchains: "toolchains",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/** The key of one value of the state steps under the form "<node>.<id>". */
|
|
||||||
export function stepsByNodeIDKey(node: string, id: string): string {
|
|
||||||
return node + "." + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<node>.<id>", or undefined for a key of another form. */
|
|
||||||
export function parseStepsByNodeIDKey(_key: string): { node: string; id: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const node = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const id = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node, id };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state pauses under the form "paused.<node>". */
|
|
||||||
export function pausesByPausedNodeKey(node: string): string {
|
|
||||||
return "paused." + node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "paused.<node>", or undefined for a key of another form. */
|
|
||||||
export function parsePausesByPausedNodeKey(_key: string): { node: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("paused.")) return undefined;
|
|
||||||
_rest = _rest.slice(7);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const node = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state pauses under the form "capacity.<node>". */
|
|
||||||
export function pausesByCapacityNodeKey(node: string): string {
|
|
||||||
return "capacity." + node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "capacity.<node>", or undefined for a key of another form. */
|
|
||||||
export function parsePausesByCapacityNodeKey(_key: string): { node: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("capacity.")) return undefined;
|
|
||||||
_rest = _rest.slice(9);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const node = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state toolchains under the form "<node>.<language>". */
|
|
||||||
export function toolchainsByNodeLanguageKey(node: string, language: string): string {
|
|
||||||
return node + "." + language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<node>.<language>", or undefined for a key of another form. */
|
|
||||||
export function parseToolchainsByNodeLanguageKey(_key: string): { node: string; language: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const node = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const language = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node, language };
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AskArtifact = buildStep.AskArtifact;
|
|
||||||
export type BuildAnswer = buildStep.BuildAnswer;
|
|
||||||
export type BuiltArtifact = buildStep.BuiltArtifact;
|
|
||||||
export type Capacity = buildStep.Capacity;
|
|
||||||
export type CheckAnswer = buildStep.CheckAnswer;
|
|
||||||
export type ComposeAnswer = buildStep.ComposeAnswer;
|
|
||||||
export type CurrentAnswer = buildStep.CurrentAnswer;
|
|
||||||
export type CurrentInput = buildStep.CurrentInput;
|
|
||||||
export type Fetch = buildStep.Fetch;
|
|
||||||
export type FetchAnswer = buildStep.FetchAnswer;
|
|
||||||
export type FetchBesideItem = buildStep.FetchBesideItem;
|
|
||||||
export type FetchPackage = buildStep.FetchPackage;
|
|
||||||
export type FetchRefusal = buildStep.FetchRefusal;
|
|
||||||
export type LevelAnswer = buildStep.LevelAnswer;
|
|
||||||
export type LevelAnswerDigest = buildStep.LevelAnswerDigest;
|
|
||||||
export type LevelAnswerDigestNeedsItem = buildStep.LevelAnswerDigestNeedsItem;
|
|
||||||
export type LevelAnswerDigestPackagesItem = buildStep.LevelAnswerDigestPackagesItem;
|
|
||||||
export type LevelAnswerKeptItem = buildStep.LevelAnswerKeptItem;
|
|
||||||
export type LevelAnswerUnmetItem = buildStep.LevelAnswerUnmetItem;
|
|
||||||
export type ModuleTree = buildStep.ModuleTree;
|
|
||||||
export type Pause = buildStep.Pause;
|
|
||||||
export type PauseAnswer = buildStep.PauseAnswer;
|
|
||||||
export type PauseInput = buildStep.PauseInput;
|
|
||||||
export type PlacedBeside = buildStep.PlacedBeside;
|
|
||||||
export type Program = buildStep.Program;
|
|
||||||
export type ResumeAnswer = buildStep.ResumeAnswer;
|
|
||||||
export type ResumeInput = buildStep.ResumeInput;
|
|
||||||
export type RunAnswer = buildStep.RunAnswer;
|
|
||||||
export type RunHead = buildStep.RunHead;
|
|
||||||
export type RunInput = buildStep.RunInput;
|
|
||||||
export type RunJob = buildStep.RunJob;
|
|
||||||
export type RunProgram = buildStep.RunProgram;
|
|
||||||
export type Step = buildStep.Step;
|
|
||||||
export type StepAsk = buildStep.StepAsk;
|
|
||||||
export type StepAskBuild = buildStep.StepAskBuild;
|
|
||||||
export type StepAskCheck = buildStep.StepAskCheck;
|
|
||||||
export type StepAskCompose = buildStep.StepAskCompose;
|
|
||||||
export type StepResult = buildStep.StepResult;
|
|
||||||
export type TakenVersion = buildStep.TakenVersion;
|
|
||||||
export type Toolchain = buildStep.Toolchain;
|
|
||||||
export type ToolchainUsed = buildStep.ToolchainUsed;
|
|
||||||
|
|
||||||
/** is the body of delivery. */
|
|
||||||
export type DeliveryAccept = StepAsk;
|
|
||||||
|
|
||||||
/** is the body of check. */
|
|
||||||
export type CheckAccept = StepAsk;
|
|
||||||
|
|
||||||
/** is the body of recheck. */
|
|
||||||
export type RecheckAccept = StepAsk;
|
|
||||||
|
|
||||||
/** is one value of the state steps under the key <node>.<id>. */
|
|
||||||
export type StepsByNodeIDValue = Step;
|
|
||||||
|
|
||||||
/** is one value of the state pauses under the key paused.<node>. */
|
|
||||||
export type PausesByPausedNodeValue = Pause;
|
|
||||||
|
|
||||||
/** is one value of the state pauses under the key capacity.<node>. */
|
|
||||||
export type PausesByCapacityNodeValue = Capacity;
|
|
||||||
|
|
||||||
/** is one value of the state toolchains under the key <node>.<language>. */
|
|
||||||
export type ToolchainsByNodeLanguageValue = Toolchain;
|
|
||||||
|
|
||||||
@@ -1,398 +0,0 @@
|
|||||||
// Code generated by seatgen from the seat definitions; DO NOT EDIT.
|
|
||||||
|
|
||||||
// The part "build-step" several seats include whole: What the three build seats share: the verbs that read and steer a node's builds, and the layouts of the asks they accept and the steps they keep. A seat lists its states against these (a part carries no states).
|
|
||||||
|
|
||||||
export const verbs = {
|
|
||||||
current: "current",
|
|
||||||
pause: "pause",
|
|
||||||
resume: "resume",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/** one artifact of a build ask: built from the fetched tree, or copied from an upstream pin */
|
|
||||||
export interface AskArtifact {
|
|
||||||
"artifact": string;
|
|
||||||
"from"?: string;
|
|
||||||
"seat"?: string;
|
|
||||||
"version"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BuildAnswer {
|
|
||||||
"artifacts": BuiltArtifact[];
|
|
||||||
"imports"?: string[];
|
|
||||||
"out-of-step"?: string[];
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one artifact a build made: its digest and the reference it was published under */
|
|
||||||
export interface BuiltArtifact {
|
|
||||||
"artifact": string;
|
|
||||||
"digest": string;
|
|
||||||
"reference"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** how many steps the node runs at once */
|
|
||||||
export interface Capacity {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"build-hours"?: string;
|
|
||||||
"build-hours-fault"?: string;
|
|
||||||
"by-cpu"?: number;
|
|
||||||
"configured": number;
|
|
||||||
"configured-from"?: string;
|
|
||||||
"cores-per-step"?: number;
|
|
||||||
"effective": number;
|
|
||||||
"ineligible"?: string;
|
|
||||||
"outside-hours"?: boolean;
|
|
||||||
"quota-cores"?: number;
|
|
||||||
"quota-from"?: string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"why": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CheckAnswer {
|
|
||||||
"fetch": FetchAnswer;
|
|
||||||
"levels"?: LevelAnswer[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ComposeAnswer {
|
|
||||||
"built": boolean;
|
|
||||||
"key"?: string;
|
|
||||||
/** the compose-candidate verdict */
|
|
||||||
"verdict"?: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FetchBesideItem {
|
|
||||||
"commit": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the TypeScript module's group package: the group's tagged version of the SDK ({name, version}), placed from the registry in each member whatever its lock names, or the group's package member ({repository, commit, ref}), packed by the fetch and served to the members in place of the registry's */
|
|
||||||
export interface FetchPackage {
|
|
||||||
"commit"?: string;
|
|
||||||
"name"?: string;
|
|
||||||
"ref"?: string;
|
|
||||||
"repository"?: string;
|
|
||||||
"version"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a build module's fetch tool is asked: the repository and the full commit, the pull request's ref when only its head carries the commit, the trunk commit to merge onto for a merge preview, the module's directory and named paths, the mesh packages to build against, and the sibling repositories placed beside */
|
|
||||||
export interface Fetch {
|
|
||||||
/** the trunk commit a merge preview merges onto */
|
|
||||||
"base"?: string;
|
|
||||||
/** the sibling repositories placed beside the fetched tree */
|
|
||||||
"beside"?: FetchBesideItem[];
|
|
||||||
/** the full commit */
|
|
||||||
"commit": string;
|
|
||||||
/** the module's directory in the repository ("." for its root), with paths */
|
|
||||||
"dir"?: string;
|
|
||||||
/** the TypeScript module's group package: the group's tagged version of the SDK ({name, version}), placed from the registry in each member whatever its lock names, or the group's package member ({repository, commit, ref}), packed by the fetch and served to the members in place of the registry's */
|
|
||||||
"package"?: FetchPackage;
|
|
||||||
/** the version (a full commit) of each mesh package to build against, by its module path */
|
|
||||||
"packages"?: Record<string, string>;
|
|
||||||
/** the paths the module names, relative to dir */
|
|
||||||
"paths"?: string[];
|
|
||||||
/** the pull request's ref, when only its head carries the commit */
|
|
||||||
"ref"?: string;
|
|
||||||
/** <owner>/<name> */
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a build module's fetch tool answers, whole: the workspace it made, the commit in it, the module directories found; and, when the call gave a base, the merge preview (the trunk commit, the merge commit, the files that conflict, the paths the merge changes, the compiled programs among them, the tree of each module directory). A head that does not merge cleanly is an answer, not an error: merge is empty and conflicts names the files. The Go module adds the sibling repositories placed and the package versions taken; the TypeScript module the directories installed and refused and the group's package */
|
|
||||||
export interface FetchAnswer {
|
|
||||||
"base"?: string;
|
|
||||||
"beside"?: PlacedBeside[];
|
|
||||||
"changed"?: string[];
|
|
||||||
"commit": string;
|
|
||||||
"conflicts"?: string[];
|
|
||||||
"group"?: string;
|
|
||||||
"installed"?: string[];
|
|
||||||
"merge"?: string;
|
|
||||||
"modules": string[];
|
|
||||||
"packages"?: TakenVersion[];
|
|
||||||
"programs"?: Program[];
|
|
||||||
"refused"?: FetchRefusal[];
|
|
||||||
"trees"?: Record<string, ModuleTree>;
|
|
||||||
"workspace": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a TypeScript module whose packages the fetch did not install, with why */
|
|
||||||
export interface FetchRefusal {
|
|
||||||
"module": string;
|
|
||||||
"reason": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerDigestNeedsItem {
|
|
||||||
"needs"?: string[];
|
|
||||||
"package"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerDigestPackagesItem {
|
|
||||||
"digest": string;
|
|
||||||
"package": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerDigest {
|
|
||||||
"beside"?: string[];
|
|
||||||
"judged_by"?: string;
|
|
||||||
"level"?: string;
|
|
||||||
"needs"?: LevelAnswerDigestNeedsItem[];
|
|
||||||
"packages"?: LevelAnswerDigestPackagesItem[];
|
|
||||||
"without_tests"?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerKeptItem {
|
|
||||||
"digest"?: string;
|
|
||||||
"package"?: string;
|
|
||||||
"tests"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerUnmetItem {
|
|
||||||
"needs"?: string[];
|
|
||||||
"package"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one level of a check ask: the digest's answer, the kept verdicts taken, one test result per test step run, and the packages the node could not test */
|
|
||||||
export interface LevelAnswer {
|
|
||||||
"digest"?: LevelAnswerDigest;
|
|
||||||
"judged"?: string;
|
|
||||||
"kept"?: LevelAnswerKeptItem[];
|
|
||||||
"level": string;
|
|
||||||
"tests"?: unknown[];
|
|
||||||
"unmet"?: LevelAnswerUnmetItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the tree of one module directory in a merge preview: its git tree, the digest of its manifest, the lock files' digests and the digests of the named paths */
|
|
||||||
export interface ModuleTree {
|
|
||||||
"locks"?: Record<string, string>;
|
|
||||||
"manifest": string;
|
|
||||||
/** no longer filled (ADR 0593 section 2); kept so a preview written before still reads */
|
|
||||||
"packages"?: string[];
|
|
||||||
"paths"?: Record<string, string>;
|
|
||||||
"tree": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** whether the node takes no new ask */
|
|
||||||
export interface Pause {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"by"?: string;
|
|
||||||
"paused": boolean;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a sibling repository placed as a plain directory under the workspace's beside directory */
|
|
||||||
export interface PlacedBeside {
|
|
||||||
"commit": string;
|
|
||||||
"dir": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a changed file that is a compiled program (issue 1577): its path, its executable format, and the commit of the branch that added it when the merge's tree no longer holds it */
|
|
||||||
export interface Program {
|
|
||||||
"commit"?: string;
|
|
||||||
/** ELF, Mach-O or PE */
|
|
||||||
"kind": string;
|
|
||||||
"path": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a run ask's step answers: whether this run built the program or took the one kept under its key, the key, the program's exit, the last line of its standard output and the first of its standard error */
|
|
||||||
export interface RunAnswer {
|
|
||||||
"built": boolean;
|
|
||||||
"exit": number;
|
|
||||||
"key": string;
|
|
||||||
/** raw when it is JSON, else a JSON string */
|
|
||||||
"output"?: unknown;
|
|
||||||
"said"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one commit a run's program reads */
|
|
||||||
export interface RunHead {
|
|
||||||
"commit": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a run's input by reference: the seat verb the asker serves it on (seat:<seat>.<verb>), the sha256 of its bytes and its size, at most 256 KiB */
|
|
||||||
export interface RunInput {
|
|
||||||
/** 64 lowercase hex digits */
|
|
||||||
"digest": string;
|
|
||||||
/** bytes */
|
|
||||||
"size": number;
|
|
||||||
"verb": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a run ask's job: where its program is built, the heads it reads (each laid read-only at its repository's path), its input by reference, its arguments and what it is for */
|
|
||||||
export interface RunJob {
|
|
||||||
/** the program's arguments, each a word or a flag */
|
|
||||||
"args"?: string[];
|
|
||||||
/** the commits the program reads, a repository at most once */
|
|
||||||
"heads": RunHead[];
|
|
||||||
"input": RunInput;
|
|
||||||
"program": RunProgram;
|
|
||||||
/** what the run is for, for a reader of the ask */
|
|
||||||
"reader"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** where a run's program is built: the repository and full commit fetched, the Go module's directory in it and the program's import path */
|
|
||||||
export interface RunProgram {
|
|
||||||
"commit": string;
|
|
||||||
"dir": string;
|
|
||||||
"package": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one step a build module runs on a node */
|
|
||||||
export interface Step {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"ended"?: string;
|
|
||||||
"id": string;
|
|
||||||
"node": string;
|
|
||||||
"owner"?: string;
|
|
||||||
"phase"?: string;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"phase-at"?: string;
|
|
||||||
"reason"?: string;
|
|
||||||
"result"?: StepResult;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"started": string;
|
|
||||||
/** running, passed, failed or refused */
|
|
||||||
"state": string;
|
|
||||||
"tool": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"what"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StepAskBuild {
|
|
||||||
"artifacts": AskArtifact[];
|
|
||||||
"fetch"?: Fetch;
|
|
||||||
"fp"?: string;
|
|
||||||
"module": string;
|
|
||||||
"path"?: string;
|
|
||||||
"publish"?: boolean;
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StepAskCheck {
|
|
||||||
"fetch": Fetch;
|
|
||||||
"kept"?: boolean;
|
|
||||||
"levels": string[];
|
|
||||||
/** the node names the check's tests run against */
|
|
||||||
"node-names"?: string[];
|
|
||||||
"packages"?: string[];
|
|
||||||
"run"?: string;
|
|
||||||
"runner"?: string;
|
|
||||||
"runner_when"?: string;
|
|
||||||
/** the toolchain the checker agreed for the language (ADR 0584 clause 2): a node on another declines the check */
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StepAskCompose {
|
|
||||||
"dir": string;
|
|
||||||
"fetch": Fetch;
|
|
||||||
"package": string;
|
|
||||||
"reader"?: string;
|
|
||||||
/** the compose-candidate request */
|
|
||||||
"request": unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one ask of a build module */
|
|
||||||
export interface StepAsk {
|
|
||||||
"asker": string;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"build"?: StepAskBuild;
|
|
||||||
"check"?: StepAskCheck;
|
|
||||||
"compose"?: StepAskCompose;
|
|
||||||
"id": string;
|
|
||||||
/** build, check or compose */
|
|
||||||
"kind": string;
|
|
||||||
/** go, typescript or image */
|
|
||||||
"language": string;
|
|
||||||
"needs"?: string[];
|
|
||||||
/** package to the tagged version a build pins */
|
|
||||||
"packages"?: Record<string, string>;
|
|
||||||
/** a run: a program built from a change and run in the build seat's sandbox over the heads, its input asked of a verb of the asker's seat; the Go seat's check stream alone carries it, as a compose */
|
|
||||||
"run"?: RunJob;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a step answered, by the kind of ask: a build's artifacts, toolchain, imports and out-of-step modules; a check's fetch and levels; a compose's built, key and verdict; a run's built, key, exit, output and said; a declined ask's declined, needs and lacks. The fields of the kinds do not meet, so one layout holds the five */
|
|
||||||
export interface StepResult {
|
|
||||||
"artifacts"?: BuiltArtifact[];
|
|
||||||
"built"?: boolean;
|
|
||||||
/** the holder declined the ask: its node lacks what the ask needs */
|
|
||||||
"declined"?: boolean;
|
|
||||||
/** a run's program's exit status */
|
|
||||||
"exit"?: number;
|
|
||||||
"fetch"?: FetchAnswer;
|
|
||||||
"imports"?: string[];
|
|
||||||
"key"?: string;
|
|
||||||
/** what the holder's node lacks of it */
|
|
||||||
"lacks"?: string[];
|
|
||||||
"levels"?: LevelAnswer[];
|
|
||||||
/** what the declined ask needs */
|
|
||||||
"needs"?: string[];
|
|
||||||
"out-of-step"?: string[];
|
|
||||||
/** a run's program's last line of standard output: raw when it is JSON, else a JSON string */
|
|
||||||
"output"?: unknown;
|
|
||||||
/** a run's program's first line of standard error, or why the step could not run it */
|
|
||||||
"said"?: string;
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
/** the compose-candidate verdict (the composer's own layout) */
|
|
||||||
"verdict"?: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** of a directory whose go.mod requires an asked mesh package, the version it is built against: the asked one, or go.mod's when it names a newer one, said */
|
|
||||||
export interface TakenVersion {
|
|
||||||
"asked": string;
|
|
||||||
"built": string;
|
|
||||||
"dir": string;
|
|
||||||
"named": string;
|
|
||||||
"package": string;
|
|
||||||
"said"?: string;
|
|
||||||
"sum"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the toolchain a node reports */
|
|
||||||
export interface Toolchain {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
/** go or typescript */
|
|
||||||
"language": string;
|
|
||||||
"recipe": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"version": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the toolchain a build was made with: the language, the installed version and the build module's recipe */
|
|
||||||
export interface ToolchainUsed {
|
|
||||||
"language": string;
|
|
||||||
"recipe": string;
|
|
||||||
"version": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what current takes. */
|
|
||||||
export interface CurrentInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what current answers. */
|
|
||||||
export type CurrentAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what pause takes. */
|
|
||||||
export interface PauseInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what pause answers. */
|
|
||||||
export type PauseAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what resume takes. */
|
|
||||||
export interface ResumeInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what resume answers. */
|
|
||||||
export type ResumeAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
// Code generated by seatgen from the seat definitions; DO NOT EDIT.
|
|
||||||
|
|
||||||
// The contract of the seat "node-build-node", defined whole (seats/node-build-node/seat.json): The Node build module on a node: it takes the asks of the builder and the checker, runs them as steps and answers.
|
|
||||||
|
|
||||||
import type * as buildStep from "./parts/build-step.js";
|
|
||||||
|
|
||||||
export const seat = "node-build-node";
|
|
||||||
|
|
||||||
export const verbs = {
|
|
||||||
current: "current",
|
|
||||||
pause: "pause",
|
|
||||||
resume: "resume",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const accepts = {
|
|
||||||
delivery: "delivery",
|
|
||||||
check: "check",
|
|
||||||
recheck: "recheck",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const deliverySubject = "mesh.seat.node-build-node.accept.delivery";
|
|
||||||
|
|
||||||
export const checkSubject = "mesh.seat.node-build-node.accept.check";
|
|
||||||
|
|
||||||
export const recheckSubject = "mesh.seat.node-build-node.accept.recheck";
|
|
||||||
|
|
||||||
export const states = {
|
|
||||||
steps: "steps",
|
|
||||||
pauses: "pauses",
|
|
||||||
toolchains: "toolchains",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/** The key of one value of the state steps under the form "<node>.<id>". */
|
|
||||||
export function stepsByNodeIDKey(node: string, id: string): string {
|
|
||||||
return node + "." + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<node>.<id>", or undefined for a key of another form. */
|
|
||||||
export function parseStepsByNodeIDKey(_key: string): { node: string; id: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const node = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const id = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node, id };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state pauses under the form "paused.<node>". */
|
|
||||||
export function pausesByPausedNodeKey(node: string): string {
|
|
||||||
return "paused." + node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "paused.<node>", or undefined for a key of another form. */
|
|
||||||
export function parsePausesByPausedNodeKey(_key: string): { node: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("paused.")) return undefined;
|
|
||||||
_rest = _rest.slice(7);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const node = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state pauses under the form "capacity.<node>". */
|
|
||||||
export function pausesByCapacityNodeKey(node: string): string {
|
|
||||||
return "capacity." + node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "capacity.<node>", or undefined for a key of another form. */
|
|
||||||
export function parsePausesByCapacityNodeKey(_key: string): { node: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
if (!_rest.startsWith("capacity.")) return undefined;
|
|
||||||
_rest = _rest.slice(9);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const node = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The key of one value of the state toolchains under the form "<node>.<language>". */
|
|
||||||
export function toolchainsByNodeLanguageKey(node: string, language: string): string {
|
|
||||||
return node + "." + language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The parts of a key of the form "<node>.<language>", or undefined for a key of another form. */
|
|
||||||
export function parseToolchainsByNodeLanguageKey(_key: string): { node: string; language: string } | undefined {
|
|
||||||
let _rest = _key;
|
|
||||||
const _at0 = _rest.indexOf(".");
|
|
||||||
if (_at0 <= 0) return undefined;
|
|
||||||
const node = _rest.slice(0, _at0);
|
|
||||||
_rest = _rest.slice(_at0 + 1);
|
|
||||||
if (_rest === "") return undefined;
|
|
||||||
const language = _rest;
|
|
||||||
_rest = "";
|
|
||||||
if (_rest !== "") return undefined;
|
|
||||||
return { node, language };
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AskArtifact = buildStep.AskArtifact;
|
|
||||||
export type BuildAnswer = buildStep.BuildAnswer;
|
|
||||||
export type BuiltArtifact = buildStep.BuiltArtifact;
|
|
||||||
export type Capacity = buildStep.Capacity;
|
|
||||||
export type CheckAnswer = buildStep.CheckAnswer;
|
|
||||||
export type ComposeAnswer = buildStep.ComposeAnswer;
|
|
||||||
export type CurrentAnswer = buildStep.CurrentAnswer;
|
|
||||||
export type CurrentInput = buildStep.CurrentInput;
|
|
||||||
export type Fetch = buildStep.Fetch;
|
|
||||||
export type FetchAnswer = buildStep.FetchAnswer;
|
|
||||||
export type FetchBesideItem = buildStep.FetchBesideItem;
|
|
||||||
export type FetchPackage = buildStep.FetchPackage;
|
|
||||||
export type FetchRefusal = buildStep.FetchRefusal;
|
|
||||||
export type LevelAnswer = buildStep.LevelAnswer;
|
|
||||||
export type LevelAnswerDigest = buildStep.LevelAnswerDigest;
|
|
||||||
export type LevelAnswerDigestNeedsItem = buildStep.LevelAnswerDigestNeedsItem;
|
|
||||||
export type LevelAnswerDigestPackagesItem = buildStep.LevelAnswerDigestPackagesItem;
|
|
||||||
export type LevelAnswerKeptItem = buildStep.LevelAnswerKeptItem;
|
|
||||||
export type LevelAnswerUnmetItem = buildStep.LevelAnswerUnmetItem;
|
|
||||||
export type ModuleTree = buildStep.ModuleTree;
|
|
||||||
export type Pause = buildStep.Pause;
|
|
||||||
export type PauseAnswer = buildStep.PauseAnswer;
|
|
||||||
export type PauseInput = buildStep.PauseInput;
|
|
||||||
export type PlacedBeside = buildStep.PlacedBeside;
|
|
||||||
export type Program = buildStep.Program;
|
|
||||||
export type ResumeAnswer = buildStep.ResumeAnswer;
|
|
||||||
export type ResumeInput = buildStep.ResumeInput;
|
|
||||||
export type RunAnswer = buildStep.RunAnswer;
|
|
||||||
export type RunHead = buildStep.RunHead;
|
|
||||||
export type RunInput = buildStep.RunInput;
|
|
||||||
export type RunJob = buildStep.RunJob;
|
|
||||||
export type RunProgram = buildStep.RunProgram;
|
|
||||||
export type Step = buildStep.Step;
|
|
||||||
export type StepAsk = buildStep.StepAsk;
|
|
||||||
export type StepAskBuild = buildStep.StepAskBuild;
|
|
||||||
export type StepAskCheck = buildStep.StepAskCheck;
|
|
||||||
export type StepAskCompose = buildStep.StepAskCompose;
|
|
||||||
export type StepResult = buildStep.StepResult;
|
|
||||||
export type TakenVersion = buildStep.TakenVersion;
|
|
||||||
export type Toolchain = buildStep.Toolchain;
|
|
||||||
export type ToolchainUsed = buildStep.ToolchainUsed;
|
|
||||||
|
|
||||||
/** is the body of delivery. */
|
|
||||||
export type DeliveryAccept = StepAsk;
|
|
||||||
|
|
||||||
/** is the body of check. */
|
|
||||||
export type CheckAccept = StepAsk;
|
|
||||||
|
|
||||||
/** is the body of recheck. */
|
|
||||||
export type RecheckAccept = StepAsk;
|
|
||||||
|
|
||||||
/** is one value of the state steps under the key <node>.<id>. */
|
|
||||||
export type StepsByNodeIDValue = Step;
|
|
||||||
|
|
||||||
/** is one value of the state pauses under the key paused.<node>. */
|
|
||||||
export type PausesByPausedNodeValue = Pause;
|
|
||||||
|
|
||||||
/** is one value of the state pauses under the key capacity.<node>. */
|
|
||||||
export type PausesByCapacityNodeValue = Capacity;
|
|
||||||
|
|
||||||
/** is one value of the state toolchains under the key <node>.<language>. */
|
|
||||||
export type ToolchainsByNodeLanguageValue = Toolchain;
|
|
||||||
|
|
||||||
@@ -1,398 +0,0 @@
|
|||||||
// Code generated by seatgen from the seat definitions; DO NOT EDIT.
|
|
||||||
|
|
||||||
// The part "build-step" several seats include whole: What the three build seats share: the verbs that read and steer a node's builds, and the layouts of the asks they accept and the steps they keep. A seat lists its states against these (a part carries no states).
|
|
||||||
|
|
||||||
export const verbs = {
|
|
||||||
current: "current",
|
|
||||||
pause: "pause",
|
|
||||||
resume: "resume",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/** one artifact of a build ask: built from the fetched tree, or copied from an upstream pin */
|
|
||||||
export interface AskArtifact {
|
|
||||||
"artifact": string;
|
|
||||||
"from"?: string;
|
|
||||||
"seat"?: string;
|
|
||||||
"version"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BuildAnswer {
|
|
||||||
"artifacts": BuiltArtifact[];
|
|
||||||
"imports"?: string[];
|
|
||||||
"out-of-step"?: string[];
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one artifact a build made: its digest and the reference it was published under */
|
|
||||||
export interface BuiltArtifact {
|
|
||||||
"artifact": string;
|
|
||||||
"digest": string;
|
|
||||||
"reference"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** how many steps the node runs at once */
|
|
||||||
export interface Capacity {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"build-hours"?: string;
|
|
||||||
"build-hours-fault"?: string;
|
|
||||||
"by-cpu"?: number;
|
|
||||||
"configured": number;
|
|
||||||
"configured-from"?: string;
|
|
||||||
"cores-per-step"?: number;
|
|
||||||
"effective": number;
|
|
||||||
"ineligible"?: string;
|
|
||||||
"outside-hours"?: boolean;
|
|
||||||
"quota-cores"?: number;
|
|
||||||
"quota-from"?: string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"why": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CheckAnswer {
|
|
||||||
"fetch": FetchAnswer;
|
|
||||||
"levels"?: LevelAnswer[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ComposeAnswer {
|
|
||||||
"built": boolean;
|
|
||||||
"key"?: string;
|
|
||||||
/** the compose-candidate verdict */
|
|
||||||
"verdict"?: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FetchBesideItem {
|
|
||||||
"commit": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the TypeScript module's group package: the group's tagged version of the SDK ({name, version}), placed from the registry in each member whatever its lock names, or the group's package member ({repository, commit, ref}), packed by the fetch and served to the members in place of the registry's */
|
|
||||||
export interface FetchPackage {
|
|
||||||
"commit"?: string;
|
|
||||||
"name"?: string;
|
|
||||||
"ref"?: string;
|
|
||||||
"repository"?: string;
|
|
||||||
"version"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a build module's fetch tool is asked: the repository and the full commit, the pull request's ref when only its head carries the commit, the trunk commit to merge onto for a merge preview, the module's directory and named paths, the mesh packages to build against, and the sibling repositories placed beside */
|
|
||||||
export interface Fetch {
|
|
||||||
/** the trunk commit a merge preview merges onto */
|
|
||||||
"base"?: string;
|
|
||||||
/** the sibling repositories placed beside the fetched tree */
|
|
||||||
"beside"?: FetchBesideItem[];
|
|
||||||
/** the full commit */
|
|
||||||
"commit": string;
|
|
||||||
/** the module's directory in the repository ("." for its root), with paths */
|
|
||||||
"dir"?: string;
|
|
||||||
/** the TypeScript module's group package: the group's tagged version of the SDK ({name, version}), placed from the registry in each member whatever its lock names, or the group's package member ({repository, commit, ref}), packed by the fetch and served to the members in place of the registry's */
|
|
||||||
"package"?: FetchPackage;
|
|
||||||
/** the version (a full commit) of each mesh package to build against, by its module path */
|
|
||||||
"packages"?: Record<string, string>;
|
|
||||||
/** the paths the module names, relative to dir */
|
|
||||||
"paths"?: string[];
|
|
||||||
/** the pull request's ref, when only its head carries the commit */
|
|
||||||
"ref"?: string;
|
|
||||||
/** <owner>/<name> */
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a build module's fetch tool answers, whole: the workspace it made, the commit in it, the module directories found; and, when the call gave a base, the merge preview (the trunk commit, the merge commit, the files that conflict, the paths the merge changes, the compiled programs among them, the tree of each module directory). A head that does not merge cleanly is an answer, not an error: merge is empty and conflicts names the files. The Go module adds the sibling repositories placed and the package versions taken; the TypeScript module the directories installed and refused and the group's package */
|
|
||||||
export interface FetchAnswer {
|
|
||||||
"base"?: string;
|
|
||||||
"beside"?: PlacedBeside[];
|
|
||||||
"changed"?: string[];
|
|
||||||
"commit": string;
|
|
||||||
"conflicts"?: string[];
|
|
||||||
"group"?: string;
|
|
||||||
"installed"?: string[];
|
|
||||||
"merge"?: string;
|
|
||||||
"modules": string[];
|
|
||||||
"packages"?: TakenVersion[];
|
|
||||||
"programs"?: Program[];
|
|
||||||
"refused"?: FetchRefusal[];
|
|
||||||
"trees"?: Record<string, ModuleTree>;
|
|
||||||
"workspace": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a TypeScript module whose packages the fetch did not install, with why */
|
|
||||||
export interface FetchRefusal {
|
|
||||||
"module": string;
|
|
||||||
"reason": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerDigestNeedsItem {
|
|
||||||
"needs"?: string[];
|
|
||||||
"package"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerDigestPackagesItem {
|
|
||||||
"digest": string;
|
|
||||||
"package": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerDigest {
|
|
||||||
"beside"?: string[];
|
|
||||||
"judged_by"?: string;
|
|
||||||
"level"?: string;
|
|
||||||
"needs"?: LevelAnswerDigestNeedsItem[];
|
|
||||||
"packages"?: LevelAnswerDigestPackagesItem[];
|
|
||||||
"without_tests"?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerKeptItem {
|
|
||||||
"digest"?: string;
|
|
||||||
"package"?: string;
|
|
||||||
"tests"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LevelAnswerUnmetItem {
|
|
||||||
"needs"?: string[];
|
|
||||||
"package"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one level of a check ask: the digest's answer, the kept verdicts taken, one test result per test step run, and the packages the node could not test */
|
|
||||||
export interface LevelAnswer {
|
|
||||||
"digest"?: LevelAnswerDigest;
|
|
||||||
"judged"?: string;
|
|
||||||
"kept"?: LevelAnswerKeptItem[];
|
|
||||||
"level": string;
|
|
||||||
"tests"?: unknown[];
|
|
||||||
"unmet"?: LevelAnswerUnmetItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the tree of one module directory in a merge preview: its git tree, the digest of its manifest, the lock files' digests and the digests of the named paths */
|
|
||||||
export interface ModuleTree {
|
|
||||||
"locks"?: Record<string, string>;
|
|
||||||
"manifest": string;
|
|
||||||
/** no longer filled (ADR 0593 section 2); kept so a preview written before still reads */
|
|
||||||
"packages"?: string[];
|
|
||||||
"paths"?: Record<string, string>;
|
|
||||||
"tree": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** whether the node takes no new ask */
|
|
||||||
export interface Pause {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"by"?: string;
|
|
||||||
"paused": boolean;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a sibling repository placed as a plain directory under the workspace's beside directory */
|
|
||||||
export interface PlacedBeside {
|
|
||||||
"commit": string;
|
|
||||||
"dir": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a changed file that is a compiled program (issue 1577): its path, its executable format, and the commit of the branch that added it when the merge's tree no longer holds it */
|
|
||||||
export interface Program {
|
|
||||||
"commit"?: string;
|
|
||||||
/** ELF, Mach-O or PE */
|
|
||||||
"kind": string;
|
|
||||||
"path": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a run ask's step answers: whether this run built the program or took the one kept under its key, the key, the program's exit, the last line of its standard output and the first of its standard error */
|
|
||||||
export interface RunAnswer {
|
|
||||||
"built": boolean;
|
|
||||||
"exit": number;
|
|
||||||
"key": string;
|
|
||||||
/** raw when it is JSON, else a JSON string */
|
|
||||||
"output"?: unknown;
|
|
||||||
"said"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one commit a run's program reads */
|
|
||||||
export interface RunHead {
|
|
||||||
"commit": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a run's input by reference: the seat verb the asker serves it on (seat:<seat>.<verb>), the sha256 of its bytes and its size, at most 256 KiB */
|
|
||||||
export interface RunInput {
|
|
||||||
/** 64 lowercase hex digits */
|
|
||||||
"digest": string;
|
|
||||||
/** bytes */
|
|
||||||
"size": number;
|
|
||||||
"verb": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** a run ask's job: where its program is built, the heads it reads (each laid read-only at its repository's path), its input by reference, its arguments and what it is for */
|
|
||||||
export interface RunJob {
|
|
||||||
/** the program's arguments, each a word or a flag */
|
|
||||||
"args"?: string[];
|
|
||||||
/** the commits the program reads, a repository at most once */
|
|
||||||
"heads": RunHead[];
|
|
||||||
"input": RunInput;
|
|
||||||
"program": RunProgram;
|
|
||||||
/** what the run is for, for a reader of the ask */
|
|
||||||
"reader"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** where a run's program is built: the repository and full commit fetched, the Go module's directory in it and the program's import path */
|
|
||||||
export interface RunProgram {
|
|
||||||
"commit": string;
|
|
||||||
"dir": string;
|
|
||||||
"package": string;
|
|
||||||
"repository": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one step a build module runs on a node */
|
|
||||||
export interface Step {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"ended"?: string;
|
|
||||||
"id": string;
|
|
||||||
"node": string;
|
|
||||||
"owner"?: string;
|
|
||||||
"phase"?: string;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"phase-at"?: string;
|
|
||||||
"reason"?: string;
|
|
||||||
"result"?: StepResult;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"started": string;
|
|
||||||
/** running, passed, failed or refused */
|
|
||||||
"state": string;
|
|
||||||
"tool": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"what"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StepAskBuild {
|
|
||||||
"artifacts": AskArtifact[];
|
|
||||||
"fetch"?: Fetch;
|
|
||||||
"fp"?: string;
|
|
||||||
"module": string;
|
|
||||||
"path"?: string;
|
|
||||||
"publish"?: boolean;
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StepAskCheck {
|
|
||||||
"fetch": Fetch;
|
|
||||||
"kept"?: boolean;
|
|
||||||
"levels": string[];
|
|
||||||
/** the node names the check's tests run against */
|
|
||||||
"node-names"?: string[];
|
|
||||||
"packages"?: string[];
|
|
||||||
"run"?: string;
|
|
||||||
"runner"?: string;
|
|
||||||
"runner_when"?: string;
|
|
||||||
/** the toolchain the checker agreed for the language (ADR 0584 clause 2): a node on another declines the check */
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StepAskCompose {
|
|
||||||
"dir": string;
|
|
||||||
"fetch": Fetch;
|
|
||||||
"package": string;
|
|
||||||
"reader"?: string;
|
|
||||||
/** the compose-candidate request */
|
|
||||||
"request": unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** one ask of a build module */
|
|
||||||
export interface StepAsk {
|
|
||||||
"asker": string;
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
"build"?: StepAskBuild;
|
|
||||||
"check"?: StepAskCheck;
|
|
||||||
"compose"?: StepAskCompose;
|
|
||||||
"id": string;
|
|
||||||
/** build, check or compose */
|
|
||||||
"kind": string;
|
|
||||||
/** go, typescript or image */
|
|
||||||
"language": string;
|
|
||||||
"needs"?: string[];
|
|
||||||
/** package to the tagged version a build pins */
|
|
||||||
"packages"?: Record<string, string>;
|
|
||||||
/** a run: a program built from a change and run in the build seat's sandbox over the heads, its input asked of a verb of the asker's seat; the Go seat's check stream alone carries it, as a compose */
|
|
||||||
"run"?: RunJob;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** what a step answered, by the kind of ask: a build's artifacts, toolchain, imports and out-of-step modules; a check's fetch and levels; a compose's built, key and verdict; a run's built, key, exit, output and said; a declined ask's declined, needs and lacks. The fields of the kinds do not meet, so one layout holds the five */
|
|
||||||
export interface StepResult {
|
|
||||||
"artifacts"?: BuiltArtifact[];
|
|
||||||
"built"?: boolean;
|
|
||||||
/** the holder declined the ask: its node lacks what the ask needs */
|
|
||||||
"declined"?: boolean;
|
|
||||||
/** a run's program's exit status */
|
|
||||||
"exit"?: number;
|
|
||||||
"fetch"?: FetchAnswer;
|
|
||||||
"imports"?: string[];
|
|
||||||
"key"?: string;
|
|
||||||
/** what the holder's node lacks of it */
|
|
||||||
"lacks"?: string[];
|
|
||||||
"levels"?: LevelAnswer[];
|
|
||||||
/** what the declined ask needs */
|
|
||||||
"needs"?: string[];
|
|
||||||
"out-of-step"?: string[];
|
|
||||||
/** a run's program's last line of standard output: raw when it is JSON, else a JSON string */
|
|
||||||
"output"?: unknown;
|
|
||||||
/** a run's program's first line of standard error, or why the step could not run it */
|
|
||||||
"said"?: string;
|
|
||||||
"toolchain"?: ToolchainUsed;
|
|
||||||
/** the compose-candidate verdict (the composer's own layout) */
|
|
||||||
"verdict"?: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** of a directory whose go.mod requires an asked mesh package, the version it is built against: the asked one, or go.mod's when it names a newer one, said */
|
|
||||||
export interface TakenVersion {
|
|
||||||
"asked": string;
|
|
||||||
"built": string;
|
|
||||||
"dir": string;
|
|
||||||
"named": string;
|
|
||||||
"package": string;
|
|
||||||
"said"?: string;
|
|
||||||
"sum"?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the toolchain a node reports */
|
|
||||||
export interface Toolchain {
|
|
||||||
/** when (RFC 3339 time) */
|
|
||||||
"at"?: string;
|
|
||||||
/** go or typescript */
|
|
||||||
"language": string;
|
|
||||||
"recipe": string;
|
|
||||||
/** the layout version */
|
|
||||||
"v"?: number;
|
|
||||||
"version": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** the toolchain a build was made with: the language, the installed version and the build module's recipe */
|
|
||||||
export interface ToolchainUsed {
|
|
||||||
"language": string;
|
|
||||||
"recipe": string;
|
|
||||||
"version": string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what current takes. */
|
|
||||||
export interface CurrentInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what current answers. */
|
|
||||||
export type CurrentAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what pause takes. */
|
|
||||||
export interface PauseInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what pause answers. */
|
|
||||||
export type PauseAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
/** is what resume takes. */
|
|
||||||
export interface ResumeInput {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** is what resume answers. */
|
|
||||||
export type ResumeAnswer = Record<string, unknown>;
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"noEmit": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"forceConsistentCasingInFileNames": true
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
@@ -16,10 +16,10 @@ import (
|
|||||||
|
|
||||||
"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
|
||||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshdeliveryclient"
|
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||||
"git.novox.be/novox/mesh-delivery/sdk/kept"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/catalogkey"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/kept"
|
||||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,10 +38,16 @@ const (
|
|||||||
// `assignments.<proposal id>`. The kind needs no proof, as the bus's put does not: its yes is an Approve, which only a
|
// `assignments.<proposal id>`. The kind needs no proof, as the bus's put does not: its yes is an Approve, which only a
|
||||||
// channel proving who answered takes and the view never does (ViewAnswerFits).
|
// channel proving who answered takes and the view never does (ViewAnswerFits).
|
||||||
AskKindAssignments = "assignments"
|
AskKindAssignments = "assignments"
|
||||||
|
// AskKindOutside is the kind of the assigner's ask about a moved module whose failing health check has waited past its bound
|
||||||
|
// on an outside cause (design 47 G §706): go on, or count it as failed. `outside.<node>.<module>.<fingerprint hex>`.
|
||||||
|
AskKindOutside = "outside"
|
||||||
|
// AskKindRevert is the kind of the assigner's ask about a held revert, one with no restore point (design 47 G §710): keep it
|
||||||
|
// held, or start the reverted build on the live data. `revert.<node>.<module>.<fingerprint hex>`, the reverted build's.
|
||||||
|
AskKindRevert = "revert"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AskKey is an ask's key read whole: its Kind, and the parts its kind has: a merge's Group and heads Hash, a hold's Module
|
// AskKey is an ask's key read whole: its Kind, and the parts its kind has: a merge's Group and heads Hash, a hold's Module
|
||||||
// and fingerprint FP, a restore's and a backup's Node, Module and FP, a record's Node, Module and the digest Composed of the
|
// and fingerprint FP, a restore's, a backup's, an outside's and a revert's Node, Module and FP, a record's Node, Module and the digest Composed of the
|
||||||
// composition it would allow, the assignments' Proposal.
|
// composition it would allow, the assignments' Proposal.
|
||||||
type AskKey struct {
|
type AskKey struct {
|
||||||
Proposal string
|
Proposal string
|
||||||
@@ -60,11 +66,11 @@ func AskNeedsProof(kind string) (bool, error) {
|
|||||||
switch kind {
|
switch kind {
|
||||||
case meshdeliveryclient.AskKindMerge:
|
case meshdeliveryclient.AskKindMerge:
|
||||||
return true, nil
|
return true, nil
|
||||||
case AskKindHold, AskKindRestore, AskKindBackup, AskKindRecord, AskKindAssignments:
|
case AskKindHold, AskKindRestore, AskKindBackup, AskKindRecord, AskKindAssignments, AskKindOutside, AskKindRevert:
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
return false, fmt.Errorf("asks: %q is not a kind of ask, %s, %s, %s, %s, %s or %s", kind, meshdeliveryclient.AskKindMerge, AskKindHold,
|
return false, fmt.Errorf("asks: %q is not a kind of ask, %s, %s, %s, %s, %s, %s, %s or %s", kind, meshdeliveryclient.AskKindMerge, AskKindHold,
|
||||||
AskKindRestore, AskKindBackup, AskKindRecord, AskKindAssignments)
|
AskKindRestore, AskKindBackup, AskKindRecord, AskKindAssignments, AskKindOutside, AskKindRevert)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HoldAskKey is the key of the ask about a module's held fingerprint: `hold.<module>.<hex>`.
|
// HoldAskKey is the key of the ask about a module's held fingerprint: `hold.<module>.<hex>`.
|
||||||
@@ -89,10 +95,23 @@ func RestoreAskKey(node, module, fingerprint string) (string, error) {
|
|||||||
return AskKindRestore + "." + node + "." + key, nil
|
return AskKindRestore + "." + node + "." + key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OutsideAskKey is the key of the ask about a module's failing check on a node that waited past its bound on an outside cause:
|
||||||
|
// `outside.<node>.<module>.<hex>`.
|
||||||
|
func OutsideAskKey(node, module, fingerprint string) (string, error) {
|
||||||
|
key, err := RestoreAskKey(node, module, fingerprint)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return AskKindOutside + strings.TrimPrefix(key, AskKindRestore), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// OutsideAbout is what the outside ask is about: `<node>.<module>.<hex>` (design 47 G §706).
|
||||||
|
func OutsideAbout(key string) string { return strings.TrimPrefix(key, AskKindOutside+".") }
|
||||||
|
|
||||||
// BackupAskKey is the key of the ask about a module's failed backup on a node before it applies a fingerprint:
|
// BackupAskKey is the key of the ask about a module's failed backup on a node before it applies a fingerprint:
|
||||||
// `backup.<node>.<module>.<hex>`.
|
// `backup.<node>.<module>.<hex>`.
|
||||||
func BackupAskKey(node, module, fingerprint string) (string, error) {
|
func BackupAskKey(node, module, fingerprint string) (string, error) {
|
||||||
part, err := meshcatalogclient.KeyPart(fingerprint)
|
part, err := catalogkey.KeyPart(fingerprint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -103,6 +122,16 @@ func BackupAskKey(node, module, fingerprint string) (string, error) {
|
|||||||
return AskKindBackup + "." + key, nil
|
return AskKindBackup + "." + key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RevertAskKey is the key of the ask about a held revert of a module on a node to the reverted build's fingerprint:
|
||||||
|
// `revert.<node>.<module>.<hex>` (design 47 G §710).
|
||||||
|
func RevertAskKey(node, module, fingerprint string) (string, error) {
|
||||||
|
key, err := BackupAskKey(node, module, fingerprint)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return AskKindRevert + strings.TrimPrefix(key, AskKindBackup), nil
|
||||||
|
}
|
||||||
|
|
||||||
// AssignmentsAskKey is the key of the authorising ask about a proposal of assignments: `assignments.<proposal id>` (ADR 0567 §5).
|
// AssignmentsAskKey is the key of the authorising ask about a proposal of assignments: `assignments.<proposal id>` (ADR 0567 §5).
|
||||||
func AssignmentsAskKey(proposal string) (string, error) {
|
func AssignmentsAskKey(proposal string) (string, error) {
|
||||||
if err := meshmoduleassignerclient.CheckProposalID(proposal); err != nil {
|
if err := meshmoduleassignerclient.CheckProposalID(proposal); err != nil {
|
||||||
@@ -124,7 +153,7 @@ func RecordAskKey(node, module, composed string) (string, error) {
|
|||||||
return AskKindRecord + "." + have + "." + strings.TrimPrefix(composed, "sha256:"), nil
|
return AskKindRecord + "." + have + "." + strings.TrimPrefix(composed, "sha256:"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseAnyAskKey reads an ask key of any kind (a merge, hold, restore, backup, record or assignments ask); it refuses an unknown
|
// ParseAnyAskKey reads an ask key of any kind (a merge, hold, restore, backup, record, assignments, outside or revert ask); it refuses an unknown
|
||||||
// kind and a key whose parts do not fit its kind, naming the key.
|
// kind and a key whose parts do not fit its kind, naming the key.
|
||||||
func ParseAnyAskKey(key string) (AskKey, error) {
|
func ParseAnyAskKey(key string) (AskKey, error) {
|
||||||
kind, rest, _ := strings.Cut(key, ".")
|
kind, rest, _ := strings.Cut(key, ".")
|
||||||
@@ -157,12 +186,19 @@ func ParseAnyAskKey(key string) (AskKey, error) {
|
|||||||
return refused(err)
|
return refused(err)
|
||||||
}
|
}
|
||||||
return AskKey{Kind: kind, Node: node, Module: module, FP: fp}, nil
|
return AskKey{Kind: kind, Node: node, Module: module, FP: fp}, nil
|
||||||
case AskKindBackup:
|
case AskKindOutside:
|
||||||
|
k, err := ParseAnyAskKey(AskKindRestore + "." + rest)
|
||||||
|
if err != nil {
|
||||||
|
return refused(fmt.Errorf("an outside ask is outside.<node>.<module>.<fingerprint hex>"))
|
||||||
|
}
|
||||||
|
k.Kind = kind
|
||||||
|
return k, nil
|
||||||
|
case AskKindBackup, AskKindRevert:
|
||||||
node, module, part, isNode, err := nodeengineclient.ParseComposedKey(rest)
|
node, module, part, isNode, err := nodeengineclient.ParseComposedKey(rest)
|
||||||
if err != nil || isNode {
|
if err != nil || isNode {
|
||||||
return refused(fmt.Errorf("a backup ask is backup.<node>.<module>.<fingerprint hex>"))
|
return refused(fmt.Errorf("a %s ask is %s.<node>.<module>.<fingerprint hex>", kind, kind))
|
||||||
}
|
}
|
||||||
fp, err := meshcatalogclient.ParseKeyPart(part)
|
fp, err := catalogkey.ParseKeyPart(part)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return refused(err)
|
return refused(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ func TestTheAssignersAskKeysKeepTheirFormsAndTheValueItsRules(t *testing.T) {
|
|||||||
backup, _ := BackupAskKey("n1", "novox.be", fp)
|
backup, _ := BackupAskKey("n1", "novox.be", fp)
|
||||||
assignments, _ := AssignmentsAskKey("p-20261028t183000-1a2b3c")
|
assignments, _ := AssignmentsAskKey("p-20261028t183000-1a2b3c")
|
||||||
record, _ := RecordAskKey("n1", "gitea", digest)
|
record, _ := RecordAskKey("n1", "gitea", digest)
|
||||||
|
revert, _ := RevertAskKey("n1", "nats", fp)
|
||||||
for key, want := range map[string]struct {
|
for key, want := range map[string]struct {
|
||||||
got string
|
got string
|
||||||
back AskKey
|
back AskKey
|
||||||
@@ -28,6 +29,7 @@ func TestTheAssignersAskKeysKeepTheirFormsAndTheValueItsRules(t *testing.T) {
|
|||||||
"backup": {backup, AskKey{Kind: "backup", Node: "n1", Module: "novox.be", FP: fp}},
|
"backup": {backup, AskKey{Kind: "backup", Node: "n1", Module: "novox.be", FP: fp}},
|
||||||
"assignments": {assignments, AskKey{Kind: "assignments", Proposal: "p-20261028t183000-1a2b3c"}},
|
"assignments": {assignments, AskKey{Kind: "assignments", Proposal: "p-20261028t183000-1a2b3c"}},
|
||||||
"record": {record, AskKey{Kind: "record", Node: "n1", Module: "gitea", Composed: digest}},
|
"record": {record, AskKey{Kind: "record", Node: "n1", Module: "gitea", Composed: digest}},
|
||||||
|
"revert": {revert, AskKey{Kind: "revert", Node: "n1", Module: "nats", FP: fp}},
|
||||||
} {
|
} {
|
||||||
back, err := ParseAnyAskKey(want.got)
|
back, err := ParseAnyAskKey(want.got)
|
||||||
if err != nil || back != want.back {
|
if err != nil || back != want.back {
|
||||||
@@ -35,7 +37,7 @@ func TestTheAssignersAskKeysKeepTheirFormsAndTheValueItsRules(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for got, want := range map[string]string{hold: "hold.gitea." + hex, restore: "restore.n1.gitea." + hex, backup: "backup.n1.novox=2ebe." + hex,
|
for got, want := range map[string]string{hold: "hold.gitea." + hex, restore: "restore.n1.gitea." + hex, backup: "backup.n1.novox=2ebe." + hex,
|
||||||
assignments: "assignments.p-20261028t183000-1a2b3c", record: "record.n1.gitea." + strings.Repeat("cd", 32)} {
|
assignments: "assignments.p-20261028t183000-1a2b3c", record: "record.n1.gitea." + strings.Repeat("cd", 32), revert: "revert.n1.nats." + hex} {
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("key %q, want %q", got, want)
|
t.Errorf("key %q, want %q", got, want)
|
||||||
}
|
}
|
||||||
@@ -45,7 +47,7 @@ func TestTheAssignersAskKeysKeepTheirFormsAndTheValueItsRules(t *testing.T) {
|
|||||||
t.Errorf("a merge ask key: %+v, %v", merge, err)
|
t.Errorf("a merge ask key: %+v, %v", merge, err)
|
||||||
}
|
}
|
||||||
for _, bad := range []string{"", "other.x", "hold.gitea", "hold.gitea.src2:" + hex, "restore.n1", "backup.n1.node", "backup.n1.gitea." + hex[:60],
|
for _, bad := range []string{"", "other.x", "hold.gitea", "hold.gitea.src2:" + hex, "restore.n1", "backup.n1.node", "backup.n1.gitea." + hex[:60],
|
||||||
"assignment.AB", "record.n1.gitea." + hex[:10], "record.n1.node." + hex, "merge.g"} {
|
"assignment.AB", "record.n1.gitea." + hex[:10], "record.n1.node." + hex, "merge.g", "revert.n1.node", "revert.n1.nats." + hex[:60]} {
|
||||||
if _, err := ParseAnyAskKey(bad); err == nil {
|
if _, err := ParseAnyAskKey(bad); err == nil {
|
||||||
t.Errorf("ParseAnyAskKey(%q) reads a wrong key", bad)
|
t.Errorf("ParseAnyAskKey(%q) reads a wrong key", bad)
|
||||||
}
|
}
|
||||||
@@ -53,8 +55,10 @@ func TestTheAssignersAskKeysKeepTheirFormsAndTheValueItsRules(t *testing.T) {
|
|||||||
if proof, err := AskNeedsProof("merge"); err != nil || !proof {
|
if proof, err := AskNeedsProof("merge"); err != nil || !proof {
|
||||||
t.Error("a merge ask needs proof")
|
t.Error("a merge ask needs proof")
|
||||||
}
|
}
|
||||||
if proof, err := AskNeedsProof("hold"); err != nil || proof {
|
for _, kind := range []string{"hold", "revert"} {
|
||||||
t.Error("a hold ask needs no proof")
|
if proof, err := AskNeedsProof(kind); err != nil || proof {
|
||||||
|
t.Errorf("a %s ask needs no proof", kind)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if _, err := AskNeedsProof("view"); err == nil {
|
if _, err := AskNeedsProof("view"); err == nil {
|
||||||
t.Error("an unknown kind of ask is taken")
|
t.Error("an unknown kind of ask is taken")
|
||||||
|
|||||||
@@ -5,19 +5,19 @@ go 1.26.0
|
|||||||
require (
|
require (
|
||||||
git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient v0.0.0-00010101000000-000000000000
|
git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient v0.0.0-00010101000000-000000000000
|
||||||
git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient v0.0.0-00010101000000-000000000000
|
git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient v0.0.0-00010101000000-000000000000
|
||||||
git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient v0.0.0-00010101000000-000000000000
|
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient v0.0.0-00010101000000-000000000000
|
||||||
git.novox.be/novox/mesh-delivery/contracts/go/clients/meshdeliveryclient v0.0.0-00010101000000-000000000000
|
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient v0.0.0-00010101000000-000000000000
|
||||||
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds v0.0.0-00010101000000-000000000000
|
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds v0.0.0-00010101000000-000000000000
|
||||||
git.novox.be/novox/mesh-delivery/sdk v0.0.0-00010101000000-000000000000
|
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk v0.0.0-00010101000000-000000000000
|
||||||
git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000
|
git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner v0.0.0-00010101000000-000000000000 // indirect
|
git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner v0.0.0-00010101000000-000000000000 // indirect
|
||||||
git.novox.be/novox/mesh-contracts/go/seats/nodeengine v0.0.0-00010101000000-000000000000 // indirect
|
git.novox.be/novox/mesh-contracts/go/seats/nodeengine v0.0.0-00010101000000-000000000000 // indirect
|
||||||
git.novox.be/novox/mesh-delivery/contracts/go/clients/containerimageregistryclient v0.0.0-00010101000000-000000000000 // indirect
|
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/containerimageregistryclient v0.0.0-00010101000000-000000000000 // indirect
|
||||||
git.novox.be/novox/mesh-delivery/contracts/go/seats/containerimageregistry v0.0.0-00010101000000-000000000000 // indirect
|
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry v0.0.0-00010101000000-000000000000 // indirect
|
||||||
git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog v0.0.0-00010101000000-000000000000 // indirect
|
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog v0.0.0-00010101000000-000000000000 // indirect
|
||||||
git.novox.be/novox/mesh-delivery/contracts/go/seats/meshdelivery v0.0.0-00010101000000-000000000000 // indirect
|
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery v0.0.0-00010101000000-000000000000 // indirect
|
||||||
git.novox.be/novox/mesh-delivery/contracts/go/seats/ociartifactregistry v0.0.0-00010101000000-000000000000 // indirect
|
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/ociartifactregistry v0.0.0-00010101000000-000000000000 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,237 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"maps"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/acting"
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
"mesh-delivery-assigner/internal/assignment"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The waits for an acting part's new version in the steps the assigner holds (design 47 G §266, §268, §276): an entry of the assignment
|
||||||
|
// graph whose acting edge names composing or placing waits, its want held, until the part's version runs on the edge's node. The wait is
|
||||||
|
// kept in the state `waits` under `acting.<node>.<module>.<part>`, said as `wait-held` when it starts and `wait-ended` (ran, released,
|
||||||
|
// replaced) when it ends; `assigner_waits` reads it and `assigner_release` with how `now` lets the entry move with the part's running
|
||||||
|
// version. A node away starts no wait: its clock starts when the node is present (§268).
|
||||||
|
|
||||||
|
// actingOf is the Module.Acting of module: the held acting edges of its entry on a node, those whose wait was not released left out.
|
||||||
|
func (p *passer) actingOf(module string, released map[string]bool) func(node string) []assign.ActingEdge {
|
||||||
|
return func(node string) []assign.ActingEdge {
|
||||||
|
var out []assign.ActingEdge
|
||||||
|
if p.engineOn(node) == module {
|
||||||
|
return nil // the node-engine's own want is held by no acting edge, so it is written first (§268, A-323, A-330)
|
||||||
|
}
|
||||||
|
for _, e := range p.entryEdges(node, module) {
|
||||||
|
if acting.Held(e.Step) && !released[acting.Key(node, module, e.Module)+"@"+e.Fp] {
|
||||||
|
out = append(out, assign.ActingEdge{Node: e.Node, Part: e.Module, Fp: e.Fp, Step: e.Step, Seat: e.Seat})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// engineOn is the module that holds the seat node-engine on node in the revision the pass computed, read from the acting edges'
|
||||||
|
// seat (A-330); "" when none is read.
|
||||||
|
func (p *passer) engineOn(node string) string {
|
||||||
|
if p.graph == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return assigngraph.Engines(slices.Collect(maps.Values(p.graph.computed.Entries)))[node]
|
||||||
|
}
|
||||||
|
|
||||||
|
// entryEdges are the acting edges of the entry of module on node in the revision the pass computed.
|
||||||
|
func (p *passer) entryEdges(node, module string) []seat.Edge {
|
||||||
|
g := p.graph
|
||||||
|
if g == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, ref := range g.computed.Revision.Entries {
|
||||||
|
if ref.Node == node && ref.Module == module {
|
||||||
|
var out []seat.Edge
|
||||||
|
for _, e := range g.computed.Entries[ref.Digest].Edges {
|
||||||
|
if e.Kind == "acting" {
|
||||||
|
out = append(out, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// actingReleased is the waits released by hand and not yet run, by `<key>@<part's fingerprint>`.
|
||||||
|
func (p *passer) actingReleased() map[string]bool {
|
||||||
|
out := map[string]bool{}
|
||||||
|
for key, raw := range p.w.read(buckets.Waits()) {
|
||||||
|
if w, err := acting.Decode(raw); err == nil && w.Released && (acting.Is(key) || acting.IsOrder(key)) {
|
||||||
|
out[key+"@"+w.Fp] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// actingWaits keeps the acting waits after the pass's wants: it starts the wait of each entry held for a part's version, ends the
|
||||||
|
// wait of one that ran, was replaced or was released, and says each.
|
||||||
|
func (p *passer) actingWaits(ctx context.Context, n assign.Nodes, wanted map[string]map[string]meshwants.Want) {
|
||||||
|
g := p.graph
|
||||||
|
if g == nil || p.kvs[buckets.Waits()] == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
now := p.clock()
|
||||||
|
kept := p.w.read(buckets.Waits())
|
||||||
|
standing := map[string]bool{}
|
||||||
|
engines := assigngraph.Engines(slices.Collect(maps.Values(g.computed.Entries)))
|
||||||
|
held := map[string]bool{} // `<node>/<module>` of each entry held for a part's version
|
||||||
|
for _, ref := range g.computed.Revision.Entries {
|
||||||
|
entry := g.computed.Entries[ref.Digest]
|
||||||
|
if w, ok := wanted[ref.Module][ref.Node]; ok && w.Fp == entry.Fp {
|
||||||
|
continue // the entry's version is wanted already: nothing moves, so nothing waits
|
||||||
|
}
|
||||||
|
if engines[ref.Node] == ref.Module {
|
||||||
|
continue // the node-engine's own want waits for no acting part (§268, A-323, A-330)
|
||||||
|
}
|
||||||
|
for _, e := range entry.Edges {
|
||||||
|
if e.Kind != "acting" || !acting.Held(e.Step) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
key := acting.Key(ref.Node, ref.Module, e.Module)
|
||||||
|
if took, runs := n.ActingRuns(assign.ActingEdge{Node: e.Node, Part: e.Module, Fp: e.Fp, Step: e.Step, Seat: e.Seat}); runs {
|
||||||
|
if took != e.Fp && kept[key] != nil {
|
||||||
|
p.logf("the wait of %s on %s for %s ends: %s runs %s, which serves the seat %s, though its newest is %s (design 47 G A-426)", ref.Module, ref.Node, e.Module, e.Node, took, e.Seat, e.Fp)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
standing[key] = true
|
||||||
|
held[ref.Node+"/"+ref.Module] = true
|
||||||
|
if raw := kept[key]; raw != nil {
|
||||||
|
if w, err := acting.Decode(raw); err == nil && w.Entry == entry.Fp && w.Fp == e.Fp {
|
||||||
|
p.actingReleaseSaid(ctx, key, w)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !n.Online[ref.Node] {
|
||||||
|
continue // a node away holds only itself, and its clock has not started (§268)
|
||||||
|
}
|
||||||
|
w := acting.Wait{Step: e.Step, Node: ref.Node, Module: ref.Module, Part: e.Module, PartNode: e.Node, Fp: e.Fp, Entry: entry.Fp,
|
||||||
|
Since: now, ClockFrom: now, Bound: acting.BoundOf(e).String()}
|
||||||
|
if err := p.wantsSay(seat.EventWaitHeld, acting.Body(w, assignment.Module()), key+"."+e.Fp+"."+entry.Fp); err != nil {
|
||||||
|
p.logf("the wait of %s on %s for %s is not said, and is said at the next pass: %v", ref.Module, ref.Node, e.Module, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
p.put(ctx, buckets.Waits(), key, func() ([]byte, error) { return acting.Encode(w) })
|
||||||
|
p.logf("the want of %s on %s is held: its acting part %s (step %s) does not run the version %s on %s; the wait %s ends when it does, or by assigner_release", ref.Module, ref.Node, e.Module, e.Step, e.Fp, e.Node, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.actingCycles(g.computed.Entries, engines, held, n)
|
||||||
|
for key, raw := range kept {
|
||||||
|
if !acting.Is(key) || standing[key] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w, err := acting.Decode(raw)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
how := acting.HowRan
|
||||||
|
if w.Released {
|
||||||
|
how = acting.HowReleased
|
||||||
|
} else if e, ok := p.edgeOf(w); !ok {
|
||||||
|
how = acting.HowReplaced
|
||||||
|
} else if _, runs := n.ActingRuns(e); !runs {
|
||||||
|
how = acting.HowReplaced
|
||||||
|
}
|
||||||
|
if !w.EndSaid {
|
||||||
|
body := acting.Body(w, assignment.Module())
|
||||||
|
body.How = how
|
||||||
|
if err := p.wantsSay(seat.EventWaitEnded, body, key+"."+w.Fp+"."+w.Entry+"."+how); err != nil {
|
||||||
|
p.logf("the end of the wait of %s on %s for %s is not said, and is said at the next pass: %v", w.Module, w.Node, w.Part, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.remove(ctx, buckets.Waits(), key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// actingReleaseSaid says wait-ended of a wait released by hand, once, and keeps its record so the entry is not held again.
|
||||||
|
func (p *passer) actingReleaseSaid(ctx context.Context, key string, w acting.Wait) {
|
||||||
|
if !w.Released || w.EndSaid {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
body := acting.Body(w, assignment.Module())
|
||||||
|
body.How = acting.HowReleased
|
||||||
|
body.By = w.By
|
||||||
|
if err := p.wantsSay(seat.EventWaitEnded, body, key+"."+w.Fp+"."+w.Entry+"."+acting.HowReleased); err != nil {
|
||||||
|
p.logf("the release of the wait of %s on %s for %s is not said, and is said at the next pass: %v", w.Module, w.Node, w.Part, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.EndSaid = true
|
||||||
|
p.put(ctx, buckets.Waits(), key, func() ([]byte, error) { return acting.Encode(w) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// edgeOf is the edge a kept wait stands on, as an acting edge.
|
||||||
|
func (p *passer) edgeOf(w acting.Wait) (assign.ActingEdge, bool) {
|
||||||
|
return assign.ActingEdge{Node: w.PartNode, Part: w.Part, Fp: w.Fp, Step: w.Step}, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// actingCycles writes the finding acting-cycle of each held want whose holding edges lie on a cycle no rule breaks, and clears it of
|
||||||
|
// every other want, a finding a pass before or another process wrote included (design 47 G A-323, A-330). An edge holds while its
|
||||||
|
// step is the assigner's, its part's version does not run and its wait was not released; the node-engine's own want is held by none.
|
||||||
|
func (p *passer) actingCycles(entries map[string]seat.AssignmentEntry, engines map[string]string, held map[string]bool, n assign.Nodes) {
|
||||||
|
if p.findings.Put == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
released := p.actingReleased()
|
||||||
|
cycles := assigngraph.HeldCycles(slices.Collect(maps.Values(entries)), func(e seat.AssignmentEntry, edge seat.Edge) bool {
|
||||||
|
return held[e.Node+"/"+e.Module] && engines[e.Node] != e.Module && edge.Kind == "acting" && acting.Held(edge.Step) &&
|
||||||
|
!released[acting.Key(e.Node, e.Module, edge.Module)+"@"+edge.Fp] && !actingRunsOf(n, edge)
|
||||||
|
})
|
||||||
|
raised := map[string]bool{}
|
||||||
|
for _, at := range slices.Sorted(maps.Keys(cycles)) {
|
||||||
|
node, module, _ := strings.Cut(at, "/")
|
||||||
|
o := assign.ActingCycleFinding(node, module, cycles[at])
|
||||||
|
key := mcseatKey(o)
|
||||||
|
raised[key] = true
|
||||||
|
if p.said[key+"="+o.Summary] {
|
||||||
|
continue // written already as it stands
|
||||||
|
}
|
||||||
|
if err := p.findings.Put(o.Finding(p.clock())); err != nil {
|
||||||
|
p.logf("the finding %s is not written: %v", key, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
p.said[key+"="+o.Summary] = true
|
||||||
|
}
|
||||||
|
if p.findings.Keys == nil || p.findings.Delete == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
keys, err := p.findings.Keys()
|
||||||
|
if err != nil {
|
||||||
|
p.logf("the findings %s are not read, so none is cleared this pass: %v", assign.KindActingCycle, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, key := range keys {
|
||||||
|
if strings.HasSuffix(key, "."+assign.KindActingCycle) && !raised[key] {
|
||||||
|
if err := p.findings.Delete(key); err != nil {
|
||||||
|
p.logf("the finding %s is not cleared: %v", key, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for said := range p.said {
|
||||||
|
if strings.HasPrefix(said, key+"=") {
|
||||||
|
delete(p.said, said)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// actingRunsOf says whether an assignment edge's acting part runs a build serving it (A-426).
|
||||||
|
func actingRunsOf(n assign.Nodes, edge seat.Edge) bool {
|
||||||
|
_, runs := n.ActingRuns(assign.ActingEdge{Node: edge.Node, Part: edge.Module, Fp: edge.Fp, Step: edge.Step, Seat: edge.Seat})
|
||||||
|
return runs
|
||||||
|
}
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||||
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/acting"
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G §266, §268, §276 (AS9): an entry with an acting edge in composing waits for the part's version to run on the edge's node;
|
||||||
|
// the wait is kept, said as wait-held with its bound and clock-from, read by assigner_waits, released by assigner_release with how
|
||||||
|
// `now` and ended when the version runs.
|
||||||
|
func TestAnEntryWaitsForItsActingPartAndTheWaitIsKeptSaidAndEnded(t *testing.T) {
|
||||||
|
now := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
|
||||||
|
p := newPasser(kvSet{buckets.Waits(): &memKV{values: map[string][]byte{}}}, now)
|
||||||
|
var events []string
|
||||||
|
var bodies []meshwants.Wait
|
||||||
|
p.publishWants = func(event string, body any, id string) error {
|
||||||
|
events = append(events, event)
|
||||||
|
bodies = append(bodies, body.(meshwants.Wait))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
entry := meshwants.AssignmentEntry{Node: "ace", Module: "nats", Fp: fpTest, Edges: []meshwants.Edge{
|
||||||
|
{Kind: "acting", Node: "ace", Module: "mesh-host", Fp: "src2:new", Seat: "node-engine", Step: "compose", Bound: "15m"},
|
||||||
|
{Kind: "acting", Node: "ace", Module: "indexer", Fp: "src2:idx", Seat: "mesh-catalog", Step: "take-in"}}}
|
||||||
|
p.graph = &graphKeeper{}
|
||||||
|
p.graph.computed.Revision.Entries = []meshwants.NodeEntryRef{{Node: "ace", Module: "nats", Digest: "d1"}}
|
||||||
|
p.graph.computed.Entries = map[string]meshwants.AssignmentEntry{"d1": entry}
|
||||||
|
// The old build of mesh-host serves no seat of the edge here, so the entry waits (A-426: one serving it ends the wait).
|
||||||
|
notServing := func(nodeengine.Running, string) (bool, bool) { return false, true }
|
||||||
|
n := assign.Nodes{Online: map[string]bool{"ace": true}, Running: map[string]map[string]nodeengine.Running{"ace": {"mesh-host": {Fingerprint: "src2:old"}}}, Serves: notServing}
|
||||||
|
wanted := map[string]map[string]mwc.Want{"nats": {"ace": {Fp: "src2:older"}}}
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
if got := p.actingOf("nats", nil)("ace"); len(got) != 1 || got[0].Part != "mesh-host" {
|
||||||
|
t.Fatalf("the assigner holds composing only: %+v", got)
|
||||||
|
}
|
||||||
|
p.actingWaits(ctx, n, wanted)
|
||||||
|
p.actingWaits(ctx, n, wanted) // said once
|
||||||
|
if len(events) != 1 || events[0] != meshwants.EventWaitHeld {
|
||||||
|
t.Fatalf("events %v", events)
|
||||||
|
}
|
||||||
|
b := bodies[0]
|
||||||
|
if b.Step != "compose" || b.Part != "mesh-host" || b.Fp != "src2:new" || b.Bound != "15m0s" || b.ClockFrom == nil || !b.ClockFrom.Equal(now) || b.Owner == "" {
|
||||||
|
t.Errorf("wait-held %+v", b)
|
||||||
|
}
|
||||||
|
key := acting.Key("ace", "nats", "mesh-host")
|
||||||
|
if _, err := acting.Decode(p.w.read(buckets.Waits())[key]); err != nil {
|
||||||
|
t.Fatalf("the wait is kept: %v", err)
|
||||||
|
}
|
||||||
|
// a release by hand lets the entry move, and ends the wait once
|
||||||
|
w, _ := acting.Decode(p.w.read(buckets.Waits())[key])
|
||||||
|
w.Released = true
|
||||||
|
raw, _ := acting.Encode(w)
|
||||||
|
p.w.put(buckets.Waits(), key, raw)
|
||||||
|
if got := p.actingOf("nats", p.actingReleased())("ace"); len(got) != 0 {
|
||||||
|
t.Errorf("a released wait still holds: %+v", got)
|
||||||
|
}
|
||||||
|
p.actingWaits(ctx, n, wanted)
|
||||||
|
p.actingWaits(ctx, n, wanted)
|
||||||
|
if len(events) != 2 || events[1] != meshwants.EventWaitEnded || bodies[1].How != acting.HowReleased {
|
||||||
|
t.Fatalf("events %v bodies %+v", events, bodies)
|
||||||
|
}
|
||||||
|
// the version runs: the record goes, said nothing more
|
||||||
|
n.Running["ace"]["mesh-host"] = nodeengine.Running{Fingerprint: "src2:new"}
|
||||||
|
p.actingWaits(ctx, n, wanted)
|
||||||
|
if len(p.w.read(buckets.Waits())) != 0 || len(events) != 2 {
|
||||||
|
t.Errorf("kept %v events %v", p.w.read(buckets.Waits()), events)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAnActingWaitOfANodeAwayStartsNoClockAndAnEntryWantedAlreadyWaitsNot(t *testing.T) {
|
||||||
|
p := newPasser(kvSet{buckets.Waits(): &memKV{values: map[string][]byte{}}}, time.Now())
|
||||||
|
p.publishWants = func(string, any, string) error { t.Fatal("said"); return nil }
|
||||||
|
p.graph = &graphKeeper{}
|
||||||
|
p.graph.computed.Revision.Entries = []meshwants.NodeEntryRef{{Node: "ace", Module: "nats", Digest: "d1"}}
|
||||||
|
p.graph.computed.Entries = map[string]meshwants.AssignmentEntry{"d1": {Node: "ace", Module: "nats", Fp: "src2:a", Edges: []meshwants.Edge{
|
||||||
|
{Kind: "acting", Node: "ace", Module: "mesh-host", Fp: "src2:new", Step: "compose"}}}}
|
||||||
|
n := assign.Nodes{Online: map[string]bool{}}
|
||||||
|
p.actingWaits(context.Background(), n, map[string]map[string]mwc.Want{})
|
||||||
|
n.Online["ace"] = true
|
||||||
|
p.actingWaits(context.Background(), n, map[string]map[string]mwc.Want{"nats": {"ace": {Fp: "src2:a"}}})
|
||||||
|
if len(p.w.read(buckets.Waits())) != 0 || strings.Contains(p.graph.computed.Entries["d1"].Fp, "x") {
|
||||||
|
t.Errorf("kept %v", p.w.read(buckets.Waits()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTheToolsReadAndReleaseAnActingWait(t *testing.T) {
|
||||||
|
var acts []string
|
||||||
|
s := newPutTools(memStore{waitsState: &memKV{values: map[string][]byte{}}, buckets.DeliveryWaitsState: &memKV{values: map[string][]byte{}}, buckets.DeliveredAgainState: &memKV{values: map[string][]byte{}}}, func(key string, body any) (json.RawMessage, error) {
|
||||||
|
acts = append(acts, key)
|
||||||
|
return json.RawMessage(`{"ok":true,"log":"logged"}`), nil
|
||||||
|
})
|
||||||
|
w := acting.Wait{Step: "compose", Node: "ace", Module: "nats", Part: "mesh-host", PartNode: "ace", Fp: "src2:new", Entry: "src2:a", Since: time.Now(), ClockFrom: time.Now(), Bound: "30m0s"}
|
||||||
|
raw, _ := acting.Encode(w)
|
||||||
|
s.st.put(waitsState, acting.Key("ace", "nats", "mesh-host"), raw)
|
||||||
|
got, err := s.doWaits(map[string]any{"module": "nats"})
|
||||||
|
if list := got.(map[string]any)["waits"].([]any); err != nil || len(list) != 1 || list[0].(actingSaid).BoundEnds == "" {
|
||||||
|
t.Fatalf("assigner_waits = %+v %v", got, err)
|
||||||
|
}
|
||||||
|
if _, err := s.doRelease(map[string]any{"node": "ace", "module": "nats", "how": "now"}, "x"); err == nil {
|
||||||
|
t.Error("a release with no why is taken")
|
||||||
|
}
|
||||||
|
if _, err := s.doRelease(map[string]any{"node": "ace", "module": "nats", "how": "now", "why": "the new engine is known good"}, "shanks.node-tools"); err != nil || len(acts) == 0 {
|
||||||
|
t.Fatalf("%v %v", err, acts)
|
||||||
|
}
|
||||||
|
raw, _, _, _ = s.st.get(waitsState, acting.Key("ace", "nats", "mesh-host"))
|
||||||
|
if r, _ := acting.Decode(raw); !r.Released || !strings.Contains(r.By, "known good") {
|
||||||
|
t.Errorf("wait = %+v", r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §268, A-323, A-330: the assigner and the node-engine on a node are one step: the node-engine's own want waits for no
|
||||||
|
// acting part, so it moves first, and the node's other wants, the assigner's own included, wait for the new node-engine; a want held
|
||||||
|
// on a cycle no rule breaks is the finding acting-cycle (scope module, id <node>.<module>) naming each edge's step, cleared by the
|
||||||
|
// next pass that finds it on none.
|
||||||
|
func TestTheNodeEngineIsWantedFirstAndAWantHeldOnACycleIsAFinding(t *testing.T) {
|
||||||
|
p := newPasser(kvSet{buckets.Waits(): &memKV{values: map[string][]byte{}}}, time.Date(2026, 11, 13, 2, 0, 0, 0, time.UTC))
|
||||||
|
p.publishWants = func(string, any, string) error { return nil }
|
||||||
|
findings := map[string]mcseat.Finding{}
|
||||||
|
p.findings = assign.Findings{
|
||||||
|
Put: func(f mcseat.Finding) error { findings[f.Scope+"."+f.ID+"."+f.Kind] = f; return nil },
|
||||||
|
Delete: func(key string) error { delete(findings, key); return nil },
|
||||||
|
Keys: func() ([]string, error) {
|
||||||
|
var keys []string
|
||||||
|
for k := range findings {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
return keys, nil
|
||||||
|
}}
|
||||||
|
compose := meshwants.Edge{Kind: "acting", Node: "ace", Module: "mesh-host", Fp: "src2:engine", Seat: "node-engine", Step: "compose"}
|
||||||
|
place := meshwants.Edge{Kind: "acting", Node: "ace", Module: "assigner", Fp: "src2:assigner", Seat: "mesh-wants", Step: "place"}
|
||||||
|
entries := map[string]meshwants.AssignmentEntry{
|
||||||
|
"d1": {Node: "ace", Module: "mesh-host", Fp: "src2:engine", Edges: []meshwants.Edge{place}},
|
||||||
|
"d2": {Node: "ace", Module: "assigner", Fp: "src2:assigner", Edges: []meshwants.Edge{compose}},
|
||||||
|
"d3": {Node: "ace", Module: "app", Fp: "src2:app", Edges: []meshwants.Edge{compose, place}},
|
||||||
|
}
|
||||||
|
p.graph = &graphKeeper{}
|
||||||
|
for d, e := range entries {
|
||||||
|
p.graph.computed.Revision.Entries = append(p.graph.computed.Revision.Entries, meshwants.NodeEntryRef{Node: e.Node, Module: e.Module, Digest: d})
|
||||||
|
}
|
||||||
|
p.graph.computed.Entries = entries
|
||||||
|
n := assign.Nodes{Online: map[string]bool{"ace": true}, Running: map[string]map[string]nodeengine.Running{"ace": {
|
||||||
|
"mesh-host": {Fingerprint: "src2:old"}, "assigner": {Fingerprint: "src2:old"}}}, Serves: func(nodeengine.Running, string) (bool, bool) { return false, true }}
|
||||||
|
wanted := map[string]map[string]mwc.Want{}
|
||||||
|
if got := p.actingOf("mesh-host", nil)("ace"); len(got) != 0 {
|
||||||
|
t.Errorf("the node-engine's want is held by %+v, want by no acting edge", got)
|
||||||
|
}
|
||||||
|
if got := p.actingOf("assigner", nil)("ace"); len(got) != 1 || got[0].Part != "mesh-host" {
|
||||||
|
t.Errorf("the assigner's own want is held by %+v, want by the new node-engine", got)
|
||||||
|
}
|
||||||
|
p.actingWaits(context.Background(), n, wanted)
|
||||||
|
kept := p.w.read(buckets.Waits())
|
||||||
|
if kept[acting.Key("ace", "mesh-host", "assigner")] != nil || kept[acting.Key("ace", "assigner", "mesh-host")] == nil || kept[acting.Key("ace", "app", "mesh-host")] == nil {
|
||||||
|
t.Errorf("the waits kept: %v", kept)
|
||||||
|
}
|
||||||
|
if len(findings) != 0 {
|
||||||
|
t.Errorf("the cycle the node-engine's want breaks is a finding: %v", findings)
|
||||||
|
}
|
||||||
|
// Two parts holding each other across compose and place, neither the node-engine: no rule breaks it.
|
||||||
|
entries["d4"] = meshwants.AssignmentEntry{Node: "ace", Module: "x", Fp: "src2:x", Edges: []meshwants.Edge{{Kind: "acting", Node: "ace", Module: "y", Fp: "src2:y", Seat: "s-y", Step: "place"}}}
|
||||||
|
entries["d5"] = meshwants.AssignmentEntry{Node: "ace", Module: "y", Fp: "src2:y", Edges: []meshwants.Edge{{Kind: "acting", Node: "ace", Module: "x", Fp: "src2:x", Seat: "s-x", Step: "compose"}}}
|
||||||
|
p.graph.computed.Revision.Entries = append(p.graph.computed.Revision.Entries, meshwants.NodeEntryRef{Node: "ace", Module: "x", Digest: "d4"},
|
||||||
|
meshwants.NodeEntryRef{Node: "ace", Module: "y", Digest: "d5"})
|
||||||
|
p.actingWaits(context.Background(), n, wanted)
|
||||||
|
f, ok := findings["module.ace.x.acting-cycle"]
|
||||||
|
if len(findings) != 2 || !ok || !strings.Contains(f.Summary, "ace/x -[place]-> ace/y -[compose]-> ace/x") {
|
||||||
|
t.Fatalf("the findings of a cycle no rule breaks: %v", findings)
|
||||||
|
}
|
||||||
|
// x's new version runs: y no longer waits, so neither is held on a cycle, and both findings clear.
|
||||||
|
n.Running["ace"]["x"] = nodeengine.Running{Fingerprint: "src2:x"}
|
||||||
|
p.actingWaits(context.Background(), n, wanted)
|
||||||
|
if len(findings) != 0 {
|
||||||
|
t.Errorf("the findings after the cycle broke: %v", findings)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-teller/tellerevents"
|
||||||
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
"mesh-delivery-assigner/internal/puts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// askAgainTool asks one of the assigner's asks again by hand (issue 1966, ADR 0668 §5): the recovery of an ask that ended at
|
||||||
|
// the operator channel without an answer when the event that would have asked it again was not heard.
|
||||||
|
const askAgainTool = "assigner_ask_again"
|
||||||
|
|
||||||
|
// asksState and answersState are the assigner's asks and the teller's answers, as the runtime names them.
|
||||||
|
const (
|
||||||
|
asksState = "asks"
|
||||||
|
answersState = buckets.TellerModule + ".answers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// askAgainByHand writes the ask at key again under a new asking, by the rules the teller's ask-ended writes it by (assign.AskedAgain:
|
||||||
|
// a proposal's authorising ask and a put's record ask are not), so the teller asks it again; an asking the operator answered
|
||||||
|
// is refused, naming the answer. The act is recorded through the seat mesh-hand-acts.
|
||||||
|
func askAgainByHand(st store, ask func(string, any) (json.RawMessage, error), key, why, by string, now time.Time) (any, error) {
|
||||||
|
switch {
|
||||||
|
case key == "":
|
||||||
|
return nil, errors.New("name the ask's key, as the tool asks lists it")
|
||||||
|
case why == "":
|
||||||
|
return nil, errors.New("a hand ask again says why")
|
||||||
|
case by == "" || by == stdio.Unproven:
|
||||||
|
return nil, errors.New("a hand ask again names who asks it, and the runtime proved no caller")
|
||||||
|
}
|
||||||
|
current, _, found, err := st.get(asksState, key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return nil, fmt.Errorf("the assigner holds no ask under %s: the tool asks lists them", key)
|
||||||
|
}
|
||||||
|
_, routerAsk, err := assign.DecodeAsk(key, current)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if raw, _, found, err := st.get(answersState, key); err == nil && found {
|
||||||
|
if a, err := meshdeliveryclient.DecodeAnswer(raw); err == nil && strings.HasPrefix(a.Warrant, routerAsk.ID+"@") {
|
||||||
|
return nil, fmt.Errorf("the asking %s was answered %q (%s): it is not asked again", routerAsk.ID, a.Option, a.Words)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var put *puts.Put
|
||||||
|
if k, err := asks.ParseAnyAskKey(key); err == nil && k.Kind == asks.AskKindRecord {
|
||||||
|
if pkey, err := puts.Key(k.Node, k.Module); err == nil {
|
||||||
|
if raw, _, found, err := st.get(putsState, pkey); err == nil && found {
|
||||||
|
if p, err := puts.Decode(raw); err == nil {
|
||||||
|
put = &p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value, refused := assign.AskedAgain(tellerevents.Ended{Key: key, Ask: routerAsk.ID, Outcome: occ.OutcomeCancelled}, current, put, now)
|
||||||
|
if refused != "" {
|
||||||
|
return nil, errors.New(refused)
|
||||||
|
}
|
||||||
|
if err := st.put(asksState, key, value); err != nil {
|
||||||
|
return nil, fmt.Errorf("the ask %s is not written again: %w", key, err)
|
||||||
|
}
|
||||||
|
_, next, _ := assign.DecodeAsk(key, value)
|
||||||
|
taken, rerr := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: askAgainTool + " " + key, Why: why + " (" + by + ")", Cause: "ask-again"})
|
||||||
|
recorded := taken.Log
|
||||||
|
if rerr != nil {
|
||||||
|
recorded = "not recorded: " + rerr.Error()
|
||||||
|
}
|
||||||
|
return map[string]any{"key": key, "ended": routerAsk.ID, "asked": next.ID, "by": by, "hand-act": recorded}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// askAgainTools is the tool over the runtime's states.
|
||||||
|
func askAgainTools(st store, ask func(string, any) (json.RawMessage, error), now func() time.Time) []stdio.Tool {
|
||||||
|
return []stdio.Tool{{Name: askAgainTool, Description: "Ask one of the assigner's asks of the operator again (issue 1966): the ask " +
|
||||||
|
"under key is written again under a new asking, which the teller asks on the operator channel, as when the channel says it " +
|
||||||
|
"ended without an answer. Refused for an asking the operator answered, a proposal's authorising ask (the seat's verb again " +
|
||||||
|
"asks it) and a record ask a put asked. Recorded as a hand act.",
|
||||||
|
Input: schema(map[string]string{"key": "the ask's key, as the tool asks lists it", "why": "why it is asked again"},
|
||||||
|
[]string{"key", "why"}),
|
||||||
|
Run: func(a map[string]any) (any, error) {
|
||||||
|
key, _ := a["key"].(string)
|
||||||
|
why, _ := a["why"].(string)
|
||||||
|
return askAgainByHand(st, ask, key, why, stdio.CallerOf(a), now())
|
||||||
|
}}}
|
||||||
|
}
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-teller/tellerevents"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
|
||||||
|
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||||
|
|
||||||
|
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
"mesh-delivery-assigner/internal/puts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// askEndedSubject is the teller's event ask-ended, as the manifest's consumes names it (`mesh-delivery-teller.ask-ended`).
|
||||||
|
var askEndedSubject = process.Account{Module: buckets.TellerModule}.EventSubject(tellerevents.AskEnded)
|
||||||
|
|
||||||
|
// staleOf says why the ask at a key is stale, as the pass reads it (passer.staleAsk), or "" when it is not or when the
|
||||||
|
// trunk is not read; nil reads nothing.
|
||||||
|
type staleOf func(key string) string
|
||||||
|
|
||||||
|
// staleOfWorld is staleOf over the world the pass reads: the same rule as the pass, over the same cache.
|
||||||
|
func staleOfWorld(w *world) staleOf {
|
||||||
|
p := &passer{w: w}
|
||||||
|
return func(key string) string {
|
||||||
|
trunk := w.trunk()
|
||||||
|
if len(trunk) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return p.staleAsk(key, trunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearAskEnded hears the teller's ask-ended on the assigner's one hub of its durable consumer on EVENTS (registered before
|
||||||
|
// the hub starts): an ask of the assigner's that ended at the operator channel without an answer while its key stands is
|
||||||
|
// written again under a new asking, so the teller asks it again (issue 1966, note 151). asksKV is the assigner's asks; the
|
||||||
|
// puts are opened at each event, since a put's record ask is not written again (ADR 0546).
|
||||||
|
func hearAskEnded(ctx context.Context, js jetstream.JetStream, hub *process.EventHub, asksKV jetstream.KeyValue, stale staleOf, logf func(string, ...any)) error {
|
||||||
|
return hub.Handle(askEndedSubject, func(m jetstream.Msg) {
|
||||||
|
var putsKV jetstream.KeyValue
|
||||||
|
if kv, err := js.KeyValue(ctx, buckets.Puts()); err == nil {
|
||||||
|
putsKV = kv
|
||||||
|
}
|
||||||
|
if err := askAgain(ctx, asksKV, putsKV, stale, m.Data(), time.Now(), logf); err != nil {
|
||||||
|
logf("%s: %v; it is heard again", m.Subject(), err)
|
||||||
|
_ = m.Nak()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := m.Ack(); err != nil {
|
||||||
|
logf("acknowledging %s: %v", m.Subject(), err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// channelAsksVerb is the operator-channel seat's verb asks, read at the assigner's consumer's bind (a seat verb: no module
|
||||||
|
// named).
|
||||||
|
const channelAsksVerb = "seat:" + oc.Seat + "." + oc.VerbAsks
|
||||||
|
|
||||||
|
// readEndedAtBind registers on the hub, before it starts, one read of the operator-channel seat's asks at each bind of the
|
||||||
|
// assigner's consumer: an ask-ended the teller said before the consumer existed is not delivered to it (issue 1966 note 155,
|
||||||
|
// ADR 0668 §4), so each held ask whose asking ended there expired or cancelled is written again as that event writes it
|
||||||
|
// (askAgain, with every rule and its compare-and-set). The read is a kept call (CallKept), made off the hub's start.
|
||||||
|
func readEndedAtBind(ctx context.Context, js jetstream.JetStream, hub *process.EventHub, asksKV jetstream.KeyValue, stale staleOf, bus caller, wait callWait, logf func(string, ...any)) {
|
||||||
|
if asksKV == nil || bus == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hub.OnBound(func(created time.Time) {
|
||||||
|
go func() {
|
||||||
|
if err := endedAtBind(ctx, js, asksKV, stale, bus, wait, created, time.Now(), logf); err != nil {
|
||||||
|
logf("the operator channel's ended asks are not read at the bind of %s (%v): an ask that ended there before is asked again when the teller says it ended", created.Format(time.RFC3339), err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// callWait is how a kept call the assigner waits on is said (novox/hq ADR 0668 §3): heard says the callee's machine is
|
||||||
|
// heard, now is the clock, and findings the assigner's findings, where the call unanswered past
|
||||||
|
// meshconditionsclient.CallUnansweredAfter is the finding call-unanswered while heard, cleared when it is answered.
|
||||||
|
type callWait struct {
|
||||||
|
heard func() bool
|
||||||
|
now func() time.Time
|
||||||
|
findings assign.Findings
|
||||||
|
}
|
||||||
|
|
||||||
|
// asksCallID is the finding's id for the bind's read of the operator channel's asks.
|
||||||
|
const asksCallID = "operator-channel-asks"
|
||||||
|
|
||||||
|
// keep makes call again after every transport fault (busretry: a request that reached no one, or one whose deadline
|
||||||
|
// passed) until it is answered or ctx ends, each try itself a kept call; past the bound with the callee heard it writes
|
||||||
|
// the finding call-unanswered, and clears it when answered. No timer: each try is the wait.
|
||||||
|
func (cw callWait) keep(ctx context.Context, id, callee string, call func() (json.RawMessage, error), logf func(string, ...any)) (json.RawMessage, error) {
|
||||||
|
clock := cw.now
|
||||||
|
if clock == nil {
|
||||||
|
clock = time.Now
|
||||||
|
}
|
||||||
|
since, said := clock(), false
|
||||||
|
key := mcc.Key(mcc.ScopeCall, id, mcc.KindCallUnanswered)
|
||||||
|
for {
|
||||||
|
answer, err := call()
|
||||||
|
if err == nil || !(busretry.Undelivered(err) || busretry.TimedOut(err)) || ctx.Err() != nil {
|
||||||
|
if said && cw.findings.Delete != nil {
|
||||||
|
if derr := cw.findings.Delete(key); derr != nil {
|
||||||
|
logf("the finding %s is not cleared: %v", key, derr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return answer, err
|
||||||
|
}
|
||||||
|
if said || clock().Sub(since) < mcc.CallUnansweredAfter || cw.heard == nil || !cw.heard() || cw.findings.Put == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
eerr := cw.findings.Put(assign.CallUnanswered(id, callee, "", err.Error(), "assigner."+mcc.KindCallUnanswered, since).Finding(clock()))
|
||||||
|
if eerr != nil {
|
||||||
|
logf("the finding %s is not written: %v", key, eerr)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
said = true
|
||||||
|
logf("%s is unanswered since %s and its callee's machine is heard: the finding %s", callee, since.UTC().Format(time.RFC3339), key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// endedAtBind is readEndedAtBind's one read: the held asks, the seat's verb (a kept call whose wait is kept, wait), and
|
||||||
|
// each ended asking written again.
|
||||||
|
func endedAtBind(ctx context.Context, js jetstream.JetStream, asksKV jetstream.KeyValue, stale staleOf, bus caller, wait callWait, created, now time.Time, logf func(string, ...any)) error {
|
||||||
|
keys, err := asksKV.Keys(ctx)
|
||||||
|
if errors.Is(err, jetstream.ErrNoKeysFound) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
held := map[string][]byte{}
|
||||||
|
for _, key := range keys {
|
||||||
|
if e, err := asksKV.Get(ctx, key); err == nil {
|
||||||
|
held[key] = e.Value()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query, ok := assign.ChannelAsksQuery(held)
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
answer, err := wait.keep(ctx, asksCallID, channelAsksVerb, func() (json.RawMessage, error) { return bus.CallKept(channelAsksVerb, query) }, logf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ended, cut, err := assign.EndedAtChannel(held, answer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if cut != "" {
|
||||||
|
logf("%s at the bind: %s", channelAsksVerb, cut)
|
||||||
|
}
|
||||||
|
var putsKV jetstream.KeyValue
|
||||||
|
if js != nil {
|
||||||
|
if kv, err := js.KeyValue(ctx, buckets.Puts()); err == nil {
|
||||||
|
putsKV = kv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, e := range ended {
|
||||||
|
body, err := tellerevents.EncodeEnded(e)
|
||||||
|
if err == nil {
|
||||||
|
err = askAgain(ctx, asksKV, putsKV, stale, body, now, logf)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logf("%s at the bind of %s: %d of %d held asks ended at the channel without an answer", channelAsksVerb, created.Format(time.RFC3339), len(ended), len(held))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// askAgain writes the ask the teller said ended again under a new asking, by compare-and-set at the revision that holds the
|
||||||
|
// asking that ended (assign.AskedAgain), and says in the journal what it wrote or why it wrote nothing. Only a bus that
|
||||||
|
// could not be read or written is an error, so the event is heard again; a body that does not read is said and dropped.
|
||||||
|
func askAgain(ctx context.Context, asksKV, putsKV jetstream.KeyValue, stale staleOf, data []byte, now time.Time, logf func(string, ...any)) error {
|
||||||
|
e, err := tellerevents.DecodeEnded(data)
|
||||||
|
if err != nil {
|
||||||
|
logf("the teller's %s holds what is not an ended ask, and is dropped: %v", tellerevents.AskEnded, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if asksKV == nil {
|
||||||
|
return errors.New("the assigner's asks are not open")
|
||||||
|
}
|
||||||
|
var current []byte
|
||||||
|
var rev uint64
|
||||||
|
entry, err := asksKV.Get(ctx, e.Key)
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, jetstream.ErrKeyNotFound):
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
default:
|
||||||
|
current, rev = entry.Value(), entry.Revision()
|
||||||
|
}
|
||||||
|
var put *puts.Put
|
||||||
|
if k, err := asks.ParseAnyAskKey(e.Key); err == nil && k.Kind == asks.AskKindRecord && putsKV != nil {
|
||||||
|
if pkey, err := puts.Key(k.Node, k.Module); err == nil {
|
||||||
|
pe, err := putsKV.Get(ctx, pkey)
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, jetstream.ErrKeyNotFound):
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
default:
|
||||||
|
if p, err := puts.Decode(pe.Value()); err == nil {
|
||||||
|
put = &p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value, why := assign.AskedAgain(e, current, put, now)
|
||||||
|
if why == "" && stale != nil {
|
||||||
|
// An ask the pass takes away is not written again: it is about a move or a composition that has been left behind, and the
|
||||||
|
// pass removes it (issue 1966 note 165).
|
||||||
|
if s := stale(e.Key); s != "" {
|
||||||
|
why = "it is stale and left to the pass to take away: " + s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if why != "" {
|
||||||
|
logf("%s: the ask %s ended (%s) at the operator channel without an answer, and is not written again: %s", e.Key, e.Ask, e.Outcome, why)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if _, err := asksKV.Update(ctx, e.Key, value, rev); err != nil {
|
||||||
|
if errors.Is(err, jetstream.ErrKeyExists) {
|
||||||
|
logf("%s: the ask %s ended (%s) without an answer, and the key changed since: it is not written again", e.Key, e.Ask, e.Outcome)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logf("%s: the ask %s ended (%s) at the operator channel without an answer, and is written again under a new asking, which the teller asks", e.Key, e.Ask, e.Outcome)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||||
|
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/judge"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Which proposals the assigner asks of the operator is its setting ask-operator-for (design 47 G A-425, A-425a): a list of change
|
||||||
|
// kinds, set at mesh level with mesh-config's config, its default take-off, remove-node and stops. A proposal none of whose changes
|
||||||
|
// is listed is applied at once when its verdict passes, said in the log and by assignments-changed; one with a listed kind is
|
||||||
|
// asked as before. The setting is read from the file the manifest declares with the content ${config:ask-operator-for}, which the
|
||||||
|
// environment names (A-112), at every pass, and a change of it is said.
|
||||||
|
|
||||||
|
// KindStops is the change kind of a verdict whose answers say a node would stop running a module.
|
||||||
|
const KindStops = "stops"
|
||||||
|
|
||||||
|
// defaultAskOperatorFor is the setting's default.
|
||||||
|
var defaultAskOperatorFor = []string{mmac.OpTakeOff, mmac.OpRemoveNode, KindStops}
|
||||||
|
|
||||||
|
// askKinds are the kinds the setting may name.
|
||||||
|
var askKinds = []string{mmac.OpPlace, mmac.OpTakeOff, mmac.OpPin, mmac.OpUnpin, mmac.OpHold, mmac.OpUnhold, mmac.OpDecide, mmac.OpConfig,
|
||||||
|
mmac.OpAddNode, mmac.OpRemoveNode, KindStops}
|
||||||
|
|
||||||
|
// parseAskOperatorFor reads the setting's value: kinds separated by commas or spaces; empty is the default. A kind it does not
|
||||||
|
// know is answered apart and named nowhere in the list.
|
||||||
|
func parseAskOperatorFor(raw string) (kinds, unknown []string) {
|
||||||
|
fields := strings.FieldsFunc(raw, func(r rune) bool { return r == ',' || r == ' ' || r == '\n' || r == '\t' })
|
||||||
|
if len(fields) == 0 {
|
||||||
|
return slices.Clone(defaultAskOperatorFor), nil
|
||||||
|
}
|
||||||
|
for _, f := range fields {
|
||||||
|
f = strings.ToLower(strings.TrimSpace(f))
|
||||||
|
switch {
|
||||||
|
case !slices.Contains(askKinds, f):
|
||||||
|
unknown = append(unknown, f)
|
||||||
|
case !slices.Contains(kinds, f):
|
||||||
|
kinds = append(kinds, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slices.Sort(kinds)
|
||||||
|
return kinds, unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
// readAskOperatorFor reads the setting's file: the default for no path or no file.
|
||||||
|
func readAskOperatorFor(path string) (kinds, unknown []string, err error) {
|
||||||
|
if path == "" {
|
||||||
|
k, u := parseAskOperatorFor("")
|
||||||
|
return k, u, nil
|
||||||
|
}
|
||||||
|
raw, err := os.ReadFile(path)
|
||||||
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
|
k, u := parseAskOperatorFor("")
|
||||||
|
return k, u, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
k, u := parseAskOperatorFor(string(raw))
|
||||||
|
return k, u, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// askOperatorFor is the setting as this pass read it: the file read again each pass, a change said once, a file that cannot be
|
||||||
|
// read keeping what was read last (the default before any).
|
||||||
|
func (p *passer) askOperatorFor() []string {
|
||||||
|
kinds, unknown, err := readAskOperatorFor(p.askForFile)
|
||||||
|
if err != nil {
|
||||||
|
if p.askFor == nil {
|
||||||
|
p.askFor = slices.Clone(defaultAskOperatorFor)
|
||||||
|
}
|
||||||
|
p.logf("the setting ask-operator-for cannot be read from %s, so %s stands: %v", p.askForFile, strings.Join(p.askFor, ", "), err)
|
||||||
|
return p.askFor
|
||||||
|
}
|
||||||
|
if !slices.Equal(kinds, p.askFor) {
|
||||||
|
words := "the setting ask-operator-for is " + strings.Join(kinds, ", ") + ": a proposal with a change of another kind only is applied with no ask"
|
||||||
|
if len(unknown) > 0 {
|
||||||
|
words += "; kinds it names that are none are left out: " + strings.Join(unknown, ", ")
|
||||||
|
}
|
||||||
|
p.logf("%s", words)
|
||||||
|
p.askFor = kinds
|
||||||
|
}
|
||||||
|
return p.askFor
|
||||||
|
}
|
||||||
|
|
||||||
|
// asksFor says whether a proposal of these change kinds is asked of the operator.
|
||||||
|
func (p *passer) asksFor(kinds []string) bool {
|
||||||
|
set := p.askOperatorFor()
|
||||||
|
for _, k := range kinds {
|
||||||
|
if slices.Contains(set, k) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// proposalKinds are the change kinds of a proposal whose verdict is v: each change's op, and stops when an answer says a node
|
||||||
|
// would stop running a module.
|
||||||
|
func proposalKinds(prop mma.Proposal, v mma.Verdict) []string {
|
||||||
|
var out []string
|
||||||
|
for _, c := range prop.Changes {
|
||||||
|
if c.Op != "" && !slices.Contains(out, c.Op) {
|
||||||
|
out = append(out, c.Op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(judge.Stops(v)) > 0 {
|
||||||
|
out = append(out, KindStops)
|
||||||
|
}
|
||||||
|
slices.Sort(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G §717: the assigner's asks are the seat mesh-wants' state asks, so every key its asks package writes is one of
|
||||||
|
// that state's key forms, read back to the same parts, and each value is the seat's Ask.
|
||||||
|
func TestTheAssignersAsksAreTheSeatMeshWantsAsks(t *testing.T) {
|
||||||
|
const hex = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
||||||
|
const fp, digest = "src2:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
||||||
|
must := func(k string, err error) string {
|
||||||
|
t.Helper()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return k
|
||||||
|
}
|
||||||
|
three := func(parse func(string) (string, string, string, bool)) func(string) []string {
|
||||||
|
return func(k string) []string {
|
||||||
|
if a, b, c, ok := parse(k); ok {
|
||||||
|
return []string{a, b, c}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, row := range []struct {
|
||||||
|
key string
|
||||||
|
parse func(string) []string
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{must(asks.HoldAskKey("web", fp)), func(k string) []string {
|
||||||
|
if a, b, ok := meshwants.ParseAsksByHoldModuleFingerprintKey(k); ok {
|
||||||
|
return []string{a, b}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, []string{"web", hex}},
|
||||||
|
{must(asks.RestoreAskKey("ace", "web", fp)), three(meshwants.ParseAsksByRestoreNodeModuleFingerprintKey), []string{"ace", "web", hex}},
|
||||||
|
{must(asks.BackupAskKey("ace", "web", fp)), three(meshwants.ParseAsksByBackupNodeModuleFingerprintKey), []string{"ace", "web", hex}},
|
||||||
|
{must(asks.OutsideAskKey("ace", "web", fp)), three(meshwants.ParseAsksByOutsideNodeModuleFingerprintKey), []string{"ace", "web", hex}},
|
||||||
|
{must(asks.RevertAskKey("ace", "web", fp)), three(meshwants.ParseAsksByRevertNodeModuleFingerprintKey), []string{"ace", "web", hex}},
|
||||||
|
{must(asks.RecordAskKey("ace", "web", digest)), three(meshwants.ParseAsksByRecordNodeModuleDigestKey), []string{"ace", "web", "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}},
|
||||||
|
{must(asks.AssignmentsAskKey("p-20261028t183000-1a2b3c")), func(k string) []string {
|
||||||
|
if a, ok := meshwants.ParseAsksByAssignmentsProposalKey(k); ok {
|
||||||
|
return []string{a}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, []string{"p-20261028t183000-1a2b3c"}},
|
||||||
|
} {
|
||||||
|
got := row.parse(row.key)
|
||||||
|
if len(got) != len(row.want) {
|
||||||
|
t.Errorf("%s is no key form of mesh-wants' asks: read as %v", row.key, got)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for i := range got {
|
||||||
|
if got[i] != row.want[i] {
|
||||||
|
t.Errorf("%s reads as %v, want %v", row.key, got, row.want)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
key := must(asks.HoldAskKey("web", fp))
|
||||||
|
raw, err := asks.EncodeAsk(key, asks.Ask{Ask: json.RawMessage(`{"id":"x"}`), Asking: 2})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if v, err := meshwants.DecodeAsksByHoldModuleFingerprintValue(raw); err != nil || v.Asking != 2 {
|
||||||
|
t.Errorf("the ask %s is not the seat's Ask: %+v, %v", raw, v, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"maps"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/assignment"
|
||||||
|
)
|
||||||
|
|
||||||
|
// What a want names of a build is heard, never read from the builder's state (design 47 G §379, §526, A-94, A-96; ADR 0596 §2): the
|
||||||
|
// builder's event `build.ended` (a done build's parts by digest, its keeping node and its branch) and the catalog's
|
||||||
|
// `version-released` (a released version and each part's digest, with the source revision it was built from), each kept as heard.
|
||||||
|
|
||||||
|
// builtEnds are the done builds' ends heard, by module and fingerprint (hearBuildEnded).
|
||||||
|
type builtEnds struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
ends map[string]builds.BuildEnded
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *builtEnds) key(module, fp string) string { return module + "@" + fp }
|
||||||
|
|
||||||
|
// put takes one build.ended in.
|
||||||
|
func (b *builtEnds) put(data []byte) error {
|
||||||
|
var e builds.BuildEnded
|
||||||
|
if err := json.Unmarshal(data, &e); err != nil {
|
||||||
|
return fmt.Errorf("a build.ended that is no end: %w", err)
|
||||||
|
}
|
||||||
|
if e.Module == "" || e.Fingerprint == "" {
|
||||||
|
return fmt.Errorf("a build's end naming no module or fingerprint: %s", data)
|
||||||
|
}
|
||||||
|
if e.Outcome == "" { // an end said before A-162 is a done build's
|
||||||
|
e.Outcome = builds.BuildDone
|
||||||
|
}
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
|
if b.ends == nil {
|
||||||
|
b.ends = map[string]builds.BuildEnded{}
|
||||||
|
}
|
||||||
|
b.ends[b.key(e.Module, e.Fingerprint)] = e
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// endOf is the end heard of module's build at fp, done or failed (A-162): none while the build has not ended.
|
||||||
|
func (b *builtEnds) endOf(module, fp string) (builds.BuildEnded, bool) {
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
|
e, ok := b.ends[b.key(module, fp)]
|
||||||
|
return e, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// partsOf is the parts of module's build at fp as its end names them (each artifact's digest by `<module>:<artifact>`), with the
|
||||||
|
// node that keeps it, for a kept build or a build of another watched branch; false for a build of the trunk not kept, whose
|
||||||
|
// parts the version's release says (releasedVersions).
|
||||||
|
func (b *builtEnds) partsOf(module, fp string) (assign.KeptBuild, bool) {
|
||||||
|
b.mu.Lock()
|
||||||
|
e, ok := b.ends[b.key(module, fp)]
|
||||||
|
b.mu.Unlock()
|
||||||
|
if !ok || (e.KeptOn == "" && e.Branch == "") {
|
||||||
|
return assign.KeptBuild{}, false
|
||||||
|
}
|
||||||
|
parts := map[string]string{}
|
||||||
|
for name, digest := range e.Made {
|
||||||
|
parts[module+":"+name] = digest
|
||||||
|
}
|
||||||
|
return assign.KeptBuild{Parts: parts, KeptOn: e.KeptOn}, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// releasedVersions are the catalog's version-released heard, by module and source revision.
|
||||||
|
type releasedVersions struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
seen map[string]assign.KeptBuild
|
||||||
|
// newest is, by module, the last version-released heard of it (delivered.go).
|
||||||
|
newest map[string]releaseHeard
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *releasedVersions) key(module string, source int64) string {
|
||||||
|
return fmt.Sprintf("%s@%d", module, source)
|
||||||
|
}
|
||||||
|
|
||||||
|
// put takes one version-released in.
|
||||||
|
func (r *releasedVersions) put(data []byte) error {
|
||||||
|
var e meshcatalog.VersionReleasedEvent
|
||||||
|
if err := json.Unmarshal(data, &e); err != nil {
|
||||||
|
return fmt.Errorf("a version-released that is none: %w", err)
|
||||||
|
}
|
||||||
|
if e.Module == "" || e.Version == "" {
|
||||||
|
return fmt.Errorf("a version-released naming no module or version: %s", data)
|
||||||
|
}
|
||||||
|
parts := map[string]string{}
|
||||||
|
for _, a := range e.Artifacts {
|
||||||
|
parts[partRef(e.Module, a.Artifact)] = a.Digest
|
||||||
|
}
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
if r.seen == nil {
|
||||||
|
r.seen = map[string]assign.KeptBuild{}
|
||||||
|
}
|
||||||
|
r.seen[r.key(e.Module, e.Source)] = assign.KeptBuild{Version: e.Version, Parts: parts}
|
||||||
|
if r.newest == nil {
|
||||||
|
r.newest = map[string]releaseHeard{}
|
||||||
|
}
|
||||||
|
h := releaseHeard{Version: e.Version, Parts: parts, Source: e.Source}
|
||||||
|
if e.At != nil {
|
||||||
|
h.At = *e.At
|
||||||
|
}
|
||||||
|
r.newest[e.Module] = h // the stream's order is the order of release
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// withParts is the version of module whose release named exactly parts (`<module>:<artifact>` -> digest), the newest such when
|
||||||
|
// more than one did; false when none did or parts is empty (design 47 G A-421).
|
||||||
|
func (r *releasedVersions) withParts(module string, parts map[string]string) (assign.KeptBuild, bool) {
|
||||||
|
if len(parts) == 0 {
|
||||||
|
return assign.KeptBuild{}, false
|
||||||
|
}
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
var out assign.KeptBuild
|
||||||
|
found := false
|
||||||
|
for key, k := range r.seen {
|
||||||
|
if m, _, ok := strings.Cut(key, "@"); !ok || m != module || !maps.Equal(k.Parts, parts) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !found || compareVersion(k.Version, out.Version) > 0 {
|
||||||
|
out, found = k, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out, found
|
||||||
|
}
|
||||||
|
|
||||||
|
// madeOf is what module's done build at fp made, by `<module>:<artifact>`, as its build.ended names it; none for a build not heard
|
||||||
|
// or not done (design 47 G A-421).
|
||||||
|
func (b *builtEnds) madeOf(module, fp string) map[string]string {
|
||||||
|
e, ok := b.endOf(module, fp)
|
||||||
|
if !ok || e.Outcome != builds.BuildDone {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
parts := map[string]string{}
|
||||||
|
for name, digest := range e.Made {
|
||||||
|
parts[module+":"+name] = digest
|
||||||
|
}
|
||||||
|
return parts
|
||||||
|
}
|
||||||
|
|
||||||
|
// of is the version of module released from the source revision, with its parts' digests; false before it is heard.
|
||||||
|
func (r *releasedVersions) of(module string, source int64) (assign.KeptBuild, bool) {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
k, ok := r.seen[r.key(module, source)]
|
||||||
|
return k, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildsStreamName is the builder's stream of build ends as the bus names it: kept last per subject (one end per module and
|
||||||
|
// fingerprint, its manifest's `last-per-subject`, design 47 G A-181, §703).
|
||||||
|
var buildsStreamName = catalogue.StreamBusName(builds.BuildsStream)
|
||||||
|
|
||||||
|
// hearBuilds reads the builder's stream of build ends whole at the start and then follows it (design 47 G A-181, §556): what was
|
||||||
|
// built, and a failed build's error, survive the assigner's restart, and it reads none of the builder's buckets. The read ends before
|
||||||
|
// it returns, so the first pass knows every build; a stream it cannot hear is said, and no want names a build until the assigner
|
||||||
|
// starts again.
|
||||||
|
func hearBuilds(ctx context.Context, js jetstream.JetStream, ends *builtEnds, wake func(), findings assign.Findings, logf func(string, ...any)) {
|
||||||
|
acct := process.Account{Node: thisNode, Module: assignment.Module()}
|
||||||
|
nh := notHeardWriter(findings, logf)
|
||||||
|
cc, err := acct.HearStream(ctx, js, buildsStreamName, func(m jetstream.Msg) {
|
||||||
|
if err := ends.put(m.Data()); err != nil {
|
||||||
|
logf("%s is not kept: %v", m.Subject(), err)
|
||||||
|
}
|
||||||
|
if err := m.Ack(); err != nil {
|
||||||
|
logf("acknowledging %s: %v", m.Subject(), err)
|
||||||
|
}
|
||||||
|
wake()
|
||||||
|
}, logf, process.FromFirst()) // read whole from its first message whether the bus keeps it last per subject or by age (A-181, A-233)
|
||||||
|
if err != nil {
|
||||||
|
nh.NotHeard(buildsStreamName, "what the builder built is not heard until the assigner starts again, so no want names a build's parts or its keeping node and no put goes on", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nh.Heard(buildsStreamName)
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
cc.Stop()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearTaken registers the hub's taker of the indexer's take-in.taken, each waking the pass (orderwaits.go, §298, A-260); before
|
||||||
|
// the hub starts.
|
||||||
|
func hearTaken(hub *process.EventHub, taken *takenSources, wake func(), logf func(string, ...any)) error {
|
||||||
|
return hub.Handle(takenSubject, func(m jetstream.Msg) {
|
||||||
|
if err := taken.put(m.Data()); err != nil {
|
||||||
|
logf("%s is not kept: %v", m.Subject(), err)
|
||||||
|
}
|
||||||
|
if err := m.Ack(); err != nil {
|
||||||
|
logf("acknowledging %s: %v", m.Subject(), err)
|
||||||
|
}
|
||||||
|
wake()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// compareVersion orders two MAJOR.MINOR.PATCH versions by their numbers; a part that is no number counts as 0.
|
||||||
|
func compareVersion(a, b string) int {
|
||||||
|
pa, pb := strings.Split(a, "."), strings.Split(b, ".")
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
var x, y int
|
||||||
|
if i < len(pa) {
|
||||||
|
x, _ = strconv.Atoi(pa[i])
|
||||||
|
}
|
||||||
|
if i < len(pb) {
|
||||||
|
y, _ = strconv.Atoi(pb[i])
|
||||||
|
}
|
||||||
|
if x != y {
|
||||||
|
return x - y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// partRef is a release's artifact as a part's key, `<module>:<artifact>`: the contract's VersionArtifact names the artifact
|
||||||
|
// reference whole (an ArtifactRef), as the catalog's version-released says it; a bare name is taken as the module's (A-96).
|
||||||
|
func partRef(module, artifact string) string {
|
||||||
|
if strings.Contains(artifact, ":") {
|
||||||
|
return artifact
|
||||||
|
}
|
||||||
|
return module + ":" + artifact
|
||||||
|
}
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G §379, §526, A-96: a build.ended heard names a kept build's or another branch's parts by digest (`<module>:<artifact>`) and its
|
||||||
|
// keeping node; a build of the trunk not kept names none, its parts being the release's.
|
||||||
|
func TestABuildEndedHeardNamesAKeptBuildsPartsAndItsNode(t *testing.T) {
|
||||||
|
put := func(b *builtEnds, e builds.BuildEnded) {
|
||||||
|
raw, _ := json.Marshal(e)
|
||||||
|
if err := b.put(raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
made := map[string]string{"program": "sha256:1"}
|
||||||
|
var b builtEnds
|
||||||
|
put(&b, builds.BuildEnded{Module: "node-engine", Fingerprint: "a", Made: made})
|
||||||
|
if _, ok := b.partsOf("node-engine", "a"); ok {
|
||||||
|
t.Error("a trunk build not kept names parts")
|
||||||
|
}
|
||||||
|
put(&b, builds.BuildEnded{Module: "node-engine", Fingerprint: "b", Made: made, KeptOn: "ace"})
|
||||||
|
if k, ok := b.partsOf("node-engine", "b"); !ok || k.KeptOn != "ace" || !reflect.DeepEqual(k.Parts, map[string]string{"node-engine:program": "sha256:1"}) {
|
||||||
|
t.Errorf("kept build = %+v, %v", k, ok)
|
||||||
|
}
|
||||||
|
put(&b, builds.BuildEnded{Module: "node-engine", Fingerprint: "c", Made: made, Branch: "cand"})
|
||||||
|
if k, ok := b.partsOf("node-engine", "c"); !ok || k.KeptOn != "" || len(k.Parts) != 1 {
|
||||||
|
t.Errorf("branch build = %+v, %v", k, ok)
|
||||||
|
}
|
||||||
|
if err := b.put([]byte(`{"module":"x"}`)); err == nil {
|
||||||
|
t.Error("an end naming no fingerprint is kept")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §379, A-96: a version-released heard names the version and the parts' digests of the module's source revision.
|
||||||
|
func TestAVersionReleasedHeardNamesItsVersionAndPartsBySource(t *testing.T) {
|
||||||
|
var r releasedVersions
|
||||||
|
raw, _ := json.Marshal(meshcatalog.VersionReleasedEvent{Module: "mail", Source: 7, Version: "1.2.3", Artifacts: []meshcatalog.VersionArtifact{{Artifact: "image", Digest: "sha256:9"}}})
|
||||||
|
if err := r.put(raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
want := assign.KeptBuild{Version: "1.2.3", Parts: map[string]string{"mail:image": "sha256:9"}}
|
||||||
|
if k, ok := r.of("mail", 7); !ok || !reflect.DeepEqual(k, want) {
|
||||||
|
t.Errorf("released = %+v, %v", k, ok)
|
||||||
|
}
|
||||||
|
if _, ok := r.of("mail", 8); ok {
|
||||||
|
t.Error("another source revision names a version")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §379, A-96, A-419: the trunk's entry takes its version and parts from the version-released of the source its
|
||||||
|
// fingerprint was built at (its fp-src), whatever source the kept assignment graph revision is at; a kept build from its end; no
|
||||||
|
// revision kept, another fingerprint, an fp-src with no release or none names none, and an unheard release is said once.
|
||||||
|
func TestATrunkEntryTakesItsVersionFromTheReleaseOfItsFingerprintsSource(t *testing.T) {
|
||||||
|
w := newWorld()
|
||||||
|
raw, _ := json.Marshal(meshcatalog.VersionReleasedEvent{Module: "mail", Source: 7, Version: "1.2.3", Artifacts: []meshcatalog.VersionArtifact{{Artifact: "mail:image", Digest: "sha256:9"}}})
|
||||||
|
if err := w.released.put(raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
endRaw, _ := json.Marshal(builds.BuildEnded{Module: "mail", Fingerprint: "k", Made: map[string]string{"image": "sha256:2"}, KeptOn: "g14"})
|
||||||
|
if err := w.ends.put(endRaw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var logs []string
|
||||||
|
p := &passer{w: w, graph: &graphKeeper{ok: true, source: 7}, logf: func(f string, a ...any) { logs = append(logs, fmt.Sprintf(f, a...)) }}
|
||||||
|
named := p.namedBuild("mail", "t", 7)
|
||||||
|
if k, ok := named("t"); !ok || k.Version != "1.2.3" || k.Parts["mail:image"] != "sha256:9" || k.KeptOn != "" {
|
||||||
|
t.Errorf("trunk entry = %+v, %v", k, ok)
|
||||||
|
}
|
||||||
|
if k, ok := named("k"); !ok || k.KeptOn != "g14" || k.Version != "" {
|
||||||
|
t.Errorf("kept build = %+v, %v", k, ok)
|
||||||
|
}
|
||||||
|
if _, ok := named("other"); ok {
|
||||||
|
t.Error("another fingerprint names a release")
|
||||||
|
}
|
||||||
|
// A build held back at an older fingerprint names the release whose parts are exactly what it made.
|
||||||
|
heldRaw, _ := json.Marshal(builds.BuildEnded{Module: "mail", Fingerprint: "old", Made: map[string]string{"image": "sha256:9"}})
|
||||||
|
if err := w.ends.put(heldRaw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if k, ok := named("old"); !ok || k.Version != "1.2.3" {
|
||||||
|
t.Errorf("a held build whose parts were released = %+v, %v; want 1.2.3", k, ok)
|
||||||
|
}
|
||||||
|
p.graph.source = 8 // a later merge that did not rebuild mail
|
||||||
|
if k, ok := named("t"); !ok || k.Version != "1.2.3" {
|
||||||
|
t.Errorf("after a later merge the trunk entry = %+v, %v; want the release of its fingerprint's source", k, ok)
|
||||||
|
}
|
||||||
|
if _, ok := p.namedBuild("mail", "t", 8)("t"); ok {
|
||||||
|
t.Error("an fp-src with no release names a version")
|
||||||
|
}
|
||||||
|
_, _ = p.namedBuild("mail", "t", 8)("t")
|
||||||
|
if _, ok := p.namedBuild("mail", "t", 0)("t"); ok {
|
||||||
|
t.Error("an entry naming no fp-src, whose build.ended is not heard, names a version")
|
||||||
|
}
|
||||||
|
// The release names each artifact by its whole reference, as the catalog says it, and the parts are keyed so (A-96); the
|
||||||
|
// assigner reads the entry's fp-src from its inputs (A-419).
|
||||||
|
// A-429: a released version's build counts as done for rule 1; a kept build (no version) and an unknown one do not.
|
||||||
|
if !releasedBuild(p.namedBuild("mail", "t", 7), "t") || releasedBuild(p.namedBuild("mail", "t", 7), "k") || releasedBuild(p.namedBuild("mail", "t", 8), "t") || releasedBuild(nil, "t") {
|
||||||
|
t.Error("rule 1's released build: the release of the entry's fingerprint counts, a kept build, another source or none does not")
|
||||||
|
}
|
||||||
|
if v, _, _ := fromEntry(meshcatalog.CatalogEntry{Module: "mail", Fp: "t", Inputs: &meshcatalog.EntryInputs{Src: 9, FpSrc: 7}}); v.FpSrc != 7 || v.Src != 9 {
|
||||||
|
t.Errorf("the entry's module value carries fp-src %d and src %d, want 7 and 9", v.FpSrc, v.Src)
|
||||||
|
}
|
||||||
|
// A-421: an entry naming no fp-src takes the release whose parts are what its build.ended made.
|
||||||
|
made, _ := json.Marshal(builds.BuildEnded{Module: "mail", Fingerprint: "t", Made: map[string]string{"image": "sha256:9"}})
|
||||||
|
if err := w.ends.put(made); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if k, ok := p.namedBuild("mail", "t", 0)("t"); !ok || k.Version != "1.2.3" {
|
||||||
|
t.Errorf("an entry naming no fp-src, its build made the released digests: %+v, %v", k, ok)
|
||||||
|
}
|
||||||
|
// A release from an earlier source than the entry's fp-src (novox 2026-11-16, 962 against 963) is still this build's when
|
||||||
|
// its parts are exactly what the build made.
|
||||||
|
if k, ok := p.namedBuild("mail", "t", 8)("t"); !ok || k.Version != "1.2.3" || k.Parts["mail:image"] != "sha256:9" {
|
||||||
|
t.Errorf("an fp-src with no release, its build made the released digests: %+v, %v", k, ok)
|
||||||
|
}
|
||||||
|
if len(logs) != 2 || !strings.Contains(logs[0], "the release of mail at fingerprint t is not heard: no version-released of it from source 8") || !strings.Contains(logs[1], "names no fp-src, and no version-released of it names the parts its build.ended made") {
|
||||||
|
t.Errorf("logs = %q, want each unheard release said once, naming the module, the fingerprint and the source", logs)
|
||||||
|
}
|
||||||
|
p.graph.ok = false
|
||||||
|
if _, ok := p.namedBuild("mail", "t", 7)("t"); ok {
|
||||||
|
t.Error("no revision kept names a release")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-162: the assigner knows a failed build from its `build.ended`: the error whole; a done end or none heard is not failed.
|
||||||
|
func TestTheStandingOfABuildIsHeardFromItsEnd(t *testing.T) {
|
||||||
|
w := newWorld()
|
||||||
|
say := func(e builds.BuildEnded) {
|
||||||
|
raw, _ := json.Marshal(e)
|
||||||
|
if err := w.ends.put(raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if failed, _ := w.buildStanding("web", "fp1"); failed {
|
||||||
|
t.Error("a build nothing was heard of failed")
|
||||||
|
}
|
||||||
|
say(builds.BuildEnded{Module: "web", Fingerprint: "fp1", Outcome: builds.BuildFailed, Error: "transport fault: connection"})
|
||||||
|
if failed, why := w.buildStanding("web", "fp1"); !failed || why != "transport fault: connection" {
|
||||||
|
t.Errorf("failed end: failed %v why %q", failed, why)
|
||||||
|
}
|
||||||
|
say(builds.BuildEnded{Module: "web", Fingerprint: "fp1", Outcome: builds.BuildDone})
|
||||||
|
if failed, _ := w.buildStanding("web", "fp1"); failed {
|
||||||
|
t.Error("a later done end leaves the build failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||||
|
)
|
||||||
|
|
||||||
|
// endDone is the builder's `build.ended` of a done build of module at fp heard by w, naming the digest of its manifest (design 47 G
|
||||||
|
// A-181: what was built is heard, never read from the builder's bucket).
|
||||||
|
func endDone(t testing.TB, w *world, module, fp, manifest string) {
|
||||||
|
t.Helper()
|
||||||
|
data, err := json.Marshal(builds.BuildEnded{Module: module, Fingerprint: fp, Outcome: builds.BuildDone, Manifest: manifest})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := w.ends.put(data); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// trunkBranch is the first watched branch the tests give the world: the code names none (design 47 G §507).
|
||||||
|
const trunkBranch = "main"
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||||
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
|
plc "mesh-delivery-assigner/internal/assignment"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// addedOf is the `added` of node's candidate (design 47 G A-316, §379, §421): by module, each module the candidate adds to node
|
||||||
|
// (laid over current) with no want there, the version and parts the want it would write carries, taken from the same code that
|
||||||
|
// writes a want's (namedBuild, the want's build at the fingerprint of the branch the want's code takes). A module whose build names none is not listed.
|
||||||
|
func (p *passer) addedOf(node string, laid *mma.Assignments, current map[string]mma.Assignments) map[string]mma.AddedModule {
|
||||||
|
if laid == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
placed := map[string]string{}
|
||||||
|
for _, m := range laid.Modules {
|
||||||
|
placed[m.Module] = m.Branch
|
||||||
|
}
|
||||||
|
var out map[string]mma.AddedModule
|
||||||
|
for _, module := range plc.ChangeOf(current[node], *laid).Added {
|
||||||
|
if key, err := mwc.WantKey(node, module); err != nil || p.w.has(buckets.Wants(), key) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// The branch the want's code takes: the one the candidate's placement names, else the module's default (groups, wants).
|
||||||
|
branch := p.w.trunkName()
|
||||||
|
if p.ends.following() {
|
||||||
|
branch = p.ends.branchOf(module, placed[module])
|
||||||
|
}
|
||||||
|
entry := p.w.trunkOf(branch)[module]
|
||||||
|
fp := entry.Fp2
|
||||||
|
if fp == "" {
|
||||||
|
p.skippedAdd(node, module, "", "the branch "+branch+" names no fingerprint of it")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
k, ok := p.namedBuild(module, fp, entry.FpSrc)(fp)
|
||||||
|
if !ok {
|
||||||
|
p.skippedAdd(node, module, fp, "no version-released of it is heard for that fingerprint, so the candidate carries no version and no parts")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if out == nil {
|
||||||
|
out = map[string]mma.AddedModule{}
|
||||||
|
}
|
||||||
|
added := mma.AddedModule{Version: k.Version, Parts: k.Parts}
|
||||||
|
if k.Version != "" {
|
||||||
|
added.Parts = nil // a released build is named by its version alone (design 47 G A-430, A-430a)
|
||||||
|
}
|
||||||
|
out[module] = added
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// candidateOf is the candidate of proposal id for node: the assignments laid over it, and what it adds (addedOf).
|
||||||
|
func (p *passer) candidateOf(id, node string, laid *mma.Assignments, current map[string]mma.Assignments) mma.CandidatesByProposalNodeValue {
|
||||||
|
return mma.CandidatesByProposalNodeValue{Proposal: id, Assignments: laid, Added: p.addedOf(node, laid, current)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// skippedAdd says once per node, module and fingerprint why a module the candidate adds is not listed in `added`.
|
||||||
|
func (p *passer) skippedAdd(node, module, fp, why string) {
|
||||||
|
key := node + "/" + module + "@" + fp + ": " + why
|
||||||
|
if p.skipped[key] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if p.skipped == nil {
|
||||||
|
p.skipped = map[string]bool{}
|
||||||
|
}
|
||||||
|
p.skipped[key] = true
|
||||||
|
if p.logf != nil {
|
||||||
|
p.logf("the candidate adds %s to %s with no parts: %s (fingerprint %q)", module, node, why, fp)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G A-316: the candidate of a node carries, for each module it adds there without a want, the version and parts the
|
||||||
|
// want it would write carries; a module with a want there, or a build that names none, is not listed.
|
||||||
|
func TestACandidateThatAddsAModuleCarriesItsParts(t *testing.T) {
|
||||||
|
w := newWorld()
|
||||||
|
for _, m := range []string{"mail", "web", "db"} {
|
||||||
|
w.putModule("main", m, meshcatalog.ModulesByModuleValue{Fp2: "fp-" + m, FpSrc: 7}, graph.Node{}, nil)
|
||||||
|
}
|
||||||
|
w.first = "main"
|
||||||
|
rel, _ := json.Marshal(meshcatalog.VersionReleasedEvent{Module: "mail", Source: 7, Version: "1.2.3", Artifacts: []meshcatalog.VersionArtifact{{Artifact: "mail:image", Digest: "sha256:9"}}})
|
||||||
|
if err := w.released.put(rel); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
end, _ := json.Marshal(builds.BuildEnded{Module: "db", Fingerprint: "fp-db", Made: map[string]string{"program": "sha256:3"}, KeptOn: "g14"})
|
||||||
|
if err := w.ends.put(end); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
w.put(buckets.Wants(), "want.ace.web", []byte(`{}`))
|
||||||
|
p := &passer{w: w, graph: &graphKeeper{ok: true, source: 9}} // a later merge: the release is matched by fp-src (A-419)
|
||||||
|
laid := &mma.Assignments{Node: "ace", Modules: []mma.PlacedModule{{Module: "mail"}, {Module: "web"}, {Module: "db"}, {Module: "old"}}}
|
||||||
|
current := map[string]mma.Assignments{"ace": {Node: "ace", Modules: []mma.PlacedModule{{Module: "old"}}}}
|
||||||
|
c := p.candidateOf("p1", "ace", laid, current)
|
||||||
|
want := map[string]mma.AddedModule{
|
||||||
|
"mail": {Version: "1.2.3"}, // a released build is named by its version alone (A-430a)
|
||||||
|
"db": {Parts: map[string]string{"db:program": "sha256:3"}},
|
||||||
|
}
|
||||||
|
if c.Proposal != "p1" || c.Assignments != laid || !reflect.DeepEqual(c.Added, want) {
|
||||||
|
t.Errorf("candidate = %+v, added want %+v", c, want)
|
||||||
|
}
|
||||||
|
if got := p.candidateOf("p1", "ace", nil, current); got.Added != nil {
|
||||||
|
t.Errorf("a candidate taking the key away adds %+v", got.Added)
|
||||||
|
}
|
||||||
|
// A placement on a watched branch is added at that branch's fingerprint, as the want's code takes it, not the trunk's.
|
||||||
|
w.putModule("feat", "mail", meshcatalog.ModulesByModuleValue{Fp2: "fp-feat"}, graph.Node{}, nil)
|
||||||
|
feat, _ := json.Marshal(builds.BuildEnded{Module: "mail", Fingerprint: "fp-feat", Made: map[string]string{"program": "sha256:4"}, KeptOn: "g14"})
|
||||||
|
if err := w.ends.put(feat); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||||
|
p.ends.trunk = w.trunkName
|
||||||
|
p.ends.on.Store(true)
|
||||||
|
onFeat := &mma.Assignments{Node: "g14", Modules: []mma.PlacedModule{{Module: "mail", Branch: "feat"}}}
|
||||||
|
if got, want := p.candidateOf("p2", "g14", onFeat, nil).Added, map[string]mma.AddedModule{"mail": {Parts: map[string]string{"mail:program": "sha256:4"}}}; !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("a placement on branch feat adds %+v, want %+v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"maps"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A run's candidate assignment graph (design 47 G §189, §190, A-201, A-235): the candidate `run-<id>`'s catalog graph revision,
|
||||||
|
// handed by meshcatalogclient's candidates hook, is read whole through the catalog seat's verb revision; the assignment graph is
|
||||||
|
// computed from it in place of its branch's half, beside every other followed branch's, and kept under candidate.<group>.<heads>;
|
||||||
|
// the runner's group-ended of the run drops it. It writes no want and says no event; the gate's heads-replaced drops nothing.
|
||||||
|
|
||||||
|
// runGroupPrefix is a run on request's candidate group before its id, `run-<id>` (A-160).
|
||||||
|
const runGroupPrefix = "run-"
|
||||||
|
|
||||||
|
// readCandidateHalf reads a candidate's catalog graph revision whole through the seat's verb revision, page by page, with the
|
||||||
|
// candidate's group and heads and the revision its event names.
|
||||||
|
func readCandidateHalf(call mcc.Call, ev meshcatalog.CatalogRevisionEvent) (mcc.Half, error) {
|
||||||
|
half := mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{}}
|
||||||
|
after := ""
|
||||||
|
for {
|
||||||
|
a, err := askCandidatePage(call, meshcatalog.RevisionInput{Branch: ev.Branch, Group: ev.Group, Heads: ev.Heads, Revision: ev.Revision, After: after})
|
||||||
|
if err != nil {
|
||||||
|
return half, err
|
||||||
|
}
|
||||||
|
if a.Revision == nil || a.Revision.Revision != ev.Revision || a.Revision.Group != ev.Group {
|
||||||
|
return half, fmt.Errorf("%s answered %+v for the candidate %s's revision %d", mcc.RevisionVerb, a.Revision, ev.Group, ev.Revision)
|
||||||
|
}
|
||||||
|
half.Revision = *a.Revision
|
||||||
|
for _, e := range a.Entries {
|
||||||
|
half.Entries[e.Module] = e
|
||||||
|
}
|
||||||
|
if a.Next == "" {
|
||||||
|
return half, nil
|
||||||
|
}
|
||||||
|
after = a.Next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// keepCandidate computes and keeps the candidate's assignment graph of a run's catalog-revision; another candidate's (a try's, a
|
||||||
|
// group's) is passed over.
|
||||||
|
func (p *passer) keepCandidate(ctx context.Context, call mcc.Call, ev meshcatalog.CatalogRevisionEvent) error {
|
||||||
|
if !strings.HasPrefix(ev.Group, runGroupPrefix) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
g := p.graph
|
||||||
|
if g == nil || g.objects == nil || g.halves == nil {
|
||||||
|
return errors.New("the assigner keeps no assignment graph, so no candidate's is kept")
|
||||||
|
}
|
||||||
|
half, err := readCandidateHalf(call, ev)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("the candidate %s's revision %d is not read, so its assignment graph is not kept: %w", ev.Group, ev.Revision, err)
|
||||||
|
}
|
||||||
|
in := p.graphInputs()
|
||||||
|
in.Halves = maps.Clone(in.Halves)
|
||||||
|
in.Halves[half.Revision.Branch] = half
|
||||||
|
c := assigngraph.Compute(in)
|
||||||
|
for _, u := range c.Uncomputed {
|
||||||
|
p.logf("the candidate %s's assignment graph leaves out %s", ev.Group, u)
|
||||||
|
}
|
||||||
|
rev, fresh, err := assigngraph.KeepCandidate(ctx, g.objects, c, ev.Group, ev.Heads, meshcatalog.EventCatalogRevision, p.clock())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("the candidate %s's assignment graph is not kept: %w", ev.Group, err)
|
||||||
|
}
|
||||||
|
if fresh {
|
||||||
|
p.logf("the candidate %s's assignment graph revision %d is kept, from its catalog graph revision %d", ev.Group, rev.Revision, ev.Revision)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// dropCandidate removes a run's candidate assignment graph on the runner's group-ended of that run (A-235).
|
||||||
|
func (p *passer) dropCandidate(ctx context.Context, group string) error {
|
||||||
|
g := p.graph
|
||||||
|
if g == nil || g.objects == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
o, ok := g.objects.(assigngraph.Remover)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("the objects %s remove nothing, so the candidate %s is kept", assigngraph.RevisionsObjects, group)
|
||||||
|
}
|
||||||
|
n, err := assigngraph.DropCandidate(ctx, o, group)
|
||||||
|
if err == nil && n > 0 {
|
||||||
|
p.logf("the candidate %s's assignment graph is dropped: its run ended", group)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// askCandidatePage is one page of a candidate's revision as the seat's verb revision answers it.
|
||||||
|
func askCandidatePage(call mcc.Call, in meshcatalog.RevisionInput) (meshcatalog.RevisionAnswer, error) {
|
||||||
|
raw, err := call(mcc.RevisionVerb, in)
|
||||||
|
if err != nil {
|
||||||
|
return meshcatalog.RevisionAnswer{}, err
|
||||||
|
}
|
||||||
|
answer, said, ok := buscalls.Unwrap(raw)
|
||||||
|
if !ok {
|
||||||
|
return meshcatalog.RevisionAnswer{}, fmt.Errorf("%s answered: %s", mcc.RevisionVerb, said)
|
||||||
|
}
|
||||||
|
var a meshcatalog.RevisionAnswer
|
||||||
|
if err := json.Unmarshal(answer, &a); err != nil {
|
||||||
|
return a, fmt.Errorf("%s answered no revision: %w", mcc.RevisionVerb, err)
|
||||||
|
}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/catalogkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Every node's published compositions, read only to compare (novox/hq ADR 0593 §8): each node's engine writes its own
|
// Every node's published compositions, read only to compare (novox/hq ADR 0593 §8): each node's engine writes its own
|
||||||
@@ -44,7 +44,7 @@ func published(values map[string][]byte) map[string][]publishedRow {
|
|||||||
_, module, part, isNode, err := nodeengineclient.ParseComposedKey(key)
|
_, module, part, isNode, err := nodeengineclient.ParseComposedKey(key)
|
||||||
var fp string
|
var fp string
|
||||||
if err == nil && !isNode {
|
if err == nil && !isNode {
|
||||||
fp, err = meshcatalogclient.ParseKeyPart(part)
|
fp, err = catalogkey.ParseKeyPart(part)
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case err != nil:
|
case err != nil:
|
||||||
|
|||||||
@@ -0,0 +1,375 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A composition run's bound (design 47 G §720; A-466n, A-466p, A-466q, A-466s, A-468b, A-469b, A-469s, A-469y, A-470): a run
|
||||||
|
// has one clock, the key `bound.<run key>` of composition-runs with its own time to live composition-step-bound, written at the
|
||||||
|
// build seat's ask-taken of the run's ask and written again at each step-progress of that ask; an ask still waiting in the queue
|
||||||
|
// has no clock but `untaken.<run key>`, written at the run's start with the time to live run-untaken-bound. Either's expiry,
|
||||||
|
// heard as the bus's event, ends the run: its ask dropped through the build seat's drop, the run ended could not run naming the
|
||||||
|
// ask and the bound, so every reader ends could not run with it. While the ask waits for a build node each reader is said waiting
|
||||||
|
// by a wait-held on mesh-wants (`on: build node`), ended `ran` at ask-taken or `superseded` when the run ends untaken.
|
||||||
|
|
||||||
|
// waitOnBuildNode is what a composition run's waiting reader waits on (A-469b, A-469y).
|
||||||
|
const waitOnBuildNode = "build node"
|
||||||
|
|
||||||
|
// dropVerbKey is the Go build seat's drop, asked as a kept call (§119, A-182).
|
||||||
|
const dropVerbKey = "seat:" + nodebuildgo.Seat + "." + nodebuildgo.VerbDrop
|
||||||
|
|
||||||
|
// dropOver asks the Go build seat's drop of a run ask as a kept call, of any holder, which records it (A-469s).
|
||||||
|
func dropOver(call func(key string, body any) (json.RawMessage, error)) func(ask, why string) error {
|
||||||
|
return func(ask, why string) error {
|
||||||
|
raw, err := call(dropVerbKey, nodebuildgo.DropInput{ID: ask, Why: why, By: runAsker})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, said, ok := buscalls.Unwrap(raw); !ok {
|
||||||
|
return fmt.Errorf("%s answered: %s", dropVerbKey, said)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitOf is a reader's wait for a build node to take its run's ask (A-469y).
|
||||||
|
func waitOf(run meshwants.CompositionRun, reader meshwants.CompositionReader) meshwants.Wait {
|
||||||
|
w := meshwants.Wait{Step: "pipeline", Owner: meshwants.Seat, Module: reader.Module, Node: run.Machine, On: waitOnBuildNode, Fp: reader.Fingerprint,
|
||||||
|
Words: fmt.Sprintf("the composition step of %s waits for a build node to take the composition run %s of %s (ask %s)", reader.Pipeline,
|
||||||
|
runKeyOf(run.Candidate, run.Machine), run.Machine, run.Ask)}
|
||||||
|
if run.Started != nil {
|
||||||
|
w.Since = *run.Started
|
||||||
|
}
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
|
||||||
|
// sayWaits says, for each reader, its wait held or ended (how: ran, superseded); a wait that cannot be said is journaled.
|
||||||
|
func (r *compositionRuns) sayWaits(run meshwants.CompositionRun, readers []meshwants.CompositionReader, how string) {
|
||||||
|
if r.say == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, c := range readers {
|
||||||
|
w := waitOf(run, c)
|
||||||
|
event, id := meshwants.EventWaitHeld, "composition."+runKeyOf(run.Candidate, run.Machine)+"."+run.Ask+"."+c.ID+".held"
|
||||||
|
if how != "" {
|
||||||
|
w.How, event, id = how, meshwants.EventWaitEnded, strings.TrimSuffix(id, ".held")+".ended"
|
||||||
|
}
|
||||||
|
if err := r.say(event, w, id); err != nil {
|
||||||
|
r.logf("the %s of %s on the composition run of %s is not said: %v", event, c.Pipeline, run.Machine, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// untaken is whether the run of ask has not been taken yet: its untaken key stands holding that ask (A-470n).
|
||||||
|
func (r *compositionRuns) untaken(key, ask string) bool {
|
||||||
|
held, _, standing, err := r.boundOf(runUntakenPrefix + key)
|
||||||
|
return err == nil && standing && held == ask
|
||||||
|
}
|
||||||
|
|
||||||
|
// boundOf reads a bound key: the ask it holds and its revision; standing false when it is not written.
|
||||||
|
func (r *compositionRuns) boundOf(boundKey string) (string, uint64, bool, error) {
|
||||||
|
raw, rev, err := r.kv.get(boundKey)
|
||||||
|
if err != nil || raw == nil {
|
||||||
|
return "", 0, false, err
|
||||||
|
}
|
||||||
|
var v boundValue
|
||||||
|
_ = json.Unmarshal(raw, &v)
|
||||||
|
return v.Ask, rev, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// armBound writes the bound key prefix+key holding ask, judged from a read of the run, then reads the run again (A-470n): when
|
||||||
|
// it no longer names ask, or has ended, the bound just written is deleted at its revision, so no bound written from the earlier
|
||||||
|
// read ends the run after it, and a bound another run wrote since is kept. It answers whether the bound stands for the run.
|
||||||
|
func (r *compositionRuns) armBound(prefix, key, ask string, ttl time.Duration) (bool, error) {
|
||||||
|
rev, err := r.kv.arm(prefix+key, ask, ttl)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
run, _, ok, err := r.read(key)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if ok && run.Ended == nil && run.Ask == ask {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
if err := r.kv.delAt(prefix+key, rev); err != nil && !errors.Is(err, errRunChanged) {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// heardAskTaken begins a run's clock at its ask's ask-taken: the bound key armed holding the ask, the untaken key of that ask
|
||||||
|
// deleted, each reader's wait ended ran. An ask no running run names is another asker's, or a late signal of a run replaced or
|
||||||
|
// ended, which moves nothing and is journaled (A-470n).
|
||||||
|
func (r *compositionRuns) heardAskTaken(e nodebuildgo.AskTaken) error {
|
||||||
|
key, run, err := r.runOfAsk(e.Asker, e.Ask)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if key == "" {
|
||||||
|
r.late("ask-taken", e.Asker, e.Ask)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
armed, err := r.armBound(runBoundPrefix, key, e.Ask, r.set.stepBound)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("the bound of the composition run %s is not armed: %w", key, err)
|
||||||
|
}
|
||||||
|
if !armed {
|
||||||
|
r.late("ask-taken", e.Asker, e.Ask)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if r.untaken(key, e.Ask) {
|
||||||
|
if err := r.clearBounds(key, e.Ask, runUntakenPrefix); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.sayWaits(run, run.Readers, "ran")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// heardProgress begins a running run's clock again at each step-progress of its ask (§720: owed progress, not run length); a
|
||||||
|
// late one moves nothing and is journaled (A-470n).
|
||||||
|
func (r *compositionRuns) heardProgress(e nodebuildgo.StepProgress) error {
|
||||||
|
key, _, err := r.runOfAsk(e.Asker, e.Ask)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
armed := false
|
||||||
|
if key != "" {
|
||||||
|
if armed, err = r.armBound(runBoundPrefix, key, e.Ask, r.set.stepBound); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !armed {
|
||||||
|
r.late("step-progress", e.Asker, e.Ask)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// late journals a signal of an ask the assigner put whose run no key names running any more (A-470n).
|
||||||
|
func (r *compositionRuns) late(signal, asker, ask string) {
|
||||||
|
if asker == runAsker && ask != "" {
|
||||||
|
r.logf("the %s of the run ask %s is late: no composition run names it running, so it moves nothing (A-470n)", signal, ask)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// runOfAsk is the running run of an ask the assigner put, or none.
|
||||||
|
func (r *compositionRuns) runOfAsk(asker, ask string) (string, meshwants.CompositionRun, error) {
|
||||||
|
if asker != runAsker || ask == "" {
|
||||||
|
return "", meshwants.CompositionRun{}, nil
|
||||||
|
}
|
||||||
|
key, run, err := r.keyOfAsk(ask)
|
||||||
|
if err != nil || key == "" || run.Ended != nil {
|
||||||
|
return "", meshwants.CompositionRun{}, err
|
||||||
|
}
|
||||||
|
return key, run, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// expired ends the run whose bound key's time to live ended (§720): its ask dropped, the run ended could not run naming the
|
||||||
|
// ask and the bound. A run that ended already, or a key of none, takes nothing.
|
||||||
|
func (r *compositionRuns) expired(boundKey string) {
|
||||||
|
key, bound, setting := "", time.Duration(0), ""
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(boundKey, runBoundPrefix):
|
||||||
|
key, bound, setting = strings.TrimPrefix(boundKey, runBoundPrefix), r.set.stepBound, "composition-step-bound"
|
||||||
|
case strings.HasPrefix(boundKey, runUntakenPrefix):
|
||||||
|
key, bound, setting = strings.TrimPrefix(boundKey, runUntakenPrefix), r.set.untaken, "run-untaken-bound"
|
||||||
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
run, _, ok, err := r.read(key)
|
||||||
|
if err != nil || !ok || run.Ended != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// The marker of an expiry holds no value (A-470o): the run ends only while its bound is still absent when read again, and
|
||||||
|
// the run is taken for bound., untaken for untaken., so an expiry heard after a bound was armed again, or of a run replaced
|
||||||
|
// since, ends nothing.
|
||||||
|
other := runUntakenPrefix
|
||||||
|
if setting == "run-untaken-bound" {
|
||||||
|
other = runBoundPrefix
|
||||||
|
}
|
||||||
|
_, _, armed, err := r.boundOf(boundKey)
|
||||||
|
if err != nil {
|
||||||
|
r.logf("the bound %s is not read again, so its expiry ends nothing: %v", boundKey, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
held, _, standing, err := r.boundOf(other + key)
|
||||||
|
if err != nil {
|
||||||
|
r.logf("the bound %s is not read, so the expiry of %s ends nothing: %v", other+key, boundKey, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if armed || (standing && held == run.Ask) {
|
||||||
|
r.logf("the expiry of %s ends nothing: the bound is armed again, or the run of ask %s is not where it bounds (A-470o)", boundKey, run.Ask)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
said := fmt.Sprintf("%s: its run ask %s said no progress within %s (%s)", run.Machine, run.Ask, bound, setting)
|
||||||
|
if setting == "run-untaken-bound" {
|
||||||
|
said = fmt.Sprintf("%s: its run ask %s was taken by no build node within %s (%s)", run.Machine, run.Ask, bound, setting)
|
||||||
|
}
|
||||||
|
if r.drop != nil {
|
||||||
|
if err := r.drop(run.Ask, said); err != nil {
|
||||||
|
r.logf("the drop of the run ask %s of the composition run %s is not answered: %v", run.Ask, key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The untaken key is gone with its expiry, so the run ended by it is said untaken here: its readers' waits end superseded.
|
||||||
|
if _, err := r.endRunOf(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, said, nil, setting == "run-untaken-bound"); err != nil {
|
||||||
|
r.logf("the composition run %s past its bound is not ended: %v", key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// endRun ends a run (end) and clears its bounds: the untaken key's readers said superseded, both bound keys deleted.
|
||||||
|
func (r *compositionRuns) endRun(key, ask, outcome, said string, verdict map[string]any) (bool, error) {
|
||||||
|
return r.endRunOf(key, ask, outcome, said, verdict, r.untaken(key, ask))
|
||||||
|
}
|
||||||
|
|
||||||
|
// endRunOf is endRun of a run whose ask is untaken, or not, as its caller judged.
|
||||||
|
func (r *compositionRuns) endRunOf(key, ask, outcome, said string, verdict map[string]any, untaken bool) (bool, error) {
|
||||||
|
return r.endRunMoving(key, ask, outcome, said, verdict, untaken, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// endRunMoving is endRunOf, moving the readers a rerun carried or not: a drop says its readers' ends itself (A-470r).
|
||||||
|
func (r *compositionRuns) endRunMoving(key, ask, outcome, said string, verdict map[string]any, untaken, move bool) (bool, error) {
|
||||||
|
// The readers a rerun carried move with the run's end (§727, A-470d): chosen before the end is written, while the rerun's own
|
||||||
|
// step still waits on it, so it alone says its own end; each mover waits for the end in the key.
|
||||||
|
if moved := r.moved.Load(); moved != nil && move {
|
||||||
|
if run, _, ok, err := r.read(key); err == nil && ok && run.Ended == nil && run.Ask == ask {
|
||||||
|
(*moved)(run)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ended, err := r.end(key, ask, outcome, said, verdict)
|
||||||
|
if err != nil || !ended {
|
||||||
|
return ended, err
|
||||||
|
}
|
||||||
|
if untaken {
|
||||||
|
if run, _, ok, err := r.read(key); err == nil && ok {
|
||||||
|
r.sayWaits(run, run.Readers, "superseded")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := r.clearBounds(key, ask, runBoundPrefix, runUntakenPrefix); err != nil {
|
||||||
|
r.logf("the bound keys of the ended composition run %s are not deleted: %v", key, err)
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// readersOfOpen are the readers of every run with no `ended`, each with its ask's id once: what the assigner takes up again at
|
||||||
|
// its start (§719), each reader's end said from the keys alone (A-468). A reader whose step said its end already, carried into a
|
||||||
|
// rerun's run, is taken up only when it is marked `rerun` (A-470l, A-470m); each with the ask of the open run it is taken up from.
|
||||||
|
func (r *compositionRuns) readersOfOpen() ([]openReader, error) {
|
||||||
|
all, err := r.keys()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
seen := map[string]bool{}
|
||||||
|
var out []openReader
|
||||||
|
for _, key := range all {
|
||||||
|
if !isRunKey(key) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
run, _, ok, err := r.read(key)
|
||||||
|
if err != nil || !ok || run.Ended != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, c := range run.Readers {
|
||||||
|
if c.Ended != nil && !c.Rerun {
|
||||||
|
continue // it ended passed already: only a reader marked rerun says its end again
|
||||||
|
}
|
||||||
|
if !seen[c.ID] {
|
||||||
|
seen[c.ID] = true
|
||||||
|
out = append(out, openReader{CompositionReader: c, ask: run.Ask})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// openReader is a reader taken up at the start and the ask of the open run it is taken up from.
|
||||||
|
type openReader struct {
|
||||||
|
meshwants.CompositionReader
|
||||||
|
ask string
|
||||||
|
}
|
||||||
|
|
||||||
|
// keysOf are the keys of the candidate's runs that the reader reads.
|
||||||
|
func (r *compositionRuns) keysOf(candidate, id string) ([]string, error) {
|
||||||
|
all, err := r.keys()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var out []string
|
||||||
|
prefix := keysPart(candidate) + "."
|
||||||
|
for _, key := range all {
|
||||||
|
if !isRunKey(key) || !strings.HasPrefix(key, prefix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if run, _, ok, err := r.read(key); err == nil && ok && hasReader(run.Readers, id) {
|
||||||
|
out = append(out, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slices.Sort(out) // by machine, as a step names its machines
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearRunBounds hears the build seats' ask-taken and step-progress on the assigner's durable consumer (§720, A-466q): each
|
||||||
|
// handed to the runs; one that cannot be written is given again by the bus.
|
||||||
|
func hearRunBounds(hub interface {
|
||||||
|
Handle(string, func(jetstream.Msg)) error
|
||||||
|
}, r *compositionRuns, logf func(string, ...any)) error {
|
||||||
|
if err := hub.Handle(nodebuildgo.SubjectAskTakenAll, func(m jetstream.Msg) {
|
||||||
|
var e nodebuildgo.AskTaken
|
||||||
|
if err := json.Unmarshal(m.Data(), &e); err != nil {
|
||||||
|
logf("%s holds what is no ask-taken, left: %v", m.Subject(), err)
|
||||||
|
_ = m.Ack()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ackOrNak(m, r.heardAskTaken(e), logf)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return hub.Handle(nodebuildgo.SubjectStepProgressAll, func(m jetstream.Msg) {
|
||||||
|
var e nodebuildgo.StepProgress
|
||||||
|
if err := json.Unmarshal(m.Data(), &e); err != nil {
|
||||||
|
logf("%s holds what is no step-progress, left: %v", m.Subject(), err)
|
||||||
|
_ = m.Ack()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ackOrNak(m, r.heardProgress(e), logf)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func ackOrNak(m jetstream.Msg, err error, logf func(string, ...any)) {
|
||||||
|
if err != nil {
|
||||||
|
logf("%s is not taken, so the bus gives it again: %v", m.Subject(), err)
|
||||||
|
_ = m.Nak()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_ = m.Ack()
|
||||||
|
}
|
||||||
|
|
||||||
|
// takeUp says, at the assigner's start, the end of each reader of a run with no `ended` once its runs end (§719, A-468): the
|
||||||
|
// step's goroutine is gone, so its end is judged from the candidate's keys naming it.
|
||||||
|
func (c *compositionSteps) takeUp(ctx context.Context, r *compositionRuns) {
|
||||||
|
readers, err := r.readersOfOpen()
|
||||||
|
if err != nil {
|
||||||
|
c.logf("composition-runs: the runs standing at the start are not read, so their readers are not taken up: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, reader := range readers {
|
||||||
|
c.logf("the composition step %s of %s is taken up again by its runs (ask %s)", reader.Pipeline, reader.Module, reader.ID)
|
||||||
|
again := "" // a reader whose step said its end already says it again under the open run's ask (A-470q)
|
||||||
|
if reader.Ended != nil {
|
||||||
|
again = reader.ask
|
||||||
|
}
|
||||||
|
go c.say1(ctx, reader.ID, stepRunOf(reader.CompositionReader), c.resume, again)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
|
ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The inputs of a composition run (design 47 G §354, §718, A-243, A-252): one request per candidate and machine, carrying that
|
||||||
|
// machine's input, asked of the machine's node-engine by the seat's verb compose-candidate when the run starts.
|
||||||
|
|
||||||
|
// composeCandidateKey is the seat verb's call key, asked of one node.
|
||||||
|
const composeCandidateKey = "seat:" + ne.Seat + "." + ne.VerbComposeCandidate
|
||||||
|
|
||||||
|
// candidateKeyOf is the key the step's pipeline names its candidate by (A-226): a run on request's `run-<id>`, or for a branch
|
||||||
|
// pipeline the branch's catalog graph revision `<branch>.<revision>`, the branch escaped as a key part as the pipeline key does.
|
||||||
|
func candidateKeyOf(run meshwants.StepRun) (string, error) {
|
||||||
|
switch {
|
||||||
|
case run.Run != "":
|
||||||
|
return nec.RunKey(run.Run)
|
||||||
|
case run.Branch == "" || run.Revision <= 0:
|
||||||
|
return "", errors.New("the step names neither a run on request nor a branch's revision, so no candidate is named")
|
||||||
|
}
|
||||||
|
return nec.RevisionKey(run.Branch, run.Revision) // built by the seat's client, never by hand (A-226b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// machinesFor are the machines of a step (A-252): the nodes whose placement of the module names the step's branch (a placement
|
||||||
|
// naming none is the trunk's, trunk the first watched branch); a branch that is not watched takes the nodes placing the module on the trunk. In name order.
|
||||||
|
func machinesFor(placed map[string]map[string]string, module, branch, trunk string, watched bool) []string {
|
||||||
|
if branch == "" || !watched {
|
||||||
|
branch = trunk
|
||||||
|
}
|
||||||
|
var out []string
|
||||||
|
for node, b := range placed[module] {
|
||||||
|
if b == "" {
|
||||||
|
b = trunk
|
||||||
|
}
|
||||||
|
if b == branch {
|
||||||
|
out = append(out, node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slices.Sort(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// machinesOf are the machines of a composition step in the world's assignments.
|
||||||
|
func (w *world) machinesOf(module, branch string) []string {
|
||||||
|
return machinesFor(w.placedBranches(), module, branch, w.trunkName(), w.holdsBranch(branch))
|
||||||
|
}
|
||||||
|
|
||||||
|
// nodeInput is one machine's input: its bytes, or why the node gave none, or that it is away.
|
||||||
|
type nodeInput struct {
|
||||||
|
Node string
|
||||||
|
Body []byte
|
||||||
|
// Why is set when the node gave no input: its words, or the call's error.
|
||||||
|
Why string
|
||||||
|
// Away is a machine the watchman said away: it is not asked (§64).
|
||||||
|
Away bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// compositionInputs asks the machines of a step for their inputs.
|
||||||
|
type compositionInputs struct {
|
||||||
|
machines func(module, branch string) []string
|
||||||
|
// callFile asks a seat verb marked chunks, addressed to one node as `seat:<seat>.<verb>@<node>`, and answers the verb's answer with
|
||||||
|
// the whole file received added as its member `file`, base64 (process.Conn.CallFile; design 47 G A-237b, A-237c, A-249). The call
|
||||||
|
// token is the body's `call`.
|
||||||
|
callFile func(key string, body any) (json.RawMessage, error)
|
||||||
|
bound time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// of asks the machine node for its input with the candidate's key (§718): asked only by the composition step that starts the
|
||||||
|
// machine's composition run, once per candidate and machine. A node that is silent, unready or answers no input has Why set.
|
||||||
|
func (c *compositionInputs) of(ctx context.Context, node, candidate string) nodeInput {
|
||||||
|
bound := c.bound
|
||||||
|
if bound <= 0 {
|
||||||
|
bound = nec.AnswerBound
|
||||||
|
}
|
||||||
|
return c.one(ctx, bound, node, candidate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// one asks one node for its input.
|
||||||
|
func (c *compositionInputs) one(ctx context.Context, bound time.Duration, node, key string) nodeInput {
|
||||||
|
in := nodeInput{Node: node}
|
||||||
|
at, cancel := context.WithTimeout(ctx, bound)
|
||||||
|
defer cancel()
|
||||||
|
type reply struct {
|
||||||
|
raw json.RawMessage
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
got := make(chan reply, 1)
|
||||||
|
go func() {
|
||||||
|
// The input is any size, so the verb sends it in chunks on the call token chosen here, and the file is the input (A-237b, A-237c).
|
||||||
|
var bits [16]byte
|
||||||
|
if _, err := rand.Read(bits[:]); err != nil {
|
||||||
|
got <- reply{nil, err}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
raw, err := c.callFile(composeCandidateKey+"@"+node, ne.ComposeCandidateInput{Candidate: key, Input: true, Call: hex.EncodeToString(bits[:])})
|
||||||
|
got <- reply{raw, err}
|
||||||
|
}()
|
||||||
|
var raw json.RawMessage
|
||||||
|
select {
|
||||||
|
case <-at.Done():
|
||||||
|
in.Why = "no answer within its bound: " + at.Err().Error()
|
||||||
|
return in
|
||||||
|
case r := <-got:
|
||||||
|
if r.err != nil {
|
||||||
|
in.Why = r.err.Error()
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
raw = r.raw
|
||||||
|
}
|
||||||
|
var a ne.ComposeCandidateAnswer
|
||||||
|
// its numbers as written (json.Number), so the input kept is the engine's own bytes' values
|
||||||
|
dec := json.NewDecoder(bytes.NewReader(raw))
|
||||||
|
dec.UseNumber()
|
||||||
|
if err := dec.Decode(&a); err != nil {
|
||||||
|
in.Why = "its answer is not a compose-candidate answer: " + err.Error()
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case a.Verdict == nec.Unready:
|
||||||
|
in.Why = "unready: " + a.Refused
|
||||||
|
return in
|
||||||
|
case a.Chunks == 0 && len(a.Input) == 0:
|
||||||
|
in.Why = "the engine answered no composition input"
|
||||||
|
if a.Refused != "" {
|
||||||
|
in.Why += ": " + a.Refused
|
||||||
|
}
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
var body []byte
|
||||||
|
if a.Chunks > 0 {
|
||||||
|
// The composition input is the file the chunks carried, the engine's own bytes (numbers as written).
|
||||||
|
var whole struct {
|
||||||
|
File string `json:"file"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(raw, &whole); err != nil {
|
||||||
|
in.Why = "its answer is not a compose-candidate answer: " + err.Error()
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
file, err := base64.StdEncoding.DecodeString(whole.File)
|
||||||
|
if err != nil || len(file) == 0 {
|
||||||
|
in.Why = fmt.Sprintf("the engine named %d chunks of composition input and the file received is empty or not base64: %v", a.Chunks, err)
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
body = file
|
||||||
|
} else {
|
||||||
|
// An answer with the input inline (an engine before A-237b, read until the checker is removed, A-237c, G-6 §321): the object, as it was.
|
||||||
|
var err error
|
||||||
|
if body, err = json.Marshal(a.Input); err != nil {
|
||||||
|
in.Why = "its composition input cannot be encoded again: " + err.Error()
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
}
|
||||||
|
in.Body = body
|
||||||
|
return in
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G A-226: the candidate a step asks is `run-<id>` for a run on request, else `<branch>.<revision>`.
|
||||||
|
func TestTheCandidateKeyOfAStep(t *testing.T) {
|
||||||
|
for _, c := range []struct {
|
||||||
|
run meshwants.StepRun
|
||||||
|
want string
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{run: meshwants.StepRun{Run: "r1", Branch: "main"}, want: "run-r1"},
|
||||||
|
{run: meshwants.StepRun{Branch: "feat/x", Revision: 42}, want: "feat/x.42"},
|
||||||
|
{run: meshwants.StepRun{Branch: "main", Revision: 362}, want: "main.362"},
|
||||||
|
{run: meshwants.StepRun{Branch: "main"}, fail: true},
|
||||||
|
{run: meshwants.StepRun{Branch: "main", Revision: 100000000000}, fail: true}, // a number the client's key would read as a heads hash
|
||||||
|
{run: meshwants.StepRun{Run: "a.b"}, fail: true}, // a run id the client refuses
|
||||||
|
} {
|
||||||
|
got, err := candidateKeyOf(c.run)
|
||||||
|
if (err != nil) != c.fail || got != c.want {
|
||||||
|
t.Errorf("%+v: %q, %v; want %q", c.run, got, err, c.want)
|
||||||
|
}
|
||||||
|
// A-226b: the node-engine reads every key the step names with the client's one parser.
|
||||||
|
if !c.fail {
|
||||||
|
if _, err := nec.ParseCandidateKey(got); err != nil {
|
||||||
|
t.Errorf("%+v: the key %q is refused by the seat's parser: %v", c.run, got, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-252: the machines of a step are the nodes whose placement names its branch; none named is the trunk; an unwatched branch takes
|
||||||
|
// the trunk's nodes.
|
||||||
|
func TestTheMachinesOfAStep(t *testing.T) {
|
||||||
|
placed := map[string]map[string]string{"m": {"ace": "", "g14": "feat", "novox": "main", "shanks": "feat"}, "other": {"ace": ""}}
|
||||||
|
for _, c := range []struct {
|
||||||
|
branch string
|
||||||
|
watched bool
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"main", true, "ace novox"},
|
||||||
|
{"feat", true, "g14 shanks"},
|
||||||
|
{"gone", false, "ace novox"},
|
||||||
|
{"", true, "ace novox"},
|
||||||
|
} {
|
||||||
|
if got := strings.Join(machinesFor(placed, "m", c.branch, trunkBranch, c.watched), " "); got != c.want {
|
||||||
|
t.Errorf("branch %q watched %v: %q, want %q", c.branch, c.watched, got, c.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if got := machinesFor(placed, "none", "main", trunkBranch, true); len(got) != 0 {
|
||||||
|
t.Errorf("a module placed nowhere has machines %v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// §354, A-243, A-252, §64: each machine is asked compose-candidate with the step's key and input true, its numbers as written; a
|
||||||
|
// silent or unready node says why, and a machine away is not asked.
|
||||||
|
func TestAStepsInputsAreAskedOfEachMachine(t *testing.T) {
|
||||||
|
// the machines are asked side by side, so the record of what each was asked is guarded.
|
||||||
|
var mu sync.Mutex
|
||||||
|
asked := map[string]string{}
|
||||||
|
call := func(key string, body any) (json.RawMessage, error) {
|
||||||
|
raw, _ := json.Marshal(body)
|
||||||
|
key, node, _ := strings.Cut(key, "@") // addressed to one node (A-237b)
|
||||||
|
mu.Lock()
|
||||||
|
asked[node] = key + " " + string(raw)
|
||||||
|
mu.Unlock()
|
||||||
|
switch node {
|
||||||
|
case "g14":
|
||||||
|
return nil, errors.New("no responders")
|
||||||
|
case "novox":
|
||||||
|
return json.RawMessage(`{"candidate":"run-r1","node":"novox","verdict":"unready","refused":"starting","modules":[],"own":{},"took":1,"v":1}`), nil
|
||||||
|
}
|
||||||
|
return json.RawMessage(`{"candidate":"run-r1","node":"` + node + `","verdict":"composed","input":{"n":12345678901234567890,"node":"` + node + `"},"modules":[],"own":{},"took":1,"v":1}`), nil
|
||||||
|
}
|
||||||
|
c := &compositionInputs{machines: func(module, branch string) []string { return []string{"ace", "g14", "novox", "shanks"} }, callFile: call, bound: time.Second}
|
||||||
|
got, err := gatherAll(c, meshwants.StepRun{Module: "m", Branch: "main", Run: "r1"}, func(node string) bool { return node == "shanks" })
|
||||||
|
if err != nil || len(got) != 4 {
|
||||||
|
t.Fatalf("%+v %v", got, err)
|
||||||
|
}
|
||||||
|
// With a call token of 128 random bits (32 hex digits), the verb being marked chunks.
|
||||||
|
if k, body, _ := strings.Cut(asked["ace"], " "); k != "seat:node-engine.compose-candidate" ||
|
||||||
|
!regexp.MustCompile(`^\{"call":"[0-9a-f]{32}","candidate":"run-r1","input":true\}$`).MatchString(body) {
|
||||||
|
t.Errorf("asked %q", asked["ace"])
|
||||||
|
}
|
||||||
|
if got[0].Node != "ace" || got[0].Why != "" || !strings.Contains(string(got[0].Body), "12345678901234567890") {
|
||||||
|
t.Errorf("ace: %+v", got[0])
|
||||||
|
}
|
||||||
|
if !strings.Contains(got[1].Why, "no responders") || !strings.Contains(got[2].Why, "unready") || got[1].Body != nil || got[2].Body != nil {
|
||||||
|
t.Errorf("g14 and novox: %+v %+v", got[1], got[2])
|
||||||
|
}
|
||||||
|
if _, was := asked["shanks"]; was || !got[3].Away {
|
||||||
|
t.Errorf("the machine away is asked or not said away: %+v", got[3])
|
||||||
|
}
|
||||||
|
none := &compositionInputs{machines: func(string, string) []string { return nil }, callFile: call}
|
||||||
|
if _, err := gatherAll(none, meshwants.StepRun{Module: "m", Run: "r1"}, nil); err == nil {
|
||||||
|
t.Error("a step with no machine is gathered")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-237b: the composition input is any size, so a node names the chunks it sent and the assigner reads the file the chunked call
|
||||||
|
// received as the input, its numbers as written; a node that names chunks and sends no file is said so.
|
||||||
|
func TestAStepsInputIsTheFileOfTheNodesChunks(t *testing.T) {
|
||||||
|
input := `{"n":12345678901234567890,"big":"` + strings.Repeat("x", 1<<20) + `"}`
|
||||||
|
file := base64.StdEncoding.EncodeToString([]byte(input))
|
||||||
|
call := func(key string, body any) (json.RawMessage, error) {
|
||||||
|
_, node, _ := strings.Cut(key, "@")
|
||||||
|
answer := `{"candidate":"run-r1","node":"` + node + `","verdict":"composed","modules":[],"own":{},"took":1,"v":1,"chunks":3`
|
||||||
|
if node == "g14" {
|
||||||
|
return json.RawMessage(answer + `}`), nil // names chunks, none received
|
||||||
|
}
|
||||||
|
return json.RawMessage(answer + `,"file":"` + file + `"}`), nil
|
||||||
|
}
|
||||||
|
c := &compositionInputs{machines: func(module, branch string) []string { return []string{"ace", "g14"} }, callFile: call, bound: time.Second}
|
||||||
|
got, err := gatherAll(c, meshwants.StepRun{Module: "m", Branch: "main", Run: "r1"}, func(string) bool { return false })
|
||||||
|
if err != nil || len(got) != 2 {
|
||||||
|
t.Fatalf("%+v %v", got, err)
|
||||||
|
}
|
||||||
|
if got[0].Why != "" || string(got[0].Body) != input {
|
||||||
|
t.Errorf("ace: why %q, %d bytes, want the file received (%d bytes) as the input", got[0].Why, len(got[0].Body), len(input))
|
||||||
|
}
|
||||||
|
if !strings.Contains(got[1].Why, "chunks") || got[1].Body != nil {
|
||||||
|
t.Errorf("g14: %+v", got[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// gatherAll asks each machine of a step for its input as each run's start does (compositionInputs.of), side by side; a machine away
|
||||||
|
// is not asked; no machine is an error.
|
||||||
|
func gatherAll(c *compositionInputs, run meshwants.StepRun, away func(string) bool) ([]nodeInput, error) {
|
||||||
|
key, err := candidateKeyOf(run)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
nodes := c.machines(run.Module, run.Branch)
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, errors.New("no machine")
|
||||||
|
}
|
||||||
|
out := make([]nodeInput, len(nodes))
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for i, node := range nodes {
|
||||||
|
if away != nil && away(node) {
|
||||||
|
out[i] = nodeInput{Node: node, Away: true}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
wg.Add(1)
|
||||||
|
go func() { defer wg.Done(); out[i] = c.of(context.Background(), node, key) }()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The reads of a composition step (design 47 G §354, A-252, A-261): the entries of one catalog revision are read once and shared by
|
||||||
|
// every composition step of that revision, since an entry is content-addressed and a revision never changes; a read that times out
|
||||||
|
// or fails in transport is made again with a growing wait for a bounded time, said in the journal, and only then ends the step as
|
||||||
|
// could not run.
|
||||||
|
|
||||||
|
const (
|
||||||
|
// readsBound is how long a read is made again before the step could not run.
|
||||||
|
readsBound = 3 * time.Minute
|
||||||
|
// readsFirstWait and readsMaxWait bound the wait between two tries.
|
||||||
|
readsFirstWait = time.Second
|
||||||
|
readsMaxWait = 15 * time.Second
|
||||||
|
// readsKept is how many catalog revisions' halves are kept; the oldest read goes first.
|
||||||
|
readsKept = 8
|
||||||
|
)
|
||||||
|
|
||||||
|
// readKey names one revision of one watched branch.
|
||||||
|
type readKey struct {
|
||||||
|
branch string
|
||||||
|
revision int
|
||||||
|
}
|
||||||
|
|
||||||
|
// readSlot is one revision's read: done closes when half or err is set.
|
||||||
|
type readSlot struct {
|
||||||
|
done chan struct{}
|
||||||
|
half mcc.Half
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// compositionReads shares the reads of composition steps.
|
||||||
|
type compositionReads struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
revs map[readKey]*readSlot
|
||||||
|
order []readKey
|
||||||
|
seats map[string]json.RawMessage // by seat and digest: the definition, raw
|
||||||
|
}
|
||||||
|
|
||||||
|
// transient says whether a read's fault is of the transport or a timeout, so that it is worth reading again.
|
||||||
|
func transient(err error, said string) bool {
|
||||||
|
text := said
|
||||||
|
if err != nil {
|
||||||
|
text = err.Error() + " " + said
|
||||||
|
}
|
||||||
|
text = strings.ToLower(text)
|
||||||
|
for _, w := range []string{"deadline exceeded", "timeout", "timed out", "no responders", "connection", "i/o", "eof", "broken pipe", "unavailable"} {
|
||||||
|
if strings.Contains(text, w) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// callRetry calls the seat verb key, again with a growing wait while its fault is transient, for readsBound; it answers the body of
|
||||||
|
// a good answer, or the last fault.
|
||||||
|
func (r *compositionRun) callRetry(ctx context.Context, key string, body any) (json.RawMessage, string, error) {
|
||||||
|
start := r.now()
|
||||||
|
wait := readsFirstWait
|
||||||
|
for try := 1; ; try++ {
|
||||||
|
raw, err := r.call(key, body)
|
||||||
|
var inner json.RawMessage
|
||||||
|
var said string
|
||||||
|
if err == nil {
|
||||||
|
var ok bool
|
||||||
|
if inner, said, ok = buscalls.Unwrap(raw); ok {
|
||||||
|
return inner, "", nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !transient(err, said) {
|
||||||
|
return nil, said, err
|
||||||
|
}
|
||||||
|
if r.now().Sub(start)+wait > readsBound {
|
||||||
|
return nil, said, err
|
||||||
|
}
|
||||||
|
r.logf("composition step: %s is not read (try %d, %v %s), read again in %s", key, try, err, said, wait)
|
||||||
|
if serr := r.waitFor(ctx, wait); serr != nil {
|
||||||
|
return nil, said, serr
|
||||||
|
}
|
||||||
|
if wait *= 2; wait > readsMaxWait {
|
||||||
|
wait = readsMaxWait
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitFor waits d, or until ctx ends.
|
||||||
|
func (r *compositionRun) waitFor(ctx context.Context, d time.Duration) error {
|
||||||
|
if r.sleep != nil {
|
||||||
|
return r.sleep(ctx, d)
|
||||||
|
}
|
||||||
|
t := time.NewTimer(d)
|
||||||
|
defer t.Stop()
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
case <-t.C:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// half is the revision's half, read once for every step of it: a step that finds it being read waits for that read, and a read that
|
||||||
|
// failed is not kept, so the next step reads again.
|
||||||
|
func (r *compositionRun) half(ctx context.Context, key readKey, read func() (mcc.Half, error)) (mcc.Half, error) {
|
||||||
|
c := r.reads
|
||||||
|
c.mu.Lock()
|
||||||
|
if c.revs == nil {
|
||||||
|
c.revs = map[readKey]*readSlot{}
|
||||||
|
}
|
||||||
|
if s, ok := c.revs[key]; ok {
|
||||||
|
c.mu.Unlock()
|
||||||
|
select {
|
||||||
|
case <-s.done:
|
||||||
|
if s.err == nil {
|
||||||
|
return s.half, nil
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
return mcc.Half{}, ctx.Err()
|
||||||
|
}
|
||||||
|
// The read this step waited for failed: read it here (the failed slot is already dropped).
|
||||||
|
return r.half(ctx, key, read)
|
||||||
|
}
|
||||||
|
s := &readSlot{done: make(chan struct{})}
|
||||||
|
c.revs[key] = s
|
||||||
|
c.order = append(c.order, key)
|
||||||
|
for len(c.order) > readsKept {
|
||||||
|
delete(c.revs, c.order[0])
|
||||||
|
c.order = c.order[1:]
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
s.half, s.err = read()
|
||||||
|
if s.err != nil {
|
||||||
|
c.mu.Lock()
|
||||||
|
if c.revs[key] == s {
|
||||||
|
delete(c.revs, key)
|
||||||
|
}
|
||||||
|
for i, k := range c.order {
|
||||||
|
if k == key {
|
||||||
|
c.order = append(c.order[:i], c.order[i+1:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
}
|
||||||
|
close(s.done)
|
||||||
|
return s.half, s.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// seatKept is the definition kept of a seat at a digest.
|
||||||
|
func (c *compositionReads) seatKept(seat, digest string) (json.RawMessage, bool) {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
d, ok := c.seats[seat+"@"+digest]
|
||||||
|
return d, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *compositionReads) keepSeat(seat, digest string, def json.RawMessage) {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
if c.seats == nil {
|
||||||
|
c.seats = map[string]json.RawMessage{}
|
||||||
|
}
|
||||||
|
c.seats[seat+"@"+digest] = def
|
||||||
|
}
|
||||||
|
|
||||||
|
func unreadErr(what string, err error, said string) error {
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s: %w", what, err)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%s: %s", what, said)
|
||||||
|
}
|
||||||
@@ -0,0 +1,635 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The run of a composition step (design 47 G §354, §63, §64, §718; A-226, A-238, A-240, A-252, A-254, A-261): the step reads one
|
||||||
|
// composition run per machine of its candidate (compositionruns.go), and the step that starts a machine's run composes it: one
|
||||||
|
// compose-candidate ask of the node, one composer.Request, depth compose, the one machine and one case `change`, its manifests,
|
||||||
|
// verdicts and seats from the step's catalog revision read through mesh-catalog's `revision`, kept once in `inputs`; one run ask
|
||||||
|
// of the seat node-build-go, naming no head, its program the node-engine build's catalog entry with the composer's package,
|
||||||
|
// chosen once and recorded in the run. The run's end is heard on the build seat's step-ended of that ask, its answer (a
|
||||||
|
// composer.Verdict) read from `output`, and written in the run's key, whose change every reading step hears. A machine the
|
||||||
|
// watchman said away (machine-away) is not composed and passes with a warning (§64).
|
||||||
|
|
||||||
|
const (
|
||||||
|
// runAsker is the assigner's name as an asker of a build seat, its seat's own name: the last token of the subject its run
|
||||||
|
// asks are put on and the first of their step keys (§467, §481, §600, A-163).
|
||||||
|
runAsker = meshwants.Seat
|
||||||
|
// changeCase is the one case each request composes.
|
||||||
|
changeCase = "change"
|
||||||
|
// inputVerbKey is the verb a run ask's input is served on: the seat mesh-wants' input (§354).
|
||||||
|
inputVerbKey = "seat:" + meshwants.Seat + "." + meshwants.VerbInput
|
||||||
|
// entryVerbKey and seatDefinitionsKey are the mesh-catalog seat verbs the step reads.
|
||||||
|
entryVerbKey = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbEntry
|
||||||
|
seatDefinitionsKey = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbSeatDefinitions
|
||||||
|
)
|
||||||
|
|
||||||
|
// compositionRun runs a composition step.
|
||||||
|
type compositionRun struct {
|
||||||
|
// runs are the composition runs of the state composition-runs (compositionruns.go).
|
||||||
|
runs *compositionRuns
|
||||||
|
inputs *compositionInputs
|
||||||
|
keeper *inputKeeper
|
||||||
|
// call asks a seat verb held once for the mesh (process.Conn.CallKept).
|
||||||
|
call func(key string, body any) (json.RawMessage, error)
|
||||||
|
// trunk is the trunk's catalog half as the assigner holds it.
|
||||||
|
trunk func() (mcc.Half, bool)
|
||||||
|
// running is the last `running` heard of a module on a node (world.runningOf), never the node-engine's bucket.
|
||||||
|
running func(node, module string) (ne.Running, bool)
|
||||||
|
// away says the watchman holds machine away (machine-away, not back since): the one presence the assigner keeps (world.awayNow),
|
||||||
|
// so a durable on the watchman's streams has one hearer.
|
||||||
|
away func(machine string) bool
|
||||||
|
// put puts a run ask on the build seat's check queue under the assigner's name.
|
||||||
|
put func(ctx context.Context, a buildstep.StepAsk) error
|
||||||
|
// reads shares the catalog reads among steps (compositionreads.go); sleep waits between two tries of a read (nil: a timer).
|
||||||
|
reads *compositionReads
|
||||||
|
sleep func(ctx context.Context, d time.Duration) error
|
||||||
|
// ask asks a seat verb on one node, for the run's answer kept as the build seat's object (buildstep.StepEnded.ReadOutput).
|
||||||
|
ask buildstep.AskVerb
|
||||||
|
now func() time.Time
|
||||||
|
logf func(string, ...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
// machineEnd is what one machine came to.
|
||||||
|
type machineEnd struct {
|
||||||
|
failed, couldNot string
|
||||||
|
warnings []string
|
||||||
|
// judged is set where the composer judged the machine, composing or not (A-467a).
|
||||||
|
judged bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// run runs one composition step and answers what it came to: per machine not away it joins or starts the candidate's
|
||||||
|
// composition run (§718), waits for each run's end in its key, and judges each machine from it; failed when a machine does not
|
||||||
|
// compose, could not run when a machine could not be composed or was not judged, else passed with a warning per machine away.
|
||||||
|
func (r *compositionRun) run(ctx context.Context, id string, step meshwants.StepRun) stepOutcome {
|
||||||
|
candidate, err := candidateKeyOf(step)
|
||||||
|
if err != nil {
|
||||||
|
return couldNotRun(err.Error())
|
||||||
|
}
|
||||||
|
nodes := r.inputs.machines(step.Module, step.Branch)
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return couldNotRun(fmt.Sprintf("no node places %s on the branch %q, so the composition step has no machine to compose", step.Module, step.Branch))
|
||||||
|
}
|
||||||
|
reader := readerOf(id, step)
|
||||||
|
prep := &runPrep{r: r, step: step}
|
||||||
|
var ends []machineEnd
|
||||||
|
var keys []string
|
||||||
|
for _, node := range nodes {
|
||||||
|
if r.away != nil && r.away(node) {
|
||||||
|
ends = append(ends, machineEnd{warnings: []string{node + " is away (the watchman's machine-away), so it is not composed"}})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
join := r.runs.join
|
||||||
|
if step.Rerun { // a step asked again (§727)
|
||||||
|
join = r.runs.rejoin
|
||||||
|
}
|
||||||
|
j, err := join(reader, candidate, node, buildstep.NewID())
|
||||||
|
if err != nil {
|
||||||
|
ends = append(ends, machineEnd{couldNot: node + ": " + err.Error()})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if j.started {
|
||||||
|
go r.start(ctx, j.key, j.run, prep)
|
||||||
|
}
|
||||||
|
keys = append(keys, j.key)
|
||||||
|
}
|
||||||
|
return r.read(ctx, step.Module, keys, ends)
|
||||||
|
}
|
||||||
|
|
||||||
|
// read waits for the end of each run of keys and judges the step of module from them, naming in its progress and its end the
|
||||||
|
// runs it reads and their asks (§723, §729).
|
||||||
|
func (r *compositionRun) read(ctx context.Context, module string, keys []string, ends []machineEnd) stepOutcome {
|
||||||
|
setShared(ctx, r.runs.sharedOf(keys, nil))
|
||||||
|
setPhase(ctx, meshwants.StepProgressEventPhaseRun)
|
||||||
|
runs := r.runs.await(ctx, keys)
|
||||||
|
setPhase(ctx, meshwants.StepProgressEventPhaseReport)
|
||||||
|
for _, key := range keys {
|
||||||
|
ends = append(ends, judgeRun(module, runs[key]))
|
||||||
|
}
|
||||||
|
out := outcomeOf(ends)
|
||||||
|
out.Shared = r.runs.sharedOf(keys, runs)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// resume judges a step taken up at the assigner's start (§719, A-468): the runs of its candidate naming it, once each has ended.
|
||||||
|
func (r *compositionRun) resume(ctx context.Context, id string, step meshwants.StepRun) stepOutcome {
|
||||||
|
candidate, err := candidateKeyOf(step)
|
||||||
|
if err != nil {
|
||||||
|
return couldNotRun(err.Error())
|
||||||
|
}
|
||||||
|
keys, err := r.runs.keysOf(candidate, id)
|
||||||
|
if err != nil {
|
||||||
|
return couldNotRun("the step's composition runs are not read: " + err.Error())
|
||||||
|
}
|
||||||
|
return r.read(ctx, step.Module, keys, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// outcomeOf is a step's outcome from its machines: failed before could not run before passed (§354); a step that judged no
|
||||||
|
// machine never passes (A-467a), each machine not judged named with why.
|
||||||
|
func outcomeOf(ends []machineEnd) stepOutcome {
|
||||||
|
var out stepOutcome
|
||||||
|
var failed, couldNot []string
|
||||||
|
judged := 0
|
||||||
|
for _, e := range ends {
|
||||||
|
if e.judged {
|
||||||
|
judged++
|
||||||
|
}
|
||||||
|
failed = appendSome(failed, e.failed)
|
||||||
|
couldNot = appendSome(couldNot, e.couldNot)
|
||||||
|
out.Warnings = append(out.Warnings, e.warnings...)
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case len(failed) > 0:
|
||||||
|
out.Outcome, out.Said = meshwants.StepEndedOutcomeFailed, strings.Join(failed, "; ")
|
||||||
|
case len(couldNot) > 0:
|
||||||
|
out.Outcome, out.Said = meshwants.StepEndedOutcomeCouldNotRun, strings.Join(couldNot, "; ")
|
||||||
|
case judged == 0:
|
||||||
|
said := "no machine was judged"
|
||||||
|
if len(out.Warnings) == 0 {
|
||||||
|
said += ": the step has no machine"
|
||||||
|
} else {
|
||||||
|
said += ": " + strings.Join(out.Warnings, "; ")
|
||||||
|
}
|
||||||
|
out.Outcome, out.Said = meshwants.StepEndedOutcomeCouldNotRun, said
|
||||||
|
default:
|
||||||
|
out.Outcome = meshwants.StepEndedOutcomePassed
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendSome(to []string, s string) []string {
|
||||||
|
if s == "" {
|
||||||
|
return to
|
||||||
|
}
|
||||||
|
return append(to, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func couldNotRun(said string) stepOutcome {
|
||||||
|
return stepOutcome{Outcome: meshwants.StepEndedOutcomeCouldNotRun, Said: said}
|
||||||
|
}
|
||||||
|
|
||||||
|
// runPrep is what the step that starts a run reads of its catalog revision, once for every machine it starts: the seats, the
|
||||||
|
// case's manifests and verdicts, and the composer program per machine.
|
||||||
|
type runPrep struct {
|
||||||
|
r *compositionRun
|
||||||
|
step meshwants.StepRun
|
||||||
|
once sync.Once
|
||||||
|
// read once
|
||||||
|
seats []json.RawMessage
|
||||||
|
manifests map[string]composer.Manifest
|
||||||
|
verdicts map[string]json.RawMessage
|
||||||
|
none map[string]string
|
||||||
|
programOf func(node string) (buildstep.RunProgram, string, error)
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *runPrep) get(ctx context.Context) error {
|
||||||
|
p.once.Do(func() {
|
||||||
|
half, err := p.r.revision(ctx, p.step)
|
||||||
|
if err != nil {
|
||||||
|
p.err = errors.New("the step's catalog revision is not read: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if p.seats, p.err = p.r.seats(ctx, half.Revision.Definitions); p.err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if p.manifests, p.verdicts, p.none, p.err = caseOf(half); p.err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.programOf, p.err = p.r.programs(ctx, half)
|
||||||
|
})
|
||||||
|
return p.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// start composes the machine of the run it started (§718): the node's input of this moment, its request kept once in `inputs`,
|
||||||
|
// the composer program chosen and recorded with the request's digest, and one run ask put. A fault ends the run could not run.
|
||||||
|
func (r *compositionRun) start(ctx context.Context, key string, run meshwants.CompositionRun, prep *runPrep) {
|
||||||
|
node, ask := run.Machine, run.Ask
|
||||||
|
end := func(said string) {
|
||||||
|
if _, err := r.runs.endRun(key, ask, meshwants.CompositionRunOutcomeCouldNotRun, said, nil); err != nil {
|
||||||
|
r.logf("the composition run %s is not ended: %v", key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := prep.get(ctx); err != nil {
|
||||||
|
end(node + ": " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
in := r.inputs.of(ctx, node, run.Candidate)
|
||||||
|
if in.Why != "" {
|
||||||
|
end(node + " gave no composition input: " + in.Why)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
program, engineFp, err := prep.programOf(node)
|
||||||
|
if err != nil {
|
||||||
|
end(node + ": " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := composer.Request{V: composer.Version, Input: in.Body, Depth: composer.DepthCompose, Machines: []string{node},
|
||||||
|
Cases: []composer.Case{{Name: changeCase, Manifests: prep.manifests, Verdicts: prep.verdicts, None: prep.none}}, Seats: prep.seats,
|
||||||
|
BlameTries: r.runs.set.blameTries} // the composer's bound of its search for culprits (§721, A-466r)
|
||||||
|
raw, err := json.Marshal(req)
|
||||||
|
if err != nil {
|
||||||
|
end(node + ": its request cannot be encoded: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
digest, err := r.keeper.keep(ask, raw)
|
||||||
|
if err != nil {
|
||||||
|
r.logf("the composition request of %s is refused: %v", node, err)
|
||||||
|
end(node + ": its request is not kept: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ref, err := buildstep.RunInputOf(inputVerbKey, raw)
|
||||||
|
if err != nil {
|
||||||
|
end(node + ": " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, _, err := r.runs.change(key, func(c *meshwants.CompositionRun) bool {
|
||||||
|
if c.Ask != ask || c.Ended != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
c.Program = &meshwants.CompositionRunProgram{Repository: program.Repository, Commit: program.Commit, Directory: program.Dir, Fingerprint: engineFp}
|
||||||
|
c.Input = digest
|
||||||
|
return true
|
||||||
|
}); err != nil {
|
||||||
|
end(node + ": the run's program and input are not written: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a := buildstep.StepAsk{ID: ask, Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: runAsker, At: r.now().UTC(),
|
||||||
|
Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the composition of " + node + " by the node-engine at " + program.Commit}}
|
||||||
|
if err := r.put(ctx, a); err != nil {
|
||||||
|
end(node + ": its run ask " + ask + " is not put: " + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// notTried is the problem the composer names a module with that its search for culprits did not try, past the request's
|
||||||
|
// blame_tries (design 47 G §721; the composer's composer.NotTried in mesh-host, compared by its words, A-470b).
|
||||||
|
const notTried = "not tried: the search reached its bound"
|
||||||
|
|
||||||
|
// judgeRun judges one machine of the step of module from the run it read (§721, §722): could not run with the run's words; else
|
||||||
|
// from the machine's composer verdict: not judged is could not run (A-467); a verdict blaming the step's module fails it, or is
|
||||||
|
// could not run where the module was not tried (A-470b); a machine that does not compose and blames no module fails every step on
|
||||||
|
// it, on the node's own account; a verdict with no `blamed` (a composer before §721) is judged as before, with the warning "the
|
||||||
|
// composer names no culprits"; otherwise the machine passes, with a warning for each other module blamed there.
|
||||||
|
func judgeRun(module string, run meshwants.CompositionRun) machineEnd {
|
||||||
|
node := run.Machine
|
||||||
|
if run.Ended == nil {
|
||||||
|
return machineEnd{couldNot: node + ": the step stopped before its composition run " + runKeyOf(run.Candidate, node) + " ended"}
|
||||||
|
}
|
||||||
|
if run.Outcome != meshwants.CompositionRunOutcomePassed {
|
||||||
|
return machineEnd{couldNot: run.Said}
|
||||||
|
}
|
||||||
|
m, err := machineOf(run.Verdict)
|
||||||
|
if err != nil {
|
||||||
|
return machineEnd{couldNot: node + ": the run's verdict does not read: " + err.Error()}
|
||||||
|
}
|
||||||
|
if m.NotJudged != "" { // a step never passes on a machine it did not judge (A-467)
|
||||||
|
return machineEnd{couldNot: node + " was not judged: " + m.NotJudged}
|
||||||
|
}
|
||||||
|
why := strings.Join(appendSome(append(slices.Clone(m.Problems), m.Refusals...), m.Reason), "; ")
|
||||||
|
switch {
|
||||||
|
case m.Blamed == nil && !m.Composes: // an old composer (§721)
|
||||||
|
return machineEnd{judged: true, failed: node + " does not compose: " + why, warnings: []string{node + ": the composer names no culprits"}}
|
||||||
|
case len(m.Blamed) == 0 && !m.Composes: // the node's own account (A-452)
|
||||||
|
return machineEnd{judged: true, failed: node + " does not compose and blames no module: " + why}
|
||||||
|
}
|
||||||
|
end := machineEnd{judged: true}
|
||||||
|
var own, others []string
|
||||||
|
for _, b := range m.Blamed {
|
||||||
|
switch {
|
||||||
|
case b.Module == module && b.Problem == notTried:
|
||||||
|
end.couldNot = fmt.Sprintf("%s holds %s untried: the composer's search for culprits reached its bound of blame_tries (A-470b)", node, module)
|
||||||
|
case b.Module == module:
|
||||||
|
own = append(own, b.Problem)
|
||||||
|
default:
|
||||||
|
others = append(others, node+" holds "+b.Module+": "+b.Problem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(own) > 0 {
|
||||||
|
end.failed, end.couldNot = node+" holds "+module+": "+strings.Join(own, "; "), ""
|
||||||
|
}
|
||||||
|
end.warnings = others
|
||||||
|
return end
|
||||||
|
}
|
||||||
|
|
||||||
|
// machineOf is the composer's verdict of one machine as a run keeps it.
|
||||||
|
func machineOf(v map[string]any) (composer.Machine, error) {
|
||||||
|
var m composer.Machine
|
||||||
|
raw, err := json.Marshal(v)
|
||||||
|
if err == nil {
|
||||||
|
err = json.Unmarshal(raw, &m)
|
||||||
|
}
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// runVerdict reads the composer's answer of one machine: its verdict as the run keeps it, or why it is none.
|
||||||
|
func runVerdict(node string, answer []byte) (map[string]any, string) {
|
||||||
|
var v composer.Verdict
|
||||||
|
if err := json.Unmarshal(answer, &v); err != nil {
|
||||||
|
return nil, node + ": the composer answered no verdict: " + err.Error()
|
||||||
|
}
|
||||||
|
if v.V != composer.Version {
|
||||||
|
return nil, fmt.Sprintf("%s: the composer answered a verdict of version %d, the assigner reads %d", node, v.V, composer.Version)
|
||||||
|
}
|
||||||
|
for _, c := range v.Cases {
|
||||||
|
if c.Name != changeCase {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
m, ok := c.Machines[node]
|
||||||
|
if !ok {
|
||||||
|
return nil, node + ": the composer's verdict names no such machine"
|
||||||
|
}
|
||||||
|
raw, err := json.Marshal(m)
|
||||||
|
var out map[string]any
|
||||||
|
if err == nil {
|
||||||
|
err = json.Unmarshal(raw, &out)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, node + ": the composer's verdict cannot be kept: " + err.Error()
|
||||||
|
}
|
||||||
|
return out, ""
|
||||||
|
}
|
||||||
|
return nil, node + ": the composer's verdict has no case " + changeCase
|
||||||
|
}
|
||||||
|
|
||||||
|
// revision reads the step's catalog revision whole, page by page, through mesh-catalog's `revision` (A-252), once for every step of
|
||||||
|
// it (compositionreads.go).
|
||||||
|
func (r *compositionRun) revision(ctx context.Context, run meshwants.StepRun) (mcc.Half, error) {
|
||||||
|
if run.Revision <= 0 {
|
||||||
|
return mcc.Half{}, errors.New("the step names no catalog revision")
|
||||||
|
}
|
||||||
|
return r.half(ctx, readKey{run.Branch, int(run.Revision)}, func() (mcc.Half, error) { return r.readRevision(ctx, run) })
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *compositionRun) readRevision(ctx context.Context, run meshwants.StepRun) (mcc.Half, error) {
|
||||||
|
half := mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{}}
|
||||||
|
in := meshcatalog.RevisionInput{Branch: keys.EscapeName(run.Branch), Revision: run.Revision}
|
||||||
|
for {
|
||||||
|
body, said, err := r.callRetry(ctx, mcc.RevisionVerb, in)
|
||||||
|
if err != nil {
|
||||||
|
return mcc.Half{}, err
|
||||||
|
}
|
||||||
|
if body == nil {
|
||||||
|
return mcc.Half{}, fmt.Errorf("%s answered: %s", mcc.RevisionVerb, said)
|
||||||
|
}
|
||||||
|
var a meshcatalog.RevisionAnswer
|
||||||
|
if err := json.Unmarshal(body, &a); err != nil {
|
||||||
|
return mcc.Half{}, fmt.Errorf("%s answered no revision: %w", mcc.RevisionVerb, err)
|
||||||
|
}
|
||||||
|
if a.NoneYet || a.Revision == nil || a.Revision.Revision != run.Revision {
|
||||||
|
return mcc.Half{}, fmt.Errorf("%s answered no revision %d of %q", mcc.RevisionVerb, run.Revision, run.Branch)
|
||||||
|
}
|
||||||
|
if in.After == "" {
|
||||||
|
half.Revision = *a.Revision // the first page names what the revision was read from, its definitions included
|
||||||
|
}
|
||||||
|
for _, e := range a.Entries {
|
||||||
|
half.Entries[e.Module] = e
|
||||||
|
}
|
||||||
|
if a.Next == "" {
|
||||||
|
return half, nil
|
||||||
|
}
|
||||||
|
in.After = a.Next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// seats are the definitions the composer is handed, raw. A revision that names definitions (A-261): the definition of each (seat, digest)
|
||||||
|
// pair, from mesh-catalog's seat-definitions where the trunk's digest is the revision's; a digest neither holds is an error naming the seat
|
||||||
|
// and the digest. A revision that names none (A-234's stand-in, A-467): every definition of the trunk seat list, read through
|
||||||
|
// seat-definitions; a list or a definition that cannot be read is an error naming it, never an empty list.
|
||||||
|
func (r *compositionRun) seats(ctx context.Context, defs []meshcatalog.CatalogRevisionDefinitionsItem) ([]json.RawMessage, error) {
|
||||||
|
if len(defs) == 0 {
|
||||||
|
return r.trunkSeats(ctx)
|
||||||
|
}
|
||||||
|
out := make([]json.RawMessage, 0, len(defs))
|
||||||
|
for _, d := range defs {
|
||||||
|
def, err := r.seatAt(ctx, d.Seat, d.Digest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out = append(out, def)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// trunkSeats are the definitions of every seat of the trunk's seat list (seat-definitions with no seat names them with their digests).
|
||||||
|
func (r *compositionRun) trunkSeats(ctx context.Context) ([]json.RawMessage, error) {
|
||||||
|
what := "the trunk's seat list is not read"
|
||||||
|
body, said, err := r.callRetry(ctx, seatDefinitionsKey, meshcatalog.SeatDefinitionsInput{})
|
||||||
|
if err != nil || body == nil {
|
||||||
|
return nil, unreadErr(what, err, said)
|
||||||
|
}
|
||||||
|
var list meshcatalog.SeatDefinitionsAnswer
|
||||||
|
if err := json.Unmarshal(body, &list); err != nil {
|
||||||
|
return nil, fmt.Errorf("%s: %w", what, err)
|
||||||
|
}
|
||||||
|
if len(list.Seats) == 0 {
|
||||||
|
return nil, errors.New(what + ": mesh-catalog's seat-definitions names no seat, so the composer has no seat list to judge by")
|
||||||
|
}
|
||||||
|
out := make([]json.RawMessage, 0, len(list.Seats))
|
||||||
|
for _, s := range list.Seats {
|
||||||
|
def, err := r.seatAt(ctx, s.Seat, s.Digest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out = append(out, def)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// seatAt is the definition of a seat at a digest, kept once read (a definition at a digest never changes).
|
||||||
|
func (r *compositionRun) seatAt(ctx context.Context, seat, digest string) (json.RawMessage, error) {
|
||||||
|
if def, ok := r.reads.seatKept(seat, digest); ok {
|
||||||
|
return def, nil
|
||||||
|
}
|
||||||
|
what := "the definition of the seat " + seat + " is not read"
|
||||||
|
body, said, err := r.callRetry(ctx, seatDefinitionsKey, meshcatalog.SeatDefinitionsInput{Seat: seat})
|
||||||
|
if err != nil || body == nil {
|
||||||
|
return nil, unreadErr(what, err, said)
|
||||||
|
}
|
||||||
|
var a meshcatalog.SeatDefinitionsAnswer
|
||||||
|
if err := json.Unmarshal(body, &a); err != nil {
|
||||||
|
return nil, fmt.Errorf("%s: %w", what, err)
|
||||||
|
}
|
||||||
|
if a.Entry == nil || a.Entry.Digest != digest || a.Entry.Definition == nil {
|
||||||
|
return nil, fmt.Errorf("no definition of the seat %s with the digest %s is held: neither the revision nor the trunk holds it", seat, digest)
|
||||||
|
}
|
||||||
|
def, err := json.Marshal(a.Entry.Definition)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r.reads.keepSeat(seat, digest, def)
|
||||||
|
return def, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// caseOf is the case's manifests, verdicts and none from the revision's entries: each manifest whole, the verdict of each one not
|
||||||
|
// accepted (a module without one is accepted), and the revision's none words of each module it gives no fingerprint, whose
|
||||||
|
// build can never be made (design 47 G A-470j, A-470k).
|
||||||
|
func caseOf(half mcc.Half) (map[string]composer.Manifest, map[string]json.RawMessage, map[string]string, error) {
|
||||||
|
manifests := map[string]composer.Manifest{}
|
||||||
|
verdicts := map[string]json.RawMessage{}
|
||||||
|
var none map[string]string
|
||||||
|
for name, e := range half.Entries {
|
||||||
|
if len(e.Manifest) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
raw, err := json.Marshal(e.Manifest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, fmt.Errorf("the manifest of %s cannot be encoded: %w", name, err)
|
||||||
|
}
|
||||||
|
manifests[name] = composer.Manifest{Raw: raw}
|
||||||
|
if e.Fp == "" && e.None != "" {
|
||||||
|
if none == nil {
|
||||||
|
none = map[string]string{}
|
||||||
|
}
|
||||||
|
none[name] = e.None
|
||||||
|
}
|
||||||
|
if e.Verdict == "" || e.Verdict == mcc.VerdictAccepted {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
v := meshcatalog.VerdictsByDigestValue{V: 1, Module: name, State: e.Verdict}
|
||||||
|
if e.Verdict != mcc.VerdictRefused {
|
||||||
|
v.State = mcc.VerdictManifestWaits
|
||||||
|
}
|
||||||
|
if e.Inputs != nil {
|
||||||
|
v.Problems, v.Unknown, v.Warnings = e.Inputs.Problems, e.Inputs.Unknown, e.Inputs.Warnings
|
||||||
|
}
|
||||||
|
raw, err = json.Marshal(v)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
verdicts[name] = raw
|
||||||
|
}
|
||||||
|
return manifests, verdicts, none, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// nodeEngineEntry is the entry of the module that claims the seat node-engine, or false.
|
||||||
|
func nodeEngineEntry(entries map[string]meshcatalog.CatalogEntry) (meshcatalog.CatalogEntry, bool) {
|
||||||
|
for _, name := range slices.Sorted(mapsKeys(entries)) {
|
||||||
|
for _, s := range entries[name].Serves {
|
||||||
|
// The catalog writes a served seat verb as `seat:<seat>.<verb>` (as the compose words above are made).
|
||||||
|
if strings.HasPrefix(strings.TrimPrefix(s, "seat:"), ne.Seat+".") {
|
||||||
|
return entries[name], true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return meshcatalog.CatalogEntry{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapsKeys(m map[string]meshcatalog.CatalogEntry) func(func(string) bool) {
|
||||||
|
return func(yield func(string) bool) {
|
||||||
|
for k := range m {
|
||||||
|
if !yield(k) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// programOfEntry is the composer built from a node-engine entry: its repository, commit and directory, the composer's package.
|
||||||
|
func programOfEntry(e meshcatalog.CatalogEntry) (buildstep.RunProgram, error) {
|
||||||
|
dir := e.Path
|
||||||
|
if dir == "" {
|
||||||
|
dir = "."
|
||||||
|
}
|
||||||
|
if e.Repository == "" || e.Commit == "" {
|
||||||
|
return buildstep.RunProgram{}, fmt.Errorf("the node-engine's entry %s names no repository or commit", e.Fp)
|
||||||
|
}
|
||||||
|
return buildstep.RunProgram{Repository: e.Repository, Commit: e.Commit, Dir: dir, Package: composer.Package}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// programs answers, per machine, the composer its run builds and the node-engine fingerprint it was chosen from (A-226, A-243,
|
||||||
|
// A-252, §719): where the revision's node-engine entry differs from the trunk's, that build for every machine; else the build the
|
||||||
|
// machine's node-engine runs, as its `running` says, its entry read through mesh-catalog's `entry`; a machine whose node-engine's
|
||||||
|
// `running` is not heard gets the revision's entry, said (A-451).
|
||||||
|
func (r *compositionRun) programs(ctx context.Context, half mcc.Half) (func(node string) (buildstep.RunProgram, string, error), error) {
|
||||||
|
engine, ok := nodeEngineEntry(half.Entries)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("the catalog revision %d holds no module claiming the seat %s", half.Revision.Revision, ne.Seat)
|
||||||
|
}
|
||||||
|
if trunk, ok := r.trunk(); !ok || func() bool { t, ok := nodeEngineEntry(trunk.Entries); return !ok || t.Fp != engine.Fp }() {
|
||||||
|
p, err := programOfEntry(engine)
|
||||||
|
return func(string) (buildstep.RunProgram, string, error) { return p, engine.Fp, err }, nil
|
||||||
|
}
|
||||||
|
var mu sync.Mutex
|
||||||
|
byFp := map[string]buildstep.RunProgram{}
|
||||||
|
return func(node string) (buildstep.RunProgram, string, error) {
|
||||||
|
running, ok := r.running(node, engine.Module)
|
||||||
|
if !ok || running.Fingerprint == "" {
|
||||||
|
r.logf("%s: no build of %s is heard running there, so its composer is the catalog revision's entry %s (A-451)", node,
|
||||||
|
engine.Module, engine.Fp)
|
||||||
|
p, err := programOfEntry(engine)
|
||||||
|
return p, engine.Fp, err
|
||||||
|
}
|
||||||
|
fp := running.Fingerprint
|
||||||
|
mu.Lock()
|
||||||
|
p, ok := byFp[fp]
|
||||||
|
mu.Unlock()
|
||||||
|
if ok {
|
||||||
|
return p, fp, nil
|
||||||
|
}
|
||||||
|
what := "the entry of the node-engine's build " + fp + " is not read"
|
||||||
|
body, said, err := r.callRetry(ctx, entryVerbKey, meshcatalog.EntryInput{Fingerprint: fp})
|
||||||
|
if err != nil || body == nil {
|
||||||
|
return buildstep.RunProgram{}, fp, unreadErr(what, err, said)
|
||||||
|
}
|
||||||
|
var a meshcatalog.EntryAnswer
|
||||||
|
if err := json.Unmarshal(body, &a); err != nil {
|
||||||
|
return buildstep.RunProgram{}, fp, fmt.Errorf("%s: %w", what, err)
|
||||||
|
}
|
||||||
|
p, err = programOfEntry(a.Entry)
|
||||||
|
if err != nil {
|
||||||
|
return p, fp, err
|
||||||
|
}
|
||||||
|
mu.Lock()
|
||||||
|
byFp[fp] = p
|
||||||
|
mu.Unlock()
|
||||||
|
return p, fp, nil
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// trunkOf is the trunk's catalog half the assigner's views hold, trunk naming the first watched branch, or false while none is
|
||||||
|
// held.
|
||||||
|
func trunkOf(iv *catalogViews, trunk func() string) func() (mcc.Half, bool) {
|
||||||
|
return func() (mcc.Half, bool) {
|
||||||
|
if iv == nil || iv.h == nil {
|
||||||
|
return mcc.Half{}, false
|
||||||
|
}
|
||||||
|
h, ok := iv.h.views()[trunk()]
|
||||||
|
return h, ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// runAskPublisher puts a run ask on the Go build seat's check queue under the assigner's name (`accept.check.assigner`, §600), its
|
||||||
|
// id the message id, so the stream takes it once.
|
||||||
|
func runAskPublisher(js jetstream.JetStream) func(ctx context.Context, a buildstep.StepAsk) error {
|
||||||
|
return func(ctx context.Context, a buildstep.StepAsk) error {
|
||||||
|
raw, err := buildstep.EncodeStepAsk(a)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
subject, err := buildstep.AskSubjectBy(a.Language, a.Kind, a.Asker)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = js.Publish(ctx, subject, raw, jetstream.WithMsgID(a.ID))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,575 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
commitE1 = "1111111111111111111111111111111111111111"
|
||||||
|
commitE2 = "2222222222222222222222222222222222222222"
|
||||||
|
commitE3 = "3333333333333333333333333333333333333333"
|
||||||
|
)
|
||||||
|
|
||||||
|
// runStand is a composition run over stand-ins of the mesh-catalog seat, the machines' engines, the build seat and its step-ended.
|
||||||
|
type runStand struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
asks map[string]buildstep.StepAsk // by node
|
||||||
|
requests map[string]composer.Request // by node
|
||||||
|
entries []string // the fingerprints `entry` was asked
|
||||||
|
r *compositionRun
|
||||||
|
runs *compositionRuns
|
||||||
|
puts int // the run asks put
|
||||||
|
// noDefinitions: the revision names no seat definition (A-234's stand-in); trunkSeats: the trunk's seat list as (seat, digest)
|
||||||
|
// pairs; unjudged: the machine the composer does not judge; listFault: the trunk's seat list cannot be read.
|
||||||
|
noDefinitions bool
|
||||||
|
trunkSeats []meshcatalog.SeatDefinitionsAnswerSeatsItem
|
||||||
|
unjudged string
|
||||||
|
listFault error
|
||||||
|
// verdict, when set, is the composer's verdict of a machine (by node), else the stand's own.
|
||||||
|
verdict func(node string) (composer.Machine, bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *runStand {
|
||||||
|
s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}}
|
||||||
|
engine := func(fp, commit string) meshcatalog.CatalogEntry {
|
||||||
|
return meshcatalog.CatalogEntry{Module: "engine", Fp: fp, Repository: "novox/mesh-host", Commit: commit, Path: ".", Serves: []string{ne.Seat + ".composition"},
|
||||||
|
Manifest: map[string]any{"module": "engine"}}
|
||||||
|
}
|
||||||
|
revisionCommit := commitE1
|
||||||
|
if revisionEngine != "src2:e1" {
|
||||||
|
revisionCommit = commitE3
|
||||||
|
}
|
||||||
|
pages := map[string]meshcatalog.RevisionAnswer{
|
||||||
|
"": {Revision: &meshcatalog.CatalogRevision{Revision: 7, Branch: "main", Definitions: []meshcatalog.CatalogRevisionDefinitionsItem{{Seat: "s1", Digest: "d1"}}},
|
||||||
|
Entries: []meshcatalog.CatalogEntry{engine(revisionEngine, revisionCommit), {Module: "bad", Verdict: mcc.VerdictRefused, Inputs: &meshcatalog.EntryInputs{Problems: []string{"no seat x"}},
|
||||||
|
Manifest: map[string]any{"module": "bad"}}}, Next: "bad"},
|
||||||
|
"bad": {Revision: &meshcatalog.CatalogRevision{Revision: 7}, Entries: []meshcatalog.CatalogEntry{{Module: "m", Verdict: mcc.VerdictAccepted, Manifest: map[string]any{"module": "m"}},
|
||||||
|
{Module: "lidarr", None: "builders disagree: node", Manifest: map[string]any{"module": "lidarr"}}}}, // no fingerprint (A-470j)
|
||||||
|
}
|
||||||
|
call := func(key string, body any) (json.RawMessage, error) {
|
||||||
|
raw, _ := json.Marshal(body)
|
||||||
|
switch key {
|
||||||
|
case mcc.RevisionVerb:
|
||||||
|
var in meshcatalog.RevisionInput
|
||||||
|
_ = json.Unmarshal(raw, &in)
|
||||||
|
if in.Revision != 7 || in.Branch != "main" {
|
||||||
|
return nil, errors.New("asked another revision")
|
||||||
|
}
|
||||||
|
page := pages[in.After]
|
||||||
|
if s.noDefinitions && page.Revision != nil {
|
||||||
|
rev := *page.Revision
|
||||||
|
rev.Definitions = nil
|
||||||
|
page.Revision = &rev
|
||||||
|
}
|
||||||
|
return json.Marshal(page)
|
||||||
|
case seatDefinitionsKey:
|
||||||
|
var sin meshcatalog.SeatDefinitionsInput
|
||||||
|
_ = json.Unmarshal(raw, &sin)
|
||||||
|
if sin.Seat == "" {
|
||||||
|
if s.listFault != nil {
|
||||||
|
return nil, s.listFault
|
||||||
|
}
|
||||||
|
return json.Marshal(meshcatalog.SeatDefinitionsAnswer{Seats: s.trunkSeats})
|
||||||
|
}
|
||||||
|
return json.Marshal(meshcatalog.SeatDefinitionsAnswer{Found: true, Entry: &meshcatalog.SeatDefinitionsAnswerEntry{Seat: "s1", Digest: seatDigest, Definition: map[string]any{"seat": "s1"}}})
|
||||||
|
case entryVerbKey:
|
||||||
|
var in meshcatalog.EntryInput
|
||||||
|
_ = json.Unmarshal(raw, &in)
|
||||||
|
s.mu.Lock()
|
||||||
|
s.entries = append(s.entries, in.Fingerprint)
|
||||||
|
s.mu.Unlock()
|
||||||
|
commit := map[string]string{"src2:e1": commitE1, "src2:e2": commitE2}[in.Fingerprint]
|
||||||
|
return json.Marshal(meshcatalog.EntryAnswer{Entry: engine(in.Fingerprint, commit)})
|
||||||
|
}
|
||||||
|
return nil, errors.New("no such verb " + key)
|
||||||
|
}
|
||||||
|
engines := func(key string, _ any) (json.RawMessage, error) {
|
||||||
|
_, node, _ := strings.Cut(key, "@") // addressed to one node (A-237b)
|
||||||
|
return json.RawMessage(`{"candidate":"main.7","node":"` + node + `","verdict":"composed","input":{"node":"` + node + `"},"modules":[],"own":{},"took":1,"v":1}`), nil
|
||||||
|
}
|
||||||
|
running := map[string]string{"ace": "src2:e1", "g14": "src2:e2"}
|
||||||
|
away := func(machine string) bool { return machine == "shanks" }
|
||||||
|
keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now)
|
||||||
|
s.runs = newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf)
|
||||||
|
s.r = &compositionRun{runs: s.runs,
|
||||||
|
inputs: &compositionInputs{machines: func(string, string) []string { return []string{"ace", "g14", "shanks"} }, callFile: engines, bound: time.Second},
|
||||||
|
keeper: keeper, reads: &compositionReads{}, call: call, away: away, now: time.Now, logf: t.Logf,
|
||||||
|
trunk: func() (mcc.Half, bool) {
|
||||||
|
return mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{"engine": engine(trunkEngine, commitE1)}}, true
|
||||||
|
},
|
||||||
|
running: func(node, module string) (ne.Running, bool) {
|
||||||
|
fp, ok := running[node]
|
||||||
|
return ne.Running{Node: node, Module: module, Fingerprint: fp}, ok && module == "engine"
|
||||||
|
},
|
||||||
|
put: func(_ context.Context, a buildstep.StepAsk) error {
|
||||||
|
body, err := keeper.body(a.Run.Input.Digest)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req, err := composer.Decode(body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
node := req.Machines[0]
|
||||||
|
s.mu.Lock()
|
||||||
|
s.asks[node], s.requests[node] = a, req
|
||||||
|
s.mu.Unlock()
|
||||||
|
m := composer.Machine{Composes: true}
|
||||||
|
override, set := composer.Machine{}, false
|
||||||
|
if s.verdict != nil {
|
||||||
|
override, set = s.verdict(node)
|
||||||
|
}
|
||||||
|
if set {
|
||||||
|
m = override
|
||||||
|
} else if node == s.unjudged {
|
||||||
|
m = composer.Machine{NotJudged: "the composer was handed no seat list"}
|
||||||
|
} else if node == "g14" {
|
||||||
|
m = composer.Machine{Reason: "two modules own one path", Problems: []string{"/etc/x is m's and bad's"}}
|
||||||
|
}
|
||||||
|
v, _ := json.Marshal(composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{{Name: changeCase, Machines: map[string]composer.Machine{node: m}}}})
|
||||||
|
s.mu.Lock()
|
||||||
|
s.puts++
|
||||||
|
s.mu.Unlock()
|
||||||
|
go func() {
|
||||||
|
if err := s.runs.heardEnd(buildstep.StepEnded{Ask: a.ID, Asker: runAsker, Node: "builder1", Outcome: buildstep.OutcomePassed, Output: string(v)},
|
||||||
|
func(e buildstep.StepEnded) ([]byte, error) { return []byte(e.Output), nil }); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §354, §63, §64, A-226, A-238, A-240, A-243, A-252, A-254, A-261: one request and one run ask per machine, the request
|
||||||
|
// depth compose with the one machine and one case `change`, its manifests, verdicts and seats from the step's revision; the
|
||||||
|
// composer is the node-engine build each machine runs, its entry read through `entry`, or the revision's where it differs from the
|
||||||
|
// trunk's, or the revision's for a machine whose node-engine is not heard running (A-451); the run's verdict is read from its step-ended; a machine away passes with a warning, one not composing fails the step.
|
||||||
|
func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
|
||||||
|
step := meshwants.StepRun{Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition}
|
||||||
|
s := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
out := s.r.run(context.Background(), "ask-step", step)
|
||||||
|
if out.Outcome != meshwants.StepEndedOutcomeFailed || !strings.Contains(out.Said, "g14 does not compose") || !strings.Contains(out.Said, "/etc/x") ||
|
||||||
|
strings.Contains(out.Said, "ace") || len(out.Warnings) != 2 || !strings.Contains(out.Warnings[0], "shanks is away") ||
|
||||||
|
out.Warnings[1] != "g14: the composer names no culprits" {
|
||||||
|
t.Fatalf("the step came to %+v", out)
|
||||||
|
}
|
||||||
|
if len(s.asks) != 2 {
|
||||||
|
t.Fatalf("asked %d runs, want one per machine not away", len(s.asks))
|
||||||
|
}
|
||||||
|
a, req := s.asks["ace"], s.requests["ace"]
|
||||||
|
if a.Kind != buildstep.AskCheck || a.Language != buildstep.AskGo || a.Asker != runAsker || a.Run == nil || len(a.Run.Heads) != 0 ||
|
||||||
|
a.Run.Input.Verb != "seat:mesh-wants.input" || a.Run.Program != (buildstep.RunProgram{Repository: "novox/mesh-host", Commit: commitE1, Dir: ".", Package: composer.Package}) {
|
||||||
|
t.Errorf("the run ask of ace %+v %+v", a, a.Run)
|
||||||
|
}
|
||||||
|
if s.asks["g14"].Run.Program.Commit != commitE2 {
|
||||||
|
t.Errorf("g14's composer is built at %s, want the build its node-engine runs", s.asks["g14"].Run.Program.Commit)
|
||||||
|
}
|
||||||
|
if req.Depth != composer.DepthCompose || req.BlameTries != 20 || len(req.Machines) != 1 || req.Machines[0] != "ace" || len(req.Cases) != 1 || req.Cases[0].Name != changeCase ||
|
||||||
|
string(req.Input) != `{"node":"ace"}` || len(req.Seats) != 1 || string(req.Seats[0]) != `{"seat":"s1"}` {
|
||||||
|
t.Errorf("the request of ace %+v", req)
|
||||||
|
}
|
||||||
|
c := req.Cases[0]
|
||||||
|
if string(c.Manifests["m"].Raw) != `{"module":"m"}` || len(c.Manifests) != 4 || len(c.None) != 1 || c.None["lidarr"] != "builders disagree: node" || len(c.Verdicts) != 1 || !strings.Contains(string(c.Verdicts["bad"]), `"refused"`) ||
|
||||||
|
!strings.Contains(string(c.Verdicts["bad"]), "no seat x") {
|
||||||
|
t.Errorf("the case %+v %s", c.Manifests, c.Verdicts)
|
||||||
|
}
|
||||||
|
if strings.Join(s.entries, " ") == "" {
|
||||||
|
t.Error("no node-engine entry is read through entry")
|
||||||
|
}
|
||||||
|
|
||||||
|
// The revision's node-engine differs from the trunk's: that build composes every machine, and no entry is asked.
|
||||||
|
changed := newRunStand(t, "src2:e3", "src2:e1", "d1")
|
||||||
|
if out := changed.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeFailed {
|
||||||
|
t.Fatalf("the step came to %+v", out)
|
||||||
|
}
|
||||||
|
if changed.asks["ace"].Run.Program.Commit != commitE3 || changed.asks["g14"].Run.Program.Commit != commitE3 || len(changed.entries) != 0 {
|
||||||
|
t.Errorf("the change's node-engine does not compose every machine: %+v %+v %v", changed.asks["ace"].Run.Program, changed.asks["g14"].Run.Program, changed.entries)
|
||||||
|
}
|
||||||
|
|
||||||
|
// No running of the node-engine is heard on g14: its composer is the revision's entry, and no entry is asked for it (A-451).
|
||||||
|
unheard := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
unheard.r.running = func(node, module string) (ne.Running, bool) {
|
||||||
|
return ne.Running{Node: node, Module: module, Fingerprint: "src2:e1"}, node == "ace" && module == "engine"
|
||||||
|
}
|
||||||
|
if out := unheard.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeFailed || !strings.Contains(out.Said, "g14 does not compose") {
|
||||||
|
t.Fatalf("the step with g14's node-engine not heard came to %+v", out)
|
||||||
|
}
|
||||||
|
if unheard.asks["g14"].Run == nil || unheard.asks["g14"].Run.Program.Commit != commitE1 {
|
||||||
|
t.Errorf("g14's composer with no running heard is %+v, want the revision's entry", unheard.asks["g14"].Run)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A seat digest neither the revision nor the trunk holds: could not run, naming the seat and the digest (A-261).
|
||||||
|
other := newRunStand(t, "src2:e1", "src2:e1", "d2")
|
||||||
|
if out := other.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeCouldNotRun ||
|
||||||
|
!strings.Contains(out.Said, "s1") || !strings.Contains(out.Said, "d1") || len(other.asks) != 0 {
|
||||||
|
t.Errorf("a seat digest not held came to %+v, %d asks", out, len(other.asks))
|
||||||
|
}
|
||||||
|
|
||||||
|
// A revision naming no definition (A-234's stand-in): the composer is handed the trunk seat list's definitions, read through
|
||||||
|
// seat-definitions (A-467); a list that cannot be read, or names no seat, ends the step could not run, naming it, with no ask put.
|
||||||
|
bare := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
bare.noDefinitions, bare.trunkSeats = true, []meshcatalog.SeatDefinitionsAnswerSeatsItem{{Seat: "s1", Digest: "d1"}}
|
||||||
|
if out := bare.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeFailed ||
|
||||||
|
len(bare.requests["ace"].Seats) != 1 || string(bare.requests["ace"].Seats[0]) != `{"seat":"s1"}` {
|
||||||
|
t.Errorf("a revision with no definitions came to %+v, seats %v", out, bare.requests["ace"].Seats)
|
||||||
|
}
|
||||||
|
for name, fault := range map[string]error{"unreadable": errors.New("no responder"), "empty": nil} {
|
||||||
|
s := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
s.noDefinitions, s.listFault = true, fault
|
||||||
|
if out := s.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeCouldNotRun ||
|
||||||
|
!strings.Contains(out.Said, "seat list is not read") || len(s.asks) != 0 {
|
||||||
|
t.Errorf("the %s seat list came to %+v, %d asks", name, out, len(s.asks))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A machine the composer did not judge is could not run, naming why: a step that judged nothing never passes (A-467).
|
||||||
|
nj := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
nj.unjudged = "g14"
|
||||||
|
if out := nj.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeCouldNotRun ||
|
||||||
|
!strings.Contains(out.Said, "g14 was not judged: the composer was handed no seat list") {
|
||||||
|
t.Errorf("a machine not judged came to %+v", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// No machine judged: every machine away, or no machine, never passes; each is named with why (A-467a).
|
||||||
|
for name, machines := range map[string][]string{"every machine away": {"shanks"}, "no machine": {}} { // none placed: the inputs say so already
|
||||||
|
want := "no machine was judged"
|
||||||
|
if len(machines) == 0 {
|
||||||
|
want = "has no machine to compose"
|
||||||
|
}
|
||||||
|
none := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
none.r.inputs.machines = func(string, string) []string { return machines }
|
||||||
|
if out := none.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeCouldNotRun ||
|
||||||
|
!strings.Contains(out.Said, want) || (len(machines) > 0 && !strings.Contains(out.Said, "shanks is away")) || len(none.asks) != 0 {
|
||||||
|
t.Errorf("%s came to %+v, %d asks", name, out, len(none.asks))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// At the inputs state's cap the ask is refused, naming the store (§354).
|
||||||
|
full := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
full.r.keeper.used = func() (int64, error) { return inputsCap, nil }
|
||||||
|
if out := full.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeCouldNotRun ||
|
||||||
|
!strings.Contains(out.Said, "the state inputs is at its cap") || len(full.asks) != 0 {
|
||||||
|
t.Errorf("an ask at the cap came to %+v, %d asks", out, len(full.asks))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §354, A-252: the entries of one catalog revision are read once for every step of it, and a read that times out is
|
||||||
|
// made again with a growing wait for a bounded time, said in the journal, before the step could not run.
|
||||||
|
func TestTheCompositionStepReadsTheRevisionOnceAndAgainOnATimeout(t *testing.T) {
|
||||||
|
step := meshwants.StepRun{Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition}
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
faults int // consecutive faults of the `revision` read before it answers
|
||||||
|
fault error // the fault
|
||||||
|
steps int
|
||||||
|
want string // the outcome of the last step
|
||||||
|
revisionCalls int
|
||||||
|
waits int
|
||||||
|
}{
|
||||||
|
{"two steps of one revision read it once", 0, nil, 2, meshwants.StepEndedOutcomeFailed, 2, 0},
|
||||||
|
{"a timeout is read again", 3, errors.New("context deadline exceeded"), 1, meshwants.StepEndedOutcomeFailed, 5, 3},
|
||||||
|
{"a fault that stays ends could not run", 1000, errors.New("nats: timeout"), 1, meshwants.StepEndedOutcomeCouldNotRun, -1, -1},
|
||||||
|
{"a fault of the answer is not read again", 1, errors.New("no such revision"), 1, meshwants.StepEndedOutcomeCouldNotRun, 1, 0},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
s := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
inner := s.r.call
|
||||||
|
var mu sync.Mutex
|
||||||
|
calls, faults := 0, tc.faults
|
||||||
|
s.r.call = func(key string, body any) (json.RawMessage, error) {
|
||||||
|
if key == mcc.RevisionVerb {
|
||||||
|
mu.Lock()
|
||||||
|
calls++
|
||||||
|
f := faults > 0
|
||||||
|
faults--
|
||||||
|
mu.Unlock()
|
||||||
|
if f {
|
||||||
|
return nil, tc.fault
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return inner(key, body)
|
||||||
|
}
|
||||||
|
clock := time.Unix(1000, 0)
|
||||||
|
var waits []time.Duration
|
||||||
|
s.r.now = func() time.Time { mu.Lock(); defer mu.Unlock(); return clock }
|
||||||
|
s.r.sleep = func(_ context.Context, d time.Duration) error {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
waits = append(waits, d)
|
||||||
|
clock = clock.Add(d)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
outs := make([]stepOutcome, tc.steps)
|
||||||
|
for i := range outs {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() { defer wg.Done(); outs[i] = s.r.run(context.Background(), "ask-step", step) }()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
for _, o := range outs {
|
||||||
|
if o.Outcome != tc.want {
|
||||||
|
t.Fatalf("a step came to %+v, want %s", o, tc.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tc.waits == -1 { // never answers: bounded, growing waits
|
||||||
|
if len(waits) < 3 || waits[0] != readsFirstWait || waits[1] != 2*readsFirstWait || waits[len(waits)-1] != readsMaxWait {
|
||||||
|
t.Errorf("the waits %v do not grow to %s", waits, readsMaxWait)
|
||||||
|
}
|
||||||
|
var total time.Duration
|
||||||
|
for _, w := range waits {
|
||||||
|
total += w
|
||||||
|
}
|
||||||
|
if total > readsBound {
|
||||||
|
t.Errorf("read again for %s, bound %s", total, readsBound)
|
||||||
|
}
|
||||||
|
if !strings.Contains(outs[0].Said, "catalog revision is not read") || !strings.Contains(outs[0].Said, "timeout") {
|
||||||
|
t.Errorf("the step said %q", outs[0].Said)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if calls != tc.revisionCalls || len(waits) != tc.waits {
|
||||||
|
t.Errorf("`revision` asked %d times with %d waits, want %d and %d", calls, len(waits), tc.revisionCalls, tc.waits)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §718, §719, §720: three composition steps of one revision on two machines start two runs, one request and one run
|
||||||
|
// ask per machine, and each step reads both verdicts; the run records its program with the node-engine fingerprint it was chosen
|
||||||
|
// from and the digest of its kept request, which names no module of the asking pipeline; a step of another candidate starts its
|
||||||
|
// own runs, and a run that could not run is never read again.
|
||||||
|
func TestTheStepsOfOneCandidateReadOneRunPerMachine(t *testing.T) {
|
||||||
|
s := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
s.r.inputs.machines = func(string, string) []string { return []string{"ace", "g14"} }
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
outs := make([]stepOutcome, 3)
|
||||||
|
for i, m := range []string{"m", "m2", "m3"} {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
outs[i] = s.r.run(context.Background(), "ask-"+m, meshwants.StepRun{Pipeline: "main.7." + m, Module: m, Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition})
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
for i, o := range outs {
|
||||||
|
if len(o.Shared) != 2 || o.Shared[0].Machine != "ace" || o.Shared[0].Run != runKeyOf("main.7", "ace") || o.Shared[0].Ask == "" ||
|
||||||
|
o.Shared[1].Machine != "g14" || o.Shared[1].Ask == o.Shared[0].Ask { // §723, §729: per machine the run read and its ask
|
||||||
|
t.Errorf("step %d names the runs %+v", i, o.Shared)
|
||||||
|
}
|
||||||
|
if o.Outcome != meshwants.StepEndedOutcomeFailed || !strings.Contains(o.Said, "g14 does not compose") {
|
||||||
|
t.Errorf("step %d came to %+v, want both machines read", i, o)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if s.puts != 2 {
|
||||||
|
t.Fatalf("%d run asks put, want one per machine", s.puts)
|
||||||
|
}
|
||||||
|
ace, _, _, _ := s.runs.read(runKeyOf("main.7", "ace"))
|
||||||
|
g14, _, _, _ := s.runs.read(runKeyOf("main.7", "g14"))
|
||||||
|
if len(ace.Readers) != 3 || len(g14.Readers) != 3 || ace.Program == nil || ace.Program.Fingerprint != "src2:e1" || ace.Program.Commit != commitE1 ||
|
||||||
|
g14.Program == nil || g14.Program.Fingerprint != "src2:e2" || ace.Input == "" || ace.Input != digestOf(mustJSON(t, s.requests["ace"])) ||
|
||||||
|
ace.Outcome != meshwants.CompositionRunOutcomePassed || g14.Outcome != meshwants.CompositionRunOutcomePassed || g14.Verdict["composes"] != false {
|
||||||
|
t.Errorf("the runs: ace %+v, g14 %+v", ace, g14)
|
||||||
|
}
|
||||||
|
if req := s.requests["ace"]; strings.Contains(string(mustJSON(t, req)), "main.7.m") || string(req.Input) != `{"node":"ace"}` {
|
||||||
|
t.Errorf("the request names the asking pipeline or not the node's input: %s", mustJSON(t, req))
|
||||||
|
}
|
||||||
|
// Another candidate (a run on request) starts its own runs.
|
||||||
|
if o := s.r.run(context.Background(), "ask-r", meshwants.StepRun{Pipeline: "run-r1.m", Module: "m", Branch: "main", Revision: 7, Run: "r1", Step: meshwants.StepRunStepComposition}); o.Outcome != meshwants.StepEndedOutcomeFailed || s.puts != 4 {
|
||||||
|
t.Errorf("a step of another candidate came to %+v with %d asks, want its own two runs", o, s.puts)
|
||||||
|
}
|
||||||
|
// A run whose ask could not be put could not run; the next step of the candidate starts it again.
|
||||||
|
f := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
f.r.inputs.machines = func(string, string) []string { return []string{"ace"} }
|
||||||
|
put, refused := f.r.put, 0
|
||||||
|
f.r.put = func(ctx context.Context, a buildstep.StepAsk) error {
|
||||||
|
if refused == 0 {
|
||||||
|
refused++
|
||||||
|
return errors.New("no stream")
|
||||||
|
}
|
||||||
|
return put(ctx, a)
|
||||||
|
}
|
||||||
|
first := f.r.run(context.Background(), "ask-1", meshwants.StepRun{Pipeline: "main.7.m", Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition})
|
||||||
|
second := f.r.run(context.Background(), "ask-2", meshwants.StepRun{Pipeline: "main.7.m2", Module: "m2", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition})
|
||||||
|
if first.Outcome != meshwants.StepEndedOutcomeCouldNotRun || !strings.Contains(first.Said, "is not put") || second.Outcome != meshwants.StepEndedOutcomePassed || f.puts != 1 {
|
||||||
|
t.Errorf("after a run that could not run: %+v then %+v, %d asks", first, second, f.puts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustJSON(t *testing.T, v any) []byte {
|
||||||
|
t.Helper()
|
||||||
|
raw, err := json.Marshal(v)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §721, §722, A-470b: a step judges each machine from its verdict's `blamed`: a verdict blaming the step's module fails
|
||||||
|
// it and passes another module's step with a warning naming the module; a machine that does not compose and blames no module fails
|
||||||
|
// every step; a verdict with no `blamed` is judged as before and says "the composer names no culprits"; a module the search did not
|
||||||
|
// try is could not run for its own step; a run that could not run is could not run.
|
||||||
|
func TestAMachineIsJudgedByTheModulesItBlames(t *testing.T) {
|
||||||
|
at := time.Now()
|
||||||
|
runOf := func(verdict string) meshwants.CompositionRun {
|
||||||
|
var v map[string]any
|
||||||
|
if err := json.Unmarshal([]byte(verdict), &v); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return meshwants.CompositionRun{Candidate: "main.7", Machine: "ace", Ended: &at, Outcome: meshwants.CompositionRunOutcomePassed, Verdict: v}
|
||||||
|
}
|
||||||
|
blamesA := `{"composes":false,"reason":"two modules own one path","blamed":[{"module":"a","problem":"/etc/x is a's and c's"}]}`
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name, module string
|
||||||
|
run meshwants.CompositionRun
|
||||||
|
failed, couldNo string
|
||||||
|
warnings []string
|
||||||
|
}{
|
||||||
|
{"blamed module fails", "a", runOf(blamesA), "ace holds a: /etc/x is a's and c's", "", nil},
|
||||||
|
{"another module passes with a warning", "b", runOf(blamesA), "", "", []string{"ace holds a: /etc/x is a's and c's"}},
|
||||||
|
{"blames no module fails both", "b", runOf(`{"composes":false,"reason":"the node's own composition","blamed":[]}`), "ace does not compose and blames no module: the node's own composition", "", nil},
|
||||||
|
{"an old composer", "b", runOf(`{"composes":false,"reason":"x"}`), "ace does not compose: x", "", []string{"ace: the composer names no culprits"}},
|
||||||
|
{"composes", "b", runOf(`{"composes":true,"blamed":[]}`), "", "", nil},
|
||||||
|
{"own module not tried", "a", runOf(`{"composes":false,"blamed":[{"module":"a","problem":"not tried: the search reached its bound"}]}`), "",
|
||||||
|
"ace holds a untried: the composer's search for culprits reached its bound of blame_tries (A-470b)", nil},
|
||||||
|
{"another not tried", "b", runOf(`{"composes":false,"blamed":[{"module":"a","problem":"not tried: the search reached its bound"}]}`), "", "",
|
||||||
|
[]string{"ace holds a: not tried: the search reached its bound"}},
|
||||||
|
{"not judged", "a", runOf(`{"composes":false,"not_judged":"no seat list","blamed":[]}`), "", "ace was not judged: no seat list", nil},
|
||||||
|
{"could not run", "a", meshwants.CompositionRun{Machine: "ace", Ended: &at, Outcome: meshwants.CompositionRunOutcomeCouldNotRun, Said: "ace: gone"}, "", "ace: gone", nil},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
e := judgeRun(tc.module, tc.run)
|
||||||
|
if e.failed != tc.failed || e.couldNot != tc.couldNo || !slices.Equal(e.warnings, tc.warnings) {
|
||||||
|
t.Errorf("judged %+v, want failed %q, could not run %q, warnings %q", e, tc.failed, tc.couldNo, tc.warnings)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §727, A-468g, A-470d: a rerun of a composition step starts a new run only on the machine it did not pass, replacing
|
||||||
|
// that key and carrying every former reader, the one that did not pass marked rerun with the rerun's caller; at the new run's end
|
||||||
|
// that reader says its end again, marked rerun, naming the new run's ask; a reader that passed does not move; the machine the
|
||||||
|
// step passed keeps its verdict.
|
||||||
|
func TestARerunMovesEveryReaderThatDidNotPass(t *testing.T) {
|
||||||
|
s := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||||
|
s.r.inputs.machines = func(string, string) []string { return []string{"ace", "g14"} }
|
||||||
|
var mu sync.Mutex
|
||||||
|
fixed := false
|
||||||
|
s.verdict = func(node string) (composer.Machine, bool) {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
m := composer.Machine{Composes: true}
|
||||||
|
m.Blamed = []struct {
|
||||||
|
Module string `json:"module"`
|
||||||
|
Problem string `json:"problem"`
|
||||||
|
}{}
|
||||||
|
if node == "g14" && !fixed {
|
||||||
|
m.Composes, m.Reason = false, "two modules own one path"
|
||||||
|
m.Blamed = append(m.Blamed, struct {
|
||||||
|
Module string `json:"module"`
|
||||||
|
Problem string `json:"problem"`
|
||||||
|
}{"a", "/etc/x"}, struct {
|
||||||
|
Module string `json:"module"`
|
||||||
|
Problem string `json:"problem"`
|
||||||
|
}{"d", "/etc/x"})
|
||||||
|
}
|
||||||
|
return m, true
|
||||||
|
}
|
||||||
|
ends := make(chan meshwants.StepEnded, 16)
|
||||||
|
msgIDs := map[string]string{} // the message id of each step's latest end
|
||||||
|
steps := &compositionSteps{node: "n1", now: time.Now, logf: t.Logf, run: s.r.run, resume: s.r.resume, ended: s.runs.stepEnded,
|
||||||
|
say: func(event string, body any, msgID string) error {
|
||||||
|
if e, ok := body.(meshwants.StepEnded); ok {
|
||||||
|
mu.Lock()
|
||||||
|
msgIDs[e.ID] = msgID
|
||||||
|
mu.Unlock()
|
||||||
|
ends <- e
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}}
|
||||||
|
move := steps.move(context.Background())
|
||||||
|
s.runs.moved.Store(&move)
|
||||||
|
step := func(m string, rerun bool) []byte {
|
||||||
|
raw, _ := json.Marshal(meshwants.StepRun{Pipeline: "main.7." + m, Module: m, Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition, Rerun: rerun, By: map[bool]string{true: "op@n1"}[rerun]})
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
got := map[string]meshwants.StepEnded{}
|
||||||
|
for _, m := range []string{"a", "b", "d"} {
|
||||||
|
steps.take(context.Background(), "ask-"+m, step(m, false))
|
||||||
|
e := <-ends
|
||||||
|
got[e.Module] = e
|
||||||
|
}
|
||||||
|
if got["a"].Outcome != meshwants.StepEndedOutcomeFailed || got["d"].Outcome != meshwants.StepEndedOutcomeFailed || got["b"].Outcome != meshwants.StepEndedOutcomePassed {
|
||||||
|
t.Fatalf("the first ends: %+v", got)
|
||||||
|
}
|
||||||
|
former := got["d"].Shared[1].Ask
|
||||||
|
mu.Lock()
|
||||||
|
fixed = true
|
||||||
|
mu.Unlock()
|
||||||
|
steps.take(context.Background(), "ask-a2", step("a", true))
|
||||||
|
moved := map[string]meshwants.StepEnded{}
|
||||||
|
for range 2 {
|
||||||
|
select {
|
||||||
|
case e := <-ends:
|
||||||
|
moved[e.ID] = e
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
t.Fatalf("the ends after the rerun: %+v", moved)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a, d := moved["ask-a2"], moved["ask-d"]
|
||||||
|
if a.Outcome != meshwants.StepEndedOutcomePassed || d.Outcome != meshwants.StepEndedOutcomePassed || !d.Rerun || d.By != "op@n1" ||
|
||||||
|
len(d.Shared) != 2 || d.Shared[1].Machine != "g14" || d.Shared[1].Ask == former || d.Shared[1].Ask != a.Shared[1].Ask {
|
||||||
|
t.Fatalf("after the rerun: a %+v, d %+v", a, d)
|
||||||
|
}
|
||||||
|
mu.Lock()
|
||||||
|
// A-470q: the first end keeps the ask's id; the end said again names the moved run's ask, so the bus does not drop it.
|
||||||
|
if msgIDs["ask-a2"] != "ask-a2" || msgIDs["ask-d"] != "ask-d."+a.Shared[1].Ask || msgIDs["ask-b"] != "ask-b" {
|
||||||
|
t.Errorf("the message ids of the ends: %v", msgIDs)
|
||||||
|
}
|
||||||
|
mu.Unlock()
|
||||||
|
if s.puts != 3 {
|
||||||
|
t.Errorf("%d run asks, want one more for the machine a did not pass", s.puts)
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case e := <-ends:
|
||||||
|
t.Errorf("a reader that passed moved: %+v", e)
|
||||||
|
case <-time.After(50 * time.Millisecond):
|
||||||
|
}
|
||||||
|
run, _, _, _ := s.runs.read(runKeyOf("main.7", "g14"))
|
||||||
|
marks := map[string]bool{}
|
||||||
|
for _, c := range run.Readers {
|
||||||
|
marks[c.ID] = c.Rerun
|
||||||
|
}
|
||||||
|
if len(run.Readers) != 3 || !marks["ask-d"] || marks["ask-b"] || !marks["ask-a2"] {
|
||||||
|
t.Errorf("the new run's readers %+v", run.Readers)
|
||||||
|
}
|
||||||
|
// A-470m: each reader's `ended` is written once its step said its end, and ask-b's carried into the new run.
|
||||||
|
deadline := time.After(5 * time.Second)
|
||||||
|
for {
|
||||||
|
wake := s.runs.wake()
|
||||||
|
run, _, _, _ = s.runs.read(runKeyOf("main.7", "g14"))
|
||||||
|
if !slices.ContainsFunc(run.Readers, func(c meshwants.CompositionReader) bool { return c.Ended == nil }) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-wake:
|
||||||
|
case <-deadline:
|
||||||
|
t.Fatalf("a reader of the new run names no end: %+v", run.Readers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,896 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The composition runs (design 47 G §718, §719; A-468, A-469d, A-469w, A-469x): the assigner composes each machine once per
|
||||||
|
// candidate, whatever number of composition steps name it. Each run is one key of its old state `composition-runs`,
|
||||||
|
// `<candidate key>.<machine>`, each part escaped as a key's name; the step that starts a run writes the key create-only,
|
||||||
|
// so two steps of one candidate starting at once start one run and the second reads it. A reader is the composition step's
|
||||||
|
// StepRun with its ask's id (A-468), added and removed by compare-and-set. A key is deleted once composition-runs-kept has
|
||||||
|
// passed since its `ended`, judged at each new run over at most 20 of the oldest ended keys, as the state inputs is
|
||||||
|
// (A-465b, A-468b); at the cap (composition-runs-cap-mib, the manifest's max-mib its ceiling, A-469d) no run is started.
|
||||||
|
|
||||||
|
const (
|
||||||
|
// runsSwept is how many of the oldest ended keys each new run judges.
|
||||||
|
runsSwept = 20
|
||||||
|
// runBoundPrefix and runUntakenPrefix open a run's two bound keys, each with its own time to live (§720, A-468b,
|
||||||
|
// A-470): `bound.<run key>` from the ask's ask-taken, `untaken.<run key>` from the run's start.
|
||||||
|
runBoundPrefix = "bound."
|
||||||
|
runUntakenPrefix = "untaken."
|
||||||
|
)
|
||||||
|
|
||||||
|
// runKeyOf is the key of a candidate's composition run of a machine (§719).
|
||||||
|
func runKeyOf(candidate, machine string) string {
|
||||||
|
return keysPart(candidate) + "." + keys.EscapeName(machine)
|
||||||
|
}
|
||||||
|
|
||||||
|
// keysPart is a name as a key's part.
|
||||||
|
func keysPart(name string) string { return keys.EscapeName(name) }
|
||||||
|
|
||||||
|
// isRunKey is whether a key of the state is a run's own, not one of its bound keys.
|
||||||
|
func isRunKey(key string) bool {
|
||||||
|
return !strings.HasPrefix(key, runBoundPrefix) && !strings.HasPrefix(key, runUntakenPrefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
// runSettings are the settings of the composition runs, each read at the start from the file the manifest declares.
|
||||||
|
type runSettings struct {
|
||||||
|
// capBytes is composition-runs-cap-mib in bytes.
|
||||||
|
capBytes int64
|
||||||
|
// kept is composition-runs-kept, stepBound composition-step-bound, untaken run-untaken-bound (A-469x).
|
||||||
|
kept, stepBound, untaken time.Duration
|
||||||
|
// blameTries is blame-tries, carried in each run's request (§721).
|
||||||
|
blameTries int
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaultRunSettings are the settings' defaults, as the manifest gives them.
|
||||||
|
var defaultRunSettings = runSettings{capBytes: 16 << 20, kept: 24 * time.Hour, stepBound: 30 * time.Minute, untaken: 24 * time.Hour, blameTries: 20}
|
||||||
|
|
||||||
|
// runSettingsOf reads the settings composition-runs-cap-mib, composition-runs-kept, composition-step-bound,
|
||||||
|
// run-untaken-bound and blame-tries from the files the environment names (A-469x, as outsideSettings): a missing or empty
|
||||||
|
// file is its default; a content that is no positive whole number or Go duration is an error naming the file.
|
||||||
|
func runSettingsOf(getenv func(string) string) (runSettings, error) {
|
||||||
|
s := defaultRunSettings
|
||||||
|
mib, err := settingFile(getenv("MESH_ASSIGNER_COMPOSITION_RUNS_CAP_MIB_FILE"))
|
||||||
|
if err != nil {
|
||||||
|
return s, err
|
||||||
|
}
|
||||||
|
if mib > 0 {
|
||||||
|
s.capBytes = int64(mib) << 20
|
||||||
|
}
|
||||||
|
tries, err := settingFile(getenv("MESH_ASSIGNER_BLAME_TRIES_FILE"))
|
||||||
|
if err != nil {
|
||||||
|
return s, err
|
||||||
|
}
|
||||||
|
if tries > 0 {
|
||||||
|
s.blameTries = tries
|
||||||
|
}
|
||||||
|
for env, to := range map[string]*time.Duration{"MESH_ASSIGNER_COMPOSITION_RUNS_KEPT_FILE": &s.kept,
|
||||||
|
"MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": &s.stepBound, "MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": &s.untaken} {
|
||||||
|
d, err := durationFile(getenv(env))
|
||||||
|
if err != nil {
|
||||||
|
return s, err
|
||||||
|
}
|
||||||
|
if d > 0 {
|
||||||
|
*to = d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// durationFile reads one setting's file holding a Go duration: 0 for no path, no file or an empty one.
|
||||||
|
func durationFile(path string) (time.Duration, error) {
|
||||||
|
if path == "" {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
raw, err := os.ReadFile(path)
|
||||||
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
v := strings.TrimSpace(string(raw))
|
||||||
|
if v == "" {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
d, err := time.ParseDuration(v)
|
||||||
|
if err != nil || d <= 0 {
|
||||||
|
return 0, fmt.Errorf("%s holds %q, which is not a positive Go duration such as 30m", path, v)
|
||||||
|
}
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// errRunChanged is a compare-and-set of a run's key that met another write.
|
||||||
|
var errRunChanged = errors.New("the composition run's key changed")
|
||||||
|
|
||||||
|
// runsKV is the state composition-runs: the bus bucket, or a test's.
|
||||||
|
type runsKV interface {
|
||||||
|
// get is a key's value and revision; nil for a key not there.
|
||||||
|
get(key string) ([]byte, uint64, error)
|
||||||
|
// create writes a key that does not stand, update one at its revision: errRunChanged when it does not stand so.
|
||||||
|
create(key string, value []byte) (uint64, error)
|
||||||
|
update(key string, value []byte, revision uint64) (uint64, error)
|
||||||
|
// delAt deletes a key at its revision: errRunChanged when it no longer stands so, nothing for a key not there. No write
|
||||||
|
// of the state is made from a value read before its latest change.
|
||||||
|
delAt(key string, revision uint64) error
|
||||||
|
keys() ([]string, error)
|
||||||
|
// arm writes a bound key afresh holding the ask of the run it bounds, with its own time to live (§720, A-470n): at the key's
|
||||||
|
// latest revision, a delete marker counted, read again when another write came between; its expiry is the bus's event. It
|
||||||
|
// answers the revision written.
|
||||||
|
arm(key, ask string, ttl time.Duration) (uint64, error)
|
||||||
|
// used is how many bytes the state holds.
|
||||||
|
used() (int64, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// busRuns is runsKV over the bus bucket.
|
||||||
|
type busRuns struct {
|
||||||
|
ctx context.Context
|
||||||
|
js jetstream.JetStream
|
||||||
|
kv jetstream.KeyValue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b busRuns) get(key string) ([]byte, uint64, error) {
|
||||||
|
e, err := b.kv.Get(b.ctx, key)
|
||||||
|
if errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||||
|
return nil, 0, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
return e.Value(), e.Revision(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b busRuns) create(key string, value []byte) (uint64, error) {
|
||||||
|
rev, err := b.kv.Create(b.ctx, key, value)
|
||||||
|
if errors.Is(err, jetstream.ErrKeyExists) {
|
||||||
|
return 0, errRunChanged
|
||||||
|
}
|
||||||
|
return rev, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b busRuns) update(key string, value []byte, revision uint64) (uint64, error) {
|
||||||
|
rev, err := b.kv.Update(b.ctx, key, value, revision)
|
||||||
|
if errors.Is(err, jetstream.ErrKeyExists) || errors.Is(err, jetstream.ErrKeyRevisionMismatch) {
|
||||||
|
return 0, errRunChanged
|
||||||
|
}
|
||||||
|
return rev, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b busRuns) delAt(key string, revision uint64) error {
|
||||||
|
err := b.kv.Delete(b.ctx, key, jetstream.LastRevision(revision))
|
||||||
|
if errors.Is(err, jetstream.ErrKeyExists) || errors.Is(err, jetstream.ErrKeyRevisionMismatch) {
|
||||||
|
return errRunChanged
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b busRuns) keys() ([]string, error) {
|
||||||
|
l, err := b.kv.ListKeys(b.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var out []string
|
||||||
|
for k := range l.Keys() {
|
||||||
|
out = append(out, k)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// boundValue is a bound key's value: the key and the ask of the run it bounds (A-470n).
|
||||||
|
type boundValue struct {
|
||||||
|
Bound string `json:"bound"`
|
||||||
|
Ask string `json:"ask"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// arm publishes the bound key holding ask with ttl as its own time to live, expecting the key's latest message (a delete
|
||||||
|
// marker counted), so a write between is read again and never overwritten unseen (A-470n); the earlier message, replaced,
|
||||||
|
// takes its time to live with it, so the expiry is heard only ttl after the last write.
|
||||||
|
func (b busRuns) arm(key, ask string, ttl time.Duration) (uint64, error) {
|
||||||
|
if b.js == nil {
|
||||||
|
return 0, errors.New("no bus to arm a bound on")
|
||||||
|
}
|
||||||
|
raw, err := json.Marshal(boundValue{Bound: key, Ask: ask})
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
subject := "$KV." + b.kv.Bucket() + "." + key
|
||||||
|
for {
|
||||||
|
st, err := b.js.Stream(b.ctx, "KV_"+b.kv.Bucket())
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
var last uint64
|
||||||
|
m, err := st.GetLastMsgForSubject(b.ctx, subject)
|
||||||
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
last = m.Sequence
|
||||||
|
case !errors.Is(err, jetstream.ErrMsgNotFound):
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
ack, err := b.js.Publish(b.ctx, subject, raw, jetstream.WithMsgTTL(ttl), jetstream.WithExpectLastSequencePerSubject(last))
|
||||||
|
if err != nil && strings.Contains(err.Error(), "wrong last sequence") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return ack.Sequence, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b busRuns) used() (int64, error) {
|
||||||
|
st, err := b.kv.Status(b.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return int64(st.Bytes()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// compositionRuns keeps the composition runs in the state composition-runs.
|
||||||
|
type compositionRuns struct {
|
||||||
|
kv runsKV
|
||||||
|
set runSettings
|
||||||
|
now func() time.Time
|
||||||
|
logf func(string, ...any)
|
||||||
|
mu sync.Mutex
|
||||||
|
// changed is closed and replaced at each change of the state heard (heard): a step waiting on a run reads its key again.
|
||||||
|
changed chan struct{}
|
||||||
|
// seen are the keys the state's watch handed and has not seen deleted: a listing of the bucket misses a key that is
|
||||||
|
// being written at that moment, so every lookup takes these beside it (keys).
|
||||||
|
seen map[string]bool
|
||||||
|
// say says an event of the seat mesh-wants (a reader's wait, A-469y); drop asks the build seat's drop of a run ask (§119);
|
||||||
|
// nil says or drops nothing.
|
||||||
|
say publisher
|
||||||
|
drop func(ask, why string) error
|
||||||
|
// moved is told each run that ended, for the readers a rerun carried to say their end again (compositionSteps.move).
|
||||||
|
// Set once the steps are served, after the hub starts.
|
||||||
|
moved atomic.Pointer[func(run meshwants.CompositionRun)]
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCompositionRuns(kv runsKV, set runSettings, now func() time.Time, logf func(string, ...any)) *compositionRuns {
|
||||||
|
return &compositionRuns{kv: kv, set: set, now: now, logf: logf, changed: make(chan struct{})}
|
||||||
|
}
|
||||||
|
|
||||||
|
// heard takes a change of the state from its watch (a module watches its own state, principle 1).
|
||||||
|
func (r *compositionRuns) heard() {
|
||||||
|
r.mu.Lock()
|
||||||
|
close(r.changed)
|
||||||
|
r.changed = make(chan struct{})
|
||||||
|
r.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// saw keeps a key the state's watch handed: standing, or deleted or expired.
|
||||||
|
func (r *compositionRuns) saw(key string, standing bool) {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
if r.seen == nil {
|
||||||
|
r.seen = map[string]bool{}
|
||||||
|
}
|
||||||
|
if standing {
|
||||||
|
r.seen[key] = true
|
||||||
|
} else {
|
||||||
|
delete(r.seen, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// keys are the state's keys: the bucket's listing with the keys its watch handed beside it, sorted. A key read gone later
|
||||||
|
// is skipped by its reader.
|
||||||
|
func (r *compositionRuns) keys() ([]string, error) {
|
||||||
|
all, err := r.kv.keys()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r.mu.Lock()
|
||||||
|
for key := range r.seen {
|
||||||
|
all = append(all, key)
|
||||||
|
}
|
||||||
|
r.mu.Unlock()
|
||||||
|
slices.Sort(all)
|
||||||
|
return slices.Compact(all), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// wake is closed at the next change heard.
|
||||||
|
func (r *compositionRuns) wake() <-chan struct{} {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
return r.changed
|
||||||
|
}
|
||||||
|
|
||||||
|
// read is a run's value and revision, or false.
|
||||||
|
func (r *compositionRuns) read(key string) (meshwants.CompositionRun, uint64, bool, error) {
|
||||||
|
raw, rev, err := r.kv.get(key)
|
||||||
|
if err != nil || raw == nil {
|
||||||
|
return meshwants.CompositionRun{}, 0, false, err
|
||||||
|
}
|
||||||
|
var run meshwants.CompositionRun
|
||||||
|
if err := json.Unmarshal(raw, &run); err != nil {
|
||||||
|
return meshwants.CompositionRun{}, 0, false, fmt.Errorf("the composition run %s does not read: %w", key, err)
|
||||||
|
}
|
||||||
|
return run, rev, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// change writes a run's key by compare-and-set: f changes the value read and says whether to write it; false leaves it.
|
||||||
|
// It answers the value written or left, and false for a key not there.
|
||||||
|
func (r *compositionRuns) change(key string, f func(*meshwants.CompositionRun) bool) (meshwants.CompositionRun, bool, error) {
|
||||||
|
for {
|
||||||
|
run, rev, ok, err := r.read(key)
|
||||||
|
if err != nil || !ok {
|
||||||
|
return run, ok, err
|
||||||
|
}
|
||||||
|
if !f(&run) {
|
||||||
|
return run, true, nil
|
||||||
|
}
|
||||||
|
raw, err := json.Marshal(run)
|
||||||
|
if err != nil {
|
||||||
|
return run, true, err
|
||||||
|
}
|
||||||
|
if _, err := r.kv.update(key, raw, rev); errors.Is(err, errRunChanged) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
return run, true, err
|
||||||
|
}
|
||||||
|
r.heard()
|
||||||
|
return run, true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill is the state's fill against its cap.
|
||||||
|
func (r *compositionRuns) fill() (meshwants.Fill, error) {
|
||||||
|
at := r.now().UTC()
|
||||||
|
used, err := r.kv.used()
|
||||||
|
return meshwants.Fill{Store: buckets.CompositionRunsState, Bytes: used, Cap: r.set.capBytes, At: &at}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// joined is a reader's place in a run: the run's key, whether this reader started it (so it composes the machine), and the
|
||||||
|
// value as it stood.
|
||||||
|
type joined struct {
|
||||||
|
key string
|
||||||
|
started bool
|
||||||
|
run meshwants.CompositionRun
|
||||||
|
}
|
||||||
|
|
||||||
|
// join finds or starts the candidate's run of the machine for reader (§718, §719, §720): a run that stands and has not
|
||||||
|
// ended, or that ended other than could not run, is read, the reader added; none, or one that could not run, is started:
|
||||||
|
// written create-only (or replacing the ended key by compare-and-set), the reader its first, ask its run ask's id. At the
|
||||||
|
// cap no run is started, an error naming the fill.
|
||||||
|
func (r *compositionRuns) join(reader meshwants.CompositionReader, candidate, machine, ask string) (joined, error) {
|
||||||
|
key := runKeyOf(candidate, machine)
|
||||||
|
for {
|
||||||
|
run, rev, ok, err := r.read(key)
|
||||||
|
if err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
if ok && (run.Ended == nil || run.Outcome != meshwants.CompositionRunOutcomeCouldNotRun) {
|
||||||
|
if hasReader(run.Readers, reader.ID) {
|
||||||
|
return joined{key: key, run: run}, nil
|
||||||
|
}
|
||||||
|
run.Readers = append(run.Readers, reader)
|
||||||
|
raw, err := json.Marshal(run)
|
||||||
|
if err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
if _, err := r.kv.update(key, raw, rev); errors.Is(err, errRunChanged) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
r.heard()
|
||||||
|
if run.Ended == nil && r.untaken(key, run.Ask) {
|
||||||
|
r.sayWaits(run, []meshwants.CompositionReader{reader}, "")
|
||||||
|
}
|
||||||
|
return joined{key: key, run: run}, nil
|
||||||
|
}
|
||||||
|
if err := r.room(); err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
started := r.now().UTC()
|
||||||
|
fresh := meshwants.CompositionRun{Candidate: candidate, Machine: machine, Ask: ask, Started: &started,
|
||||||
|
Readers: []meshwants.CompositionReader{reader}}
|
||||||
|
raw, err := json.Marshal(fresh)
|
||||||
|
if err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
_, err = r.kv.update(key, raw, rev) // could not run is never read: a new run replaces it (§720)
|
||||||
|
} else {
|
||||||
|
_, err = r.kv.create(key, raw)
|
||||||
|
}
|
||||||
|
if errors.Is(err, errRunChanged) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
r.heard()
|
||||||
|
// An ask waiting in the queue has no clock but run-untaken-bound from its start (A-466s, A-468b, A-470, A-470n).
|
||||||
|
if _, err := r.armBound(runUntakenPrefix, key, ask, r.set.untaken); err != nil {
|
||||||
|
r.logf("the untaken bound of the composition run %s is not armed: %v", key, err)
|
||||||
|
}
|
||||||
|
r.sayWaits(fresh, fresh.Readers, "")
|
||||||
|
return joined{key: key, started: true, run: fresh}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// room sweeps the state and says whether a new run may start: an error naming the fill at the cap (as A-465a).
|
||||||
|
func (r *compositionRuns) room() error {
|
||||||
|
if err := r.sweep(); err != nil {
|
||||||
|
r.logf("composition-runs: the keys past composition-runs-kept are not all deleted: %v", err)
|
||||||
|
}
|
||||||
|
f, err := r.fill()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("the fill of the state %s is not read, so no composition run is started: %w", buckets.CompositionRunsState, err)
|
||||||
|
}
|
||||||
|
if f.Bytes >= f.Cap {
|
||||||
|
return fmt.Errorf("the state %s is at its cap of %d MiB (%d bytes kept), so no composition run is started", buckets.CompositionRunsState,
|
||||||
|
f.Cap>>20, f.Bytes)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// sweep deletes, among the 20 oldest ended runs, those ended more than composition-runs-kept ago, with their bound keys.
|
||||||
|
func (r *compositionRuns) sweep() error {
|
||||||
|
all, err := r.keys()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
type endedAt struct {
|
||||||
|
key string
|
||||||
|
at time.Time
|
||||||
|
}
|
||||||
|
var ended []endedAt
|
||||||
|
for _, key := range all {
|
||||||
|
if !isRunKey(key) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
run, _, ok, err := r.read(key)
|
||||||
|
if err != nil || !ok || run.Ended == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ended = append(ended, endedAt{key, *run.Ended})
|
||||||
|
}
|
||||||
|
slices.SortFunc(ended, func(a, b endedAt) int { return a.at.Compare(b.at) })
|
||||||
|
if len(ended) > runsSwept {
|
||||||
|
ended = ended[:runsSwept]
|
||||||
|
}
|
||||||
|
var errs []error
|
||||||
|
for _, e := range ended {
|
||||||
|
if r.now().Sub(e.at) >= r.set.kept {
|
||||||
|
errs = append(errs, r.deleteRun(e.key, func(run meshwants.CompositionRun) bool {
|
||||||
|
return run.Ended != nil && r.now().Sub(*run.Ended) >= r.set.kept
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors.Join(errs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// deleteRun deletes a run's key with its bound keys while the value it holds is still one gone judges gone, each delete at the
|
||||||
|
// revision just read and judged again on a conflict: a run that replaced the key meanwhile, and its bounds, stand.
|
||||||
|
func (r *compositionRuns) deleteRun(key string, gone func(meshwants.CompositionRun) bool) error {
|
||||||
|
for {
|
||||||
|
run, rev, ok, err := r.read(key)
|
||||||
|
if err != nil || !ok || !gone(run) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := r.clearBounds(key, run.Ask, runBoundPrefix, runUntakenPrefix); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := r.kv.delAt(key, rev); errors.Is(err, errRunChanged) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.heard()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clearBounds deletes the bound keys of the run of ask while key holds that run (or none) and the bound holds that ask: each at
|
||||||
|
// the revision it was read at, read again on a conflict, so a bound a newer run of the key armed is never deleted.
|
||||||
|
func (r *compositionRuns) clearBounds(key, ask string, prefixes ...string) error {
|
||||||
|
var errs []error
|
||||||
|
for _, prefix := range prefixes {
|
||||||
|
for {
|
||||||
|
run, _, ok, err := r.read(key)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if ok && run.Ask != ask {
|
||||||
|
break // a newer run holds the key: its bounds are its own
|
||||||
|
}
|
||||||
|
held, rev, standing, err := r.boundOf(prefix + key)
|
||||||
|
if err != nil || !standing {
|
||||||
|
errs = append(errs, err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if held != ask {
|
||||||
|
break // the bound of another ask (A-470n): not this run's to delete
|
||||||
|
}
|
||||||
|
if err := r.kv.delAt(prefix+key, rev); errors.Is(err, errRunChanged) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors.Join(errs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// stepEnded writes at as the `ended` of the reader asked under id in each run of its step's candidate naming it, by
|
||||||
|
// compare-and-set (A-470m): the time its step said its end, carried with it into a rerun's run.
|
||||||
|
func (r *compositionRuns) stepEnded(id string, step meshwants.StepRun, at time.Time) {
|
||||||
|
candidate, err := candidateKeyOf(step)
|
||||||
|
if err != nil {
|
||||||
|
r.logf("the end of the composition step %s is not written on its runs: %v", id, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
keys, err := r.keysOf(candidate, id)
|
||||||
|
if err != nil {
|
||||||
|
r.logf("the end of the composition step %s is not written on its runs: %v", id, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
at = at.UTC()
|
||||||
|
for _, key := range keys {
|
||||||
|
if _, _, err := r.change(key, func(c *meshwants.CompositionRun) bool {
|
||||||
|
i := slices.IndexFunc(c.Readers, func(c meshwants.CompositionReader) bool { return c.ID == id })
|
||||||
|
if i < 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
c.Readers[i].Ended = &at
|
||||||
|
return true
|
||||||
|
}); err != nil {
|
||||||
|
r.logf("the end of the composition step %s is not written on the composition run %s: %v", id, key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hasReader is whether readers holds the step asked under id.
|
||||||
|
func hasReader(readers []meshwants.CompositionReader, id string) bool {
|
||||||
|
return slices.ContainsFunc(readers, func(c meshwants.CompositionReader) bool { return c.ID == id })
|
||||||
|
}
|
||||||
|
|
||||||
|
// readerOf is a composition step as a run's reader: its StepRun with its ask's id (A-468).
|
||||||
|
func readerOf(id string, s meshwants.StepRun) meshwants.CompositionReader {
|
||||||
|
return meshwants.CompositionReader{ID: id, Pipeline: s.Pipeline, Step: s.Step, Module: s.Module, Branch: s.Branch, Commit: s.Commit,
|
||||||
|
Revision: s.Revision, Source: s.Source, Fingerprint: s.Fingerprint, Run: s.Run, Rerun: s.Rerun, By: s.By}
|
||||||
|
}
|
||||||
|
|
||||||
|
// stepRunOf is a reader's StepRun again, for its step-ended.
|
||||||
|
func stepRunOf(c meshwants.CompositionReader) meshwants.StepRun {
|
||||||
|
return meshwants.StepRun{Pipeline: c.Pipeline, Step: c.Step, Module: c.Module, Branch: c.Branch, Commit: c.Commit, Revision: c.Revision,
|
||||||
|
Source: c.Source, Fingerprint: c.Fingerprint, Run: c.Run, Rerun: c.Rerun, By: c.By}
|
||||||
|
}
|
||||||
|
|
||||||
|
// watchRuns hears the changes of the state composition-runs (principle 1): each change wakes the steps waiting on a run, and
|
||||||
|
// the expiry of a bound key, the bus's marker, is handed to expired (§720). After the values that stand, ready is called.
|
||||||
|
func watchRuns(ctx context.Context, kv jetstream.KeyValue, r *compositionRuns, expired func(key string), ready func()) error {
|
||||||
|
w, err := kv.WatchAll(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
defer func() { _ = w.Stop() }()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case e, ok := <-w.Updates():
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if e == nil {
|
||||||
|
if ready != nil {
|
||||||
|
ready()
|
||||||
|
ready = nil
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
r.saw(e.Key(), e.Operation() == jetstream.KeyValuePut)
|
||||||
|
if e.Operation() == jetstream.KeyValuePurge && !isRunKey(e.Key()) && expired != nil {
|
||||||
|
expired(e.Key())
|
||||||
|
}
|
||||||
|
r.heard()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// end ends the run of ask in its key with an outcome, its words and the machine's verdict, by compare-and-set; it answers
|
||||||
|
// false when the key holds another run or the run has ended already.
|
||||||
|
func (r *compositionRuns) end(key, ask, outcome, said string, verdict map[string]any) (bool, error) {
|
||||||
|
ended := false
|
||||||
|
_, _, err := r.change(key, func(c *meshwants.CompositionRun) bool {
|
||||||
|
if c.Ask != ask || c.Ended != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
at := r.now().UTC()
|
||||||
|
c.Ended, c.Outcome, c.Said, c.Verdict = &at, outcome, said, verdict
|
||||||
|
ended = true
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return ended, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// keyOfAsk is the key of the run whose ask is ask, or none.
|
||||||
|
func (r *compositionRuns) keyOfAsk(ask string) (string, meshwants.CompositionRun, error) {
|
||||||
|
all, err := r.keys()
|
||||||
|
if err != nil {
|
||||||
|
return "", meshwants.CompositionRun{}, err
|
||||||
|
}
|
||||||
|
for _, key := range all {
|
||||||
|
if !isRunKey(key) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
run, _, ok, err := r.read(key)
|
||||||
|
if err == nil && ok && run.Ask == ask {
|
||||||
|
return key, run, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", meshwants.CompositionRun{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// heardEnd ends the run of the ask a build seat's step-ended names (§719, A-240): a run ask that ended other than passed
|
||||||
|
// could not run; a passed one's answer, read with read, is the machine's verdict, or why it is none. An end of an ask no run
|
||||||
|
// names is another asker's, or of a run gone, and changes nothing.
|
||||||
|
func (r *compositionRuns) heardEnd(e buildstep.StepEnded, read func(buildstep.StepEnded) ([]byte, error)) error {
|
||||||
|
if e.Asker != runAsker || e.Ask == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
key, run, err := r.keyOfAsk(e.Ask)
|
||||||
|
if err != nil || key == "" {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if run.Ended != nil { // ended by its bound or a drop: the end heard later is ignored (§720)
|
||||||
|
r.logf("the step-ended of the run ask %s is ignored: its composition run %s ended before it (%s)", e.Ask, key, run.Said)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
node := run.Machine
|
||||||
|
outcome, said := meshwants.CompositionRunOutcomeCouldNotRun, ""
|
||||||
|
var verdict map[string]any
|
||||||
|
if e.Outcome != buildstep.OutcomePassed {
|
||||||
|
said = fmt.Sprintf("%s: its run ask %s ended %s on %s: %s", node, e.Ask, e.Outcome, e.Node, e.Said)
|
||||||
|
} else if answer, err := read(e); err != nil { // the program's last line of standard output (A-254)
|
||||||
|
said = node + ": " + err.Error()
|
||||||
|
} else if verdict, said = runVerdict(node, answer); said == "" {
|
||||||
|
outcome = meshwants.CompositionRunOutcomePassed
|
||||||
|
}
|
||||||
|
_, err = r.endRun(key, e.Ask, outcome, said, verdict)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// await waits until each run of keys has ended, through the state's changes heard, or ctx ends: it answers each run as it
|
||||||
|
// stands then; a key gone could not run.
|
||||||
|
func (r *compositionRuns) await(ctx context.Context, keys []string) map[string]meshwants.CompositionRun {
|
||||||
|
out := map[string]meshwants.CompositionRun{}
|
||||||
|
for {
|
||||||
|
wake := r.wake()
|
||||||
|
open := false
|
||||||
|
for _, key := range keys {
|
||||||
|
run, _, ok, err := r.read(key)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
open = true
|
||||||
|
continue
|
||||||
|
case !ok:
|
||||||
|
at := r.now().UTC()
|
||||||
|
candidate, machine, _ := strings.Cut(key, ".")
|
||||||
|
run = meshwants.CompositionRun{Candidate: unescape(candidate), Machine: unescape(machine), Ended: &at,
|
||||||
|
Outcome: meshwants.CompositionRunOutcomeCouldNotRun, Said: unescape(machine) + ": its composition run " + key + " is gone"}
|
||||||
|
case run.Ended == nil:
|
||||||
|
open = true
|
||||||
|
}
|
||||||
|
out[key] = run
|
||||||
|
}
|
||||||
|
if !open {
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return out
|
||||||
|
case <-wake:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unescape is a key's part as a name again; a part that does not read stays as it is.
|
||||||
|
func unescape(part string) string {
|
||||||
|
if name, err := keys.UnescapeName(part); err == nil {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
return part
|
||||||
|
}
|
||||||
|
|
||||||
|
// sharedOf names per machine the runs of keys and their asks (§729): from runs where given, else as each key stands.
|
||||||
|
func (r *compositionRuns) sharedOf(keys []string, runs map[string]meshwants.CompositionRun) []meshwants.Shared {
|
||||||
|
out := []meshwants.Shared{}
|
||||||
|
for _, key := range keys {
|
||||||
|
run, ok := runs[key]
|
||||||
|
if !ok {
|
||||||
|
if run, _, ok, _ = r.read(key); !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out = append(out, meshwants.Shared{Machine: run.Machine, Run: key, Ask: run.Ask})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// leave removes the composition steps of a superseded or cancelled pipeline from every run's readers (§723, A-469n), and answers
|
||||||
|
// their asks' ids, each told to stop before a run is ended; a running run left with no reader has its ask dropped and ends could not run, "no reader is left" (A-469z),
|
||||||
|
// so a later step of the candidate starts a new run. A run other readers read goes on for them.
|
||||||
|
func (r *compositionRuns) leave(pipeline string, stop func(ids []string)) ([]string, error) {
|
||||||
|
all, err := r.keys()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var ids []string
|
||||||
|
var errs []error
|
||||||
|
for _, key := range all {
|
||||||
|
if !isRunKey(key) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var left []string
|
||||||
|
var leaving []meshwants.CompositionReader
|
||||||
|
run, ok, err := r.change(key, func(c *meshwants.CompositionRun) bool {
|
||||||
|
left, leaving = nil, nil
|
||||||
|
keep := c.Readers[:0:0]
|
||||||
|
for _, reader := range c.Readers {
|
||||||
|
if reader.Pipeline == pipeline && reader.Step == meshwants.CompositionReaderStepComposition {
|
||||||
|
left = append(left, reader.ID)
|
||||||
|
leaving = append(leaving, reader)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
keep = append(keep, reader)
|
||||||
|
}
|
||||||
|
c.Readers = keep
|
||||||
|
return len(left) > 0
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !ok || len(left) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ids = append(ids, left...)
|
||||||
|
if run.Ended == nil && r.untaken(key, run.Ask) { // a reader leaving a run not yet taken: its wait ends at once (A-470u)
|
||||||
|
r.sayWaits(run, leaving, "superseded")
|
||||||
|
}
|
||||||
|
if stop != nil {
|
||||||
|
stop(left) // the steps that left say no end, the run's included
|
||||||
|
}
|
||||||
|
if run.Ended != nil || len(run.Readers) > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
why := "no reader is left: the pipeline " + pipeline + " is superseded or cancelled"
|
||||||
|
if r.drop != nil {
|
||||||
|
if err := r.drop(run.Ask, why); err != nil {
|
||||||
|
r.logf("the drop of the run ask %s of the composition run %s is not answered: %v", run.Ask, key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := r.endRun(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, run.Machine+": "+why, nil); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ids, errors.Join(errs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// passedOn is whether the step of module passed on the machine of an ended run (§722): neither failed nor could not run there.
|
||||||
|
func passedOn(module string, run meshwants.CompositionRun) bool {
|
||||||
|
e := judgeRun(module, run)
|
||||||
|
return e.failed == "" && e.couldNot == ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// formerOf is the place in readers of a step's former ask: the reader of the same pipeline's composition step, or -1.
|
||||||
|
func formerOf(readers []meshwants.CompositionReader, pipeline string) int {
|
||||||
|
return slices.IndexFunc(readers, func(c meshwants.CompositionReader) bool {
|
||||||
|
return c.Pipeline == pipeline && c.Step == meshwants.CompositionReaderStepComposition
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// rejoin is join for a step asked again (§727, A-468g, A-470d): on a machine whose ended run it passed it keeps that verdict,
|
||||||
|
// reading the run under its new ask; a running run it joins; an ended run it did not read and that could run it reads, as one
|
||||||
|
// started after its last end; otherwise it starts a new run, replacing the ended key by compare-and-set and carrying every former
|
||||||
|
// reader into the new value: each that did not pass on the former run marked `rerun` with by the rerun's caller, each that passed
|
||||||
|
// not (A-470d).
|
||||||
|
func (r *compositionRuns) rejoin(reader meshwants.CompositionReader, candidate, machine, ask string) (joined, error) {
|
||||||
|
key := runKeyOf(candidate, machine)
|
||||||
|
for {
|
||||||
|
run, rev, ok, err := r.read(key)
|
||||||
|
if err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return r.join(reader, candidate, machine, ask)
|
||||||
|
}
|
||||||
|
at := formerOf(run.Readers, reader.Pipeline)
|
||||||
|
ended := run.Ended != nil
|
||||||
|
keep := ended && at >= 0 && passedOn(reader.Module, run)
|
||||||
|
read := !ended || (at < 0 && run.Outcome != meshwants.CompositionRunOutcomeCouldNotRun)
|
||||||
|
if keep || read {
|
||||||
|
if at >= 0 && run.Readers[at].ID == reader.ID {
|
||||||
|
return joined{key: key, run: run}, nil
|
||||||
|
}
|
||||||
|
var former []meshwants.CompositionReader
|
||||||
|
if at >= 0 {
|
||||||
|
former = []meshwants.CompositionReader{run.Readers[at]}
|
||||||
|
run.Readers[at] = reader
|
||||||
|
} else {
|
||||||
|
run.Readers = append(run.Readers, reader)
|
||||||
|
}
|
||||||
|
if err := r.write(key, run, rev); errors.Is(err, errRunChanged) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
if run.Ended == nil && r.untaken(key, run.Ask) { // as join: a reader of a run not yet taken waits for a build node (A-469y)
|
||||||
|
r.sayWaits(run, former, "superseded") // the place it takes: that wait ends at once (A-470u)
|
||||||
|
r.sayWaits(run, []meshwants.CompositionReader{reader}, "")
|
||||||
|
}
|
||||||
|
return joined{key: key, run: run}, nil
|
||||||
|
}
|
||||||
|
if err := r.room(); err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
started := r.now().UTC()
|
||||||
|
fresh := meshwants.CompositionRun{Candidate: candidate, Machine: machine, Ask: ask, Started: &started}
|
||||||
|
for i, c := range run.Readers {
|
||||||
|
if i == at {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
c.Rerun, c.By = !passedOn(c.Module, run), ""
|
||||||
|
if c.Rerun {
|
||||||
|
c.By = reader.By
|
||||||
|
}
|
||||||
|
fresh.Readers = append(fresh.Readers, c)
|
||||||
|
}
|
||||||
|
fresh.Readers = append(fresh.Readers, reader)
|
||||||
|
if err := r.clearBounds(key, run.Ask, runBoundPrefix, runUntakenPrefix); err != nil { // the former run's bounds go with it
|
||||||
|
r.logf("the bound keys of the former composition run %s are not deleted: %v", key, err)
|
||||||
|
}
|
||||||
|
if err := r.write(key, fresh, rev); errors.Is(err, errRunChanged) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
return joined{}, err
|
||||||
|
}
|
||||||
|
if _, err := r.armBound(runUntakenPrefix, key, ask, r.set.untaken); err != nil {
|
||||||
|
r.logf("the untaken bound of the composition run %s is not armed: %v", key, err)
|
||||||
|
}
|
||||||
|
r.sayWaits(fresh, fresh.Readers, "")
|
||||||
|
return joined{key: key, started: true, run: fresh}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// write writes a run's value at its revision.
|
||||||
|
func (r *compositionRuns) write(key string, run meshwants.CompositionRun, rev uint64) error {
|
||||||
|
raw, err := json.Marshal(run)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := r.kv.update(key, raw, rev); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.heard()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
+404
@@ -0,0 +1,404 @@
|
|||||||
|
//go:build integration
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient/enginereads"
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Test 108 (design 47 G §733; §718 to §723, §727, §728; A-468 to A-470f): the assigner started whole against the bus composes
|
||||||
|
// each machine once per candidate. Two or three composition steps of one candidate on two machines make one key, one request and
|
||||||
|
// one run ask per machine, and each step reads both verdicts; a machine blaming a and b fails their steps and passes c's with a
|
||||||
|
// warning; a verdict with no `blamed` is judged as before, "the composer names no culprits", and a machine blaming none fails
|
||||||
|
// every step; a step of another candidate starts its own runs. A taken ask that keeps saying progress is not ended by the bound,
|
||||||
|
// one silent past it ends could not run with its ask dropped, a step-ended after that is ignored and journaled, and an ask never
|
||||||
|
// taken ends at run-untaken-bound; a bound holds its run's ask (A-470n). A rerun of a starts one run on the machine it did not
|
||||||
|
// pass and moves b; a superseded step leaves
|
||||||
|
// a run running for its other reader; an assigner restarted during a run takes it up by its ask; compositions-drop ends the
|
||||||
|
// readers and deletes the key; at the cap a step ends could not run, naming the fill.
|
||||||
|
func TestOneCompositionRunPerCandidateAndMachine(t *testing.T) {
|
||||||
|
b := startBed(t, "")
|
||||||
|
b.settings = map[string]string{"MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "2s", "MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": "15s", // past a restart
|
||||||
|
"MESH_ASSIGNER_COMPOSITION_RUNS_CAP_MIB_FILE": "1"}
|
||||||
|
nc, err := nats.Connect(b.srv.ClientURL())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(nc.Close)
|
||||||
|
const commit = "1111111111111111111111111111111111111111"
|
||||||
|
if _, err := b.js.CreateOrUpdateConsumer(b.ctx, "EVENTS", jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-assigner",
|
||||||
|
FilterSubjects: []string{enginereads.SubjectPrefix + "*", "mesh.mod." + buckets.IndexerModule + ".event.views.>", meshcatalog.SubjectCatalogRevisionAll,
|
||||||
|
nodebuildgo.SubjectStepEndedAll, nodebuildgo.SubjectAskTakenAll, nodebuildgo.SubjectStepProgressAll, pipelineEndedSubject},
|
||||||
|
AckPolicy: jetstream.AckExplicitPolicy, AckWait: 2 * time.Second}); err != nil { // an event handed to the stopped assigner's pull comes again soon
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, node := range []string{"n1", "n2"} {
|
||||||
|
raw, _ := json.Marshal(nodeengine.Running{V: 1, Node: node, Module: "engine", Fingerprint: "src2:e1", At: time.Now().UTC()})
|
||||||
|
if _, err := b.js.Publish(b.ctx, nodeengine.SubjectRunning(node, "engine"), raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
awaitKept(t, b, nodeengine.StreamRunning, 2)
|
||||||
|
engine := meshcatalog.CatalogEntry{Module: "engine", Fp: "src2:e1", Repository: "novox/mesh-host", Commit: commit, Path: ".",
|
||||||
|
Serves: []string{nodeengine.Seat + ".composition"}, Manifest: map[string]any{"module": "engine", "version": "0.1"}}
|
||||||
|
b.cat.mu.Lock()
|
||||||
|
b.cat.entries[trunkBranch] = map[string]meshcatalog.CatalogEntry{"engine": engine}
|
||||||
|
for _, m := range []string{"a", "b", "c"} {
|
||||||
|
b.cat.entries[trunkBranch][m] = meshcatalog.CatalogEntry{Module: m, Fp: "src2:" + m, Repository: "novox/" + m, Commit: commit, Path: ".", Manifest: map[string]any{"module": m}}
|
||||||
|
}
|
||||||
|
b.cat.rev[trunkBranch] = 3
|
||||||
|
b.cat.mu.Unlock()
|
||||||
|
for _, node := range []string{"n1", "n2"} {
|
||||||
|
for _, m := range []string{"a", "b", "c"} {
|
||||||
|
b.place(t, node, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var mu sync.Mutex
|
||||||
|
inputsAsked := map[string]int{} // by candidate and node
|
||||||
|
var drops []string
|
||||||
|
respond := func(subject string, f func(m *nats.Msg) any) {
|
||||||
|
sub, err := nc.Subscribe(subject, func(m *nats.Msg) {
|
||||||
|
raw, _ := json.Marshal(map[string]any{"result": f(m), "node": "n0"})
|
||||||
|
_ = m.Respond(raw)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||||
|
}
|
||||||
|
respond("mesh.seat.node-engine.call.compose-candidate.*.*", func(m *nats.Msg) any {
|
||||||
|
node := strings.Split(m.Subject, ".")[5]
|
||||||
|
var in nodeengine.ComposeCandidateInput
|
||||||
|
_ = json.Unmarshal(m.Data, &in)
|
||||||
|
mu.Lock()
|
||||||
|
inputsAsked[in.Candidate+" "+node]++
|
||||||
|
mu.Unlock()
|
||||||
|
return map[string]any{"candidate": in.Candidate, "node": node, "verdict": "composed", "input": map[string]any{"node": node}, "modules": []any{}, "own": map[string]any{}, "took": 1, "v": 1}
|
||||||
|
})
|
||||||
|
respond("mesh.seat.mesh-catalog.call.entry.*", func(*nats.Msg) any { return meshcatalog.EntryAnswer{Entry: engine} })
|
||||||
|
respond("mesh.seat.node-build-go.call.drop.*", func(m *nats.Msg) any {
|
||||||
|
var in nodebuildgo.DropInput
|
||||||
|
_ = json.Unmarshal(m.Data, &in)
|
||||||
|
mu.Lock()
|
||||||
|
drops = append(drops, in.ID)
|
||||||
|
mu.Unlock()
|
||||||
|
return map[string]any{}
|
||||||
|
})
|
||||||
|
respond("mesh.seat.mesh-hand-acts.call.hand-act.*", func(*nats.Msg) any { return map[string]any{"log": "hand-act-1"} })
|
||||||
|
// The ends are read from the stream through a durable consumer, as the runner hears them: an end the bus drops as a
|
||||||
|
// repeated message id is never heard (A-470q).
|
||||||
|
ended := make(chan meshwants.StepEnded, 32)
|
||||||
|
runner, err := b.js.CreateOrUpdateConsumer(b.ctx, "EVENTS", jetstream.ConsumerConfig{Durable: "runner-stand-in",
|
||||||
|
FilterSubject: "mesh.seat.mesh-wants.event.step-ended.n1", AckPolicy: jetstream.AckExplicitPolicy, DeliverPolicy: jetstream.DeliverNewPolicy})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
heard, err := runner.Consume(func(m jetstream.Msg) {
|
||||||
|
var e meshwants.StepEnded
|
||||||
|
_ = json.Unmarshal(m.Data(), &e)
|
||||||
|
_ = m.Ack()
|
||||||
|
ended <- e
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(heard.Stop)
|
||||||
|
subscribed(t, nc)
|
||||||
|
|
||||||
|
from := b.journal.mark()
|
||||||
|
_, stop := b.startStoppable(t)
|
||||||
|
b.journal.await(t, from, "the composition step is heard on", "the composition step served", 30*time.Second)
|
||||||
|
select {
|
||||||
|
case <-b.seatListRead:
|
||||||
|
case <-time.After(30 * time.Second):
|
||||||
|
t.Fatal("the assigner did not read the seat list within 30 s")
|
||||||
|
}
|
||||||
|
queue, _ := buildstep.AskStream(buildstep.AskGo)
|
||||||
|
worker, err := b.js.CreateOrUpdateConsumer(b.ctx, queue, jetstream.ConsumerConfig{Durable: "stand-in", FilterSubject: "mesh.seat.node-build-go.accept.check.mesh-wants",
|
||||||
|
AckPolicy: jetstream.AckExplicitPolicy})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
step := func(id, module, run string, rerun bool) {
|
||||||
|
t.Helper()
|
||||||
|
s := meshwants.StepRun{Pipeline: "main.3." + module, Step: meshwants.StepRunStepComposition, Module: module, Branch: trunkBranch, Revision: 3,
|
||||||
|
Commit: commit, Fingerprint: "src2:" + module, Run: run, Rerun: rerun}
|
||||||
|
if run != "" {
|
||||||
|
s.Pipeline = "run-" + run + "." + module
|
||||||
|
}
|
||||||
|
if rerun {
|
||||||
|
s.By = "op@n1"
|
||||||
|
}
|
||||||
|
raw, _ := json.Marshal(s)
|
||||||
|
msg := nats.NewMsg(meshwants.AcceptSubjectStep)
|
||||||
|
msg.Header.Set("x-event-id", id)
|
||||||
|
msg.Data = raw
|
||||||
|
if err := nc.PublishMsg(msg); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type asked struct {
|
||||||
|
ask buildstep.StepAsk
|
||||||
|
machine string
|
||||||
|
}
|
||||||
|
// asks takes n run asks of the stand-in build seat, each with the machine its request composes.
|
||||||
|
asks := func(n int) []asked {
|
||||||
|
t.Helper()
|
||||||
|
var out []asked
|
||||||
|
for range n {
|
||||||
|
got, err := worker.Next(jetstream.FetchMaxWait(20 * time.Second))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%d of %d run asks put: %v", len(out), n, err)
|
||||||
|
}
|
||||||
|
_ = got.Ack()
|
||||||
|
a, err := buildstep.DecodeStepAsk(got.Data())
|
||||||
|
if err != nil || a.Run == nil {
|
||||||
|
t.Fatalf("the run ask %s does not read: %v", got.Data(), err)
|
||||||
|
}
|
||||||
|
req, err := composer.Decode(readInput(t, nc, a.Run.Input))
|
||||||
|
if err != nil || len(req.Machines) != 1 || req.BlameTries != 20 {
|
||||||
|
t.Fatalf("the request of %s: %+v %v", a.ID, req, err)
|
||||||
|
}
|
||||||
|
out = append(out, asked{a, req.Machines[0]})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
noMoreAsks := func(what string) {
|
||||||
|
t.Helper()
|
||||||
|
if got, err := worker.Next(jetstream.FetchMaxWait(300 * time.Millisecond)); err == nil {
|
||||||
|
t.Fatalf("%s: one more run ask is put: %s", what, got.Data())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
say := func(event string, node string, body any) {
|
||||||
|
t.Helper()
|
||||||
|
raw, _ := json.Marshal(body)
|
||||||
|
if _, err := b.js.Publish(b.ctx, "mesh.seat.node-build-go.event."+event+"."+node, raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
answer := func(a asked, machine string) {
|
||||||
|
t.Helper()
|
||||||
|
v := fmt.Sprintf(`{"v":%d,"cases":[{"name":"change","manifests":{},"machines":{%q:%s}}]}`, composer.Version, a.machine, machine)
|
||||||
|
say("step-ended", "b1", buildstep.StepEnded{V: 1, ID: a.ask.ID, Ask: a.ask.ID, Asker: runAsker, Node: "b1", Outcome: buildstep.OutcomePassed, Output: v, At: time.Now().UTC()})
|
||||||
|
}
|
||||||
|
ends := func(n int, what string) map[string]meshwants.StepEnded {
|
||||||
|
t.Helper()
|
||||||
|
out := map[string]meshwants.StepEnded{}
|
||||||
|
for len(out) < n {
|
||||||
|
select {
|
||||||
|
case e := <-ended:
|
||||||
|
out[e.ID] = e
|
||||||
|
case <-time.After(20 * time.Second):
|
||||||
|
t.Fatalf("%s: %d of %d steps ended: %+v", what, len(out), n, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
runKeys := func(candidate string) []string {
|
||||||
|
all, _ := b.buckets[buckets.CompositionRuns()].Keys(b.ctx)
|
||||||
|
var out []string
|
||||||
|
for _, k := range all {
|
||||||
|
if isRunKey(k) && strings.HasPrefix(k, keysPart(candidate)+".") {
|
||||||
|
out = append(out, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
// readers waits, through a watch of the key, until the run of key has n readers.
|
||||||
|
readers := func(key string, n int) {
|
||||||
|
t.Helper()
|
||||||
|
w, err := b.buckets[buckets.CompositionRuns()].Watch(b.ctx, key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() { _ = w.Stop() }()
|
||||||
|
deadline := time.After(10 * time.Second)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case e := <-w.Updates():
|
||||||
|
var run meshwants.CompositionRun
|
||||||
|
if e != nil && json.Unmarshal(e.Value(), &run) == nil && len(run.Readers) == n {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-deadline:
|
||||||
|
t.Fatalf("the run %s has not %d readers", key, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
blames := `{"composes":false,"reason":"two modules own one path","blamed":[{"module":"a","problem":"/etc/x is a's and b's"},{"module":"b","problem":"/etc/x is a's and b's"}]}`
|
||||||
|
composes := `{"composes":true,"blamed":[]}`
|
||||||
|
|
||||||
|
// One candidate, three steps, two machines: two runs.
|
||||||
|
for _, m := range []string{"a", "b", "c"} {
|
||||||
|
step("step-"+m, m, "", false)
|
||||||
|
}
|
||||||
|
first := asks(2)
|
||||||
|
noMoreAsks("three steps of one candidate")
|
||||||
|
for _, a := range first {
|
||||||
|
answer(a, map[string]string{"n1": composes, "n2": blames}[a.machine])
|
||||||
|
}
|
||||||
|
got := ends(3, "the three steps")
|
||||||
|
if a, bb, c := got["step-a"], got["step-b"], got["step-c"]; a.Outcome != meshwants.StepEndedOutcomeFailed || !strings.Contains(a.Said, "n2 holds a") ||
|
||||||
|
bb.Outcome != meshwants.StepEndedOutcomeFailed || c.Outcome != meshwants.StepEndedOutcomePassed || len(c.Warnings) != 2 ||
|
||||||
|
!strings.Contains(c.Warnings[0], "n2 holds a") || len(c.Shared) != 2 || c.Shared[0].Ask == c.Shared[1].Ask {
|
||||||
|
t.Fatalf("the steps of one candidate: %+v", got)
|
||||||
|
}
|
||||||
|
if keys := runKeys("main.3"); len(keys) != 2 || inputsAsked["main.3 n1"] != 1 || inputsAsked["main.3 n2"] != 1 {
|
||||||
|
t.Fatalf("keys %v, inputs asked %v: want one run and one input per machine", keys, inputsAsked)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Another candidate (a run on request): its own runs; an old composer and a machine blaming none fail.
|
||||||
|
step("step-r1", "a", "r1", false)
|
||||||
|
for _, a := range asks(2) {
|
||||||
|
answer(a, map[string]string{"n1": `{"composes":false,"reason":"x"}`, "n2": `{"composes":false,"reason":"own","blamed":[]}`}[a.machine])
|
||||||
|
}
|
||||||
|
if e := ends(1, "another candidate")["step-r1"]; e.Outcome != meshwants.StepEndedOutcomeFailed || !strings.Contains(e.Said, "n2 does not compose and blames no module") ||
|
||||||
|
len(e.Warnings) != 1 || e.Warnings[0] != "n1: the composer names no culprits" {
|
||||||
|
t.Fatalf("a step of another candidate: %+v", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The bound: n1's ask taken and saying progress past the bound, then silent; n2's never taken.
|
||||||
|
from = b.journal.mark()
|
||||||
|
step("step-r2", "a", "r2", false)
|
||||||
|
bound := asks(2)
|
||||||
|
var n1 asked
|
||||||
|
for _, a := range bound {
|
||||||
|
if a.machine == "n1" {
|
||||||
|
n1 = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
say("ask-taken", "b1", nodebuildgo.AskTaken{Ask: n1.ask.ID, Asker: runAsker, At: time.Now().UTC(), Node: "b1"})
|
||||||
|
for i := range 3 { // past the 2 s bound, each beat within it
|
||||||
|
select {
|
||||||
|
case e := <-ended:
|
||||||
|
t.Fatalf("a run saying its progress ended: %+v", e)
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
}
|
||||||
|
if i == 0 { // the bound holds its run's ask, published at the key's latest revision with its own time to live (A-470n)
|
||||||
|
runs := b.buckets[buckets.CompositionRuns()]
|
||||||
|
all, _ := runs.Keys(b.ctx)
|
||||||
|
held := ""
|
||||||
|
for _, k := range all {
|
||||||
|
if strings.HasPrefix(k, runBoundPrefix) {
|
||||||
|
if e, err := runs.Get(b.ctx, k); err == nil {
|
||||||
|
var v boundValue
|
||||||
|
_ = json.Unmarshal(e.Value(), &v)
|
||||||
|
held += v.Ask
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if held != n1.ask.ID {
|
||||||
|
t.Fatalf("the bound keys hold the asks %q, want n1's %s alone", held, n1.ask.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
say("step-progress", "b1", nodebuildgo.StepProgress{Ask: n1.ask.ID, Asker: runAsker, At: time.Now().UTC(), Phase: "run"})
|
||||||
|
}
|
||||||
|
e := ends(1, "the bounds")["step-r2"]
|
||||||
|
if e.Outcome != meshwants.StepEndedOutcomeCouldNotRun || !strings.Contains(e.Said, "said no progress within 2s (composition-step-bound)") ||
|
||||||
|
!strings.Contains(e.Said, "taken by no build node within 15s (run-untaken-bound)") {
|
||||||
|
t.Fatalf("past the bounds: %+v", e)
|
||||||
|
}
|
||||||
|
mu.Lock()
|
||||||
|
dropped := len(drops)
|
||||||
|
mu.Unlock()
|
||||||
|
if dropped != 2 {
|
||||||
|
t.Fatalf("%d asks dropped past their bounds, want 2", dropped)
|
||||||
|
}
|
||||||
|
answer(n1, composes) // heard after the bound: ignored and journaled
|
||||||
|
b.journal.await(t, from, "the step-ended of the run ask "+n1.ask.ID+" is ignored", "a late step-ended", 10*time.Second)
|
||||||
|
|
||||||
|
// A rerun of a: n1 it passed keeps its verdict; n2 it failed starts one run carrying b, which moves.
|
||||||
|
step("step-a2", "a", "", true)
|
||||||
|
again := asks(1)
|
||||||
|
noMoreAsks("a rerun of a")
|
||||||
|
if again[0].machine != "n2" {
|
||||||
|
t.Fatalf("the rerun composes %s, want only the machine a did not pass", again[0].machine)
|
||||||
|
}
|
||||||
|
answer(again[0], composes)
|
||||||
|
moved := ends(2, "the rerun")
|
||||||
|
if a2, bb := moved["step-a2"], moved["step-b"]; a2.Outcome != meshwants.StepEndedOutcomePassed || bb.Outcome != meshwants.StepEndedOutcomePassed ||
|
||||||
|
!bb.Rerun || bb.By != "op@n1" || len(bb.Shared) != 2 || bb.Shared[1].Ask != again[0].ask.ID {
|
||||||
|
t.Fatalf("after the rerun (asked again %s): a2 %+v; b %+v", again[0].ask.ID, moved["step-a2"].Shared, moved["step-b"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// A superseded step leaves the runs; its other reader goes on.
|
||||||
|
step("step-r3a", "a", "r3", false)
|
||||||
|
step("step-r3b", "b", "r3", false)
|
||||||
|
sup := asks(2)
|
||||||
|
readers(runKeyOf("run-r3", "n1"), 2)
|
||||||
|
readers(runKeyOf("run-r3", "n2"), 2)
|
||||||
|
pe, _ := json.Marshal(mpr.PipelineEnded{V: 1, Pipeline: "run-r3.a", Module: "a", Branch: trunkBranch, Commit: commit, Outcome: mpr.PipelineEndedOutcomeSuperseded, Run: "r3", Steps: []mpr.StepResult{}})
|
||||||
|
if _, err := b.js.Publish(b.ctx, "mesh.seat."+mpr.Seat+".event."+mpr.EventPipelineEnded+".n1", pe); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, a := range sup {
|
||||||
|
answer(a, composes)
|
||||||
|
}
|
||||||
|
if got := ends(1, "the superseded run"); got["step-r3b"].Outcome != meshwants.StepEndedOutcomePassed {
|
||||||
|
t.Fatalf("the other reader: %+v", got)
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case e := <-ended:
|
||||||
|
t.Fatalf("a superseded step said its end: %+v", e)
|
||||||
|
case <-time.After(200 * time.Millisecond):
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restarted during a run: the new assigner takes it up by its ask.
|
||||||
|
step("step-r4", "c", "r4", false)
|
||||||
|
restart := asks(2)
|
||||||
|
stop()
|
||||||
|
for _, a := range restart {
|
||||||
|
answer(a, composes)
|
||||||
|
}
|
||||||
|
from = b.journal.mark()
|
||||||
|
b.startStoppable(t)
|
||||||
|
b.journal.await(t, from, "is taken up again by its runs (ask step-r4)", "the take-up", 30*time.Second)
|
||||||
|
if e := ends(1, "the take-up")["step-r4"]; e.Outcome != meshwants.StepEndedOutcomePassed || len(e.Shared) != 2 {
|
||||||
|
t.Fatalf("the step taken up: %+v", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// compositions-drop: the readers ended naming the drop, the key deleted.
|
||||||
|
step("step-r5", "a", "r5", false)
|
||||||
|
asks(2)
|
||||||
|
body, _ := json.Marshal(meshwants.CompositionsDropInput{Candidate: "run-r5", Machine: "n1", Why: "stuck"})
|
||||||
|
reply, err := nc.Request("mesh.seat.mesh-wants.call.compositions-drop.n1~mesh-delivery-pipeline", body, 10*time.Second)
|
||||||
|
if err != nil || !strings.Contains(string(reply.Data), `"ended":[`) {
|
||||||
|
t.Fatalf("compositions-drop answered %s %v", reply.Data, err)
|
||||||
|
}
|
||||||
|
if e := ends(1, "the drop")["step-r5"]; e.Outcome != meshwants.StepEndedOutcomeCouldNotRun || !strings.Contains(e.Said, "dropped by hand: stuck") {
|
||||||
|
t.Fatalf("a reader of the dropped run: %+v", e)
|
||||||
|
}
|
||||||
|
if keys := runKeys("run-r5"); len(keys) != 1 {
|
||||||
|
t.Errorf("the keys of run-r5 after the drop: %v, want n2's alone", keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// At the cap of 1 MiB no run starts: the step ends could not run, naming the fill.
|
||||||
|
for i := range 2 {
|
||||||
|
if _, err := b.buckets[buckets.CompositionRuns()].Put(b.ctx, fmt.Sprintf("fill%d", i), make([]byte, 700<<10)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
step("step-r6", "a", "r6", false)
|
||||||
|
if e := ends(1, "the cap")["step-r6"]; e.Outcome != meshwants.StepEndedOutcomeCouldNotRun || !strings.Contains(e.Said, "is at its cap of 1 MiB") {
|
||||||
|
t.Fatalf("at the cap: %+v", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,642 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"maps"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
|
)
|
||||||
|
|
||||||
|
// runsMem is the state composition-runs in memory, its bound keys' times to live kept beside.
|
||||||
|
type runsMem struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
vals map[string][]byte
|
||||||
|
revs map[string]uint64
|
||||||
|
ttl map[string]time.Duration
|
||||||
|
bytes int64
|
||||||
|
n uint64
|
||||||
|
// beforeDel, when set, runs once before the next delete: another write landing between a read and the delete.
|
||||||
|
beforeDel func()
|
||||||
|
// beforeArm, when set, runs once before the next arm: another write landing between a read and the arm.
|
||||||
|
beforeArm func()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *runsMem) another() {
|
||||||
|
k.mu.Lock()
|
||||||
|
f := k.beforeDel
|
||||||
|
k.beforeDel = nil
|
||||||
|
k.mu.Unlock()
|
||||||
|
if f != nil {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRunsMem() *runsMem {
|
||||||
|
return &runsMem{vals: map[string][]byte{}, revs: map[string]uint64{}, ttl: map[string]time.Duration{}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *runsMem) get(key string) ([]byte, uint64, error) {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
return k.vals[key], k.revs[key], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *runsMem) create(key string, v []byte) (uint64, error) {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
if _, ok := k.vals[key]; ok {
|
||||||
|
return 0, errRunChanged
|
||||||
|
}
|
||||||
|
k.n++
|
||||||
|
k.vals[key], k.revs[key] = v, k.n
|
||||||
|
return k.n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *runsMem) update(key string, v []byte, rev uint64) (uint64, error) {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
if k.revs[key] != rev {
|
||||||
|
return 0, errRunChanged
|
||||||
|
}
|
||||||
|
k.n++
|
||||||
|
k.vals[key], k.revs[key] = v, k.n
|
||||||
|
return k.n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *runsMem) delAt(key string, rev uint64) error {
|
||||||
|
k.another()
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
if _, ok := k.vals[key]; !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if k.revs[key] != rev {
|
||||||
|
return errRunChanged
|
||||||
|
}
|
||||||
|
delete(k.vals, key)
|
||||||
|
delete(k.revs, key)
|
||||||
|
delete(k.ttl, key)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *runsMem) keys() ([]string, error) {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
var out []string
|
||||||
|
for key := range k.vals {
|
||||||
|
out = append(out, key)
|
||||||
|
}
|
||||||
|
slices.Sort(out)
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *runsMem) arm(key, ask string, ttl time.Duration) (uint64, error) {
|
||||||
|
k.mu.Lock()
|
||||||
|
f := k.beforeArm
|
||||||
|
k.beforeArm = nil
|
||||||
|
k.mu.Unlock()
|
||||||
|
if f != nil {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
raw, _ := json.Marshal(boundValue{Bound: key, Ask: ask})
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
k.n++
|
||||||
|
k.vals[key], k.revs[key], k.ttl[key] = raw, k.n, ttl
|
||||||
|
return k.n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// expire ends a bound key's time to live: the key gone, as the bus's marker leaves it.
|
||||||
|
func (k *runsMem) expire(key string) {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
delete(k.vals, key)
|
||||||
|
delete(k.revs, key)
|
||||||
|
delete(k.ttl, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *runsMem) used() (int64, error) {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
if k.bytes > 0 {
|
||||||
|
return k.bytes, nil
|
||||||
|
}
|
||||||
|
var n int64
|
||||||
|
for _, v := range k.vals {
|
||||||
|
n += int64(len(v))
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §718, §719, §720, A-468, A-469d, A-469x: a run's key is `<candidate key>.<machine>`, each part escaped; two
|
||||||
|
// steps of one candidate joining at once start one run and the second reads it; a run that could not run is replaced; at the
|
||||||
|
// cap no run starts, naming the fill; a run is deleted composition-runs-kept after its end; the settings are read from their files.
|
||||||
|
func TestACompositionRunIsOneKeyPerCandidateAndMachine(t *testing.T) {
|
||||||
|
now := time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC)
|
||||||
|
step := func(id, module string) meshwants.CompositionReader {
|
||||||
|
return readerOf(id, meshwants.StepRun{Pipeline: "main.3." + module, Step: meshwants.StepRunStepComposition, Module: module, Branch: "main", Revision: 3})
|
||||||
|
}
|
||||||
|
t.Run("key", func(t *testing.T) {
|
||||||
|
if k := runKeyOf("main.3", "n1"); k != "main=2e3.n1" {
|
||||||
|
t.Errorf("the key is %q, want each part escaped as a key's name", k)
|
||||||
|
}
|
||||||
|
if isRunKey(runBoundPrefix+"main=2e3.n1") || isRunKey(runUntakenPrefix+"main=2e3.n1") || !isRunKey("main=2e3.n1") {
|
||||||
|
t.Error("a bound key is taken for a run's or a run's for a bound key")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("one run for two steps at once", func(t *testing.T) {
|
||||||
|
kv := newRunsMem()
|
||||||
|
r := newCompositionRuns(kv, defaultRunSettings, func() time.Time { return now }, t.Logf)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
got := make([]joined, 2)
|
||||||
|
for i, m := range []string{"a", "b"} {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
j, err := r.join(step("ask-"+m, m), "main.3", "n1", "run-"+m)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
got[i] = j
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
runKeys := func() []string {
|
||||||
|
all, _ := kv.keys()
|
||||||
|
return slices.DeleteFunc(all, func(k string) bool { return !isRunKey(k) })
|
||||||
|
}
|
||||||
|
if got[0].started == got[1].started {
|
||||||
|
t.Fatalf("started %v and %v: want exactly one step to start the run", got[0].started, got[1].started)
|
||||||
|
}
|
||||||
|
keys := runKeys()
|
||||||
|
run, _, _, _ := r.read(runKeyOf("main.3", "n1"))
|
||||||
|
if len(keys) != 1 || len(run.Readers) != 2 || run.Candidate != "main.3" || run.Machine != "n1" || run.Started == nil {
|
||||||
|
t.Errorf("keys %v, run %+v: want one key read by both", keys, run)
|
||||||
|
}
|
||||||
|
if j, _ := r.join(step("ask-a", "a"), "main.3", "n1", "run-c"); j.started || len(j.run.Readers) != 2 {
|
||||||
|
t.Errorf("a reader joining again is added again or starts a run: %+v", j)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("could not run is never read", func(t *testing.T) {
|
||||||
|
kv := newRunsMem()
|
||||||
|
r := newCompositionRuns(kv, defaultRunSettings, func() time.Time { return now }, t.Logf)
|
||||||
|
if _, err := r.join(step("ask-a", "a"), "main.3", "n1", "run-1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
key := runKeyOf("main.3", "n1")
|
||||||
|
_, _, _ = r.change(key, func(c *meshwants.CompositionRun) bool {
|
||||||
|
c.Ended, c.Outcome = &now, meshwants.CompositionRunOutcomeCouldNotRun
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
j, err := r.join(step("ask-b", "b"), "main.3", "n1", "run-2")
|
||||||
|
if err != nil || !j.started || j.run.Ask != "run-2" || len(j.run.Readers) != 1 || j.run.Ended != nil {
|
||||||
|
t.Errorf("after a could not run: %+v %v, want a new run read by its starter alone", j, err)
|
||||||
|
}
|
||||||
|
_, _, _ = r.change(key, func(c *meshwants.CompositionRun) bool {
|
||||||
|
c.Ended, c.Outcome = &now, meshwants.CompositionRunOutcomePassed
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
if j, _ := r.join(step("ask-c", "c"), "main.3", "n1", "run-3"); j.started || j.run.Ask != "run-2" {
|
||||||
|
t.Errorf("a passed run is not read: %+v", j)
|
||||||
|
}
|
||||||
|
if j, _ := r.join(step("ask-d", "d"), "main.4", "n1", "run-4"); !j.started {
|
||||||
|
t.Errorf("a step of another candidate reads the first's run: %+v", j)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("cap", func(t *testing.T) {
|
||||||
|
kv := newRunsMem()
|
||||||
|
kv.bytes = 16 << 20
|
||||||
|
r := newCompositionRuns(kv, defaultRunSettings, func() time.Time { return now }, t.Logf)
|
||||||
|
_, err := r.join(step("ask-a", "a"), "main.3", "n1", "run-1")
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "at its cap of 16 MiB (16777216 bytes kept)") {
|
||||||
|
t.Errorf("at the cap: %v, want the fill named", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("kept", func(t *testing.T) {
|
||||||
|
kv := newRunsMem()
|
||||||
|
at := now
|
||||||
|
r := newCompositionRuns(kv, defaultRunSettings, func() time.Time { return at }, t.Logf)
|
||||||
|
for _, c := range []string{"main.1", "main.2"} {
|
||||||
|
if _, err := r.join(step("ask-"+c, "a"), c, "n1", "run-"+c); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
old := now.Add(-25 * time.Hour)
|
||||||
|
_, _, _ = r.change(runKeyOf("main.1", "n1"), func(c *meshwants.CompositionRun) bool { c.Ended, c.Outcome = &old, "passed"; return true })
|
||||||
|
_, _ = kv.arm(runBoundPrefix+runKeyOf("main.1", "n1"), "run-main.1", time.Minute)
|
||||||
|
recent := now.Add(-time.Hour)
|
||||||
|
_, _, _ = r.change(runKeyOf("main.2", "n1"), func(c *meshwants.CompositionRun) bool { c.Ended, c.Outcome = &recent, "passed"; return true })
|
||||||
|
if _, err := r.join(step("ask-x", "a"), "main.9", "n1", "run-9"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
keys, _ := kv.keys()
|
||||||
|
for _, k := range []string{runBoundPrefix, runUntakenPrefix} {
|
||||||
|
if v, _, _ := kv.get(k + runKeyOf("main.1", "n1")); v != nil {
|
||||||
|
t.Errorf("the key %s stays past its run", k+runKeyOf("main.1", "n1"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
keys = slices.DeleteFunc(keys, func(k string) bool { return !isRunKey(k) })
|
||||||
|
if want := []string{runKeyOf("main.2", "n1"), runKeyOf("main.9", "n1")}; !slices.Equal(keys, want) {
|
||||||
|
t.Errorf("keys %v, want %v: a run ended more than a day ago goes with its bound key at the next run", keys, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("a listing that misses a key being written", func(t *testing.T) {
|
||||||
|
kv := &missingRuns{runsMem: newRunsMem()}
|
||||||
|
r := newCompositionRuns(kv, defaultRunSettings, func() time.Time { return now }, t.Logf)
|
||||||
|
if _, err := r.join(step("ask-a", "a"), "main.3", "n1", "run-1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
kv.hide = runKeyOf("main.3", "n1")
|
||||||
|
if key, _, _ := r.keyOfAsk("run-1"); key != "" {
|
||||||
|
t.Fatalf("the stand's listing does not hide the key")
|
||||||
|
}
|
||||||
|
r.saw(kv.hide, true) // as the state's watch hands it
|
||||||
|
if key, _, _ := r.keyOfAsk("run-1"); key != kv.hide {
|
||||||
|
t.Errorf("the run of ask run-1 is not found by the keys the watch handed: %q", key)
|
||||||
|
}
|
||||||
|
r.saw(kv.hide, false)
|
||||||
|
if keys, _ := r.keys(); slices.Contains(keys, kv.hide) {
|
||||||
|
t.Errorf("a key the watch saw deleted is still listed: %v", keys)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// No delete lands on a value newer than the one it was judged from (the kind test 109 met in test-runs): a rerun's run
|
||||||
|
// replacing the key, and its untaken bound, stand.
|
||||||
|
for _, c := range []struct {
|
||||||
|
name string
|
||||||
|
ended time.Time
|
||||||
|
act func(r *compositionRuns, key string) error
|
||||||
|
}{
|
||||||
|
{"the sweep of a run replaced meanwhile", now.Add(-25 * time.Hour), func(r *compositionRuns, _ string) error { return r.sweep() }},
|
||||||
|
{"the end of a run replaced meanwhile", time.Time{}, func(r *compositionRuns, key string) error {
|
||||||
|
_, err := r.endRun(key, "run-1", meshwants.CompositionRunOutcomePassed, "", nil)
|
||||||
|
return err
|
||||||
|
}},
|
||||||
|
} {
|
||||||
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
kv := newRunsMem()
|
||||||
|
r := newCompositionRuns(kv, defaultRunSettings, func() time.Time { return now }, t.Logf)
|
||||||
|
if _, err := r.join(step("ask-a", "a"), "main.3", "n1", "run-1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
key := runKeyOf("main.3", "n1")
|
||||||
|
if !c.ended.IsZero() {
|
||||||
|
_, _, _ = r.change(key, func(run *meshwants.CompositionRun) bool { run.Ended, run.Outcome = &c.ended, "failed"; return true })
|
||||||
|
}
|
||||||
|
_, _ = kv.arm(runBoundPrefix+key, "run-1", time.Minute)
|
||||||
|
kv.beforeDel = func() { // a rerun replaces the key and arms its untaken bound
|
||||||
|
for {
|
||||||
|
raw, rev, _ := kv.get(key)
|
||||||
|
var run meshwants.CompositionRun
|
||||||
|
_ = json.Unmarshal(raw, &run)
|
||||||
|
if run.Ended == nil {
|
||||||
|
at := now
|
||||||
|
run.Ended, run.Outcome = &at, "failed"
|
||||||
|
}
|
||||||
|
fresh, _ := json.Marshal(meshwants.CompositionRun{Candidate: "main.3", Machine: "n1", Ask: "run-2", Started: &now, Readers: run.Readers})
|
||||||
|
if _, err := kv.update(key, fresh, rev); err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, _ = kv.arm(runUntakenPrefix+key, "run-2", time.Hour)
|
||||||
|
}
|
||||||
|
if err := c.act(r, key); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if run, _, ok, _ := r.read(key); !ok || run.Ask != "run-2" || run.Ended != nil {
|
||||||
|
t.Errorf("the key holds %+v (stands %v), want the rerun's running run-2", run, ok)
|
||||||
|
}
|
||||||
|
if v, _, _ := kv.get(runUntakenPrefix + key); v == nil {
|
||||||
|
t.Error("the untaken bound the rerun's run armed is deleted")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
t.Run("settings", func(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
files := map[string]string{"MESH_ASSIGNER_COMPOSITION_RUNS_CAP_MIB_FILE": "8", "MESH_ASSIGNER_COMPOSITION_RUNS_KEPT_FILE": "2h",
|
||||||
|
"MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "2s", "MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": "", "MESH_ASSIGNER_BLAME_TRIES_FILE": "5"}
|
||||||
|
env := map[string]string{}
|
||||||
|
for name, content := range files {
|
||||||
|
p := filepath.Join(dir, name)
|
||||||
|
if err := os.WriteFile(p, []byte(content), 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
env[name] = p
|
||||||
|
}
|
||||||
|
s, err := runSettingsOf(func(k string) string { return env[k] })
|
||||||
|
if err != nil || s.capBytes != 8<<20 || s.kept != 2*time.Hour || s.stepBound != 2*time.Second || s.untaken != 24*time.Hour || s.blameTries != 5 {
|
||||||
|
t.Errorf("settings %+v %v", s, err)
|
||||||
|
}
|
||||||
|
_ = os.WriteFile(env["MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE"], []byte("30"), 0o600)
|
||||||
|
if _, err := runSettingsOf(func(k string) string { return env[k] }); err == nil || !strings.Contains(err.Error(), "not a positive Go duration") {
|
||||||
|
t.Errorf("a bound of no unit: %v", err)
|
||||||
|
}
|
||||||
|
if s, err := runSettingsOf(func(string) string { return "" }); err != nil || s != defaultRunSettings {
|
||||||
|
t.Errorf("no files: %+v %v, want the defaults", s, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
raw, _ := json.Marshal(step("x", "a"))
|
||||||
|
if !strings.Contains(string(raw), `"id":"x"`) {
|
||||||
|
t.Errorf("a reader names no ask id: %s", raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §720, A-466s, A-468b, A-469y, A-470: a run's untaken bound is armed at its start and each reader said waiting for a
|
||||||
|
// build node; ask-taken arms the bound of composition-step-bound and ends the waits ran; each step-progress arms it again; the
|
||||||
|
// bound's expiry drops the ask and ends the run could not run naming the ask and the bound, a step-ended heard later ignored and
|
||||||
|
// journaled; the untaken bound's expiry ends it naming run-untaken-bound, the waits superseded; the readers of a run with no end
|
||||||
|
// are taken up at the start.
|
||||||
|
func TestACompositionRunsBoundTimesOwedProgress(t *testing.T) {
|
||||||
|
now := time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC)
|
||||||
|
reader := func(id string) meshwants.CompositionReader {
|
||||||
|
return readerOf(id, meshwants.StepRun{Pipeline: "main.3." + id, Step: meshwants.StepRunStepComposition, Module: id, Branch: "main", Revision: 3})
|
||||||
|
}
|
||||||
|
type said struct{ event, how, module string }
|
||||||
|
setup := func(t *testing.T) (*runsMem, *compositionRuns, *[]said, *[]string, *[]string) {
|
||||||
|
kv := newRunsMem()
|
||||||
|
var saids []said
|
||||||
|
var drops, journal []string
|
||||||
|
var mu sync.Mutex
|
||||||
|
r := newCompositionRuns(kv, defaultRunSettings, func() time.Time { return now }, func(f string, a ...any) {
|
||||||
|
mu.Lock()
|
||||||
|
journal = append(journal, fmt.Sprintf(f, a...))
|
||||||
|
mu.Unlock()
|
||||||
|
})
|
||||||
|
r.say = func(event string, body any, _ string) error {
|
||||||
|
w := body.(meshwants.Wait)
|
||||||
|
if w.On != waitOnBuildNode || w.Step != "pipeline" || w.Owner != meshwants.Seat || w.Node == "" {
|
||||||
|
t.Errorf("the wait said %+v", w)
|
||||||
|
}
|
||||||
|
saids = append(saids, said{event, w.How, w.Module})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
r.drop = func(ask, why string) error { drops = append(drops, ask+": "+why); return nil }
|
||||||
|
return kv, r, &saids, &drops, &journal
|
||||||
|
}
|
||||||
|
key := runKeyOf("main.3", "n1")
|
||||||
|
t.Run("taken, progress, bound", func(t *testing.T) {
|
||||||
|
kv, r, saids, drops, journal := setup(t)
|
||||||
|
if _, err := r.join(reader("a"), "main.3", "n1", "run-1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := r.join(reader("b"), "main.3", "n1", "run-2"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if kv.ttl[runUntakenPrefix+key] != 24*time.Hour || !slices.Equal(*saids, []said{{meshwants.EventWaitHeld, "", "a"}, {meshwants.EventWaitHeld, "", "b"}}) {
|
||||||
|
t.Fatalf("at the start: untaken %v, said %v", kv.ttl, *saids)
|
||||||
|
}
|
||||||
|
if err := r.heardAskTaken(nodebuildgo.AskTaken{Ask: "run-1", Asker: "someone-else"}); err != nil || kv.ttl[runBoundPrefix+key] != 0 {
|
||||||
|
t.Fatalf("another asker's ask-taken arms a bound: %v %v", kv.ttl, err)
|
||||||
|
}
|
||||||
|
if err := r.heardAskTaken(nodebuildgo.AskTaken{Ask: "run-1", Asker: runAsker, Node: "b1"}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, untaken, _ := kv.get(runUntakenPrefix + key)
|
||||||
|
if kv.ttl[runBoundPrefix+key] != 30*time.Minute || untaken != 0 || len(*saids) != 4 || (*saids)[2].how != "ran" || (*saids)[3].how != "ran" {
|
||||||
|
t.Fatalf("at ask-taken: %v, said %v", kv.ttl, *saids)
|
||||||
|
}
|
||||||
|
before := kv.revs[runBoundPrefix+key]
|
||||||
|
if err := r.heardProgress(nodebuildgo.StepProgress{Ask: "run-1", Asker: runAsker}); err != nil || kv.revs[runBoundPrefix+key] == before {
|
||||||
|
t.Fatalf("a step-progress does not arm the bound again: %v", err)
|
||||||
|
}
|
||||||
|
kv.expire(runBoundPrefix + key)
|
||||||
|
r.expired(runBoundPrefix + key)
|
||||||
|
run, _, _, _ := r.read(key)
|
||||||
|
if run.Outcome != meshwants.CompositionRunOutcomeCouldNotRun || run.Said != "n1: its run ask run-1 said no progress within 30m0s (composition-step-bound)" ||
|
||||||
|
len(*drops) != 1 || !strings.HasPrefix((*drops)[0], "run-1: ") {
|
||||||
|
t.Fatalf("past the bound: %+v, drops %v", run, *drops)
|
||||||
|
}
|
||||||
|
if got := judgeRun("a", run); got.couldNot != run.Said {
|
||||||
|
t.Errorf("a reader of the run past its bound: %+v", got)
|
||||||
|
}
|
||||||
|
late := buildstep.StepEnded{Ask: "run-1", Asker: runAsker, Outcome: buildstep.OutcomePassed, Output: "{}"}
|
||||||
|
if err := r.heardEnd(late, func(e buildstep.StepEnded) ([]byte, error) { return []byte(e.Output), nil }); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if again, _, _, _ := r.read(key); again.Said != run.Said || !slices.ContainsFunc(*journal, func(l string) bool {
|
||||||
|
return strings.Contains(l, "step-ended of the run ask run-1 is ignored") && strings.Contains(l, key)
|
||||||
|
}) {
|
||||||
|
t.Errorf("a step-ended after the bound: %+v, journal %v", again, *journal)
|
||||||
|
}
|
||||||
|
if keys, _ := kv.keys(); !slices.Equal(keys, []string{key}) {
|
||||||
|
t.Errorf("the bound keys stay past the run's end: %v", keys)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("untaken", func(t *testing.T) {
|
||||||
|
kv, r, saids, drops, _ := setup(t)
|
||||||
|
if _, err := r.join(reader("a"), "main.3", "n1", "run-1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
kv.expire(runUntakenPrefix + key)
|
||||||
|
r.expired(runUntakenPrefix + key)
|
||||||
|
run, _, _, _ := r.read(key)
|
||||||
|
if run.Outcome != meshwants.CompositionRunOutcomeCouldNotRun || run.Said != "n1: its run ask run-1 was taken by no build node within 24h0m0s (run-untaken-bound)" ||
|
||||||
|
len(*drops) != 1 || !slices.Equal(*saids, []said{{meshwants.EventWaitHeld, "", "a"}, {meshwants.EventWaitEnded, "superseded", "a"}}) {
|
||||||
|
t.Errorf("untaken past its bound: %+v, drops %v, said %v", run, *drops, *saids)
|
||||||
|
}
|
||||||
|
r.expired(runUntakenPrefix + key) // a run ended takes nothing
|
||||||
|
if len(*drops) != 1 {
|
||||||
|
t.Errorf("an ended run is dropped again: %v", *drops)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// A-470n, A-470o: a bound holds its run's ask, armed for it alone; a late signal of a run replaced moves nothing and is
|
||||||
|
// journaled; an expiry ends the run only while its bound is still absent and the run taken (bound.) or untaken (untaken.).
|
||||||
|
rerun := func(kv *runsMem, r *compositionRuns) func() { // a rerun replaces run-1 by run-2, its bounds gone, run-2's untaken armed
|
||||||
|
return func() {
|
||||||
|
_, _, _ = r.change(key, func(c *meshwants.CompositionRun) bool { c.Ask = "run-2"; return true })
|
||||||
|
kv.expire(runBoundPrefix + key)
|
||||||
|
_, _ = kv.arm(runUntakenPrefix+key, "run-2", time.Hour)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taken := func(t *testing.T, r *compositionRuns) {
|
||||||
|
if err := r.heardAskTaken(nodebuildgo.AskTaken{Ask: "run-1", Asker: runAsker, Node: "b1"}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range []struct {
|
||||||
|
name string
|
||||||
|
act func(t *testing.T, kv *runsMem, r *compositionRuns)
|
||||||
|
ended bool
|
||||||
|
bound string // the ask the bound key holds, "" for none
|
||||||
|
untaken string
|
||||||
|
journal string
|
||||||
|
}{
|
||||||
|
{"a late ask-taken of a run replaced as it is heard", func(t *testing.T, kv *runsMem, r *compositionRuns) {
|
||||||
|
kv.beforeArm = rerun(kv, r)
|
||||||
|
taken(t, r)
|
||||||
|
}, false, "", "run-2", "the ask-taken of the run ask run-1 is late"},
|
||||||
|
{"a late step-progress of a run replaced as it is heard", func(t *testing.T, kv *runsMem, r *compositionRuns) {
|
||||||
|
taken(t, r)
|
||||||
|
kv.beforeArm = rerun(kv, r)
|
||||||
|
if err := r.heardProgress(nodebuildgo.StepProgress{Ask: "run-1", Asker: runAsker}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
kv.expire(runBoundPrefix + key) // a bound left standing would end run-2 here
|
||||||
|
r.expired(runBoundPrefix + key)
|
||||||
|
}, false, "", "run-2", "the step-progress of the run ask run-1 is late"},
|
||||||
|
{"a step-progress of a run gone", func(t *testing.T, kv *runsMem, r *compositionRuns) {
|
||||||
|
taken(t, r)
|
||||||
|
rerun(kv, r)()
|
||||||
|
if err := r.heardProgress(nodebuildgo.StepProgress{Ask: "run-1", Asker: runAsker}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}, false, "", "run-2", "the step-progress of the run ask run-1 is late"},
|
||||||
|
{"an expiry heard after the bound was armed again", func(t *testing.T, kv *runsMem, r *compositionRuns) {
|
||||||
|
taken(t, r)
|
||||||
|
r.expired(runBoundPrefix + key)
|
||||||
|
}, false, "run-1", "", "the expiry of " + runBoundPrefix + key + " ends nothing"},
|
||||||
|
{"the bound's expiry of a run not taken", func(t *testing.T, kv *runsMem, r *compositionRuns) {
|
||||||
|
_, _ = kv.arm(runBoundPrefix+key, "run-1", time.Minute)
|
||||||
|
kv.expire(runBoundPrefix + key)
|
||||||
|
r.expired(runBoundPrefix + key)
|
||||||
|
}, false, "", "run-1", "the expiry of " + runBoundPrefix + key + " ends nothing"},
|
||||||
|
{"the untaken expiry of a run taken", func(t *testing.T, kv *runsMem, r *compositionRuns) {
|
||||||
|
_, _ = kv.arm(runBoundPrefix+key, "run-1", time.Minute)
|
||||||
|
kv.expire(runUntakenPrefix + key)
|
||||||
|
r.expired(runUntakenPrefix + key)
|
||||||
|
}, false, "run-1", "", "the expiry of " + runUntakenPrefix + key + " ends nothing"},
|
||||||
|
{"an end of another ask", func(t *testing.T, kv *runsMem, r *compositionRuns) {
|
||||||
|
if ended, err := r.end(key, "run-0", meshwants.CompositionRunOutcomePassed, "", nil); ended || err != nil {
|
||||||
|
t.Errorf("the end of run-0 ended the run of run-1: %v %v", ended, err)
|
||||||
|
}
|
||||||
|
}, false, "", "run-1", ""},
|
||||||
|
{"the ask-taken of the run's own ask", func(t *testing.T, kv *runsMem, r *compositionRuns) {
|
||||||
|
taken(t, r)
|
||||||
|
}, false, "run-1", "", ""},
|
||||||
|
} {
|
||||||
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
kv, r, _, _, journal := setup(t)
|
||||||
|
if _, err := r.join(reader("a"), "main.3", "n1", "run-1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
c.act(t, kv, r)
|
||||||
|
run, _, _, _ := r.read(key)
|
||||||
|
if (run.Ended != nil) != c.ended {
|
||||||
|
t.Errorf("the run ended %v (%s), want %v", run.Ended != nil, run.Said, c.ended)
|
||||||
|
}
|
||||||
|
for prefix, want := range map[string]string{runBoundPrefix: c.bound, runUntakenPrefix: c.untaken} {
|
||||||
|
if held, _, _, _ := r.boundOf(prefix + key); held != want {
|
||||||
|
t.Errorf("%s holds the ask %q, want %q", prefix+key, held, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if c.journal != "" && !slices.ContainsFunc(*journal, func(l string) bool { return strings.Contains(l, c.journal) }) {
|
||||||
|
t.Errorf("the journal %v does not say %q", *journal, c.journal)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// A-469y, A-470u: a step asked again that joins a running run not yet taken, beside a reader or in its pipeline's former
|
||||||
|
// reader's place, says its own wait held, as join does; the former reader's wait, and that of a reader leaving, ends at once
|
||||||
|
// superseded.
|
||||||
|
held := func(m string) said { return said{meshwants.EventWaitHeld, "", m} }
|
||||||
|
gone := func(m string) said { return said{meshwants.EventWaitEnded, "superseded", m} }
|
||||||
|
for _, c := range []struct {
|
||||||
|
name string
|
||||||
|
act func(t *testing.T, r *compositionRuns)
|
||||||
|
want []said
|
||||||
|
}{
|
||||||
|
{"a rerun joins", func(t *testing.T, r *compositionRuns) {
|
||||||
|
again := reader("b")
|
||||||
|
again.Rerun = true
|
||||||
|
if _, err := r.rejoin(again, "main.3", "n1", "run-2"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}, []said{held("a"), held("b")}},
|
||||||
|
{"a rerun takes its former place", func(t *testing.T, r *compositionRuns) {
|
||||||
|
again := reader("a2")
|
||||||
|
again.Pipeline, again.Module, again.Rerun = "main.3.a", "a2", true
|
||||||
|
if _, err := r.rejoin(again, "main.3", "n1", "run-2"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}, []said{held("a"), gone("a"), held("a2")}},
|
||||||
|
{"a reader leaves", func(t *testing.T, r *compositionRuns) {
|
||||||
|
if _, err := r.join(reader("b"), "main.3", "n1", "run-2"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := r.leave("main.3.a", nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}, []said{held("a"), held("b"), gone("a")}},
|
||||||
|
} {
|
||||||
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
_, r, saids, _, _ := setup(t)
|
||||||
|
if _, err := r.join(reader("a"), "main.3", "n1", "run-1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
c.act(t, r)
|
||||||
|
if !slices.Equal(*saids, c.want) {
|
||||||
|
t.Errorf("said %v, want %v", *saids, c.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
t.Run("taken up at the start", func(t *testing.T) {
|
||||||
|
_, r, _, _, _ := setup(t)
|
||||||
|
for _, c := range []struct{ id, machine string }{{"a", "n1"}, {"a", "n2"}, {"b", "n1"}} {
|
||||||
|
if _, err := r.join(reader(c.id), "main.3", c.machine, "run-"+c.machine); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ended := now
|
||||||
|
_, _, _ = r.change(runKeyOf("main.3", "n2"), func(c *meshwants.CompositionRun) bool { c.Ended, c.Outcome = &ended, "passed"; return true })
|
||||||
|
// A rerun's run carrying readers whose steps said their end (A-470l, A-470m): c passed and is not taken up, d is marked rerun.
|
||||||
|
_, _, _ = r.change(runKeyOf("main.3", "n1"), func(run *meshwants.CompositionRun) bool {
|
||||||
|
for _, id := range []string{"c", "d"} {
|
||||||
|
c := reader(id)
|
||||||
|
c.Ended, c.Rerun = &ended, id == "d"
|
||||||
|
run.Readers = append(run.Readers, c)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
readers, err := r.readersOfOpen()
|
||||||
|
if err != nil || len(readers) != 3 || readers[0].ID != "a" || readers[1].ID != "b" || readers[2].ID != "d" {
|
||||||
|
t.Fatalf("the readers taken up: %+v %v", readers, err)
|
||||||
|
}
|
||||||
|
if keys, _ := r.keysOf("main.3", "a"); !slices.Equal(keys, []string{runKeyOf("main.3", "n1"), runKeyOf("main.3", "n2")}) {
|
||||||
|
t.Errorf("the runs of reader a: %v", keys)
|
||||||
|
}
|
||||||
|
// A-470q: a reader with no `ended` says its first end under its ask's id; d, marked rerun, says its end again under
|
||||||
|
// `<id>.<the open run's ask>`.
|
||||||
|
ids := make(chan [2]string, 3)
|
||||||
|
steps := &compositionSteps{node: "n1", now: func() time.Time { return now }, logf: t.Logf,
|
||||||
|
resume: func(context.Context, string, meshwants.StepRun) stepOutcome {
|
||||||
|
return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed}
|
||||||
|
},
|
||||||
|
say: func(_ string, body any, id string) error {
|
||||||
|
ids <- [2]string{body.(meshwants.StepEnded).ID, id}
|
||||||
|
return nil
|
||||||
|
}}
|
||||||
|
steps.takeUp(context.Background(), r)
|
||||||
|
got := map[string]string{}
|
||||||
|
for range 3 {
|
||||||
|
select {
|
||||||
|
case e := <-ids:
|
||||||
|
got[e[0]] = e[1]
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
t.Fatalf("the ends of the take-up: %v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if want := map[string]string{"a": "a", "b": "b", "d": "d.run-n1"}; !maps.Equal(got, want) {
|
||||||
|
t.Errorf("the message ids of the take-up's ends: %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// missingRuns is runsMem whose listing misses one key, as a bucket's listing misses a key being written at that moment.
|
||||||
|
type missingRuns struct {
|
||||||
|
*runsMem
|
||||||
|
hide string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *missingRuns) keys() ([]string, error) {
|
||||||
|
all, err := k.runsMem.keys()
|
||||||
|
return slices.DeleteFunc(all, func(key string) bool { return key == k.hide }), err
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The composition runs' read and drop (design 47 G §728; A-469f, A-469u, A-469v): the seat mesh-wants' verbs `compositions`
|
||||||
|
// (class read) and `compositions-drop` (class act, §391's default callers), answered by the assigner's process, which keeps the
|
||||||
|
// runs and says the readers' ends; the module's tools `assigner_compositions` and `assigner_compositions_drop` call them.
|
||||||
|
|
||||||
|
// The tools that call the two verbs.
|
||||||
|
const (
|
||||||
|
compositionsTool = "assigner_compositions"
|
||||||
|
compositionsDropTool = "assigner_compositions_drop"
|
||||||
|
)
|
||||||
|
|
||||||
|
// compositions answers each composition run the state keeps, under §719's field names plus its key, with the candidate and the
|
||||||
|
// machine named only those, and the state's fill against its cap.
|
||||||
|
func (r *compositionRuns) compositions(in meshwants.CompositionsInput) (meshwants.CompositionsAnswer, error) {
|
||||||
|
all, err := r.keys()
|
||||||
|
if err != nil {
|
||||||
|
return meshwants.CompositionsAnswer{}, fmt.Errorf("the state %s is not listed: %w", "composition-runs", err)
|
||||||
|
}
|
||||||
|
slices.Sort(all)
|
||||||
|
out := meshwants.CompositionsAnswer{Runs: []meshwants.CompositionRun{}}
|
||||||
|
for _, key := range all {
|
||||||
|
if !isRunKey(key) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
run, _, ok, err := r.read(key)
|
||||||
|
if err != nil || !ok || (in.Candidate != "" && run.Candidate != in.Candidate) || (in.Machine != "" && run.Machine != in.Machine) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
run.Key = key
|
||||||
|
out.Runs = append(out.Runs, run)
|
||||||
|
}
|
||||||
|
out.Fill, err = r.fill()
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// drop drops one composition run by hand (§728): the act and why written in the hand-act log first (record), then a running run's
|
||||||
|
// ask dropped, each of its readers' waits stopped and, for each reader whose end is owed (no `ended`, or marked rerun), its end
|
||||||
|
// said could not run naming the drop, once (A-470r), and the key deleted with its bound keys. It answers the entry deleted and
|
||||||
|
// the readers it ended.
|
||||||
|
func (c *compositionSteps) drop(r *compositionRuns, record func(meshhandactsclient.Request) error, caller string, in meshwants.CompositionsDropInput) (meshwants.CompositionsDropAnswer, error) {
|
||||||
|
why := strings.TrimSpace(in.Why)
|
||||||
|
if in.Candidate == "" || in.Machine == "" || why == "" {
|
||||||
|
return meshwants.CompositionsDropAnswer{}, errors.New("name the candidate, the machine and why the composition run is dropped")
|
||||||
|
}
|
||||||
|
key := runKeyOf(in.Candidate, in.Machine)
|
||||||
|
run, _, ok, err := r.read(key)
|
||||||
|
if err != nil {
|
||||||
|
return meshwants.CompositionsDropAnswer{}, err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return meshwants.CompositionsDropAnswer{}, fmt.Errorf("no composition run of %s on %s is kept", in.Candidate, in.Machine)
|
||||||
|
}
|
||||||
|
if err := record(meshhandactsclient.Request{What: meshwants.VerbCompositionsDrop + " " + key, Why: why + " (" + caller + ")", Cause: "compositions-drop"}); err != nil {
|
||||||
|
return meshwants.CompositionsDropAnswer{}, fmt.Errorf("the hand act was not recorded, so nothing was dropped: %w", err)
|
||||||
|
}
|
||||||
|
said := fmt.Sprintf("%s: the composition run %s was dropped by hand: %s", in.Machine, key, why)
|
||||||
|
answer := meshwants.CompositionsDropAnswer{Run: run}
|
||||||
|
answer.Run.Key = key
|
||||||
|
if run.Ended == nil {
|
||||||
|
if r.drop != nil {
|
||||||
|
if err := r.drop(run.Ask, said); err != nil {
|
||||||
|
r.logf("the drop of the run ask %s of the composition run %s is not answered: %v", run.Ask, key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ids := make([]string, 0, len(run.Readers))
|
||||||
|
for _, reader := range run.Readers {
|
||||||
|
ids = append(ids, reader.ID)
|
||||||
|
}
|
||||||
|
c.leave(ids) // their waits say no end of their own
|
||||||
|
// The run ends without moving its readers: the drop says each owed end itself, once (A-470r).
|
||||||
|
if _, err := r.endRunMoving(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, said, nil, r.untaken(key, run.Ask), false); err != nil {
|
||||||
|
return answer, err
|
||||||
|
}
|
||||||
|
shared := []meshwants.Shared{{Machine: run.Machine, Run: key, Ask: run.Ask}}
|
||||||
|
for _, reader := range run.Readers {
|
||||||
|
if reader.Ended != nil && !reader.Rerun {
|
||||||
|
continue // it ended passed already and keeps its verdict (A-470r)
|
||||||
|
}
|
||||||
|
again := "" // a reader whose step said its end already says it again under the dropped run's ask (A-470q)
|
||||||
|
if reader.Ended != nil {
|
||||||
|
again = run.Ask
|
||||||
|
}
|
||||||
|
c.sayEnd(reader.ID, stepRunOf(reader), nil, stepOutcome{Outcome: meshwants.StepEndedOutcomeCouldNotRun, Said: said, Shared: shared}, again)
|
||||||
|
answer.Ended = append(answer.Ended, reader)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The dropped run's key goes while it holds that run: a run started on it since stands.
|
||||||
|
err = r.deleteRun(key, func(c meshwants.CompositionRun) bool { return c.Ask == run.Ask })
|
||||||
|
r.heard()
|
||||||
|
return answer, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// compositionVerbs are the process's handlers of the seat mesh-wants' verbs compositions and compositions-drop.
|
||||||
|
func compositionVerbs(r *compositionRuns, c *compositionSteps, record func(meshhandactsclient.Request) error) map[string]process.SeatHandler {
|
||||||
|
return map[string]process.SeatHandler{
|
||||||
|
meshwants.VerbCompositions: func(_ string, raw json.RawMessage) (any, error) {
|
||||||
|
var in meshwants.CompositionsInput
|
||||||
|
if len(raw) > 0 {
|
||||||
|
if err := json.Unmarshal(raw, &in); err != nil {
|
||||||
|
return nil, fmt.Errorf("the arguments are not JSON: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r.compositions(in)
|
||||||
|
},
|
||||||
|
meshwants.VerbCompositionsDrop: func(caller string, raw json.RawMessage) (any, error) {
|
||||||
|
var in meshwants.CompositionsDropInput
|
||||||
|
if err := json.Unmarshal(raw, &in); err != nil {
|
||||||
|
return nil, fmt.Errorf("the arguments are not JSON: %w", err)
|
||||||
|
}
|
||||||
|
return c.drop(r, record, caller, in)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// compositionsTools are the module's tools of §728's names, each calling its verb (A-469f).
|
||||||
|
func compositionsTools(ask func(string, any) (json.RawMessage, error)) []stdio.Tool {
|
||||||
|
call := func(verb string, args map[string]any, names ...string) (any, error) {
|
||||||
|
in := map[string]any{}
|
||||||
|
for _, n := range names {
|
||||||
|
if v := arg(args, n); v != "" {
|
||||||
|
in[n] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raw, err := ask("seat:"+meshwants.Seat+"."+verb, in)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var out any
|
||||||
|
if err := json.Unmarshal(raw, &out); err != nil {
|
||||||
|
return nil, fmt.Errorf("%s answered what is not JSON: %w", verb, err)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
return []stdio.Tool{
|
||||||
|
{Name: compositionsTool, Description: "The composition runs the assigner keeps, one per candidate and machine (design 47 G §719, §728): each with " +
|
||||||
|
"its program, input digest, ask, readers, outcome and verdict, and the state's fill against its cap; with candidate or machine, only those. Read-only.",
|
||||||
|
Input: schema(map[string]string{"candidate": "the candidate's key: <branch>.<revision>, or run-<id>", "machine": "a machine"}, nil),
|
||||||
|
Run: func(args map[string]any) (any, error) {
|
||||||
|
return call(meshwants.VerbCompositions, args, "candidate", "machine")
|
||||||
|
}},
|
||||||
|
{Name: compositionsDropTool, Description: "Drop one composition run by hand (design 47 G §728): written in the hand-act log first, then its ask " +
|
||||||
|
"is dropped, each reader ended could not run naming the drop, and the key deleted.",
|
||||||
|
Input: schema(map[string]string{"candidate": "the candidate's key", "machine": "the machine", "why": "why the run is dropped"}, []string{"candidate", "machine", "why"}),
|
||||||
|
Run: func(args map[string]any) (any, error) {
|
||||||
|
return call(meshwants.VerbCompositionsDrop, args, "candidate", "machine", "why")
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G §728, A-469f, A-469u, A-469v: compositions answers each run with its key and the fill, only those of a candidate or
|
||||||
|
// machine when named; compositions-drop writes the hand act first (nothing is dropped when it is not recorded), drops a running
|
||||||
|
// run's ask, ends each reader could not run naming the drop and deletes the key with its bound keys; the tools call the verbs.
|
||||||
|
func TestTheCompositionRunsAreReadAndDroppedByTheirVerbs(t *testing.T) {
|
||||||
|
now := time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC)
|
||||||
|
kv := newRunsMem()
|
||||||
|
r := newCompositionRuns(kv, defaultRunSettings, func() time.Time { return now }, t.Logf)
|
||||||
|
var drops []string
|
||||||
|
r.drop = func(ask, why string) error { drops = append(drops, ask); return nil }
|
||||||
|
ends := newSaidEvents()
|
||||||
|
var endIDs []string // the message id of each end said
|
||||||
|
c := &compositionSteps{node: "n1", now: func() time.Time { return now }, logf: t.Logf, say: func(event string, body any, id string) error {
|
||||||
|
endIDs = append(endIDs, id)
|
||||||
|
return ends.say(event, body, id)
|
||||||
|
}}
|
||||||
|
moves := 0
|
||||||
|
move := func(meshwants.CompositionRun) { moves++ }
|
||||||
|
r.moved.Store(&move)
|
||||||
|
for _, m := range []string{"n1", "n2"} {
|
||||||
|
if _, err := r.join(readerOf("ask-a", meshwants.StepRun{Pipeline: "main.3.a", Step: meshwants.StepRunStepComposition, Module: "a"}), "main.3", m, "run-"+m); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A-470r: n2's run carries a reader that ended passed (p) and one marked rerun (q); only q's end is owed, said once.
|
||||||
|
_, _, _ = r.change(runKeyOf("main.3", "n2"), func(run *meshwants.CompositionRun) bool {
|
||||||
|
for _, id := range []string{"ask-p", "ask-q"} {
|
||||||
|
c := readerOf(id, meshwants.StepRun{Pipeline: "main.3." + id, Step: meshwants.StepRunStepComposition, Module: id})
|
||||||
|
c.Ended, c.Rerun = &now, id == "ask-q"
|
||||||
|
run.Readers = append(run.Readers, c)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
var recorded []meshhandactsclient.Request
|
||||||
|
record := func(q meshhandactsclient.Request) error { recorded = append(recorded, q); return nil }
|
||||||
|
verbs := compositionVerbs(r, c, record)
|
||||||
|
out, err := verbs[meshwants.VerbCompositions]("op", json.RawMessage(`{"machine":"n2"}`))
|
||||||
|
read, _ := out.(meshwants.CompositionsAnswer)
|
||||||
|
if err != nil || len(read.Runs) != 1 || read.Runs[0].Key != runKeyOf("main.3", "n2") || read.Runs[0].Ask != "run-n2" || len(read.Runs[0].Readers) != 3 ||
|
||||||
|
read.Fill.Store != "composition-runs" || read.Fill.Cap != 16<<20 || read.Fill.Bytes == 0 {
|
||||||
|
t.Fatalf("compositions = %+v %v", out, err)
|
||||||
|
}
|
||||||
|
refuse := compositionVerbs(r, c, func(meshhandactsclient.Request) error { return errors.New("no holder") })
|
||||||
|
if _, err := refuse[meshwants.VerbCompositionsDrop]("op", json.RawMessage(`{"candidate":"main.3","machine":"n2","why":"stuck"}`)); err == nil ||
|
||||||
|
!strings.Contains(err.Error(), "nothing was dropped") || len(drops) != 0 {
|
||||||
|
t.Fatalf("a drop not recorded: %v, drops %v", err, drops)
|
||||||
|
}
|
||||||
|
out, err = verbs[meshwants.VerbCompositionsDrop]("op@n1", json.RawMessage(`{"candidate":"main.3","machine":"n2","why":"stuck"}`))
|
||||||
|
dropped, _ := out.(meshwants.CompositionsDropAnswer)
|
||||||
|
if err != nil || dropped.Run.Key != runKeyOf("main.3", "n2") || len(dropped.Ended) != 2 || dropped.Ended[0].ID != "ask-a" || dropped.Ended[1].ID != "ask-q" ||
|
||||||
|
moves != 0 || len(endIDs) != 2 || endIDs[0] != "ask-a" || endIDs[1] != "ask-q.run-n2" ||
|
||||||
|
len(recorded) != 1 || recorded[0].Why != "stuck (op@n1)" || len(drops) != 1 || drops[0] != "run-n2" {
|
||||||
|
t.Fatalf("compositions-drop = %+v %v, recorded %+v, drops %v, moves %d, ends %v", out, err, recorded, drops, moves, endIDs)
|
||||||
|
}
|
||||||
|
end, _ := ends.said[meshwants.EventStepEnded+".n1"].(meshwants.StepEnded)
|
||||||
|
if end.ID != "ask-q" || end.Outcome != meshwants.StepEndedOutcomeCouldNotRun || !strings.Contains(end.Said, "dropped by hand: stuck") ||
|
||||||
|
len(end.Shared) != 1 || end.Shared[0].Ask != "run-n2" {
|
||||||
|
t.Errorf("the reader's end %+v", end)
|
||||||
|
}
|
||||||
|
if keys, _ := kv.keys(); len(keys) != 2 || keys[0] != runKeyOf("main.3", "n1") {
|
||||||
|
t.Errorf("keys after the drop %v, want n1's run and its untaken key", keys)
|
||||||
|
}
|
||||||
|
// The tools call the verbs with what they were given.
|
||||||
|
var asked []string
|
||||||
|
tools := compositionsTools(func(key string, body any) (json.RawMessage, error) {
|
||||||
|
raw, _ := json.Marshal(body)
|
||||||
|
asked = append(asked, key+" "+string(raw))
|
||||||
|
return json.RawMessage(`{"runs":[],"fill":{"store":"composition-runs","bytes":0,"cap":1}}`), nil
|
||||||
|
})
|
||||||
|
for _, tool := range tools {
|
||||||
|
if _, err := tool.Run(map[string]any{"candidate": "main.3", "machine": "n1", "why": "x"}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(tools) != 2 || tools[0].Name != compositionsTool || tools[1].Name != compositionsDropTool ||
|
||||||
|
asked[0] != `seat:mesh-wants.compositions {"candidate":"main.3","machine":"n1"}` || asked[1] != `seat:mesh-wants.compositions-drop {"candidate":"main.3","machine":"n1","why":"x"}` {
|
||||||
|
t.Errorf("the tools asked %v", asked)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,268 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
|
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The composition step (design 47 G §22, §354, §63): the assigner takes the seat mesh-wants' accepted kind `step`, the
|
||||||
|
// composition step of one module's pipeline that the runner asks, runs it, and says its end as the seat's event
|
||||||
|
// step-ended.<node>, the ask's id as the event's id and the event's `id`, which the runner holds the end to.
|
||||||
|
|
||||||
|
// stepOutcome is what one composition step came to.
|
||||||
|
type stepOutcome struct {
|
||||||
|
Outcome string
|
||||||
|
Said string
|
||||||
|
Warnings []string
|
||||||
|
// Shared names per machine composed the composition run the step read and its ask (design 47 G §723, §729).
|
||||||
|
Shared []meshwants.Shared
|
||||||
|
}
|
||||||
|
|
||||||
|
// compositionSteps takes the composition steps and says their ends.
|
||||||
|
type compositionSteps struct {
|
||||||
|
node string
|
||||||
|
// say says one event of the seat mesh-wants (wantsPublisher).
|
||||||
|
say publisher
|
||||||
|
// run runs one step and answers what it came to; resume judges a step taken up at the start from its runs (takeUp).
|
||||||
|
run func(ctx context.Context, id string, run meshwants.StepRun) stepOutcome
|
||||||
|
resume func(ctx context.Context, id string, run meshwants.StepRun) stepOutcome
|
||||||
|
// ended writes, once the step asked under id said its end, that time on its reader in each run naming it (A-470m); nil
|
||||||
|
// writes none.
|
||||||
|
ended func(id string, run meshwants.StepRun, at time.Time)
|
||||||
|
now func() time.Time
|
||||||
|
logf func(string, ...any)
|
||||||
|
// asker is the name the step's progress names as its asker, read when it is said (stepAskerOf).
|
||||||
|
asker func() string
|
||||||
|
// ticks is a ticker of every d, its channel and its stop (time.NewTicker); nil is the clock's. A test hands its own.
|
||||||
|
ticks func(d time.Duration) (<-chan time.Time, func())
|
||||||
|
mu sync.Mutex
|
||||||
|
// stops ends the wait of a running step by its ask's id, when its pipeline is superseded or cancelled (leave).
|
||||||
|
stops map[string]context.CancelFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
// stepAskerOf is the asker a composition step's progress names: the one caller the seat mesh-wants' definition lists for its
|
||||||
|
// accepted kind step, read from the seat list when it is said, since that subject names no asker (design 47 G A-294, which
|
||||||
|
// corrects A-267). Empty while the seat list holds no definition naming exactly one.
|
||||||
|
func stepAskerOf(definition func() (seatdef.Definition, bool)) func() string {
|
||||||
|
return func() string {
|
||||||
|
d, ok := definition()
|
||||||
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
var one string
|
||||||
|
for _, m := range d.Accepts {
|
||||||
|
if m.Name != meshwants.AcceptStep || m.Callers == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, e := range m.Callers.List {
|
||||||
|
name, isSeat := strings.CutPrefix(e, seatdef.CallerSeatPrefix)
|
||||||
|
if !isSeat || (one != "" && one != name) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
one = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return one
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// progressEvery is how often a running composition step says its progress (design 47 G §496, A-262).
|
||||||
|
const progressEvery = time.Minute
|
||||||
|
|
||||||
|
// stepPhase is the phase a running step is in: fetch, build, run or report (§496), set by the run through its context, and the
|
||||||
|
// composition runs it waits on (§723, §729).
|
||||||
|
type stepPhase struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
phase string
|
||||||
|
shared []meshwants.Shared
|
||||||
|
}
|
||||||
|
|
||||||
|
// setShared names the runs the step ctx runs waits on, when it runs one.
|
||||||
|
func setShared(ctx context.Context, shared []meshwants.Shared) {
|
||||||
|
if p, ok := ctx.Value(phaseKey{}).(*stepPhase); ok {
|
||||||
|
p.mu.Lock()
|
||||||
|
p.shared = shared
|
||||||
|
p.mu.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *stepPhase) waitsOn() []meshwants.Shared {
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
|
return p.shared
|
||||||
|
}
|
||||||
|
|
||||||
|
type phaseKey struct{}
|
||||||
|
|
||||||
|
// setPhase sets the phase of the step ctx runs, when it runs one.
|
||||||
|
func setPhase(ctx context.Context, phase string) {
|
||||||
|
if p, ok := ctx.Value(phaseKey{}).(*stepPhase); ok {
|
||||||
|
p.mu.Lock()
|
||||||
|
p.phase = phase
|
||||||
|
p.mu.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *stepPhase) get() string {
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
|
return p.phase
|
||||||
|
}
|
||||||
|
|
||||||
|
// take takes one ask of the accepted kind `step` by its id and body: a step that is no composition step, or an ask with no
|
||||||
|
// id, is left with a log line; one taken is run in its own goroutine and its end said.
|
||||||
|
func (c *compositionSteps) take(ctx context.Context, id string, data []byte) bool {
|
||||||
|
var run meshwants.StepRun
|
||||||
|
if err := json.Unmarshal(data, &run); err != nil || id == "" || run.Step != meshwants.StepRunStepComposition {
|
||||||
|
c.logf("a step ask that is no composition step with an id is left: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
go c.say1(ctx, id, run, c.run, "")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// say1 runs one step with how and says its end, naming in `shared` the runs it read (§723); again is, for an end said again, the
|
||||||
|
// ask of the run whose end makes it say again (sayEnd). A step whose wait was ended by its pipeline's supersede or cancel (leave)
|
||||||
|
// says nothing: the runner ended it already.
|
||||||
|
func (c *compositionSteps) say1(ctx context.Context, id string, run meshwants.StepRun, how func(context.Context, string, meshwants.StepRun) stepOutcome, again string) {
|
||||||
|
started := c.now().UTC()
|
||||||
|
ctx, stopWait := context.WithCancel(ctx)
|
||||||
|
c.mu.Lock()
|
||||||
|
if c.stops == nil {
|
||||||
|
c.stops = map[string]context.CancelFunc{}
|
||||||
|
}
|
||||||
|
if c.stops[id] != nil { // the step asked under id is running already: it says its own end
|
||||||
|
c.mu.Unlock()
|
||||||
|
stopWait()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.stops[id] = stopWait
|
||||||
|
c.mu.Unlock()
|
||||||
|
defer func() {
|
||||||
|
c.mu.Lock()
|
||||||
|
delete(c.stops, id)
|
||||||
|
c.mu.Unlock()
|
||||||
|
stopWait()
|
||||||
|
}()
|
||||||
|
phase := &stepPhase{phase: meshwants.StepProgressEventPhaseFetch}
|
||||||
|
stop := c.sayProgress(id, phase)
|
||||||
|
o := how(context.WithValue(ctx, phaseKey{}, phase), id, run)
|
||||||
|
stop()
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
c.logf("the composition step %s of %s says no end: its wait ended (%v)", id, run.Pipeline, context.Cause(ctx))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.sayEnd(id, run, &started, o, again)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sayEnd says the end of the step asked under id as the seat's step-ended.<node>, its id the ask's; once said, its time is
|
||||||
|
// written as its reader's `ended` (A-470m). Its first end's message id is the ask's id; an end said again is published under
|
||||||
|
// `<ask id>.<again>`, again the ask of the run whose end makes it say again, so the bus's deduplication never drops it (A-470q).
|
||||||
|
func (c *compositionSteps) sayEnd(id string, run meshwants.StepRun, started *time.Time, o stepOutcome, again string) {
|
||||||
|
ended := c.now().UTC()
|
||||||
|
if started == nil {
|
||||||
|
started = &ended
|
||||||
|
}
|
||||||
|
end := meshwants.StepEnded{V: 1, ID: id, Pipeline: run.Pipeline, Step: meshwants.StepEndedStepComposition, Module: run.Module,
|
||||||
|
Commit: run.Commit, Fingerprint: run.Fingerprint, Node: c.node, Outcome: o.Outcome, Said: o.Said, Warnings: o.Warnings,
|
||||||
|
Rerun: run.Rerun, By: run.By, Started: started, Ended: &ended, Shared: o.Shared}
|
||||||
|
msgID := id
|
||||||
|
if again != "" {
|
||||||
|
msgID = id + "." + again
|
||||||
|
}
|
||||||
|
if err := c.say(meshwants.EventStepEnded+"."+c.node, end, msgID); err != nil {
|
||||||
|
c.logf("saying the end of the composition step %s: %v", id, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if c.ended != nil {
|
||||||
|
c.ended(id, run, ended)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// move says the end again of each reader a rerun carried into an ended run, marked rerun (§727, A-470d): its machines judged
|
||||||
|
// from the candidate's keys naming it, the run's new ask in `shared`. A reader running here says its own end.
|
||||||
|
func (c *compositionSteps) move(ctx context.Context) func(run meshwants.CompositionRun) {
|
||||||
|
return func(run meshwants.CompositionRun) {
|
||||||
|
for _, reader := range run.Readers {
|
||||||
|
if !reader.Rerun || c.running(reader.ID) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
c.logf("the composition step %s of %s moves with the composition run of %s (ask %s)", reader.ID, reader.Pipeline, run.Machine, run.Ask)
|
||||||
|
go c.say1(ctx, reader.ID, stepRunOf(reader), c.resume, run.Ask) // said again under the moved run's ask (A-470q)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// running is whether the step asked under id runs here.
|
||||||
|
func (c *compositionSteps) running(id string) bool {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
return c.stops[id] != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// leave ends the waits of the steps asked under ids (§723: a superseded or cancelled step leaves its runs).
|
||||||
|
func (c *compositionSteps) leave(ids []string) {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
for _, id := range ids {
|
||||||
|
if stop := c.stops[id]; stop != nil {
|
||||||
|
stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sayProgress says the step's progress on the seat's step-progress.<node> once a minute until the returned stop is called (design
|
||||||
|
// 47 G §496, A-262): a ticker inside the running step, as the build seats' step runner says its own beat.
|
||||||
|
func (c *compositionSteps) sayProgress(id string, phase *stepPhase) (stop func()) {
|
||||||
|
ticks := c.ticks
|
||||||
|
if ticks == nil {
|
||||||
|
ticks = func(d time.Duration) (<-chan time.Time, func()) { t := time.NewTicker(d); return t.C, t.Stop }
|
||||||
|
}
|
||||||
|
tick, stopTicks := ticks(progressEvery)
|
||||||
|
done := make(chan struct{})
|
||||||
|
ended := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(ended)
|
||||||
|
defer stopTicks()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
return
|
||||||
|
case <-tick:
|
||||||
|
at := c.now().UTC()
|
||||||
|
p := meshwants.StepProgressEvent{Ask: id, Asker: c.asker(), Phase: phase.get(), At: at, Shared: phase.waitsOn()}
|
||||||
|
if err := c.say(meshwants.EventStepProgress+"."+c.node, p, id+".progress."+at.Format(time.RFC3339Nano)); err != nil {
|
||||||
|
c.logf("saying the progress of the composition step %s: %v", id, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return func() { close(done); <-ended }
|
||||||
|
}
|
||||||
|
|
||||||
|
// stepAskID is an ask's id as the asker names it: its event id, else its message id.
|
||||||
|
func stepAskID(m *nats.Msg) string {
|
||||||
|
if id := m.Header.Get("x-event-id"); id != "" {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
return m.Header.Get(nats.MsgIdHdr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// serveCompositionSteps hears the composition step asks on the seat mesh-wants' accept subject.
|
||||||
|
func serveCompositionSteps(ctx context.Context, conn process.Subscriber, c *compositionSteps) error {
|
||||||
|
sub, err := conn.Subscribe(meshwants.AcceptSubjectStep, func(m *nats.Msg) { c.take(ctx, stepAskID(m), m.Data) })
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
go func() { <-ctx.Done(); _ = sub.Drain() }()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
+243
@@ -0,0 +1,243 @@
|
|||||||
|
//go:build integration
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient/enginereads"
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G §354, §22, §63, §64, §389, A-240, A-252, A-254: the assigner started whole takes the runner's composition step of a
|
||||||
|
// module placed on three machines, one of them away: it asks the two others' node-engines for their inputs, puts one run ask per
|
||||||
|
// machine on the Go build seat's check queue under its name, its program the node-engine build each machine runs; the stand-in
|
||||||
|
// build seat reads each request by the seat mesh-wants' verb input in chunks and says its step-ended with the composer's verdict;
|
||||||
|
// the step's step-ended fails naming the machine that does not compose, warns of the machine away, and no input stays kept.
|
||||||
|
func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) {
|
||||||
|
b := startBed(t, "")
|
||||||
|
nc, err := nats.Connect(b.srv.ClientURL())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(nc.Close)
|
||||||
|
const engineCommit = "1111111111111111111111111111111111111111"
|
||||||
|
// The assigner's durable on EVENTS hears, beside the bed's, the build seat's step-ended and the watchman's machine-away and
|
||||||
|
// machine-back, as the grants part derives them from its consumes; what each node runs it hears on its kept stream (the bed's).
|
||||||
|
if _, err := b.js.CreateOrUpdateConsumer(b.ctx, "EVENTS", jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-assigner",
|
||||||
|
FilterSubjects: []string{enginereads.SubjectPrefix + "*", "mesh.mod." + buckets.IndexerModule + ".event.views.>", meshcatalog.SubjectCatalogRevisionAll,
|
||||||
|
nodebuildgo.SubjectStepEndedAll, meshwatchdogs.SubjectMachineAwayAll, meshwatchdogs.SubjectMachineBackAll}, AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, node := range []string{"n1", "n2"} {
|
||||||
|
raw, _ := json.Marshal(nodeengine.Running{V: 1, Node: node, Module: "engine", Fingerprint: "src2:e1", At: time.Now().UTC()})
|
||||||
|
if _, err := b.js.Publish(b.ctx, nodeengine.SubjectRunning(node, "engine"), raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
awaitKept(t, b, nodeengine.StreamRunning, 2)
|
||||||
|
away, _ := json.Marshal(meshwatchdogs.MachineAwayEvent{V: 1, Machine: "n3", At: time.Now().UTC(), LastHeard: time.Now().UTC()})
|
||||||
|
if _, err := b.js.Publish(b.ctx, meshwatchdogs.SubjectMachineAway("n3"), away); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// The trunk's catalog half holds the module and the node-engine, the module claiming the seat node-engine.
|
||||||
|
engine := meshcatalog.CatalogEntry{Module: "engine", Fp: "src2:e1", Repository: "novox/mesh-host", Commit: engineCommit, Path: ".",
|
||||||
|
Serves: []string{nodeengine.Seat + ".composition"}, Manifest: map[string]any{"module": "engine", "version": "0.1"}}
|
||||||
|
b.cat.mu.Lock()
|
||||||
|
b.cat.entries[trunkBranch] = map[string]meshcatalog.CatalogEntry{"engine": engine,
|
||||||
|
"m": {Module: "m", Fp: "src2:m1", Repository: "novox/m", Commit: engineCommit, Path: ".", Manifest: map[string]any{"module": "m", "version": "0.1"}}}
|
||||||
|
b.cat.rev[trunkBranch] = 3
|
||||||
|
b.cat.mu.Unlock()
|
||||||
|
for _, node := range []string{"n1", "n2", "n3"} {
|
||||||
|
b.place(t, node, "m")
|
||||||
|
}
|
||||||
|
// The node-engines of n1 and n2 answer compose-candidate with their inputs; n3 is never asked.
|
||||||
|
asked := make(chan string, 8)
|
||||||
|
engines, err := nc.Subscribe("mesh.seat.node-engine.call.compose-candidate.*.*", func(m *nats.Msg) {
|
||||||
|
node := strings.Split(m.Subject, ".")[5]
|
||||||
|
asked <- node
|
||||||
|
raw, _ := json.Marshal(map[string]any{"result": map[string]any{"candidate": "main.3", "node": node, "verdict": "composed", "input": map[string]any{"node": node},
|
||||||
|
"modules": []any{}, "own": map[string]any{}, "took": 1, "v": 1}, "node": node})
|
||||||
|
_ = m.Respond(raw)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(func() { _ = engines.Unsubscribe() })
|
||||||
|
// mesh-catalog's entry answers the node-engine build's entry by its fingerprint.
|
||||||
|
entries, err := nc.Subscribe("mesh.seat.mesh-catalog.call.entry.*", func(m *nats.Msg) {
|
||||||
|
raw, _ := json.Marshal(map[string]any{"result": meshcatalog.EntryAnswer{Entry: engine}, "node": "n0"})
|
||||||
|
_ = m.Respond(raw)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(func() { _ = entries.Unsubscribe() })
|
||||||
|
subscribed(t, nc)
|
||||||
|
// The runner hears the step's end.
|
||||||
|
ended := make(chan meshwants.StepEnded, 1)
|
||||||
|
ends, err := nc.Subscribe("mesh.seat.mesh-wants.event.step-ended.n1", func(m *nats.Msg) {
|
||||||
|
var e meshwants.StepEnded
|
||||||
|
_ = json.Unmarshal(m.Data, &e)
|
||||||
|
ended <- e
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(func() { _ = ends.Unsubscribe() })
|
||||||
|
subscribed(t, nc)
|
||||||
|
|
||||||
|
from := b.journal.mark()
|
||||||
|
b.start(t)
|
||||||
|
b.journal.await(t, from, "the composition step is heard on", "the composition step served", 30*time.Second)
|
||||||
|
b.journal.await(t, from, "n3 is away (machine-away)", "the machine-away of n3 heard", 30*time.Second)
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-b.seatListRead: // the seat server admits a caller of input once the seat list is read (A-278)
|
||||||
|
case <-time.After(30 * time.Second):
|
||||||
|
t.Fatal("the assigner did not read the seat list within 30 s")
|
||||||
|
}
|
||||||
|
step, _ := json.Marshal(meshwants.StepRun{Pipeline: "main.3.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch,
|
||||||
|
Revision: 3, Commit: engineCommit, Fingerprint: "src2:m1"})
|
||||||
|
msg := nats.NewMsg(meshwants.AcceptSubjectStep)
|
||||||
|
msg.Header.Set("x-event-id", "step-ask-1")
|
||||||
|
msg.Data = step
|
||||||
|
if err := nc.PublishMsg(msg); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The stand-in Go build seat takes the run asks put under the assigner's name, reads each request by the verb input and says
|
||||||
|
// its end with the composer's verdict: n1 composes, n2 does not.
|
||||||
|
queue, _ := buildstep.AskStream(buildstep.AskGo)
|
||||||
|
// A-163: the assigner asks under its seat's own name.
|
||||||
|
subject := "mesh.seat.node-build-go.accept.check.mesh-wants"
|
||||||
|
worker, err := b.js.CreateOrUpdateConsumer(b.ctx, queue, jetstream.ConsumerConfig{Durable: "stand-in", FilterSubject: subject, AckPolicy: jetstream.AckExplicitPolicy})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
programs := map[string]string{}
|
||||||
|
for range 2 {
|
||||||
|
got, err := worker.Next(jetstream.FetchMaxWait(30 * time.Second))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("no run ask is put: %v", err)
|
||||||
|
}
|
||||||
|
_ = got.Ack()
|
||||||
|
a, err := buildstep.DecodeStepAsk(got.Data())
|
||||||
|
if err != nil || a.Run == nil {
|
||||||
|
t.Fatalf("the run ask %s does not read: %v", got.Data(), err)
|
||||||
|
}
|
||||||
|
req, err := composer.Decode(readInput(t, nc, a.Run.Input))
|
||||||
|
if err != nil || len(req.Machines) != 1 {
|
||||||
|
t.Fatalf("the request of %s: %+v %v", a.ID, req, err)
|
||||||
|
}
|
||||||
|
if len(req.Seats) == 0 { // the revision names no definition: the request carries the trunk seat list's (A-467)
|
||||||
|
t.Errorf("the request of %s carries no seat definition", a.ID)
|
||||||
|
}
|
||||||
|
node := req.Machines[0]
|
||||||
|
programs[node] = a.Run.Program.Commit
|
||||||
|
m := composer.Machine{Composes: true}
|
||||||
|
if node == "n2" {
|
||||||
|
m = composer.Machine{Reason: "two modules own one path", Problems: []string{"/etc/x"}}
|
||||||
|
}
|
||||||
|
v, _ := json.Marshal(composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{{Name: changeCase, Machines: map[string]composer.Machine{node: m}}}})
|
||||||
|
end, _ := json.Marshal(buildstep.StepEnded{V: 1, ID: a.ID, Ask: a.ID, Asker: runAsker, Node: "b1", Outcome: buildstep.OutcomePassed, Output: string(v), At: time.Now().UTC()})
|
||||||
|
if _, err := b.js.Publish(b.ctx, nodebuildgo.SubjectStepEnded("b1"), end); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var e meshwants.StepEnded
|
||||||
|
select {
|
||||||
|
case e = <-ended:
|
||||||
|
case <-b.ctx.Done():
|
||||||
|
t.Fatal("the composition step said no end")
|
||||||
|
}
|
||||||
|
if e.ID != "step-ask-1" || e.Outcome != meshwants.StepEndedOutcomeFailed || !strings.Contains(e.Said, "n2 does not compose") ||
|
||||||
|
strings.Contains(e.Said, "n1") || len(e.Warnings) != 2 || !strings.Contains(e.Warnings[0], "n3 is away") ||
|
||||||
|
e.Warnings[1] != "n2: the composer names no culprits" {
|
||||||
|
t.Fatalf("the step ended %+v", e)
|
||||||
|
}
|
||||||
|
if programs["n1"] != engineCommit || programs["n2"] != engineCommit {
|
||||||
|
t.Errorf("the composers were built at %v, want the node-engine build each machine runs", programs)
|
||||||
|
}
|
||||||
|
close(asked)
|
||||||
|
for node := range asked {
|
||||||
|
if node == "n3" {
|
||||||
|
t.Error("the machine away was asked for its input")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The run's end comes before the input's delete (A-470o, A-470p): the inputs go after the step's end, heard by their watch.
|
||||||
|
inputs := b.buckets[buckets.Inputs()]
|
||||||
|
w, err := inputs.WatchAll(b.ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() { _ = w.Stop() }()
|
||||||
|
deadline := time.After(10 * time.Second)
|
||||||
|
for {
|
||||||
|
keys, _ := inputs.Keys(b.ctx)
|
||||||
|
if len(keys) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-w.Updates():
|
||||||
|
case <-deadline:
|
||||||
|
t.Fatalf("the inputs stay kept past their step-ended: %v", keys)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// readInput reads a run's input as a build seat does: the seat mesh-wants' verb input answers its digest and chunk count, then its
|
||||||
|
// chunks on the call's subjects, each acknowledged.
|
||||||
|
func readInput(t *testing.T, nc *nats.Conn, in buildstep.RunInput) []byte {
|
||||||
|
t.Helper()
|
||||||
|
call := "standin" + strings.Repeat("0", 16)
|
||||||
|
chunks := buscalls.SeatChunks{Seat: meshwants.Seat, Verb: meshwants.VerbInput, Call: call}
|
||||||
|
sub, err := nc.SubscribeSync(chunks.Chunks())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer sub.Unsubscribe()
|
||||||
|
body, _ := json.Marshal(meshwants.InputInput{Digest: in.Digest, Call: call})
|
||||||
|
// On the call's subject naming its caller, the stand-in build seat's account: the seat server admits no unproven caller (A-179).
|
||||||
|
reply, err := nc.Request("mesh.seat.mesh-wants.call.input.n1~mesh-build-go", body, 10*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
raw, said, ok := buscalls.Unwrap(reply.Data)
|
||||||
|
var a meshwants.InputAnswer
|
||||||
|
if !ok || json.Unmarshal(raw, &a) != nil || a.Chunks < 1 {
|
||||||
|
t.Fatalf("the verb input answered %s: %s", reply.Data, said)
|
||||||
|
}
|
||||||
|
var out bytes.Buffer
|
||||||
|
next := func() (string, []byte, error) {
|
||||||
|
m, err := sub.NextMsg(buscalls.SeatAckWithin)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
return m.Subject, m.Data, nil
|
||||||
|
}
|
||||||
|
ack := func(subject string) error { _, err := nc.Request(subject, nil, 10*time.Second); return err }
|
||||||
|
if _, err := chunks.Receive(a.Chunks, next, ack, &out); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := in.Verify(out.Bytes()); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return out.Bytes()
|
||||||
|
}
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
)
|
||||||
|
|
||||||
|
// saidEvents keeps what a publisher says.
|
||||||
|
type saidEvents struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
said map[string]any
|
||||||
|
ids map[string]string
|
||||||
|
heard chan string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSaidEvents() *saidEvents {
|
||||||
|
return &saidEvents{said: map[string]any{}, ids: map[string]string{}, heard: make(chan string, 8)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *saidEvents) say(event string, body any, id string) error {
|
||||||
|
s.mu.Lock()
|
||||||
|
s.said[event], s.ids[event] = body, id
|
||||||
|
s.mu.Unlock()
|
||||||
|
s.heard <- event
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AS5 (§22, §354): the assigner takes mesh-wants' accepted kind `step` for the composition step and says the seat's
|
||||||
|
// step-ended.<node> with the ask's id, what the step was asked at and what it came to; an ask of another step is left.
|
||||||
|
func TestTheCompositionStepIsTakenAndItsEndSaid(t *testing.T) {
|
||||||
|
said := newSaidEvents()
|
||||||
|
at := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
|
||||||
|
var asked meshwants.StepRun
|
||||||
|
c := &compositionSteps{node: "n1", say: said.say, now: func() time.Time { return at }, logf: t.Logf,
|
||||||
|
run: func(_ context.Context, id string, run meshwants.StepRun) stepOutcome {
|
||||||
|
asked = run
|
||||||
|
return stepOutcome{Outcome: meshwants.StepEndedOutcomeFailed, Said: "a and b own /etc/x", Warnings: []string{"n3 asleep"},
|
||||||
|
Shared: []meshwants.Shared{{Machine: "n1", Run: "main=2e4.n1", Ask: "run-1"}}}
|
||||||
|
}}
|
||||||
|
other, _ := json.Marshal(map[string]any{"pipeline": "main.4.m", "step": "build", "module": "m"})
|
||||||
|
if c.take(context.Background(), "ask-0", other) {
|
||||||
|
t.Fatal("a step ask of another step is taken")
|
||||||
|
}
|
||||||
|
body, _ := json.Marshal(meshwants.StepRun{Pipeline: "main.4.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: "main",
|
||||||
|
Commit: "c0ffee", Revision: 4, Fingerprint: "fp1", Rerun: true, By: "lead@n1"})
|
||||||
|
if c.take(context.Background(), "", body) {
|
||||||
|
t.Fatal("a step ask with no id is taken")
|
||||||
|
}
|
||||||
|
if !c.take(context.Background(), "ask-1", body) {
|
||||||
|
t.Fatal("the composition step is not taken")
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-said.heard:
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
t.Fatal("no step-ended is said")
|
||||||
|
}
|
||||||
|
event := meshwants.EventStepEnded + ".n1"
|
||||||
|
end, ok := said.said[event].(meshwants.StepEnded)
|
||||||
|
if !ok || said.ids[event] != "ask-1" {
|
||||||
|
t.Fatalf("said %v under %v, want step-ended.n1 under the ask's id", said.said, said.ids)
|
||||||
|
}
|
||||||
|
if asked.Module != "m" || end.ID != "ask-1" || end.Pipeline != "main.4.m" || end.Step != meshwants.StepEndedStepComposition ||
|
||||||
|
end.Module != "m" || end.Commit != "c0ffee" || end.Fingerprint != "fp1" || end.Node != "n1" ||
|
||||||
|
end.Outcome != meshwants.StepEndedOutcomeFailed || end.Said != "a and b own /etc/x" || len(end.Warnings) != 1 ||
|
||||||
|
!end.Rerun || end.By != "lead@n1" || end.Started == nil || end.Ended == nil ||
|
||||||
|
len(end.Shared) != 1 || end.Shared[0] != (meshwants.Shared{Machine: "n1", Run: "main=2e4.n1", Ask: "run-1"}) { // §723, §729
|
||||||
|
t.Fatalf("step-ended %+v", end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §496, A-262: a running composition step says step-progress.<node> on every tick of its ticker, with the ask, its
|
||||||
|
// asker, the phase the run is in and the time, and says none once it has ended.
|
||||||
|
func TestARunningCompositionStepSaysItsProgress(t *testing.T) {
|
||||||
|
said := newSaidEvents()
|
||||||
|
tick := make(chan time.Time)
|
||||||
|
stopped := make(chan struct{})
|
||||||
|
at := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
|
||||||
|
release := make(chan struct{})
|
||||||
|
// A-294: the asker is the one caller mesh-wants' definition lists for step, read from the seat list; none while unread
|
||||||
|
// or while it lists more than one.
|
||||||
|
runner := seatdef.Definition{Seat: meshwants.Seat, Accepts: []seatdef.Message{{Name: meshwants.AcceptStep,
|
||||||
|
Callers: &seatdef.Callers{List: []string{"seat:mesh-pipeline-runner"}}}}}
|
||||||
|
two := seatdef.Definition{Seat: meshwants.Seat, Accepts: []seatdef.Message{{Name: meshwants.AcceptStep,
|
||||||
|
Callers: &seatdef.Callers{List: []string{"seat:mesh-pipeline-runner", "seat:mesh-catalog"}}}}}
|
||||||
|
for _, d := range []struct {
|
||||||
|
def seatdef.Definition
|
||||||
|
read bool
|
||||||
|
want string
|
||||||
|
}{{runner, true, "mesh-pipeline-runner"}, {runner, false, ""}, {two, true, ""}} {
|
||||||
|
if got := stepAskerOf(func() (seatdef.Definition, bool) { return d.def, d.read })(); got != d.want {
|
||||||
|
t.Errorf("the asker of %+v (read %v) = %q, want %q", d.def.Accepts, d.read, got, d.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c := &compositionSteps{node: "n1", say: said.say, now: func() time.Time { return at }, logf: t.Logf,
|
||||||
|
asker: stepAskerOf(func() (seatdef.Definition, bool) { return runner, true }),
|
||||||
|
ticks: func(d time.Duration) (<-chan time.Time, func()) {
|
||||||
|
if d != time.Minute {
|
||||||
|
t.Errorf("the progress ticks every %s, want a minute", d)
|
||||||
|
}
|
||||||
|
return tick, func() { close(stopped) }
|
||||||
|
},
|
||||||
|
run: func(ctx context.Context, _ string, _ meshwants.StepRun) stepOutcome {
|
||||||
|
setPhase(ctx, meshwants.StepProgressEventPhaseRun)
|
||||||
|
setShared(ctx, []meshwants.Shared{{Machine: "n1", Run: "main=2e4.n1", Ask: "run-1"}})
|
||||||
|
<-release
|
||||||
|
return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed}
|
||||||
|
}}
|
||||||
|
body, _ := json.Marshal(meshwants.StepRun{Pipeline: "main.4.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: "main"})
|
||||||
|
if !c.take(context.Background(), "ask-1", body) {
|
||||||
|
t.Fatal("the composition step is not taken")
|
||||||
|
}
|
||||||
|
progress := meshwants.EventStepProgress + ".n1"
|
||||||
|
for range 2 {
|
||||||
|
tick <- at
|
||||||
|
if e := <-said.heard; e != progress {
|
||||||
|
t.Fatalf("said %s on a tick, want %s", e, progress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
said.mu.Lock()
|
||||||
|
p, ok := said.said[progress].(meshwants.StepProgressEvent)
|
||||||
|
said.mu.Unlock()
|
||||||
|
if !ok || p.Ask != "ask-1" || p.Asker != "mesh-pipeline-runner" || p.Phase != meshwants.StepProgressEventPhaseRun || !p.At.Equal(at) ||
|
||||||
|
len(p.Shared) != 1 || p.Shared[0].Ask != "run-1" { // the runs the step waits on (§723)
|
||||||
|
t.Fatalf("step-progress %+v", p)
|
||||||
|
}
|
||||||
|
close(release)
|
||||||
|
if e := <-said.heard; e != meshwants.EventStepEnded+".n1" {
|
||||||
|
t.Fatalf("said %s at the end, want step-ended", e)
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-stopped:
|
||||||
|
default:
|
||||||
|
t.Fatal("the ticker is not stopped when the step has ended")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §723, A-469n, A-469z: a superseded or cancelled pipeline's composition step leaves the runs it reads and says no end;
|
||||||
|
// a run another pipeline's step reads goes on for it; a run left with no reader has its ask dropped and ends could not run, "no
|
||||||
|
// reader is left", so a later step starts a new run.
|
||||||
|
func TestASupersededStepLeavesItsRuns(t *testing.T) {
|
||||||
|
now := time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC)
|
||||||
|
r := newCompositionRuns(newRunsMem(), defaultRunSettings, func() time.Time { return now }, t.Logf)
|
||||||
|
var drops []string
|
||||||
|
r.drop = func(ask, why string) error { drops = append(drops, ask+": "+why); return nil }
|
||||||
|
step := func(pipeline string) meshwants.StepRun {
|
||||||
|
return meshwants.StepRun{Pipeline: pipeline, Step: meshwants.StepRunStepComposition, Module: pipeline, Branch: "main", Revision: 3}
|
||||||
|
}
|
||||||
|
said := newSaidEvents()
|
||||||
|
c := &compositionSteps{node: "n1", say: said.say, now: func() time.Time { return now }, logf: t.Logf,
|
||||||
|
run: func(ctx context.Context, id string, s meshwants.StepRun) stepOutcome {
|
||||||
|
j, err := r.join(readerOf(id, s), "main.3", "n1", "run-"+id)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
r.await(ctx, []string{j.key})
|
||||||
|
return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed}
|
||||||
|
}}
|
||||||
|
body := func(s meshwants.StepRun) []byte { raw, _ := json.Marshal(s); return raw }
|
||||||
|
for _, p := range []string{"main.3.a", "main.3.b"} {
|
||||||
|
if !c.take(context.Background(), "ask-"+p, body(step(p))) {
|
||||||
|
t.Fatal("not taken")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
key := runKeyOf("main.3", "n1")
|
||||||
|
for {
|
||||||
|
wake := r.wake()
|
||||||
|
if run, _, _, _ := r.read(key); len(run.Readers) == 2 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
<-wake
|
||||||
|
}
|
||||||
|
ids, err := r.leave("main.3.a", c.leave)
|
||||||
|
run, _, _, _ := r.read(key)
|
||||||
|
if err != nil || !slices.Equal(ids, []string{"ask-main.3.a"}) || run.Ended != nil || len(run.Readers) != 1 || len(drops) != 0 {
|
||||||
|
t.Fatalf("after a's supersede: %v %v, run %+v, drops %v: want the run going on for b", ids, err, run, drops)
|
||||||
|
}
|
||||||
|
_, err = r.leave("main.3.b", c.leave)
|
||||||
|
run, _, _, _ = r.read(key)
|
||||||
|
if err != nil || run.Outcome != meshwants.CompositionRunOutcomeCouldNotRun || !strings.Contains(run.Said, "no reader is left") || len(drops) != 1 ||
|
||||||
|
!strings.HasPrefix(drops[0], run.Ask+": no reader is left") {
|
||||||
|
t.Fatalf("after b's supersede: %v, run %+v, drops %v", err, run, drops)
|
||||||
|
}
|
||||||
|
deadline := time.After(5 * time.Second)
|
||||||
|
for {
|
||||||
|
c.mu.Lock()
|
||||||
|
n := len(c.stops)
|
||||||
|
c.mu.Unlock()
|
||||||
|
if n == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-deadline:
|
||||||
|
t.Fatal("the steps that left still wait")
|
||||||
|
case <-time.After(time.Millisecond):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
said.mu.Lock()
|
||||||
|
defer said.mu.Unlock()
|
||||||
|
if _, ok := said.said[meshwants.EventStepEnded+".n1"]; ok {
|
||||||
|
t.Errorf("a step that left says its end: %v", said.said)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,454 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
wd "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/assignment"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A delivery is waited for mesh-wide (design 47 G §376, §389, A-189, A-246). At its start the assigner reads whole, from their first
|
||||||
|
// message, the streams of the catalog seat's version-released and of its own version-delivered (mesh-sdk process.FromFirst, A-233),
|
||||||
|
// and the watchman's machine-away and machine-back, never its state; then it hears them. A released version of a module is said
|
||||||
|
// version-delivered on the seat mesh-wants once, when every present machine placing it on the branch it is released from runs, healthy,
|
||||||
|
// the want the assigner wrote naming that version; a version no present machine places is not delivered. A dependent whose want
|
||||||
|
// changes fingerprint waits, by an edge of kind 2, 4 or 6, for its dependency's newest released version not yet said delivered, on
|
||||||
|
// the branch it is released from; on another branch no version is released and nothing waits. The wait is said wait-held, step
|
||||||
|
// delivery, bound 60 minutes from the version's release, kept in the state delivery-waits under the dependent's name, and said
|
||||||
|
// wait-ended when the version is delivered (ran) or released by hand (assigner_release, released).
|
||||||
|
|
||||||
|
// deliveryWaitBound is a dependent's delivery wait's bound, from its dependency's version-released.
|
||||||
|
const deliveryWaitBound = 60 * time.Minute
|
||||||
|
|
||||||
|
// Wait-ended's how of a delivery wait.
|
||||||
|
const (
|
||||||
|
deliveryWaitRan = "ran"
|
||||||
|
deliveryWaitReleased = "released"
|
||||||
|
)
|
||||||
|
|
||||||
|
// releaseHeard is one version-released heard: the version, each part's digest, the source revision and when it was said.
|
||||||
|
type releaseHeard struct {
|
||||||
|
Version string
|
||||||
|
Parts map[string]string
|
||||||
|
Source int64
|
||||||
|
At time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// newestOf is the newest version of module released, the last heard of it in the stream's order.
|
||||||
|
func (r *releasedVersions) newestOf(module string) (releaseHeard, bool) {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
h, ok := r.newest[module]
|
||||||
|
return h, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// deliveredVersions are the version-delivered said, the assigner's own, by module and version: each is said once.
|
||||||
|
type deliveredVersions struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
said map[string]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deliveredVersions) key(module, version string) string { return module + "@" + version }
|
||||||
|
|
||||||
|
// put takes one version-delivered in.
|
||||||
|
func (d *deliveredVersions) put(data []byte) error {
|
||||||
|
var e meshwants.VersionDeliveredEvent
|
||||||
|
if err := json.Unmarshal(data, &e); err != nil {
|
||||||
|
return fmt.Errorf("a version-delivered that is none: %w", err)
|
||||||
|
}
|
||||||
|
if e.Module == "" || e.Version == "" {
|
||||||
|
return fmt.Errorf("a version-delivered naming no module or version: %s", data)
|
||||||
|
}
|
||||||
|
d.mark(e.Module, e.Version)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deliveredVersions) mark(module, version string) {
|
||||||
|
d.mu.Lock()
|
||||||
|
defer d.mu.Unlock()
|
||||||
|
if d.said == nil {
|
||||||
|
d.said = map[string]bool{}
|
||||||
|
}
|
||||||
|
d.said[d.key(module, version)] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// has says whether version-delivered of module's version was said.
|
||||||
|
func (d *deliveredVersions) has(module, version string) bool {
|
||||||
|
d.mu.Lock()
|
||||||
|
defer d.mu.Unlock()
|
||||||
|
return d.said[d.key(module, version)]
|
||||||
|
}
|
||||||
|
|
||||||
|
// presenceOf reads one machine-away or machine-back: the machine and when it was said.
|
||||||
|
func presenceOf(data []byte) (string, time.Time, error) {
|
||||||
|
var e wd.MachineAwayEvent // machine-back has the same fields
|
||||||
|
if err := json.Unmarshal(data, &e); err != nil {
|
||||||
|
return "", time.Time{}, err
|
||||||
|
}
|
||||||
|
if e.Machine == "" {
|
||||||
|
return "", time.Time{}, fmt.Errorf("it names no machine: %s", data)
|
||||||
|
}
|
||||||
|
return e.Machine, e.At, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearDelivery reads whole, then follows, the four streams a delivery is judged from: version-released, version-delivered,
|
||||||
|
// machine-away and machine-back. A stream not heard is said as the assigner's finding, and what it carries is not known until
|
||||||
|
// the assigner starts again.
|
||||||
|
func hearDelivery(ctx context.Context, js jetstream.JetStream, w *world, wake func(), findings assign.Findings, logf func(string, ...any)) {
|
||||||
|
acct := process.Account{Node: thisNode, Module: assignment.Module()}
|
||||||
|
nh := notHeardWriter(findings, logf)
|
||||||
|
for _, s := range []struct {
|
||||||
|
stream, words string
|
||||||
|
take func([]byte) error
|
||||||
|
}{
|
||||||
|
{meshcatalog.StreamVersionReleased, "no want names a released version and no delivery is judged", w.released.put},
|
||||||
|
{meshwants.StreamVersionDelivered, "a version said delivered before is said again once it is judged", w.delivered.put},
|
||||||
|
{wd.StreamMachineAway, "no machine is known away, so a delivery waits for a machine that is away", func(data []byte) error {
|
||||||
|
m, at, err := presenceOf(data)
|
||||||
|
if err == nil {
|
||||||
|
w.heardPresence(m, true, at)
|
||||||
|
logf("%s is away (machine-away): a composition step does not compose it until its machine-back", m)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}},
|
||||||
|
{wd.StreamMachineBack, "a machine once away is not known back", func(data []byte) error {
|
||||||
|
m, at, err := presenceOf(data)
|
||||||
|
if err == nil {
|
||||||
|
w.heardPresence(m, false, at)
|
||||||
|
logf("%s is back (machine-back): a composition step composes it again", m)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}},
|
||||||
|
} {
|
||||||
|
take := s.take
|
||||||
|
cc, err := acct.HearSeatEvents(ctx, js, s.stream, func(m jetstream.Msg) {
|
||||||
|
if err := take(m.Data()); err != nil {
|
||||||
|
logf("%s is not kept: %v", m.Subject(), err)
|
||||||
|
}
|
||||||
|
if err := m.Ack(); err != nil {
|
||||||
|
logf("acknowledging %s: %v", m.Subject(), err)
|
||||||
|
}
|
||||||
|
wake()
|
||||||
|
}, logf, process.FromFirst())
|
||||||
|
if err != nil {
|
||||||
|
nh.NotHeard(s.stream, s.words+" until the assigner starts again", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
nh.Heard(s.stream)
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
cc.Stop()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// releaseBranch is the branch module's versions are released from: the first watched branch of its registration (§371).
|
||||||
|
func (p *passer) releaseBranch(module string) string {
|
||||||
|
if p.ends.following() {
|
||||||
|
return p.ends.branchOf(module, "")
|
||||||
|
}
|
||||||
|
return p.w.trunkName()
|
||||||
|
}
|
||||||
|
|
||||||
|
// placing is every machine placing module on the branch its versions are released from, sorted.
|
||||||
|
func (p *passer) placing(module string) []string {
|
||||||
|
branch := p.releaseBranch(module)
|
||||||
|
var out []string
|
||||||
|
for node, placed := range p.w.placedBranches()[module] {
|
||||||
|
if p.ends.following() {
|
||||||
|
placed = p.ends.branchOf(module, placed)
|
||||||
|
} else {
|
||||||
|
placed = p.w.trunkName() // the trunk-only form: every placement runs the trunk's
|
||||||
|
}
|
||||||
|
if placed == branch {
|
||||||
|
out = append(out, node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// deliveryStanding is where module's version stands: the present placing machines not yet running it healthy as its want names
|
||||||
|
// it, and the placing machines away.
|
||||||
|
func (p *passer) deliveryStanding(module, version string) (notRunning, away []string, placing int) {
|
||||||
|
gone := p.w.awayNow()
|
||||||
|
n := assign.Nodes{Running: p.w.runningNow()}
|
||||||
|
wanted := p.w.wantsOf()[module]
|
||||||
|
nodes := p.placing(module)
|
||||||
|
for _, node := range nodes {
|
||||||
|
if gone[node] {
|
||||||
|
away = append(away, node)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
want, ok := wanted[node]
|
||||||
|
if !ok || want.Removed || want.Version != version || !n.RunsHealthy(node, module, want.Fp) {
|
||||||
|
notRunning = append(notRunning, node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return notRunning, away, len(nodes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// judgeDelivered says version-delivered of each module's newest released version not said yet, once every present machine placing
|
||||||
|
// it runs it healthy; judged again at each pass, which each running, machine-away, machine-back and placement change wakes.
|
||||||
|
func (p *passer) judgeDelivered() {
|
||||||
|
for _, module := range p.releasedModules() {
|
||||||
|
rel, _ := p.w.released.newestOf(module)
|
||||||
|
if p.w.delivered.has(module, rel.Version) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
notRunning, away, placing := p.deliveryStanding(module, rel.Version)
|
||||||
|
if placing == 0 || len(away) == placing || len(notRunning) > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := p.sayDelivered(module, rel, away); err != nil {
|
||||||
|
p.logf("version-delivered of %s %s is not said, and is judged again at the next pass: %v", module, rel.Version, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sayDelivered says version-delivered of module's release rel, with the machines away, and keeps it said.
|
||||||
|
func (p *passer) sayDelivered(module string, rel releaseHeard, away []string) error {
|
||||||
|
at := p.clock().UTC()
|
||||||
|
body := meshwants.VersionDeliveredEvent{V: keys.Version, Module: module, Version: rel.Version, Parts: rel.Parts, Away: away, At: &at}
|
||||||
|
if err := p.wantsSay(meshwants.EventVersionDelivered, body, fmt.Sprintf("%s.%s.%s.%s", meshwants.EventVersionDelivered, module, rel.Version, at.Format(time.RFC3339Nano))); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.w.delivered.mark(module, rel.Version)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// releasedModules is every module a version-released was heard of, sorted.
|
||||||
|
func (p *passer) releasedModules() []string {
|
||||||
|
r := &p.w.released
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
out := make([]string, 0, len(r.newest))
|
||||||
|
for m := range r.newest {
|
||||||
|
out = append(out, m)
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// deliveryWait is what a dependent waits for: its dependency, the version and the machines not yet running it.
|
||||||
|
type deliveryWait struct {
|
||||||
|
dependency string
|
||||||
|
rel releaseHeard
|
||||||
|
notRunning []string
|
||||||
|
away []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitsForDelivery says whether module, whose want on its nodes changes to fp on branch, waits for a dependency's delivery: by
|
||||||
|
// each edge of kind 2, 4 or 6 into it in branch's catalog half, the dependency's newest released version on branch not yet said
|
||||||
|
// delivered. A want that changes no fingerprint waits for nothing; on a branch no version is released from, nothing waits.
|
||||||
|
func (p *passer) waitsForDelivery(module, fp, branch string, nodes []string) (deliveryWait, bool) {
|
||||||
|
wanted := p.w.wantsOf()[module]
|
||||||
|
changes := false
|
||||||
|
for _, node := range nodes {
|
||||||
|
if w, ok := wanted[node]; !ok || w.Removed || w.Fp != fp {
|
||||||
|
changes = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !changes || fp == "" {
|
||||||
|
return deliveryWait{}, false
|
||||||
|
}
|
||||||
|
var deps []string
|
||||||
|
for _, e := range p.w.edgesOf(branch, module) {
|
||||||
|
if e.Kind != 2 && e.Kind != 4 && e.Kind != 6 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dep, _, _ := strings.Cut(e.From, ":")
|
||||||
|
if dep != "" && dep != module && !slices.Contains(deps, dep) {
|
||||||
|
deps = append(deps, dep)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(deps)
|
||||||
|
for _, dep := range deps {
|
||||||
|
if p.releaseBranch(dep) != branch {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
rel, ok := p.w.released.newestOf(dep)
|
||||||
|
if !ok || p.w.delivered.has(dep, rel.Version) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
notRunning, away, _ := p.deliveryStanding(dep, rel.Version)
|
||||||
|
return deliveryWait{dependency: dep, rel: rel, notRunning: notRunning, away: away}, true
|
||||||
|
}
|
||||||
|
return deliveryWait{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// words is a delivery wait in plain words, as assigner_why_not and the status view say it.
|
||||||
|
func (d deliveryWait) words() string {
|
||||||
|
if len(d.notRunning) == 0 && len(d.away) > 0 {
|
||||||
|
return fmt.Sprintf("waiting for %s to be back", strings.Join(d.away, ", "))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("waiting for delivery of %s %s on %s", d.dependency, d.rel.Version, strings.Join(d.notRunning, ", "))
|
||||||
|
}
|
||||||
|
|
||||||
|
// deliveryWaitBody is the wait-held of module's delivery wait d.
|
||||||
|
func deliveryWaitBody(module, fp string, d deliveryWait, since time.Time) meshwants.Wait {
|
||||||
|
from := d.rel.At.UTC()
|
||||||
|
if from.IsZero() {
|
||||||
|
from = since.UTC()
|
||||||
|
}
|
||||||
|
return meshwants.Wait{Step: meshwants.WaitStepDelivery, Owner: meshwants.Seat, Module: module, Version: fp, Part: d.dependency,
|
||||||
|
On: d.dependency + "@" + d.rel.Version, Machines: d.notRunning, Since: since.UTC(), ClockFrom: &from, Bound: deliveryWaitBound.String(),
|
||||||
|
Words: d.words()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// deliveryWaiting is one delivery wait the state delivery-waits keeps, by its dependent's name: the wait-held said, and a release
|
||||||
|
// by hand written by assigner_release.
|
||||||
|
type deliveryWaiting struct {
|
||||||
|
meshwants.Wait
|
||||||
|
// Released is set by assigner_release: the wait ends released and the dependent's want is written.
|
||||||
|
Released bool `json:"released,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// saidDeliveryWaits is every delivery wait the state delivery-waits holds, by module; a value that does not decode is said and left.
|
||||||
|
func (p *passer) saidDeliveryWaits() map[string]deliveryWaiting {
|
||||||
|
out := map[string]deliveryWaiting{}
|
||||||
|
for key, value := range p.w.read(buckets.DeliveryWaits()) {
|
||||||
|
var w deliveryWaiting
|
||||||
|
if err := json.Unmarshal(value, &w); err != nil || w.Module == "" {
|
||||||
|
p.logf("%s %s holds no delivery wait, left: %v", buckets.DeliveryWaits(), key, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out[w.Module] = w
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// holdForDelivery says whether module's want, changing to fp on branch, is held for a dependency's delivery this pass: it says
|
||||||
|
// wait-held once and keeps it; a wait released by hand holds nothing; a wait that no longer holds is ended ran.
|
||||||
|
func (p *passer) holdForDelivery(ctx context.Context, module, fp, branch string, nodes []string) bool {
|
||||||
|
if p.kvs[buckets.DeliveryWaits()] == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
key := keys.EscapeName(module)
|
||||||
|
said, was := p.saidDeliveryWaits()[module]
|
||||||
|
d, waits := p.waitsForDelivery(module, fp, branch, nodes)
|
||||||
|
switch {
|
||||||
|
case was && said.Released:
|
||||||
|
p.endDeliveryWait(ctx, key, said, deliveryWaitReleased) // the want is written now, so it changes nothing at the next pass
|
||||||
|
return false
|
||||||
|
case !waits:
|
||||||
|
if was {
|
||||||
|
p.endDeliveryWait(ctx, key, said, deliveryWaitRan)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
body := deliveryWaitBody(module, fp, d, p.clock())
|
||||||
|
if was && said.On == body.On && said.Version == fp && slices.Equal(said.Machines, body.Machines) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if was {
|
||||||
|
body.Since = said.Since
|
||||||
|
}
|
||||||
|
id := fmt.Sprintf("%s.delivery.%s.%s.%s", key, fp, body.On, strings.Join(body.Machines, ","))
|
||||||
|
if err := p.wantsSay(meshwants.EventWaitHeld, body, id); err != nil {
|
||||||
|
p.logf("the delivery wait of %s is not said, and is said at the next pass: %v", module, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
kept := deliveryWaiting{Wait: body}
|
||||||
|
p.put(ctx, buckets.DeliveryWaits(), key, func() ([]byte, error) { return json.Marshal(kept) })
|
||||||
|
p.logf("%s at %s on %s waits for the delivery of its dependency %s on %s: the rules write no want of it until then (design 47 G §376)", module, shortHex(fp), branch, body.On, strings.Join(body.Machines, ", "))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// endDeliveryWait says wait-ended of a delivery wait with how and removes it from the state.
|
||||||
|
func (p *passer) endDeliveryWait(ctx context.Context, key string, w deliveryWaiting, how string) {
|
||||||
|
body := w.Wait
|
||||||
|
body.How = how
|
||||||
|
if err := p.wantsSay(meshwants.EventWaitEnded, body, key+".delivery."+body.Version+"."+how); err != nil {
|
||||||
|
p.logf("the end of the delivery wait of %s is not said, and is said at the next pass: %v", w.Module, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.remove(ctx, buckets.DeliveryWaits(), key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// againAsk is one ask of assigner_delivered_again, kept in the state delivered-again under its module (A-250): the version to say
|
||||||
|
// delivered again, who asked and why, and, while it does not hold, why not.
|
||||||
|
type againAsk struct {
|
||||||
|
Module string `json:"module"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
By string `json:"by"`
|
||||||
|
Why string `json:"why"`
|
||||||
|
Waits string `json:"waits,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// releaseOf is the release heard of module's version.
|
||||||
|
func (r *releasedVersions) releaseOf(module, version string) (releaseHeard, bool) {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
if h, ok := r.newest[module]; ok && h.Version == version {
|
||||||
|
return h, true
|
||||||
|
}
|
||||||
|
for key, k := range r.seen {
|
||||||
|
if strings.HasPrefix(key, module+"@") && k.Version == version {
|
||||||
|
return releaseHeard{Version: version, Parts: k.Parts}, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return releaseHeard{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// deliveredAgain takes each ask of assigner_delivered_again, heard at once through the watch of the state delivered-again: it says
|
||||||
|
// version-delivered again when every present machine placing the module runs that version healthy and removes the ask, else keeps
|
||||||
|
// it with why it does not hold, which assigner_waits reads.
|
||||||
|
func (p *passer) deliveredAgain(ctx context.Context) {
|
||||||
|
if p.kvs[buckets.DeliveredAgain()] == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for key, value := range p.w.read(buckets.DeliveredAgain()) {
|
||||||
|
var a againAsk
|
||||||
|
if err := json.Unmarshal(value, &a); err != nil || a.Version == "" {
|
||||||
|
p.logf("%s %s holds no ask, left: %v", buckets.DeliveredAgain(), key, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
module := a.Module
|
||||||
|
if module == "" {
|
||||||
|
module = key
|
||||||
|
}
|
||||||
|
waits := ""
|
||||||
|
rel, ok := p.w.released.releaseOf(module, a.Version)
|
||||||
|
notRunning, away, placing := p.deliveryStanding(module, a.Version)
|
||||||
|
switch {
|
||||||
|
case !ok:
|
||||||
|
waits = fmt.Sprintf("no version-released of %s %s is heard", module, a.Version)
|
||||||
|
case placing == 0:
|
||||||
|
waits = fmt.Sprintf("no machine places %s", module)
|
||||||
|
case len(away) == placing:
|
||||||
|
waits = fmt.Sprintf("every machine placing %s is away: %s", module, strings.Join(away, ", "))
|
||||||
|
case len(notRunning) > 0:
|
||||||
|
waits = fmt.Sprintf("%s %s does not run healthy on %s", module, a.Version, strings.Join(notRunning, ", "))
|
||||||
|
}
|
||||||
|
if waits == "" {
|
||||||
|
if err := p.sayDelivered(module, rel, away); err != nil {
|
||||||
|
p.logf("version-delivered of %s %s asked again is not said, and is asked at the next pass: %v", module, a.Version, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
p.logf("version-delivered of %s %s said again, asked by %s: %s", module, a.Version, a.By, a.Why)
|
||||||
|
p.remove(ctx, buckets.DeliveredAgain(), key)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if a.Waits != waits {
|
||||||
|
a.Waits = waits
|
||||||
|
p.put(ctx, buckets.DeliveredAgain(), key, func() ([]byte, error) { return json.Marshal(a) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G §376, §389, §498, A-189, A-246: a released version is said version-delivered once, when every present machine placing
|
||||||
|
// it runs healthy the want naming it, a machine away named and not waited for, none when every placing machine is away; a dependent
|
||||||
|
// whose want changes fingerprint waits by an edge of kind 2, 4 or 6 for its dependency's newest released version not yet said
|
||||||
|
// delivered, said wait-held (step delivery, 60 minutes from the release) once and kept in delivery-waits, and wait-ended ran once
|
||||||
|
// the version is delivered; a kind-1 edge, or a dependency with no version released, waits for nothing; one released by hand ends
|
||||||
|
// released and its want is written.
|
||||||
|
func TestADependentWaitsForItsDependencysDelivery(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
at := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
|
||||||
|
waits := &memKV{values: map[string][]byte{}}
|
||||||
|
again := &memKV{values: map[string][]byte{}}
|
||||||
|
p := newPasser(kvSet{buckets.Wants(): &memKV{values: map[string][]byte{}}, buckets.DeliveryWaits(): waits, buckets.DeliveredAgain(): again}, at)
|
||||||
|
p.logf = t.Logf
|
||||||
|
var events []said
|
||||||
|
p.publishWants = func(event string, body any, id string) error {
|
||||||
|
raw, _ := json.Marshal(body)
|
||||||
|
events = append(events, said{event, id, raw})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
p.w.runningHeard = true
|
||||||
|
placeOn(t, p.w, "ace", "db", "app")
|
||||||
|
placeOn(t, p.w, "g14", "db")
|
||||||
|
fp := func(c string) string { return meshcatalogclient.SourcePrefix2 + strings.Repeat(c, 64) }
|
||||||
|
want := func(node, module, fp, version string) {
|
||||||
|
key, _ := mwc.WantKey(node, module)
|
||||||
|
raw, err := mwc.EncodeWant(mwc.Want{Fp: fp, Version: version, Self: true})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
p.w.put(buckets.Wants(), key, raw)
|
||||||
|
}
|
||||||
|
runs := func(node, module, fp string) {
|
||||||
|
raw, _ := json.Marshal(map[string]any{"v": 1, "node": node, "module": module, "fingerprint": fp, "at": at})
|
||||||
|
if err := p.w.hearRunning("running", raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
source := int64(3)
|
||||||
|
release := func(module, version string) {
|
||||||
|
source++
|
||||||
|
raw, _ := json.Marshal(meshcatalog.VersionReleasedEvent{V: 1, Module: module, Version: version, Source: source, At: &at,
|
||||||
|
Artifacts: []meshcatalog.VersionArtifact{{Artifact: "program", Digest: "sha256:d"}}})
|
||||||
|
if err := p.w.released.put(raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saidOf := func(event string) []said {
|
||||||
|
var out []said
|
||||||
|
for _, e := range events {
|
||||||
|
if e.event == event {
|
||||||
|
out = append(out, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
want("ace", "app", fp("1"), "")
|
||||||
|
|
||||||
|
// No version of db is released: app's new fingerprint waits for nothing.
|
||||||
|
p.w.putEdges(trunkBranch, "app", []meshcatalog.Edge{{Kind: 4, From: "db:program", To: "app:program"}})
|
||||||
|
if p.holdForDelivery(ctx, "app", fp("2"), trunkBranch, []string{"ace"}) {
|
||||||
|
t.Fatal("app waits with no version of db released")
|
||||||
|
}
|
||||||
|
release("db", "1.1.0")
|
||||||
|
want("ace", "db", fp("d"), "1.1.0")
|
||||||
|
want("g14", "db", fp("d"), "1.1.0")
|
||||||
|
runs("ace", "db", fp("d"))
|
||||||
|
// A kind-1 edge orders nothing.
|
||||||
|
p.w.putEdges(trunkBranch, "app", []meshcatalog.Edge{{Kind: 1, From: "db:program", To: "app:program"}})
|
||||||
|
if p.holdForDelivery(ctx, "app", fp("2"), trunkBranch, []string{"ace"}) {
|
||||||
|
t.Fatal("a kind-1 edge holds app")
|
||||||
|
}
|
||||||
|
p.w.putEdges(trunkBranch, "app", []meshcatalog.Edge{{Kind: 4, From: "db:program", To: "app:program"}})
|
||||||
|
// app's want unchanged waits for nothing.
|
||||||
|
if p.holdForDelivery(ctx, "app", fp("1"), trunkBranch, []string{"ace"}) {
|
||||||
|
t.Fatal("app's unchanged want waits")
|
||||||
|
}
|
||||||
|
// g14 places db and does not run 1.1.0 yet: not delivered, and app's new version waits, said once.
|
||||||
|
p.judgeDelivered()
|
||||||
|
if !p.holdForDelivery(ctx, "app", fp("2"), trunkBranch, []string{"ace"}) || !p.holdForDelivery(ctx, "app", fp("2"), trunkBranch, []string{"ace"}) {
|
||||||
|
t.Fatal("app does not wait for db 1.1.0")
|
||||||
|
}
|
||||||
|
if len(saidOf(meshwants.EventVersionDelivered)) != 0 {
|
||||||
|
t.Fatalf("db is said delivered while g14 does not run it: %+v", events)
|
||||||
|
}
|
||||||
|
held := saidOf(meshwants.EventWaitHeld)
|
||||||
|
if len(held) != 1 {
|
||||||
|
t.Fatalf("wait-held said %d times, want once", len(held))
|
||||||
|
}
|
||||||
|
var w meshwants.Wait
|
||||||
|
_ = json.Unmarshal(held[0].body, &w)
|
||||||
|
if w.Step != meshwants.WaitStepDelivery || w.Part != "db" || w.Module != "app" || w.Version != fp("2") || w.Bound != "1h0m0s" ||
|
||||||
|
w.ClockFrom == nil || !w.ClockFrom.Equal(at) || len(w.Machines) != 1 || w.Machines[0] != "g14" || w.Words != "waiting for delivery of db 1.1.0 on g14" {
|
||||||
|
t.Errorf("the wait said is %+v", w)
|
||||||
|
}
|
||||||
|
if _, ok := waits.values["app"]; !ok {
|
||||||
|
t.Errorf("the wait is not kept in delivery-waits: %v", waits.values)
|
||||||
|
}
|
||||||
|
// g14 away: every present machine runs it, so it is delivered, g14 named away; once only.
|
||||||
|
p.w.heardPresence("g14", true, at)
|
||||||
|
p.judgeDelivered()
|
||||||
|
p.judgeDelivered()
|
||||||
|
delivered := saidOf(meshwants.EventVersionDelivered)
|
||||||
|
var d meshwants.VersionDeliveredEvent
|
||||||
|
if len(delivered) != 1 || json.Unmarshal(delivered[0].body, &d) != nil || d.Module != "db" || d.Version != "1.1.0" ||
|
||||||
|
len(d.Away) != 1 || d.Away[0] != "g14" || d.Parts["db:program"] != "sha256:d" {
|
||||||
|
t.Fatalf("version-delivered said %+v", delivered)
|
||||||
|
}
|
||||||
|
// The wait ends ran, and app's want goes on.
|
||||||
|
if p.holdForDelivery(ctx, "app", fp("2"), trunkBranch, []string{"ace"}) {
|
||||||
|
t.Fatal("app still waits once db 1.1.0 is delivered")
|
||||||
|
}
|
||||||
|
ended := saidOf(meshwants.EventWaitEnded)
|
||||||
|
if len(ended) != 1 || json.Unmarshal(ended[0].body, &w) != nil || w.How != deliveryWaitRan {
|
||||||
|
t.Errorf("wait-ended said %+v", ended)
|
||||||
|
}
|
||||||
|
if _, ok := waits.values["app"]; ok {
|
||||||
|
t.Error("the ended wait is kept")
|
||||||
|
}
|
||||||
|
// A newer release with every placing machine away is not delivered, and its wait says the machines it waits to be back.
|
||||||
|
release("db", "1.2.0")
|
||||||
|
p.w.heardPresence("ace", true, at)
|
||||||
|
p.judgeDelivered()
|
||||||
|
if len(saidOf(meshwants.EventVersionDelivered)) != 1 {
|
||||||
|
t.Error("a version is said delivered while every placing machine is away")
|
||||||
|
}
|
||||||
|
if !p.holdForDelivery(ctx, "app", fp("3"), trunkBranch, []string{"ace"}) {
|
||||||
|
t.Fatal("app does not wait for db 1.2.0")
|
||||||
|
}
|
||||||
|
held = saidOf(meshwants.EventWaitHeld)
|
||||||
|
if json.Unmarshal(held[len(held)-1].body, &w) != nil || w.Words != "waiting for ace, g14 to be back" {
|
||||||
|
t.Errorf("the wait while every machine is away says %q", w.Words)
|
||||||
|
}
|
||||||
|
// Released by hand (assigner_release writes it): the wait ends released and app's want is written.
|
||||||
|
var kept deliveryWaiting
|
||||||
|
_ = json.Unmarshal(waits.values["app"], &kept)
|
||||||
|
kept.Released = true
|
||||||
|
raw, _ := json.Marshal(kept)
|
||||||
|
p.w.put(buckets.DeliveryWaits(), "app", raw)
|
||||||
|
if p.holdForDelivery(ctx, "app", fp("3"), trunkBranch, []string{"ace"}) {
|
||||||
|
t.Fatal("a released wait holds app")
|
||||||
|
}
|
||||||
|
ended = saidOf(meshwants.EventWaitEnded)
|
||||||
|
if json.Unmarshal(ended[len(ended)-1].body, &w) != nil || w.How != deliveryWaitReleased {
|
||||||
|
t.Errorf("the released wait ended %+v", w)
|
||||||
|
}
|
||||||
|
// Presence: the later of machine-away and machine-back holds, whichever stream is read first.
|
||||||
|
p.w.heardPresence("ace", false, at.Add(time.Minute))
|
||||||
|
p.w.heardPresence("ace", true, at)
|
||||||
|
if p.w.awayNow()["ace"] || !p.w.online()["ace"] {
|
||||||
|
t.Error("an older machine-away read after a newer machine-back leaves ace away")
|
||||||
|
}
|
||||||
|
// A-250: an ask of assigner_delivered_again of 1.1.0, which ace (present) runs and g14 (away) does not, is said again and taken
|
||||||
|
// away; one of 1.2.0, which no machine runs, is kept with why.
|
||||||
|
ask := func(version string) {
|
||||||
|
raw, _ := json.Marshal(againAsk{Module: "db", Version: version, By: "op", Why: "the catalog missed it"})
|
||||||
|
p.w.put(buckets.DeliveredAgain(), "db", raw)
|
||||||
|
}
|
||||||
|
before := len(saidOf(meshwants.EventVersionDelivered))
|
||||||
|
ask("1.1.0")
|
||||||
|
p.deliveredAgain(ctx)
|
||||||
|
if len(saidOf(meshwants.EventVersionDelivered)) != before+1 || p.w.has(buckets.DeliveredAgain(), "db") {
|
||||||
|
t.Errorf("the ask of 1.1.0 said %d version-delivered and is kept %v", len(saidOf(meshwants.EventVersionDelivered))-before, p.w.has(buckets.DeliveredAgain(), "db"))
|
||||||
|
}
|
||||||
|
ask("1.2.0")
|
||||||
|
p.deliveredAgain(ctx)
|
||||||
|
var a againAsk
|
||||||
|
if json.Unmarshal(p.w.value(buckets.DeliveredAgain(), "db"), &a) != nil || a.Waits != "db 1.2.0 does not run healthy on ace" ||
|
||||||
|
len(saidOf(meshwants.EventVersionDelivered)) != before+1 {
|
||||||
|
t.Errorf("the ask of 1.2.0 = %+v", a)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/busstate"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// runtimeObjects is the kept data assignment-revisions as the bundle reaches it through its runtime (the old objects
|
||||||
|
// section of a foundation part, design 47 lines 1362-1366).
|
||||||
|
type runtimeObjects struct{ o busstate.Objects }
|
||||||
|
|
||||||
|
func (r runtimeObjects) Put(_ context.Context, name string, data []byte) error {
|
||||||
|
_, err := r.o.Put(name, data, "")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r runtimeObjects) Get(_ context.Context, name string) ([]byte, error) {
|
||||||
|
d, err := r.o.Get(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if d.Info.Name == "" || d.Info.Deleted {
|
||||||
|
return nil, assigngraph.ErrNoObject
|
||||||
|
}
|
||||||
|
return d.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r runtimeObjects) Names(context.Context) ([]string, error) {
|
||||||
|
infos, err := r.o.List()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
names := []string{}
|
||||||
|
for _, i := range infos {
|
||||||
|
if !i.Deleted {
|
||||||
|
names = append(names, i.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// graphVerbs are the seat mesh-wants' verbs revision, entry and difference (design 47 lines 1365-1366: an assignment graph
|
||||||
|
// revision is served by the seat's verbs), each reading only the kept revisions.
|
||||||
|
func graphVerbs(o assigngraph.Objects) map[string]func(map[string]any) (any, error) {
|
||||||
|
return map[string]func(map[string]any) (any, error){
|
||||||
|
meshwants.VerbRevision: func(a map[string]any) (any, error) {
|
||||||
|
var in meshwants.RevisionInput
|
||||||
|
if err := decodeArgs(a, &in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return assigngraph.Revision(context.Background(), o, in)
|
||||||
|
},
|
||||||
|
meshwants.VerbEntry: func(a map[string]any) (any, error) {
|
||||||
|
var in meshwants.EntryInput
|
||||||
|
if err := decodeArgs(a, &in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return assigngraph.Entry(context.Background(), o, in)
|
||||||
|
},
|
||||||
|
meshwants.VerbDifference: func(a map[string]any) (any, error) {
|
||||||
|
var in meshwants.DifferenceInput
|
||||||
|
if err := decodeArgs(a, &in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return assigngraph.Difference(context.Background(), o, in)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// decodeArgs reads a verb's arguments into its input type; a caller's own fields beside them are the runtime's.
|
||||||
|
func decodeArgs(a map[string]any, into any) error {
|
||||||
|
raw, err := json.Marshal(a)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return json.Unmarshal(raw, into)
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A store filling is said before it is full (design 47 G §181, in the assigner's part): the assignment graph revisions' object store
|
||||||
|
// says `filling` of the seat mesh-wants when it passes 80 % of its cap, and `full` when the next revision does not fit: the assigner then keeps
|
||||||
|
// its last revision and writes no new want, and says `room` when the store is back below 80 % and goes on. Nothing is dropped to make room.
|
||||||
|
|
||||||
|
// fillOf is the store's fill now: its bytes and cap, when the bucket says them and has a cap.
|
||||||
|
func (g *graphKeeper) fillOf(ctx context.Context) (used, capacity int64, ok bool) {
|
||||||
|
f, is := g.objects.(assigngraph.Filler)
|
||||||
|
if !is {
|
||||||
|
return 0, 0, false
|
||||||
|
}
|
||||||
|
used, capacity, err := f.Fill(ctx)
|
||||||
|
return used, capacity, err == nil && capacity > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *passer) sayFill(event, about string, used, capacity int64, refused string) {
|
||||||
|
at := p.clock().UTC()
|
||||||
|
body := meshwants.Fill{Store: assigngraph.RevisionsObjects, Bytes: used, Cap: capacity, Refused: refused, At: &at}
|
||||||
|
if err := p.wantsSay(event, body, event+"-"+about); err != nil {
|
||||||
|
p.logf("%s of %s is not said: %v", event, assigngraph.RevisionsObjects, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fillAtStart judges the store once at the process's first pass, when no event is pending: a store past 80 % says filling (full when at
|
||||||
|
// its cap), so a fill reached while the process was down is said too.
|
||||||
|
func (p *passer) fillAtStart(ctx context.Context) {
|
||||||
|
g := p.graph
|
||||||
|
used, capacity, ok := g.fillOf(ctx)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case used >= capacity:
|
||||||
|
g.full = true
|
||||||
|
p.sayFill(meshwants.EventFull, "start", used, capacity, "the next revision")
|
||||||
|
case used*5 >= capacity*4:
|
||||||
|
p.sayFill(meshwants.EventFilling, "start", used, capacity, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fullBefore says the next revision does not fit its store, and keeps nothing: it says `full` once, and `room` once the store is below
|
||||||
|
// 80 % again. It answers true while the store is full.
|
||||||
|
func (p *passer) fullBefore(ctx context.Context, c assigngraph.Computed) bool {
|
||||||
|
g := p.graph
|
||||||
|
used, capacity, ok := g.fillOf(ctx)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if g.full && used*5 < capacity*4 {
|
||||||
|
g.full = false
|
||||||
|
p.sayFill(meshwants.EventRoom, fmt.Sprint(used), used, capacity, "")
|
||||||
|
}
|
||||||
|
if used+assigngraph.NewBytes(ctx, g.objects, c) <= capacity {
|
||||||
|
g.full = false
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !g.full {
|
||||||
|
g.full = true
|
||||||
|
p.sayFill(meshwants.EventFull, fmt.Sprint(used), used, capacity, "the next revision")
|
||||||
|
}
|
||||||
|
p.logf("the assignment graph revision is not kept: %s is full (%d of %d bytes), the last revision stays and no want is written until there is room", assigngraph.RevisionsObjects, used, capacity)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// fillingAfter says `filling` when keeping a revision took the store past 80 % of its cap.
|
||||||
|
func (p *passer) fillingAfter(ctx context.Context, before int64) {
|
||||||
|
g := p.graph
|
||||||
|
used, capacity, ok := g.fillOf(ctx)
|
||||||
|
if ok && before*5 < capacity*4 && used*5 >= capacity*4 {
|
||||||
|
p.sayFill(meshwants.EventFilling, fmt.Sprint(used), used, capacity, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// filled is an object bucket with a fill: the bytes it holds count beside what is stored.
|
||||||
|
type filled struct {
|
||||||
|
objs map[string][]byte
|
||||||
|
base int64
|
||||||
|
cap int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *filled) Put(_ context.Context, name string, data []byte) error {
|
||||||
|
f.objs[name] = data
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (f *filled) Get(_ context.Context, name string) ([]byte, error) {
|
||||||
|
if d, ok := f.objs[name]; ok {
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
return nil, assigngraph.ErrNoObject
|
||||||
|
}
|
||||||
|
func (f *filled) Names(context.Context) ([]string, error) {
|
||||||
|
out := []string{}
|
||||||
|
for n := range f.objs {
|
||||||
|
out = append(out, n)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
func (f *filled) Fill(context.Context) (int64, int64, error) {
|
||||||
|
used := f.base
|
||||||
|
for _, d := range f.objs {
|
||||||
|
used += int64(len(d))
|
||||||
|
}
|
||||||
|
return used, f.cap, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §181 (AS13): the assignment graph revisions' store says filling past 80 % of its cap, refuses a revision that does not fit
|
||||||
|
// with `full` (the last revision stays, no want is written), and says `room` below 80 % again; at the start a store already past 80 % is said.
|
||||||
|
func TestTheAssignmentGraphStoreSaysFillingFullAndRoom(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
p := newPasser(kvSet{}, time.Now())
|
||||||
|
var events []string
|
||||||
|
p.publishWants = func(event string, body any, id string) error {
|
||||||
|
if _, ok := body.(meshwants.Fill); ok {
|
||||||
|
events = append(events, event)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
o := &filled{objs: map[string][]byte{}, base: 500, cap: 1000}
|
||||||
|
p.graph = &graphKeeper{objects: o, halves: func() map[string]mcc.Half { return nil }}
|
||||||
|
p.keepGraph(ctx) // the first pass judges at the start: 500 of 1000 is below 80 %
|
||||||
|
if len(events) != 0 {
|
||||||
|
t.Fatalf("events %v", events)
|
||||||
|
}
|
||||||
|
o.base = 700
|
||||||
|
p.graph.started = false
|
||||||
|
p.keepGraph(ctx)
|
||||||
|
if len(events) != 1 || events[0] != meshwants.EventFilling {
|
||||||
|
t.Fatalf("at the start past 80 %%: %v", events)
|
||||||
|
}
|
||||||
|
c := assigngraph.Computed{Revision: meshwants.AssignmentRevision{Entries: []meshwants.NodeEntryRef{}}}
|
||||||
|
o.base = 990
|
||||||
|
if !p.fullBefore(ctx, c) || !p.graph.full || events[len(events)-1] != meshwants.EventFull {
|
||||||
|
t.Fatalf("a revision that does not fit: events %v", events)
|
||||||
|
}
|
||||||
|
p.fullBefore(ctx, c)
|
||||||
|
if n := len(events); n != 2 {
|
||||||
|
t.Errorf("full is said once: %v", events)
|
||||||
|
}
|
||||||
|
o.base = 100
|
||||||
|
if p.fullBefore(ctx, c) || p.graph.full || events[len(events)-1] != meshwants.EventRoom {
|
||||||
|
t.Errorf("room: events %v", events)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,245 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"maps"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// graphKeeper is the pass's assignment graph (design 47 G §292, A-67): per catalog revision taken in it computes the revision
|
||||||
|
// from the catalog halves it follows, the placements, the first branch of each registration and each node's capability reading,
|
||||||
|
// keeps it in the objects assignment-revisions and says the seat mesh-wants' event assignment-revision; the wants of the pass
|
||||||
|
// that follows are written from the revision it holds.
|
||||||
|
type graphKeeper struct {
|
||||||
|
objects assigngraph.Objects
|
||||||
|
// halves is every followed branch's catalog graph revision held now.
|
||||||
|
halves func() map[string]mcc.Half
|
||||||
|
// last is the revision last computed, so a pass whose inputs did not change keeps and says nothing.
|
||||||
|
last meshwants.AssignmentRevision
|
||||||
|
has bool
|
||||||
|
// kept is the revision the wants follow, and kept's source the trunk's source revision it carries; ok is false until one is kept.
|
||||||
|
kept meshwants.AssignmentRevision
|
||||||
|
source int64
|
||||||
|
ok bool
|
||||||
|
said string
|
||||||
|
// cycled is the cycles last said (assigngraph.Cycles).
|
||||||
|
cycled string
|
||||||
|
// full says the next revision did not fit the store, so no want is written (graphfill.go); started says the first pass judged the fill.
|
||||||
|
full, started bool
|
||||||
|
// pins removes a revision that ceased to be current once nothing pins it (pins.go); nil keeps every revision.
|
||||||
|
pins *pinKeeper
|
||||||
|
// computed is the revision computed by the last pass, with its entries: the edges the wants wait on (actingwaits.go).
|
||||||
|
computed assigngraph.Computed
|
||||||
|
}
|
||||||
|
|
||||||
|
// keepGraph computes the revision of this pass and keeps it when the pass's inputs differ from the last computed.
|
||||||
|
func (p *passer) keepGraph(ctx context.Context) {
|
||||||
|
g := p.graph
|
||||||
|
if g == nil || g.objects == nil || g.halves == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c := assigngraph.Compute(p.graphInputs())
|
||||||
|
g.computed = c
|
||||||
|
if p.ends != nil {
|
||||||
|
p.ends.setRunner(assigngraph.Runner(slices.Collect(maps.Values(c.Entries)))) // the runner's member of a group goes first (A-334)
|
||||||
|
}
|
||||||
|
for _, u := range c.Uncomputed {
|
||||||
|
if g.said != u {
|
||||||
|
g.said = u
|
||||||
|
p.logf("the assignment graph leaves out %s", u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cycles := strings.Join(c.Cycles, "; "); cycles != g.cycled {
|
||||||
|
g.cycled = cycles
|
||||||
|
if cycles != "" {
|
||||||
|
p.logf("the assignment graph holds a cycle among the acting waits, within one step or across steps: %s", cycles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !g.started {
|
||||||
|
g.started = true
|
||||||
|
p.fillAtStart(ctx)
|
||||||
|
}
|
||||||
|
if g.has && g.ok && assigngraph.Same(g.last, c.Revision) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
used, _, _ := g.fillOf(ctx)
|
||||||
|
if p.fullBefore(ctx, c) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rev, fresh, err := assigngraph.Keep(ctx, g.objects, c, meshwants.EventAssignmentRevision, p.clock())
|
||||||
|
if err != nil {
|
||||||
|
p.logf("the assignment graph revision is not kept, so no want is said as wanted until it is: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
g.last, g.has, g.kept, g.ok = c.Revision, true, rev, true
|
||||||
|
g.source = 0
|
||||||
|
for _, cat := range rev.Catalogs {
|
||||||
|
if cat.Branch == p.w.trunkName() {
|
||||||
|
g.source = cat.Source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !fresh {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.fillingAfter(ctx, used)
|
||||||
|
if g.pins != nil {
|
||||||
|
g.pins.judge() // the revision before ceased to be current
|
||||||
|
}
|
||||||
|
id := fmt.Sprintf("%s-%s-%d", meshwants.EventAssignmentRevision, rev.Kind, rev.Revision)
|
||||||
|
if err := p.wantsSay(meshwants.EventAssignmentRevision, assigngraph.Event(rev), id); err != nil {
|
||||||
|
p.logf("the assignment revision %d is kept but not said: %v", rev.Revision, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// graphInputs are what the pass's assignment graph is computed from: every followed branch's catalog half, the placements, each
|
||||||
|
// node's capability reading and the first branch of each registration.
|
||||||
|
func (p *passer) graphInputs() assigngraph.Inputs {
|
||||||
|
in := assigngraph.Inputs{Halves: p.graph.halves(), Placements: p.w.assignments(), Capabilities: p.capabilityDigests()}
|
||||||
|
// The seat definitions read through the seat mesh-catalog's verb seat-definitions say which seat delivers a requirement
|
||||||
|
// (design 47 G §708).
|
||||||
|
if r := p.seats.Reader(); r != nil {
|
||||||
|
in.Definitions = r.Definitions()
|
||||||
|
}
|
||||||
|
// With no pipeline ends kept, the wants are the trunk-only form (pass.go): a placement naming no branch runs the trunk's.
|
||||||
|
first := p.w.trunkName()
|
||||||
|
in.FirstBranch = func(string) string { return first }
|
||||||
|
if p.ends != nil {
|
||||||
|
in.FirstBranch = func(module string) string { return p.ends.branchOf(module, "") }
|
||||||
|
}
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
|
||||||
|
// capabilityDigests is each node's capability reading, by node: the statement its engine made of what it reads, and the
|
||||||
|
// capabilities its tool runner states with the fingerprint of the runner that announced them, as the node's record carries
|
||||||
|
// them (design 46 approval mark §6, lead answer A-203), the digest over all of it.
|
||||||
|
func (p *passer) capabilityDigests() []meshwants.AssignmentRevisionCapabilitiesItem {
|
||||||
|
records := p.w.records()
|
||||||
|
known := p.w.knownNodes()
|
||||||
|
slices.Sort(known)
|
||||||
|
var out []meshwants.AssignmentRevisionCapabilitiesItem
|
||||||
|
for _, node := range known {
|
||||||
|
read := p.reads != nil && p.reads.Known(node)
|
||||||
|
rec, recorded := records[node]
|
||||||
|
if !read && !recorded {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var reads []string
|
||||||
|
if read {
|
||||||
|
reads = slices.Clone(p.reads.Reads([]string{node})[node])
|
||||||
|
slices.Sort(reads)
|
||||||
|
}
|
||||||
|
item := meshwants.AssignmentRevisionCapabilitiesItem{Node: node, Readings: slices.Clone(rec.RunnerCapabilities),
|
||||||
|
Fingerprint: rec.RunnerFingerprint}
|
||||||
|
slices.Sort(item.Readings)
|
||||||
|
raw, _ := json.Marshal(struct {
|
||||||
|
Reads []string `json:"reads"`
|
||||||
|
Readings []string `json:"readings"`
|
||||||
|
Fingerprint string `json:"fingerprint"`
|
||||||
|
}{reads, item.Readings, item.Fingerprint})
|
||||||
|
sum := sha256.Sum256(raw)
|
||||||
|
item.Digest = "sha256:" + hex.EncodeToString(sum[:])
|
||||||
|
out = append(out, item)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// sayWanted says `wanted` for a want written or removed now, from the revision the pass keeps (A-61, A-67); with none kept, it is
|
||||||
|
// said in the log that it was not said. fp is the want's, and for a removal the fingerprint last wanted there.
|
||||||
|
func (p *passer) sayWanted(node, module, fp string, removed bool) {
|
||||||
|
if p.publishWants == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
g := p.graph
|
||||||
|
if g == nil || !g.ok {
|
||||||
|
p.logf("the want of %s on %s is written, but no assignment graph revision is kept, so wanted is not said", module, node)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
at := p.clock().UTC()
|
||||||
|
body := meshwants.WantedEvent{V: keys.Version, Node: node, Module: module, Fp: fp, Removed: removed, Revision: g.kept.Revision, Source: g.source, At: &at}
|
||||||
|
event := strings.TrimPrefix(meshwants.SubjectWanted(keys.EscapeName(node), keys.EscapeName(module)), "mesh.seat."+meshwants.Seat+".event.")
|
||||||
|
id := fmt.Sprintf("wanted.%s.%s.%s.%t.%d.%s", keys.EscapeName(node), keys.EscapeName(module), fp, removed, g.kept.Revision, at.Format(time.RFC3339Nano))
|
||||||
|
if err := p.wantsSay(event, body, id); err != nil {
|
||||||
|
p.logf("wanted of %s on %s is not said: %v", module, node, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// namedBuild answers what a want of module at fp names of its build (design 47 G §379, §526, A-96): a kept build's or another watched
|
||||||
|
// branch's parts and keeping node from the builder's `build.ended`; for the trunk's entry (fp is the module's, trunkFP), the released
|
||||||
|
// version and the parts of the `version-released` of the module whose source is the one its fingerprint was built at, the entry's
|
||||||
|
// `fp-src` (A-419: a merge that does not rebuild the module leaves it so), or for an entry naming none the one whose parts are the
|
||||||
|
// digests its build.ended made (A-421). A trunk entry whose release is not heard is said, once, naming which was tried.
|
||||||
|
func (p *passer) namedBuild(module, trunkFP string, fpSrc int64, unreleased ...bool) func(fp string) (assign.KeptBuild, bool) {
|
||||||
|
return func(fp string) (assign.KeptBuild, bool) {
|
||||||
|
if k, ok := p.w.ends.partsOf(module, fp); ok {
|
||||||
|
return k, true
|
||||||
|
}
|
||||||
|
if len(unreleased) > 0 && unreleased[0] && fp == trunkFP {
|
||||||
|
// Wanted with no passed pipeline (the holder of mesh-catalog, the runner's first start): no pipeline released it,
|
||||||
|
// so its want names the parts its build.ended made, until a release of it is heard (design 47 G §16, A-428).
|
||||||
|
if k, ok := p.w.released.withParts(module, p.w.ends.madeOf(module, fp)); ok {
|
||||||
|
return k, true
|
||||||
|
}
|
||||||
|
if made := p.w.ends.madeOf(module, fp); len(made) > 0 {
|
||||||
|
return assign.KeptBuild{Parts: made}, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if fp != trunkFP {
|
||||||
|
// A want held back at an older build (rule 2: no pipeline passed at the trunk's newer fingerprint) names that build's
|
||||||
|
// release when one names exactly the digests it made (novox 2026-11-16: mesh-hand-acts 0.1.13 held at 4eb3cf48 after
|
||||||
|
// the mesh-sdk merge moved its fingerprint).
|
||||||
|
return p.w.released.withParts(module, p.w.ends.madeOf(module, fp))
|
||||||
|
}
|
||||||
|
if p.graph == nil || !p.graph.ok {
|
||||||
|
p.unheardRelease(module, fp, "no assignment graph revision is kept yet, so no release is looked up")
|
||||||
|
return assign.KeptBuild{}, false
|
||||||
|
}
|
||||||
|
if fpSrc == 0 {
|
||||||
|
// No fp-src (its fingerprint moved with no merge): the release whose parts are what its build made (A-421).
|
||||||
|
if k, ok := p.w.released.withParts(module, p.w.ends.madeOf(module, fp)); ok {
|
||||||
|
return k, true
|
||||||
|
}
|
||||||
|
p.unheardRelease(module, fp, "its catalog entry names no fp-src, and no version-released of it names the parts its build.ended made")
|
||||||
|
return assign.KeptBuild{}, false
|
||||||
|
}
|
||||||
|
k, ok := p.w.released.of(module, fpSrc)
|
||||||
|
if !ok {
|
||||||
|
// The release names the source its reservation was made at, which can be an earlier revision than the entry's
|
||||||
|
// fp-src (novox 2026-11-16: mesh-hand-acts 0.1.13 released from 962, its entry's fp-src 963): the release whose parts
|
||||||
|
// are exactly the digests this fingerprint's build made is this build's (A-421).
|
||||||
|
if k, ok = p.w.released.withParts(module, p.w.ends.madeOf(module, fp)); ok {
|
||||||
|
return k, true
|
||||||
|
}
|
||||||
|
p.unheardRelease(module, fp, fmt.Sprintf("no version-released of it from source %d, the one its fingerprint was built at, nor one naming the parts its build.ended made, is heard", fpSrc))
|
||||||
|
}
|
||||||
|
return k, ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unheardRelease says once per module, fingerprint and why that a trunk entry's release is not heard, so its wants and candidates
|
||||||
|
// carry no version and no parts (design 47 G A-419).
|
||||||
|
func (p *passer) unheardRelease(module, fp, why string) {
|
||||||
|
key := "release " + module + "@" + fp + ": " + why
|
||||||
|
if p.skipped[key] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if p.skipped == nil {
|
||||||
|
p.skipped = map[string]bool{}
|
||||||
|
}
|
||||||
|
p.skipped[key] = true
|
||||||
|
if p.logf != nil {
|
||||||
|
p.logf("the release of %s at fingerprint %s is not heard: %s; its wants and candidates carry no version and no parts", module, fp, why)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// said is one event the passer said on the seat mesh-wants.
|
||||||
|
type said struct {
|
||||||
|
event, id string
|
||||||
|
body json.RawMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G A-67, §292: the pass keeps an assignment graph revision per catalog revision taken in, before it writes any want, and
|
||||||
|
// says assignment-revision; A-61, §693: a want written or removed is said `wanted` on the subject of its node and module in the same
|
||||||
|
// write, from the kept revision and its catalog's source, a put that wrote nothing says nothing, and with no revision kept none is said.
|
||||||
|
func TestTheWantsAreSaidWantedFromTheKeptAssignmentGraphRevision(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
at := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
|
||||||
|
kv := &memKV{values: map[string][]byte{}}
|
||||||
|
p := newPasser(kvSet{buckets.Wants(): kv}, at)
|
||||||
|
p.logf = t.Logf
|
||||||
|
var events []said
|
||||||
|
p.publishWants = func(event string, body any, id string) error {
|
||||||
|
raw, _ := json.Marshal(body)
|
||||||
|
events = append(events, said{event, id, raw})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
placeOn(t, p.w, "ace", "web")
|
||||||
|
// Design 46 approval mark §6: a node's reading keeps the fingerprint of the runner that announced it, as its record says.
|
||||||
|
rec, _ := json.Marshal(nodeengine.HaveByNodeNodeValue{V: 1, Record: &nodeengine.NodeRecord{V: 1, Node: "ace",
|
||||||
|
RunnerCapabilities: []string{"bus-state-calls", "approval-mark/1"}, RunnerFingerprint: "sha256:runner"}})
|
||||||
|
p.w.put(buckets.Have, "ace.node", rec)
|
||||||
|
if c := p.capabilityDigests(); len(c) != 1 || c[0].Node != "ace" || c[0].Fingerprint != "sha256:runner" ||
|
||||||
|
!slices.Equal(c[0].Readings, []string{"approval-mark/1", "bus-state-calls"}) || !strings.HasPrefix(c[0].Digest, "sha256:") {
|
||||||
|
t.Errorf("the capability readings are %+v", c)
|
||||||
|
}
|
||||||
|
half := mcc.Half{Revision: meshcatalog.CatalogRevision{Branch: trunkBranch, Kind: "trunk", Revision: 4, Source: 9,
|
||||||
|
Entries: []meshcatalog.EntryRef{{Module: "web", Digest: "sha256:" + strings.Repeat("a", 64)}}},
|
||||||
|
Entries: map[string]meshcatalog.CatalogEntry{"web": {Module: "web", Fp: fpTest}}}
|
||||||
|
objects := memObjects{}
|
||||||
|
p.graph = &graphKeeper{objects: objects, halves: func() map[string]mcc.Half { return map[string]mcc.Half{trunkBranch: half} }}
|
||||||
|
want := mwc.Want{Fp: fpTest, Self: true}
|
||||||
|
|
||||||
|
p.putWant(ctx, "ace", "web", want) // no revision kept yet: written, and not said
|
||||||
|
if len(events) != 0 || kv.puts != 1 {
|
||||||
|
t.Fatalf("with no revision kept: %d events, %d puts", len(events), kv.puts)
|
||||||
|
}
|
||||||
|
key, _ := mwc.WantKey("ace", "web")
|
||||||
|
delete(p.w.read(buckets.Wants()), key) // the world forgets the want, as before the first pass
|
||||||
|
kv.puts = 0
|
||||||
|
p.w.put(buckets.Wants(), key, nil)
|
||||||
|
|
||||||
|
p.keepGraph(ctx)
|
||||||
|
if len(events) != 1 || events[0].event != meshwants.EventAssignmentRevision || len(objects) == 0 {
|
||||||
|
t.Fatalf("the pass kept %d objects and said %+v", len(objects), events)
|
||||||
|
}
|
||||||
|
p.keepGraph(ctx) // the same inputs: nothing kept, nothing said
|
||||||
|
if len(events) != 1 {
|
||||||
|
t.Fatalf("a pass of the same inputs said %d events", len(events))
|
||||||
|
}
|
||||||
|
p.putWant(ctx, "ace", "web", want)
|
||||||
|
p.putWant(ctx, "ace", "web", want) // unchanged: not written, not said
|
||||||
|
if len(events) != 2 || kv.puts != 1 {
|
||||||
|
t.Fatalf("a want put twice: %d events, %d puts", len(events), kv.puts)
|
||||||
|
}
|
||||||
|
if wantEvent := "wanted.ace.web"; events[1].event != wantEvent {
|
||||||
|
t.Errorf("wanted said on %q, want %q", events[1].event, wantEvent)
|
||||||
|
}
|
||||||
|
var w meshwants.WantedEvent
|
||||||
|
if err := json.Unmarshal(events[1].body, &w); err != nil || w.Node != "ace" || w.Module != "web" || w.Fp != fpTest || w.Removed || w.Revision != 1 || w.Source != 9 {
|
||||||
|
t.Errorf("wanted = %+v (%v)", w, err)
|
||||||
|
}
|
||||||
|
p.putWant(ctx, "ace", "web", mwc.Want{Removed: true})
|
||||||
|
if err := json.Unmarshal(events[len(events)-1].body, &w); err != nil || len(events) != 3 || !w.Removed || w.Fp != fpTest {
|
||||||
|
t.Errorf("a removing want said %+v (%v), %d events", w, err, len(events))
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-201, A-235: a run's candidate catalog revision, read whole through the seat's verb revision, keeps the run's assignment
|
||||||
|
// graph under candidate.<group>.<heads> in place of its branch's half; it says nothing and writes no want, a try's candidate
|
||||||
|
// keeps none, and the run's group-ended drops it.
|
||||||
|
before, puts := len(events), kv.puts
|
||||||
|
ev := meshcatalog.CatalogRevisionEvent{Kind: "candidate", Branch: trunkBranch, Group: "run-7", Heads: "h1", Revision: 5}
|
||||||
|
var asked []meshcatalog.RevisionInput
|
||||||
|
call := func(key string, body any) (json.RawMessage, error) {
|
||||||
|
in := body.(meshcatalog.RevisionInput)
|
||||||
|
asked = append(asked, in)
|
||||||
|
rev := meshcatalog.CatalogRevision{Branch: trunkBranch, Kind: "candidate", Group: "run-7", Heads: "h1", Revision: 5, Source: 9,
|
||||||
|
Entries: []meshcatalog.EntryRef{{Module: "web", Digest: "sha256:" + strings.Repeat("b", 64)}}}
|
||||||
|
a := meshcatalog.RevisionAnswer{Revision: &rev, Entries: []meshcatalog.CatalogEntry{{Module: "web", Fp: "src2:w2"}}}
|
||||||
|
return json.Marshal(a)
|
||||||
|
}
|
||||||
|
if err := p.keepCandidate(ctx, call, meshcatalog.CatalogRevisionEvent{Kind: "candidate", Branch: trunkBranch, Group: "try-3", Heads: "h", Revision: 2}); err != nil || len(asked) != 0 {
|
||||||
|
t.Errorf("a try's candidate asked %v: %v", asked, err)
|
||||||
|
}
|
||||||
|
if err := p.keepCandidate(ctx, call, ev); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(asked) != 1 || asked[0].Group != "run-7" || asked[0].Heads != "h1" || asked[0].Revision != 5 {
|
||||||
|
t.Errorf("the candidate's revision was asked as %+v", asked)
|
||||||
|
}
|
||||||
|
a, err := assigngraph.Revision(ctx, objects, meshwants.RevisionInput{Group: "run-7"})
|
||||||
|
if err != nil || a.Revision.Kind != "candidate" || len(a.Revision.Catalogs) != 1 || a.Revision.Catalogs[0].Revision != 5 {
|
||||||
|
t.Errorf("the run's assignment graph is %+v: %v", a.Revision, err)
|
||||||
|
}
|
||||||
|
if e, err := assigngraph.Entry(ctx, objects, meshwants.EntryInput{Group: "run-7", Node: "ace", Module: "web"}); err != nil || e.Entry.Fp != "src2:w2" {
|
||||||
|
t.Errorf("the run's entry of web is %+v: %v", e.Entry, err)
|
||||||
|
}
|
||||||
|
if len(events) != before || kv.puts != puts {
|
||||||
|
t.Errorf("a candidate said %d events and wrote %d wants", len(events)-before, kv.puts-puts)
|
||||||
|
}
|
||||||
|
if err := p.dropCandidate(ctx, "run-7"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, ok := objects[assigngraph.CandidateObject("run-7", "h1")]; ok {
|
||||||
|
t.Error("the run's group-ended left its candidate kept")
|
||||||
|
}
|
||||||
|
if _, err := assigngraph.Revision(ctx, objects, meshwants.RevisionInput{}); err != nil {
|
||||||
|
t.Errorf("dropping the run's candidate dropped trunk: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"slices"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/views"
|
||||||
|
)
|
||||||
|
|
||||||
|
// halves follows the catalog half of each watched branch through the seat mesh-catalog (design 47 G §14, §184, §195, §507, §532): the
|
||||||
|
// branch follower of meshcatalogclient, adopted on the module's views reader (A-26), follows the branches the registrations name
|
||||||
|
// and, before the first registrations, the branches the gate's verb `source` answers and its event `source-moved` brings; each
|
||||||
|
// branch's view asks the verb `revision`, hears each `catalog-revision` of that branch and raises and clears the follower's findings;
|
||||||
|
// each entry is taken into the world as the value and the graph node the rules read. Of the view the assigner reads only the catalog
|
||||||
|
// half, never its own output back (§195).
|
||||||
|
type halves struct {
|
||||||
|
w *world
|
||||||
|
call mcc.Call
|
||||||
|
reader *views.ProcessReader
|
||||||
|
wake func()
|
||||||
|
logf func(string, ...any)
|
||||||
|
ctx context.Context
|
||||||
|
|
||||||
|
branches *mcc.Branches
|
||||||
|
mu sync.Mutex
|
||||||
|
// settled is told once when the first watched branch's first view is answered, for the first pass to wait on.
|
||||||
|
settled chan<- struct{}
|
||||||
|
told bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// follow makes the branch follower on the reader; the reader's start asks the first views.
|
||||||
|
func (h *halves) follow() error {
|
||||||
|
b, err := mcc.FollowBranchesProcess(h.reader, h.call)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.Logf = h.logf
|
||||||
|
b.Changed = func(branch, module string, entry json.RawMessage, deleted bool, _ time.Time) {
|
||||||
|
h.changed(branch, module, entry, deleted)
|
||||||
|
}
|
||||||
|
b.Adopted = h.adopted
|
||||||
|
h.mu.Lock()
|
||||||
|
h.branches = b
|
||||||
|
h.mu.Unlock()
|
||||||
|
h.settleWhenNoBranch()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// settleWhenNoBranch tells the first pass once, when the registrations and the gate's source are answered and name no branch: the
|
||||||
|
// trunk is none-yet and the world is empty, as the catalog client's Ready says it (design 47 G, A-372). A mesh that names a branch is
|
||||||
|
// told by adopted, when that branch's first view is answered.
|
||||||
|
func (h *halves) settleWhenNoBranch() {
|
||||||
|
if h.settled == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.mu.Lock()
|
||||||
|
b := h.branches
|
||||||
|
h.mu.Unlock()
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-b.FirstViews(h.ctx):
|
||||||
|
case <-h.ctx.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(b.Followed()) > 0 || b.Ready() != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.mu.Lock()
|
||||||
|
told := h.told
|
||||||
|
h.told = true
|
||||||
|
h.mu.Unlock()
|
||||||
|
if !told {
|
||||||
|
h.settled <- struct{}{}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// first is the first watched branch followed, the trunk's: "" while none is.
|
||||||
|
func (h *halves) first() string {
|
||||||
|
h.mu.Lock()
|
||||||
|
b := h.branches
|
||||||
|
h.mu.Unlock()
|
||||||
|
if b == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if f := b.Followed(); len(f) > 0 {
|
||||||
|
return f[0]
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// adopted is told of each branch whose view the follower adopted: the first branch is the trunk's, and the first pass waits for its
|
||||||
|
// first view.
|
||||||
|
func (h *halves) adopted(branch string, c *mcc.Catalog) {
|
||||||
|
first := h.first()
|
||||||
|
if first == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.w.setTrunk(first)
|
||||||
|
h.wake()
|
||||||
|
if branch != first || h.settled == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.mu.Lock()
|
||||||
|
told := h.told
|
||||||
|
h.told = true
|
||||||
|
h.mu.Unlock()
|
||||||
|
if told {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-c.Ready():
|
||||||
|
h.settled <- struct{}{}
|
||||||
|
case <-h.ctx.Done():
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// changed takes one entry of branch's half into the world, or a module taken out of it.
|
||||||
|
func (h *halves) changed(branch, module string, raw json.RawMessage, deleted bool) {
|
||||||
|
defer h.wake()
|
||||||
|
if deleted {
|
||||||
|
h.w.dropModule(branch, module)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var e meshcatalog.CatalogEntry
|
||||||
|
if err := json.Unmarshal(raw, &e); err != nil {
|
||||||
|
h.logf("the entry of %s on branch %q does not read: %v", module, branch, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v, n, m := fromEntry(e)
|
||||||
|
h.w.putModule(branch, module, v, n, m)
|
||||||
|
h.w.putEdges(branch, module, e.Edges)
|
||||||
|
}
|
||||||
|
|
||||||
|
// fromEntry is a catalog entry as the value and the graph node the rules read, and its manifest parsed once under the digest of
|
||||||
|
// its words.
|
||||||
|
func fromEntry(e meshcatalog.CatalogEntry) (meshcatalog.ModulesByModuleValue, graph.Node, *parsed) {
|
||||||
|
v := meshcatalog.ModulesByModuleValue{Commit: e.Commit, Fp2: e.Fp, Needs: e.Needs, None2: e.None, Packages: e.Packages,
|
||||||
|
Path: e.Path, Repository: e.Repository, Verdict: e.Verdict}
|
||||||
|
// The source revisions it was taken in at and its fingerprint was built at: the release of a trunk build is matched by the
|
||||||
|
// latter (design 47 G A-419).
|
||||||
|
if e.Inputs != nil {
|
||||||
|
v.Src, v.FpSrc = e.Inputs.Src, e.Inputs.FpSrc
|
||||||
|
}
|
||||||
|
n := graph.Node{FP: e.Fp, None: e.None, Repository: e.Repository, Path: e.Path, Bases: e.Bases, Provides: e.Provides, Requires: e.Requires,
|
||||||
|
Awaits: e.Awaits, Invokes: e.Invokes, Serves: e.Serves, LeftOut: e.LeftOut}
|
||||||
|
for p := range e.Packages {
|
||||||
|
n.Packages = append(n.Packages, p)
|
||||||
|
}
|
||||||
|
slices.Sort(n.Packages)
|
||||||
|
if len(e.Manifest) == 0 {
|
||||||
|
return v, n, nil
|
||||||
|
}
|
||||||
|
raw, err := json.Marshal(e.Manifest)
|
||||||
|
if err != nil {
|
||||||
|
return v, n, nil
|
||||||
|
}
|
||||||
|
sum := sha256.Sum256(raw)
|
||||||
|
v.Manifest = "sha256:" + hex.EncodeToString(sum[:])
|
||||||
|
man, err := catalogue.Decode(raw)
|
||||||
|
if err != nil {
|
||||||
|
return v, n, &parsed{module: e.Module, err: "it does not decode: " + err.Error()}
|
||||||
|
}
|
||||||
|
n.Serves = graph.ServesOf(man)
|
||||||
|
// The entry's requires name the optional ones too; the node means those required, not optionally (A-229).
|
||||||
|
n.Requires = slices.DeleteFunc(slices.Clone(n.Requires), man.IsOptional)
|
||||||
|
return v, n, &parsed{module: e.Module, manifest: man}
|
||||||
|
}
|
||||||
|
|
||||||
|
// views is the catalog graph revision held now of each followed branch whose first view is answered.
|
||||||
|
func (h *halves) views() map[string]mcc.Half {
|
||||||
|
h.mu.Lock()
|
||||||
|
b := h.branches
|
||||||
|
h.mu.Unlock()
|
||||||
|
out := map[string]mcc.Half{}
|
||||||
|
if b == nil {
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
for _, branch := range b.Followed() {
|
||||||
|
if c, ok := b.Catalog(branch); ok {
|
||||||
|
if half, ok := c.View(); ok {
|
||||||
|
out[branch] = half
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/views"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Design 47 G A-372: the assigner's wait for its catalog half asks the catalog client's Ready as well: a mesh whose registrations and
|
||||||
|
// gate's source are answered and name no branch is none-yet, and the first pass is told so once; before they answer it is not told.
|
||||||
|
func TestAMeshThatNamesNoBranchSettlesTheAssignersFirstPass(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
call := func(key string, _ any) (json.RawMessage, error) {
|
||||||
|
if key == mcc.RegistrationsVerb {
|
||||||
|
return json.Marshal(seat.RegistrationsAnswer{Registrations: []seat.Registration{}})
|
||||||
|
}
|
||||||
|
return json.Marshal(map[string][]string{"branches": {}})
|
||||||
|
}
|
||||||
|
for _, answered := range []bool{false, true} {
|
||||||
|
settled := make(chan struct{}, 2)
|
||||||
|
reader := &views.ProcessReader{Module: "mesh-delivery-assigner", Call: call, Logf: t.Logf}
|
||||||
|
h := &halves{w: newWorld(), call: call, reader: reader, wake: func() {}, logf: t.Logf, ctx: ctx, settled: settled}
|
||||||
|
if err := h.follow(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if answered {
|
||||||
|
for _, f := range reader.Followers() {
|
||||||
|
if err := f.Start(ctx); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-settled:
|
||||||
|
case <-ctx.Done():
|
||||||
|
t.Fatal("a mesh that names no branch never settled the first pass")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-settled:
|
||||||
|
t.Errorf("answered %v: the first pass was told twice or before the first views", answered)
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,581 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/stateobjects"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A step's input by its digest (design 47 G §354, §712, A-237, A-243): the assigner keeps the input of each composition step
|
||||||
|
// request it asked a build seat to run in its state `inputs`, one key per input, its sha256 alone (A-465a), the value the input's bytes in
|
||||||
|
// base64 with the state's object store `inputs-objects` holding one over a key's limit (mesh-sdk stateobjects), and the seat
|
||||||
|
// mesh-wants' verb `input` answers one by its digest in chunks, to the holders of the build seats alone (the verb's callers, §338).
|
||||||
|
// An input is kept once per content: every ask that names its digest shares it (A-465a). It is deleted, with its object, when the
|
||||||
|
// step-ended of the last ask that names it is heard, or a day after its last write, whichever is first, the day judged at each new
|
||||||
|
// ask over at most 20 of the oldest inputs. `assigner_inputs` reads them. This mirrors the indexer's
|
||||||
|
// (mesh-delivery-indexer internal/index/run_inputs.go): the two are separate modules' code, owed to mesh-sdk.
|
||||||
|
|
||||||
|
// inputsTool is the tool that reads the kept inputs.
|
||||||
|
const inputsTool = "assigner_inputs"
|
||||||
|
|
||||||
|
const (
|
||||||
|
// inputsKeptFor is how long an input is kept at the longest.
|
||||||
|
inputsKeptFor = 24 * time.Hour
|
||||||
|
// inputsSwept is how many of the oldest keys each new ask judges.
|
||||||
|
inputsSwept = 20
|
||||||
|
inputsTime = "20060102T150405Z"
|
||||||
|
// inputsAskPrefix opens the keys that name an input by the id of the ask it was kept for: ask.<id>, the id escaped as a name,
|
||||||
|
// holding the digest of the input the ask uses, so the build seat's step-ended of that ask finds it.
|
||||||
|
inputsAskPrefix = "ask."
|
||||||
|
)
|
||||||
|
|
||||||
|
// inputAsk is what an ask's key holds (A-465b): the digest of the input the ask uses and the time the ask wrote it, in inputsTime.
|
||||||
|
type inputAsk struct {
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
At string `json:"at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// readAsk reads an ask's key: the JSON form, or the bare key of the old form `<time>.<digest>` an earlier assigner wrote, which
|
||||||
|
// carries its time in the key itself.
|
||||||
|
func readAsk(raw []byte) (digest string, at time.Time) {
|
||||||
|
var a inputAsk
|
||||||
|
if json.Unmarshal(raw, &a) == nil && a.Digest != "" {
|
||||||
|
at, _ = time.Parse(inputsTime, a.At)
|
||||||
|
return a.Digest, at
|
||||||
|
}
|
||||||
|
digest = string(raw)
|
||||||
|
t, _, _ := strings.Cut(digest, ".")
|
||||||
|
at, _ = time.Parse(inputsTime, t)
|
||||||
|
return digest, at
|
||||||
|
}
|
||||||
|
|
||||||
|
// isDigest is whether a key is an input's own key: 64 hex digits.
|
||||||
|
func isDigest(key string) bool {
|
||||||
|
if len(key) != 64 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
_, err := hex.DecodeString(key)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// digestOf is an input's digest as the ask names it: its sha256 in hex.
|
||||||
|
func digestOf(b []byte) string { sum := sha256.Sum256(b); return hex.EncodeToString(sum[:]) }
|
||||||
|
|
||||||
|
// inputsCap is the state inputs' cap (design 47 G §354's kept-data row: 64 MiB, the manifest's max-mib): at it, an ask is refused.
|
||||||
|
const inputsCap = 64 << 20
|
||||||
|
|
||||||
|
// inputKeeper keeps the inputs over the state and its object store.
|
||||||
|
type inputKeeper struct {
|
||||||
|
vals stateobjects.Values
|
||||||
|
now func() time.Time
|
||||||
|
logf func(string, ...any)
|
||||||
|
// used is how many bytes the state and its object store hold; nil judges no cap.
|
||||||
|
used func() (int64, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// keep keeps the exact bytes of the input of the ask under their sha256, after sweeping, and names the digest and the time in the
|
||||||
|
// ask's key; it answers the digest. The same bytes asked again are the same one input (A-465a, A-465b). The ask's key is written
|
||||||
|
// first, so a sweep never finds the input unnamed.
|
||||||
|
func (k *inputKeeper) keep(ask string, body []byte) (string, error) {
|
||||||
|
if ask == "" {
|
||||||
|
return "", errors.New("name the ask the input is kept for")
|
||||||
|
}
|
||||||
|
if err := k.sweep(); err != nil {
|
||||||
|
k.logf("inputs: the keys older than a day are not all deleted: %v", err)
|
||||||
|
}
|
||||||
|
digest := digestOf(body)
|
||||||
|
raw, err := json.Marshal(inputAsk{Digest: digest, At: k.now().UTC().Format(inputsTime)})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
askKey := inputsAskPrefix + keys.EscapeName(ask)
|
||||||
|
if err := k.vals.KV.Create(askKey, raw); err != nil && !errors.Is(err, stateobjects.ErrChanged) {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
have, err := k.vals.KV.Get(digest)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if have != nil {
|
||||||
|
return digest, nil
|
||||||
|
}
|
||||||
|
if k.used != nil {
|
||||||
|
used, err := k.used()
|
||||||
|
if err == nil && used+int64(len(body)) > inputsCap {
|
||||||
|
err = fmt.Errorf("the state %s is at its cap of %d MiB (%d bytes kept), so the ask's input of %d bytes is refused",
|
||||||
|
buckets.InputsState, inputsCap>>20, used, len(body))
|
||||||
|
} else if err != nil {
|
||||||
|
err = fmt.Errorf("the fill of the state %s is not read, so no input is kept: %w", buckets.InputsState, err)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
_ = k.vals.KV.Delete(askKey)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := k.vals.Put(digest, base64.StdEncoding.EncodeToString(body)); err != nil && !errors.Is(err, stateobjects.ErrChanged) {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return digest, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ended removes the ask's key when the build seat's step-ended of that ask is heard, and deletes the input it named, with its
|
||||||
|
// object, when no other ask's key names it (A-465a); an ask that kept none changes nothing.
|
||||||
|
func (k *inputKeeper) ended(ask string) error {
|
||||||
|
if ask == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
askKey := inputsAskPrefix + keys.EscapeName(ask)
|
||||||
|
e, err := k.vals.KV.Get(askKey)
|
||||||
|
if err != nil || e == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
digest, _ := readAsk(e.Value)
|
||||||
|
if err := k.vals.KV.Delete(askKey); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
named, err := k.named()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if named[digest] {
|
||||||
|
return nil // another running ask still names it
|
||||||
|
}
|
||||||
|
return k.deleteInput(digest)
|
||||||
|
}
|
||||||
|
|
||||||
|
// named is the inputs some ask's key names now.
|
||||||
|
func (k *inputKeeper) named() (map[string]bool, error) {
|
||||||
|
all, err := k.vals.KV.Keys()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
named := map[string]bool{}
|
||||||
|
for _, key := range all {
|
||||||
|
if !strings.HasPrefix(key, inputsAskPrefix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
o, err := k.vals.KV.Get(key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if o != nil {
|
||||||
|
d, _ := readAsk(o.Value)
|
||||||
|
named[d] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return named, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// deleteInput deletes an input's key and the object that key names, when it names one (A-465): an owner that ends its own key
|
||||||
|
// ends its object. A key already gone leaves nothing to remove here; the start and assigner_inputs_drop remove what a key left.
|
||||||
|
func (k *inputKeeper) deleteInput(key string) error {
|
||||||
|
e, err := k.vals.KV.Get(key)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := k.vals.KV.Delete(key); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if e == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if ref, ok := stateobjects.ReadRef(e.Value); ok {
|
||||||
|
if err := k.vals.Objects.Delete(ref.Object); err != nil {
|
||||||
|
return fmt.Errorf("the object %s of %s: %w", ref.Object, key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// dropKeyGone removes every object of the state whose key is gone and answers their count and bytes (A-465).
|
||||||
|
func (k *inputKeeper) dropKeyGone() (dropped []stateobjects.Kept, bytes int64, err error) {
|
||||||
|
kept, err := k.vals.Kept()
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
names, err := k.vals.DropKeyGone()
|
||||||
|
gone := map[string]bool{}
|
||||||
|
for _, n := range names {
|
||||||
|
gone[n] = true
|
||||||
|
}
|
||||||
|
for _, o := range kept {
|
||||||
|
if gone[o.Name] {
|
||||||
|
dropped = append(dropped, o)
|
||||||
|
bytes += o.Size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dropped, bytes, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// dropAtStart removes the objects whose key is gone at the program's start, said with their count and bytes (A-465). An object
|
||||||
|
// store not on the bus yet is said and left.
|
||||||
|
func (k *inputKeeper) dropAtStart() {
|
||||||
|
dropped, bytes, err := k.dropKeyGone()
|
||||||
|
if err != nil {
|
||||||
|
k.logf("inputs: the objects of deleted keys are not all removed at the start (%d objects, %d bytes removed): %v", len(dropped), bytes, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
k.logf("inputs: %d objects of deleted keys removed at the start, %d bytes", len(dropped), bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sweep deletes, among the 20 oldest ask keys, those written more than a day ago; every input of the digest form no ask's key names
|
||||||
|
// now, with its object; a key of the old form `<time>.<digest>` a day after the time it carries; and an old-form ask key whose
|
||||||
|
// input is gone (A-465b).
|
||||||
|
func (k *inputKeeper) sweep() error {
|
||||||
|
all, err := k.vals.KV.Keys()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var errs []error
|
||||||
|
type askAt struct {
|
||||||
|
key string
|
||||||
|
at time.Time
|
||||||
|
}
|
||||||
|
var asks []askAt
|
||||||
|
var inputs []string
|
||||||
|
for _, key := range all {
|
||||||
|
if strings.HasPrefix(key, inputsAskPrefix) {
|
||||||
|
e, err := k.vals.KV.Get(key)
|
||||||
|
if err != nil || e == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
d, at := readAsk(e.Value)
|
||||||
|
if !isDigest(d) {
|
||||||
|
if gone, err := k.vals.KV.Get(d); err == nil && gone == nil {
|
||||||
|
errs = append(errs, k.vals.KV.Delete(key))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
asks = append(asks, askAt{key, at})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !isDigest(key) {
|
||||||
|
t, _, _ := strings.Cut(key, ".")
|
||||||
|
if at, err := time.Parse(inputsTime, t); err == nil && k.now().Sub(at) >= inputsKeptFor {
|
||||||
|
errs = append(errs, k.deleteInput(key))
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
inputs = append(inputs, key)
|
||||||
|
}
|
||||||
|
slices.SortFunc(asks, func(a, b askAt) int { return a.at.Compare(b.at) })
|
||||||
|
if len(asks) > inputsSwept {
|
||||||
|
asks = asks[:inputsSwept]
|
||||||
|
}
|
||||||
|
for _, a := range asks {
|
||||||
|
if !a.at.IsZero() && k.now().Sub(a.at) >= inputsKeptFor {
|
||||||
|
errs = append(errs, k.vals.KV.Delete(a.key))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
named, err := k.named()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Join(append(errs, err)...)
|
||||||
|
}
|
||||||
|
for _, key := range inputs {
|
||||||
|
if !named[key] {
|
||||||
|
errs = append(errs, k.deleteInput(key))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors.Join(errs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// keyOf is the key of the input of the digest, or none: the digest itself.
|
||||||
|
func (k *inputKeeper) keyOf(digest string) (string, error) {
|
||||||
|
if !isDigest(digest) {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
e, err := k.vals.KV.Get(digest)
|
||||||
|
if err != nil || e == nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return digest, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// body is the exact bytes of the input of the digest, checked against it, whatever its size.
|
||||||
|
func (k *inputKeeper) body(digest string) ([]byte, error) {
|
||||||
|
if len(digest) != 64 {
|
||||||
|
return nil, errors.New("input takes the input's sha256, 64 hex digits")
|
||||||
|
}
|
||||||
|
key, err := k.keyOf(digest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the state %s cannot be read: %w", buckets.InputsState, err)
|
||||||
|
}
|
||||||
|
if key == "" {
|
||||||
|
return nil, fmt.Errorf("the assigner keeps no input with the digest %s", digest)
|
||||||
|
}
|
||||||
|
var text string
|
||||||
|
found, err := k.vals.Get(key, &text)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the input %s cannot be read: %w", key, err)
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return nil, fmt.Errorf("the assigner keeps no input with the digest %s", digest)
|
||||||
|
}
|
||||||
|
b, err := base64.StdEncoding.DecodeString(text)
|
||||||
|
if err != nil || digestOf(b) != digest {
|
||||||
|
return nil, fmt.Errorf("the input %s does not hold the bytes its digest names", key)
|
||||||
|
}
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var callToken = regexp.MustCompile(`^[A-Za-z0-9_-]{16,64}$`)
|
||||||
|
|
||||||
|
// verb answers the seat's verb input (marked chunks): the digest and how many chunks carry the bytes, then sends them in chunks of at
|
||||||
|
// most buscalls.SeatChunkBytes on the call's chunk subjects, each acknowledged before the next (A-237, A-139). The input is of any
|
||||||
|
// size. A caller that does not acknowledge within `within` ends the send, said in logf.
|
||||||
|
func (k *inputKeeper) verb(line buscalls.ChunkLine, within time.Duration) process.SeatHandler {
|
||||||
|
return func(_ string, raw json.RawMessage) (any, error) {
|
||||||
|
var in meshwants.InputInput
|
||||||
|
if err := json.Unmarshal(raw, &in); err != nil {
|
||||||
|
return nil, fmt.Errorf("the arguments are not JSON: %w", err)
|
||||||
|
}
|
||||||
|
if !callToken.MatchString(in.Call) {
|
||||||
|
return nil, errors.New("call is one token of 16 to 64 letters, digits, - or _: 128 random bits the caller chooses")
|
||||||
|
}
|
||||||
|
digest := strings.TrimPrefix(strings.TrimSpace(in.Digest), "sha256:")
|
||||||
|
body, err := k.body(digest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
send := buscalls.SeatChunks{Seat: meshwants.Seat, Verb: meshwants.VerbInput, Call: in.Call}
|
||||||
|
total := int64((len(body) + buscalls.SeatChunkBytes - 1) / buscalls.SeatChunkBytes)
|
||||||
|
// the send subscribes to the acknowledgements itself and ends when it has sent every chunk or one is not acknowledged
|
||||||
|
go func() {
|
||||||
|
if err := send.Send(line, body, within, k.logf); err != nil {
|
||||||
|
k.logf("the send %s of the input %s: %v", in.Call, digest, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return meshwants.InputAnswer{Digest: digest, Chunks: total}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// inputObjects is the object store beside the state inputs (`inputs-objects`, a state's own, §712), opened when first used: until
|
||||||
|
// the grants part has made it every call is process.ErrNotYet.
|
||||||
|
type inputObjects struct {
|
||||||
|
js jetstream.JetStream
|
||||||
|
module string
|
||||||
|
mu sync.Mutex
|
||||||
|
bus stateobjects.Objects
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *inputObjects) open() (stateobjects.Objects, error) {
|
||||||
|
o.mu.Lock()
|
||||||
|
defer o.mu.Unlock()
|
||||||
|
if o.bus != nil {
|
||||||
|
return o.bus, nil
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
store, err := o.js.ObjectStore(ctx, catalogue.BusName(o.module, catalogue.StateObjectsName(buckets.InputsState)))
|
||||||
|
if errors.Is(err, jetstream.ErrBucketNotFound) || errors.Is(err, jetstream.ErrStreamNotFound) {
|
||||||
|
return nil, fmt.Errorf("the object store of the state inputs is not on the bus yet: %w", process.ErrNotYet)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the object store of the state inputs is not open: %w", err)
|
||||||
|
}
|
||||||
|
o.bus = stateobjects.BusObjects{Store: store}
|
||||||
|
return o.bus, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *inputObjects) MostBytes() int { return 0 }
|
||||||
|
|
||||||
|
func (o *inputObjects) Put(name string, data []byte) error {
|
||||||
|
b, err := o.open()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return b.Put(name, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *inputObjects) Get(name string) ([]byte, error) {
|
||||||
|
b, err := o.open()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return b.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *inputObjects) Delete(name string) error {
|
||||||
|
b, err := o.open()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return b.Delete(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *inputObjects) List() ([]stateobjects.Object, error) {
|
||||||
|
b, err := o.open()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return b.List()
|
||||||
|
}
|
||||||
|
|
||||||
|
// inputsOver is the inputs the program keeps, over its bucket and its object store beside it; nil when the bucket is not opened.
|
||||||
|
func inputsOver(kv jetstream.KeyValue, js jetstream.JetStream, module string, logf func(string, ...any)) *inputKeeper {
|
||||||
|
if kv == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
objects := &inputObjects{js: js, module: module}
|
||||||
|
v := stateobjects.Values{KV: stateobjects.BusKV{KV: kv}, Objects: objects, Store: catalogue.StateObjectsName(buckets.InputsState)}
|
||||||
|
used := func() (int64, error) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
st, err := kv.Status(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
n := int64(st.Bytes())
|
||||||
|
objs, err := objects.List()
|
||||||
|
if err != nil && !errors.Is(err, process.ErrNotYet) {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
for _, o := range objs {
|
||||||
|
n += o.Size
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
return &inputKeeper{vals: v, now: time.Now, logf: logf, used: used}
|
||||||
|
}
|
||||||
|
|
||||||
|
// inputSaid is one kept input as assigner_inputs lists it.
|
||||||
|
type inputSaid struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Time string `json:"time"`
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
Size int `json:"size"`
|
||||||
|
Input string `json:"input,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// inputsRead is the tool assigner_inputs over the kept inputs: every kept input with its size, or the one named by digest whole.
|
||||||
|
func inputsRead(k *inputKeeper) stdio.Tool {
|
||||||
|
return stdio.Tool{Name: inputsTool, Description: "The inputs the assigner keeps for the composition steps it asked a build seat to run (design 47 G §354): each " +
|
||||||
|
"with its write time, digest and size, or one by `digest` whole (base64). Read-only.",
|
||||||
|
Input: schema(map[string]string{"digest": "one input's sha256"}, nil), Run: func(args map[string]any) (any, error) {
|
||||||
|
want := arg(args, "digest")
|
||||||
|
all, err := k.vals.KV.Keys()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the inputs cannot be listed: %w", err)
|
||||||
|
}
|
||||||
|
slices.Sort(all)
|
||||||
|
lastAsk := map[string]string{} // the latest write time an ask's key names for each input
|
||||||
|
for _, key := range all {
|
||||||
|
if e, err := k.vals.KV.Get(key); err == nil && e != nil && strings.HasPrefix(key, inputsAskPrefix) {
|
||||||
|
if d, at := readAsk(e.Value); !at.IsZero() && at.Format(inputsTime) > lastAsk[d] {
|
||||||
|
lastAsk[d] = at.Format(inputsTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out := []inputSaid{}
|
||||||
|
for _, key := range all {
|
||||||
|
d := key
|
||||||
|
if !isDigest(key) || (want != "" && d != want) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
t := lastAsk[key]
|
||||||
|
var text string
|
||||||
|
if found, err := k.vals.Get(key, &text); err != nil || !found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
said := inputSaid{Key: key, Time: t, Digest: d, Size: base64.StdEncoding.DecodedLen(len(text))}
|
||||||
|
if b, err := base64.StdEncoding.DecodeString(text); err == nil {
|
||||||
|
said.Size = len(b)
|
||||||
|
}
|
||||||
|
if want != "" {
|
||||||
|
said.Input = text
|
||||||
|
}
|
||||||
|
out = append(out, said)
|
||||||
|
}
|
||||||
|
gone := []map[string]any{}
|
||||||
|
var goneBytes int64
|
||||||
|
answer := map[string]any{"inputs": out}
|
||||||
|
kept, err := k.vals.Kept()
|
||||||
|
if err != nil {
|
||||||
|
// never an empty list for objects that could not be read (A-465)
|
||||||
|
answer["key-gone-error"] = fmt.Sprintf("the objects of the state inputs cannot be listed, so key-gone objects are not known: %v", err)
|
||||||
|
return answer, nil
|
||||||
|
}
|
||||||
|
for _, o := range kept {
|
||||||
|
if o.KeyGone {
|
||||||
|
gone = append(gone, map[string]any{"object": o.Name, "key": o.Key, "size": o.Size})
|
||||||
|
goneBytes += o.Size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
answer["key-gone"], answer["key-gone-bytes"] = gone, goneBytes
|
||||||
|
return answer, nil
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// inputsDropTool is the tool that removes the objects whose key is gone.
|
||||||
|
const inputsDropTool = "assigner_inputs_drop"
|
||||||
|
|
||||||
|
// inputsDrop is the tool assigner_inputs_drop (A-465): a hand act, recorded first, that removes the objects of the state inputs
|
||||||
|
// whose key is gone now and answers what it removed.
|
||||||
|
func inputsDrop(k *inputKeeper, ask func(string, any) (json.RawMessage, error)) stdio.Tool {
|
||||||
|
return stdio.Tool{Name: inputsDropTool, Description: "Remove the objects of the assigner's state inputs whose key is gone now (design 47 G A-465), " +
|
||||||
|
"and answer which and how many bytes. An object a key names is never removed. Recorded as a hand act; assigner_inputs lists them as key-gone.",
|
||||||
|
Input: schema(map[string]string{"why": "why the objects of deleted keys are dropped now"}, []string{"why"}), Run: func(args map[string]any) (any, error) {
|
||||||
|
why := strings.TrimSpace(arg(args, "why"))
|
||||||
|
if why == "" {
|
||||||
|
return nil, errors.New("say why the objects of deleted keys are dropped")
|
||||||
|
}
|
||||||
|
taken, err := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: inputsDropTool, Why: why + " (" + stdio.CallerOf(args) + ")", Cause: "inputs-drop"})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the hand act was not recorded, so nothing was removed: %w", err)
|
||||||
|
}
|
||||||
|
dropped, bytes, err := k.dropKeyGone()
|
||||||
|
out := []map[string]any{}
|
||||||
|
for _, o := range dropped {
|
||||||
|
out = append(out, map[string]any{"object": o.Name, "key": o.Key, "size": o.Size})
|
||||||
|
}
|
||||||
|
return map[string]any{"dropped": out, "count": len(out), "bytes": bytes, "hand-act": taken.Log}, err
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// heardStepEnded hands the end a build seat's step-ended names to the composition run of that ask (A-240, §719), which writes it
|
||||||
|
// in the run's key, and then deletes the input kept for the ask (design 47 G §354): the run's end first, so no other act delays
|
||||||
|
// it past its bound (A-470o, A-470p). One whose run's end cannot be written, or whose input cannot be deleted, is given again by
|
||||||
|
// the bus; its redelivery finds the run ended, said as ignored for the run, and still deletes the input.
|
||||||
|
func heardStepEnded(k *inputKeeper, runEnded func(buildstep.StepEnded) error, m jetstream.Msg, logf func(string, ...any)) {
|
||||||
|
var e buildstep.StepEnded
|
||||||
|
if err := json.Unmarshal(m.Data(), &e); err != nil {
|
||||||
|
logf("%s holds what is no step-ended, left: %v", m.Subject(), err)
|
||||||
|
_ = m.Ack()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if runEnded != nil {
|
||||||
|
if err := runEnded(e); err != nil {
|
||||||
|
logf("the composition run of the ask %s is not ended, so the bus gives its step-ended again: %v", e.Ask, err)
|
||||||
|
_ = m.Nak()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := k.ended(e.Ask); err != nil {
|
||||||
|
logf("inputs: the input of the ask %s could not be deleted, so the bus gives it again: %v", e.Ask, err)
|
||||||
|
_ = m.Nak()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_ = m.Ack()
|
||||||
|
}
|
||||||
@@ -0,0 +1,503 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
|
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/stateobjects"
|
||||||
|
)
|
||||||
|
|
||||||
|
type kvMem struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
vals map[string][]byte
|
||||||
|
revs map[string]uint64
|
||||||
|
// delErr, when set, fails the next Delete once.
|
||||||
|
delErr error
|
||||||
|
}
|
||||||
|
|
||||||
|
func newKVMem() *kvMem { return &kvMem{vals: map[string][]byte{}, revs: map[string]uint64{}} }
|
||||||
|
|
||||||
|
func (k *kvMem) Get(key string) (*stateobjects.Entry, error) {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
v, ok := k.vals[key]
|
||||||
|
if !ok {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &stateobjects.Entry{Value: v, Revision: k.revs[key]}, nil
|
||||||
|
}
|
||||||
|
func (k *kvMem) Create(key string, v []byte) error {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
if _, ok := k.vals[key]; ok {
|
||||||
|
return stateobjects.ErrChanged
|
||||||
|
}
|
||||||
|
k.vals[key], k.revs[key] = v, 1
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (k *kvMem) Update(key string, v []byte, rev uint64) error {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
if k.revs[key] != rev {
|
||||||
|
return stateobjects.ErrChanged
|
||||||
|
}
|
||||||
|
k.vals[key], k.revs[key] = v, rev+1
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (k *kvMem) Delete(key string) error {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
if err := k.delErr; err != nil {
|
||||||
|
k.delErr = nil
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
delete(k.vals, key)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (k *kvMem) Keys() ([]string, error) {
|
||||||
|
k.mu.Lock()
|
||||||
|
defer k.mu.Unlock()
|
||||||
|
var out []string
|
||||||
|
for key := range k.vals {
|
||||||
|
out = append(out, key)
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type objectsMem struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
objs map[string][]byte
|
||||||
|
listErr error // List fails with it
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*objectsMem) MostBytes() int { return 0 }
|
||||||
|
func (o *objectsMem) Put(name string, data []byte) error {
|
||||||
|
o.mu.Lock()
|
||||||
|
defer o.mu.Unlock()
|
||||||
|
o.objs[name] = data
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (o *objectsMem) Get(name string) ([]byte, error) {
|
||||||
|
o.mu.Lock()
|
||||||
|
defer o.mu.Unlock()
|
||||||
|
d, ok := o.objs[name]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("no such object")
|
||||||
|
}
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
func (o *objectsMem) Delete(name string) error {
|
||||||
|
o.mu.Lock()
|
||||||
|
defer o.mu.Unlock()
|
||||||
|
delete(o.objs, name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (o *objectsMem) List() ([]stateobjects.Object, error) {
|
||||||
|
o.mu.Lock()
|
||||||
|
defer o.mu.Unlock()
|
||||||
|
if o.listErr != nil {
|
||||||
|
return nil, o.listErr
|
||||||
|
}
|
||||||
|
var out []stateobjects.Object
|
||||||
|
for n, d := range o.objs {
|
||||||
|
out = append(out, stateobjects.Object{Name: n, Size: int64(len(d))})
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// lineMem is a core bus in memory: a chunk published is kept, and its acknowledgement heard at once.
|
||||||
|
type lineMem struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
hear nats.MsgHandler
|
||||||
|
chunks map[string][]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *lineMem) Publish(subject string, data []byte) error {
|
||||||
|
l.mu.Lock()
|
||||||
|
l.chunks[subject] = data
|
||||||
|
h := l.hear
|
||||||
|
l.mu.Unlock()
|
||||||
|
var c buscalls.SeatChunk
|
||||||
|
if err := json.Unmarshal(data, &c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
go h(&nats.Msg{Subject: buscalls.SeatChunks{Seat: meshwants.Seat, Verb: meshwants.VerbInput, Call: "0123456789abcdef"}.Ack(c.N)})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *lineMem) Subscribe(_ string, fn nats.MsgHandler) (*nats.Subscription, error) {
|
||||||
|
l.mu.Lock()
|
||||||
|
l.hear = fn
|
||||||
|
l.mu.Unlock()
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func testKeeper(objs *objectsMem, now func() time.Time) *inputKeeper {
|
||||||
|
return &inputKeeper{vals: stateobjects.Values{KV: newKVMem(), Objects: objs, Store: "inputs-objects"}, now: now, logf: func(string, ...any) {}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §354, §712, A-237: an input of any size is kept as an object beside the state, and the seat mesh-wants' verb input
|
||||||
|
// answers it in chunks of at most 512 KiB, each acknowledged before the next.
|
||||||
|
func TestAnInputOverOneMiBIsKeptAsAnObjectAndAnsweredInChunks(t *testing.T) {
|
||||||
|
objs := &objectsMem{objs: map[string][]byte{}}
|
||||||
|
k := testKeeper(objs, time.Now)
|
||||||
|
body := make([]byte, 3<<20+17)
|
||||||
|
if _, err := rand.Read(body); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
digest, err := k.keep("ask-big", body)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(objs.objs) != 1 {
|
||||||
|
t.Fatalf("a large input is one object beside the state, got %d", len(objs.objs))
|
||||||
|
}
|
||||||
|
if got, err := k.body(digest); err != nil || !bytes.Equal(got, body) {
|
||||||
|
t.Fatalf("the input read back: %d bytes, %v", len(got), err)
|
||||||
|
}
|
||||||
|
line := &lineMem{chunks: map[string][]byte{}}
|
||||||
|
verb := k.verb(line, time.Second)
|
||||||
|
raw, _ := json.Marshal(meshwants.InputInput{Digest: digest, Call: "0123456789abcdef"})
|
||||||
|
out, err := verb("", raw)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ans := out.(meshwants.InputAnswer)
|
||||||
|
want := int64((len(body) + buscalls.SeatChunkBytes - 1) / buscalls.SeatChunkBytes)
|
||||||
|
if ans.Digest != digest || ans.Chunks != want || want < 6 {
|
||||||
|
t.Fatalf("the answer %+v, want %d chunks", ans, want)
|
||||||
|
}
|
||||||
|
send := buscalls.SeatChunks{Seat: meshwants.Seat, Verb: meshwants.VerbInput, Call: "0123456789abcdef"}
|
||||||
|
var got []byte
|
||||||
|
deadline := time.Now().Add(5 * time.Second)
|
||||||
|
for n := int64(1); n <= want; n++ {
|
||||||
|
for {
|
||||||
|
line.mu.Lock()
|
||||||
|
data, ok := line.chunks[send.Chunk(n)]
|
||||||
|
line.mu.Unlock()
|
||||||
|
if ok {
|
||||||
|
var c buscalls.SeatChunk
|
||||||
|
if err := json.Unmarshal(data, &c); err != nil || c.N != n || c.Of != want {
|
||||||
|
t.Fatalf("chunk %d: %+v, %v", n, c, err)
|
||||||
|
}
|
||||||
|
got = append(got, c.Data...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if time.Now().After(deadline) {
|
||||||
|
t.Fatalf("chunk %d of %d never sent", n, want)
|
||||||
|
}
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !bytes.Equal(got, body) {
|
||||||
|
t.Error("the chunks do not carry the input's bytes")
|
||||||
|
}
|
||||||
|
if _, err := verb("", json.RawMessage(`{"digest":"`+strings.Repeat("b", 64)+`","call":"0123456789abcdef"}`)); err == nil {
|
||||||
|
t.Error("an input never kept is answered")
|
||||||
|
}
|
||||||
|
if _, err := verb("", json.RawMessage(`{"digest":"`+digest+`","call":"x"}`)); err == nil {
|
||||||
|
t.Error("a call of no token is answered")
|
||||||
|
}
|
||||||
|
// assigner_inputs lists it with its size and gives one whole by digest
|
||||||
|
list, err := inputsRead(k).Run(map[string]any{})
|
||||||
|
if err != nil || len(list.(map[string]any)["inputs"].([]inputSaid)) != 1 || list.(map[string]any)["inputs"].([]inputSaid)[0].Size != len(body) {
|
||||||
|
t.Errorf("assigner_inputs = %+v %v", list, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// §354: an input is deleted when the build seat's step-ended of its ask is heard, or a day after its write, judged at each new ask.
|
||||||
|
func TestAnInputIsDeletedAtItsStepEndedOrAfterADay(t *testing.T) {
|
||||||
|
now := time.Date(2026, 11, 12, 10, 0, 0, 0, time.UTC)
|
||||||
|
k := testKeeper(&objectsMem{objs: map[string][]byte{}}, func() time.Time { return now })
|
||||||
|
d1, err := k.keep("ask/one", []byte(`{"heads":"abc"}`))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := k.body(d1); err != nil {
|
||||||
|
t.Fatalf("a kept input is not read: %v", err)
|
||||||
|
}
|
||||||
|
if err := k.ended("ask/other"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := k.body(d1); err != nil {
|
||||||
|
t.Fatalf("the step-ended of another ask deleted it: %v", err)
|
||||||
|
}
|
||||||
|
if err := k.ended("ask/one"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := k.body(d1); err == nil {
|
||||||
|
t.Error("the input of an ended ask is still answered")
|
||||||
|
}
|
||||||
|
if keys, _ := k.vals.KV.Keys(); len(keys) != 0 {
|
||||||
|
t.Errorf("keys left after the step-ended: %v", keys)
|
||||||
|
}
|
||||||
|
d2, _ := k.keep("ask/two", []byte(`{"heads":"def"}`))
|
||||||
|
now = now.Add(25 * time.Hour)
|
||||||
|
if _, err := k.keep("ask/three", []byte(`{"heads":"ghi"}`)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := k.body(d2); err == nil {
|
||||||
|
t.Error("an input a day old is still kept at the next ask")
|
||||||
|
}
|
||||||
|
// A-470o, A-470p: the step-ended's run end is written before the input is deleted; a delete that fails asks the event again,
|
||||||
|
// whose redelivery finds the run ended and still deletes the input; a run end not written asks it again with the input kept.
|
||||||
|
for _, c := range []struct {
|
||||||
|
name string
|
||||||
|
delErr error
|
||||||
|
runErr error
|
||||||
|
naked bool
|
||||||
|
runs int
|
||||||
|
deleted bool
|
||||||
|
}{
|
||||||
|
{name: "the run's end before the input's delete", runs: 1, deleted: true},
|
||||||
|
{name: "an input not deleted asks the event again", delErr: errors.New("the bus is away"), naked: true, runs: 2, deleted: true},
|
||||||
|
{name: "a run's end not written asks the event again", runErr: errors.New("the run is not read"), naked: true, runs: 1},
|
||||||
|
} {
|
||||||
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
k := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now)
|
||||||
|
d, _ := k.keep("ask/run", []byte(`{"heads":"abc"}`))
|
||||||
|
k.vals.KV.(*kvMem).delErr = c.delErr
|
||||||
|
runs := 0
|
||||||
|
runEnded := func(e buildstep.StepEnded) error {
|
||||||
|
runs++
|
||||||
|
if _, err := k.body(d); err != nil {
|
||||||
|
t.Errorf("the run's end is written after the input's delete (%d)", runs)
|
||||||
|
}
|
||||||
|
return c.runErr
|
||||||
|
}
|
||||||
|
raw, _ := json.Marshal(buildstep.StepEnded{Ask: "ask/run"})
|
||||||
|
m := &heardMsg{data: raw, subject: "step-ended"}
|
||||||
|
heardStepEnded(k, runEnded, m, t.Logf)
|
||||||
|
if m.naked != c.naked || m.acked == c.naked {
|
||||||
|
t.Fatalf("acked %v, naked %v, want naked %v", m.acked, m.naked, c.naked)
|
||||||
|
}
|
||||||
|
if m.naked && c.delErr != nil { // the redelivery
|
||||||
|
m = &heardMsg{data: raw, subject: "step-ended"}
|
||||||
|
heardStepEnded(k, func(e buildstep.StepEnded) error { runs++; return nil }, m, t.Logf)
|
||||||
|
}
|
||||||
|
if _, err := k.body(d); runs != c.runs || (err != nil) != c.deleted {
|
||||||
|
t.Errorf("the run's end heard %d times (want %d), the input deleted %v (want %v)", runs, c.runs, err != nil, c.deleted)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G A-465: an input the assigner ends itself (the step-ended of its ask, the sweep of a day-old key) ends its object
|
||||||
|
// too; the objects of keys another part deleted are removed by dropKeyGone and by the tool assigner_inputs_drop, which lists
|
||||||
|
// them as key-gone first, and never removes an object a key names.
|
||||||
|
func TestAnEndedInputEndsItsObjectAndTheDropToolRemovesWhatAKeyLeft(t *testing.T) {
|
||||||
|
now := time.Date(2026, 11, 17, 10, 0, 0, 0, time.UTC)
|
||||||
|
objs := &objectsMem{objs: map[string][]byte{}}
|
||||||
|
k := testKeeper(objs, func() time.Time { return now })
|
||||||
|
big := func(b byte) []byte { return bytes.Repeat([]byte{b}, 2<<20) }
|
||||||
|
if _, err := k.keep("ask-one", big('a')); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := k.keep("ask-two", big('b')); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(objs.objs) != 2 {
|
||||||
|
t.Fatalf("objects = %d, want 2", len(objs.objs))
|
||||||
|
}
|
||||||
|
if err := k.ended("ask-one"); err != nil || len(objs.objs) != 1 {
|
||||||
|
t.Fatalf("the step-ended left %d objects (%v), want 1", len(objs.objs), err)
|
||||||
|
}
|
||||||
|
now = now.Add(25 * time.Hour)
|
||||||
|
if _, err := k.keep("ask-three", big('c')); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(objs.objs) != 1 {
|
||||||
|
t.Fatalf("after the sweep of the day-old input %d objects, want only the new one", len(objs.objs))
|
||||||
|
}
|
||||||
|
// An object whose key another part deleted is listed as key-gone and removed by the tool; a live one stays.
|
||||||
|
keys, _ := k.vals.KV.Keys()
|
||||||
|
for _, key := range keys {
|
||||||
|
if !strings.HasPrefix(key, inputsAskPrefix) {
|
||||||
|
if err := k.vals.KV.Delete(key); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
live := []byte(`{"heads":"x"}`)
|
||||||
|
if _, err := k.keep("ask-four", append(live, make([]byte, 2<<20)...)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
list, err := inputsRead(k).Run(map[string]any{})
|
||||||
|
if err != nil || len(list.(map[string]any)["key-gone"].([]map[string]any)) != 1 {
|
||||||
|
t.Fatalf("assigner_inputs key-gone = %+v %v, want the one object of the deleted key", list, err)
|
||||||
|
}
|
||||||
|
ask := func(string, any) (json.RawMessage, error) {
|
||||||
|
return json.RawMessage(`{"answer":{"log":"hand-acts"}}`), nil
|
||||||
|
}
|
||||||
|
if _, err := inputsDrop(k, ask).Run(map[string]any{}); err == nil {
|
||||||
|
t.Error("dropped with no reason")
|
||||||
|
}
|
||||||
|
out, err := inputsDrop(k, ask).Run(map[string]any{"why": "a key left its object"})
|
||||||
|
if err != nil || out.(map[string]any)["count"] != 1 || len(objs.objs) != 1 {
|
||||||
|
t.Fatalf("assigner_inputs_drop = %+v %v, %d objects left: want one removed and the live one kept", out, err, len(objs.objs))
|
||||||
|
}
|
||||||
|
// The start drops what a key left, said with its count and bytes.
|
||||||
|
if _, err := k.keep("ask-five", live); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, key := range keysOf(t, k) {
|
||||||
|
if !strings.HasPrefix(key, inputsAskPrefix) {
|
||||||
|
_ = k.vals.KV.Delete(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var logged []string
|
||||||
|
k.logf = func(f string, a ...any) { logged = append(logged, fmt.Sprintf(f, a...)) }
|
||||||
|
before := len(objs.objs)
|
||||||
|
k.dropAtStart()
|
||||||
|
if len(objs.objs) != 0 || before == 0 || len(logged) != 1 || !strings.Contains(logged[0], fmt.Sprintf("%d objects of deleted keys removed at the start", before)) || !strings.Contains(logged[0], " bytes") {
|
||||||
|
t.Errorf("the start left %d of %d objects and said %q: want every key-gone object removed and its count and bytes said", len(objs.objs), before, logged)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func keysOf(t *testing.T, k *inputKeeper) []string {
|
||||||
|
t.Helper()
|
||||||
|
keys, err := k.vals.KV.Keys()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G A-465: assigner_inputs says why key-gone objects are not known when the objects cannot be listed, and never
|
||||||
|
// answers them as none.
|
||||||
|
func TestAssignerInputsSaysWhenTheKeyGoneObjectsCannotBeListed(t *testing.T) {
|
||||||
|
objs := &objectsMem{objs: map[string][]byte{}, listErr: errors.New("the object store does not answer")}
|
||||||
|
k := testKeeper(objs, time.Now)
|
||||||
|
out, err := inputsRead(k).Run(map[string]any{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
m := out.(map[string]any)
|
||||||
|
if msg, _ := m["key-gone-error"].(string); !strings.Contains(msg, "does not answer") {
|
||||||
|
t.Errorf("answer %+v: want key-gone-error naming the failure", m)
|
||||||
|
}
|
||||||
|
if _, has := m["key-gone"]; has {
|
||||||
|
t.Errorf("answer %+v: an unreadable store is not answered as no key-gone objects", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G A-465a: an input is kept once per content under its sha256 alone; every ask names the digest it uses, and the input
|
||||||
|
// goes, with its object, at the step-ended of the last ask that names it, or a day after its last write; a request the cap still
|
||||||
|
// refuses says the fill; an input of the old form (a key that is no digest) is ended with its object.
|
||||||
|
func TestAnInputIsKeptOncePerContentAndEndsWithItsLastAsk(t *testing.T) {
|
||||||
|
now := time.Date(2026, 11, 17, 10, 0, 0, 0, time.UTC)
|
||||||
|
objs := &objectsMem{objs: map[string][]byte{}}
|
||||||
|
k := testKeeper(objs, func() time.Time { return now })
|
||||||
|
body := bytes.Repeat([]byte{'n'}, 2<<20)
|
||||||
|
var digests []string
|
||||||
|
for _, ask := range []string{"ask-1", "ask-2", "ask-3"} {
|
||||||
|
d, err := k.keep(ask, body)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
digests = append(digests, d)
|
||||||
|
}
|
||||||
|
if digests[0] != digestOf(body) || digests[1] != digests[0] || digests[2] != digests[0] {
|
||||||
|
t.Fatalf("digests = %v, want the sha256 of the bytes each time", digests)
|
||||||
|
}
|
||||||
|
if _, err := k.vals.KV.Get(digests[0]); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if e, _ := k.vals.KV.Get(digests[0]); e == nil || len(objs.objs) != 1 {
|
||||||
|
t.Fatalf("one key by the digest and one object wanted, got entry %v and %d objects", e, len(objs.objs))
|
||||||
|
}
|
||||||
|
for _, key := range keysOf(t, k) {
|
||||||
|
if !strings.HasPrefix(key, inputsAskPrefix) && key != digests[0] {
|
||||||
|
t.Errorf("a key %q beside the one input", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if e, _ := k.vals.KV.Get(inputsAskPrefix + "ask-2"); e == nil || !strings.Contains(string(e.Value), digests[0]) || !strings.Contains(string(e.Value), "20261117T100000Z") {
|
||||||
|
t.Errorf("the ask does not name the digest it uses: %v", e)
|
||||||
|
}
|
||||||
|
for _, ask := range []string{"ask-1", "ask-2"} {
|
||||||
|
if err := k.ended(ask); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := k.body(digests[0]); err != nil {
|
||||||
|
t.Fatalf("the input went at the end of %s while ask-3 still names it: %v", ask, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := k.ended("ask-3"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := k.body(digests[0]); err == nil || len(objs.objs) != 0 || len(keysOf(t, k)) != 0 {
|
||||||
|
t.Errorf("the last step-ended left the input (%v), %d objects, keys %v", err, len(objs.objs), keysOf(t, k))
|
||||||
|
}
|
||||||
|
// a day after its last write, a renewed write counted
|
||||||
|
if _, err := k.keep("ask-4", body); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
now = now.Add(20 * time.Hour)
|
||||||
|
if _, err := k.keep("ask-5", body); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
now = now.Add(20 * time.Hour)
|
||||||
|
if _, err := k.keep("ask-6", []byte("other")); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := k.body(digests[0]); err != nil {
|
||||||
|
t.Errorf("an input written again 20 hours ago was swept: %v", err)
|
||||||
|
}
|
||||||
|
now = now.Add(25 * time.Hour)
|
||||||
|
if _, err := k.keep("ask-7", []byte("another")); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := k.body(digests[0]); err == nil || len(objs.objs) != 0 {
|
||||||
|
t.Errorf("an input a day after its last write is kept (%v), %d objects", err, len(objs.objs))
|
||||||
|
}
|
||||||
|
// an input of the old form goes a day after the time its key carries, with its object, never earlier
|
||||||
|
old := "20261117T090000Z." + digestOf([]byte("old"))
|
||||||
|
if err := k.vals.Put(old, base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{'o'}, 2<<20))); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
recent := now.Add(-time.Hour).Format(inputsTime) + "." + digestOf([]byte("recent"))
|
||||||
|
if err := k.vals.Put(recent, "cmVjZW50"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := k.sweep(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if e, _ := k.vals.KV.Get(old); e != nil || len(objs.objs) != 0 {
|
||||||
|
t.Errorf("the input of the old form is kept (%v) with %d objects", e, len(objs.objs))
|
||||||
|
}
|
||||||
|
if e, _ := k.vals.KV.Get(recent); e == nil {
|
||||||
|
t.Error("an input of the old form under a day old was deleted early")
|
||||||
|
}
|
||||||
|
// a new content the cap refuses says the fill; the same content, already kept, needs no room
|
||||||
|
full := newTestKeeperWithFill(objs, now, inputsCap-10)
|
||||||
|
if _, err := full.keep("ask-8", []byte("fits")); err != nil {
|
||||||
|
t.Fatalf("a content that fits is refused: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := full.keep("ask-9", []byte("does not fit at all")); err == nil || !strings.Contains(err.Error(), "bytes kept") {
|
||||||
|
t.Errorf("the refusal does not name the fill: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := full.keep("ask-10", []byte("fits")); err != nil {
|
||||||
|
t.Errorf("the content already kept is refused at the cap: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestKeeperWithFill(objs *objectsMem, now time.Time, used int64) *inputKeeper {
|
||||||
|
k := testKeeper(objs, func() time.Time { return now })
|
||||||
|
k.used = func() (int64, error) { return used, nil }
|
||||||
|
return k
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -8,15 +8,22 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"maps"
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
"mesh-delivery-assigner/internal/assignment"
|
"mesh-delivery-assigner/internal/assignment"
|
||||||
"mesh-delivery-assigner/internal/buckets"
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -24,9 +31,11 @@ import (
|
|||||||
"github.com/nats-io/nats.go/jetstream"
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||||
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
||||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
"git.novox.be/novox/mesh-sdk/go/announce"
|
"git.novox.be/novox/mesh-sdk/go/announce"
|
||||||
"git.novox.be/novox/mesh-sdk/go/process"
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||||
@@ -38,6 +47,9 @@ import (
|
|||||||
plc "mesh-delivery-assigner/internal/assignment"
|
plc "mesh-delivery-assigner/internal/assignment"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// composeCallBound is how long the program's calls wait for an answer (main).
|
||||||
|
const composeCallBound = 3 * time.Minute
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if os.Getenv(process.BrokerFileEnv) == "" {
|
if os.Getenv(process.BrokerFileEnv) == "" {
|
||||||
// Started by the tool runner, with no credential of its own: the put's tools (ADR 0546), served through the runtime,
|
// Started by the tool runner, with no credential of its own: the put's tools (ADR 0546), served through the runtime,
|
||||||
@@ -48,6 +60,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// A call waits up to composeCallBound for its answer: compose-candidate composes a whole revision in shadow on each node and
|
||||||
|
// answered in about 34 s on g14 and shanks (2026-11-16 23:27), past the SDK's 30 s, so every composition step could not run.
|
||||||
|
// A responder that is absent still answers at once. To be replaced by a bound per verb from the seat's definition.
|
||||||
|
process.CallTimeout = composeCallBound
|
||||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
defer stop()
|
defer stop()
|
||||||
if err := run(ctx, os.Getenv, os.Stderr); err != nil {
|
if err := run(ctx, os.Getenv, os.Stderr); err != nil {
|
||||||
@@ -60,13 +76,8 @@ func main() {
|
|||||||
// holds the two lists equal), so the controller's broker grants exactly these.
|
// holds the two lists equal), so the controller's broker grants exactly these.
|
||||||
var readBuckets = []string{
|
var readBuckets = []string{
|
||||||
buckets.Grants,
|
buckets.Grants,
|
||||||
buckets.Answers,
|
|
||||||
buckets.Builds,
|
|
||||||
buckets.Presence,
|
|
||||||
buckets.Have,
|
buckets.Have,
|
||||||
buckets.Provisions,
|
buckets.Provisions,
|
||||||
buckets.Source,
|
|
||||||
buckets.Merges,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// readFamilies are the states kept one bucket per node the assigner reads, each named in its manifest's reads: every
|
// readFamilies are the states kept one bucket per node the assigner reads, each named in its manifest's reads: every
|
||||||
@@ -75,22 +86,29 @@ var readFamilies = []string{buckets.ComposedRead}
|
|||||||
|
|
||||||
// ownBuckets are the assigner's own states, as its manifest declares them: the seat mesh-module-assigner's three among them
|
// ownBuckets are the assigner's own states, as its manifest declares them: the seat mesh-module-assigner's three among them
|
||||||
// (ADR 0567 §1), named after the assigner as every module state is.
|
// (ADR 0567 §1), named after the assigner as every module state is.
|
||||||
var ownBuckets = []string{buckets.Asks, buckets.Differences,
|
func ownBuckets() []string {
|
||||||
buckets.Puts, buckets.Wants, plc.AssignmentsBucket, plc.ProposalsBucket,
|
return []string{buckets.Asks(), buckets.Differences(),
|
||||||
plc.CandidatesBucket, plc.PulsesBucket, assign.FindingsBucket, assign.PoliciesBucket, plc.SeatHoldersBucket,
|
buckets.Puts(), buckets.Wants(), plc.AssignmentsBucket(), plc.ProposalsBucket(),
|
||||||
engineReadsBucket, retiredBucket, copiesBucket}
|
plc.CandidatesBucket(), plc.PulsesBucket(), assign.FindingsBucket(), assign.PoliciesBucket(), plc.SeatHoldersBucket(),
|
||||||
|
engineReadsBucket(), retiredBucket(), copiesBucket(), writtenBucket(), buckets.Waits(), buckets.PutWaits(), buckets.DeliveryWaits(), buckets.DeliveredAgain(), buckets.Inputs(), buckets.CompositionRuns(), pinsBucket()}
|
||||||
|
}
|
||||||
|
|
||||||
// engineReadsState is the assigner's state of what each node's engine states it reads (ADR 0618 §3), one key `<node>`, as
|
// engineReadsState is the assigner's state of what each node's engine states it reads (ADR 0618 §3), one key `<node>`, as
|
||||||
// the verb manifest-reads last answered it or the fallback read it: what assigner_engine_reads lists and asks again.
|
// the verb manifest-reads last answered it or the fallback read it: what assigner_engine_reads lists and asks again.
|
||||||
const engineReadsState = "engine-reads"
|
const engineReadsState = "engine-reads"
|
||||||
|
|
||||||
// engineReadsBucket is that state's bucket.
|
// engineReadsBucket is that state's bucket.
|
||||||
const engineReadsBucket = assignment.Module + "_" + engineReadsState
|
func engineReadsBucket() string { return assignment.Module() + "_" + engineReadsState }
|
||||||
|
|
||||||
|
// writtenBucket is the bucket of the state written (pipelines.go): the pipeline ends the wants follow.
|
||||||
|
func writtenBucket() string { return assignment.Module() + "_" + writtenState }
|
||||||
|
|
||||||
// seatBuckets are the seat's states, new with it: until the controller has made them from the manifest and the bus grants
|
// seatBuckets are the seat's states, new with it: until the controller has made them from the manifest and the bus grants
|
||||||
// them, the assigner starts without them and binds each once the bus says it was created (issue 1790's kind).
|
// them, the assigner starts without them and binds each once the bus says it was created (issue 1790's kind).
|
||||||
var seatBuckets = []string{plc.AssignmentsBucket, plc.ProposalsBucket, plc.CandidatesBucket,
|
func seatBuckets() []string {
|
||||||
plc.PulsesBucket, copiesBucket}
|
return []string{plc.AssignmentsBucket(), plc.ProposalsBucket(), plc.CandidatesBucket(),
|
||||||
|
plc.PulsesBucket(), copiesBucket()}
|
||||||
|
}
|
||||||
|
|
||||||
// keptStates is what the assigner keeps and who may read it (ADR 0495 §2-§3): its wants by the watchman and the view
|
// keptStates is what the assigner keeps and who may read it (ADR 0495 §2-§3): its wants by the watchman and the view
|
||||||
// (and the node agent from release 6), its differences by the view, its asks by the view
|
// (and the node agent from release 6), its differences by the view, its asks by the view
|
||||||
@@ -106,7 +124,7 @@ var keptStates = []announce.State{
|
|||||||
{Name: "differences", Readable: true},
|
{Name: "differences", Readable: true},
|
||||||
{Name: "puts", Readable: true},
|
{Name: "puts", Readable: true},
|
||||||
{Name: "wants", Readable: true},
|
{Name: "wants", Readable: true},
|
||||||
{Name: mcc.FindingsState, Readable: true},
|
{Name: assign.FindingsState, Readable: true},
|
||||||
{Name: buckets.PoliciesState, Readable: true},
|
{Name: buckets.PoliciesState, Readable: true},
|
||||||
{Name: mma.StateSeatHolders, Readable: true},
|
{Name: mma.StateSeatHolders, Readable: true},
|
||||||
{Name: views.MarksState, Readable: true}, // what its views family said each state up to (views.go)
|
{Name: views.MarksState, Readable: true}, // what its views family said each state up to (views.go)
|
||||||
@@ -114,6 +132,14 @@ var keptStates = []announce.State{
|
|||||||
{Name: engineReadsState, Readable: true},
|
{Name: engineReadsState, Readable: true},
|
||||||
{Name: retiredState}, // read only by the copy into assignments (migrate.go)
|
{Name: retiredState}, // read only by the copy into assignments (migrate.go)
|
||||||
{Name: copiesState, Readable: true},
|
{Name: copiesState, Readable: true},
|
||||||
|
{Name: writtenState, Readable: true},
|
||||||
|
{Name: buckets.WaitsState, Readable: true},
|
||||||
|
{Name: buckets.PutWaitsState, Readable: true}, // the put waits said (putwaits.go, design 47 G A-211)
|
||||||
|
{Name: buckets.DeliveryWaitsState, Readable: true}, // the delivery waits said (delivered.go, design 47 G A-246)
|
||||||
|
{Name: buckets.DeliveredAgainState, Readable: true}, // the asks of assigner_delivered_again (delivered.go, design 47 G A-250)
|
||||||
|
{Name: buckets.InputsState, Readable: true}, // read by the tool process alone: the verb input and assigner_inputs (design 47 G §354)
|
||||||
|
{Name: buckets.CompositionRunsState, Readable: true}, // the composition runs, read by the process and its tools (design 47 G §719, A-468c)
|
||||||
|
{Name: pinsState, Readable: true}, // the records pinning each assignment graph revision (design 47 G §579)
|
||||||
}
|
}
|
||||||
|
|
||||||
// kvSet is every bucket the assigner opened, by name.
|
// kvSet is every bucket the assigner opened, by name.
|
||||||
@@ -125,18 +151,18 @@ type kvSet map[string]jetstream.KeyValue
|
|||||||
// without it and takes no put further until it starts again (ADR 0546).
|
// without it and takes no put further until it starts again (ADR 0546).
|
||||||
func open(ctx context.Context, js process.BucketOpener, logf func(string, ...any)) (kvSet, error) {
|
func open(ctx context.Context, js process.BucketOpener, logf func(string, ...any)) (kvSet, error) {
|
||||||
out := kvSet{}
|
out := kvSet{}
|
||||||
for _, name := range append(append([]string{}, readBuckets...), ownBuckets...) {
|
for _, name := range append(append([]string{}, readBuckets...), ownBuckets()...) {
|
||||||
kv, err := js.KeyValue(ctx, name)
|
kv, err := js.KeyValue(ctx, name)
|
||||||
if name == buckets.Puts && err != nil {
|
if name == buckets.Puts() && err != nil {
|
||||||
logf("the bucket %s cannot be opened (%v): no put is taken further until the assigner starts again", name, err)
|
logf("the bucket %s cannot be opened (%v): no put is taken further until the assigner starts again", name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if slices.Contains(seatBuckets, name) && err != nil {
|
if slices.Contains(seatBuckets(), name) && err != nil {
|
||||||
// The seat's states come in the same delivery as this assigner (ADR 0567 §1): without assignments no module is placed.
|
// The seat's states come in the same delivery as this assigner (ADR 0567 §1): without assignments no module is placed.
|
||||||
logf("the bucket %s cannot be opened (%v): it is bound once the bus says it was made", name, err)
|
logf("the bucket %s cannot be opened (%v): it is bound once the bus says it was made", name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if name == plc.SeatHoldersBucket && err != nil {
|
if name == plc.SeatHoldersBucket() && err != nil {
|
||||||
// The seat's state, new with ADR 0571 §4: bound once the bus says it was made; until then nobody is told who
|
// The seat's state, new with ADR 0571 §4: bound once the bus says it was made; until then nobody is told who
|
||||||
// holds which seat here, and the controller's seats still answer.
|
// holds which seat here, and the controller's seats still answer.
|
||||||
logf("the bucket %s cannot be opened (%v): it is bound once the bus says it was made", name, err)
|
logf("the bucket %s cannot be opened (%v): it is bound once the bus says it was made", name, err)
|
||||||
@@ -148,31 +174,56 @@ func open(ctx context.Context, js process.BucketOpener, logf func(string, ...any
|
|||||||
logf("the bucket %s cannot be opened (%v): it is bound once the bus says it was made", name, err)
|
logf("the bucket %s cannot be opened (%v): it is bound once the bus says it was made", name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if name == assign.PoliciesBucket && err != nil {
|
if name == assign.PoliciesBucket() && err != nil {
|
||||||
// The seat mesh-wants' state, new with it (ADR 0565 §7): bound once the bus says it was made; until then no
|
// The seat mesh-wants' state, new with it (ADR 0565 §7): bound once the bus says it was made; until then no
|
||||||
// person's policy is read, so the controller's beside each composition holds, as before.
|
// person's policy is read, so the controller's beside each composition holds, as before.
|
||||||
logf("the bucket %s cannot be opened (%v): it is bound once the bus says it was made", name, err)
|
logf("the bucket %s cannot be opened (%v): it is bound once the bus says it was made", name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if name == assign.FindingsBucket && err != nil {
|
if name == assign.FindingsBucket() && err != nil {
|
||||||
// New with health leaving the controller (issue 1952 WM6): without it the conditions are said straight to the
|
// New with health leaving the controller (issue 1952 WM6): without it the conditions are said straight to the
|
||||||
// router and kept as no finding.
|
// router and kept as no finding.
|
||||||
logf("the bucket %s cannot be opened (%v): the assigner's conditions are said straight to the router until it starts again", name, err)
|
logf("the bucket %s cannot be opened (%v): the assigner's conditions are said straight to the router until it starts again", name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (name == buckets.Source || name == buckets.Merges) && err != nil {
|
if name == engineReadsBucket() && err != nil {
|
||||||
// The gate's source and merges (ADR 0601 §1): without them no release is known to carry a build, so every move of
|
|
||||||
// a record module is asked of a person, as before.
|
|
||||||
logf("the bucket %s cannot be opened (%v): no release's Approve answers a record ask until it is bound", name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if name == engineReadsBucket && err != nil {
|
|
||||||
// New with ADR 0618 §3: without it the statements the verb answers are kept in memory only, and
|
// New with ADR 0618 §3: without it the statements the verb answers are kept in memory only, and
|
||||||
// assigner_engine_reads lists nothing.
|
// assigner_engine_reads lists nothing.
|
||||||
logf("the bucket %s cannot be opened (%v): what each node's engine reads is kept in memory only until it starts again", name, err)
|
logf("the bucket %s cannot be opened (%v): what each node's engine reads is kept in memory only until it starts again", name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if name == retiredBucket && err != nil {
|
if name == buckets.Inputs() && err != nil {
|
||||||
|
// New with the verb input (design 47 G §354): only the tool process reads it, so the program starts without it.
|
||||||
|
logf("the bucket %s cannot be opened (%v): it is read by the tool process alone", name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if name == pinsBucket() && err != nil {
|
||||||
|
// New with the pins (design 47 G §579): without it no pin is kept and no revision is removed.
|
||||||
|
logf("the bucket %s cannot be opened (%v): no pin is kept and no revision removed until it starts again", name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if name == buckets.Waits() && err != nil {
|
||||||
|
// New with the wait on an outside cause (design 47 G §706): without it no wait is made, and a failing check is judged
|
||||||
|
// as before.
|
||||||
|
logf("the bucket %s cannot be opened (%v): no outside wait is kept until the assigner starts again", name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if name == buckets.DeliveredAgain() && err != nil {
|
||||||
|
// New with A-250: without it assigner_delivered_again is not taken until the assigner starts again.
|
||||||
|
logf("the bucket %s cannot be opened (%v): no version is said delivered again until the assigner starts again", name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if name == buckets.DeliveryWaits() && err != nil {
|
||||||
|
// New with A-246: without it no dependent waits for its dependency's delivery until the assigner starts again.
|
||||||
|
logf("the bucket %s cannot be opened (%v): no delivery wait is kept until the assigner starts again", name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if name == buckets.PutWaits() && err != nil {
|
||||||
|
// New with A-211: without it no put's wait is said until the assigner starts again.
|
||||||
|
logf("the bucket %s cannot be opened (%v): no put's wait is said until the assigner starts again", name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if name == retiredBucket() && err != nil {
|
||||||
// The retired state is read only for the copy into `assignments` (migrate.go): a mesh made after the switch has
|
// The retired state is read only for the copy into `assignments` (migrate.go): a mesh made after the switch has
|
||||||
// none, and nothing is copied.
|
// none, and nothing is copied.
|
||||||
logf("the bucket %s cannot be opened (%v): nothing is copied from it", name, err)
|
logf("the bucket %s cannot be opened (%v): nothing is copied from it", name, err)
|
||||||
@@ -195,11 +246,11 @@ func open(ctx context.Context, js process.BucketOpener, logf func(string, ...any
|
|||||||
// states and those new with a delivery of their own, bound once made, and the two that choose the grants' source.
|
// states and those new with a delivery of their own, bound once made, and the two that choose the grants' source.
|
||||||
func startsWithout(name string) bool {
|
func startsWithout(name string) bool {
|
||||||
switch name {
|
switch name {
|
||||||
case plc.SeatHoldersBucket, buckets.Provisions, assign.PoliciesBucket, assign.FindingsBucket,
|
case plc.SeatHoldersBucket(), buckets.Provisions, assign.PoliciesBucket(), assign.FindingsBucket(),
|
||||||
buckets.Puts, buckets.Source, buckets.Merges, engineReadsBucket, retiredBucket:
|
buckets.Puts(), engineReadsBucket(), retiredBucket(), writtenBucket(), buckets.Waits(), buckets.PutWaits(), buckets.DeliveryWaits(), buckets.DeliveredAgain(), buckets.Inputs(), pinsBucket():
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return slices.Contains(seatBuckets, name) || name == buckets.Grants
|
return slices.Contains(seatBuckets(), name) || name == buckets.Grants
|
||||||
}
|
}
|
||||||
|
|
||||||
// run is the program: it returns when ctx ends or the bus cannot be used.
|
// run is the program: it returns when ctx ends or the bus cannot be used.
|
||||||
@@ -209,6 +260,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
plc.SetModule(account.Module) // the assigner names its own states from its credential's module (A-296, §428)
|
||||||
conn, js, err := account.Dial()
|
conn, js, err := account.Dial()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -230,11 +282,14 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
|||||||
}
|
}
|
||||||
thisNode = account.Node
|
thisNode = account.Node
|
||||||
logger.Printf("started on the account %s, reading %d buckets", account.User, len(kvs))
|
logger.Printf("started on the account %s, reading %d buckets", account.User, len(kvs))
|
||||||
findings := findingsOf(ctx, kvs, logger.Printf)
|
findings, writer := findingsOf(ctx, account, conn, js, said, kvs, logger.Printf)
|
||||||
|
if writer != nil {
|
||||||
|
defer writer.Close()
|
||||||
|
}
|
||||||
// Each change of the states its readers read is said on its views family (ADR 0615 §5, ADR 0619 §2); a watch of it
|
// Each change of the states its readers read is said on its views family (ADR 0615 §5, ADR 0619 §2); a watch of it
|
||||||
// that ends stops the program, as a watch of what a pass reads does.
|
// that ends stops the program, as a watch of what a pass reads does.
|
||||||
viewErrs := make(chan error, len(viewedStates))
|
viewErrs := make(chan error, len(viewedStates()))
|
||||||
startViews(ctx, js, conn, account, kvs, findings, viewErrs, logger.Printf)
|
startViews(ctx, js, conn, account, kvs, wireOf(writer), viewErrs, logger.Printf)
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@@ -243,27 +298,66 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
|||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
iv := &indexerViews{js: js, account: account, call: said.Call, findings: findings, logf: logger.Printf,
|
iv := &catalogViews{js: js, account: account, call: said.Call, writer: wireOf(writer), logf: logger.Printf,
|
||||||
status: process.AwaitBucket(ctx, js, conn, firstViewsBucket, "assigner_first_views reads nothing and assigner_first_view_again is not heard", logger.Printf)}
|
status: process.AwaitBucket(ctx, js, conn, firstViewsBucket(), "assigner_first_views reads nothing and assigner_first_view_again is not heard", logger.Printf)}
|
||||||
return follow(ctx, js, conn, kvs, findings.Say(sayVia(ctx, js)), findings, emitting{said}, iv, logger)
|
// The inputs of the composition steps it asks a build seat to run: the seat mesh-wants' verb input is answered here in chunks
|
||||||
|
// of the core connection, of any size (design 47 G §354, §712, A-237).
|
||||||
|
inputs := inputsOver(kvs[buckets.Inputs()], js, account.Module, logger.Printf)
|
||||||
|
// The seat list (seatlist.go), followed in follow over the connection and the hub: the verb input's callers are checked
|
||||||
|
// against the seat's definition it holds (A-186).
|
||||||
|
gate := seatlist.NewPart("assigner", seatListAgainCallers)
|
||||||
|
if inputs != nil {
|
||||||
|
inputs.dropAtStart() // the objects of keys another part deleted (A-465)
|
||||||
|
stopInput, err := said.AnswerSeat(meshwants.Seat, seatlist.Definition(gate.Reader, meshwants.Seat), map[string]process.SeatHandler{meshwants.VerbInput: inputs.verb(conn, buscalls.SeatAckWithin)})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("answering the verb input: %w", err)
|
||||||
|
}
|
||||||
|
defer stopInput()
|
||||||
|
}
|
||||||
|
return follow(ctx, js, conn, kvs, findings.Say(sayVia(ctx, js)), findings, emitting{said}, iv, inputs, gate, logger, getenv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// findingsOf is where the assigner's said conditions go as findings (issue 1952 WM6): its findings bucket, which the
|
// findingsOf is where the assigner's said conditions go as findings (issue 1952 WM6): its findings bucket, which the
|
||||||
// condition keeper carries (novox/hq ADR 0590 §3). Without it the conditions are said straight to the router.
|
// condition keeper carries (novox/hq ADR 0590 §3). Without it the conditions are said straight to the router.
|
||||||
func findingsOf(ctx context.Context, kvs kvSet, logf func(string, ...any)) assign.Findings {
|
func findingsOf(ctx context.Context, account process.Account, conn *nats.Conn, js jetstream.JetStream, said *process.Conn, kvs kvSet, logf func(string, ...any)) (assign.Findings, *heldWriter) {
|
||||||
var f assign.Findings
|
var f assign.Findings
|
||||||
if kv := kvs[assign.FindingsBucket]; kv != nil {
|
if kvs[assign.FindingsBucket()] == nil {
|
||||||
f.Put = func(key string, value []byte) error { _, err := kv.Put(ctx, key, value); return err }
|
return f, nil
|
||||||
f.Delete = func(key string) error { return kv.Delete(ctx, key) }
|
|
||||||
f.Keys = func() ([]string, error) {
|
|
||||||
keys, err := kv.Keys(ctx)
|
|
||||||
if errors.Is(err, jetstream.ErrNoKeysFound) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return keys, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return f
|
state := said.State(assign.FindingsState)
|
||||||
|
w, err := views.NewHeldWriter(views.WriterConfig[mcseat.Finding, mcseat.FindingCleared, mcseat.FindingsStated, mcseat.FindingsAskedEvent]{
|
||||||
|
Module: account.Module, State: state, Node: account.Node, Asked: mcseat.SubjectFindingsAsked, JS: js, Conn: conn, Logf: logf})
|
||||||
|
if err != nil {
|
||||||
|
logf("the assigner's finding writer cannot be made, so its findings are not written: %v", err)
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
// A writer that cannot start (the stream of its asks is not there yet) is said; its findings are then kept in the
|
||||||
|
// state alone and said by the next start (as the node-engine's is).
|
||||||
|
if err := w.Start(ctx); err != nil {
|
||||||
|
logf("the finding writer cannot start, its findings are kept in the state alone: %v", err)
|
||||||
|
}
|
||||||
|
f.Put = func(x mcseat.Finding) error { return w.Write(ctx, x) }
|
||||||
|
f.Delete = func(key string) error {
|
||||||
|
scope, rest, _ := strings.Cut(key, ".")
|
||||||
|
i := strings.LastIndex(rest, ".")
|
||||||
|
if i < 0 {
|
||||||
|
return fmt.Errorf("%q is no finding's key", key)
|
||||||
|
}
|
||||||
|
return w.Clear(ctx, scope, rest[:i], rest[i+1:], "the assigner no longer observes it")
|
||||||
|
}
|
||||||
|
f.Keys = state.Keys
|
||||||
|
return f, w
|
||||||
|
}
|
||||||
|
|
||||||
|
// heldWriter is the assigner's finding writer: its findings are raised as they happen, so the writer holds them (design 47 G A-29).
|
||||||
|
type heldWriter = views.HeldWriter[mcseat.Finding, mcseat.FindingCleared, mcseat.FindingsStated, mcseat.FindingsAskedEvent]
|
||||||
|
|
||||||
|
// wireOf is w as the views parts' finding writer; nil when the assigner has none, so no part writes through a nil writer.
|
||||||
|
func wireOf(w *heldWriter) views.WireWriter {
|
||||||
|
if w == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
// thisNode is the node this process runs on, as its credential names it: said with each of the seat's events.
|
// thisNode is the node this process runs on, as its credential names it: said with each of the seat's events.
|
||||||
@@ -274,34 +368,43 @@ type emitting struct{ *process.Conn }
|
|||||||
|
|
||||||
func (e emitting) Emit(eventType string, body any) error { return e.Conn.Emit(eventType, body) }
|
func (e emitting) Emit(eventType string, body any) error { return e.Conn.Emit(eventType, body) }
|
||||||
|
|
||||||
|
// optionalEnds is what stops when the watch of a bucket that never gates the first pass ends.
|
||||||
|
func optionalEnds() map[string]string {
|
||||||
|
return map[string]string{buckets.Puts(): "no put is taken further", buckets.Answers: "no ask is answered"}
|
||||||
|
}
|
||||||
|
|
||||||
// watched are the buckets whose every value a pass reads; the manifests are read by digest when a pass needs one, and
|
// watched are the buckets whose every value a pass reads; the manifests are read by digest when a pass needs one, and
|
||||||
// watched only for keys, so a manifest that arrives wakes a composition that waits for it.
|
// watched only for keys, so a manifest that arrives wakes a composition that waits for it.
|
||||||
var watched = []string{
|
func watched() []string {
|
||||||
buckets.Grants,
|
return []string{
|
||||||
buckets.Answers,
|
buckets.Grants,
|
||||||
buckets.Builds,
|
plc.AssignmentsBucket(),
|
||||||
plc.AssignmentsBucket,
|
plc.ProposalsBucket(),
|
||||||
plc.ProposalsBucket,
|
plc.CandidatesBucket(),
|
||||||
plc.CandidatesBucket,
|
plc.PulsesBucket(),
|
||||||
plc.PulsesBucket,
|
copiesBucket(),
|
||||||
copiesBucket,
|
buckets.Have,
|
||||||
buckets.Presence,
|
buckets.Asks(),
|
||||||
buckets.Have,
|
buckets.Differences(),
|
||||||
buckets.Asks,
|
buckets.Wants(),
|
||||||
buckets.Differences,
|
assign.PoliciesBucket(),
|
||||||
buckets.Wants,
|
buckets.Provisions,
|
||||||
assign.PoliciesBucket,
|
plc.SeatHoldersBucket(),
|
||||||
buckets.Provisions,
|
engineReadsBucket(),
|
||||||
plc.SeatHoldersBucket,
|
writtenBucket(),
|
||||||
buckets.Source,
|
buckets.Waits(),
|
||||||
buckets.Merges,
|
buckets.PutWaits(),
|
||||||
engineReadsBucket,
|
buckets.DeliveryWaits(),
|
||||||
|
buckets.DeliveredAgain(), // its watch wakes a pass at once on an ask of assigner_delivered_again (A-250)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// follow watches every bucket a pass reads and makes a pass at start, once every watch handed what stands, and after
|
// follow watches every bucket a pass reads and makes a pass at start, once every watch handed what stands, and after
|
||||||
// each change; changes that come during a pass make one more. It returns when ctx ends or a watch ends.
|
// each change; changes that come during a pass make one more. It returns when ctx ends or a watch ends.
|
||||||
func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, kvs kvSet, say func(oc.Condition) error, findings assign.Findings, bus caller, iv *indexerViews, logger *log.Logger) error {
|
func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, kvs kvSet, say func(oc.Condition) error, findings assign.Findings, bus caller, iv *catalogViews, inputs *inputKeeper, gate *seatlist.Part, logger *log.Logger, getenv func(string) string) error {
|
||||||
w := newWorld()
|
w := newWorld()
|
||||||
|
// The callers' seat entries are resolved from the assigner's own seat-holders as it last read them (A-298).
|
||||||
|
gate.Holders(seatlist.HoldersIn(func() (map[string][]byte, error) { return w.read(plc.SeatHoldersBucket()), nil }))
|
||||||
dirty := make(chan struct{}, 1)
|
dirty := make(chan struct{}, 1)
|
||||||
wake := func() {
|
wake := func() {
|
||||||
select {
|
select {
|
||||||
@@ -309,15 +412,16 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errs := make(chan error, len(watched)+2)
|
errs := make(chan error, len(watched())+2)
|
||||||
settled := make(chan struct{}, len(watched)+2)
|
settled := make(chan struct{}, len(watched())+2)
|
||||||
// What each node's engine reads (ADR 0618 §3, §4): asked through the seat's verb, kept in the state engine-reads, read
|
// What each node's engine reads (ADR 0618 §3, §4): asked through the seat's verb, kept in the state engine-reads, read
|
||||||
// from the node's record where the engine does not answer (the fallback, said in the journal).
|
// from the node's record where the engine does not answer (the fallback, said in the journal).
|
||||||
reads := &enginereads.Keeper{Fallback: w.recordReads, Changed: wake, Logf: logger.Printf}
|
reads := &enginereads.Keeper{Fallback: w.recordReads, Changed: wake, Logf: logger.Printf}
|
||||||
if bus != nil {
|
if bus != nil {
|
||||||
reads.Call = bus.CallOn
|
reads.Call = bus.CallKeptOn // a kept call, called again through a transport fault (ADR 0668 §1)
|
||||||
|
reads.Once = bus.CallOn // its fault keeps the fallback at once while the kept call asks on (ADR 0668 §3)
|
||||||
}
|
}
|
||||||
if kv := kvs[engineReadsBucket]; kv != nil {
|
if kv := kvs[engineReadsBucket()]; kv != nil {
|
||||||
reads.Put = func(node string, v []byte) error { _, err := kv.Put(ctx, node, v); return err }
|
reads.Put = func(node string, v []byte) error { _, err := kv.Put(ctx, node, v); return err }
|
||||||
reads.Delete = func(node string) error { return kv.Delete(ctx, node) }
|
reads.Delete = func(node string) error { return kv.Delete(ctx, node) }
|
||||||
}
|
}
|
||||||
@@ -327,7 +431,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
return fmt.Errorf("the bucket %s cannot be watched: %w", name, err)
|
return fmt.Errorf("the bucket %s cannot be watched: %w", name, err)
|
||||||
}
|
}
|
||||||
// The puts' watch never stops the wants (ADR 0546): when it ends, the puts are no longer heard, said in the journal.
|
// The puts' watch never stops the wants (ADR 0546): when it ends, the puts are no longer heard, said in the journal.
|
||||||
optional := name == buckets.Puts
|
optional := name == buckets.Puts() || name == buckets.Answers
|
||||||
go func() {
|
go func() {
|
||||||
defer kw.Stop()
|
defer kw.Stop()
|
||||||
for {
|
for {
|
||||||
@@ -338,7 +442,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
case e, ok := <-kw.Updates():
|
case e, ok := <-kw.Updates():
|
||||||
if !ok {
|
if !ok {
|
||||||
if optional {
|
if optional {
|
||||||
logger.Printf("the watch of %s ended: no put is taken further until the assigner starts again", name)
|
logger.Printf("the watch of %s ended: %s until the assigner starts again", name, optionalEnds()[name])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
errs <- fmt.Errorf("the watch of %s ended", name)
|
errs <- fmt.Errorf("the watch of %s ended", name)
|
||||||
@@ -354,7 +458,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
if e.Operation() == jetstream.KeyValuePut {
|
if e.Operation() == jetstream.KeyValuePut {
|
||||||
value = e.Value()
|
value = e.Value()
|
||||||
}
|
}
|
||||||
if name == engineReadsBucket {
|
if name == engineReadsBucket() {
|
||||||
reads.Heard(e.Key(), value, value == nil) // it wakes a pass when a statement changed
|
reads.Heard(e.Key(), value, value == nil) // it wakes a pass when a statement changed
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -367,10 +471,10 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
}
|
}
|
||||||
// The puts' watch is not waited for before the first pass: a watch of them that ends before it handed what stands only
|
// The puts' watch is not waited for before the first pass: a watch of them that ends before it handed what stands only
|
||||||
// stops the puts, never the wants.
|
// stops the puts, never the wants.
|
||||||
if kvs[buckets.Puts] != nil {
|
if kvs[buckets.Puts()] != nil {
|
||||||
if err := watch(buckets.Puts); err != nil {
|
if err := watch(buckets.Puts()); err != nil {
|
||||||
logger.Printf("%v: no put is taken further until it is opened again", err)
|
logger.Printf("%v: no put is taken further until it is opened again", err)
|
||||||
delete(kvs, buckets.Puts)
|
delete(kvs, buckets.Puts())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The puts' bucket is made by the controller from the manifest's states at its start (ADR 0201), and the assigner's
|
// The puts' bucket is made by the controller from the manifest's states at its start (ADR 0201), and the assigner's
|
||||||
@@ -379,34 +483,34 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
// further, without a restart.
|
// further, without a restart.
|
||||||
var triedPuts time.Time
|
var triedPuts time.Time
|
||||||
reopenPuts := func(p *passer) {
|
reopenPuts := func(p *passer) {
|
||||||
if kvs[buckets.Puts] != nil || time.Since(triedPuts) < PutsReopenEvery {
|
if kvs[buckets.Puts()] != nil || time.Since(triedPuts) < PutsReopenEvery {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
triedPuts = time.Now()
|
triedPuts = time.Now()
|
||||||
kv, err := js.KeyValue(ctx, buckets.Puts)
|
kv, err := js.KeyValue(ctx, buckets.Puts())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
kvs[buckets.Puts] = kv
|
kvs[buckets.Puts()] = kv
|
||||||
if err := watch(buckets.Puts); err != nil {
|
if err := watch(buckets.Puts()); err != nil {
|
||||||
logger.Printf("%v: no put is taken further until it is opened again", err)
|
logger.Printf("%v: no put is taken further until it is opened again", err)
|
||||||
delete(kvs, buckets.Puts)
|
delete(kvs, buckets.Puts())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bus != nil {
|
if bus != nil {
|
||||||
p.acts = newPutActs(bus, wake, logger.Printf)
|
p.acts = newPutActs(bus, wake, logger.Printf)
|
||||||
}
|
}
|
||||||
logger.Printf("the bucket %s is open: puts are taken further", buckets.Puts)
|
logger.Printf("the bucket %s is open: puts are taken further", buckets.Puts())
|
||||||
}
|
}
|
||||||
started := 0
|
started := 0
|
||||||
for _, name := range watched {
|
for _, name := range watched() {
|
||||||
if kvs[name] == nil && startsWithout(name) {
|
if kvs[name] == nil && startsWithout(name) {
|
||||||
continue // not on the bus at this start (open said so)
|
continue // not on the bus at this start (open said so)
|
||||||
}
|
}
|
||||||
started++
|
started++
|
||||||
var opts []jetstream.WatchOpt
|
var opts []jetstream.WatchOpt
|
||||||
if name == buckets.Have || name == buckets.Source {
|
if name == buckets.Have {
|
||||||
// what each node ran healthy before, for a set-back; and the release behind each source revision (ADR 0601 §1)
|
// what each node ran healthy before, for a set-back
|
||||||
opts = append(opts, jetstream.IncludeHistory())
|
opts = append(opts, jetstream.IncludeHistory())
|
||||||
}
|
}
|
||||||
if err := watch(name, opts...); err != nil {
|
if err := watch(name, opts...); err != nil {
|
||||||
@@ -418,15 +522,54 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
hub := process.NewEventHub(logger.Printf)
|
hub := process.NewEventHub(logger.Printf)
|
||||||
// The seat list (seatlist.go), read over the connection and heard on the hub, given to catalogue at every change, and a
|
// The seat list (seatlist.go), read over the connection and heard on the hub, given to catalogue at every change, and a
|
||||||
// pass made then: registered before the hub starts.
|
// pass made then: registered before the hub starts.
|
||||||
gate := &seatGate{}
|
|
||||||
if bus != nil {
|
if bus != nil {
|
||||||
gate.follow(seatlist.ProcessBus(bus.Call, hub), wake, logger.Printf)
|
gate.Follow(seatlist.ProcessBus(bus.Call, hub), wake, logger.Printf)
|
||||||
|
}
|
||||||
|
// The build seat's step-ended of an ask deletes the input kept for it (design 47 G §354) and ends the composition run that waits
|
||||||
|
// for it (A-240). The machines a composition step does not compose are the watchman's machine-away, heard once, in the world (§64, §389).
|
||||||
|
// The composition runs (design 47 G §718, §719), watched in their own state; a build seat's step-ended of a run's ask ends
|
||||||
|
// the run in its key.
|
||||||
|
var runs *compositionRuns
|
||||||
|
if kv := kvs[buckets.CompositionRuns()]; kv != nil {
|
||||||
|
set, err := runSettingsOf(getenv)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
runs = newCompositionRuns(busRuns{ctx, js, kv}, set, time.Now, logger.Printf)
|
||||||
|
if js != nil {
|
||||||
|
runs.say = wantsPublisher(ctx, js, thisNode)
|
||||||
|
}
|
||||||
|
if bus != nil {
|
||||||
|
runs.drop = dropOver(bus.CallKept)
|
||||||
|
}
|
||||||
|
// The build seats' ask-taken and step-progress begin a run's clock (§720, A-466q).
|
||||||
|
if err := hearRunBounds(hub, runs, logger.Printf); err != nil {
|
||||||
|
logger.Printf("the build seats' ask-taken and step-progress are not heard, so a composition run is ended by no bound: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if inputs != nil {
|
||||||
|
var runEnded func(buildstep.StepEnded) error
|
||||||
|
if runs != nil && bus != nil {
|
||||||
|
read := func(e buildstep.StepEnded) ([]byte, error) { return e.ReadOutput(buildstep.AskGo, bus.CallFile) }
|
||||||
|
runEnded = func(e buildstep.StepEnded) error { return runs.heardEnd(e, read) }
|
||||||
|
}
|
||||||
|
if err := hub.Handle(nodebuildgo.SubjectStepEndedAll, func(m jetstream.Msg) { heardStepEnded(inputs, runEnded, m, logger.Printf) }); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// The indexer's manifests, modules and module graph, through its first views and views family, never its buckets
|
// The indexer's manifests, modules and module graph, through its first views and views family, never its buckets
|
||||||
// (DLV-F2r, ADR 0631): the first pass waits for the three answers, as it waits for every watch to hand what stands.
|
// (DLV-F2r, ADR 0631): the first pass waits for the three answers, as it waits for every watch to hand what stands.
|
||||||
if iv != nil {
|
if iv != nil {
|
||||||
iv.hub = hub
|
iv.hub = hub
|
||||||
started += iv.start(ctx, w, wake, settled)
|
started += iv.start(ctx, w, wake, settled)
|
||||||
|
// The teller's answers' picture is watched as a bucket is, but never gates the first pass: a teller that does not
|
||||||
|
// answer its first view only leaves the asks unanswered, said by the reader's finding (A-175).
|
||||||
|
if iv.answers != nil {
|
||||||
|
kvs[buckets.Answers] = iv.answers
|
||||||
|
if err := watch(buckets.Answers); err != nil {
|
||||||
|
logger.Printf("%v: no ask is answered until the assigner starts again", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// The seat's states arrive with the same delivery as this assigner (ADR 0567 §1): one not on the bus at this start is
|
// The seat's states arrive with the same delivery as this assigner (ADR 0567 §1): one not on the bus at this start is
|
||||||
// bound once the bus says it was created, and watched from then on, with no restart (issue 1790's kind). Until then no
|
// bound once the bus says it was created, and watched from then on, with no restart (issue 1790's kind). Until then no
|
||||||
@@ -435,15 +578,15 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
name string
|
name string
|
||||||
kv jetstream.KeyValue
|
kv jetstream.KeyValue
|
||||||
}
|
}
|
||||||
assignmentsAppeared := make(chan appeared, len(seatBuckets)+2)
|
assignmentsAppeared := make(chan appeared, len(seatBuckets())+2)
|
||||||
for _, name := range seatBuckets {
|
for _, name := range seatBuckets() {
|
||||||
if kvs[name] == nil && js != nil {
|
if kvs[name] == nil && js != nil {
|
||||||
process.AwaitBucket(ctx, js, nc, name, "the seat mesh-module-assigner waits for it",
|
process.AwaitBucket(ctx, js, nc, name, "the seat mesh-module-assigner waits for it",
|
||||||
logger.Printf).Ready(func(kv jetstream.KeyValue) { assignmentsAppeared <- appeared{name, kv} })
|
logger.Printf).Ready(func(kv jetstream.KeyValue) { assignmentsAppeared <- appeared{name, kv} })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// And the two that choose where grants are read from, with the same delivery as the grants part that writes one.
|
// And the two that choose where grants are read from, with the same delivery as the grants part that writes one.
|
||||||
for _, name := range []string{buckets.Grants, assign.PoliciesBucket, buckets.Provisions, plc.SeatHoldersBucket} {
|
for _, name := range []string{buckets.Grants, assign.PoliciesBucket(), buckets.Provisions, plc.SeatHoldersBucket()} {
|
||||||
if kvs[name] == nil && js != nil {
|
if kvs[name] == nil && js != nil {
|
||||||
name := name
|
name := name
|
||||||
process.AwaitBucket(ctx, js, nc, name, "until then the bucket is not read",
|
process.AwaitBucket(ctx, js, nc, name, "until then the bucket is not read",
|
||||||
@@ -472,16 +615,133 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
p := &passer{kvs: kvs, w: w, logf: logger.Printf, say: say, findings: findings, said: map[string]bool{}, answeredAt: map[string]uint64{},
|
p := &passer{kvs: kvs, w: w, logf: logger.Printf, say: say, findings: findings, said: map[string]bool{}, answeredAt: map[string]uint64{},
|
||||||
reads: reads, seats: gate}
|
reads: reads, seats: gate, askForFile: getenv("MESH_ASSIGNER_ASK_OPERATOR_FOR_FILE")}
|
||||||
|
p.askOperatorFor() // the setting ask-operator-for said once at the start (design 47 G A-425a)
|
||||||
|
// The wait on an outside cause (outside.go, design 47 G §706): the keeper's three events say when to judge again, and the
|
||||||
|
// seat mesh-wants' wait-held and wait-ended are said; registered before the hub starts.
|
||||||
|
if bus != nil && kvs[buckets.Waits()] != nil {
|
||||||
|
bound, settle, err := outsideSettings(getenv)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.outside = newOutsideActs(bus.CallKept, wake, logger.Printf, bound, settle)
|
||||||
|
for _, subject := range []string{mcseat.SubjectConditionRaised, mcseat.SubjectConditionChanged, mcseat.SubjectConditionCleared} {
|
||||||
|
subject := subject
|
||||||
|
if err := hub.Handle(subject, func(m jetstream.Msg) {
|
||||||
|
p.outside.Heard(m.Subject(), m.Data())
|
||||||
|
if err := m.Ack(); err != nil {
|
||||||
|
logger.Printf("acknowledging %s: %v", m.Subject(), err)
|
||||||
|
}
|
||||||
|
}); err != nil {
|
||||||
|
logger.Printf("%s is not heard, so a wait on an outside cause is judged again only when its check changes: %v", subject, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.outside.readStart()
|
||||||
|
}
|
||||||
|
if js != nil {
|
||||||
|
p.publishWants = wantsPublisher(ctx, js, thisNode)
|
||||||
|
if iv != nil && iv.h != nil {
|
||||||
|
objects := newBusObjects(js, process.Account{Node: thisNode, Module: assignment.Module()}, assigngraph.RevisionsObjects)
|
||||||
|
p.graph = &graphKeeper{objects: objects, halves: iv.h.views}
|
||||||
|
keep := func(ctx context.Context, ev meshcatalog.CatalogRevisionEvent) error {
|
||||||
|
return p.keepCandidate(ctx, iv.call, ev)
|
||||||
|
}
|
||||||
|
iv.candidates.Store(&keep)
|
||||||
|
// A held revert's running entry and its want's, asked of the seat mesh-catalog's verb entry (design 47 G §710, A-217).
|
||||||
|
p.entries = meshcatalogclient.NewEntries(iv.h.call)
|
||||||
|
p.entries.Changed = func(meshcatalogclient.EntryRow) { wake() }
|
||||||
|
// The pins of the revisions (pins.go, design 47 G §579): the gate's pinned, freed, heads-replaced and pins-stated
|
||||||
|
// on the hub, registered before it starts.
|
||||||
|
if kv := kvs[pinsBucket()]; kv != nil {
|
||||||
|
k := &pinKeeper{ctx: ctx, st: kvEnds{ctx, kv}, objects: objects, inUse: inUseOf(w), findings: findings, now: time.Now, logf: logger.Printf}
|
||||||
|
if err := k.made(); err != nil {
|
||||||
|
logger.Printf("the state %s is not marked made, so no revision is removed until it is: %v", pinsState, err)
|
||||||
|
}
|
||||||
|
if err := hearPins(hub, k); err != nil {
|
||||||
|
logger.Printf("a pin is not heard, so no revision is removed until the assigner starts again: %v", err)
|
||||||
|
} else {
|
||||||
|
p.graph.pins = k
|
||||||
|
k.watchUnpins(kv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// The node-engine seat's manifest-reads-changed, for one node (ADR 0618 §4): that node is asked again, with no timer.
|
// The node-engine seat's manifest-reads-changed, for one node (ADR 0618 §4): that node is asked again, with no timer.
|
||||||
// Heard on the assigner's durable consumer on EVENTS, which the grants part makes from the manifest's consumes; where it
|
// Heard on the assigner's durable consumer on EVENTS, which the grants part makes from the manifest's consumes; where it
|
||||||
// is not there yet, a node is asked again only when it comes back online.
|
// is not there yet, a node is asked again only when it comes back online.
|
||||||
if js != nil {
|
if js != nil {
|
||||||
hearReadsChanged(ctx, js, hub, reads, findings, gate.eventsLive, logger.Printf)
|
// The teller's ask-ended (issue 1966): an ask ended at the channel without an answer is written again; registered
|
||||||
|
// before hearReadsChanged starts the hub.
|
||||||
|
if err := hearAskEnded(ctx, js, hub, kvs[buckets.Asks()], staleOfWorld(w), logger.Printf); err != nil {
|
||||||
|
logger.Printf("%s is not heard, so an ask that ends at the operator channel without an answer is not asked again until the assigner starts again: %v", askEndedSubject, err)
|
||||||
|
}
|
||||||
|
readEndedAtBind(ctx, js, hub, kvs[buckets.Asks()], staleOfWorld(w), bus, callWait{heard: func() bool { return w.seatHeard(oc.Seat) }, findings: findings}, logger.Printf)
|
||||||
|
if kv := kvs[writtenBucket()]; kv != nil {
|
||||||
|
// The runner's pipeline-ended and group-ended (design 47 G §29): kept in the state written, which the wants follow
|
||||||
|
// once the first registrations are written (§95, §353).
|
||||||
|
p.ends = newPipelineEnds(kvEnds{ctx, kv}, wake, logger.Printf)
|
||||||
|
p.ends.trunk = w.trunkName
|
||||||
|
p.ends.runEnded = func(group string) error { return p.dropCandidate(ctx, group) }
|
||||||
|
err := hearEnds(hub, p.ends)
|
||||||
|
if err == nil && bus != nil {
|
||||||
|
err = followRegistrations(ctx, hub, bus.Call, p.ends)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
logger.Printf("a pipeline's end or a registration is not heard, so the wants keep the trunk-only form until the assigner starts again: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hearDelivery(ctx, js, w, wake, findings, logger.Printf) // version-released, version-delivered, machine-away and machine-back
|
||||||
|
hearBuilds(ctx, js, &w.ends, wake, findings, logger.Printf)
|
||||||
|
if err := hearTaken(hub, &w.taken, wake, logger.Printf); err != nil {
|
||||||
|
logger.Printf("the indexer's take-ins are not heard, so an entry held by an order edge waits until the assigner starts again: %v", err)
|
||||||
|
}
|
||||||
|
hearReadsChanged(ctx, js, hub, reads, findings, gate.EventsLive, logger.Printf)
|
||||||
|
hearRunning(ctx, js, w, wake, findings, logger.Printf)
|
||||||
}
|
}
|
||||||
if bus != nil && kvs[buckets.Puts] != nil {
|
if bus != nil && kvs[buckets.Puts()] != nil {
|
||||||
p.acts = newPutActs(bus, wake, logger.Printf)
|
p.acts = newPutActs(bus, wake, logger.Printf)
|
||||||
}
|
}
|
||||||
|
// The composition step (design 47 G §22, §354): the seat mesh-wants' accepted kind step, run by one run ask per machine.
|
||||||
|
if bus != nil && js != nil && inputs != nil && p.publishWants != nil && runs != nil {
|
||||||
|
run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFile}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept,
|
||||||
|
trunk: trunkOf(iv, w.trunkName), running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf}
|
||||||
|
steps := &compositionSteps{node: thisNode, say: p.publishWants, run: run.run, resume: run.resume, ended: runs.stepEnded, now: time.Now, logf: logger.Printf,
|
||||||
|
asker: stepAskerOf(seatlist.Definition(gate.Reader, meshwants.Seat))}
|
||||||
|
move := steps.move(ctx) // the readers a rerun carried (§727, A-470d)
|
||||||
|
runs.moved.Store(&move)
|
||||||
|
// The state's watch wakes the steps waiting on a run and hears a bound's expiry; the runs standing at the start are taken up
|
||||||
|
// once the values that stand are read (§719, §720).
|
||||||
|
if err := watchRuns(ctx, kvs[buckets.CompositionRuns()], runs, runs.expired, func() { steps.takeUp(ctx, runs) }); err != nil {
|
||||||
|
return fmt.Errorf("the state %s is not watched: %w", buckets.CompositionRunsState, err)
|
||||||
|
}
|
||||||
|
// The runs' read and drop, the seat mesh-wants' verbs compositions and compositions-drop (§728, A-469f), answered here
|
||||||
|
// where the runs are kept and the readers' ends said; the drop's hand act recorded through the seat mesh-hand-acts first.
|
||||||
|
if e, ok := bus.(emitting); ok {
|
||||||
|
record := func(q meshhandactsclient.Request) error {
|
||||||
|
_, err := meshhandactsclient.Recorder{Ask: bus.Call}.Record(q)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
stopVerbs, err := e.AnswerSeat(meshwants.Seat, seatlist.Definition(gate.Reader, meshwants.Seat), compositionVerbs(runs, steps, record))
|
||||||
|
if err != nil {
|
||||||
|
logger.Printf("the verbs %s and %s are not answered until the assigner starts again: %v", meshwants.VerbCompositions, meshwants.VerbCompositionsDrop, err)
|
||||||
|
} else {
|
||||||
|
go func() { <-ctx.Done(); stopVerbs() }()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A superseded or cancelled pipeline's composition step leaves the runs it reads (§723, A-469n).
|
||||||
|
if p.ends != nil {
|
||||||
|
left := func(pipeline string) error {
|
||||||
|
_, err := runs.leave(pipeline, steps.leave)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.ends.left.Store(&left)
|
||||||
|
}
|
||||||
|
if err := serveCompositionSteps(ctx, nc, steps); err != nil {
|
||||||
|
logger.Printf("the composition step is not heard, so no composition step runs until the assigner starts again: %v", err)
|
||||||
|
} else {
|
||||||
|
logger.Printf("the composition step is heard on %s", meshwants.AcceptSubjectStep)
|
||||||
|
}
|
||||||
|
}
|
||||||
if bus != nil {
|
if bus != nil {
|
||||||
p.seat = newSeatActs(bus, wake, logger.Printf)
|
p.seat = newSeatActs(bus, wake, logger.Printf)
|
||||||
}
|
}
|
||||||
@@ -506,7 +766,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
// be said before this credential may hear it: every pass, itself started by a watched change, binds each one the
|
// be said before this credential may hear it: every pass, itself started by a watched change, binds each one the
|
||||||
// bus now holds, and says the seat waits while one is missing.
|
// bus now holds, and says the seat waits while one is missing.
|
||||||
var unbound []string
|
var unbound []string
|
||||||
for _, name := range seatBuckets {
|
for _, name := range seatBuckets() {
|
||||||
if kvs[name] != nil || js == nil {
|
if kvs[name] != nil || js == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -531,7 +791,7 @@ var PutsReopenEvery = time.Minute
|
|||||||
// (ADR 0437 clause 9).
|
// (ADR 0437 clause 9).
|
||||||
func sayVia(ctx context.Context, js jetstream.JetStream) func(oc.Condition) error {
|
func sayVia(ctx context.Context, js jetstream.JetStream) func(oc.Condition) error {
|
||||||
return func(c oc.Condition) error {
|
return func(c oc.Condition) error {
|
||||||
subject, err := occ.ConditionSubject(assignment.Module)
|
subject, err := occ.ConditionSubject(assignment.Module())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -544,13 +804,10 @@ func sayVia(ctx context.Context, js jetstream.JetStream) func(oc.Condition) erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// hearReadsChanged hears the node-engine seat's event manifest-reads-changed on the assigner's one hub of its durable
|
// readsChangedHandler is what the assigner does with each event manifest-reads-changed: acknowledges it, keeps what it says
|
||||||
// consumer on EVENTS, and asks the node it names again; the hub also hands the indexer's views to the followers of
|
// of the node (a statement older than it does not stand) and asks the node again.
|
||||||
// indexerViews, and starts once both are registered.
|
func readsChangedHandler(reads *enginereads.Keeper, logf func(string, ...any)) func(jetstream.Msg) {
|
||||||
func hearReadsChanged(ctx context.Context, js jetstream.JetStream, hub *process.EventHub, reads *enginereads.Keeper, findings assign.Findings, live func(), logf func(string, ...any)) {
|
return func(m jetstream.Msg) {
|
||||||
account := process.Account{Node: thisNode, Module: assignment.Module}
|
|
||||||
w := notHeardWriter(findings, logf)
|
|
||||||
handle := func(m jetstream.Msg) {
|
|
||||||
if err := m.Ack(); err != nil {
|
if err := m.Ack(); err != nil {
|
||||||
logf("acknowledging %s: %v", m.Subject(), err)
|
logf("acknowledging %s: %v", m.Subject(), err)
|
||||||
}
|
}
|
||||||
@@ -561,10 +818,26 @@ func hearReadsChanged(ctx context.Context, js jetstream.JetStream, hub *process.
|
|||||||
logf("%s holds what is not %s, and %s is asked again all the same: %v", m.Subject(), enginereads.Event, node, err)
|
logf("%s holds what is not %s, and %s is asked again all the same: %v", m.Subject(), enginereads.Event, node, err)
|
||||||
reads.AskNode(node, enginereads.Event+" that does not read")
|
reads.AskNode(node, enginereads.Event+" that does not read")
|
||||||
default:
|
default:
|
||||||
|
// What the event says is kept first: a statement older than it does not stand while the node is asked again.
|
||||||
|
if e, derr := enginereads.DecodeChanged(m.Data()); derr == nil {
|
||||||
|
reads.HeardChanged(e)
|
||||||
|
}
|
||||||
reads.AskNode(node, enginereads.Event)
|
reads.AskNode(node, enginereads.Event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearReadsChanged hears the node-engine seat's event manifest-reads-changed on the assigner's one hub of its durable
|
||||||
|
// consumer on EVENTS, and asks the node it names again; the hub also hands the indexer's views to the followers of
|
||||||
|
// indexerViews, and starts once both are registered.
|
||||||
|
func hearReadsChanged(ctx context.Context, js jetstream.JetStream, hub *process.EventHub, reads *enginereads.Keeper, findings assign.Findings, live func(), logf func(string, ...any)) {
|
||||||
|
account := process.Account{Node: thisNode, Module: assignment.Module()}
|
||||||
|
w := notHeardWriter(findings, logf)
|
||||||
|
handle := readsChangedHandler(reads, logf)
|
||||||
err := hub.Handle(enginereads.SubjectPrefix+"*", handle)
|
err := hub.Handle(enginereads.SubjectPrefix+"*", handle)
|
||||||
|
// At each bind every node the assigner holds a statement of is asked again: an event said before its consumer existed
|
||||||
|
// is not delivered to it (issue 1966 note 155: ace's bootstrapped statement stood; ADR 0668 §4).
|
||||||
|
hub.OnBound(reads.AtBind(func() []string { return slices.Sorted(maps.Keys(reads.Statements())) }))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = hub.Start(ctx, js, account)
|
err = hub.Start(ctx, js, account)
|
||||||
}
|
}
|
||||||
@@ -573,8 +846,11 @@ func hearReadsChanged(ctx context.Context, js jetstream.JetStream, hub *process.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Heard(process.EventsStream)
|
w.Heard(process.EventsStream)
|
||||||
|
// The build seats' step-ended is a kept seat event, on its own stream and never on EVENTS: bound here, or no composition
|
||||||
|
// run's end is heard and every composition step waits for ever (design 47 G §354, A-240; mesh-sdk EventHub.StartKept).
|
||||||
|
logf("the kept seat events heard: %d streams bound", hub.StartKept(ctx, js, account))
|
||||||
if live != nil {
|
if live != nil {
|
||||||
live() // the seat list, unread while the seat was silent, is read now (seatGate.eventsLive)
|
live() // the seat list, unread while the seat was silent, is read now (seatlist.Part.EventsLive)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/views"
|
||||||
"mesh-delivery-assigner/internal/assign"
|
"mesh-delivery-assigner/internal/assign"
|
||||||
plc "mesh-delivery-assigner/internal/assignment"
|
plc "mesh-delivery-assigner/internal/assignment"
|
||||||
"mesh-delivery-assigner/internal/buckets"
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
@@ -25,14 +28,14 @@ import (
|
|||||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
"git.novox.be/novox/mesh-sdk/go/process"
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 1297/B2a: the buckets the program opens are exactly the manifest's reads and states, as the broker names them
|
// 1297/B2a: the buckets the program opens are exactly the manifest's reads and states, as the broker names them
|
||||||
// (`<module>.<state>` read as the bucket `<module>_<state>`), so it is granted what it reads and reads nothing else.
|
// (`<module>.<state>` read as the bucket `<module>_<state>`), so it is granted what it reads and reads nothing else.
|
||||||
func TestOpensWhatItsManifestNames(t *testing.T) {
|
func TestOpensWhatItsManifestNames(t *testing.T) {
|
||||||
// Review round 2: the assigner's views emitter writes its finding view-unsaid (Emitter.Findings set) when it keeps findings.
|
// Review round 2: the assigner's views emitter writes its finding view-unsaid (Emitter.Findings set) when it keeps findings.
|
||||||
findings := assign.Findings{Put: func(string, []byte) error { return nil }, Delete: func(string) error { return nil }}
|
if viewsEmitter(nil, process.Account{}, nil, &heldWriter{}, t.Logf).Findings == nil {
|
||||||
if viewsEmitter(nil, process.Account{}, nil, findings, nil, t.Logf).Findings == nil {
|
|
||||||
t.Error("the assigner's views emitter writes no view-unsaid finding")
|
t.Error("the assigner's views emitter writes no view-unsaid finding")
|
||||||
}
|
}
|
||||||
// 1297/B2a: without a credential the program does not start, and says why.
|
// 1297/B2a: without a credential the program does not start, and says why.
|
||||||
@@ -66,7 +69,7 @@ func TestOpensWhatItsManifestNames(t *testing.T) {
|
|||||||
for _, pair := range []struct {
|
for _, pair := range []struct {
|
||||||
what string
|
what string
|
||||||
code, want []string
|
code, want []string
|
||||||
}{{"reads", readBuckets, reads}, {"states", append(slices.Clone(ownBuckets), marksBucket, firstViewsBucket), states}} { // the marks are bound by the views family (views.go)
|
}{{"reads", readBuckets, reads}, {"states", append(slices.Clone(ownBuckets()), marksBucket(), firstViewsBucket()), states}} { // the marks are bound by the views family (views.go)
|
||||||
got, want := slices.Sorted(slices.Values(pair.code)), slices.Sorted(slices.Values(pair.want))
|
got, want := slices.Sorted(slices.Values(pair.code)), slices.Sorted(slices.Values(pair.want))
|
||||||
if !reflect.DeepEqual(got, want) {
|
if !reflect.DeepEqual(got, want) {
|
||||||
t.Errorf("the program's %s are %v, the manifest's %v", pair.what, got, want)
|
t.Errorf("the program's %s are %v, the manifest's %v", pair.what, got, want)
|
||||||
@@ -76,7 +79,7 @@ func TestOpensWhatItsManifestNames(t *testing.T) {
|
|||||||
for _, s := range keptStates {
|
for _, s := range keptStates {
|
||||||
kept = append(kept, m.Module+"_"+s.Name)
|
kept = append(kept, m.Module+"_"+s.Name)
|
||||||
}
|
}
|
||||||
if got, want := slices.Sorted(slices.Values(kept)), slices.Sorted(slices.Values(append(slices.Clone(ownBuckets), marksBucket, firstViewsBucket))); !reflect.DeepEqual(got, want) {
|
if got, want := slices.Sorted(slices.Values(kept)), slices.Sorted(slices.Values(append(slices.Clone(ownBuckets()), marksBucket(), firstViewsBucket()))); !reflect.DeepEqual(got, want) {
|
||||||
t.Errorf("the program announces %v, keeps %v", got, want)
|
t.Errorf("the program announces %v, keeps %v", got, want)
|
||||||
}
|
}
|
||||||
// ADR 0546: whatever keeps the puts' bucket from opening (not there, not granted, no answer in time), the assigner opens
|
// ADR 0546: whatever keeps the puts' bucket from opening (not there, not granted, no answer in time), the assigner opens
|
||||||
@@ -87,17 +90,17 @@ func TestOpensWhatItsManifestNames(t *testing.T) {
|
|||||||
starts bool
|
starts bool
|
||||||
said string
|
said string
|
||||||
}{
|
}{
|
||||||
{buckets.Puts, jetstream.ErrBucketNotFound, true, "no put is taken further"},
|
{buckets.Puts(), jetstream.ErrBucketNotFound, true, "no put is taken further"},
|
||||||
{buckets.Puts, errors.New("nats: permissions violation for subscription to \"$JS.API.STREAM.INFO.KV_mesh-delivery-assigner_puts\""), true, "no put is taken further"},
|
{buckets.Puts(), errors.New("nats: permissions violation for subscription to \"$JS.API.STREAM.INFO.KV_mesh-delivery-assigner_puts\""), true, "no put is taken further"},
|
||||||
{buckets.Puts, context.DeadlineExceeded, true, "no put is taken further"},
|
{buckets.Puts(), context.DeadlineExceeded, true, "no put is taken further"},
|
||||||
{buckets.Wants, errors.New("nats: permissions violation"), false, ""},
|
{buckets.Wants(), errors.New("nats: permissions violation"), false, ""},
|
||||||
// Issue 774: the grants part's grants not there do not stop the start.
|
// Issue 774: the grants part's grants not there do not stop the start.
|
||||||
{buckets.Grants, jetstream.ErrBucketNotFound, true, "no grant is read"},
|
{buckets.Grants, jetstream.ErrBucketNotFound, true, "no grant is read"},
|
||||||
} {
|
} {
|
||||||
var logged string
|
var logged string
|
||||||
kvs, err := open(context.Background(), refusingJS{missing: c.missing, err: c.err}, func(f string, a ...any) { logged += fmt.Sprintf(f, a...) })
|
kvs, err := open(context.Background(), refusingJS{missing: c.missing, err: c.err}, func(f string, a ...any) { logged += fmt.Sprintf(f, a...) })
|
||||||
switch {
|
switch {
|
||||||
case c.starts && (err != nil || kvs[c.missing] != nil || len(kvs) != len(readBuckets)+len(ownBuckets)-1 || !strings.Contains(logged, c.said)):
|
case c.starts && (err != nil || kvs[c.missing] != nil || len(kvs) != len(readBuckets)+len(ownBuckets())-1 || !strings.Contains(logged, c.said)):
|
||||||
t.Errorf("%s refused with %v: the start answered %v, %d buckets, logged %q", c.missing, c.err, err, len(kvs), logged)
|
t.Errorf("%s refused with %v: the start answered %v, %d buckets, logged %q", c.missing, c.err, err, len(kvs), logged)
|
||||||
case !c.starts && (err == nil || !strings.Contains(err.Error(), "grant of "+c.missing)): // 1945: named with its grant
|
case !c.starts && (err == nil || !strings.Contains(err.Error(), "grant of "+c.missing)): // 1945: named with its grant
|
||||||
t.Errorf("%s refused with %v: the start answered %v", c.missing, c.err, err)
|
t.Errorf("%s refused with %v: the start answered %v", c.missing, c.err, err)
|
||||||
@@ -109,7 +112,7 @@ func TestOpensWhatItsManifestNames(t *testing.T) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
wrote := make(chan string, 8)
|
wrote := make(chan string, 8)
|
||||||
kvs := kvSet{}
|
kvs := kvSet{}
|
||||||
for _, name := range append(append([]string{}, readBuckets...), ownBuckets...) {
|
for _, name := range append(append([]string{}, readBuckets...), ownBuckets()...) {
|
||||||
kvs[name] = &watchKV{memKV: &memKV{values: map[string][]byte{}}}
|
kvs[name] = &watchKV{memKV: &memKV{values: map[string][]byte{}}}
|
||||||
}
|
}
|
||||||
placed, err := mmac.AssignmentsValues(mma.Assignments{Node: "ace"})
|
placed, err := mmac.AssignmentsValues(mma.Assignments{Node: "ace"})
|
||||||
@@ -117,12 +120,12 @@ func TestOpensWhatItsManifestNames(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for key, raw := range placed {
|
for key, raw := range placed {
|
||||||
kv := kvs[plc.AssignmentsBucket].(*watchKV)
|
kv := kvs[plc.AssignmentsBucket()].(*watchKV)
|
||||||
kv.entries = append(kv.entries, kvEntry{key: key, value: raw})
|
kv.entries = append(kv.entries, kvEntry{key: key, value: raw})
|
||||||
}
|
}
|
||||||
kvs[buckets.Puts].(*watchKV).closed = true
|
kvs[buckets.Puts()].(*watchKV).closed = true
|
||||||
kvs[buckets.Wants].(*watchKV).wrote = wrote
|
kvs[buckets.Wants()].(*watchKV).wrote = wrote
|
||||||
go follow(ctx, nil, nil, kvs, func(oc.Condition) error { return nil }, assign.Findings{}, nil, nil, log.New(io.Discard, "", 0))
|
go follow(ctx, nil, nil, kvs, func(oc.Condition) error { return nil }, assign.Findings{}, nil, nil, nil, seatlist.NewPart("assigner", seatListAgainCallers), log.New(io.Discard, "", 0), func(string) string { return "" })
|
||||||
select {
|
select {
|
||||||
case key := <-wrote:
|
case key := <-wrote:
|
||||||
if key != "want.ace.node" {
|
if key != "want.ace.node" {
|
||||||
@@ -197,3 +200,12 @@ func (e kvEntry) Created() time.Time { return time.Time{} }
|
|||||||
func (w *watchKV) Keys(context.Context, ...jetstream.WatchOpt) ([]string, error) {
|
func (w *watchKV) Keys(context.Context, ...jetstream.WatchOpt) ([]string, error) {
|
||||||
return nil, jetstream.ErrNoKeysFound
|
return nil, jetstream.ErrNoKeysFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// putInto is an assign.Findings Put that keeps each finding in into, as the finding writer would, by its key and its words.
|
||||||
|
func putInto(into map[string][]byte) func(mcseat.Finding) error {
|
||||||
|
return func(f mcseat.Finding) error {
|
||||||
|
raw, err := json.Marshal(f)
|
||||||
|
into[views.FindingKey(f.Scope, f.ID, f.Kind)] = raw
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,10 +18,9 @@ import (
|
|||||||
// The state this seat's assignments were kept in before ADR 0641 gave it its name. The assigner reads it here and nowhere
|
// The state this seat's assignments were kept in before ADR 0641 gave it its name. The assigner reads it here and nowhere
|
||||||
// else: at its start it copies each key into `assignments` (copyRetired) and keeps no reader of it afterwards. The
|
// else: at its start it copies each key into `assignments` (copyRetired) and keeps no reader of it afterwards. The
|
||||||
// manifest still declares the state, so the assigner's account may read it for the copy; a later release drops it.
|
// manifest still declares the state, so the assigner's account may read it for the copy; a later release drops it.
|
||||||
const (
|
const retiredState = "placement"
|
||||||
retiredState = "placement"
|
|
||||||
retiredBucket = plc.Module + "_" + retiredState
|
func retiredBucket() string { return plc.Module() + "_" + retiredState }
|
||||||
)
|
|
||||||
|
|
||||||
// CopiedEvent is the module's event saying the copy was made, once: mesh.mod.mesh-delivery-assigner.event.assignments-copied.
|
// CopiedEvent is the module's event saying the copy was made, once: mesh.mod.mesh-delivery-assigner.event.assignments-copied.
|
||||||
const CopiedEvent = "assignments-copied"
|
const CopiedEvent = "assignments-copied"
|
||||||
@@ -37,10 +36,9 @@ type copiedSaid struct {
|
|||||||
|
|
||||||
// copiesState is the assigner's own state of its copies, read by its tool assigner_read_copies, and copiesBucket its bucket.
|
// copiesState is the assigner's own state of its copies, read by its tool assigner_read_copies, and copiesBucket its bucket.
|
||||||
// The retired state gets nothing written: readers of other modules still parse every key in it.
|
// The retired state gets nothing written: readers of other modules still parse every key in it.
|
||||||
const (
|
const copiesState = "copies"
|
||||||
copiesState = "copies"
|
|
||||||
copiesBucket = plc.Module + "_" + copiesState
|
func copiesBucket() string { return plc.Module() + "_" + copiesState }
|
||||||
)
|
|
||||||
|
|
||||||
// copiedMarker is the key, in the state copies, that says the copy ended: its time and the keys it copied. It is written
|
// copiedMarker is the key, in the state copies, that says the copy ended: its time and the keys it copied. It is written
|
||||||
// after the last key, and the copy is made at every start until it is there and never after, so a copy cut short by a
|
// after the last key, and the copy is made at every start until it is there and never after, so a copy cut short by a
|
||||||
@@ -63,12 +61,12 @@ func (p *passer) copyRetired(ctx context.Context) bool {
|
|||||||
if p.copied {
|
if p.copied {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
old, next, copies := p.kvs[retiredBucket], p.kvs[plc.AssignmentsBucket], p.kvs[copiesBucket]
|
old, next, copies := p.kvs[retiredBucket()], p.kvs[plc.AssignmentsBucket()], p.kvs[copiesBucket()]
|
||||||
if next == nil || copies == nil {
|
if next == nil || copies == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if old == nil {
|
if old == nil {
|
||||||
p.logf("assignments: the retired state %s cannot be read, so nothing is copied from it", retiredBucket)
|
p.logf("assignments: the retired state %s cannot be read, so nothing is copied from it", retiredBucket())
|
||||||
p.copied = true
|
p.copied = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -77,12 +75,12 @@ func (p *passer) copyRetired(ctx context.Context) bool {
|
|||||||
p.copied = true // the copy ended at an earlier start: nothing is copied again
|
p.copied = true // the copy ended at an earlier start: nothing is copied again
|
||||||
return true
|
return true
|
||||||
case !errors.Is(err, jetstream.ErrKeyNotFound):
|
case !errors.Is(err, jetstream.ErrKeyNotFound):
|
||||||
p.logf("assignments: the marker %s of %s cannot be read, and the copy is tried again at the next pass: %v", copiedMarker, copiesBucket, err)
|
p.logf("assignments: the marker %s of %s cannot be read, and the copy is tried again at the next pass: %v", copiedMarker, copiesBucket(), err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
names, err := old.Keys(ctx)
|
names, err := old.Keys(ctx)
|
||||||
if err != nil && !errors.Is(err, jetstream.ErrNoKeysFound) {
|
if err != nil && !errors.Is(err, jetstream.ErrNoKeysFound) {
|
||||||
p.logf("assignments: the keys of %s cannot be listed, and are tried again at the next pass: %v", retiredBucket, err)
|
p.logf("assignments: the keys of %s cannot be listed, and are tried again at the next pass: %v", retiredBucket(), err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// A node's module keys before its node key: the node key is the commit the readers wait for.
|
// A node's module keys before its node key: the node key is the commit the readers wait for.
|
||||||
@@ -120,13 +118,13 @@ func (p *passer) copyRetired(ctx context.Context) bool {
|
|||||||
return false
|
return false
|
||||||
default:
|
default:
|
||||||
said.Copied++
|
said.Copied++
|
||||||
p.w.putEntry(plc.AssignmentsBucket, key, entry.Value(), rev, p.clock())
|
p.w.putEntry(plc.AssignmentsBucket(), key, entry.Value(), rev, p.clock())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mark, _ := json.Marshal(copiedMark{At: p.clock(), Copied: said.Copied + said.Present})
|
mark, _ := json.Marshal(copiedMark{At: p.clock(), Copied: said.Copied + said.Present})
|
||||||
if _, err := copies.Put(ctx, copiedMarker, mark); err != nil {
|
if _, err := copies.Put(ctx, copiedMarker, mark); err != nil {
|
||||||
p.logf("assignments: the end of the copy is not written as %s in %s, and the copy is tried again at the next pass: %v", copiedMarker, copiesBucket, err)
|
p.logf("assignments: the end of the copy is not written as %s in %s, and the copy is tried again at the next pass: %v", copiedMarker, copiesBucket(), err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
p.copied = true
|
p.copied = true
|
||||||
@@ -134,7 +132,7 @@ func (p *passer) copyRetired(ctx context.Context) bool {
|
|||||||
return true // the retired state holds nothing
|
return true // the retired state holds nothing
|
||||||
}
|
}
|
||||||
p.logf("assignments: copied %d keys of %s into %s (%d already there kept as they are, %d of the form placement.<node> not copied, %d fitting no form left)",
|
p.logf("assignments: copied %d keys of %s into %s (%d already there kept as they are, %d of the form placement.<node> not copied, %d fitting no form left)",
|
||||||
said.Copied, retiredBucket, plc.AssignmentsBucket, said.Present, said.Dropped, said.Skipped)
|
said.Copied, retiredBucket(), plc.AssignmentsBucket(), said.Present, said.Dropped, said.Skipped)
|
||||||
if p.seat != nil {
|
if p.seat != nil {
|
||||||
if err := p.seat.bus.Emit(CopiedEvent, said); err != nil {
|
if err := p.seat.bus.Emit(CopiedEvent, said); err != nil {
|
||||||
p.logf("assignments: the copy is not said as an event: %v", err)
|
p.logf("assignments: the copy is not said as an event: %v", err)
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The module claiming the seat node-engine is found by its served verbs, in the catalog's form `seat:<seat>.<verb>`
|
||||||
|
// and in the bare form (live, 2026-11-16: every composition step said "holds no module claiming the seat node-engine").
|
||||||
|
func TestTheNodeEngineEntryIsFoundByItsServedVerbs(t *testing.T) {
|
||||||
|
for _, c := range []struct {
|
||||||
|
name string
|
||||||
|
serves []string
|
||||||
|
found bool
|
||||||
|
}{
|
||||||
|
{"the catalog's seat form", []string{"seat:node-engine.compose", "seat:node-engine.acts"}, true},
|
||||||
|
{"the bare form", []string{"node-engine.compose"}, true},
|
||||||
|
{"another seat", []string{"seat:node-engine-x.compose", "seat:mesh-wants.ask"}, false},
|
||||||
|
} {
|
||||||
|
e, ok := nodeEngineEntry(map[string]meshcatalog.CatalogEntry{"other": {Serves: []string{"seat:mesh-builds.ask"}}, "engine": {Serves: c.serves}})
|
||||||
|
if ok != c.found || (ok && e.Serves[0] != c.serves[0]) {
|
||||||
|
t.Errorf("%s: found %v (%v), want %v", c.name, ok, e.Serves, c.found)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// busObjects is the assigner's own object bucket assignment-revisions in the old `objects` section (novox/hq ADR 0619 §2),
|
||||||
|
// which the grants part creates, as the passer's process reaches it: opened at its first use and kept; until the bucket exists
|
||||||
|
// every call is an error saying so, and the next call opens it again (design 47 G A-67, modelled on the indexer's busObjects).
|
||||||
|
type busObjects struct {
|
||||||
|
js jetstream.JetStream
|
||||||
|
module string
|
||||||
|
local string
|
||||||
|
mu sync.Mutex
|
||||||
|
o jetstream.ObjectStore
|
||||||
|
}
|
||||||
|
|
||||||
|
// newBusObjects is the object bucket of this local name of the module the account runs as.
|
||||||
|
func newBusObjects(js jetstream.JetStream, cred process.Account, local string) *busObjects {
|
||||||
|
return &busObjects{js: js, module: cred.Module, local: local}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *busObjects) open(ctx context.Context) (jetstream.ObjectStore, error) {
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
|
if b.o != nil {
|
||||||
|
return b.o, nil
|
||||||
|
}
|
||||||
|
o, err := b.js.ObjectStore(ctx, catalogue.ObjectsBucket(b.module, b.local))
|
||||||
|
if errors.Is(err, jetstream.ErrBucketNotFound) || errors.Is(err, jetstream.ErrStreamNotFound) {
|
||||||
|
return nil, fmt.Errorf("the object bucket %s is not on the bus yet (the grants part creates it from the manifest's objects): %w", b.local, process.ErrNotYet)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the object bucket %s is not open: %w", b.local, err)
|
||||||
|
}
|
||||||
|
b.o = o
|
||||||
|
return o, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *busObjects) Put(ctx context.Context, name string, data []byte) error {
|
||||||
|
o, err := b.open(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = o.Put(ctx, jetstream.ObjectMeta{Name: name}, bytes.NewReader(data))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *busObjects) Get(ctx context.Context, name string) ([]byte, error) {
|
||||||
|
o, err := b.open(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
data, err := o.GetBytes(ctx, name)
|
||||||
|
if errors.Is(err, jetstream.ErrObjectNotFound) {
|
||||||
|
return nil, assigngraph.ErrNoObject
|
||||||
|
}
|
||||||
|
return data, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *busObjects) Names(ctx context.Context) ([]string, error) {
|
||||||
|
o, err := b.open(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
infos, err := o.List(ctx)
|
||||||
|
if errors.Is(err, jetstream.ErrNoObjectsFound) {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
names := make([]string, 0, len(infos))
|
||||||
|
for _, i := range infos {
|
||||||
|
names = append(names, i.Name)
|
||||||
|
}
|
||||||
|
return names, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete removes the object of that name; one not held is no error (design 47 G §579: a revision nothing pins is removed).
|
||||||
|
func (b *busObjects) Delete(ctx context.Context, name string) error {
|
||||||
|
o, err := b.open(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := o.Delete(ctx, name); err != nil && !errors.Is(err, jetstream.ErrObjectNotFound) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill is the bytes the bucket holds and its cap (assigngraph.Filler).
|
||||||
|
func (b *busObjects) Fill(ctx context.Context) (int64, int64, error) {
|
||||||
|
o, err := b.open(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
|
st, err := o.Status(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
|
info, err := b.js.Stream(ctx, "OBJ_"+st.Bucket())
|
||||||
|
if err != nil {
|
||||||
|
return int64(st.Size()), 0, err
|
||||||
|
}
|
||||||
|
return int64(st.Size()), info.CachedInfo().Config.MaxBytes, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/meshbroker"
|
||||||
|
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||||
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/acting"
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
"mesh-delivery-assigner/internal/assignment"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The three order edges of a delivery that crosses a form change (design 47 G §298, A-245, A-258, A-259, A-260). Each is an acting wait of the
|
||||||
|
// assigner, kept in the state `waits` under `order.<node>.<module>.<part>` beside the acting waits, in the step placing, said as wait-held
|
||||||
|
// when a want is held for it and wait-ended (ran, released, replaced) when it moves; assigner_waits reads them and assigner_release with
|
||||||
|
// how `now` releases them, as it does an acting wait. The holders of the seats are read from the seat holders the assignments compose
|
||||||
|
// (assignment.SeatHoldersOf), never named:
|
||||||
|
// - the node-backup holder's and the bus module's (the holder of the seat mesh-broker) new versions run before a module whose kept data's
|
||||||
|
// form changes is moved, since the restore point needs both (OrderBackup);
|
||||||
|
// - at a revert a node's node-engine goes back last on that node, after every module it restores there runs the reverted build, which it
|
||||||
|
// starts only once it has said `restored` (OrderEngineLast);
|
||||||
|
// - the reverted assigner and gate are wanted only once the indexer's take-in.taken of the trunk branch names a source revision at least
|
||||||
|
// the trunk's head, the highest `src` of the trunk branch's module values (OrderTakenIn, A-260).
|
||||||
|
|
||||||
|
// takenSubject is the indexer's event take-in.taken on its own stream, as the manifest's consumes names it.
|
||||||
|
var takenSubject = process.ModuleStreamSubject(buckets.IndexerModule, "take-in.taken")
|
||||||
|
|
||||||
|
// takenSources are the newest source revisions a take-in.taken named, by watched branch, as heard (hearBuildsAndReleases).
|
||||||
|
type takenSources struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
own map[string]int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// put takes one take-in.taken in. A hand drop, and a taken with no source revision (one said before G), take nothing in.
|
||||||
|
func (t *takenSources) put(data []byte) error {
|
||||||
|
var e meshcatalog.TakeInTaken
|
||||||
|
if err := json.Unmarshal(data, &e); err != nil {
|
||||||
|
return fmt.Errorf("a take-in.taken that is none: %w", err)
|
||||||
|
}
|
||||||
|
if e.Dropped || e.Source == 0 || e.Branch == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
t.mu.Lock()
|
||||||
|
defer t.mu.Unlock()
|
||||||
|
if t.own == nil {
|
||||||
|
t.own = map[string]int64{}
|
||||||
|
}
|
||||||
|
t.own[e.Branch] = max(t.own[e.Branch], e.Source)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// of is the newest source revision of branch taken in; 0 before one is heard.
|
||||||
|
func (t *takenSources) of(branch string) int64 {
|
||||||
|
t.mu.Lock()
|
||||||
|
defer t.mu.Unlock()
|
||||||
|
return t.own[branch]
|
||||||
|
}
|
||||||
|
|
||||||
|
// orderEdge is one order edge held on module's want on node: part's version fp must run on partNode (OrderBackup, OrderEngineLast), or the
|
||||||
|
// trunk's source revision source be taken in (OrderTakenIn).
|
||||||
|
type orderEdge struct {
|
||||||
|
node, module, part, partNode, fp, entry, order string
|
||||||
|
source int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e orderEdge) key() string { return acting.OrderKey(e.node, e.module, e.part) }
|
||||||
|
|
||||||
|
func (e orderEdge) acting() assign.ActingEdge {
|
||||||
|
return assign.ActingEdge{Node: e.partNode, Part: e.part, Fp: e.fp, Step: seatdef.StepPlace}
|
||||||
|
}
|
||||||
|
|
||||||
|
// orderRuns says an order edge is met: its part runs the version, or the source revision is taken in.
|
||||||
|
func (p *passer) orderRuns(n assign.Nodes, e orderEdge) bool {
|
||||||
|
if e.order == acting.OrderTakenIn {
|
||||||
|
return p.w.taken.of(p.w.trunkName()) >= e.source
|
||||||
|
}
|
||||||
|
return n.Runs(e.acting())
|
||||||
|
}
|
||||||
|
|
||||||
|
// seatHolders are the holders of each seat as the assignments compose them, by seat name.
|
||||||
|
func (p *passer) holdersBySeat() map[string][]mma.SeatHoldersHoldersItem {
|
||||||
|
out := map[string][]mma.SeatHoldersHoldersItem{}
|
||||||
|
for _, sh := range assignment.SeatHoldersOf(p.w.assignments()) {
|
||||||
|
out[sh.Seat] = append(out[sh.Seat], sh.Holders...)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// orderEdgesOf computes §298's edges on the wants of module m on each of its nodes, into p.orders. wanted is m's wants by node; trunk the
|
||||||
|
// trunk's module values. A node that has no running build heard, runs m at its trunk version already, or is wanted that version already
|
||||||
|
// has none: nothing moves. It answers, by node, whether an edge still stands that cannot be recorded as a wait because the catalog entry
|
||||||
|
// it reads is not answered yet (asked, and its answer wakes a pass): the want is held meanwhile, never written across a form change unread.
|
||||||
|
func (p *passer) orderEdgesOf(ctx context.Context, m assign.Module, wanted map[string]mwc.Want, trunk map[string]meshcatalog.ModulesByModuleValue) map[string]bool {
|
||||||
|
unread := map[string]bool{}
|
||||||
|
p.orderVisited[m.Name] = true
|
||||||
|
if m.FP == "" || p.graph == nil || p.entries == nil {
|
||||||
|
return unread
|
||||||
|
}
|
||||||
|
var holders map[string][]mma.SeatHoldersHoldersItem
|
||||||
|
for _, node := range m.Nodes {
|
||||||
|
if w, ok := wanted[node]; ok && !w.Removed && w.Fp == m.FP {
|
||||||
|
continue // the version is wanted already: nothing moves, so nothing waits
|
||||||
|
}
|
||||||
|
run, heard := p.w.runningOf(node, m.Name)
|
||||||
|
if !heard || run.Stopped || run.Fingerprint == "" || run.Fingerprint == m.FP {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if holders == nil {
|
||||||
|
holders = p.holdersBySeat()
|
||||||
|
}
|
||||||
|
held := func(seatName string) bool {
|
||||||
|
for _, h := range holders[seatName] {
|
||||||
|
if h.Module == m.Name && h.Node == node {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
add := func(e orderEdge) {
|
||||||
|
e.node, e.module, e.entry = node, m.Name, m.FP
|
||||||
|
p.orders[e.key()] = e
|
||||||
|
}
|
||||||
|
// 1. a kept data's form changes: the restore point needs the new node-backup holder and bus module.
|
||||||
|
changes, known := p.formChange(ctx, m.Name, run.Fingerprint, m.FP)
|
||||||
|
if !known {
|
||||||
|
unread[node] = true
|
||||||
|
}
|
||||||
|
if len(changes) > 0 {
|
||||||
|
for seatName, onNode := range map[string]bool{catalogue.BackupSeat: true, meshbroker.Seat: false} {
|
||||||
|
for _, h := range holders[seatName] {
|
||||||
|
if h.Module == m.Name || (onNode && h.Node != node) || trunk[h.Module].Fp2 == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
add(orderEdge{part: h.Module, partNode: h.Node, fp: trunk[h.Module].Fp2, order: acting.OrderBackup})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !held(nodeengine.Seat) && !held(mma.Seat) && !held(meshdelivery.Seat) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
reverted, err := assigngraph.Reverted(ctx, p.graph.objects, node, m.Name, run.Fingerprint, m.FP)
|
||||||
|
if err != nil {
|
||||||
|
p.logf("whether the want of %s on %s at %s is a revert is not read: %v", m.Name, node, m.FP, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !reverted {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// 2. at a revert the node-engine goes back last on its node: after every module that is set back there across a form change runs.
|
||||||
|
if held(nodeengine.Seat) {
|
||||||
|
for module, byNode := range p.w.wantsOf() {
|
||||||
|
// What it is set back to is its trunk version, which the rules write as its want in this pass.
|
||||||
|
target := trunk[module].Fp2
|
||||||
|
if w, ok := byNode[node]; module == m.Name || !ok || w.Removed || target == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
xrun, heard := p.w.runningOf(node, module)
|
||||||
|
if !heard || xrun.Stopped || xrun.Fingerprint == "" || xrun.Fingerprint == target {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if back, err := assigngraph.Reverted(ctx, p.graph.objects, node, module, xrun.Fingerprint, target); err != nil || !back {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
xchanges, known := p.formChange(ctx, module, xrun.Fingerprint, target)
|
||||||
|
if !known {
|
||||||
|
unread[node] = true
|
||||||
|
}
|
||||||
|
if len(xchanges) > 0 {
|
||||||
|
add(orderEdge{part: module, partNode: node, fp: target, order: acting.OrderEngineLast})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 3. the reverted assigner and gate wait for the indexer to take in the trunk's head.
|
||||||
|
if held(mma.Seat) || held(meshdelivery.Seat) {
|
||||||
|
var head int64
|
||||||
|
for _, v := range p.w.trunkOf(p.w.trunkName()) {
|
||||||
|
head = max(head, v.Src)
|
||||||
|
}
|
||||||
|
if head > 0 {
|
||||||
|
add(orderEdge{part: buckets.IndexerModule, fp: strconv.FormatInt(head, 10), source: head, order: acting.OrderTakenIn})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unread
|
||||||
|
}
|
||||||
|
|
||||||
|
// orderActing is the order edges of module on node that still hold its want, as acting edges: those not met, and not released by hand. A
|
||||||
|
// node whose catalog entry is not read yet holds its want too, on a stand-in edge no part runs.
|
||||||
|
func (p *passer) orderActing(module string, released map[string]bool, unread map[string]bool, n func() assign.Nodes) func(node string) []assign.ActingEdge {
|
||||||
|
return func(node string) []assign.ActingEdge {
|
||||||
|
var out []assign.ActingEdge
|
||||||
|
nodes := n()
|
||||||
|
for _, e := range p.orders {
|
||||||
|
if e.module == module && e.node == node && !released[e.key()+"@"+e.fp] && !p.orderRuns(nodes, e) {
|
||||||
|
out = append(out, assign.ActingEdge{Node: e.partNode, Part: e.part, Fp: e.fp, Step: seatdef.StepPlace})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if unread[node] {
|
||||||
|
out = append(out, assign.ActingEdge{Node: node, Part: "the catalog entry", Step: seatdef.StepPlace})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// orderWaits keeps the order waits after the pass's wants, as actingWaits keeps the acting waits: it starts the wait of each edge not met,
|
||||||
|
// ends the wait of one that ran, was replaced or was released, and says each.
|
||||||
|
func (p *passer) orderWaits(ctx context.Context, n assign.Nodes, wanted map[string]map[string]mwc.Want) {
|
||||||
|
if p.kvs[buckets.Waits()] == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
now := p.clock()
|
||||||
|
kept := p.w.read(buckets.Waits())
|
||||||
|
trunk := p.w.trunk()
|
||||||
|
if p.orderSaid == nil {
|
||||||
|
p.orderSaid = map[string]bool{}
|
||||||
|
}
|
||||||
|
standing := map[string]bool{}
|
||||||
|
for key, e := range p.orders {
|
||||||
|
if w, ok := wanted[e.module][e.node]; ok && !w.Removed && w.Fp == e.entry {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if p.orderRuns(n, e) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
standing[key] = true
|
||||||
|
if raw := kept[key]; raw != nil {
|
||||||
|
if w, err := acting.Decode(raw); err == nil && w.Entry == e.entry && w.Fp == e.fp {
|
||||||
|
if !w.Released && !p.orderSaid[key] {
|
||||||
|
// A wait still held after a restart is said again, as wait-held (A-260).
|
||||||
|
if err := p.wantsSay(seat.EventWaitHeld, acting.Body(w, assignment.Module()), key+"."+e.fp+"."+e.entry+".again"); err != nil {
|
||||||
|
p.logf("the wait of %s on %s for %s is not said again, and is said at the next pass: %v", e.module, e.node, e.part, err)
|
||||||
|
} else {
|
||||||
|
p.orderSaid[key] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.actingReleaseSaid(ctx, key, w)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !n.Online[e.node] {
|
||||||
|
continue // a node away holds only itself, and its clock has not started (§268)
|
||||||
|
}
|
||||||
|
w := acting.Wait{Step: seatdef.StepPlace, Node: e.node, Module: e.module, Part: e.part, PartNode: e.partNode, Fp: e.fp, Entry: e.entry, Order: e.order,
|
||||||
|
Since: now, ClockFrom: now, Bound: acting.BoundOf(seat.Edge{Step: seatdef.StepPlace}).String()}
|
||||||
|
if err := p.wantsSay(seat.EventWaitHeld, acting.Body(w, assignment.Module()), key+"."+e.fp+"."+e.entry); err != nil {
|
||||||
|
p.logf("the wait of %s on %s for %s is not said, and is said at the next pass: %v", e.module, e.node, e.part, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
p.put(ctx, buckets.Waits(), key, func() ([]byte, error) { return acting.Encode(w) })
|
||||||
|
p.orderSaid[key] = true
|
||||||
|
}
|
||||||
|
for key, raw := range kept {
|
||||||
|
if !acting.IsOrder(key) || standing[key] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w, err := acting.Decode(raw)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, there := trunk[w.Module]; there && !p.orderVisited[w.Module] {
|
||||||
|
continue // the module was not looked at in this pass (no pipeline passed for it yet): its wait stands as kept
|
||||||
|
}
|
||||||
|
how := acting.HowRan
|
||||||
|
switch e, there := p.orders[key]; {
|
||||||
|
case w.Released:
|
||||||
|
how = acting.HowReleased
|
||||||
|
case there && e.fp != w.Fp, !there && wanted[w.Module][w.Node].Fp != w.Entry:
|
||||||
|
how = acting.HowReplaced
|
||||||
|
}
|
||||||
|
if !w.EndSaid {
|
||||||
|
body := acting.Body(w, assignment.Module())
|
||||||
|
body.How = how
|
||||||
|
if err := p.wantsSay(seat.EventWaitEnded, body, key+"."+w.Fp+"."+w.Entry+"."+how); err != nil {
|
||||||
|
p.logf("the end of the wait of %s on %s for %s is not said, and is said at the next pass: %v", w.Module, w.Node, w.Part, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.remove(ctx, buckets.Waits(), key)
|
||||||
|
delete(p.orderSaid, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,351 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/meshbroker"
|
||||||
|
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-grants/grantsstate"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/acting"
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
plc "mesh-delivery-assigner/internal/assignment"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// orderFP is a fingerprint of the form the trunk keeps, made of one letter.
|
||||||
|
func orderFP(c string) string {
|
||||||
|
return meshcatalogclient.SourcePrefix2 + strings.Repeat(fmt.Sprintf("%x", c[0]&15), 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
// orderMod is one module of an order test: the fingerprint it runs on ace and the one the trunk holds, the form of its kept data at each
|
||||||
|
// fingerprint (0: it keeps none), the seats it holds and the source revision of its trunk value.
|
||||||
|
type orderMod struct {
|
||||||
|
name string
|
||||||
|
run, trunk string
|
||||||
|
forms map[string]int
|
||||||
|
holds []string
|
||||||
|
src int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type orderFixture struct {
|
||||||
|
t *testing.T
|
||||||
|
p *passer
|
||||||
|
wants *memKV
|
||||||
|
events []string
|
||||||
|
bodies []meshwants.Wait
|
||||||
|
answers chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOrderFixture is a pass on node ace, which composes its own modules, with each module running its fingerprint healthy, built and
|
||||||
|
// granted at the trunk's, an older want, the catalog's entries answered and each held seat as the assignments say it. history lists the
|
||||||
|
// fingerprints of each module by assignment graph revision, oldest first (the objects Reverted reads).
|
||||||
|
func newOrderFixture(t *testing.T, mods []orderMod, history ...map[string]string) *orderFixture {
|
||||||
|
t.Helper()
|
||||||
|
ctx := context.Background()
|
||||||
|
f := &orderFixture{t: t, wants: &memKV{values: map[string][]byte{}}, answers: make(chan struct{}, 64)}
|
||||||
|
f.p = newPasser(kvSet{buckets.Wants(): f.wants, buckets.Asks(): &memKV{values: map[string][]byte{}}, buckets.Waits(): &memKV{values: map[string][]byte{}}}, time.Now())
|
||||||
|
p := f.p
|
||||||
|
p.logf = t.Logf
|
||||||
|
p.say = func(oc.Condition) error { return nil }
|
||||||
|
p.publishWants = func(event string, body any, id string) error {
|
||||||
|
f.events = append(f.events, event)
|
||||||
|
f.bodies = append(f.bodies, body.(meshwants.Wait))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
digest := "sha256:" + strings.Repeat("c", 64)
|
||||||
|
pl := mma.Assignments{Node: "ace"}
|
||||||
|
forms := map[string]int{} // by fingerprint: each module's own
|
||||||
|
modules := []string{}
|
||||||
|
for _, m := range mods {
|
||||||
|
modules = append(modules, m.name)
|
||||||
|
pl.Modules = append(pl.Modules, mma.PlacedModule{Module: m.name})
|
||||||
|
for _, seat := range m.holds {
|
||||||
|
scope := "node"
|
||||||
|
if seat != catalogue.BackupSeat && seat != nodeengine.Seat {
|
||||||
|
scope = "mesh"
|
||||||
|
}
|
||||||
|
pl.Holds = append(pl.Holds, mma.Holding{Claim: seat, Module: m.name, Scope: scope})
|
||||||
|
}
|
||||||
|
for fp, form := range m.forms {
|
||||||
|
forms[fp] = form
|
||||||
|
}
|
||||||
|
mdigest := fmt.Sprintf("%064x", len(modules))
|
||||||
|
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: m.trunk, Manifest: mdigest, Repository: "novox/" + m.name, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath, Src: m.src})
|
||||||
|
putModuleRaw(p.w, trunkBranch, m.name, mod)
|
||||||
|
p.w.manifests[mdigest] = parsed{module: m.name, manifest: catalogue.Manifest{Module: m.name}}
|
||||||
|
endDone(t, p.w, m.name, m.trunk, mdigest)
|
||||||
|
gkey, _ := grantsstate.PartGrantKey(m.name, m.trunk)
|
||||||
|
grant, _ := grantsstate.EncodeGrant(grantsstate.Grant{})
|
||||||
|
p.w.put(buckets.Grants, gkey, grant)
|
||||||
|
f.runs(m.name, m.run)
|
||||||
|
wkey, _ := mwc.WantKey("ace", m.name)
|
||||||
|
old, _ := mwc.EncodeWant(mwc.Want{Fp: m.run, Self: true})
|
||||||
|
p.w.put(buckets.Wants(), wkey, old)
|
||||||
|
f.wants.values[wkey] = old
|
||||||
|
}
|
||||||
|
composes(t, p.w, "ace", digest)
|
||||||
|
values, err := mmac.AssignmentsValues(pl)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for key, raw := range values {
|
||||||
|
p.w.put(plc.AssignmentsBucket(), key, raw)
|
||||||
|
}
|
||||||
|
p.w.heardPresence("ace", false, time.Now()) // ace is online: its last presence event heard is machine-back
|
||||||
|
objects := memObjects{}
|
||||||
|
for i, at := range history {
|
||||||
|
half := meshcatalogclient.Half{Revision: meshcatalog.CatalogRevision{Branch: trunkBranch, Kind: "trunk", Revision: int64(i + 1), Source: int64(i + 1)},
|
||||||
|
Entries: map[string]meshcatalog.CatalogEntry{}}
|
||||||
|
for _, module := range modules {
|
||||||
|
digest := fmt.Sprintf("sha256:%064x", (i+1)*1000+len(half.Entries))
|
||||||
|
half.Revision.Entries = append(half.Revision.Entries, meshcatalog.EntryRef{Module: module, Digest: digest})
|
||||||
|
half.Entries[module] = meshcatalog.CatalogEntry{Module: module, Fp: at[module]}
|
||||||
|
}
|
||||||
|
placed := mma.Assignments{Node: "ace"}
|
||||||
|
for _, module := range modules {
|
||||||
|
placed.Modules = append(placed.Modules, mma.PlacedModule{Module: module})
|
||||||
|
}
|
||||||
|
in := assigngraph.Inputs{Halves: map[string]meshcatalogclient.Half{trunkBranch: half}, FirstBranch: func(string) string { return trunkBranch },
|
||||||
|
Placements: map[string]mma.Assignments{"ace": placed}}
|
||||||
|
if _, _, err := assigngraph.Keep(ctx, objects, assigngraph.Compute(in), "test", time.Now()); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.graph = &graphKeeper{objects: objects}
|
||||||
|
p.entries = meshcatalogclient.NewEntries(func(_ string, body any) (json.RawMessage, error) {
|
||||||
|
in := body.(meshcatalog.EntryInput)
|
||||||
|
entry := meshcatalog.CatalogEntry{Module: "m", Fp: in.Fingerprint, Manifest: map[string]any{"module": "m"}}
|
||||||
|
if form := forms[in.Fingerprint]; form > 0 {
|
||||||
|
entry.Manifest = map[string]any{"module": "m", "state": []any{map[string]any{"name": "sessions", "form": form}}}
|
||||||
|
}
|
||||||
|
return json.Marshal(meshcatalog.EntryAnswer{Entry: entry})
|
||||||
|
})
|
||||||
|
p.entries.Changed = func(meshcatalogclient.EntryRow) { f.answers <- struct{}{} }
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
// runs says module runs fp healthy on ace, heard as the node-engine seat's running and in the have.
|
||||||
|
func (f *orderFixture) runs(module, fp string) {
|
||||||
|
have, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fp, Composed: "sha256:" + strings.Repeat("c", 64), Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
|
||||||
|
f.p.w.put(buckets.Have, "ace."+module, have)
|
||||||
|
f.p.w.running["ace."+module] = nodeengine.Running{Node: "ace", Module: module, Fingerprint: fp}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pass makes a pass, and after it every catalog entry it asked is answered.
|
||||||
|
func (f *orderFixture) pass() {
|
||||||
|
f.t.Helper()
|
||||||
|
f.p.wants(context.Background())
|
||||||
|
asked := 0
|
||||||
|
for _, row := range f.p.entries.Rows() {
|
||||||
|
if row.State == meshcatalogclient.EntryAsked {
|
||||||
|
asked++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for range asked {
|
||||||
|
select {
|
||||||
|
case <-f.answers:
|
||||||
|
case <-time.After(10 * time.Second): // a bound on a failure only: the answers come at once
|
||||||
|
f.t.Fatal("an entry asked was not answered")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// wantAt is the fingerprint module is wanted at on ace.
|
||||||
|
func (f *orderFixture) wantAt(module string) string {
|
||||||
|
f.t.Helper()
|
||||||
|
key, _ := mwc.WantKey("ace", module)
|
||||||
|
w, err := mwc.DecodeWant(f.wants.values[key])
|
||||||
|
if err != nil {
|
||||||
|
f.t.Fatal(err)
|
||||||
|
}
|
||||||
|
return w.Fp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *orderFixture) waits() []string {
|
||||||
|
var out []string
|
||||||
|
for key := range f.p.w.read(buckets.Waits()) {
|
||||||
|
if acting.IsOrder(key) {
|
||||||
|
out = append(out, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §298 first edge, A-258, A-259: a module whose kept data's form changes is not moved until the new version of the node-backup
|
||||||
|
// holder and of the holder of the seat mesh-broker run; the wait is kept under `order.` in the state waits, said as wait-held, and ends
|
||||||
|
// ran (wait-ended) when the holders run; a module whose kept data keeps its form is moved at once.
|
||||||
|
func TestAModuleWhoseKeptDataChangesFormWaitsForTheNewBackupHolderAndTheBusModule(t *testing.T) {
|
||||||
|
f := newOrderFixture(t, []orderMod{
|
||||||
|
{name: "web", run: orderFP("a"), trunk: orderFP("b"), forms: map[string]int{orderFP("a"): 1, orderFP("b"): 2}},
|
||||||
|
{name: "plain", run: orderFP("c"), trunk: orderFP("d"), forms: map[string]int{orderFP("c"): 1, orderFP("d"): 1}},
|
||||||
|
{name: "backup", run: orderFP("e"), trunk: orderFP("f"), holds: []string{catalogue.BackupSeat}},
|
||||||
|
{name: "bus", run: orderFP("g"), trunk: orderFP("h"), holds: []string{meshbroker.Seat}},
|
||||||
|
})
|
||||||
|
f.pass() // the entries are asked: no want crosses a form change unread
|
||||||
|
if got := f.wantAt("web"); got != orderFP("a") {
|
||||||
|
t.Fatalf("web is wanted at %s before the entries are read", got)
|
||||||
|
}
|
||||||
|
f.pass()
|
||||||
|
if got := f.wantAt("web"); got != orderFP("a") {
|
||||||
|
t.Fatalf("web moved across a form change at %s while the new node-backup holder and bus module do not run", got)
|
||||||
|
}
|
||||||
|
if got := f.wantAt("plain"); got != orderFP("d") {
|
||||||
|
t.Errorf("a module whose kept data keeps its form is wanted at %s, not moved", got)
|
||||||
|
}
|
||||||
|
if len(f.waits()) != 2 || len(f.events) != 2 || f.events[0] != meshwants.EventWaitHeld || f.bodies[0].Step != seatdef.StepPlace || f.bodies[0].Module != "web" {
|
||||||
|
t.Fatalf("waits %v events %v bodies %+v: want two wait-held in the step place, `order.ace.web.backup` and `order.ace.web.bus`", f.waits(), f.events, f.bodies)
|
||||||
|
}
|
||||||
|
if _, err := acting.Decode(f.p.w.read(buckets.Waits())[acting.OrderKey("ace", "web", "backup")]); err != nil {
|
||||||
|
t.Fatalf("the wait is not kept under its key: %v", err)
|
||||||
|
}
|
||||||
|
f.pass()
|
||||||
|
if len(f.events) != 2 {
|
||||||
|
t.Fatalf("a pass that changed nothing said %v", f.events)
|
||||||
|
}
|
||||||
|
f.runs("backup", orderFP("f"))
|
||||||
|
f.pass()
|
||||||
|
if got := f.wantAt("web"); got != orderFP("a") || len(f.events) != 3 || f.events[2] != meshwants.EventWaitEnded || f.bodies[2].How != acting.HowRan {
|
||||||
|
t.Fatalf("with the bus module still old: web at %s, events %v", got, f.events)
|
||||||
|
}
|
||||||
|
f.runs("bus", orderFP("h"))
|
||||||
|
f.pass()
|
||||||
|
f.pass()
|
||||||
|
if got := f.wantAt("web"); got != orderFP("b") || len(f.waits()) != 0 || len(f.events) != 4 {
|
||||||
|
t.Fatalf("with both running: web at %s, waits %v, events %v", got, f.waits(), f.events)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// §298 first edge, the hand: assigner_waits reads an order wait and assigner_release with how `now` lets the module move.
|
||||||
|
func TestAnOrderWaitIsReadAndReleasedByTheExistingTools(t *testing.T) {
|
||||||
|
f := newOrderFixture(t, []orderMod{
|
||||||
|
{name: "web", run: orderFP("a"), trunk: orderFP("b"), forms: map[string]int{orderFP("a"): 1, orderFP("b"): 2}},
|
||||||
|
{name: "backup", run: orderFP("e"), trunk: orderFP("f"), holds: []string{catalogue.BackupSeat}},
|
||||||
|
})
|
||||||
|
f.pass()
|
||||||
|
f.pass()
|
||||||
|
var acts []string
|
||||||
|
s := newPutTools(memStore{waitsState: f.p.kvs[buckets.Waits()].(*memKV), buckets.DeliveryWaitsState: &memKV{values: map[string][]byte{}}, buckets.DeliveredAgainState: &memKV{values: map[string][]byte{}}}, func(key string, body any) (json.RawMessage, error) {
|
||||||
|
acts = append(acts, key)
|
||||||
|
return json.RawMessage(`{"ok":true,"log":"logged"}`), nil
|
||||||
|
})
|
||||||
|
got, err := s.doWaits(map[string]any{"module": "web"})
|
||||||
|
if list := got.(map[string]any)["waits"].([]any); err != nil || len(list) != 1 || list[0].(actingSaid).Key != "order.ace.web.backup" {
|
||||||
|
t.Fatalf("assigner_waits = %+v %v", got, err)
|
||||||
|
}
|
||||||
|
if _, err := s.doRelease(map[string]any{"node": "ace", "module": "web", "how": "now", "why": "the restore point is taken by hand"}, "shanks.node-tools"); err != nil || len(acts) == 0 {
|
||||||
|
t.Fatalf("%v %v", err, acts)
|
||||||
|
}
|
||||||
|
f.p.w.put(buckets.Waits(), "order.ace.web.backup", f.p.kvs[buckets.Waits()].(*memKV).values["order.ace.web.backup"])
|
||||||
|
f.pass()
|
||||||
|
f.pass()
|
||||||
|
if got := f.wantAt("web"); got != orderFP("b") || f.bodies[len(f.bodies)-1].How != acting.HowReleased {
|
||||||
|
t.Fatalf("after the release: web at %s, last %+v", got, f.bodies[len(f.bodies)-1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// §298 second edge, A-259: at a revert the node-engine goes back last on its node, after every module that is set back there across a
|
||||||
|
// form change runs the reverted build.
|
||||||
|
func TestAtARevertTheNodeEngineGoesBackLast(t *testing.T) {
|
||||||
|
old, now := map[string]string{"web": orderFP("a"), "engine": orderFP("c")}, map[string]string{"web": orderFP("b"), "engine": orderFP("d")}
|
||||||
|
f := newOrderFixture(t, []orderMod{
|
||||||
|
{name: "web", run: orderFP("b"), trunk: orderFP("a"), forms: map[string]int{orderFP("a"): 1, orderFP("b"): 2}},
|
||||||
|
{name: "engine", run: orderFP("d"), trunk: orderFP("c"), holds: []string{nodeengine.Seat}},
|
||||||
|
}, old, now)
|
||||||
|
f.pass()
|
||||||
|
f.pass()
|
||||||
|
if f.wantAt("web") != orderFP("a") {
|
||||||
|
t.Fatalf("web is wanted at %s: the module set back is not held", f.wantAt("web"))
|
||||||
|
}
|
||||||
|
if got := f.wantAt("engine"); got != orderFP("d") {
|
||||||
|
t.Fatalf("the node-engine is set back to %s before web runs its reverted build", got)
|
||||||
|
}
|
||||||
|
if w := f.waits(); len(w) != 1 || w[0] != "order.ace.engine.web" || f.bodies[len(f.bodies)-1].Module != "engine" {
|
||||||
|
t.Fatalf("waits %v bodies %+v", w, f.bodies)
|
||||||
|
}
|
||||||
|
f.runs("web", orderFP("a"))
|
||||||
|
f.pass()
|
||||||
|
f.pass()
|
||||||
|
if got := f.wantAt("engine"); got != orderFP("c") || len(f.waits()) != 0 {
|
||||||
|
t.Fatalf("with web back: the node-engine is wanted at %s, waits %v", got, f.waits())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// §298 third edge, A-259, A-260: the reverted assigner and gate are wanted only once the indexer's take-in.taken of the trunk branch names a
|
||||||
|
// source revision at least the trunk's head (the highest src of the trunk's module values).
|
||||||
|
func TestTheRevertedAssignerAndGateWaitForTheIndexerToTakeInTheTrunksHead(t *testing.T) {
|
||||||
|
old, now := map[string]string{"asg": orderFP("a"), "gate": orderFP("c"), "idx": orderFP("e")}, map[string]string{"asg": orderFP("b"), "gate": orderFP("d"), "idx": orderFP("f")}
|
||||||
|
f := newOrderFixture(t, []orderMod{
|
||||||
|
{name: "asg", run: orderFP("b"), trunk: orderFP("a"), holds: []string{mma.Seat}, src: 6},
|
||||||
|
{name: "gate", run: orderFP("d"), trunk: orderFP("c"), holds: []string{meshdelivery.Seat}, src: 7},
|
||||||
|
{name: "idx", run: orderFP("e"), trunk: orderFP("e"), src: 7},
|
||||||
|
}, old, now)
|
||||||
|
f.pass()
|
||||||
|
f.pass()
|
||||||
|
if f.wantAt("asg") != orderFP("b") || f.wantAt("gate") != orderFP("d") {
|
||||||
|
t.Fatalf("the reverted assigner (%s) and gate (%s) are wanted before the head is taken in", f.wantAt("asg"), f.wantAt("gate"))
|
||||||
|
}
|
||||||
|
if len(f.waits()) != 2 || f.bodies[0].Part != "mesh-delivery-indexer" {
|
||||||
|
t.Fatalf("waits %v bodies %+v", f.waits(), f.bodies)
|
||||||
|
}
|
||||||
|
taken := func(branch string, source int64) {
|
||||||
|
raw, _ := json.Marshal(meshcatalog.TakeInTaken{Kind: "taken", Key: "m.1", Branch: branch, Source: source})
|
||||||
|
if err := f.p.w.taken.put(raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taken("beta", 9) // another branch, and
|
||||||
|
taken(trunkBranch, 6)
|
||||||
|
f.pass()
|
||||||
|
if f.wantAt("asg") != orderFP("b") {
|
||||||
|
t.Fatal("a source revision before the trunk's head was taken in, and the assigner was wanted")
|
||||||
|
}
|
||||||
|
taken(trunkBranch, 7)
|
||||||
|
f.pass()
|
||||||
|
f.pass()
|
||||||
|
if f.wantAt("asg") != orderFP("a") || f.wantAt("gate") != orderFP("c") || len(f.waits()) != 0 {
|
||||||
|
t.Fatalf("after the head is taken in: asg %s gate %s waits %v", f.wantAt("asg"), f.wantAt("gate"), f.waits())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-260: an order wait still held after a restart is said again as wait-held, by a pass that remembers nothing, and ends at the next
|
||||||
|
// take-in.taken that names the trunk's head.
|
||||||
|
func TestAnOrderWaitHeldAfterARestartIsSaidAgain(t *testing.T) {
|
||||||
|
old, now := map[string]string{"asg": orderFP("a")}, map[string]string{"asg": orderFP("b")}
|
||||||
|
f := newOrderFixture(t, []orderMod{{name: "asg", run: orderFP("b"), trunk: orderFP("a"), holds: []string{mma.Seat}, src: 7}}, old, now)
|
||||||
|
f.pass()
|
||||||
|
f.pass()
|
||||||
|
if len(f.events) != 1 {
|
||||||
|
t.Fatalf("events %v", f.events)
|
||||||
|
}
|
||||||
|
f.p.orderSaid = nil // a process started again
|
||||||
|
f.pass()
|
||||||
|
if len(f.events) != 2 || f.events[1] != meshwants.EventWaitHeld || len(f.waits()) != 1 {
|
||||||
|
t.Fatalf("events %v waits %v", f.events, f.waits())
|
||||||
|
}
|
||||||
|
raw, _ := json.Marshal(meshcatalog.TakeInTaken{Kind: "taken", Key: "m.1", Branch: trunkBranch, Source: 8})
|
||||||
|
if err := f.p.w.taken.put(raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
f.pass()
|
||||||
|
f.pass()
|
||||||
|
if f.wantAt("asg") != orderFP("a") || len(f.waits()) != 0 || f.events[len(f.events)-1] != meshwants.EventWaitEnded {
|
||||||
|
t.Fatalf("asg at %s, waits %v, events %v", f.wantAt("asg"), f.waits(), f.events)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,499 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/catalogkey"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/views"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/assignment"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
"mesh-delivery-assigner/internal/outside"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The wait on an outside cause (design 47 G §706, ADR 0677): the assigner judges a node's health after a want moves, and a moved
|
||||||
|
// module's failing check on a machine whose open conditions name an outside cause is held as a wait (internal/outside has the
|
||||||
|
// rules). The conditions come only through the seat mesh-conditions: its verb `conditions`, read at each judging as a kept
|
||||||
|
// call, and its events, which only say when to judge again.
|
||||||
|
|
||||||
|
// conditionsVerb is the seat verb the keeper answers `conditions` by.
|
||||||
|
const conditionsVerb = "seat:" + mcseat.Seat + "." + mcseat.VerbConditions
|
||||||
|
|
||||||
|
// wantsPublisher says one of the seat mesh-wants' events, `wait-held` and `wait-ended` among them, under a message id the bus
|
||||||
|
// keeps one of.
|
||||||
|
func wantsPublisher(ctx context.Context, js jetstream.JetStream, node string) publisher {
|
||||||
|
return func(event string, body any, id string) error {
|
||||||
|
data, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
msg := nats.NewMsg(seatdef.EventSubject(meshwants.Seat, event))
|
||||||
|
msg.Header.Set("x-event-id", id)
|
||||||
|
msg.Header.Set("x-source", assignment.Module())
|
||||||
|
msg.Header.Set("x-node", node)
|
||||||
|
msg.Header.Set("x-time", time.Now().UTC().Format(time.RFC3339Nano))
|
||||||
|
msg.Header.Set("content-type", "application/json")
|
||||||
|
msg.Data = data
|
||||||
|
_, err = js.PublishMsg(ctx, msg, jetstream.WithMsgID(id))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// outsideActs keeps, while the process runs, what the judging of outside waits needs beside the kept waits: the conditions read
|
||||||
|
// for each machine (one answer is one judging), the machines a heard event says to judge again, the machines whose own network
|
||||||
|
// is held open, and each check's last signature.
|
||||||
|
type outsideActs struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
call func(key string, body any) (json.RawMessage, error) // a kept call
|
||||||
|
wake func()
|
||||||
|
logf func(string, ...any)
|
||||||
|
// bound and settle are the settings outside-wait-minutes and outside-settle-seconds.
|
||||||
|
bound, settle time.Duration
|
||||||
|
// reading is a read in flight by machine, answered the answers it brought, not yet judged by.
|
||||||
|
reading map[string]bool
|
||||||
|
answered map[string][]outside.Cond
|
||||||
|
// dirty is a machine whose waits are judged again, cleared a wait's key whose cause's clearing was heard.
|
||||||
|
dirty map[string]bool
|
||||||
|
cleared map[string]bool
|
||||||
|
// sigs is each check's last signature, by node.module.
|
||||||
|
sigs map[string]string
|
||||||
|
// own is the machines whose own network is open; ownRead says the read at the start was answered.
|
||||||
|
own map[string]bool
|
||||||
|
ownRead bool
|
||||||
|
// causes is, by condition key, the nodes whose waits stand on it, as the last pass kept them.
|
||||||
|
causes map[string][]string
|
||||||
|
// started says the first pass judged every wait again.
|
||||||
|
started bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOutsideActs(call func(string, any) (json.RawMessage, error), wake func(), logf func(string, ...any), bound, settle time.Duration) *outsideActs {
|
||||||
|
if bound <= 0 {
|
||||||
|
bound = outside.DefaultBound
|
||||||
|
}
|
||||||
|
if settle <= 0 {
|
||||||
|
settle = outside.DefaultSettle
|
||||||
|
}
|
||||||
|
return &outsideActs{call: call, wake: wake, logf: logf, bound: bound, settle: settle, reading: map[string]bool{}, answered: map[string][]outside.Cond{},
|
||||||
|
dirty: map[string]bool{}, cleared: map[string]bool{}, sigs: map[string]string{}, own: map[string]bool{}, causes: map[string][]string{}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// outsideSettings are the bounds of the wait, the settings outside-wait-minutes and outside-settle-seconds (design 47 G §633, §706),
|
||||||
|
// each read at the start from the file the manifest declares with the content ${config:<key>}, which the environment names
|
||||||
|
// (A-112, as the builder reads its own); zero for one whose file is missing or empty, which is its default, and an error
|
||||||
|
// naming the file for a content that is no positive whole number.
|
||||||
|
func outsideSettings(getenv func(string) string) (bound, settle time.Duration, err error) {
|
||||||
|
minutes, err := settingFile(getenv("MESH_ASSIGNER_OUTSIDE_WAIT_FILE"))
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
|
seconds, err := settingFile(getenv("MESH_ASSIGNER_OUTSIDE_SETTLE_FILE"))
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
|
return time.Duration(minutes) * time.Minute, time.Duration(seconds) * time.Second, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// settingFile reads one setting's file: 0 for no path, no file or an empty one.
|
||||||
|
func settingFile(path string) (int, error) {
|
||||||
|
if path == "" {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
raw, err := os.ReadFile(path)
|
||||||
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
v := strings.TrimSpace(string(raw))
|
||||||
|
if v == "" {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
n, err := strconv.Atoi(v)
|
||||||
|
if err != nil || n < 1 {
|
||||||
|
return 0, fmt.Errorf("%s holds %q, which is not a positive whole number", path, v)
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// readStart reads the open conditions of every machine once at the start, for the machines whose own network is held.
|
||||||
|
func (o *outsideActs) readStart() {
|
||||||
|
go func() {
|
||||||
|
answer, err := o.call(conditionsVerb, map[string]any{"scope": "machine"})
|
||||||
|
if err != nil {
|
||||||
|
o.logf("the open conditions are not read at the start (%v): no machine is held for its own network until its event is heard", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conds, err := outside.ParseConditions(answer)
|
||||||
|
if err != nil {
|
||||||
|
o.logf("%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
o.mu.Lock()
|
||||||
|
for m := range outside.OwnNetwork(conds) {
|
||||||
|
o.own[m] = true
|
||||||
|
}
|
||||||
|
o.ownRead = true
|
||||||
|
o.mu.Unlock()
|
||||||
|
o.wake()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Heard is one of the seat's events condition-raised, -changed or -cleared: it says which machines to judge again and keeps the
|
||||||
|
// machines whose own network is open; nothing is kept of the condition.
|
||||||
|
func (o *outsideActs) Heard(subject string, body []byte) {
|
||||||
|
var e mcseat.ConditionEvent
|
||||||
|
if err := json.Unmarshal(body, &e); err != nil || e.Key == "" {
|
||||||
|
o.logf("%s holds what is not a condition's event, and is dropped: %v", subject, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cleared := strings.HasSuffix(subject, "."+mcseat.EventConditionCleared)
|
||||||
|
o.mu.Lock()
|
||||||
|
if p := strings.Split(e.Key, "."); len(p) == 3 && p[0] == "machine" && p[2] == "network" {
|
||||||
|
o.own[p[1]] = !cleared
|
||||||
|
}
|
||||||
|
if cleared {
|
||||||
|
for _, node := range o.causes[e.Key] {
|
||||||
|
o.dirty[node] = true
|
||||||
|
o.cleared[node+"|"+e.Key] = true
|
||||||
|
}
|
||||||
|
} else if e.Subject != nil {
|
||||||
|
o.dirty[e.Subject.Machine] = true
|
||||||
|
for _, m := range e.Subject.Also {
|
||||||
|
o.dirty[m] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o.mu.Unlock()
|
||||||
|
o.wake()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Held says whether machine's own network is open: no want moves to it.
|
||||||
|
func (o *outsideActs) Held(machine string) bool {
|
||||||
|
if o == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
o.mu.Lock()
|
||||||
|
defer o.mu.Unlock()
|
||||||
|
return o.own[machine]
|
||||||
|
}
|
||||||
|
|
||||||
|
// take is the conditions read for machine, consumed (one answer is one judging), or false while the kept call is unanswered,
|
||||||
|
// which it starts when none is in flight.
|
||||||
|
func (o *outsideActs) take(machine string) ([]outside.Cond, bool) {
|
||||||
|
o.mu.Lock()
|
||||||
|
defer o.mu.Unlock()
|
||||||
|
if c, ok := o.answered[machine]; ok {
|
||||||
|
delete(o.answered, machine)
|
||||||
|
return c, true
|
||||||
|
}
|
||||||
|
if o.reading[machine] {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
o.reading[machine] = true
|
||||||
|
go func() {
|
||||||
|
answer, err := o.call(conditionsVerb, map[string]any{"scope": "machine", "machine": machine})
|
||||||
|
var conds []outside.Cond
|
||||||
|
if err == nil {
|
||||||
|
conds, err = outside.ParseConditions(answer)
|
||||||
|
}
|
||||||
|
o.mu.Lock()
|
||||||
|
o.reading[machine] = false
|
||||||
|
if err != nil {
|
||||||
|
o.logf("the conditions of %s are not read (%v): the move waits on %s", machine, err, outside.OnUnread)
|
||||||
|
} else {
|
||||||
|
o.answered[machine] = conds
|
||||||
|
o.dirty[machine] = true // the kept call answered: the move is judged by it
|
||||||
|
}
|
||||||
|
o.mu.Unlock()
|
||||||
|
if err == nil {
|
||||||
|
o.wake()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// outsideReview is the judging of module's check at fp on each of its nodes (§706): it returns the nodes as the rules read them,
|
||||||
|
// the have of a waiting move no failure (its health unknown) and a go-on's counted healthy, and keeps the waits, says their
|
||||||
|
// events, finding and ask. moved says the delivery moved owner to node.
|
||||||
|
func (p *passer) outsideReview(ctx context.Context, module, fp string, nodes []string, n assign.Nodes, keeperSelf bool, moved func(owner, node string) bool) assign.Nodes {
|
||||||
|
o := p.outside
|
||||||
|
if o == nil || fp == "" || p.kvs[buckets.Waits()] == nil {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
hex, err := catalogkey.KeyPart(fp)
|
||||||
|
if err != nil {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
now := p.clock()
|
||||||
|
kept := p.w.read(buckets.Waits())
|
||||||
|
override := map[string]string{}
|
||||||
|
// A wait of another fingerprint of this module is replaced by the newer want.
|
||||||
|
for key, raw := range kept {
|
||||||
|
if w, err := outside.Decode(raw); err == nil && w.Module == module && w.FP != fp {
|
||||||
|
p.outsideEnd(ctx, key, w, outside.HowReplaced, now)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, node := range nodes {
|
||||||
|
key := outside.Key(node, module, hex)
|
||||||
|
var prev *outside.Wait
|
||||||
|
if raw := kept[key]; raw != nil {
|
||||||
|
if w, err := outside.Decode(raw); err == nil {
|
||||||
|
prev = &w
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h, ok := n.Haves[node][module]
|
||||||
|
sig := fmt.Sprintf("%s|%s|%s", h.Fp, h.Phase, h.Health)
|
||||||
|
o.mu.Lock()
|
||||||
|
first := !o.started
|
||||||
|
changed := o.sigs[node+"."+module] != sig
|
||||||
|
o.sigs[node+"."+module] = sig
|
||||||
|
dirty := o.dirty[node]
|
||||||
|
cleared := prev != nil && prev.Cause != "" && o.cleared[node+"|"+prev.Cause]
|
||||||
|
o.mu.Unlock()
|
||||||
|
failing, healthy := ok && h.Fp == fp && assign.Failed(h), n.RunsHealthy(node, module, fp)
|
||||||
|
if !failing && !healthy && prev == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if prev != nil && p.outsideAnswered(prev, node, module, fp) {
|
||||||
|
dirty = true
|
||||||
|
}
|
||||||
|
due := prev != nil && (prev.Release != "" || (prev.Settling && !now.Before(prev.SettleEnds)))
|
||||||
|
var d outside.Decision
|
||||||
|
if prev != nil && !(first || changed || dirty || due) {
|
||||||
|
// nothing to judge by: the wait stands as kept; the bound's ask is made when it has run
|
||||||
|
d = outside.Decision{Wait: prev, Waiting: prev.Standing() || prev.Settling, Own: prev.Decided == outside.HowFailed || prev.Decided == outside.HowOwnFailure,
|
||||||
|
Counted: prev.Decided == outside.HowGoOn}
|
||||||
|
if prev.Standing() && !now.Before(prev.ClockFrom.Add(o.bound)) {
|
||||||
|
d.Ask = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f := outside.Facts{Now: now, Failing: failing, Healthy: healthy, Node: node, KeeperSelf: keeperSelf, Bound: o.bound, Settle: o.settle,
|
||||||
|
Moved: func(owner string) bool { return moved(owner, node) }, CauseCleared: cleared}
|
||||||
|
if failing && !keeperSelf {
|
||||||
|
f.Conds, f.Read = o.take(node)
|
||||||
|
}
|
||||||
|
d = outside.Judge(prev, node, module, fp, f)
|
||||||
|
o.mu.Lock()
|
||||||
|
delete(o.dirty, node)
|
||||||
|
if prev != nil {
|
||||||
|
delete(o.cleared, node+"|"+prev.Cause)
|
||||||
|
}
|
||||||
|
o.mu.Unlock()
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case d.Waiting:
|
||||||
|
override[node] = nodeengineclient.HealthUnknown
|
||||||
|
case d.Counted:
|
||||||
|
override[node] = nodeengineclient.HealthOK
|
||||||
|
}
|
||||||
|
p.outsideApply(ctx, key, hex, node, module, fp, prev, d, now)
|
||||||
|
}
|
||||||
|
o.mu.Lock()
|
||||||
|
o.started = true
|
||||||
|
o.mu.Unlock()
|
||||||
|
if len(override) == 0 {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
out := n
|
||||||
|
out.Haves = map[string]map[string]nodeengine.HaveByNodeModuleValue{}
|
||||||
|
for node, byModule := range n.Haves {
|
||||||
|
out.Haves[node] = map[string]nodeengine.HaveByNodeModuleValue{}
|
||||||
|
for m, h := range byModule {
|
||||||
|
out.Haves[node][m] = h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for node, health := range override {
|
||||||
|
h := out.Haves[node][module]
|
||||||
|
h.Health = health
|
||||||
|
if health == nodeengineclient.HealthOK {
|
||||||
|
h.Phase = nodeengineclient.PhaseRunning
|
||||||
|
}
|
||||||
|
out.Haves[node][module] = h
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// outsideAnswered reads the operator's answer to the wait's ask, from the teller's record of it under the ask's key (answeredWith,
|
||||||
|
// §700's path as the assigner reads an ask's answer), and notes it on the wait as a release; it says whether it did.
|
||||||
|
func (p *passer) outsideAnswered(w *outside.Wait, node, module, fp string) bool {
|
||||||
|
if w.Ask == "" || w.Release != "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
key, err := asks.OutsideAskKey(node, module, fp)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, how := range []string{assign.OptionGoOn, assign.OptionFailed} {
|
||||||
|
if p.answeredWith(key, how) {
|
||||||
|
w.Release, w.By, w.Why = how, "the operator", "the answer to the ask "+w.Ask
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// outsideApply keeps what a judging came to: the wait's record, its events, its finding and its ask.
|
||||||
|
func (p *passer) outsideApply(ctx context.Context, key, hex, node, module, fp string, prev *outside.Wait, d outside.Decision, now time.Time) {
|
||||||
|
o := p.outside
|
||||||
|
switch {
|
||||||
|
case d.End != "":
|
||||||
|
p.outsideEnd(ctx, key, *prev, d.End, now)
|
||||||
|
if d.Wait != nil {
|
||||||
|
p.keepWait(ctx, key, *d.Wait)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
case d.Wait == nil:
|
||||||
|
if prev != nil {
|
||||||
|
p.outsideEnd(ctx, key, *prev, "", now)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w := *d.Wait
|
||||||
|
if d.Held {
|
||||||
|
body := p.outsideBody(w)
|
||||||
|
if err := p.wantsSay(meshwants.EventWaitHeld, body, key+"."+w.On+"."+w.ClockFrom.UTC().Format(time.RFC3339Nano)); err != nil {
|
||||||
|
p.logf("the wait of %s on %s is not said, and is said at the next pass: %v", module, node, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.outsideFinding(w, true)
|
||||||
|
}
|
||||||
|
if d.Ask && w.Ask == "" {
|
||||||
|
if id := p.outsideAsk(ctx, node, module, fp, w, now); id != "" {
|
||||||
|
w.Ask = id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if w.Standing() || w.Settling || w.Decided != "" {
|
||||||
|
o.mu.Lock()
|
||||||
|
if w.Cause != "" && w.Standing() {
|
||||||
|
if !containsString(o.causes[w.Cause], node) {
|
||||||
|
o.causes[w.Cause] = append(o.causes[w.Cause], node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o.mu.Unlock()
|
||||||
|
if w.Settling {
|
||||||
|
p.wakeAt(w.SettleEnds, now)
|
||||||
|
} else if w.Standing() {
|
||||||
|
p.wakeAt(w.ClockFrom.Add(o.bound), now)
|
||||||
|
}
|
||||||
|
p.keepWait(ctx, key, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func containsString(l []string, s string) bool {
|
||||||
|
for _, x := range l {
|
||||||
|
if x == s {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// keepWait writes the wait's record.
|
||||||
|
func (p *passer) keepWait(ctx context.Context, key string, w outside.Wait) {
|
||||||
|
p.put(ctx, buckets.Waits(), key, func() ([]byte, error) { return outside.Encode(w) })
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *passer) outsideBody(w outside.Wait) meshwants.Wait {
|
||||||
|
since, from := w.Since, w.ClockFrom
|
||||||
|
return meshwants.Wait{Step: meshwants.WaitStepOutside, Owner: assignment.Module(), Node: w.Node, Module: w.Module, Fingerprint: w.FP, On: w.On,
|
||||||
|
Since: since, ClockFrom: &from, Bound: w.Bound,
|
||||||
|
Words: fmt.Sprintf("%s on %s waits on %s", w.Module, w.Node, w.On)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// outsideEnd ends a wait: its wait-ended with how (none for a settle, which was never said), its finding and ask taken away, and
|
||||||
|
// its record deleted unless the end decided it (the caller keeps that record).
|
||||||
|
func (p *passer) outsideEnd(ctx context.Context, key string, w outside.Wait, how string, now time.Time) {
|
||||||
|
if w.Standing() && how != "" {
|
||||||
|
body := p.outsideBody(w)
|
||||||
|
body.How = how
|
||||||
|
if err := p.wantsSay(meshwants.EventWaitEnded, body, key+"."+how+"."+now.UTC().Format(time.RFC3339Nano)); err != nil {
|
||||||
|
p.logf("the end of the wait of %s on %s is not said, and is said at the next pass: %v", w.Module, w.Node, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.outsideFinding(w, false)
|
||||||
|
if ask, err := asks.OutsideAskKey(w.Node, w.Module, w.FP); err == nil {
|
||||||
|
p.remove(ctx, buckets.Asks(), ask)
|
||||||
|
}
|
||||||
|
if p.outside != nil && w.Cause != "" {
|
||||||
|
p.outside.mu.Lock()
|
||||||
|
p.outside.causes[w.Cause] = removeString(p.outside.causes[w.Cause], w.Node)
|
||||||
|
p.outside.mu.Unlock()
|
||||||
|
}
|
||||||
|
p.remove(ctx, buckets.Waits(), key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeString(l []string, s string) []string {
|
||||||
|
var out []string
|
||||||
|
for _, x := range l {
|
||||||
|
if x != s {
|
||||||
|
out = append(out, x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// outsideFinding writes the finding delivery-waits-outside, or clears it.
|
||||||
|
func (p *passer) outsideFinding(w outside.Wait, raised bool) {
|
||||||
|
if p.findings.Put == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
o := assign.WaitsOutsideFinding(w.Node, w.Module, w.Cause, w.On, p.clock())
|
||||||
|
if raised {
|
||||||
|
if err := p.findings.Put(o.Finding(p.clock())); err != nil {
|
||||||
|
p.logf("the finding %s is not written: %v", "delivery."+o.ID, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if p.findings.Delete != nil {
|
||||||
|
if err := p.findings.Delete(mcseatKey(o)); err != nil {
|
||||||
|
p.logf("the finding %s is not cleared: %v", "delivery."+o.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mcseatKey(o assign.Observed) string {
|
||||||
|
return views.FindingKey(o.Scope, assign.KeyID(o.ID), o.Kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
// outsideAsk asks the operator at the wait's bound, once, and returns the asking's id.
|
||||||
|
func (p *passer) outsideAsk(ctx context.Context, node, module, fp string, w outside.Wait, now time.Time) string {
|
||||||
|
key, err := asks.OutsideAskKey(node, module, fp)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
asking := assign.AskingSeconds(now)
|
||||||
|
a := assign.OutsideAsk(key, asks.OutsideAbout(key), node, module, fp, w.On, w.ClockFrom, asking, now)
|
||||||
|
p.put(ctx, buckets.Asks(), key, func() ([]byte, error) { return assign.EncodeAsk(key, a) })
|
||||||
|
if ask, err := assign.AskOf(a); err == nil {
|
||||||
|
return ask.ID
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// wakeAt makes a pass when t comes: the settle's end and the bound are the waits' own times, the one wake (no polling).
|
||||||
|
func (p *passer) wakeAt(t, now time.Time) {
|
||||||
|
if p.outside == nil || p.outside.wake == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.AfterFunc(max(t.Sub(now), 0)+time.Millisecond, p.outside.wake)
|
||||||
|
}
|
||||||
@@ -0,0 +1,333 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||||
|
mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||||
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
"mesh-delivery-assigner/internal/outside"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The whole of the wait on an outside cause in the pass (design 47 G §706): a fixture keeper answering `conditions` and saying
|
||||||
|
// its events, a failing check of nats on ace, and the events, finding, ask and record the pass leaves.
|
||||||
|
type outsideRig struct {
|
||||||
|
t *testing.T
|
||||||
|
p *passer
|
||||||
|
now time.Time
|
||||||
|
conds []map[string]any
|
||||||
|
unread bool
|
||||||
|
events []string
|
||||||
|
bodies []meshwants.Wait
|
||||||
|
found map[string]bool
|
||||||
|
woke chan struct{}
|
||||||
|
health string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOutsideRig(t *testing.T) *outsideRig {
|
||||||
|
r := &outsideRig{t: t, now: time.Date(2026, 11, 11, 10, 0, 0, 0, time.UTC), found: map[string]bool{}, woke: make(chan struct{}, 16), health: nodeengineclient.HealthFailed}
|
||||||
|
r.p = newPasser(kvSet{buckets.Waits(): &memKV{values: map[string][]byte{}}, buckets.Asks(): &memKV{values: map[string][]byte{}}}, r.now)
|
||||||
|
r.p.now = func() time.Time { return r.now }
|
||||||
|
r.p.w.put(buckets.Asks(), "x", nil)
|
||||||
|
r.p.outside = newOutsideActs(func(key string, body any) (json.RawMessage, error) {
|
||||||
|
if r.unread {
|
||||||
|
return nil, context.DeadlineExceeded
|
||||||
|
}
|
||||||
|
return json.Marshal(map[string]any{"conditions": r.conds})
|
||||||
|
}, func() { r.woke <- struct{}{} }, func(string, ...any) {}, 30*time.Minute, 90*time.Second)
|
||||||
|
r.p.publishWants = func(event string, body any, id string) error {
|
||||||
|
r.events = append(r.events, event)
|
||||||
|
r.bodies = append(r.bodies, body.(meshwants.Wait))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
r.p.findings.Put = func(f mcseat.Finding) error { r.found[f.Scope+"."+f.ID+"."+f.Kind] = true; return nil }
|
||||||
|
r.p.findings.Delete = func(key string) error { delete(r.found, key); return nil }
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *outsideRig) cond(key string, also ...string) {
|
||||||
|
r.conds = append(r.conds, map[string]any{"key": key, "subject": map[string]any{"machine": strings.Split(key, ".")[1], "also": also}})
|
||||||
|
}
|
||||||
|
|
||||||
|
// review is one pass's judging of nats on ace at the fingerprint, with the read answered at once when one is started.
|
||||||
|
func (r *outsideRig) review(keeperSelf bool, moved func(string, string) bool) assign.Nodes {
|
||||||
|
r.t.Helper()
|
||||||
|
n := assign.Nodes{Online: map[string]bool{"ace": true}, Haves: map[string]map[string]nodeengine.HaveByNodeModuleValue{
|
||||||
|
"ace": {"nats": {Fp: fpTest, Phase: nodeengineclient.PhaseRunning, Health: r.health}}}}
|
||||||
|
healthy := r.health == nodeengineclient.HealthOK
|
||||||
|
n.Running = map[string]map[string]nodeengine.Running{"ace": {"nats": {Node: "ace", Module: "nats", Fingerprint: fpTest, Healthy: &healthy}}}
|
||||||
|
if moved == nil {
|
||||||
|
moved = func(string, string) bool { return false }
|
||||||
|
}
|
||||||
|
out := r.p.outsideReview(context.Background(), "nats", fpTest, []string{"ace"}, n, keeperSelf, moved)
|
||||||
|
select {
|
||||||
|
case <-r.woke: // the read was answered: the next pass judges by it
|
||||||
|
out = r.p.outsideReview(context.Background(), "nats", fpTest, []string{"ace"}, n, keeperSelf, moved)
|
||||||
|
case <-time.After(50 * time.Millisecond):
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *outsideRig) wait() outside.Wait {
|
||||||
|
r.t.Helper()
|
||||||
|
for _, v := range r.p.w.read(buckets.Waits()) {
|
||||||
|
w, err := outside.Decode(v)
|
||||||
|
if err != nil {
|
||||||
|
r.t.Fatal(err)
|
||||||
|
}
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
return outside.Wait{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTheWaitOnAnOutsideCause(t *testing.T) {
|
||||||
|
healthOf := func(n assign.Nodes) string { return n.Haves["ace"]["nats"].Health }
|
||||||
|
t.Run("a cause listing the machine is a wait said at once, ended cleared when it clears healthy", func(t *testing.T) {
|
||||||
|
r := newOutsideRig(t)
|
||||||
|
r.cond("machine.hub.unreachable", "ace")
|
||||||
|
n := r.review(false, nil)
|
||||||
|
if healthOf(n) == nodeengineclient.HealthFailed || len(r.events) != 1 || r.events[0] != meshwants.EventWaitHeld {
|
||||||
|
t.Fatalf("health %s events %v", healthOf(n), r.events)
|
||||||
|
}
|
||||||
|
b := r.bodies[0]
|
||||||
|
if b.Step != meshwants.WaitStepOutside || b.On != "unreachable:hub" || b.Bound != "30m0s" || b.ClockFrom == nil || !b.ClockFrom.Equal(r.now) || b.Node != "ace" || b.Module != "nats" {
|
||||||
|
t.Errorf("wait-held %+v", b)
|
||||||
|
}
|
||||||
|
if !r.found["delivery.ace.nats.delivery-waits-outside"] {
|
||||||
|
t.Errorf("findings %v", r.found)
|
||||||
|
}
|
||||||
|
// the cause clears and the module runs healthy
|
||||||
|
r.conds, r.health, r.now = nil, nodeengineclient.HealthOK, r.now.Add(time.Minute)
|
||||||
|
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-cleared", []byte(`{"key":"machine.hub.unreachable","event":"cleared","change":"cleared","at":"2026-11-11T10:01:00Z","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||||
|
<-r.woke
|
||||||
|
r.review(false, nil)
|
||||||
|
if len(r.events) != 2 || r.events[1] != meshwants.EventWaitEnded || r.bodies[1].How != outside.HowCleared || len(r.found) != 0 || len(r.p.w.read(buckets.Waits())) != 0 {
|
||||||
|
t.Errorf("events %v bodies %+v findings %v", r.events, r.bodies, r.found)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("a cause not listing the machine settles, then the failure is the delivery's", func(t *testing.T) {
|
||||||
|
r := newOutsideRig(t)
|
||||||
|
r.cond("machine.hub.unreachable", "g14")
|
||||||
|
n := r.review(false, nil)
|
||||||
|
if healthOf(n) == nodeengineclient.HealthFailed || len(r.events) != 0 || !r.wait().Settling {
|
||||||
|
t.Fatalf("settle: health %s events %v wait %+v", healthOf(n), r.events, r.wait())
|
||||||
|
}
|
||||||
|
r.now = r.now.Add(91 * time.Second)
|
||||||
|
if n := r.review(false, nil); healthOf(n) != nodeengineclient.HealthFailed {
|
||||||
|
t.Errorf("past the settle the check still counts as failing: %s", healthOf(n))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("a cause turning into another keeps the wait and its clock; a rewritten naming a moved module fails at once", func(t *testing.T) {
|
||||||
|
r := newOutsideRig(t)
|
||||||
|
r.cond("machine.hub.unreachable", "ace")
|
||||||
|
r.review(false, nil)
|
||||||
|
r.conds = nil
|
||||||
|
r.cond("machine.hub.network", "ace")
|
||||||
|
r.now = r.now.Add(5 * time.Minute)
|
||||||
|
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-raised", []byte(`{"key":"machine.hub.network","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||||
|
<-r.woke
|
||||||
|
r.review(false, nil)
|
||||||
|
last := len(r.bodies) - 1
|
||||||
|
if len(r.events) != 2 || r.events[last] != meshwants.EventWaitHeld || r.bodies[last].On != "network:hub" || !r.bodies[last].ClockFrom.Equal(*r.bodies[0].ClockFrom) {
|
||||||
|
t.Errorf("events %v bodies %+v", r.events, r.bodies)
|
||||||
|
}
|
||||||
|
r2 := newOutsideRig(t)
|
||||||
|
r2.cond("machine.ace.nats.rewritten")
|
||||||
|
n := r2.review(false, func(owner, node string) bool { return owner == "nats" })
|
||||||
|
if healthOf(n) == nodeengineclient.HealthFailed || !r2.wait().Settling {
|
||||||
|
t.Errorf("a rewritten of the moved module is its failure: %s %+v", healthOf(n), r2.wait())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("the keeper silent waits on conditions-unread, and its own module is judged with no read", func(t *testing.T) {
|
||||||
|
r := newOutsideRig(t)
|
||||||
|
r.unread = true
|
||||||
|
r.review(false, nil)
|
||||||
|
r.now = r.now.Add(90 * time.Second) // the settle has run with no answer
|
||||||
|
r.review(false, nil)
|
||||||
|
if len(r.bodies) != 1 || r.bodies[0].On != outside.OnUnread {
|
||||||
|
t.Fatalf("bodies %+v", r.bodies)
|
||||||
|
}
|
||||||
|
r2 := newOutsideRig(t)
|
||||||
|
r2.cond("machine.hub.unreachable", "ace")
|
||||||
|
if n := r2.review(true, nil); healthOf(n) != nodeengineclient.HealthFailed || len(r2.events) != 0 {
|
||||||
|
t.Errorf("the keeper's own failing check waits: %s %v", healthOf(n), r2.events)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("past the bound the operator is asked; Go on counts it healthy and Count as failed holds it, each said ended", func(t *testing.T) {
|
||||||
|
for how, want := range map[string]string{assign.OptionGoOn: nodeengineclient.HealthOK, assign.OptionFailed: nodeengineclient.HealthFailed} {
|
||||||
|
r := newOutsideRig(t)
|
||||||
|
r.cond("machine.hub.silent", "ace")
|
||||||
|
r.review(false, nil)
|
||||||
|
r.now = r.now.Add(31 * time.Minute)
|
||||||
|
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(`{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||||
|
<-r.woke
|
||||||
|
r.review(false, nil)
|
||||||
|
key, _ := asks.OutsideAskKey("ace", "nats", fpTest)
|
||||||
|
raw := r.p.w.value(buckets.Asks(), key)
|
||||||
|
if raw == nil {
|
||||||
|
t.Fatalf("%s: no ask at %s", how, key)
|
||||||
|
}
|
||||||
|
_, ask, err := assign.DecodeAsk(key, raw)
|
||||||
|
if err != nil || ask.About != "ace.nats."+strings.TrimPrefix(key[strings.LastIndex(key, ".")+1:], "") || len(ask.Options) != 2 {
|
||||||
|
t.Fatalf("ask %+v %v", ask, err)
|
||||||
|
}
|
||||||
|
v, _ := mdc.EncodeAnswer(mdc.Answer{Option: how, Warrant: ask.ID + "@2026-11-11T10:32:00Z", Words: "the operator"})
|
||||||
|
r.p.w.put(buckets.Answers, key, v)
|
||||||
|
n := r.review(false, nil)
|
||||||
|
if r.events[len(r.events)-1] != meshwants.EventWaitEnded || r.bodies[len(r.bodies)-1].How != how || healthOf(n) != want {
|
||||||
|
t.Errorf("%s: events %v last %+v health %s", how, r.events, r.bodies[len(r.bodies)-1], healthOf(n))
|
||||||
|
}
|
||||||
|
if r.p.w.value(buckets.Asks(), key) != nil || len(r.found) != 0 {
|
||||||
|
t.Errorf("%s: the ask or the finding stands after the end", how)
|
||||||
|
}
|
||||||
|
// a check that goes on failing is not waited on again
|
||||||
|
r.now = r.now.Add(time.Minute)
|
||||||
|
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-raised", []byte(`{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||||
|
<-r.woke
|
||||||
|
before := len(r.events)
|
||||||
|
r.review(false, nil)
|
||||||
|
if len(r.events) != before {
|
||||||
|
t.Errorf("%s: a decided check is waited on again", how)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("a newer want ends the wait replaced, and a restart judges it again", func(t *testing.T) {
|
||||||
|
r := newOutsideRig(t)
|
||||||
|
r.cond("machine.hub.unreachable", "ace")
|
||||||
|
r.review(false, nil)
|
||||||
|
n := assign.Nodes{Online: map[string]bool{"ace": true}, Haves: map[string]map[string]nodeengine.HaveByNodeModuleValue{}}
|
||||||
|
r.p.outsideReview(context.Background(), "nats", "src2:"+strings.Repeat("c", 64), []string{"ace"}, n, false, func(string, string) bool { return false })
|
||||||
|
if r.events[len(r.events)-1] != meshwants.EventWaitEnded || r.bodies[len(r.bodies)-1].How != outside.HowReplaced {
|
||||||
|
t.Errorf("events %v", r.events)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("its bounds are read at the start from the files the manifest declares (A-112)", func(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
write := func(name, content string) string {
|
||||||
|
p := filepath.Join(dir, name)
|
||||||
|
if err := os.WriteFile(p, []byte(content), 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
env := map[string]string{"MESH_ASSIGNER_OUTSIDE_WAIT_FILE": write("wait", "45\n"), "MESH_ASSIGNER_OUTSIDE_SETTLE_FILE": write("settle", "7")}
|
||||||
|
if bound, settle, err := outsideSettings(func(k string) string { return env[k] }); err != nil || bound != 45*time.Minute || settle != 7*time.Second {
|
||||||
|
t.Errorf("bound %v settle %v err %v, want 45m and 7s", bound, settle, err)
|
||||||
|
}
|
||||||
|
env["MESH_ASSIGNER_OUTSIDE_WAIT_FILE"], env["MESH_ASSIGNER_OUTSIDE_SETTLE_FILE"] = filepath.Join(dir, "missing"), write("empty", "")
|
||||||
|
if bound, settle, err := outsideSettings(func(k string) string { return env[k] }); err != nil || bound != 0 || settle != 0 {
|
||||||
|
t.Errorf("bound %v settle %v err %v, want both defaults", bound, settle, err)
|
||||||
|
}
|
||||||
|
env["MESH_ASSIGNER_OUTSIDE_SETTLE_FILE"] = write("bad", "soon")
|
||||||
|
if _, _, err := outsideSettings(func(k string) string { return env[k] }); err == nil || !strings.Contains(err.Error(), "bad") {
|
||||||
|
t.Errorf("err %v, want one naming the file", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAMachineWhoseOwnNetworkIsOpenGetsNoWant(t *testing.T) {
|
||||||
|
m := assign.Module{Name: "nats", FP: fpTest, Built: true, Nodes: []string{"ace"}, MachineHeld: func(node string) bool { return node == "ace" }}
|
||||||
|
ok, rule, why := assign.Holds(m, "ace", assign.Nodes{Online: map[string]bool{"ace": true}})
|
||||||
|
if ok || rule == 0 || !strings.Contains(why, "machine.ace.network") {
|
||||||
|
t.Errorf("holds = %v %d %q", ok, rule, why)
|
||||||
|
}
|
||||||
|
o := newOutsideActs(nil, func() {}, func(string, ...any) {}, 0, 0)
|
||||||
|
o.Heard("mesh.seat.mesh-conditions.event.condition-raised", []byte(`{"key":"machine.ace.network","subject":{"id":"ace","scope":"machine","machine":"ace"}}`))
|
||||||
|
if !o.Held("ace") || o.Held("g14") {
|
||||||
|
t.Error("the own network condition's event does not hold the machine")
|
||||||
|
}
|
||||||
|
o.Heard("mesh.seat.mesh-conditions.event.condition-cleared", []byte(`{"key":"machine.ace.network","subject":{"id":"ace","scope":"machine","machine":"ace"}}`))
|
||||||
|
if o.Held("ace") {
|
||||||
|
t.Error("the machine is held after its condition cleared")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTheToolsReadAndReleaseAnOutsideWait(t *testing.T) {
|
||||||
|
r := newOutsideRig(t)
|
||||||
|
r.cond("machine.hub.unreachable", "ace")
|
||||||
|
r.review(false, nil)
|
||||||
|
var acts []string
|
||||||
|
s := newPutTools(memStore{waitsState: &memKV{values: map[string][]byte{}}, buckets.DeliveryWaitsState: &memKV{values: map[string][]byte{}}, buckets.DeliveredAgainState: &memKV{values: map[string][]byte{}}}, func(key string, body any) (json.RawMessage, error) {
|
||||||
|
acts = append(acts, key)
|
||||||
|
return json.RawMessage(`{"ok":true,"log":"logged"}`), nil
|
||||||
|
})
|
||||||
|
for k, v := range r.p.w.read(buckets.Waits()) {
|
||||||
|
s.st.put(waitsState, k, v)
|
||||||
|
}
|
||||||
|
got, err := s.doWaits(map[string]any{"module": "nats"})
|
||||||
|
if err != nil || len(got.(map[string]any)["waits"].([]any)) != 1 {
|
||||||
|
t.Fatalf("assigner_waits = %+v %v", got, err)
|
||||||
|
}
|
||||||
|
if w := got.(map[string]any)["waits"].([]any)[0].(waitSaid); w.On != "unreachable:hub" || w.BoundEnds == "" {
|
||||||
|
t.Errorf("wait = %+v", w)
|
||||||
|
}
|
||||||
|
if _, err := s.doRelease(map[string]any{"node": "ace", "module": "nats", "how": "sideways", "why": "x"}, "shanks.node-tools"); err == nil {
|
||||||
|
t.Error("an unknown how is taken")
|
||||||
|
}
|
||||||
|
if _, err := s.doRelease(map[string]any{"node": "ace", "module": "nats", "how": "go-on"}, "shanks.node-tools"); err == nil || len(acts) != 0 {
|
||||||
|
t.Error("a release with no why is taken")
|
||||||
|
}
|
||||||
|
if _, err := s.doRelease(map[string]any{"node": "ace", "module": "nats", "how": "go-on", "why": "the hub is being rebuilt"}, "shanks.node-tools"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(acts) == 0 || !strings.Contains(acts[0], "hand-act") {
|
||||||
|
t.Errorf("the hand act is not recorded first: %v", acts)
|
||||||
|
}
|
||||||
|
keys, _ := s.st.keys(waitsState)
|
||||||
|
raw, _, _, _ := s.st.get(waitsState, keys[0])
|
||||||
|
if w, _ := outside.Decode(raw); w.Release != "go-on" || !strings.Contains(w.By, "the hub is being rebuilt") {
|
||||||
|
t.Errorf("wait = %+v", w)
|
||||||
|
}
|
||||||
|
// the process takes the release at its next pass: ended go-on, counted healthy
|
||||||
|
r.p.w.put(buckets.Waits(), keys[0], raw)
|
||||||
|
n := r.review(false, nil)
|
||||||
|
if r.bodies[len(r.bodies)-1].How != "go-on" || n.Haves["ace"]["nats"].Health != nodeengineclient.HealthOK {
|
||||||
|
t.Errorf("last %+v health %s", r.bodies[len(r.bodies)-1], n.Haves["ace"]["nats"].Health)
|
||||||
|
}
|
||||||
|
// A-246: a dependent's delivery wait is listed beside them, and released by its module and step delivery, its hand act first.
|
||||||
|
dw, _ := json.Marshal(deliveryWaiting{Wait: meshwants.Wait{Step: meshwants.WaitStepDelivery, Module: "app", Part: "db", On: "db@1.1.0", Machines: []string{"g14"}}})
|
||||||
|
s.st.put(buckets.DeliveryWaitsState, "app", dw)
|
||||||
|
got, err = s.doWaits(map[string]any{"node": "g14"})
|
||||||
|
if d := got.(map[string]any)["delivery"].([]deliveryWaiting); err != nil || len(d) != 1 || d[0].Module != "app" {
|
||||||
|
t.Errorf("the delivery waits listed = %+v %v", got, err)
|
||||||
|
}
|
||||||
|
if _, err := s.doRelease(map[string]any{"module": "app", "step": "build", "why": "x"}, "shanks.node-tools"); err == nil {
|
||||||
|
t.Error("a release of another step is taken")
|
||||||
|
}
|
||||||
|
if _, err := s.doRelease(map[string]any{"module": "web", "step": "delivery", "why": "x"}, "shanks.node-tools"); err == nil {
|
||||||
|
t.Error("a release of a module waiting for no delivery is taken")
|
||||||
|
}
|
||||||
|
before := len(acts)
|
||||||
|
if _, err := s.doRelease(map[string]any{"module": "app", "step": "delivery", "why": "db is fine as it runs"}, "shanks.node-tools"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
raw, _, _, _ = s.st.get(buckets.DeliveryWaitsState, "app")
|
||||||
|
var released deliveryWaiting
|
||||||
|
if json.Unmarshal(raw, &released) != nil || !released.Released || !strings.Contains(released.By, "db is fine") || len(acts) != before+1 {
|
||||||
|
t.Errorf("the delivery wait after its release = %+v, hand acts %v", released, acts[before:])
|
||||||
|
}
|
||||||
|
// A-250: assigner_delivered_again records its hand act, writes the ask and answers asked; assigner_waits lists it.
|
||||||
|
if _, err := s.doDeliveredAgain(map[string]any{"module": "db", "version": "1.1.0"}, "op"); err == nil {
|
||||||
|
t.Error("an ask with no why is taken")
|
||||||
|
}
|
||||||
|
ans, err := s.doDeliveredAgain(map[string]any{"module": "db", "version": "1.1.0", "why": "the catalog missed it"}, "op")
|
||||||
|
if err != nil || ans.(map[string]any)["asked"] != "db" || len(acts) != before+2 {
|
||||||
|
t.Fatalf("assigner_delivered_again = %+v %v", ans, err)
|
||||||
|
}
|
||||||
|
got, _ = s.doWaits(map[string]any{})
|
||||||
|
if a := got.(map[string]any)["delivered-again"].([]againAsk); len(a) != 1 || a[0].Version != "1.1.0" || a[0].By != "op" {
|
||||||
|
t.Errorf("the asks listed = %+v", a)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,300 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/acting"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
"mesh-delivery-assigner/internal/outside"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The tools of the waits on an outside cause (design 47 G §706, §276's row *delivery on an outside cause*): `assigner_waits` reads
|
||||||
|
// each, the settle included, and `assigner_release` with `how` takes one. The tool writes the release into the wait's record and the
|
||||||
|
// assigner's process ends the wait at its next pass, saying wait-ended with that how.
|
||||||
|
|
||||||
|
// toolWaits is the tool that reads the outside waits.
|
||||||
|
const toolWaits = "assigner_waits"
|
||||||
|
|
||||||
|
// waitsState is the assigner's state of waits, as the runtime names a module's own state.
|
||||||
|
const waitsState = buckets.WaitsState
|
||||||
|
|
||||||
|
// waitSaid is one wait as assigner_waits answers it: its record and where it stands.
|
||||||
|
type waitSaid struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
outside.Wait
|
||||||
|
// Settling's end is in the record; Ends is when the bound runs from clock-from, empty for a settle.
|
||||||
|
BoundEnds string `json:"bound-ends,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// actingSaid is one wait for an acting part's new version as assigner_waits answers it (actingwaits.go).
|
||||||
|
type actingSaid struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
acting.Wait
|
||||||
|
BoundEnds string `json:"bound-ends,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// doWaits is the tool assigner_waits.
|
||||||
|
func (s *putTools) doWaits(args map[string]any) (any, error) {
|
||||||
|
keys, err := s.st.keys(waitsState)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the waits cannot be listed: %w", err)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
out := []any{}
|
||||||
|
for _, key := range keys {
|
||||||
|
raw, _, found, err := s.st.get(waitsState, key)
|
||||||
|
if err != nil || !found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if acting.Is(key) || acting.IsOrder(key) {
|
||||||
|
if a, err := acting.Decode(raw); err == nil && (arg(args, "node") == "" || a.Node == arg(args, "node")) && (arg(args, "module") == "" || a.Module == arg(args, "module")) {
|
||||||
|
said := actingSaid{Key: key, Wait: a}
|
||||||
|
if d, err := time.ParseDuration(a.Bound); err == nil && !a.Released {
|
||||||
|
said.BoundEnds = a.ClockFrom.Add(d).UTC().Format("2006-01-02T15:04:05Z")
|
||||||
|
}
|
||||||
|
out = append(out, said)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w, err := outside.Decode(raw)
|
||||||
|
if err != nil || (arg(args, "node") != "" && w.Node != arg(args, "node")) || (arg(args, "module") != "" && w.Module != arg(args, "module")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
said := waitSaid{Key: key, Wait: w}
|
||||||
|
if w.Standing() {
|
||||||
|
if d, err := time.ParseDuration(w.Bound); err == nil {
|
||||||
|
said.BoundEnds = w.ClockFrom.Add(d).UTC().Format("2006-01-02T15:04:05Z")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out = append(out, said)
|
||||||
|
}
|
||||||
|
// And each dependent's wait for its dependency's delivery (design 47 G §376, A-246), from the state delivery-waits.
|
||||||
|
delivery := []deliveryWaiting{}
|
||||||
|
dkeys, err := s.st.keys(buckets.DeliveryWaitsState)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the delivery waits cannot be listed: %w", err)
|
||||||
|
}
|
||||||
|
sort.Strings(dkeys)
|
||||||
|
for _, key := range dkeys {
|
||||||
|
raw, _, found, err := s.st.get(buckets.DeliveryWaitsState, key)
|
||||||
|
if err != nil || !found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var w deliveryWaiting
|
||||||
|
if json.Unmarshal(raw, &w) != nil || (arg(args, "module") != "" && w.Module != arg(args, "module")) ||
|
||||||
|
(arg(args, "node") != "" && !slices.Contains(w.Machines, arg(args, "node"))) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
delivery = append(delivery, w)
|
||||||
|
}
|
||||||
|
// And each ask of assigner_delivered_again not yet holding, with why (A-250).
|
||||||
|
again := []againAsk{}
|
||||||
|
akeys, err := s.st.keys(buckets.DeliveredAgainState)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the asks to say a version delivered again cannot be listed: %w", err)
|
||||||
|
}
|
||||||
|
sort.Strings(akeys)
|
||||||
|
for _, key := range akeys {
|
||||||
|
raw, _, found, err := s.st.get(buckets.DeliveredAgainState, key)
|
||||||
|
var a againAsk
|
||||||
|
if err != nil || !found || json.Unmarshal(raw, &a) != nil || (arg(args, "module") != "" && a.Module != arg(args, "module")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
again = append(again, a)
|
||||||
|
}
|
||||||
|
return map[string]any{"waits": out, "delivery": delivery, "delivered-again": again}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// toolDeliveredAgain is the tool that asks version-delivered said again for one version (design 47 G §376, A-250).
|
||||||
|
const toolDeliveredAgain = "assigner_delivered_again"
|
||||||
|
|
||||||
|
// doDeliveredAgain is assigner_delivered_again: the hand act is recorded first, then the ask is written into the state
|
||||||
|
// delivered-again, whose watch the assigner's process hears at once; it answers that it is asked.
|
||||||
|
func (s *putTools) doDeliveredAgain(args map[string]any, by string) (any, error) {
|
||||||
|
module, version, why := arg(args, "module"), arg(args, "version"), arg(args, "why")
|
||||||
|
if module == "" || version == "" || why == "" {
|
||||||
|
return nil, errors.New("assigner_delivered_again names the module, its version and why: it is kept in the hand-act log")
|
||||||
|
}
|
||||||
|
rec := meshhandactsclient.Recorder{Ask: s.ask}
|
||||||
|
taken, err := rec.Record(meshhandactsclient.Request{What: fmt.Sprintf("assigner_delivered_again %s %s", module, version), Why: why,
|
||||||
|
Cause: "version-delivered", Verb: "mesh-wants.assigner_delivered_again"})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the hand act could not be recorded, so nothing was asked: %w", err)
|
||||||
|
}
|
||||||
|
data, err := json.Marshal(againAsk{Module: module, Version: version, By: by, Why: why})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := s.st.put(buckets.DeliveredAgainState, keys.EscapeName(module), data); err != nil {
|
||||||
|
return nil, fmt.Errorf("the ask of %s %s is not written: %w", module, version, err)
|
||||||
|
}
|
||||||
|
return map[string]any{"asked": module, "version": version, "hand-act": taken.Log,
|
||||||
|
"follow": "the assigner says version-delivered again once every present machine placing it runs it healthy; assigner_waits says why it does not yet"}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// deliveredAgainTool is assigner_delivered_again as the runtime serves it.
|
||||||
|
func (s *putTools) deliveredAgainTool() stdio.Tool {
|
||||||
|
return stdio.Tool{Name: toolDeliveredAgain, Description: "Say version-delivered again for one version of a module, for the operator and the healers " +
|
||||||
|
"(design 47 G §376): written in the hand-act log first, then asked of the assigner, which says it once every present machine placing " +
|
||||||
|
"the module runs that version healthy; until then assigner_waits lists the ask with why it does not hold. Answers that it is asked.",
|
||||||
|
Input: schema(map[string]string{"module": "the module", "version": "its MAJOR.MINOR.PATCH", "why": "why, kept in the hand-act log"},
|
||||||
|
[]string{"module", "version", "why"}),
|
||||||
|
Run: func(a map[string]any) (any, error) { return s.doDeliveredAgain(a, stdio.CallerOf(a)) }}
|
||||||
|
}
|
||||||
|
|
||||||
|
// doReleaseDelivery is assigner_release with step delivery: the hand act is recorded first, then the release is written on the
|
||||||
|
// module's delivery wait, which the assigner's process ends released at its next pass, writing the module's want.
|
||||||
|
func (s *putTools) doReleaseDelivery(args map[string]any, by string) (any, error) {
|
||||||
|
module, why := arg(args, "module"), arg(args, "why")
|
||||||
|
if why == "" {
|
||||||
|
return nil, errors.New("release says why: it is kept in the hand-act log")
|
||||||
|
}
|
||||||
|
key := keys.EscapeName(module)
|
||||||
|
raw, _, found, err := s.st.get(buckets.DeliveryWaitsState, key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the delivery wait of %s is not read: %w", module, err)
|
||||||
|
}
|
||||||
|
var w deliveryWaiting
|
||||||
|
if !found || json.Unmarshal(raw, &w) != nil || w.Released {
|
||||||
|
return nil, fmt.Errorf("%s waits for no delivery: assigner_waits lists the delivery waits", module)
|
||||||
|
}
|
||||||
|
rec := meshhandactsclient.Recorder{Ask: s.ask}
|
||||||
|
taken, err := rec.Record(meshhandactsclient.Request{What: fmt.Sprintf("assigner_release %s step delivery (waits on %s)", module, w.On), Why: why,
|
||||||
|
Cause: "delivery-wait", Verb: "mesh-wants.assigner_release"})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the hand act could not be recorded, so nothing was released: %w", err)
|
||||||
|
}
|
||||||
|
w.Released, w.By = true, by+": "+why
|
||||||
|
data, err := json.Marshal(w)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := s.st.put(buckets.DeliveryWaitsState, key, data); err != nil {
|
||||||
|
return nil, fmt.Errorf("the release of %s's delivery wait is not written: %w", module, err)
|
||||||
|
}
|
||||||
|
return map[string]any{"released": module, "step": meshwants.WaitStepDelivery, "by": by, "hand-act": taken.Log}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// doReleaseWait is assigner_release with how: the hand act is recorded first, then the release is written on the wait of node and
|
||||||
|
// module, which the assigner's process takes at its next pass.
|
||||||
|
func (s *putTools) doReleaseWait(args map[string]any, by string) (any, error) {
|
||||||
|
node, module, how, why := arg(args, "node"), arg(args, "module"), arg(args, "how"), arg(args, "why")
|
||||||
|
if how == acting.HowNow {
|
||||||
|
return s.doReleaseActing(node, module, why, by)
|
||||||
|
}
|
||||||
|
if !slices.Contains([]string{outside.HowGoOn, outside.HowFailed, outside.HowRejudge}, how) {
|
||||||
|
return nil, fmt.Errorf("how is %s, %s or %s, not %q", outside.HowGoOn, outside.HowFailed, outside.HowRejudge, how)
|
||||||
|
}
|
||||||
|
if why == "" {
|
||||||
|
return nil, errors.New("release says why: it is kept in the hand-act log")
|
||||||
|
}
|
||||||
|
keys, err := s.st.keys(waitsState)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the waits cannot be listed: %w", err)
|
||||||
|
}
|
||||||
|
prefix := node + "." + module + "."
|
||||||
|
var key string
|
||||||
|
var w outside.Wait
|
||||||
|
for _, k := range keys {
|
||||||
|
if !strings.HasPrefix(k, prefix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
raw, _, found, err := s.st.get(waitsState, k)
|
||||||
|
if err != nil || !found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if c, err := outside.Decode(raw); err == nil && c.Decided == "" {
|
||||||
|
key, w = k, c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if key == "" {
|
||||||
|
return nil, fmt.Errorf("%s holds no wait of %s on an outside cause: assigner_waits lists them", node, module)
|
||||||
|
}
|
||||||
|
rec := meshhandactsclient.Recorder{Ask: s.ask}
|
||||||
|
taken, err := rec.Record(meshhandactsclient.Request{What: fmt.Sprintf("assigner_release %s %s %s", node, module, how), Why: why,
|
||||||
|
Cause: "outside-wait", Verb: "mesh-wants.assigner_release"})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the hand act could not be recorded, so nothing was released: %w", err)
|
||||||
|
}
|
||||||
|
w.Release, w.By, w.Why = how, by+": "+why, why
|
||||||
|
data, err := outside.Encode(w)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := s.st.put(waitsState, key, data); err != nil {
|
||||||
|
return nil, fmt.Errorf("the release of %s on %s is not written: %w", module, node, err)
|
||||||
|
}
|
||||||
|
return map[string]any{"released": key, "how": how, "by": by, "hand-act": taken.Log}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// doReleaseActing is assigner_release with how `now`: the entry of module on node moves with its acting parts' running versions. The
|
||||||
|
// hand act is recorded first; the release is written on each standing wait of the entry, and the process says wait-ended at its next pass.
|
||||||
|
func (s *putTools) doReleaseActing(node, module, why, by string) (any, error) {
|
||||||
|
if why == "" {
|
||||||
|
return nil, errors.New("release says why: it is kept in the hand-act log")
|
||||||
|
}
|
||||||
|
keys, err := s.st.keys(waitsState)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the waits cannot be listed: %w", err)
|
||||||
|
}
|
||||||
|
type one struct {
|
||||||
|
key string
|
||||||
|
w acting.Wait
|
||||||
|
}
|
||||||
|
var held []one
|
||||||
|
prefix, orderPrefix := acting.Prefix+node+"."+module+".", acting.OrderPrefix+node+"."+module+"."
|
||||||
|
for _, k := range keys {
|
||||||
|
if !strings.HasPrefix(k, prefix) && !strings.HasPrefix(k, orderPrefix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
raw, _, found, err := s.st.get(waitsState, k)
|
||||||
|
if err != nil || !found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if w, err := acting.Decode(raw); err == nil && !w.Released {
|
||||||
|
held = append(held, one{k, w})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(held) == 0 {
|
||||||
|
return nil, fmt.Errorf("%s holds no wait of %s for an acting part: assigner_waits lists them", node, module)
|
||||||
|
}
|
||||||
|
rec := meshhandactsclient.Recorder{Ask: s.ask}
|
||||||
|
taken, err := rec.Record(meshhandactsclient.Request{What: fmt.Sprintf("assigner_release %s %s %s", node, module, acting.HowNow), Why: why,
|
||||||
|
Cause: "acting-wait", Verb: "mesh-wants.assigner_release"})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the hand act could not be recorded, so nothing was released: %w", err)
|
||||||
|
}
|
||||||
|
released := []string{}
|
||||||
|
for _, h := range held {
|
||||||
|
h.w.Released, h.w.By, h.w.Why = true, by+": "+why, why
|
||||||
|
data, err := acting.Encode(h.w)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := s.st.put(waitsState, h.key, data); err != nil {
|
||||||
|
return nil, fmt.Errorf("the release of %s on %s is not written: %w", module, node, err)
|
||||||
|
}
|
||||||
|
released = append(released, h.key)
|
||||||
|
}
|
||||||
|
return map[string]any{"released": released, "how": acting.HowNow, "by": by, "hand-act": taken.Log}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitsTool is assigner_waits as the runtime serves it.
|
||||||
|
func (s *putTools) waitsTool() stdio.Tool {
|
||||||
|
return stdio.Tool{Name: toolWaits, Description: "Every wait of the delivery and where it stands: an entry waiting for an acting part's new version in composing or placing (§266, §268), with its part, version, step, clock-from and bound; and a moved module's failing health check on a " +
|
||||||
|
"machine whose open conditions name a cause outside the delivery (design 47 G §706), with its module, machine, fingerprint, the " +
|
||||||
|
"condition's key, what it stands `on`, its clock-from, bound, its ask and its state; a settle shows as settling with its end. Narrowed by " +
|
||||||
|
"machine or module. Read-only.",
|
||||||
|
Input: schema(map[string]string{"node": "one machine", "module": "one module"}, nil), Run: s.doWaits}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import plc "mesh-delivery-assigner/internal/assignment"
|
||||||
|
|
||||||
|
// The assigner's tests run as the module its manifest names, as a credential's module would say it at its start (design 47 G A-296).
|
||||||
|
func init() { plc.SetModule("mesh-delivery-assigner") }
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,539 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||||
|
|
||||||
|
mdseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
"mesh-delivery-assigner/internal/assignment"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The pins of the assignment graph revisions (design 47 G §153, §178, §216, §579; A-169): the gate says on the seat
|
||||||
|
// mesh-delivery which revisions a delivery record starts (`pinned`) and stops (`freed`) pointing at, and once at each of its
|
||||||
|
// starts `pins-stated`. The assigner hears them on its durable consumer of the events stream and keeps, in its old `state`
|
||||||
|
// section `pins` (4 MiB), one key `trunk.<n>` per assignment graph revision whose value is the list of the records pinning
|
||||||
|
// it, added or removed by compare-and-set before the event is acknowledged; a record heard twice pins once. Two more keys:
|
||||||
|
// `made`, written once when the state is first used, and `pins-stated`, the `at` of the last pins-stated applied. A revision
|
||||||
|
// is removed, its object and its key and the entry objects no kept revision lists and no want or running build names
|
||||||
|
// (§179), when its list is empty and it is not current (the newest the assigner wrote), only while the consumer is caught up
|
||||||
|
// and once a pins-stated said after `made` was applied; judged on a freed, on a revision ceasing to be current, on being
|
||||||
|
// caught up, and at start once both hold. Never on a timer, and never by reading the gate's state.
|
||||||
|
|
||||||
|
const (
|
||||||
|
pinsState = "pins"
|
||||||
|
pinsTool = "assigner_pins"
|
||||||
|
unpinTool = "assigner_unpin"
|
||||||
|
pinsMadeKey = "made"
|
||||||
|
pinsStatedKey = "pins-stated"
|
||||||
|
pinsCapBytes = 4 << 20
|
||||||
|
pinMissingKind = "pin-missing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PinsValue is one value of the state pins: the records that pin the revision, and whether the revision was no longer held
|
||||||
|
// when a record pinned it.
|
||||||
|
type PinsValue struct {
|
||||||
|
Records []string `json:"records"`
|
||||||
|
Missing bool `json:"missing,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// pinKey is the key of an assignment graph revision, its object's own name (A-169).
|
||||||
|
func pinKey(revision int64) string { return assigngraph.TrunkObject(revision) }
|
||||||
|
|
||||||
|
// pinRevision is the revision a key of the state names, and whether it names one.
|
||||||
|
func pinRevision(key string) (int64, bool) {
|
||||||
|
n, ok := strings.CutPrefix(key, "trunk.")
|
||||||
|
if !ok {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
r, err := strconv.ParseInt(n, 10, 64)
|
||||||
|
return r, err == nil && r > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// pinObjects is the object bucket of the revisions as the pins remove from it.
|
||||||
|
type pinObjects interface {
|
||||||
|
assigngraph.Objects
|
||||||
|
Delete(ctx context.Context, name string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// pinKeeper keeps the pins and removes what nothing pins.
|
||||||
|
type pinKeeper struct {
|
||||||
|
ctx context.Context
|
||||||
|
st endStore
|
||||||
|
objects pinObjects
|
||||||
|
// inUse says a want or a running build names the module's fingerprint (§179).
|
||||||
|
inUse func(module, fp string) bool
|
||||||
|
findings assign.Findings
|
||||||
|
now func() time.Time
|
||||||
|
logf func(string, ...any)
|
||||||
|
mu sync.Mutex
|
||||||
|
// caught is whether the last event applied left none of the consumer's messages pending.
|
||||||
|
caught bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// edit applies change to the value at key by compare-and-set, again while another write comes between.
|
||||||
|
func (k *pinKeeper) edit(key string, change func(v PinsValue, found bool) (PinsValue, bool)) error {
|
||||||
|
for {
|
||||||
|
raw, rev, err := k.st.get(key)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var v PinsValue
|
||||||
|
if raw != nil {
|
||||||
|
if err := json.Unmarshal(raw, &v); err != nil {
|
||||||
|
return fmt.Errorf("the pins of %s do not read: %w", key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next, write := change(v, raw != nil)
|
||||||
|
if !write {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
value, _ := json.Marshal(next)
|
||||||
|
if err := k.st.swap(key, value, rev); errors.Is(err, errSwapped) {
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// held says the revision's object is kept.
|
||||||
|
func (k *pinKeeper) held(revision int64) (bool, error) {
|
||||||
|
_, err := k.objects.Get(k.ctx, assigngraph.TrunkObject(revision))
|
||||||
|
if errors.Is(err, assigngraph.ErrNoObject) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return err == nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// pin adds record to each assignment graph revision of p; a revision no longer held is written missing, with the finding
|
||||||
|
// pin-missing naming the record.
|
||||||
|
func (k *pinKeeper) pin(p mdseat.Pins) error {
|
||||||
|
for _, r := range p.Assignment {
|
||||||
|
held, err := k.held(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = k.edit(pinKey(r), func(v PinsValue, _ bool) (PinsValue, bool) {
|
||||||
|
if slices.Contains(v.Records, p.Record) && (held || v.Missing) {
|
||||||
|
return v, false
|
||||||
|
}
|
||||||
|
if !slices.Contains(v.Records, p.Record) {
|
||||||
|
v.Records = append(v.Records, p.Record)
|
||||||
|
slices.Sort(v.Records)
|
||||||
|
}
|
||||||
|
v.Missing = v.Missing || !held
|
||||||
|
return v, true
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !held {
|
||||||
|
k.missing(r, p.Record)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// free removes record from each assignment graph revision of p; a freed applied twice changes nothing.
|
||||||
|
func (k *pinKeeper) free(p mdseat.Pins) error {
|
||||||
|
for _, r := range p.Assignment {
|
||||||
|
err := k.edit(pinKey(r), func(v PinsValue, found bool) (PinsValue, bool) {
|
||||||
|
i := slices.Index(v.Records, p.Record)
|
||||||
|
if !found || i < 0 {
|
||||||
|
return v, false
|
||||||
|
}
|
||||||
|
v.Records = slices.Delete(v.Records, i, i+1)
|
||||||
|
return v, true
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// missing writes the finding pin-missing, scope the assigner, id the revision.
|
||||||
|
func (k *pinKeeper) missing(revision int64, record string) {
|
||||||
|
if k.findings.Put == nil {
|
||||||
|
k.logf("the revision %d the record %s pins is not held, and no finding writer is wired to say so", revision, record)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
o := assign.Observed{Scope: assignment.Module(), ID: strconv.FormatInt(revision, 10), Kind: pinMissingKind,
|
||||||
|
Summary: fmt.Sprintf("the delivery record %s pins the assignment graph revision %d, which the assigner no longer holds", record, revision),
|
||||||
|
Headline: "A delivery record pins a revision the assigner no longer holds",
|
||||||
|
Explanation: fmt.Sprintf("The record %s pinned revision %d after it was removed; %s clears it.", record, revision, unpinTool),
|
||||||
|
Source: assignment.Module()}
|
||||||
|
if err := k.findings.Put(o.Finding(k.now())); err != nil {
|
||||||
|
k.logf("the finding %s of revision %d is not written: %v", pinMissingKind, revision, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// made writes the key made once, create-only; one there already stays.
|
||||||
|
func (k *pinKeeper) made() error {
|
||||||
|
raw, _, err := k.st.get(pinsMadeKey)
|
||||||
|
if err != nil || raw != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
value, _ := json.Marshal(k.now().UTC())
|
||||||
|
if err := k.st.swap(pinsMadeKey, value, 0); err != nil && !errors.Is(err, errSwapped) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// timeAt is the time a key holds; false when it holds none.
|
||||||
|
func (k *pinKeeper) timeAt(key string) (time.Time, bool, error) {
|
||||||
|
raw, _, err := k.st.get(key)
|
||||||
|
if err != nil || raw == nil {
|
||||||
|
return time.Time{}, false, err
|
||||||
|
}
|
||||||
|
var t time.Time
|
||||||
|
if err := json.Unmarshal(raw, &t); err != nil {
|
||||||
|
return t, false, fmt.Errorf("the key %s does not read: %w", key, err)
|
||||||
|
}
|
||||||
|
return t, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// stated keeps the at of a pins-stated applied.
|
||||||
|
func (k *pinKeeper) stated(at time.Time) error {
|
||||||
|
for {
|
||||||
|
raw, rev, err := k.st.get(pinsStatedKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var was time.Time
|
||||||
|
if raw != nil && json.Unmarshal(raw, &was) == nil && !at.After(was) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
value, _ := json.Marshal(at.UTC())
|
||||||
|
if err := k.st.swap(pinsStatedKey, value, rev); errors.Is(err, errSwapped) {
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// statedSinceMade says a pins-stated said after the state was made was applied.
|
||||||
|
func (k *pinKeeper) statedSinceMade() (bool, error) {
|
||||||
|
made, ok, err := k.timeAt(pinsMadeKey)
|
||||||
|
if err != nil || !ok {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
at, ok, err := k.timeAt(pinsStatedKey)
|
||||||
|
if err != nil || !ok {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return at.After(made), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// hear applies one of the seat mesh-delivery's events and acknowledges it only once applied.
|
||||||
|
func (k *pinKeeper) hear(m jetstream.Msg) {
|
||||||
|
err := k.apply(m.Subject(), m.Data())
|
||||||
|
if err != nil {
|
||||||
|
k.logf("%s: %v; it is heard again", m.Subject(), err)
|
||||||
|
_ = m.Nak()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_ = m.Ack()
|
||||||
|
caught := false
|
||||||
|
if meta, merr := m.Metadata(); merr == nil {
|
||||||
|
caught = meta.NumPending == 0
|
||||||
|
}
|
||||||
|
k.mu.Lock()
|
||||||
|
was := k.caught
|
||||||
|
k.caught = caught
|
||||||
|
k.mu.Unlock()
|
||||||
|
if caught && (!was || m.Subject() != mdseat.SubjectPinned) {
|
||||||
|
k.judge() // on a freed, on a candidate's heads replaced, on pins-stated, and on being caught up
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply takes one event's body.
|
||||||
|
func (k *pinKeeper) apply(subject string, data []byte) error {
|
||||||
|
switch subject {
|
||||||
|
case mdseat.SubjectPinned, mdseat.SubjectFreed:
|
||||||
|
var p mdseat.Pins
|
||||||
|
if err := json.Unmarshal(data, &p); err != nil || p.Record == "" {
|
||||||
|
k.logf("%s holds no pins naming a record, and is not taken: %v", subject, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if subject == mdseat.SubjectPinned {
|
||||||
|
return k.pin(p)
|
||||||
|
}
|
||||||
|
return k.free(p)
|
||||||
|
case mdseat.SubjectPinsStated:
|
||||||
|
var s mdseat.PinsStatedEvent
|
||||||
|
if err := json.Unmarshal(data, &s); err != nil || s.At.IsZero() {
|
||||||
|
k.logf("%s holds no at, and is not taken: %v", subject, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return k.stated(s.At)
|
||||||
|
}
|
||||||
|
return nil // heads-replaced: a candidate's revision stops being current, judged after
|
||||||
|
}
|
||||||
|
|
||||||
|
// judge removes every revision neither pinned nor current, when the rule allows a removal at all.
|
||||||
|
func (k *pinKeeper) judge() {
|
||||||
|
k.mu.Lock()
|
||||||
|
caught := k.caught
|
||||||
|
k.mu.Unlock()
|
||||||
|
if !caught {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ok, err := k.statedSinceMade()
|
||||||
|
if err != nil {
|
||||||
|
k.logf("the pins are not judged: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return // no pins-stated applied since the state was made: a pin said before may not be heard yet
|
||||||
|
}
|
||||||
|
if err := k.remove(); err != nil {
|
||||||
|
k.logf("the revisions nothing pins are not removed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove removes each kept revision that is not current and that no record pins, and then the entries left unlisted.
|
||||||
|
func (k *pinKeeper) remove() error {
|
||||||
|
names, err := k.objects.Names(k.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var kept []int64
|
||||||
|
for _, n := range names {
|
||||||
|
if r, ok := pinRevision(n); ok {
|
||||||
|
kept = append(kept, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(kept) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
current := slices.Max(kept)
|
||||||
|
listed := map[string]bool{}
|
||||||
|
removed := 0
|
||||||
|
for _, r := range kept {
|
||||||
|
raw, _, err := k.st.get(pinKey(r))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var v PinsValue
|
||||||
|
if raw != nil {
|
||||||
|
if err := json.Unmarshal(raw, &v); err != nil {
|
||||||
|
return fmt.Errorf("the pins of %d do not read: %w", r, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if r == current || len(v.Records) > 0 {
|
||||||
|
rev, err := assigngraph.ReadRevision(k.ctx, k.objects, r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, e := range rev.Entries {
|
||||||
|
listed[e.Digest] = true
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := k.objects.Delete(k.ctx, assigngraph.TrunkObject(r)); err != nil {
|
||||||
|
return fmt.Errorf("revision %d: %w", r, err)
|
||||||
|
}
|
||||||
|
if raw != nil {
|
||||||
|
if err := k.st.drop(pinKey(r)); err != nil {
|
||||||
|
return fmt.Errorf("the pins of %d: %w", r, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
removed++
|
||||||
|
}
|
||||||
|
if removed == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// A run's candidate kept now lists its entries too, until its group-ended drops it (A-201, A-235).
|
||||||
|
for _, n := range names {
|
||||||
|
group, heads, ok := meshwants.ParseAssignmentRevisionsByCandidateGroupHeadsKey(n)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
rev, err := assigngraph.ReadCandidate(k.ctx, k.objects, group, heads)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, e := range rev.Entries {
|
||||||
|
listed[e.Digest] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, n := range names {
|
||||||
|
digest, ok := strings.CutPrefix(n, "entry.")
|
||||||
|
if !ok || listed[digest] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
e, err := assigngraph.ReadEntry(k.ctx, k.objects, digest)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if k.inUse != nil && k.inUse(e.Module, e.Fp) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := k.objects.Delete(k.ctx, n); err != nil {
|
||||||
|
return fmt.Errorf("the entry %s: %w", digest, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
k.logf("%d assignment graph revisions no record pins and not current are removed", removed)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearPins registers the seat mesh-delivery's four events on the assigner's hub.
|
||||||
|
func hearPins(hub *process.EventHub, k *pinKeeper) error {
|
||||||
|
for _, s := range []string{mdseat.SubjectPinned, mdseat.SubjectFreed, mdseat.SubjectHeadsReplaced, mdseat.SubjectPinsStated} {
|
||||||
|
if err := hub.Handle(s, k.hear); err != nil {
|
||||||
|
return fmt.Errorf("%s: %w", s, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// pinsTools are assigner_pins and assigner_unpin over the runtime's states.
|
||||||
|
func pinsTools(st store, ask func(string, any) (json.RawMessage, error)) []stdio.Tool {
|
||||||
|
return []stdio.Tool{{Name: pinsTool, Description: "the assignment graph revisions the delivery records pin (design 47 G §579): per revision " +
|
||||||
|
"the records that pin it and whether it was missing when pinned, the newest revision kept (current, never removed), when the state " +
|
||||||
|
"was made, the last pins-stated applied, and the state's fill against its cap of 4 MiB.",
|
||||||
|
Run: func(map[string]any) (any, error) { return readPins(st) }},
|
||||||
|
{Name: unpinTool, Description: "Remove one record from a revision's pins, for a freed that was lost (design 47 G §579); written in the " +
|
||||||
|
"hand-act log first. The removal rule then applies.",
|
||||||
|
Input: schema(map[string]string{"revision": "the assignment graph revision's number", "record": "the delivery record's id",
|
||||||
|
"why": "why it is removed by hand"}, []string{"revision", "record", "why"}),
|
||||||
|
Run: func(a map[string]any) (any, error) {
|
||||||
|
record, _ := a["record"].(string)
|
||||||
|
why, _ := a["why"].(string)
|
||||||
|
return unpin(st, ask, fmt.Sprint(a["revision"]), record, why, stdio.CallerOf(a))
|
||||||
|
}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// readPins is what assigner_pins answers.
|
||||||
|
func readPins(st store) (any, error) {
|
||||||
|
ks, err := st.keys(pinsState)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sort.Strings(ks)
|
||||||
|
revisions := map[string]PinsValue{}
|
||||||
|
out := map[string]any{"revisions": revisions}
|
||||||
|
var newest int64
|
||||||
|
bytes := 0
|
||||||
|
for _, key := range ks {
|
||||||
|
raw, _, found, err := st.get(pinsState, key)
|
||||||
|
if err != nil || !found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
bytes += len(key) + len(raw)
|
||||||
|
if r, ok := pinRevision(key); ok {
|
||||||
|
var v PinsValue
|
||||||
|
if json.Unmarshal(raw, &v) == nil {
|
||||||
|
revisions[key] = v
|
||||||
|
}
|
||||||
|
newest = max(newest, r)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out[key] = json.RawMessage(raw)
|
||||||
|
}
|
||||||
|
out["fill"] = meshwants.Fill{Store: pinsState, Bytes: int64(bytes), Cap: pinsCapBytes}
|
||||||
|
if newest > 0 {
|
||||||
|
out["newest-pinned"] = newest
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// unpin removes one record from one revision's list, the hand act recorded first.
|
||||||
|
func unpin(st store, ask func(string, any) (json.RawMessage, error), revision, record, why, by string) (any, error) {
|
||||||
|
r, err := strconv.ParseInt(strings.TrimPrefix(revision, "trunk."), 10, 64)
|
||||||
|
switch {
|
||||||
|
case err != nil || r <= 0:
|
||||||
|
return nil, fmt.Errorf("revision %q is no assignment graph revision's number", revision)
|
||||||
|
case record == "" || why == "":
|
||||||
|
return nil, errors.New("name the record and say why")
|
||||||
|
case by == "" || by == stdio.Unproven:
|
||||||
|
return nil, errors.New("an unpin names who asks it, and the runtime proved no caller")
|
||||||
|
}
|
||||||
|
key := pinKey(r)
|
||||||
|
raw, _, found, err := st.get(pinsState, key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var v PinsValue
|
||||||
|
if found {
|
||||||
|
if err := json.Unmarshal(raw, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i := slices.Index(v.Records, record)
|
||||||
|
if i < 0 {
|
||||||
|
return nil, fmt.Errorf("the record %s does not pin revision %d: %s lists its pins", record, r, pinsTool)
|
||||||
|
}
|
||||||
|
taken, err := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: unpinTool + " " + key + " " + record,
|
||||||
|
Why: why + " (" + by + ")", Cause: "unpin"})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("the hand act is not recorded, so nothing is removed: %w", err)
|
||||||
|
}
|
||||||
|
v.Records = slices.Delete(v.Records, i, i+1)
|
||||||
|
value, _ := json.Marshal(v)
|
||||||
|
if err := st.put(pinsState, key, value); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return map[string]any{"revision": r, "unpinned": record, "records": v.Records, "hand-act": taken.Log}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// watchUnpins judges again when a revision's pins change in the state itself, as assigner_unpin writes them from the tool
|
||||||
|
// process: the assigner's own state, heard as it changes, never on a timer.
|
||||||
|
func (k *pinKeeper) watchUnpins(kv jetstream.KeyValue) {
|
||||||
|
w, err := kv.WatchAll(k.ctx, jetstream.UpdatesOnly())
|
||||||
|
if err != nil {
|
||||||
|
k.logf("the state %s is not watched, so a hand unpin is judged at the next freed or revision: %v", pinsState, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
defer func() { _ = w.Stop() }()
|
||||||
|
for e := range w.Updates() {
|
||||||
|
if e == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := pinRevision(e.Key()); ok && e.Operation() == jetstream.KeyValuePut {
|
||||||
|
k.judge()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// inUseOf says a want or a running build names the module's fingerprint, as the world holds them now.
|
||||||
|
func inUseOf(w *world) func(module, fp string) bool {
|
||||||
|
return func(module, fp string) bool {
|
||||||
|
for _, want := range w.wantsOf()[module] {
|
||||||
|
if want.Fp == fp {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, mods := range w.runningNow() {
|
||||||
|
if r, ok := mods[module]; ok && r.Fingerprint == fp {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func pinsBucket() string { return assignment.Module() + "_" + pinsState }
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||||
|
mdseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/assign"
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m memObjects) Delete(_ context.Context, name string) error { delete(m, name); return nil }
|
||||||
|
|
||||||
|
// The pins of the assignment graph revisions (design 47 G §153, §178, §579; A-169): a revision two records pin stays until
|
||||||
|
// both free it; a record pinning twice pins once; the current revision is never removed; nothing is removed before a
|
||||||
|
// pins-stated said after the state was made, nor while the consumer is behind; a revision no longer held is pinned missing,
|
||||||
|
// with the finding pin-missing; an entry another kept revision lists, or a want or a running build names, stays.
|
||||||
|
func TestPinsKeepARevisionWhileARecordPinsIt(t *testing.T) {
|
||||||
|
objects := memObjects{}
|
||||||
|
entry := func(module, fp string) string {
|
||||||
|
e := meshwants.AssignmentEntry{Node: "n1", Module: module, Fp: fp}
|
||||||
|
d := assigngraph.EntryDigest(e)
|
||||||
|
raw, _ := json.Marshal(e)
|
||||||
|
objects[assigngraph.EntryObject(d)] = raw
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
shared, old, running := entry("a", "fp-a"), entry("b", "fp-b1"), entry("c", "fp-c1")
|
||||||
|
revision := func(n int64, digests ...string) {
|
||||||
|
rev := meshwants.AssignmentRevision{Revision: n}
|
||||||
|
for _, d := range digests {
|
||||||
|
rev.Entries = append(rev.Entries, meshwants.NodeEntryRef{Node: "n1", Digest: d})
|
||||||
|
}
|
||||||
|
raw, _ := json.Marshal(rev)
|
||||||
|
objects[assigngraph.TrunkObject(n)] = raw
|
||||||
|
}
|
||||||
|
// A run's candidate lists an entry no trunk revision lists (A-201): it stays while the candidate is kept.
|
||||||
|
cand := entry("d", "fp-d2")
|
||||||
|
candRaw, _ := json.Marshal(meshwants.AssignmentRevision{Revision: 1, Kind: "candidate", Group: "run-7", Heads: "h1",
|
||||||
|
Entries: []meshwants.NodeEntryRef{{Node: "n1", Module: "d", Digest: cand}}})
|
||||||
|
objects[assigngraph.CandidateObject("run-7", "h1")] = candRaw
|
||||||
|
revision(1, shared, old, running)
|
||||||
|
revision(2, shared, old)
|
||||||
|
revision(3, shared)
|
||||||
|
var found []mcseat.Finding
|
||||||
|
clock := time.Date(2026, 11, 12, 10, 0, 0, 0, time.UTC)
|
||||||
|
k := &pinKeeper{ctx: context.Background(), st: newMemEnds(), objects: objects, now: func() time.Time { return clock },
|
||||||
|
logf: t.Logf,
|
||||||
|
inUse: func(module, fp string) bool { return module == "c" && fp == "fp-c1" },
|
||||||
|
findings: assign.Findings{Put: func(f mcseat.Finding) error { found = append(found, f); return nil }}}
|
||||||
|
if err := k.made(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
say := func(subject string, body any) {
|
||||||
|
t.Helper()
|
||||||
|
raw, _ := json.Marshal(body)
|
||||||
|
if err := k.apply(subject, raw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
k.judge()
|
||||||
|
}
|
||||||
|
pins := func(record string, revs ...int64) mdseat.Pins { return mdseat.Pins{Record: record, Assignment: revs} }
|
||||||
|
has := func(n int64) bool { _, ok := objects[assigngraph.TrunkObject(n)]; return ok }
|
||||||
|
|
||||||
|
k.caught = true
|
||||||
|
say(mdseat.SubjectPinned, pins("r1", 1))
|
||||||
|
say(mdseat.SubjectPinned, pins("r1", 1))
|
||||||
|
say(mdseat.SubjectPinned, pins("r2", 1))
|
||||||
|
say(mdseat.SubjectFreed, pins("r9", 2)) // nothing pins 2, but no pins-stated since made: nothing removed
|
||||||
|
if !has(2) {
|
||||||
|
t.Fatal("revision 2 was removed before a pins-stated said after the state was made")
|
||||||
|
}
|
||||||
|
k.caught = false
|
||||||
|
say(mdseat.SubjectPinsStated, mdseat.PinsStatedEvent{At: clock.Add(time.Minute)})
|
||||||
|
if !has(2) {
|
||||||
|
t.Fatal("revision 2 was removed while the consumer was behind")
|
||||||
|
}
|
||||||
|
k.caught = true
|
||||||
|
say(mdseat.SubjectFreed, pins("r1", 1))
|
||||||
|
if has(2) {
|
||||||
|
t.Error("revision 2, neither pinned nor current, is kept")
|
||||||
|
}
|
||||||
|
if !has(1) || !has(3) {
|
||||||
|
t.Error("revision 1 (pinned by r2) or 3 (current) was removed")
|
||||||
|
}
|
||||||
|
raw, _, _ := k.st.get(pinKey(1))
|
||||||
|
if string(raw) != `{"records":["r2"]}` {
|
||||||
|
t.Errorf("the pins of 1 = %s, want r2 alone (r1 pinned twice pins once, and freed once)", raw)
|
||||||
|
}
|
||||||
|
say(mdseat.SubjectFreed, pins("r2", 1))
|
||||||
|
if has(1) {
|
||||||
|
t.Error("revision 1 is kept once both records freed it")
|
||||||
|
}
|
||||||
|
if _, ok := objects[assigngraph.EntryObject(old)]; ok {
|
||||||
|
t.Error("the entry no kept revision lists and nothing names is kept")
|
||||||
|
}
|
||||||
|
if _, ok := objects[assigngraph.EntryObject(running)]; !ok {
|
||||||
|
t.Error("the entry of a running build is removed")
|
||||||
|
}
|
||||||
|
if _, ok := objects[assigngraph.EntryObject(shared)]; !ok {
|
||||||
|
t.Error("the entry the current revision lists is removed")
|
||||||
|
}
|
||||||
|
if _, ok := objects[assigngraph.EntryObject(cand)]; !ok {
|
||||||
|
t.Error("the entry a run's kept candidate lists is removed")
|
||||||
|
}
|
||||||
|
say(mdseat.SubjectHeadsReplaced, mdseat.HeadsReplacedEvent{})
|
||||||
|
if _, ok := objects[assigngraph.CandidateObject("run-7", "h1")]; !ok {
|
||||||
|
t.Error("the gate's heads-replaced dropped a run's candidate")
|
||||||
|
}
|
||||||
|
say(mdseat.SubjectPinned, pins("r3", 2))
|
||||||
|
raw, _, _ = k.st.get(pinKey(2))
|
||||||
|
if string(raw) != `{"records":["r3"],"missing":true}` || len(found) != 1 || found[0].Kind != pinMissingKind || found[0].ID != "2" {
|
||||||
|
t.Errorf("a pin of a revision no longer held = %s, findings %+v", raw, found)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,504 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
mprc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshpipelinerunnerclient"
|
||||||
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
|
mpcat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||||
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The wants follow a passed pipeline (design 47 G §29, §35, §325, §352): the runner says each pipeline's end as
|
||||||
|
// pipeline-ended, and a group's as group-ended. The assigner keeps, in its old state `written`, one key per module and
|
||||||
|
// watched branch: the source revision and end count of the newest end it heard for it, and whether the wants were written
|
||||||
|
// from it. A newer end replaces it by compare-and-set; an older one, or the same one again, writes nothing.
|
||||||
|
|
||||||
|
// writtenState is the assigner's state of the pipeline ends its wants follow; writtenTool reads it.
|
||||||
|
const (
|
||||||
|
writtenState = "written"
|
||||||
|
writtenTool = "assigner_written"
|
||||||
|
)
|
||||||
|
|
||||||
|
// pipelineEndedSubject and groupEndedSubject are the runner's events the assigner consumes.
|
||||||
|
const (
|
||||||
|
pipelineEndedSubject = "mesh.seat." + mpr.Seat + ".event." + mpr.EventPipelineEnded + ".>"
|
||||||
|
groupEndedSubject = "mesh.seat." + mpr.Seat + ".event." + mpr.EventGroupEnded + ".>"
|
||||||
|
)
|
||||||
|
|
||||||
|
// End is one value of the state written: the newest end of a module's pipeline on a watched branch.
|
||||||
|
type End struct {
|
||||||
|
Source int64 `json:"source"`
|
||||||
|
EndCount int64 `json:"end-count"`
|
||||||
|
Fp string `json:"fp"`
|
||||||
|
Commit string `json:"commit,omitempty"`
|
||||||
|
// Passed: the pipeline ended passed, every required step passed (and, for a group, the group ended passed).
|
||||||
|
Passed bool `json:"passed"`
|
||||||
|
// Written: the wants were written from this end.
|
||||||
|
Written bool `json:"written,omitempty"`
|
||||||
|
Why string `json:"why,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// endKey is the key of a module on a watched branch, each name escaped as a key's name is.
|
||||||
|
func endKey(module, branch string) string {
|
||||||
|
return keys.EscapeName(module) + "." + keys.EscapeName(branch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// newer says whether an end of (source, count) replaces the one kept: a later source revision, or the same one ended again.
|
||||||
|
func (e End) newer(source, count int64) bool {
|
||||||
|
return source > e.Source || (source == e.Source && count > e.EndCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// requiredPassed says whether no required step of a pipeline stands failed, unasked or unended (design 47 G §30: a failed
|
||||||
|
// optional step holds nothing).
|
||||||
|
func requiredPassed(p mpr.PipelineEnded) bool {
|
||||||
|
for _, s := range p.Steps {
|
||||||
|
if s.Status != mpr.StepResultStatusRequired {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch s.Outcome {
|
||||||
|
case mpr.StepResultOutcomeFailed, mpr.StepResultOutcomeCouldNotRun, mpr.StepResultOutcomeDeclined, mpr.StepResultOutcomeNotAsked,
|
||||||
|
mpr.StepResultOutcomeCancelled, mpr.StepResultOutcomeSuperseded, mpr.StepResultOutcomeDidNotBuild,
|
||||||
|
mpr.StepResultOutcomeRunning, mpr.StepResultOutcomeWaiting, mpr.StepResultOutcomeWaitingForABuildNode:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p.Outcome == mpr.PipelineEndedOutcomePassed
|
||||||
|
}
|
||||||
|
|
||||||
|
// endStore is the kept state written: the bus bucket, or a test's.
|
||||||
|
type endStore interface {
|
||||||
|
// get is a key's value and revision; none for a key not there.
|
||||||
|
get(key string) (value []byte, revision uint64, err error)
|
||||||
|
// swap writes value at key if the key stands at revision (0: if it does not stand); errSwapped when it does not.
|
||||||
|
swap(key string, value []byte, revision uint64) error
|
||||||
|
// keys are the keys that stand, and drop deletes one.
|
||||||
|
keys() ([]string, error)
|
||||||
|
drop(key string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
var errSwapped = errors.New("the key changed")
|
||||||
|
|
||||||
|
// kvEnds is endStore over a bus bucket.
|
||||||
|
type kvEnds struct {
|
||||||
|
ctx context.Context
|
||||||
|
kv jetstream.KeyValue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k kvEnds) get(key string) ([]byte, uint64, error) {
|
||||||
|
e, err := k.kv.Get(k.ctx, key)
|
||||||
|
if errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||||
|
return nil, 0, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
return e.Value(), e.Revision(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k kvEnds) swap(key string, value []byte, revision uint64) error {
|
||||||
|
var err error
|
||||||
|
if revision == 0 {
|
||||||
|
_, err = k.kv.Create(k.ctx, key, value)
|
||||||
|
} else {
|
||||||
|
_, err = k.kv.Update(k.ctx, key, value, revision)
|
||||||
|
}
|
||||||
|
if errors.Is(err, jetstream.ErrKeyExists) || (err != nil && isWrongSequence(err)) {
|
||||||
|
return errSwapped
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k kvEnds) keys() ([]string, error) {
|
||||||
|
ks, err := k.kv.Keys(k.ctx)
|
||||||
|
if errors.Is(err, jetstream.ErrNoKeysFound) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return ks, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k kvEnds) drop(key string) error { return k.kv.Delete(k.ctx, key) }
|
||||||
|
|
||||||
|
func isWrongSequence(err error) bool {
|
||||||
|
var ae *jetstream.APIError
|
||||||
|
return errors.As(err, &ae) && ae.ErrorCode == jetstream.JSErrCodeStreamWrongLastSequence
|
||||||
|
}
|
||||||
|
|
||||||
|
// pipelineEnds follows the runner's ends. A nil *pipelineEnds is the trunk-only want, kept until the first registrations
|
||||||
|
// (design 47 G §95, §353).
|
||||||
|
type pipelineEnds struct {
|
||||||
|
st endStore
|
||||||
|
wake func()
|
||||||
|
logf func(string, ...any)
|
||||||
|
// on is whether the wants follow the ends: set by the first registration heard, never before (design 47 G §95, §353).
|
||||||
|
on atomic.Bool
|
||||||
|
mu sync.Mutex
|
||||||
|
// firsts is, by module, the first watched branch of its registration, the branch of a placement that names none (design
|
||||||
|
// 47 G §14).
|
||||||
|
firsts map[string]string
|
||||||
|
// runEnded is told a run on request's group-ended, its group `run-<id>`, to drop the run's candidate (A-235); nil drops nothing.
|
||||||
|
runEnded func(group string) error
|
||||||
|
// left is told the key of a pipeline ended superseded or cancelled, whose composition steps leave the runs they read
|
||||||
|
// (design 47 G §723, A-469n); none tells nothing. Set once the composition steps are served, after the hub starts.
|
||||||
|
left atomic.Pointer[func(pipeline string) error]
|
||||||
|
// onBranches is told the branches a registration names, for the catalog half of each to be followed (design 47 G §14, §195).
|
||||||
|
onBranches func([]string)
|
||||||
|
// trunk names the first watched branch, the trunk's (design 47 G §507), the branch of a module registered with none.
|
||||||
|
trunk func() string
|
||||||
|
// runner is the module holding the seat mesh-pipeline-runner, as the last pass read it from the acting edges (A-334); nil
|
||||||
|
// until a pass read the graph.
|
||||||
|
runner atomic.Pointer[string]
|
||||||
|
// held are the group members' pipeline-ended heard before a pass read the graph, by their body: unacknowledged, so the
|
||||||
|
// bus keeps them, and taken once the runner is read (A-334), never dropped for the runner not being known yet.
|
||||||
|
held map[string]jetstream.Msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// setRunner keeps the module holding the seat mesh-pipeline-runner, read by the pass from the acting edges (A-334); the
|
||||||
|
// first one takes the group members' ends held until the graph was read.
|
||||||
|
func (e *pipelineEnds) setRunner(module string) {
|
||||||
|
e.mu.Lock()
|
||||||
|
first := e.runner.Swap(&module) == nil
|
||||||
|
held := e.held
|
||||||
|
e.held = nil
|
||||||
|
e.mu.Unlock()
|
||||||
|
if !first {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, m := range held {
|
||||||
|
e.hearPipeline(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// holdUntilRead keeps m, a group member's pipeline-ended, until a pass reads the runner from the graph; false when the
|
||||||
|
// runner is read already, so m is taken now.
|
||||||
|
func (e *pipelineEnds) holdUntilRead(m jetstream.Msg) bool {
|
||||||
|
e.mu.Lock()
|
||||||
|
defer e.mu.Unlock()
|
||||||
|
if e.runner.Load() != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if e.held == nil {
|
||||||
|
e.held = map[string]jetstream.Msg{}
|
||||||
|
}
|
||||||
|
e.held[string(m.Data())] = m
|
||||||
|
e.logf("%s is a group member's end heard before the assignment graph is read: held until a pass reads which module is the runner (A-334)", m.Subject())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// isRunner says whether module holds the seat mesh-pipeline-runner, as the last pass read it.
|
||||||
|
func (e *pipelineEnds) isRunner(module string) bool {
|
||||||
|
r := e.runner.Load()
|
||||||
|
return r != nil && *r != "" && *r == module
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPipelineEnds(st endStore, wake func(), logf func(string, ...any)) *pipelineEnds {
|
||||||
|
return &pipelineEnds{st: st, wake: wake, logf: logf, firsts: map[string]string{}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// take keeps one pipeline's end if it is newer than the one kept for its module and branch, by compare-and-set.
|
||||||
|
func (e *pipelineEnds) take(p mpr.PipelineEnded, passed bool) error {
|
||||||
|
key := endKey(p.Module, p.Branch)
|
||||||
|
for {
|
||||||
|
raw, rev, err := e.st.get(key)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if raw != nil {
|
||||||
|
var kept End
|
||||||
|
if err := json.Unmarshal(raw, &kept); err == nil && !kept.newer(p.Source, p.EndCount) {
|
||||||
|
return nil // an older end, or this one again
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end := End{Source: p.Source, EndCount: p.EndCount, Fp: p.Fingerprint, Commit: p.Commit, Passed: passed, Why: p.Why}
|
||||||
|
value, err := json.Marshal(end)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := e.st.swap(key, value, rev); errors.Is(err, errSwapped) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
e.wake()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// markWritten says the wants of module on branch were written from the end it keeps, if that is still the end of fp.
|
||||||
|
func (e *pipelineEnds) markWritten(module, branch, fp string) {
|
||||||
|
key := endKey(module, branch)
|
||||||
|
for {
|
||||||
|
raw, rev, err := e.st.get(key)
|
||||||
|
var kept End
|
||||||
|
if err != nil || raw == nil || json.Unmarshal(raw, &kept) != nil || kept.Fp != fp || kept.Written {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
kept.Written = true
|
||||||
|
value, _ := json.Marshal(kept)
|
||||||
|
if err := e.st.swap(key, value, rev); errors.Is(err, errSwapped) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
e.logf("the end of %s on %s is not marked written: %v", module, branch, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// passedAt says whether the newest end kept for module on branch passed at fp.
|
||||||
|
func (e *pipelineEnds) passedAt(module, branch, fp string) bool {
|
||||||
|
raw, _, err := e.st.get(endKey(module, branch))
|
||||||
|
var kept End
|
||||||
|
return err == nil && raw != nil && json.Unmarshal(raw, &kept) == nil && kept.Passed && kept.Fp == fp
|
||||||
|
}
|
||||||
|
|
||||||
|
// branchOf is the watched branch a placement names, else the first of the module's registration, else the trunk's.
|
||||||
|
func (e *pipelineEnds) branchOf(module, placed string) string {
|
||||||
|
if placed != "" {
|
||||||
|
return placed
|
||||||
|
}
|
||||||
|
e.mu.Lock()
|
||||||
|
defer e.mu.Unlock()
|
||||||
|
if b := e.firsts[module]; b != "" {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
if e.trunk != nil {
|
||||||
|
return e.trunk()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearPipeline takes a pipeline-ended. A pipeline of a group writes nothing on its own end, but the runner's: in a group
|
||||||
|
// take-in that changes the runner it is the acting part the other members wait on, so it goes first, wanted on its own end
|
||||||
|
// once that passed, ahead of the group (A-334, as the node-engine does, §268). A run on request delivers nothing (design 47 G
|
||||||
|
// §29, §64).
|
||||||
|
func (e *pipelineEnds) hearPipeline(m jetstream.Msg) {
|
||||||
|
p, err := mprc.PipelineEnded(m.Data())
|
||||||
|
if left := e.left.Load(); err == nil && left != nil && (p.Outcome == mpr.PipelineEndedOutcomeSuperseded || p.Outcome == mpr.PipelineEndedOutcomeCancelled) {
|
||||||
|
if err := (*left)(p.Pipeline); err != nil {
|
||||||
|
e.logf("%s: the composition steps of %s do not all leave their runs: %v; it is heard again", m.Subject(), p.Pipeline, err)
|
||||||
|
_ = m.Nak()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
e.logf("%s is not taken: %v", m.Subject(), err)
|
||||||
|
case p.Run == "" && p.Group != "" && e.holdUntilRead(m):
|
||||||
|
return
|
||||||
|
case p.Run != "" || (p.Group != "" && !e.isRunner(p.Module)):
|
||||||
|
default:
|
||||||
|
if err := e.take(p, requiredPassed(p)); err != nil {
|
||||||
|
e.logf("%s: %v; it is heard again", m.Subject(), err)
|
||||||
|
_ = m.Nak()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ = m.Ack()
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearGroup takes a group-ended: each member's end, passed only if the group passed. A run on request's (group `run-<id>`) delivers
|
||||||
|
// nothing: it drops the run's candidate assignment graph (A-235).
|
||||||
|
func (e *pipelineEnds) hearGroup(m jetstream.Msg) {
|
||||||
|
g, err := mprc.GroupEnded(m.Data())
|
||||||
|
if err != nil {
|
||||||
|
e.logf("%s is not taken: %v", m.Subject(), err)
|
||||||
|
_ = m.Ack()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(g.Group, runGroupPrefix) {
|
||||||
|
if e.runEnded != nil {
|
||||||
|
if err := e.runEnded(g.Group); err != nil {
|
||||||
|
e.logf("%s: %v; it is heard again", m.Subject(), err)
|
||||||
|
_ = m.Nak()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ = m.Ack()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, p := range g.Pipelines {
|
||||||
|
if err := e.take(p, g.Outcome == mpr.GroupEndedOutcomePassed && requiredPassed(p)); err != nil {
|
||||||
|
e.logf("%s: %v; it is heard again", m.Subject(), err)
|
||||||
|
_ = m.Nak()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ = m.Ack()
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearEnds registers the two events on the assigner's hub.
|
||||||
|
func hearEnds(hub *process.EventHub, e *pipelineEnds) error {
|
||||||
|
if err := hub.Handle(pipelineEndedSubject, e.hearPipeline); err != nil {
|
||||||
|
return fmt.Errorf("%s: %w", pipelineEndedSubject, err)
|
||||||
|
}
|
||||||
|
if err := hub.Handle(groupEndedSubject, e.hearGroup); err != nil {
|
||||||
|
return fmt.Errorf("%s: %w", groupEndedSubject, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// writtenTools is the tool assigner_written: every key of the state written, with its end.
|
||||||
|
func writtenTools(st store) []stdio.Tool {
|
||||||
|
return []stdio.Tool{{Name: writtenTool, Description: "the pipeline ends the assigner's wants follow: per module and watched branch, the source revision and end count of the newest end heard, whether it passed and whether the wants were written from it; with why, why each want is what it is (as assigner_why).",
|
||||||
|
Input: schema(map[string]string{"why": "true: why each want is what it is", "module": "with why: a module's name", "node": "with why: a node's name"}, nil, "why"),
|
||||||
|
Run: func(args map[string]any) (any, error) {
|
||||||
|
if args["why"] == true || args["why"] == "true" {
|
||||||
|
return whyTools(st)[0].Run(args) // a want's why (why.go), until the manifest naming assigner_why is taken in
|
||||||
|
}
|
||||||
|
ks, err := st.keys(writtenState)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sort.Strings(ks)
|
||||||
|
out := map[string]End{}
|
||||||
|
for _, k := range ks {
|
||||||
|
if strings.HasPrefix(k, whyPrefix) {
|
||||||
|
continue // a want's why (why.go), read by assigner_why
|
||||||
|
}
|
||||||
|
raw, _, ok, err := st.get(writtenState, k)
|
||||||
|
if err != nil || !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var e End
|
||||||
|
if json.Unmarshal(raw, &e) == nil {
|
||||||
|
out[k] = e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// branchesOf is the watched branches the placements of module chose, each once; the default branch when none names one.
|
||||||
|
func (e *pipelineEnds) branchesOf(module string, placed map[string]map[string]string) []string {
|
||||||
|
if !e.following() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
seen := map[string]bool{}
|
||||||
|
var out []string
|
||||||
|
for _, b := range placed[module] {
|
||||||
|
b = e.branchOf(module, b)
|
||||||
|
if !seen[b] {
|
||||||
|
seen[b] = true
|
||||||
|
out = append(out, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(out) == 0 {
|
||||||
|
out = append(out, e.branchOf(module, ""))
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// mayWant says whether module's wants may name fp: a pipeline passed at fp on every branch, or the wants name fp already
|
||||||
|
// (a node placed later, a module taken away).
|
||||||
|
func (e *pipelineEnds) mayWant(module, fp string, branches []string, wanted map[string]mwc.Want) bool {
|
||||||
|
if !e.following() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, w := range wanted {
|
||||||
|
if w.Fp == fp {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, b := range branches {
|
||||||
|
if !e.passedAt(module, b, fp) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// wrote marks the end the wants of module were written from.
|
||||||
|
func (e *pipelineEnds) wrote(module, fp string, branches []string) {
|
||||||
|
if !e.following() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, b := range branches {
|
||||||
|
e.markWritten(module, b, fp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// following says whether the wants follow the pipeline ends yet; a nil follower never does.
|
||||||
|
func (e *pipelineEnds) following() bool { return e != nil && e.on.Load() }
|
||||||
|
|
||||||
|
// registered takes a module's registration (design 47 G §353): the first one heard switches the wants to the ends, its first
|
||||||
|
// watched branch is the default a placement runs, and the ends kept for a branch it no longer watches are deleted (§352). gone
|
||||||
|
// is a registration removed: all its ends go.
|
||||||
|
func (e *pipelineEnds) registered(reg mpcat.Registration, gone bool) {
|
||||||
|
e.mu.Lock()
|
||||||
|
if gone || len(reg.Branches) == 0 {
|
||||||
|
delete(e.firsts, reg.Module)
|
||||||
|
} else {
|
||||||
|
e.firsts[reg.Module] = reg.Branches[0]
|
||||||
|
}
|
||||||
|
e.mu.Unlock()
|
||||||
|
kept, err := e.st.keys()
|
||||||
|
if err != nil {
|
||||||
|
e.logf("the ends kept cannot be listed: %v", err)
|
||||||
|
}
|
||||||
|
prefix := keys.EscapeName(reg.Module) + "."
|
||||||
|
for _, k := range kept {
|
||||||
|
rest, ok := strings.CutPrefix(k, prefix)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
branch, err := keys.UnescapeName(rest)
|
||||||
|
if err == nil && !gone && slices.Contains(reg.Branches, branch) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := e.st.drop(k); err != nil {
|
||||||
|
e.logf("the end %s is not deleted: %v", k, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if e.onBranches != nil && !gone {
|
||||||
|
e.onBranches(reg.Branches)
|
||||||
|
}
|
||||||
|
if !e.on.Swap(true) {
|
||||||
|
e.logf("the first registration is heard (%s): the wants follow the pipelines' ends from now", reg.Module)
|
||||||
|
}
|
||||||
|
e.wake()
|
||||||
|
}
|
||||||
|
|
||||||
|
// followRegistrations follows the registrations through the seat mesh-catalog (design 47 G §353): a first view of its verb
|
||||||
|
// and each registration-changed on the hub. It returns when the hub's handler is registered; the first view is asked on its own
|
||||||
|
// goroutine, the wants keep the trunk-only form until a registration is heard.
|
||||||
|
func followRegistrations(ctx context.Context, hub *process.EventHub, call mcc.Call, e *pipelineEnds) error {
|
||||||
|
regs := mcc.NewRegistrations(call)
|
||||||
|
regs.Follower.Logf = e.logf
|
||||||
|
regs.Follower.Changed = func(module string, value json.RawMessage, gone bool, _ time.Time) {
|
||||||
|
reg := mpcat.Registration{Module: module}
|
||||||
|
if !gone {
|
||||||
|
_ = json.Unmarshal(value, ®)
|
||||||
|
}
|
||||||
|
e.registered(reg, gone)
|
||||||
|
}
|
||||||
|
if err := hub.Handle(mpcat.SubjectRegistrationChanged, func(m jetstream.Msg) {
|
||||||
|
if err := regs.Hear(ctx, m.Data()); err != nil {
|
||||||
|
e.logf("%s: %v", m.Subject(), err)
|
||||||
|
}
|
||||||
|
_ = m.Ack()
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
if err := regs.Start(ctx); err != nil && ctx.Err() == nil {
|
||||||
|
e.logf("the first view of the registrations is not answered: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,450 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||||
|
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||||
|
plc "mesh-delivery-assigner/internal/assignment"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||||
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
mpcat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||||
|
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||||
|
|
||||||
|
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-grants/grantsstate"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
|
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||||
|
"mesh-delivery-assigner/internal/assigngraph"
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
|
||||||
|
mws "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
|
)
|
||||||
|
|
||||||
|
// memEnds is endStore over a map, with revisions.
|
||||||
|
type memEnds struct {
|
||||||
|
vals map[string][]byte
|
||||||
|
revs map[string]uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMemEnds() *memEnds { return &memEnds{vals: map[string][]byte{}, revs: map[string]uint64{}} }
|
||||||
|
|
||||||
|
func (m *memEnds) get(key string) ([]byte, uint64, error) { return m.vals[key], m.revs[key], nil }
|
||||||
|
func (m *memEnds) keys() (out []string, _ error) {
|
||||||
|
for k := range m.vals {
|
||||||
|
out = append(out, k)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
func (m *memEnds) drop(key string) error { delete(m.vals, key); delete(m.revs, key); return nil }
|
||||||
|
func (m *memEnds) swap(key string, v []byte, rev uint64) error {
|
||||||
|
if m.revs[key] != rev {
|
||||||
|
return errSwapped
|
||||||
|
}
|
||||||
|
m.vals[key], m.revs[key] = v, rev+1
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// heardMsg is one message as a handler of the hub is handed it, saying whether it was acknowledged or given back.
|
||||||
|
type heardMsg struct {
|
||||||
|
jetstream.Msg
|
||||||
|
data []byte
|
||||||
|
subject string
|
||||||
|
acked, naked bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *heardMsg) Data() []byte { return m.data }
|
||||||
|
func (m *heardMsg) Subject() string { return m.subject }
|
||||||
|
func (m *heardMsg) Ack() error { m.acked = true; return nil }
|
||||||
|
func (m *heardMsg) Nak() error { m.naked = true; return nil }
|
||||||
|
|
||||||
|
func pipe(module, branch string, source, count int64, fp, outcome string, steps ...mpr.StepResult) mpr.PipelineEnded {
|
||||||
|
return mpr.PipelineEnded{Module: module, Branch: branch, Source: source, EndCount: count, Fingerprint: fp, Outcome: outcome, Steps: steps,
|
||||||
|
Pipeline: branch + "." + module, Commit: "c"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func step(status, outcome string) mpr.StepResult {
|
||||||
|
return mpr.StepResult{Step: "unit", Status: status, Outcome: outcome}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §29, §35, §325, §352 (tests 66, 67, 89): a want follows a passed pipeline, by compare-and-set per module and branch.
|
||||||
|
func TestAWantFollowsAPassedPipeline(t *testing.T) {
|
||||||
|
const fp1, fp2 = "fp1", "fp2"
|
||||||
|
pass, fail := mpr.PipelineEndedOutcomePassed, mpr.PipelineEndedOutcomeFailed
|
||||||
|
req, opt := mpr.StepResultStatusRequired, mpr.StepResultStatusOptional
|
||||||
|
for _, c := range []struct {
|
||||||
|
name string
|
||||||
|
ends []mpr.PipelineEnded
|
||||||
|
group *mpr.GroupEnded
|
||||||
|
module string
|
||||||
|
branch string
|
||||||
|
fp string
|
||||||
|
may bool
|
||||||
|
}{
|
||||||
|
{"a failed required step writes no want", []mpr.PipelineEnded{pipe("web", "main", 5, 1, fp1, fail, step(req, "failed"))}, nil, "web", "main", fp1, false},
|
||||||
|
{"a pipeline passed writes", []mpr.PipelineEnded{pipe("web", "main", 5, 1, fp1, pass, step(req, "passed"))}, nil, "web", "main", fp1, true},
|
||||||
|
{"a failed optional step holds nothing", []mpr.PipelineEnded{pipe("web", "main", 5, 1, fp1, pass, step(req, "passed"), step(opt, "failed"))}, nil, "web", "main", fp1, true},
|
||||||
|
{"a pipeline passed at another fingerprint", []mpr.PipelineEnded{pipe("web", "main", 5, 1, fp1, pass)}, nil, "web", "main", fp2, false},
|
||||||
|
{"an older revision ending after a newer one writes nothing", []mpr.PipelineEnded{pipe("web", "main", 6, 1, fp2, fail), pipe("web", "main", 5, 1, fp1, pass)}, nil, "web", "main", fp1, false},
|
||||||
|
{"another branch writes its own", []mpr.PipelineEnded{pipe("web", "main", 6, 1, fp2, fail), pipe("web", "beta", 5, 1, fp1, pass)}, nil, "web", "beta", fp1, true},
|
||||||
|
{"a later end of the same revision writes", []mpr.PipelineEnded{pipe("web", "main", 5, 1, fp1, fail, step(req, "failed")), pipe("web", "main", 5, 2, fp1, pass, step(req, "passed"))}, nil, "web", "main", fp1, true},
|
||||||
|
{"the same end again after a later one keeps the later", []mpr.PipelineEnded{pipe("web", "main", 5, 2, fp1, pass), pipe("web", "main", 5, 1, fp1, fail)}, nil, "web", "main", fp1, true},
|
||||||
|
{"a member's own end writes nothing", []mpr.PipelineEnded{func() mpr.PipelineEnded { p := pipe("web", "main", 5, 1, fp1, pass); p.Group = "g"; return p }()}, nil, "web", "main", fp1, false},
|
||||||
|
{"a group ended passed writes its members", nil, &mpr.GroupEnded{Branch: "main", Group: "g", Outcome: mpr.GroupEndedOutcomePassed, Pipelines: []mpr.PipelineEnded{pipe("web", "main", 5, 1, fp1, pass)}}, "web", "main", fp1, true},
|
||||||
|
{"a group ended failed writes none", nil, &mpr.GroupEnded{Branch: "main", Group: "g", Outcome: mpr.GroupEndedOutcomeFailed, Pipelines: []mpr.PipelineEnded{pipe("web", "main", 5, 1, fp1, pass)}}, "web", "main", fp1, false},
|
||||||
|
} {
|
||||||
|
woken := 0
|
||||||
|
e := newPipelineEnds(newMemEnds(), func() { woken++ }, t.Logf)
|
||||||
|
e.on.Store(true)
|
||||||
|
for _, p := range c.ends {
|
||||||
|
if p.Group != "" {
|
||||||
|
continue // heard and ignored, as hearPipeline does
|
||||||
|
}
|
||||||
|
if err := e.take(p, requiredPassed(p)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if g := c.group; g != nil {
|
||||||
|
for _, p := range g.Pipelines {
|
||||||
|
if err := e.take(p, g.Outcome == mpr.GroupEndedOutcomePassed && requiredPassed(p)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if got := e.mayWant(c.module, c.fp, []string{c.branch}, nil); got != c.may {
|
||||||
|
t.Errorf("%s: may want = %v, want %v", c.name, got, c.may)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A run on request's group-ended (group run-<id>, A-235) writes no want and drops the run's candidate; a drop that fails is
|
||||||
|
// heard again.
|
||||||
|
{
|
||||||
|
e := newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||||
|
e.on.Store(true)
|
||||||
|
var dropped []string
|
||||||
|
fail := false
|
||||||
|
e.runEnded = func(group string) error {
|
||||||
|
dropped = append(dropped, group)
|
||||||
|
if fail {
|
||||||
|
return fmt.Errorf("the bucket is not open")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
raw, _ := json.Marshal(mpr.GroupEnded{V: 1, Branch: "main", Group: "run-7", Outcome: mpr.GroupEndedOutcomePassed,
|
||||||
|
Pipelines: []mpr.PipelineEnded{func() mpr.PipelineEnded { p := pipe("web", "main", 5, 1, fp1, pass); p.Run = "7"; return p }()}})
|
||||||
|
m := &heardMsg{data: raw, subject: "mesh.seat.mesh-pipeline-runner.event.group-ended.x"}
|
||||||
|
e.hearGroup(m)
|
||||||
|
if e.mayWant("web", fp1, []string{"main"}, nil) || !slices.Equal(dropped, []string{"run-7"}) || !m.acked {
|
||||||
|
t.Errorf("a run's group-ended: may want %v, dropped %v, acked %v; want no want, run-7 dropped, acked",
|
||||||
|
e.mayWant("web", fp1, []string{"main"}, nil), dropped, m.acked)
|
||||||
|
}
|
||||||
|
fail = true
|
||||||
|
m = &heardMsg{data: raw, subject: m.subject}
|
||||||
|
e.hearGroup(m)
|
||||||
|
if !m.naked {
|
||||||
|
t.Error("a run's candidate not dropped is not heard again")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A-334 (§29, §65, §268): in a group take-in that changes the runner, the runner's member (the holder of the seat
|
||||||
|
// mesh-pipeline-runner, read from the acting edges) is wanted on its own pipeline-ended once it passed, ahead of the group;
|
||||||
|
// the other members wait for group-ended.
|
||||||
|
{
|
||||||
|
e := newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||||
|
e.on.Store(true)
|
||||||
|
heard := func(p mpr.PipelineEnded) *heardMsg {
|
||||||
|
p.Group = "g"
|
||||||
|
raw, _ := json.Marshal(p)
|
||||||
|
m := &heardMsg{data: raw, subject: "mesh.seat.mesh-pipeline-runner.event.pipeline-ended.x"}
|
||||||
|
e.hearPipeline(m)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
hear := func(p mpr.PipelineEnded) {
|
||||||
|
if m := heard(p); !m.acked {
|
||||||
|
t.Errorf("the pipeline-ended of %s is not acknowledged", p.Module)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The runner's end heard before a pass read the graph is held, unacknowledged, and taken once the runner is read.
|
||||||
|
early := heard(pipe("runner", "main", 5, 1, "fp-runner", pass, step(req, "passed")))
|
||||||
|
if early.acked || early.naked || e.mayWant("runner", "fp-runner", []string{"main"}, nil) {
|
||||||
|
t.Fatalf("the runner's end before the graph is read: acked %v, naked %v, wanted %v; want it held", early.acked, early.naked,
|
||||||
|
e.mayWant("runner", "fp-runner", []string{"main"}, nil))
|
||||||
|
}
|
||||||
|
e.setRunner(assigngraph.Runner([]mws.AssignmentEntry{{Node: "ace", Module: "web", Edges: []mws.Edge{
|
||||||
|
{Kind: assigngraph.EdgeActing, Node: "ace", Module: "runner", Seat: mpr.Seat, Step: "pipeline"}}}}))
|
||||||
|
if !early.acked {
|
||||||
|
t.Error("the runner's end held until the graph was read is not taken once it is")
|
||||||
|
}
|
||||||
|
hear(pipe("web", "main", 5, 1, fp1, pass, step(req, "passed")))
|
||||||
|
if !e.mayWant("runner", "fp-runner", []string{"main"}, nil) || e.mayWant("web", fp1, []string{"main"}, nil) {
|
||||||
|
t.Errorf("a group changing the runner: may want the runner %v, web %v; want the runner ahead of the group and web not yet",
|
||||||
|
e.mayWant("runner", "fp-runner", []string{"main"}, nil), e.mayWant("web", fp1, []string{"main"}, nil))
|
||||||
|
}
|
||||||
|
hear(pipe("runner", "main", 6, 1, "fp-runner-2", fail, step(req, "failed")))
|
||||||
|
if e.mayWant("runner", "fp-runner-2", []string{"main"}, nil) {
|
||||||
|
t.Error("the runner's member that failed is wanted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Design 47 G A-428: the runner's first start skips the gate while no module claiming the seat runs; another module never
|
||||||
|
// does, and a runner running anywhere (stopped ones aside) closes it; with no running heard the gate stands.
|
||||||
|
manifests := map[string]catalogue.Manifest{"runner": {Claims: []catalogue.Claim{{Name: mpr.Seat}}}, "web": {}}
|
||||||
|
none := map[string]map[string]nodeengine.Running{"ace": {"web": {Fingerprint: fp1}}}
|
||||||
|
if !runnerFirstStart("runner", manifests, none) || runnerFirstStart("web", manifests, none) || runnerFirstStart("runner", manifests, nil) {
|
||||||
|
t.Error("the runner's first start: the runner skips the gate, another module or an unknown world does not")
|
||||||
|
}
|
||||||
|
if runnerFirstStart("runner", manifests, map[string]map[string]nodeengine.Running{"novox": {"runner": {Fingerprint: "fp-runner"}}}) ||
|
||||||
|
!runnerFirstStart("runner", manifests, map[string]map[string]nodeengine.Running{"novox": {"runner": {Stopped: true}}}) {
|
||||||
|
t.Error("a runner running closes the gate's opening; one stopped does not")
|
||||||
|
}
|
||||||
|
// A want that names the fingerprint already is not held by a later failure (a node placed afterwards gets it).
|
||||||
|
e := newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||||
|
e.on.Store(true)
|
||||||
|
if !e.mayWant("web", fp1, []string{"main"}, map[string]mwc.Want{"g14": {Fp: fp1}}) {
|
||||||
|
t.Error("a want naming the fingerprint was held")
|
||||||
|
}
|
||||||
|
// markWritten keeps the end and says it was written from; a newer end replaces it unwritten.
|
||||||
|
st := newMemEnds()
|
||||||
|
e = newPipelineEnds(st, func() {}, t.Logf)
|
||||||
|
e.on.Store(true)
|
||||||
|
_ = e.take(pipe("web", "main", 5, 1, fp1, pass), true)
|
||||||
|
e.wrote("web", fp1, []string{"main"})
|
||||||
|
var end End
|
||||||
|
_ = json.Unmarshal(st.vals[endKey("web", "main")], &end)
|
||||||
|
if !end.Written || end.Source != 5 {
|
||||||
|
t.Errorf("end = %+v, want written at source 5", end)
|
||||||
|
}
|
||||||
|
_ = e.take(pipe("web", "main", 6, 1, fp2, pass), true)
|
||||||
|
end = End{}
|
||||||
|
_ = json.Unmarshal(st.vals[endKey("web", "main")], &end)
|
||||||
|
if end.Written || end.Source != 6 {
|
||||||
|
t.Errorf("a newer end = %+v, want unwritten at source 6", end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §29: the wants of a pass follow a pipeline: with the follower on, a module whose fingerprint no pipeline passed at
|
||||||
|
// gets no want and one a pipeline passed at gets it; with it off (nil, the trunk-only want) the pass is as before.
|
||||||
|
func TestAPassWritesNoWantWithoutAPassedPipeline(t *testing.T) {
|
||||||
|
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64)
|
||||||
|
for _, c := range []struct {
|
||||||
|
name string
|
||||||
|
follow bool
|
||||||
|
passed bool
|
||||||
|
want bool
|
||||||
|
}{{"the trunk-only want", false, false, true}, {"no pipeline passed", true, false, false}, {"a pipeline passed", true, true, true}} {
|
||||||
|
wantsKV := &memKV{values: map[string][]byte{}}
|
||||||
|
p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, time.Now())
|
||||||
|
p.say = func(oc.Condition) error { return nil }
|
||||||
|
mdigest := strings.Repeat("e", 64)
|
||||||
|
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: mdigest, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||||
|
putModuleRaw(p.w, trunkBranch, "web", mod)
|
||||||
|
p.w.manifests[mdigest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web"}}
|
||||||
|
endDone(t, p.w, "web", fp, mdigest)
|
||||||
|
gkey, _ := grantsstate.PartGrantKey("web", fp)
|
||||||
|
grant, _ := grantsstate.EncodeGrant(grantsstate.Grant{})
|
||||||
|
p.w.put(buckets.Grants, gkey, grant)
|
||||||
|
digest := "sha256:" + strings.Repeat("c", 64)
|
||||||
|
have, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fp, Composed: digest, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
|
||||||
|
p.w.put(buckets.Have, "g14.web", have)
|
||||||
|
composes(t, p.w, "g14", digest)
|
||||||
|
placeOn(t, p.w, "g14", "web")
|
||||||
|
on := true
|
||||||
|
p.w.heardPresence("g14", !on, time.Now())
|
||||||
|
if c.follow {
|
||||||
|
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||||
|
p.ends.trunk = p.w.trunkName
|
||||||
|
p.ends.on.Store(true)
|
||||||
|
if c.passed {
|
||||||
|
_ = p.ends.take(pipe("web", trunkBranch, 5, 1, fp, mpr.PipelineEndedOutcomePassed), true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.wants(context.Background())
|
||||||
|
key, _ := mwc.WantKey("g14", "web")
|
||||||
|
if _, got := wantsKV.values[key]; got != c.want {
|
||||||
|
t.Errorf("%s: a want written = %v, want %v", c.name, got, c.want)
|
||||||
|
}
|
||||||
|
if c.follow && c.passed {
|
||||||
|
raw, _, _ := p.ends.st.get(endKey("web", trunkBranch))
|
||||||
|
var end End
|
||||||
|
_ = json.Unmarshal(raw, &end)
|
||||||
|
if !end.Written {
|
||||||
|
t.Errorf("%s: the end was not marked written", c.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §95, §130, §353, §352 (test 100): the wants keep the trunk-only form until the first registration is heard and
|
||||||
|
// switch on it; a branch a registration no longer watches loses its end, and its first branch is a placement's default.
|
||||||
|
func TestTheWantsSwitchOnTheFirstRegistration(t *testing.T) {
|
||||||
|
st := newMemEnds()
|
||||||
|
woken := 0
|
||||||
|
e := newPipelineEnds(st, func() { woken++ }, t.Logf)
|
||||||
|
e.trunk = func() string { return trunkBranch }
|
||||||
|
_ = e.take(pipe("web", "main", 5, 1, "fp1", mpr.PipelineEndedOutcomeFailed), false)
|
||||||
|
_ = e.take(pipe("web", "beta", 5, 1, "fp1", mpr.PipelineEndedOutcomePassed), true)
|
||||||
|
if e.following() || !e.mayWant("web", "fp1", []string{"main"}, nil) {
|
||||||
|
t.Fatal("the follower held a want before any registration")
|
||||||
|
}
|
||||||
|
e.registered(mpcat.Registration{Module: "web", Branches: []string{"beta"}}, false)
|
||||||
|
if !e.following() || woken == 0 {
|
||||||
|
t.Error("the first registration did not switch the wants on")
|
||||||
|
}
|
||||||
|
if e.mayWant("web", "fp1", []string{"main"}, nil) || !e.mayWant("web", "fp1", []string{"beta"}, nil) {
|
||||||
|
t.Error("after the switch the wants did not follow the ends")
|
||||||
|
}
|
||||||
|
if len(st.vals) != 1 || e.branchOf("web", "") != "beta" || e.branchOf("other", "") != trunkBranch {
|
||||||
|
t.Errorf("ends kept %d, default branch %q: an unwatched branch's end stayed, or the default is wrong", len(st.vals), e.branchOf("web", ""))
|
||||||
|
}
|
||||||
|
e.registered(mpcat.Registration{Module: "web"}, true)
|
||||||
|
if len(st.vals) != 0 {
|
||||||
|
t.Errorf("a registration gone left %d ends", len(st.vals))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §14, §184 (test 68): a node's entry is computed from the catalog half of the branch its placement names, so a
|
||||||
|
// change on `beta` moves only the want of the node whose placement chose `beta`.
|
||||||
|
func TestACommitOnBetaMovesOnlyTheNodeThatChoseBeta(t *testing.T) {
|
||||||
|
fp := func(c string) string { return meshcatalogclient.SourcePrefix2 + strings.Repeat(c, 64) }
|
||||||
|
wantsKV := &memKV{values: map[string][]byte{}}
|
||||||
|
p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, time.Now())
|
||||||
|
p.say = func(oc.Condition) error { return nil }
|
||||||
|
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||||
|
p.ends.trunk = p.w.trunkName
|
||||||
|
p.ends.registered(mpcat.Registration{Module: "web", Branches: []string{"main", "beta"}}, false)
|
||||||
|
digest := "sha256:" + strings.Repeat("c", 64)
|
||||||
|
on := true
|
||||||
|
for _, node := range []string{"g14", "ace"} {
|
||||||
|
composes(t, p.w, node, digest)
|
||||||
|
p.w.heardPresence(node, !on, time.Now())
|
||||||
|
}
|
||||||
|
for node, branch := range map[string]string{"g14": "", "ace": "beta"} {
|
||||||
|
pl := mma.Assignments{Node: node, Modules: []mma.PlacedModule{{Module: "web", Branch: branch}}}
|
||||||
|
values, err := mmac.AssignmentsValues(pl)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for key, raw := range values {
|
||||||
|
p.w.put(plc.AssignmentsBucket(), key, raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// publish makes the half of branch name web at fingerprint f: built, granted and passed by its pipeline.
|
||||||
|
publish := func(branch, f string, source int64) {
|
||||||
|
mdigest := strings.Repeat("e", 62) + fmt.Sprintf("%02d", source)
|
||||||
|
if branch == "beta" {
|
||||||
|
mdigest = strings.Repeat("f", 62) + fmt.Sprintf("%02d", source)
|
||||||
|
}
|
||||||
|
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: f, Manifest: mdigest, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||||
|
putModuleRaw(p.w, branch, "web", mod)
|
||||||
|
p.w.manifests[mdigest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web"}}
|
||||||
|
endDone(t, p.w, "web", f, mdigest)
|
||||||
|
gkey, _ := grantsstate.PartGrantKey("web", f)
|
||||||
|
grant, _ := grantsstate.EncodeGrant(grantsstate.Grant{})
|
||||||
|
p.w.put(buckets.Grants, gkey, grant)
|
||||||
|
_ = p.ends.take(pipe("web", branch, source, 1, f, mpr.PipelineEndedOutcomePassed), true)
|
||||||
|
}
|
||||||
|
run := func(node, f string) {
|
||||||
|
have, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: f, Composed: digest, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
|
||||||
|
p.w.put(buckets.Have, node+".web", have)
|
||||||
|
}
|
||||||
|
fpWant := func(node string) string {
|
||||||
|
key, _ := mwc.WantKey(node, "web")
|
||||||
|
w, err := mwc.DecodeWant(wantsKV.values[key])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("the want of web on %s: %v", node, err)
|
||||||
|
}
|
||||||
|
return w.Fp
|
||||||
|
}
|
||||||
|
publish("main", fp("a"), 5)
|
||||||
|
publish("beta", fp("b"), 5)
|
||||||
|
run("g14", fp("a"))
|
||||||
|
run("ace", fp("b"))
|
||||||
|
p.wants(context.Background())
|
||||||
|
if fpWant("g14") != fp("a") || fpWant("ace") != fp("b") {
|
||||||
|
t.Fatalf("each node is wanted at its branch's build: g14 %s, ace %s", fpWant("g14"), fpWant("ace"))
|
||||||
|
}
|
||||||
|
publish("beta", fp("d"), 6)
|
||||||
|
p.wants(context.Background())
|
||||||
|
if fpWant("g14") != fp("a") || fpWant("ace") != fp("d") {
|
||||||
|
t.Errorf("a commit on beta moves only ace: g14 %s (want main's), ace %s (want beta's new)", fpWant("g14"), fpWant("ace"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §14, §195: the catalog half of each branch is taken into the world per branch, an entry as the value and graph node
|
||||||
|
// the rules read, and a registration's branches are each followed.
|
||||||
|
func TestTheCatalogHalfIsTakenInPerBranch(t *testing.T) {
|
||||||
|
w := newWorld()
|
||||||
|
woken := 0
|
||||||
|
h := &halves{w: w, wake: func() { woken++ }, logf: t.Logf}
|
||||||
|
entry := func(fp string) json.RawMessage {
|
||||||
|
raw, _ := json.Marshal(meshcatalog.CatalogEntry{Module: "web", Fp: fp, Repository: "novox/web", Commit: "c1",
|
||||||
|
Manifest: map[string]any{"module": "web", "version": "1", "requires": []any{"database", map[string]any{"name": "cache", "optional": true}}},
|
||||||
|
Invokes: []string{"seat:x.v"}, Requires: []string{"cache", "database"}})
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
h.changed("main", "web", entry("src2:1"), false)
|
||||||
|
h.changed("beta", "web", entry("src2:2"), false)
|
||||||
|
if w.trunkOf("main")["web"].Fp2 != "src2:1" || w.trunkOf("beta")["web"].Fp2 != "src2:2" || woken != 2 {
|
||||||
|
t.Errorf("main %+v, beta %+v, woken %d: each branch keeps its own entry", w.trunkOf("main")["web"], w.trunkOf("beta")["web"], woken)
|
||||||
|
}
|
||||||
|
v := w.trunkOf("beta")["web"]
|
||||||
|
if got := w.manifest(v.Manifest); got.err != "" || got.manifest.Module != "web" {
|
||||||
|
t.Errorf("the entry's manifest is not read by its digest: %+v", got)
|
||||||
|
}
|
||||||
|
// The entry's requires name the optional cache too; the graph node means those required, not optionally (A-229).
|
||||||
|
if n := w.graphOf("main")["web"]; n.FP != "src2:1" || !slices.Equal(n.Invokes, []string{"seat:x.v"}) || !slices.Equal(n.Requires, []string{"database"}) {
|
||||||
|
t.Errorf("graph node %+v", n)
|
||||||
|
}
|
||||||
|
h.changed("beta", "web", nil, true)
|
||||||
|
if _, ok := w.trunkOf("beta")["web"]; ok || w.trunkOf("main")["web"].Fp2 == "" {
|
||||||
|
t.Error("a module taken out of beta's half leaves main's")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Design 47 G §379, §526: a want held at an older build, the trunk's newer fingerprint having passed no pipeline, is rewritten
|
||||||
|
// with that build's released version (and parts for an engine that reads them), the rest of the want kept; no want names the
|
||||||
|
// unpassed fingerprint (novox 2026-11-16, mesh-hand-acts 0.1.13 at 4eb3cf48).
|
||||||
|
func TestAWantHeldAtAnOlderBuildNamesItsReleaseWithoutAPassedPipeline(t *testing.T) {
|
||||||
|
old := meshcatalogclient.SourcePrefix2 + strings.Repeat("4", 64)
|
||||||
|
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("9", 64)
|
||||||
|
wantsKV := &memKV{values: map[string][]byte{}}
|
||||||
|
p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, time.Now())
|
||||||
|
p.say = func(oc.Condition) error { return nil }
|
||||||
|
mdigest := strings.Repeat("e", 64)
|
||||||
|
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: mdigest, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||||
|
putModuleRaw(p.w, trunkBranch, "web", mod)
|
||||||
|
p.w.manifests[mdigest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web"}}
|
||||||
|
endRaw, _ := json.Marshal(builds.BuildEnded{Module: "web", Fingerprint: old, Outcome: builds.BuildDone, Manifest: mdigest, Made: map[string]string{"tools": "sha256:1c"}})
|
||||||
|
if err := p.w.ends.put(endRaw); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rel, _ := json.Marshal(meshcatalog.VersionReleasedEvent{Module: "web", Source: 962, Version: "0.1.13", Artifacts: []meshcatalog.VersionArtifact{{Artifact: "tools", Digest: "sha256:1c"}}})
|
||||||
|
if err := p.w.released.put(rel); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
placeOn(t, p.w, "g14", "web")
|
||||||
|
key, _ := mwc.WantKey("g14", "web")
|
||||||
|
held, _ := mwc.EncodeWant(mwc.Want{Fp: old, Self: true})
|
||||||
|
wantsKV.values[key] = held
|
||||||
|
p.w.put(buckets.Wants(), key, held)
|
||||||
|
p.w.heardPresence("g14", false, time.Now())
|
||||||
|
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||||
|
p.ends.trunk = p.w.trunkName
|
||||||
|
p.ends.on.Store(true)
|
||||||
|
p.wants(context.Background())
|
||||||
|
got, err := mwc.DecodeWant(wantsKV.values[key])
|
||||||
|
if err != nil || got.Fp != old || got.Version != "0.1.13" || !got.Self {
|
||||||
|
t.Errorf("the held want = %+v, %v; want %s at 0.1.13, self kept", got, err, old)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"mesh-delivery-assigner/internal/buckets"
|
||||||
|
"mesh-delivery-assigner/internal/puts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// placementBy is who a put the placement's build makes names as its asker: the placement, whose proposal the operator
|
||||||
|
// approved, is the warrant (design 47 *Going back is one act*; ADR 0666 §24).
|
||||||
|
const placementBy = "the placement"
|
||||||
|
|
||||||
|
// placementPuts makes each placed module's `build` a held put of that build, and releases a put the placement made once its
|
||||||
|
// placement names that build no more (design 47 line 912: "a return to an earlier build is one value in the placement, the
|
||||||
|
// module's `build` in its placement key, set by a placement proposal"; ADR 0666 §24; B-K1). The put then goes its own steps
|
||||||
|
// (the builder's build, the composition, an ask where the module's policy needs one, the want, holding) and is read with
|
||||||
|
// `assigner_puts` and released with `assigner_release` like any other; a placement's build the builder never built is refused
|
||||||
|
// by its build step, said in the put's words. A put asked by a person stands until the placement names another build.
|
||||||
|
func (p *passer) placementPuts(ctx context.Context) {
|
||||||
|
kv := p.kvs[buckets.Puts()]
|
||||||
|
if kv == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
now := p.clock().UTC()
|
||||||
|
named := map[string]string{} // put key -> the build its placement names
|
||||||
|
for node, a := range p.w.assignments() {
|
||||||
|
for _, m := range a.Modules {
|
||||||
|
if m.Build == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if key, err := puts.Key(node, m.Module); err == nil {
|
||||||
|
named[key] = m.Build
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
held := p.w.read(buckets.Puts())
|
||||||
|
keys := make([]string, 0, len(named)+len(held))
|
||||||
|
for k := range named {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
for k := range held {
|
||||||
|
if _, there := named[k]; !there {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
for _, key := range keys {
|
||||||
|
build, names := named[key]
|
||||||
|
var before *puts.Put
|
||||||
|
if raw, ok := held[key]; ok {
|
||||||
|
if got, err := puts.Decode(raw); err == nil {
|
||||||
|
before = &got
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var next puts.Put
|
||||||
|
switch {
|
||||||
|
case names && before != nil && before.FP == build:
|
||||||
|
continue // made already, or a person's put of the same build: it goes its own steps, ended or not
|
||||||
|
case names:
|
||||||
|
words := fmt.Sprintf("asked by %s: it names build %s of %s", placementBy, shortFP(build), key)
|
||||||
|
if before != nil && !puts.Ended(before.Step) {
|
||||||
|
words += fmt.Sprintf("; it replaces the put of %s, which stood at %s", shortFP(before.FP), before.Step)
|
||||||
|
}
|
||||||
|
next = puts.Put{FP: build, Hold: true, Why: "the placement names this build (ADR 0666 §24)", By: placementBy, At: now}.Said(now, puts.Asked, words)
|
||||||
|
case before != nil && before.By == placementBy && !puts.Ended(before.Step):
|
||||||
|
next = before.Said(now, puts.Released, fmt.Sprintf("released by %s: it names no build of its own any more; the assigner's rules write the want again", placementBy))
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
data, err := puts.Encode(next)
|
||||||
|
if err != nil {
|
||||||
|
p.logf("the placement's put %s is not written: %v", key, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if before == nil {
|
||||||
|
_, err = kv.Create(ctx, key, data)
|
||||||
|
} else if e, gerr := kv.Get(ctx, key); gerr != nil {
|
||||||
|
err = gerr
|
||||||
|
} else {
|
||||||
|
_, err = kv.Update(ctx, key, data, e.Revision())
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
p.logf("the placement's put %s could not be written, and is written at the next pass: %v", key, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
p.w.put(buckets.Puts(), key, data)
|
||||||
|
p.logf("put %s: %s: %s", key, next.Step, next.Words)
|
||||||
|
if p.acts != nil {
|
||||||
|
p.acts.say(key, next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,10 +13,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshdeliveryclient"
|
|
||||||
mwc "git.novox.be/novox/mesh-delivery/contracts/go/clients/meshwantsclient"
|
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||||
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-grants/grantsstate"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-grants/grantsstate"
|
||||||
|
|
||||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||||
@@ -41,6 +40,12 @@ const PutEvent = "put"
|
|||||||
type caller interface {
|
type caller interface {
|
||||||
Call(key string, body any) (json.RawMessage, error)
|
Call(key string, body any) (json.RawMessage, error)
|
||||||
CallOn(node, key string, body any) (json.RawMessage, error)
|
CallOn(node, key string, body any) (json.RawMessage, error)
|
||||||
|
// CallKept is Call for a kept call, safe to call again (process.Conn.CallKept; ADR 0668).
|
||||||
|
CallKept(key string, body any) (json.RawMessage, error)
|
||||||
|
// CallKeptOn is CallOn for a kept call, safe to call again (process.Conn.CallKeptOn; ADR 0668).
|
||||||
|
CallKeptOn(node, key string, body any) (json.RawMessage, error)
|
||||||
|
// CallFile is Call of a verb marked chunks, its answer read whole (process.Conn.CallFile; design 47 G A-291).
|
||||||
|
CallFile(key string, body any) (json.RawMessage, error)
|
||||||
Emit(eventType string, body any) error
|
Emit(eventType string, body any) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +83,7 @@ func identity(key string, p puts.Put) string {
|
|||||||
// putsByModule is every put the assigner holds, by module then node.
|
// putsByModule is every put the assigner holds, by module then node.
|
||||||
func (p *passer) putsByModule() map[string]map[string]puts.Put {
|
func (p *passer) putsByModule() map[string]map[string]puts.Put {
|
||||||
out := map[string]map[string]puts.Put{}
|
out := map[string]map[string]puts.Put{}
|
||||||
for key, value := range p.w.read(buckets.Puts) {
|
for key, value := range p.w.read(buckets.Puts()) {
|
||||||
node, module, err := puts.ParseKey(key)
|
node, module, err := puts.ParseKey(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@@ -101,13 +106,14 @@ func (p *passer) puts(ctx context.Context) {
|
|||||||
if p.acts == nil {
|
if p.acts == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
p.placementPuts(ctx)
|
||||||
all := p.putsByModule()
|
all := p.putsByModule()
|
||||||
|
defer func() { p.putWaits(ctx, p.putsByModule()) }()
|
||||||
if len(all) == 0 {
|
if len(all) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assigned := p.w.assigned()
|
assigned := p.w.assigned()
|
||||||
trunk := p.w.trunk()
|
trunk := p.w.trunk()
|
||||||
get := p.w.getter(buckets.Manifests) // the indexer's manifests, as its first view and views family say them
|
|
||||||
wanted := p.w.wantsOf()
|
wanted := p.w.wantsOf()
|
||||||
modules := make([]string, 0, len(all))
|
modules := make([]string, 0, len(all))
|
||||||
for m := range all {
|
for m := range all {
|
||||||
@@ -117,7 +123,7 @@ func (p *passer) puts(ctx context.Context) {
|
|||||||
for _, module := range modules {
|
for _, module := range modules {
|
||||||
var manifest catalogue.Manifest
|
var manifest catalogue.Manifest
|
||||||
if mod, ok := trunk[module]; ok && mod.Manifest != "" {
|
if mod, ok := trunk[module]; ok && mod.Manifest != "" {
|
||||||
if got := p.w.manifest(ctx, get, mod.Manifest); got.err == "" {
|
if got := p.w.manifest(mod.Manifest); got.err == "" {
|
||||||
manifest = got.manifest
|
manifest = got.manifest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,11 +161,9 @@ func (p *passer) puts(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
if next.Put.Step == puts.Wanted && put.Step != puts.Wanted {
|
if next.Put.Step == puts.Wanted && put.Step != puts.Wanted {
|
||||||
// The want is written in this pass too, before the next one would: Module.Puts writes the same.
|
// The want is written in this pass too, before the next one would: Module.Puts writes the same.
|
||||||
if wkey, err := mwc.WantKey(node, module); err == nil {
|
want := assign.PutWant(next.Put)
|
||||||
want := assign.PutWant(next.Put)
|
if before, ok := wanted[module][node]; !ok || !mwc.SameWant(normalWant(before), normalWant(want)) {
|
||||||
if before, ok := wanted[module][node]; !ok || !mwc.SameWant(normalWant(before), normalWant(want)) {
|
p.putWant(ctx, node, module, want)
|
||||||
p.put(ctx, buckets.Wants, wkey, func() ([]byte, error) { return mwc.EncodeWant(want) })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if next.Warranted {
|
if next.Warranted {
|
||||||
p.acts.warrant(id, meshdeliveryclient.AskingID(next.Put.Ask, assign.PutAsking(next.Put)))
|
p.acts.warrant(id, meshdeliveryclient.AskingID(next.Put.Ask, assign.PutAsking(next.Put)))
|
||||||
@@ -182,19 +186,13 @@ func (p *passer) putWorld(node, module string, put puts.Put, manifest catalogue.
|
|||||||
w.Assigned = true
|
w.Assigned = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bkey, err := builds.BuilderBuildKey(module, put.FP); err == nil {
|
if e, ok := p.w.ends.endOf(module, put.FP); ok { // the build's end heard (A-181): none heard, no state
|
||||||
if raw := p.w.value(buckets.Builds, bkey); raw != nil {
|
w.Build, w.BuildWords = e.Outcome, e.Error
|
||||||
if b, err := builds.DecodeBuilderBuild(raw); err == nil {
|
|
||||||
w.Build, w.BuildWords = b.State, b.Error
|
|
||||||
} else {
|
|
||||||
w.Build = "unreadable: " + err.Error()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
w.Composed, w.Granted = p.composedFor(node, module, put.FP)
|
w.Composed, w.Granted = p.composedFor(node, module, put.FP)
|
||||||
if d := w.Composed; d != nil {
|
if d := w.Composed; d != nil {
|
||||||
policy := d.Policy
|
policy := d.Policy
|
||||||
chosen, _ := assign.DecodePolicies(p.w.read(assign.PoliciesBucket))
|
chosen, _ := assign.DecodePolicies(p.w.read(assign.PoliciesBucket()))
|
||||||
if c, ok := chosen[module]; ok {
|
if c, ok := chosen[module]; ok {
|
||||||
policy, _, _, _ = catalogue.Upgrade(manifest, &c) // a person's choice at the assigner (ADR 0565 §7)
|
policy, _, _, _ = catalogue.Upgrade(manifest, &c) // a person's choice at the assigner (ADR 0565 §7)
|
||||||
} else if policy == "" {
|
} else if policy == "" {
|
||||||
@@ -203,7 +201,7 @@ func (p *passer) putWorld(node, module string, put puts.Put, manifest catalogue.
|
|||||||
w.Recorded = policy == catalogue.PolicyRecord
|
w.Recorded = policy == catalogue.PolicyRecord
|
||||||
if akey, err := asks.RecordAskKey(node, module, d.Digest); err == nil && put.Ask == akey {
|
if akey, err := asks.RecordAskKey(node, module, d.Digest); err == nil && put.Ask == akey {
|
||||||
// Only this put's own ask counts: an ask (and its answer) of an earlier put under the same key is another asking.
|
// Only this put's own ask counts: an ask (and its answer) of an earlier put under the same key is another asking.
|
||||||
if a, ask, err := assign.DecodeAsk(akey, p.w.value(buckets.Asks, akey)); err == nil && a.Asking == assign.PutAsking(put) {
|
if a, ask, err := assign.DecodeAsk(akey, p.w.value(buckets.Asks(), akey)); err == nil && a.Asking == assign.PutAsking(put) {
|
||||||
switch {
|
switch {
|
||||||
case p.answeredWith(akey, assign.OptionYes):
|
case p.answeredWith(akey, assign.OptionYes):
|
||||||
w.Answer = assign.OptionYes
|
w.Answer = assign.OptionYes
|
||||||
@@ -216,6 +214,9 @@ func (p *passer) putWorld(node, module string, put puts.Put, manifest catalogue.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if r, ok := p.w.runningOf(node, module); ok {
|
||||||
|
w.Running = &r
|
||||||
|
}
|
||||||
if hkey, err := nodeengineclient.HaveKey(node, module); err == nil {
|
if hkey, err := nodeengineclient.HaveKey(node, module); err == nil {
|
||||||
if raw := p.w.value(buckets.Have, hkey); raw != nil {
|
if raw := p.w.value(buckets.Have, hkey); raw != nil {
|
||||||
if h, err := nodeengineclient.DecodeHave(raw); err == nil {
|
if h, err := nodeengineclient.DecodeHave(raw); err == nil {
|
||||||
@@ -251,13 +252,13 @@ func (p *passer) actOn(ctx context.Context, node, module, id string, w assign.Pu
|
|||||||
// The put's own ask, written again over one an earlier put left under the key (its asking differs), so the teller
|
// The put's own ask, written again over one an earlier put left under the key (its asking differs), so the teller
|
||||||
// raises it anew under its own id.
|
// raises it anew under its own id.
|
||||||
akey := next.Put.Ask
|
akey := next.Put.Ask
|
||||||
current, _, err := assign.DecodeAsk(akey, p.w.value(buckets.Asks, akey))
|
current, _, err := assign.DecodeAsk(akey, p.w.value(buckets.Asks(), akey))
|
||||||
if err != nil || current.Asking != assign.PutAsking(next.Put) {
|
if err != nil || current.Asking != assign.PutAsking(next.Put) {
|
||||||
a, err := assign.PutAsk(akey, node, module, next.Put, *w.Composed, w.Bus, w.Now)
|
a, err := assign.PutAsk(akey, node, module, next.Put, *w.Composed, w.Bus, w.Now)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.logf("the ask about putting %s on %s is not written: %v", module, node, err)
|
p.logf("the ask about putting %s on %s is not written: %v", module, node, err)
|
||||||
} else {
|
} else {
|
||||||
p.put(ctx, buckets.Asks, akey, func() ([]byte, error) { return assign.EncodeAsk(akey, a) })
|
p.put(ctx, buckets.Asks(), akey, func() ([]byte, error) { return assign.EncodeAsk(akey, a) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -268,7 +269,7 @@ func (p *passer) actOn(ctx context.Context, node, module, id string, w assign.Pu
|
|||||||
|
|
||||||
// performs checks that the act about to be performed is the one the yes of the ask at key bound (occ.Performs).
|
// performs checks that the act about to be performed is the one the yes of the ask at key bound (occ.Performs).
|
||||||
func (p *passer) performs(key string, act occ.Act) error {
|
func (p *passer) performs(key string, act occ.Act) error {
|
||||||
_, ask, err := assign.DecodeAsk(key, p.w.value(buckets.Asks, key))
|
_, ask, err := assign.DecodeAsk(key, p.w.value(buckets.Asks(), key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("the ask %s cannot be read: %w", key, err)
|
return fmt.Errorf("the ask %s cannot be read: %w", key, err)
|
||||||
}
|
}
|
||||||
@@ -288,7 +289,7 @@ func samePut(a, b puts.Put) bool {
|
|||||||
// writePut writes a put's next value over the one the pass read, by compare-and-set, unless the tool has put again or
|
// writePut writes a put's next value over the one the pass read, by compare-and-set, unless the tool has put again or
|
||||||
// released it since; and says it as the event put. It says whether it wrote.
|
// released it since; and says it as the event put. It says whether it wrote.
|
||||||
func (p *passer) writePut(ctx context.Context, key string, read, next puts.Put) bool {
|
func (p *passer) writePut(ctx context.Context, key string, read, next puts.Put) bool {
|
||||||
kv := p.kvs[buckets.Puts]
|
kv := p.kvs[buckets.Puts()]
|
||||||
if kv == nil {
|
if kv == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -312,7 +313,7 @@ func (p *passer) writePut(ctx context.Context, key string, read, next puts.Put)
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
p.w.put(buckets.Puts, key, data)
|
p.w.put(buckets.Puts(), key, data)
|
||||||
p.logf("put %s: %s: %s", key, next.Step, next.Words)
|
p.logf("put %s: %s: %s", key, next.Step, next.Words)
|
||||||
p.acts.say(key, next)
|
p.acts.say(key, next)
|
||||||
return true
|
return true
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user