interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / node / journal-test.om

1136 lines · 23718 bytes Raw Blame History
1note Concatenate after transport.om, pool.om, super.om, sched.om,
2note seed/authority/action.om, journal.om and auth.om. CPU-only acceptance of
3note DRA-289: a conductor forks a creator, makes it crash at each durable and
4note effect boundary (exit 77 at jcrash points 1..6, or SIGKILL while a tool
5note runs), restarts it, and then checks the journal, the effects and the
6note recovered outcomes with its own reader (jt_load, not jn_scan).
7note Journal directory build/node/jt, relative to the repository root.
8note Job id kind*1000 + op. Tools (/bin/sh -c), all writing under the
9note directory: kind 1 appends "<op>" to sink; kind 2 sleeps 1 s first;
10note kind 3 is idempotent: it creates key k.<op> with ln (never replaces)
11note and appends "<op>" only when it did; kind 4 appends "s<op>", sleeps
12note 1 s, then acts as kind 3. Kinds 1 and 2 are class 1 (external effect),
13note kinds 3 and 4 class 3 (idempotent, decided by the key at recovery).
14text jtsh "/bin/sh"
15text jtdc "-c"
16text jtt2 "echo "
17text jtt3 " >> build/node/jt/sink"
18text jtt4 "sleep 1; "
19text jtt5 " > build/node/jt/t."
20text jtt6 " && ln build/node/jt/t."
21text jtt7 " build/node/jt/k."
22text jtt8 " && echo "
23text jtt9 "; rm -f build/node/jt/t."
24text jtts "echo s"
25text jtdir "build/node/jt"
26text jtfj "build/node/jt/journal"
27text jtfl "build/node/jt/lock"
28text jtfs "build/node/jt/sink"
29text jtfk "build/node/jt/k."
30text jtft "build/node/jt/t."
31text jtok "PASS node journal\n"
32global jtm long 1
33global jtr ulong 4096
34global jtn ulong 1
35global jtb uchar 65536
36global jtp uchar 64
37
38fn jt_ok ok bool code int to void
39if not ok
40exit code
41end
42end
43
44fn jt_tlen k ulong to ulong
45if eq k 0
46ret len jtsh
47end
48if eq k 1
49ret len jtdc
50end
51if eq k 2
52ret len jtt2
53end
54if eq k 3
55ret len jtt3
56end
57if eq k 4
58ret len jtt4
59end
60if eq k 5
61ret len jtt5
62end
63if eq k 6
64ret len jtt6
65end
66if eq k 7
67ret len jtt7
68end
69if eq k 8
70ret len jtt8
71end
72if eq k 9
73ret len jtt9
74end
75ret len jtts
76end
77
78fn jt_tb k ulong i ulong to uchar
79if eq k 0
80ret get jtsh i
81end
82if eq k 1
83ret get jtdc i
84end
85if eq k 2
86ret get jtt2 i
87end
88if eq k 3
89ret get jtt3 i
90end
91if eq k 4
92ret get jtt4 i
93end
94if eq k 5
95ret get jtt5 i
96end
97if eq k 6
98ret get jtt6 i
99end
100if eq k 7
101ret get jtt7 i
102end
103if eq k 8
104ret get jtt8 i
105end
106if eq k 9
107ret get jtt9 i
108end
109ret get jtts i
110end
111
112note Append text k to s at n; the new length.
113fn jt_add s edit uchar 1024 n ulong k ulong to ulong
114m = jt_tlen k
115for i ulong m bound 64
116put s add n i jt_tb k i
117end
118ret add n m
119end
120
121note Append the decimal v to s at n; the new length.
122fn jt_num s edit uchar 1024 n ulong v ulong to ulong
123d = new uchar 20 0
124x = v
125k = ulong 20
126for i ulong 20
127k = sub k 1
128put d k uchar add rem x 10 48
129x = div x 10
130if eq x 0
131break
132end
133end
134for i ulong sub 20 k bound 20
135put s add n i get d add k i
136end
137ret add n sub 20 k
138end
139
140note The idempotent part: echo N > t.N && ln t.N k.N && echo N >> sink; rm -f t.N
141fn jt_keyed s edit uchar 1024 n ulong op ulong to ulong
142m = jt_add s n 2
143m = jt_num s m op
144m = jt_add s m 5
145m = jt_num s m op
146m = jt_add s m 6
147m = jt_num s m op
148m = jt_add s m 7
149m = jt_num s m op
150m = jt_add s m 8
151m = jt_num s m op
152m = jt_add s m 3
153m = jt_add s m 9
154ret jt_num s m op
155end
156
157fn jt_script kind ulong op ulong s edit uchar 1024 to ulong
158n = ulong 0
159if eq kind 4
160n = jt_add s n 10
161n = jt_num s n op
162n = jt_add s n 3
163put s n 59
164put s add n 1 32
165n = add n 2
166end
167if or eq kind 2 eq kind 4
168n = jt_add s n 4
169end
170if ge kind 3
171ret jt_keyed s n op
172end
173n = jt_add s n 2
174n = jt_num s n op
175ret jt_add s n 3
176end
177
178note Packed argv: /bin/sh -c <script>.
179fn jt_pack kind ulong op ulong pk edit uchar 4096 to ulong
180s = new uchar 1024 0
181m = jt_script kind op s
182put pk 0 3
183put pk 1 0
184w = ulong 2
185for a ulong 2
186k = jt_tlen a
187put pk w uchar k
188put pk add w 1 0
189for i ulong k bound 16
190put pk add add w 2 i jt_tb a i
191end
192w = add add w 2 k
193end
194put pk w uchar and m 255
195put pk add w 1 uchar shr m 8
196for i ulong m bound 1024
197put pk add add w 2 i get s i
198end
199ret add add w 2 m
200end
201
202fn jt_job c long w ulong q ulong to void
203op = new ulong 4 0
204pk = new uchar 4096 0
205out = new uchar 4096 0
206id = sc_cell w 8
207kind = div id 1000
208cl = ulong 1
209if ge kind 3
210cl = 3
211end
212put op 0 rem id 1000
213put op 1 7
214put op 2 1
215put op 3 1
216r = auth_propose w q op cl
217v = auth_wdecide c w q 30000000000
218if ne v 0
219r = sched_wdone w q add 16 ulong v out 0
220ret
221end
222pn = jt_pack kind rem id 1000 pk
223o = auth_wtool c w q pk pn cl
224r = auth_wreport w q ulong o
225r = sched_wdone w q ulong o out 0
226end
227
228fn jt_worker c long w ulong to int
229for it ulong 1000000000
230q = sched_wjob w
231if gt q 0
232jt_job c w q
233end
234r = auth_wwait c w neg int 1 1000000000
235if or eq r 2 eq r 3
236ret 0
237end
238if eq r 4
239t = auth_wctl w
240end
241if lt r 0
242ret 45
243end
244end
245ret 46
246end
247
248note Job set js: its i-th job id, 0 past the end.
249fn jt_jobid js ulong i ulong to ulong
250if eq js 1
251if eq i 0
252ret 1001
253end
254end
255if eq js 2
256if eq i 0
257ret 3002
258end
259end
260if eq js 3
261if eq i 0
262ret 1001
263end
264if eq i 1
265ret 3002
266end
267end
268if eq js 4
269if eq i 0
270ret 4003
271end
272end
273if eq js 5
274if eq i 0
275ret 2004
276end
277end
278ret 0
279end
280
281fn jt_open ob ulong ms ulong to ulong
282d = new uchar 128 0
283o = new ulong 4 0
284n = len jtdir
285for i ulong n bound 128
286put d i get jtdir i
287end
288put o 0 ob
289put o 1 7
290put o 2 7
291put o 3 7
292ret jn_open d n o ms
293end
294
295note Creator steps until every job of set js is released, up to 20 s.
296fn jt_drive c long js ulong to int
297dl = add ulong monons 20000000000
298for t ulong 100000000
299r = sched_step c 5000000
300k = auth_step c
301for j ulong 64
302if eq get sjst j 4
303x = jn_release j
304end
305end
306all = true
307for i ulong 8
308id = jt_jobid js i
309if and gt id 0 not jn_done_j id
310all = false
311end
312end
313if all
314ret 0
315end
316if ge ulong monons dl
317ret 62
318end
319end
320ret 62
321end
322
323note Creator process: open the journal (lock wait 3 s, 100 ms when fl bit 4),
324note recover, spawn two workers, admit the jobs of set js the journal does
325note not know, run to completion. fl bit 1: pause, then exit cleanly. fl bit
326note 2: check that the journaled pause survived the restart, then resume.
327note Exit 77 at crash point cp; journal refusals exit with their code.
328fn jt_run cp ulong js ulong ob ulong fl ulong to int
329c = pool_new 4 2
330jt_ok gt c 0 50
331jt_ok eq sup_init c 0 51
332jt_ok eq sched_new c 8 8 0 52
333jt_ok eq auth_new c 0 53
334ms = ulong 3000
335if ne and fl 4 0
336ms = 100
337end
338e = jt_open ob ms
339if ne e 0
340ret int e
341end
342put jcrash 0 cp
343e = auth_recover c
344if ne e 0
345ret int add 33 e
346end
347for w ulong 2
348p = auth_spawn c w
349if eq p 0
350exit jt_worker c w
351end
352jt_ok gt p 0 54
353end
354for i ulong 8
355id = jt_jobid js i
356if and gt id 0 not jn_known id
357jt_ok ge jn_admit id 0 0 0 55
358end
359end
360if ne and fl 1 0
361k = auth_pause c true
362jn_close
363ret 0
364end
365if ne and fl 2 0
366for t ulong 60
367r = sched_step c 5000000
368k = auth_step c
369end
370jt_ok eq sched_count 3 3 0 61
371jt_ok eq get scpause 0 1 61
372k = auth_pause c false
373end
374e = ulong jt_drive c js
375if ne e 0
376ret int e
377end
378r = sched_stop c 2000000000
379sup_closeall
380jn_close
381ret 0
382end
383
384fn jt_fork cp ulong js ulong ob ulong fl ulong to long
385p = fork
386if eq p 0
387exit jt_run cp js ob fl
388end
389ret p
390end
391
392fn jt_reap p long to ulong
393ws = new uchar 4 0
394g = waitpid int p ws 0 4 0
395if le g 0
396ret 999
397end
398if ne and get ws 0 127 0
399ret add 128 ulong and get ws 0 127
400end
401ret ulong get ws 1
402end
403
404fn jt_runc cp ulong js ulong ob ulong fl ulong to ulong
405ret jt_reap jt_fork cp js ob fl
406end
407
408note Path prefix k (0 journal, 1 lock, 2 sink, 3 key prefix, 4 temp
409note prefix), with the decimal v appended for 3 and 4, in jtp; the length.
410fn jt_path k ulong v ulong to ulong
411s = new uchar 1024 0
412n = ulong 0
413if eq k 0
414n = len jtfj
415for i ulong n bound 64
416put s i get jtfj i
417end
418end
419if eq k 1
420n = len jtfl
421for i ulong n bound 64
422put s i get jtfl i
423end
424end
425if eq k 2
426n = len jtfs
427for i ulong n bound 64
428put s i get jtfs i
429end
430end
431if eq k 3
432n = len jtfk
433for i ulong n bound 64
434put s i get jtfk i
435end
436end
437if eq k 4
438n = len jtft
439for i ulong n bound 64
440put s i get jtft i
441end
442end
443if ge k 3
444n = jt_num s n v
445end
446for i ulong n bound 64
447put jtp i get s i
448end
449ret n
450end
451
452fn jt_clean to void
453for k ulong 3
454n = jt_path k 0
455r = unlink jtp 0 n
456end
457for v ulong 5
458for k ulong 2
459n = jt_path add k 3 v
460r = unlink jtp 0 n
461end
462end
463end
464
465fn jt_exists k ulong v ulong to bool
466st = new uchar 128 0
467n = jt_path k v
468ret eq stat jtp 0 n st 0 128 0
469end
470
471note Read file k (0 journal, 2 sink) into jtb; the byte count.
472fn jt_slurp k ulong to ulong
473n = jt_path k 0
474fd = fopen jtp 0 n 524288 0
475if lt fd 0
476ret 0
477end
478t = ulong 0
479for i ulong 4096
480g = read int fd jtb t sub 65536 t
481if le g 0
482break
483end
484t = add t ulong g
485end
486r = fclose int fd
487ret t
488end
489
490fn jt_w o ulong to ulong
491v = ulong 0
492for k ulong 8
493v = or v shl ulong get jtb add o k mul k 8
494end
495ret v
496end
497
498note Independent reader: the journal is well formed for objective ob: exact
499note size, header, every record's checksum and seq, each OPEN raises the
500note fence by one and every other record carries the current fence.
501note Records go to jtr, count in jtn.
502fn jt_load ob ulong to bool
503r = new ulong 16 0
504sz = jt_slurp 0
505if or lt sz 64 ne rem sub sz 64 128 0
506ret false
507end
508for i ulong 8
509put r i jt_w mul i 8
510end
511if or ne get r 0 5786624599 or ne get r 3 ob ne get r 7 jn_sum r 7
512ret false
513end
514n = div sub sz 64 128
515if gt n 256
516ret false
517end
518fe = ulong 0
519for i ulong n bound 256
520for k ulong 16
521put r k jt_w add add 64 mul i 128 mul k 8
522put jtr add mul i 16 k get r k
523end
524s = jn_sum r 15
525if or ne get r 15 s ne get r 1 add i 1
526ret false
527end
528if eq get r 0 1
529if ne get r 2 add fe 1
530ret false
531end
532fe = get r 2
533end
534if ne get r 2 fe
535ret false
536end
537end
538put jtn 0 n
539ret true
540end
541
542fn jt_rw i ulong k ulong to ulong
543ret get jtr add mul i 16 k
544end
545
546note Records of type t whose word 3 is v (all when v is 0).
547fn jt_cnt t ulong v ulong to ulong
548n = ulong 0
549for i ulong get jtn 0 bound 256
550if and eq jt_rw i 0 t or eq v 0 eq jt_rw i 3 v
551n = add n 1
552end
553end
554ret n
555end
556
557note Per operation: a START only when none is open and no DONE said
558note performed or UNKNOWN; every START closed by exactly one DONE.
559fn jt_order op ulong to bool
560open = false
561shut = false
562for i ulong get jtn 0 bound 256
563t = jt_rw i 0
564if and eq jt_rw i 3 op or eq t 3 eq t 4
565if eq t 3
566if or open shut
567ret false
568end
569open = true
570else
571if not open
572ret false
573end
574open = false
575o = jt_rw i 7
576if or eq o 0 eq o 2
577shut = true
578end
579end
580end
581end
582ret not open
583end
584
585note Outcome of the only RELEASE of job id; 999 when there is none, 998
586note when there are several.
587fn jt_rel id ulong to ulong
588o = ulong 999
589for i ulong get jtn 0 bound 256
590if and eq jt_rw i 0 5 eq jt_rw i 3 id
591if ne o 999
592ret 998
593end
594o = jt_rw i 4
595end
596end
597ret o
598end
599
600fn jt_lineq st ulong m ulong t view uchar 1024 to bool
601for k ulong m bound 64
602if ne get jtb add st k get t k
603ret false
604end
605end
606ret true
607end
608
609note Lines of the sink equal to the decimal v (prefixed "s" when s).
610fn jt_sink v ulong s bool to ulong
611t = new uchar 1024 0
612m = ulong 0
613if s
614put t 0 115
615m = 1
616end
617m = jt_num t m v
618sz = jt_slurp 2
619n = ulong 0
620st = ulong 0
621for i ulong sz bound 65536
622if eq get jtb i 10
623if and eq sub i st m jt_lineq st m t
624n = add n 1
625end
626st = add i 1
627end
628end
629ret n
630end
631
632note Checks shared by every case for operation op of job id: a well-formed
633note journal for objective 1, ordered transitions, one RELEASE with outcome
634note o, s sink lines. Exit base+1..base+4.
635fn jt_common id ulong o ulong s ulong base int to void
636jt_ok jt_load 1 add base 1
637jt_ok jt_order rem id 1000 add base 2
638jt_ok eq jt_rel id o add base 3
639jt_ok eq jt_sink rem id 1000 false s add base 4
640end
641
642note Run once with crash point cp (exit 77), then restart to completion.
643fn jt_crash cp ulong js ulong base int to void
644jt_clean
645jt_ok eq jt_runc cp js 1 0 77 base
646jt_ok eq jt_runc 0 js 1 0 0 add base 5
647end
648
649note Case 0, baseline: both jobs performed once; the key exists.
650fn jt_c0 to void
651jt_clean
652jt_ok eq jt_runc 0 3 1 0 0 10
653jt_common 1001 2 1 10
654jt_common 3002 2 1 15
655jt_ok jt_exists 3 2 19
656end
657
658note Case 1, crash after ADMIT is durable: the admitted job is admitted again
659note and the unadmitted one admitted; each performed once.
660fn jt_c1 to void
661jt_crash 1 3 20
662jt_common 1001 2 1 20
663jt_ok eq jt_cnt 2 1001 1 26
664jt_ok eq jt_cnt 3 1 1 27
665jt_ok eq jt_rel 3002 2 28
666jt_ok eq jt_sink 2 false 1 29
667end
668
669note Case 2, crash after START is durable, before the grant is published:
670note class 1 is UNKNOWN, never run, and two more restarts add no transition.
671fn jt_c2 to void
672jt_crash 2 1 30
673jt_common 1001 0 0 30
674x = get jtn 0
675o = jt_cnt 1 0
676jt_ok eq jt_runc 0 1 1 0 0 36
677jt_ok eq jt_runc 0 1 1 0 0 36
678jt_ok jt_load 1 37
679jt_ok eq sub get jtn 0 jt_cnt 1 0 sub x o 38
680jt_ok eq jt_cnt 1 0 add o 2 39
681end
682
683note Case 3, the same crash for class 3: the key is absent, so not performed;
684note run again (attempt 2) and performed once.
685fn jt_c3 to void
686jt_crash 2 2 40
687jt_common 3002 2 1 40
688jt_ok eq jt_cnt 3 2 2 46
689jt_ok jt_exists 3 2 47
690end
691
692note Case 4, crash after the report, before DONE: class 1 performed but
693note UNKNOWN, never run again.
694fn jt_c4 to void
695jt_crash 3 1 50
696jt_common 1001 0 1 50
697jt_ok eq jt_cnt 3 1 1 56
698end
699
700note Case 5, the same for class 3: the key is present, so performed.
701fn jt_c5 to void
702jt_crash 3 2 60
703jt_common 3002 2 1 60
704jt_ok eq jt_cnt 3 2 1 66
705end
706
707note Case 6, crash after DONE, before RELEASE: released as performed.
708fn jt_c6 to void
709jt_crash 4 1 70
710jt_common 1001 2 1 70
711jt_ok eq jt_cnt 3 1 1 76
712end
713
714note Case 7, crash after RELEASE: nothing left to do.
715fn jt_c7 to void
716jt_crash 5 1 80
717jt_common 1001 2 1 80
718jt_ok eq jt_cnt 4 1 1 86
719end
720
721note Case 8, a torn DONE: 60 bytes of it on disk after the crash; the
722note restart cuts them and the operation is UNKNOWN.
723fn jt_c8 to void
724jt_clean
725jt_ok eq jt_runc 6 1 1 0 77 90
726sz = jt_slurp 0
727jt_ok eq rem sub sz 64 128 60 96
728jt_ok eq jt_runc 0 1 1 0 0 95
729jt_common 1001 0 1 90
730end
731
732note Wait until the journal holds a START, up to ms.
733fn jt_started ms ulong to bool
734for t ulong ms bound 100000
735if jt_load 1
736if gt jt_cnt 3 0 0
737ret true
738end
739end
740r = sleepns 1000000
741end
742ret false
743end
744
745note Cases 9 and 10, SIGKILL of the creator while a slow tool runs. Its
746note workers kill the tool. Class 3: run again and performed once (two tool
747note starts). Class 1: UNKNOWN, no effect, never run again.
748fn jt_c9 to void
749jt_clean
750p = jt_fork 0 4 1 0
751jt_ok jt_started 5000 120
752r = sleepns 100000000
753jt_ok eq killpid int p 9 0 120
754jt_ok eq jt_reap p 137 120
755jt_ok eq jt_runc 0 4 1 0 0 125
756jt_common 4003 2 1 120
757jt_ok eq jt_cnt 3 3 2 126
758jt_ok eq jt_sink 3 true 2 127
759jt_ok jt_exists 3 3 128
760end
761
762fn jt_c10 to void
763jt_clean
764p = jt_fork 0 5 1 0
765jt_ok jt_started 5000 130
766r = sleepns 100000000
767jt_ok eq killpid int p 9 0 130
768jt_ok eq jt_reap p 137 130
769jt_ok eq jt_runc 0 5 1 0 0 135
770jt_common 2004 0 0 130
771jt_ok eq jt_cnt 3 4 1 136
772end
773
774note Case 11, fencing: while a creator runs a tool, a second creator on the
775note same directory is refused (20) and the journal is unchanged.
776fn jt_c11 to void
777jt_clean
778p = jt_fork 0 4 1 0
779jt_ok jt_started 5000 140
780a = jt_slurp 0
781jt_ok eq jt_runc 0 4 1 4 20 141
782jt_ok eq jt_slurp 0 a 142
783jt_ok eq jt_reap p 0 143
784jt_common 4003 2 1 140
785end
786
787note Cases 12 to 14 on a finished baseline directory: another objective
788note (22), a header from another format version (21) and a corrupt record
789note before the last (23) are refused, and the journal is unchanged.
790fn jt_c12 to void
791b = new uchar 128 0
792h = new ulong 16 0
793jt_clean
794jt_ok eq jt_runc 0 1 1 0 0 150
795a = jt_slurp 0
796jt_ok eq jt_runc 0 1 2 0 22 151
797jt_ok eq jt_slurp 0 a 152
798n = jt_path 0 0
799fd = fopen jtp 0 n 524290 0
800jt_ok ge fd 0 153
801jt_ok eq pread int fd b 0 64 0 64 153
802jn_dec b h
803put h 1 3
804put h 7 jn_sum h 7
805jn_enc h b
806jt_ok eq pwrite int fd b 0 64 0 64 153
807jt_ok eq jt_runc 0 1 1 0 21 154
808jt_ok eq jt_slurp 0 a 155
809put h 1 2
810put h 7 jn_sum h 7
811jn_enc h b
812jt_ok eq pwrite int fd b 0 64 0 64 156
813jt_ok eq pread int fd b 0 1 212 1 156
814put b 0 uchar xor get b 0 1
815jt_ok eq pwrite int fd b 0 1 212 1 156
816r = fclose int fd
817jt_ok eq jt_runc 0 1 1 0 23 157
818jt_ok eq jt_slurp 0 a 158
819end
820
821note Case 15, pause survives a restart: no job starts until resumed.
822fn jt_c15 to void
823jt_clean
824jt_ok eq jt_runc 0 1 1 1 0 160
825jt_ok eq jt_runc 0 1 1 2 0 161
826jt_common 1001 2 1 160
827jt_ok eq jt_cnt 7 0 2 166
828end
829
830note Case 16, RESULT (type 10, DRA-292): an objective's result survives a
831note reopen; a second result for it, result 0 and an index past 63 are
832note refused with 25 before any write, so the file holds exactly one RESULT.
833fn jt_c16 to void
834jt_clean
835jt_ok eq jt_open 9 0 0 170
836jt_ok eq jn_result 3 15 4 0 171
837jt_ok eq jn_res 3 15 172
838jt_ok eq jn_result 3 1 2 25 173
839jt_ok eq jn_result 5 0 2 25 174
840jt_ok eq jn_result 64 1 2 25 175
841jt_ok eq jn_res 5 0 176
842jn_close
843jt_ok eq jt_open 9 0 0 177
844jt_ok eq jn_res 3 15 178
845jt_ok eq jn_rturn 3 4 179
846jt_ok eq jn_result 3 15 4 25 180
847jn_close
848jt_ok jt_load 9 181
849jt_ok eq jt_cnt 10 0 1 182
850jt_ok eq jt_cnt 10 3 1 183
851jt_ok eq jt_cnt 1 0 2 184
852end
853
854note Case 17, admission at the limit (P-DRA-14, DRA-396): with admission
855note limit 2 full, a duplicate id is refused as a duplicate (-4) and takes
856note no ticket (185, 186); a new id is refused and takes one (187); once a
857note slot frees (cancelled as auth_cancel does: CANCEL, then RELEASE), the
858note duplicate asking again does not hold it up: the ticket holder enters
859note (188). Nothing is spawned; the journal is real.
860fn jt_c17 to void
861jt_clean
862c = pool_new 2 2
863jt_ok gt c 0 185
864jt_ok eq sup_init c 0 185
865jt_ok eq sched_new c 2 8 0 185
866jt_ok eq jt_open 1 3000 0 185
867a = jn_admit 7001 0 0
868jt_ok ge a 0 185
869jt_ok ge jn_admit 7002 0 0 0 185
870jt_ok eq jn_admit 7001 0 0 neg long 4 185
871jt_ok eq sched_stat 30 0 186
872jt_ok eq jn_admit 7003 0 0 neg long 2 187
873jt_ok eq sched_stat 30 1 187
874jt_ok eq jn_rec 8 7001 0 0 0 188
875jt_ok eq sched_cancel ulong a 1 188
876jt_ok eq jn_rec 5 7001 300 0 0 188
877jt_ok eq jn_admit 7001 0 0 neg long 4 188
878jt_ok ge jn_admit 7003 0 0 0 188
879jn_close
880jt_clean
881end
882
883note Case 18, a full table below the admission limit (P-DRA-14, DRA-396):
884note limit 64, 64 jobs admitted and then put in UNKNOWN directly, the state
885note a worker loss leaves a job not safe to rerun in (synthetic occupancy:
886note nothing is spawned, no recovery runs), so no job is active and no slot
887note is free. A new id is refused with a ticket, the journal does not grow
888note and no ADMIT for it reaches the journal (189, 190, the last checked by
889note the independent reader). Settling one job (its RELEASE journaled
890note first, so the journal frees the slot too) frees its slot and the same
891note id is admitted and journaled once (191, 192).
892fn jt_c18 to void
893jt_clean
894c = pool_new 2 2
895jt_ok gt c 0 189
896jt_ok eq sup_init c 0 189
897jt_ok eq sched_new c 64 64 0 189
898jt_ok eq jt_open 1 3000 0 189
899for i ulong 64
900jt_ok ge jn_admit add 8001 i 0 0 0 189
901end
902for j ulong 64
903put sjst j 6
904end
905jt_ok eq sched_count 0 0 0 189
906q = get jseq 0
907jt_ok eq jn_admit 9001 0 0 neg long 2 189
908jt_ok eq sched_stat 30 1 189
909jt_ok eq get jseq 0 q 190
910jt_ok not jn_known 9001 190
911jt_ok jt_load 1 190
912jt_ok eq jt_cnt 2 0 64 190
913jt_ok eq jt_cnt 2 9001 0 190
914jt_ok eq jn_rec 5 get sjid 5 0 0 0 191
915jt_ok eq sched_settle 5 0 191
916jt_ok ge jn_admit 9001 0 0 0 191
917jt_ok jn_known 9001 192
918jt_ok jt_load 1 192
919jt_ok eq jt_cnt 2 9001 1 192
920jt_ok eq jt_cnt 2 0 65 192
921jn_close
922jt_clean
923end
924
925note Case 19's raw journals, written as a creator of that format would:
926note jt_rnew starts the file afresh with a header of version v for the
927note objective jt_open 1 names and keeps it open in jtrd; jt_raw writes
928note record i (seq i + 1) of type t under fence f with words 3..5; jt_rend
929note closes it and returns its size.
930global jtrd int 1
931fn jt_rnew v ulong to void
932d = new uchar 128 0
933n = len jtdir
934for i ulong n bound 128
935put d i get jtdir i
936end
937x = makedir d 0 n 448
938jt_clean
939m = jt_path 0 0
940fd = fopen jtp 0 m 524354 384
941jt_ok ge fd 0 193
942put jtrd 0 int fd
943h = new ulong 16 0
944b = new uchar 128 0
945put h 0 5786624599
946put h 1 v
947put h 2 128
948put h 3 1
949put h 4 7
950put h 5 7
951put h 6 7
952put h 7 jn_sum h 7
953jn_enc h b
954jt_ok eq pwrite get jtrd 0 b 0 64 0 64 193
955end
956
957global jtrr ulong 16
958fn jt_raw i ulong t ulong f ulong a ulong b ulong c ulong to void
959put jtrr 0 t
960put jtrr 1 add i 1
961put jtrr 2 f
962put jtrr 3 a
963put jtrr 4 b
964put jtrr 5 c
965jt_rput i
966end
967
968fn jt_rput i ulong to void
969r = new ulong 16 0
970x = new uchar 128 0
971for k ulong 15
972put r k get jtrr k
973end
974put r 15 jn_sum r 15
975jn_enc r x
976o = long add 64 mul i 128
977jt_ok eq pwrite get jtrd 0 x 0 128 o 128 193
978end
979
980fn jt_rend to ulong
981x = fclose get jtrd 0
982ret jt_slurp 0
983end
984
985note Case 19, a format-1 journal continued (DRA-292's release acceptance
986note runs a format-1 build's journal forward): a version-1 file written as
987note the format-1 creator (79894168) writes it: OPEN (word 5 zero), ADMIT
988note 6001 and 6002, CANCEL 6001, ADMIT 6003, OPEN, RELEASE 6001 cancelled,
989note ADMIT 6004. This build opens it (193). The format-1 jobs replay with
990note request 0 into the lowest slot no unreleased job holds: 6002 in 1,
991note 6003 in 2 (6001, cancelled but not yet released, keeps 0), 6004 in 0
992note (194). The header is unchanged; FORMAT under the last fence, then OPEN
993note with SPVER, are appended and the independent reader accepts the file
994note (195). A second open appends one more OPEN and no second FORMAT (196);
995note recovery admits the jobs into those slots (197). Refused with the file
996note unchanged: a format-1 OPEN after FORMAT, an OPEN with SPVER before
997note FORMAT in a version-1 file, a FORMAT or a format-1 OPEN in a version-2
998note file (198, all 33); a GOAL in a format-1 incarnation (199, 25); a 65th
999note live format-1 job, no slot left (200, 25).
1000fn jt_c19 to void
1001jt_rnew 1
1002jt_raw 0 1 1 111 1 0
1003jt_raw 1 2 1 6001 0 0
1004jt_raw 2 2 1 6002 0 0
1005jt_raw 3 8 1 6001 0 0
1006jt_raw 4 2 1 6003 0 0
1007jt_raw 5 1 2 112 2 0
1008jt_raw 6 5 2 6001 300 0
1009jt_raw 7 2 2 6004 0 0
1010a = jt_rend
1011hb = new uchar 64 0
1012for i ulong 64
1013put hb i get jtb i
1014end
1015jt_ok eq jt_open 1 3000 0 193
1016jt_ok jt_rslot 6002 1 194
1017jt_ok jt_rslot 6003 2 194
1018jt_ok jt_rslot 6004 0 194
1019jn_close
1020jt_ok jt_load 1 195
1021jt_ok eq jt_slurp 0 add a 256 195
1022jt_ok jt_rsame hb 195
1023jt_ok eq jt_rw 8 0 14 195
1024jt_ok eq jt_rw 8 3 2 195
1025jt_ok eq jt_rw 8 2 2 195
1026jt_ok eq jt_rw 9 0 1 195
1027jt_ok eq jt_rw 9 5 SPVER 195
1028jt_ok eq jt_rw 9 2 3 195
1029jt_ok eq jt_open 1 3000 0 196
1030jn_close
1031jt_ok jt_load 1 196
1032jt_ok eq jt_cnt 14 0 1 196
1033jt_ok eq jt_cnt 1 0 4 196
1034jt_c19r
1035jt_c19x
1036jt_clean
1037end
1038
1039note Case 19: the replayed job id holds slot s with request 0.
1040fn jt_rslot id ulong s ulong to bool
1041k = jn_jfind id
1042if lt k 0
1043ret false
1044end
1045ret and eq get jslot ulong k s eq get jreq ulong k 0
1046end
1047
1048note Case 19: the journal read last (jtb) starts with header hb.
1049fn jt_rsame hb view uchar 64 to bool
1050for i ulong 64
1051if ne get jtb i get hb i
1052ret false
1053end
1054end
1055ret true
1056end
1057
1058note Case 19: recovery admits the format-1 jobs into their replay slots.
1059fn jt_c19r to void
1060c = pool_new 2 2
1061jt_ok gt c 0 197
1062jt_ok eq sup_init c 0 197
1063jt_ok eq sched_new c 64 64 0 197
1064jt_ok eq jt_open 1 3000 0 197
1065jt_ok eq jn_recover c 0 197
1066jt_ok eq get sjid 1 6002 197
1067jt_ok eq get sjid 2 6003 197
1068jt_ok eq get sjid 0 6004 197
1069jn_close
1070end
1071
1072note Case 19: the raw file just written is refused with e and unchanged.
1073fn jt_rref e ulong code int to void
1074a = jt_rend
1075jt_ok eq jt_open 1 3000 e code
1076jt_ok eq jt_slurp 0 a code
1077end
1078
1079note Case 19's refusals.
1080fn jt_c19x to void
1081jt_rnew 1
1082jt_raw 0 1 1 111 1 0
1083jt_raw 1 14 1 2 0 0
1084jt_raw 2 1 2 112 2 0
1085jt_rref 33 198
1086jt_rnew 1
1087jt_raw 0 1 1 111 1 0
1088jt_raw 1 1 2 112 2 SPVER
1089jt_rref 33 198
1090jt_rnew 2
1091jt_raw 0 1 1 111 1 SPVER
1092jt_raw 1 14 1 2 0 0
1093jt_rref 33 198
1094jt_rnew 2
1095jt_raw 0 1 1 111 1 0
1096jt_rref 33 198
1097jt_rnew 1
1098jt_raw 0 1 1 111 1 0
1099jt_raw 1 2 1 6001 0 0
1100jt_raw 2 12 1 6001 1 5
1101jt_rref 25 199
1102jt_rnew 1
1103jt_raw 0 1 1 111 1 0
1104for i ulong 65
1105jt_raw add i 1 2 1 add 7001 i 0 0
1106end
1107jt_rref 25 200
1108end
1109
1110fn main to int
1111m = mapnew neg int 1 0 4096 3 33
1112jt_ok gt m 0 9
1113put jtm 0 m
1114jt_c0
1115jt_c1
1116jt_c2
1117jt_c3
1118jt_c4
1119jt_c5
1120jt_c6
1121jt_c7
1122jt_c8
1123jt_c9
1124jt_c10
1125jt_c11
1126jt_c12
1127jt_c15
1128jt_c16
1129jt_c17
1130jt_c18
1131jt_c19
1132if ne write 1 jtok 0 len jtok long len jtok
1133ret 100
1134end
1135ret 0
1136end