interplane.Get Omega
Read in your language

spark-connector

aien-dev/spark-connector

Brought by drakestapleton

branch main Branches Tags History

spark-connector / runner / 40job.om

333 lines · 5857 bytes Raw Blame History
1note runner/40job.om -- one job: ask the hub, check the compiler, fetch the record, run the cell,
2note sign and post the result. Run by a worker process the supervisor forks for each cycle.
3
4text rtnext "next"
5text rtnonce "nonce"
6text rtokjob "ipcc1 ok job\n"
7text rtoknone "ipcc1 ok none\n"
8text rtjobn "job"
9text rtpartn "part"
10text rtcompn "compiler"
11text rtbinn "binary"
12text rtoutn "stdout"
13text rtexitn "exit"
14text rtresn "result"
15text rtwork "work"
16text rtmagic "IPSLV001"
17text rtlhub "hub: "
18text rtlnone "no work\n"
19text rtlpin "refused: the job names a compiler other than the pinned omc 3ad9f10f\n"
20text rtlomc "refused: bin/omc is not the pinned compiler; run join again\n"
21text rtlrec "refused: the record is missing, is not the revision the job names, or is not a part\n"
22text rtljd "error: could not make the job directory\n"
23text rtlcell "error: the cell could not start a stage\n"
24text rtlres "result "
25text rtlsign "error: could not sign\n"
26text rtlnet "error: hub not reachable, status "
27text rtlarr " -> "
28text rtxneg "-"
29text rtokcnt "ipcc1 ok counted\n"
30text rtokst "ipcc1 ok stored\n"
31text rtlcellp "the cell could not start on this computer (see the result above); checks pause for an hour. Run: interplane-runner selftest\n"
32
33note r_logt: "<unix seconds> " on stdout (the log when running in the background)
34fn r_logt to void
35r_num ulong div realns 1000000000
36r_say rtsp
37end
38
39fn r_lognet s long to void
40r_logt
41r_say rtlnet
42if lt s 0
43r_say rtxneg
44r_num ulong neg s
45else
46r_num ulong s
47end
48r_say rtnl
49end
50
51note r_ask: "next"; 0 with the job in rjf, 1 no work, 2 refused or error
52fn r_ask to ulong
53nb = new uchar 16 0
54nh = new uchar 32 0
55j = new uchar 32 0
56p = new uchar 64 0
57c = new uchar 64 0
58r_mbeg rtnext
59r_mkey
60r_mtime
61x = random nb 0 16 0
62if ne x 16
63ret 2
64end
65k = r_hex nb nh 0
66r_mline rtnonce nh
67if not r_msign
68r_logt
69r_say rtlsign
70ret 2
71end
72s = r_post
73if lt s 0
74r_lognet s
75ret 2
76end
77if r_rspis rtoknone
78ret 1
79end
80if not r_rspis rtokjob
81r_logt
82r_say rtlhub
83r_rspline
84r_say rtnl
85ret 2
86end
87ok = and and r_rspfld rtjobn j r_rspfld rtpartn p r_rspfld rtcompn c
88if not ok
89ret 2
90end
91if not and and r_ishex j r_ishex p r_ishex c
92ret 2
93end
94for i ulong 32
95put rjf add rfjob i get j i
96end
97for i ulong 64
98put rjf add rfpart i get p i
99put rjf add rfcomp i get c i
100end
101ret 0
102end
103
104note r_jfeq: rjf[o, o+len t) equals t
105fn r_jfeq o ulong t view uchar * to bool
106for i ulong len t bound 256
107if ne get rjf add o i get t i
108ret false
109end
110end
111ret true
112end
113
114note r_omcok: <state>/bin/omc hashes to the pin
115fn r_omcok to bool
116h = new uchar 32 0
117x = new uchar 64 0
118n = r_path rtomc
119if not r_fsha h
120ret false
121end
122k = r_hex h x 0
123ret r_eq x rtpin
124end
125
126note r_fetch: GET /salvage/<part>/record into rrsp; its SHA-256 must be the part id and it must
127note parse as a part record (IPSLV001, kind 2, twelve field lengths that add up exactly);
128note sets the source and stdin field offsets
129fn r_fetch to bool
130pth = new uchar 128 0
131p = new uchar 64 0
132k = r_cp pth 0 rtsalv
133for i ulong 64
134put p i get rjf add rfpart i
135end
136k = r_cp pth k p
137k = r_cp pth k rtrecs
138put rgv rpost 0
139s = r_call part pth 0 k
140if ne s 200
141if ne s 404
142r_lognet s
143end
144ret false
145end
146ret r_recok p
147end
148
149fn r_recok p view uchar * to bool
150b = new uchar 65536 0
151h = new uchar 32 0
152x = new uchar 64 0
153n = get rgv rrspl
154for i ulong n bound 65536
155put b i get rrsp i
156end
157r_sha part b 0 n h
158k = r_hex h x 0
159if not r_eq x p
160ret false
161end
162if lt n 64
163ret false
164end
165if not r_eq part b 0 8 rtmagic
166ret false
167end
168if ne get b 8 2
169ret false
170end
171for i ulong 7
172if ne get b add 9 i 0
173ret false
174end
175end
176o = ulong 64
177for f ulong 12
178l = r_u32 b add 16 mul f 4
179if gt l n
180ret false
181end
182if eq f 5
183put rgv rsrco o
184put rgv rsrcn l
185end
186if eq f 7
187put rgv rstio o
188put rgv rstin l
189end
190o = add o l
191end
192ret eq o n
193end
194
195note r_rspfile: rrsp[o, o+n) into the new job file nm
196fn r_rspfile nm view uchar * o ulong n ulong to bool
197b = new uchar 65536 0
198for i ulong n bound 65536
199put b i get rrsp add o i
200end
201k = r_jpath nm
202ret r_wr part b 0 n rfonew 384
203end
204
205note r_jdir: rjd = <state>/work/<job>, a new 0700 directory
206fn r_jdir nm view uchar * to bool
207q = new uchar 4100 0
208n = r_path rtwork
209r = makedir rph 0 n 448
210if and lt r 0 ne r -17
211ret false
212end
213p = new uchar 4100 0
214pl = r_phcp p
215k = r_join part p 0 pl nm q
216if eq k 0
217ret false
218end
219x = r_rmtree part q 0 k
220r = makedir q 0 k 448
221if lt r 0
222ret false
223end
224for i ulong k bound 4100
225put rjd i get q i
226end
227put rgv rjdl k
228ret true
229end
230
231fn r_jdel to void
232q = new uchar 4100 0
233n = get rgv rjdl
234for i ulong n bound 4100
235put q i get rjd i
236end
237x = r_rmtree part q 0 n
238end
239
240note r_result: sign and post the result in rjf; 0 counted, 2 refused or error
241fn r_result to ulong
242r_mbeg rtresn
243r_mkey
244r_mjf rtjobn rfjob 32
245r_mjf rtpartn rfpart 64
246r_mjf rtcompn rfcomp 64
247r_mjf rtbinn rfbin 64
248r_mjf rtoutn rfout 64
249r_mjf rtexitn rfexit get rgv rexl
250r_mtime
251if not r_msign
252r_logt
253r_say rtlsign
254ret 2
255end
256s = r_post
257r_logt
258r_say rtlres
259r_jfsay rfpart 64
260r_say rtsp
261r_jfsay rfexit get rgv rexl
262r_say rtlarr
263if lt s 0
264r_say rtxneg
265r_num ulong neg s
266r_say rtnl
267ret 2
268end
269r_rspline
270r_say rtnl
271if r_rspis rtokcnt
272ret 0
273end
274if r_rspis rtokst
275ret 3
276end
277ret 2
278end
279
280fn r_jfsay o ulong n ulong to void
281d = new uchar 256 0
282for i ulong n bound 256
283put d i get rjf add o i
284end
285w = write 1 d 0 n
286end
287
288note r_job: one whole cycle; 0 a result was counted, 1 no work, 2 refused or error
289fn r_job to ulong
290j = new uchar 32 0
291a = r_ask
292if eq a 1
293r_logt
294r_say rtlnone
295end
296if ne a 0
297ret a
298end
299if not r_jfeq rfcomp rtpin
300r_logt
301r_say rtlpin
302ret 2
303end
304if not r_omcok
305r_logt
306r_say rtlomc
307ret 2
308end
309if not r_fetch
310r_logt
311r_say rtlrec
312ret 2
313end
314for i ulong 32
315put j i get rjf add rfjob i
316end
317if not r_jdir j
318r_logt
319r_say rtljd
320ret 2
321end
322ok = and r_rspfile rtsrc get rgv rsrco get rgv rsrcn r_rspfile rtsin get rgv rstio get rgv rstin
323if ok
324ok = r_check
325end
326r_jdel
327if not ok
328r_logt
329r_say rtlcell
330ret 2
331end
332ret r_result
333end