urbit/pkg/base-dev/sur/hood.hoon

318 lines
8.1 KiB
Plaintext
Raw Normal View History

=, clay
=* dude dude:gall
|%
2021-09-28 22:33:16 +03:00
:: $snap: kiln snapshot
::
+$ snap (map desk arak)
:: $diff: subscription update
::
+$ diff
$% [%block =desk =arak =weft blockers=(set desk)]
[%reset =desk =arak]
2021-09-15 22:57:08 +03:00
[%commit =desk =arak]
[%merge-sunk =desk =arak =tang]
[%merge-fail =desk =arak =tang]
[%suspend =desk =arak]
[%revive =desk =arak]
==
:: $arak: foreign vat tracker
::
2021-09-06 17:27:17 +03:00
:: .rail: upstream tracking state, if any
:: .rein: configuration for agents
::
+$ arak
$: rail=(unit rail)
2021-09-06 17:27:17 +03:00
=rein
==
:: $rail: upstream tracking state
::
:: .publisher: Ship that originally published desk, if available
:: .paused: is tracking paused? or live
:: .ship: upstream ship (could be .our)
:: .desk: name of upstream desk
:: .aeon: next aeon to pull from upstream
:: .next: list of pending commits with future kelvins
::
2021-09-06 17:27:17 +03:00
+$ rail
$: publisher=(unit ship)
paused=?
2021-09-06 17:27:17 +03:00
=ship
=desk
=aeon
next=(list rung)
==
2021-09-06 17:27:17 +03:00
:: $rung: reference to upstream commit
::
+$ rung [=aeon =weft]
:: $rein: diff from desk manifest
::
:: .liv: suspended? if suspended, no agents should run
:: .add: agents not in manifest that should be running
:: .sub: agents in manifest that should not be running
::
+$ rein
$: liv=_&
add=(set dude)
sub=(set dude)
==
::
+$ vat [=desk hash=@uv =cass =arak]
:: +report-vats: report on all desk installations
::
++ report-vats
|= [our=@p now=@da]
^- tang
=+ .^ raz=(list vat)
%gx /(scot %p our)/hood/(scot %da now)/kiln/vats/noun
==
2021-10-01 15:14:10 +03:00
:- (report-kids our now)
(turn raz |=(v=vat (report-vat our now v)))
:: +report-vat: report on a single desk installation
::
++ report-vat
|= [our=ship now=@da vat]
^- tank
?: =(ud.cass 0)
leaf+"desk does not yet exist: {<desk>}"
2021-09-22 06:20:05 +03:00
=/ kel-path
/(scot %p our)/[desk]/(scot %da now)/sys/kelvin
?. .^(? %cu kel-path)
leaf+"bad desk: {<desk>}"
=+ .^(=weft %cx kel-path)
:+ %rose ["" "{<desk>}" "::"]
^- tang
=/ meb (mergebase-hashes our desk now arak)
=/ poz
?~ rail.arak "local"
?:(paused.u.rail.arak "paused" "tracking")
=/ sat ?:(liv.rein.arak "running" "suspended")
=/ pen
?~ rail.arak "~"
<(turn next.u.rail.arak |=([@ lal=@tas num=@] [lal num]))>
2021-09-25 23:15:55 +03:00
:~ leaf/"/sys/kelvin: {<[lal num]:weft>}"
leaf/"base hash: {?.(=(1 (lent meb)) <meb> <(head meb)>)}"
leaf/"%cz hash: {<hash>}"
::
leaf/"app status: {sat}"
leaf/"force on: {?:(=(~ add.rein.arak) "~" <add.rein.arak>)}"
leaf/"force off: {?:(=(~ sub.rein.arak) "~" <sub.rein.arak>)}"
::
leaf/"publishing ship: {?~(rail.arak <~> <publisher.u.rail.arak>)}"
2021-09-25 23:15:55 +03:00
leaf/"updates: {poz}"
leaf/"source ship: {?~(rail.arak <~> <ship.u.rail.arak>)}"
leaf/"source desk: {?~(rail.arak <~> <desk.u.rail.arak>)}"
leaf/"source aeon: {?~(rail.arak <~> <aeon.u.rail.arak>)}"
leaf/"pending updates: {pen}"
==
:: +report-kids: non-vat cz hash report for kids desk
::
++ report-kids
|= [our=ship now=@da]
^- tank
=/ dek %kids
=/ ego (scot %p our)
=/ wen (scot %da now)
?. (~(has in .^((set desk) %cd /[ego]//[wen])) dek)
leaf/"no %kids desk"
=+ .^(hash=@uv %cz /[ego]/[dek]/[wen])
leaf/"%kids %cz hash: {<hash>}"
:: +read-kelvin-foreign: read /sys/kelvin from a foreign desk
::
++ read-kelvin-foreign
|= [=ship =desk =aeon]
^- weft
2021-09-29 21:59:13 +03:00
~| read-foreign-kelvin/+<
=/ her (scot %p ship)
=/ syd (scot %tas desk)
=/ yon (scot %ud aeon)
::
=/ dom .^(dome cv/~[her syd yon])
=/ tak (scot %uv (~(got by hit.dom) let.dom))
=/ yak .^(yaki cs/~[her syd yon %yaki tak])
=/ lob (scot %uv (~(got by q.yak) /sys/kelvin))
=/ bob .^(blob cs/~[her syd yon %blob lob])
::
;; weft
?- -.bob
%direct q.q.bob
%delta q.r.bob
clay: Add support for representing tombstones This adds support for tombstoned files to clay. It does not include any way to actually tombstone them; that is left for later. This allows tombstoning at the level of a file. Precisely, this expands +blob:clay by adding a %dead case: +$ blob :: fs blob $% [%delta p=lobe q=[p=mark q=lobe] r=page] :: delta on q [%direct p=lobe q=page] :: immediate [%dead p=lobe ~] :: tombstone == :: Thus, we maintain the invariant that every lobe corresponds to a blob, but now a blob may be an explicit tombstone. Details: - This has not been tested at all, except that it compiles and boots. - This does not have a state adapter from master. The only state change is the definition of +cach. - Additionally, out-of-date ships may unexpectedly receive a %dead blob from a foreign clay which would interfere with their ability to download that desk. No code changes necessary, but sponsors should avoid tombstoning files in %base for a while so their children can get the update. - A merge will only fail if the tombstoned file conflicts with another change. Note that as written, merging from a past desk *can* bring a tombstoned file to the head of a desk. Possibly this shouldn't be allowed. This also includes a couple refactors that were made possible by ford fusion (since everything is synchronous now) but never got done. In both cases we get to remove a monad, which simplifies the code considerably. - refactor +merge's error handling to use !!/mule instead of threading through errors - refactor all +read-* functions and related parts of +try-fill-sub to eagerly convert lobes to cages. We also add support reading %a/b/c/e/f/r/x from past and foreign desks, when possible. Apologies that all of these are in one commit, it was all a single chunk of work. This is a draft until we have a way to tombstone. I suspect we'll want to have a mechanism of keeping track of gc roots and trace to remove, but this PR doesn't suggest any particular strategy.
2021-11-08 09:17:02 +03:00
%dead ~|(%tombstoned-kelvin !!)
==
:: +read-kelvin-local: read /sys/kelvin from a local desk
::
++ read-kelvin-local
|= [our=ship =desk now=@da]
^- (unit weft)
~| read-kelvin-local+desk
=/ pax (en-beam [our desk da+now] /sys/kelvin)
?. .^(? cu/pax)
~
[~ .^(weft cx/pax)]
:: +read-bill-foreign: read /desk/bill from a foreign desk
::
++ read-bill-foreign
|= [=ship =desk =aeon]
^- (list dude)
~| +<
=/ her (scot %p ship)
=/ syd (scot %tas desk)
=/ yon (scot %ud aeon)
::
=/ dom .^(dome cv/~[her syd yon])
=/ tak ~| aeons=~(key by hit.dom)
(scot %uv (~(got by hit.dom) aeon))
=/ yak .^(yaki cs/~[her syd yon %yaki tak])
=/ fil (~(get by q.yak) /desk/bill)
?~ fil ~
=/ lob (scot %uv u.fil)
=/ bob .^(blob cs/~[her syd yon %blob lob])
::
;; (list dude)
?- -.bob
%direct q.q.bob
%delta q.r.bob
clay: Add support for representing tombstones This adds support for tombstoned files to clay. It does not include any way to actually tombstone them; that is left for later. This allows tombstoning at the level of a file. Precisely, this expands +blob:clay by adding a %dead case: +$ blob :: fs blob $% [%delta p=lobe q=[p=mark q=lobe] r=page] :: delta on q [%direct p=lobe q=page] :: immediate [%dead p=lobe ~] :: tombstone == :: Thus, we maintain the invariant that every lobe corresponds to a blob, but now a blob may be an explicit tombstone. Details: - This has not been tested at all, except that it compiles and boots. - This does not have a state adapter from master. The only state change is the definition of +cach. - Additionally, out-of-date ships may unexpectedly receive a %dead blob from a foreign clay which would interfere with their ability to download that desk. No code changes necessary, but sponsors should avoid tombstoning files in %base for a while so their children can get the update. - A merge will only fail if the tombstoned file conflicts with another change. Note that as written, merging from a past desk *can* bring a tombstoned file to the head of a desk. Possibly this shouldn't be allowed. This also includes a couple refactors that were made possible by ford fusion (since everything is synchronous now) but never got done. In both cases we get to remove a monad, which simplifies the code considerably. - refactor +merge's error handling to use !!/mule instead of threading through errors - refactor all +read-* functions and related parts of +try-fill-sub to eagerly convert lobes to cages. We also add support reading %a/b/c/e/f/r/x from past and foreign desks, when possible. Apologies that all of these are in one commit, it was all a single chunk of work. This is a draft until we have a way to tombstone. I suspect we'll want to have a mechanism of keeping track of gc roots and trace to remove, but this PR doesn't suggest any particular strategy.
2021-11-08 09:17:02 +03:00
%dead ~|(%tombstoned-bill !!)
==
:: +read-bill: read contents of /desk/bill manifest
::
++ read-bill
|= [our=ship =desk now=@da]
=/ pax (en-beam [our desk da+now] /desk/bill)
?. .^(? cu/pax)
*(list dude)
.^((list dude) cx/pax)
:: +adjust-dudes: which agents should be started and stopped
::
:: Will ask Gall to start agents that it's already running
:: but that should be ok, and might be safer in case other
:: unprocessed moves would have turned them off.
::
++ adjust-dudes
|= $: local=[our=ship =desk now=@da]
=rein
==
^- [jolt=(list dude) idle=(list dude)]
=/ all=(list dude) (read-bill local)
=/ want (get-apps-want local all rein)
=/ have (get-apps-live local)
[want (skip have ~(has in (sy want)))]
::
++ get-remote-diff
|= [our=ship here=desk now=@da her=ship there=desk when=aeon]
=+ .^(our-hash=@uv cz/[(scot %p our) here (scot %da now) ~])
=+ .^(her-hash=@uv cz/[(scot %p her) there (scot %ud when) ~])
!=(our-hash her-hash)
::
++ get-publisher
|= [our=ship =desk now=@da]
^- (unit ship)
=/ pax /(scot %p our)/[desk]/(scot %da now)/desk/ship
?. .^(? %cu pax) ~
`.^(ship %cx pax)
::
++ get-apps-live
|= [our=ship =desk now=@da]
^- (list dude)
%+ murn (get-apps-have our desk now)
|=([=dude live=?] ?.(live ~ `dude))
:: +get-apps-have: find which apps Gall is running on a desk
::
++ get-apps-have
|= [our=ship =desk now=@da]
^- (list [=dude live=?])
%~ tap in
.^((set [=dude live=?]) ge+/(scot %p our)/[desk]/(scot %da now))
:: +get-apps-want: find which apps should be running on a desk
::
++ get-apps-want
|= [local=[our=ship =desk now=@da] duz=(list dude) =rein]
^- (list dude)
?. liv.rein ~
?. |(=(`zuse+zuse (read-kelvin-local local)) =(%base desk.local)) ~
=. duz (skip duz ~(has in sub.rein))
=. duz (weld duz (skip ~(tap in add.rein) ~(has in (sy duz))))
duz
::
++ mergebase-hashes
|= [our=@p =desk now=@da =arak]
?~ rail.arak
~
=/ her (scot %p ship.u.rail.arak)
=/ ego (scot %p our)
=/ wen (scot %da now)
%+ turn .^((list tako) %cs ~[ego desk wen %base her desk.u.rail.arak])
|=(=tako .^(@uv %cs ~[ego desk wen %hash (scot %uv tako)]))
::
++ enjs
=, enjs:format
|%
++ vats
|= v=(list ^vat)
^- json
%- pairs
%+ turn v
|= va=^vat
[desk.va (vat va)]
::
++ tim
|= t=@
^- json
(numb (fall (mole |.((unm:chrono:userlib t))) 0))
::
++ cass
|= c=^cass
%- pairs
:~ ud+(numb ud.c)
da+(tim da.c)
==
::
++ vat
|= v=^vat
%- pairs
:~ desk+s+desk.v
hash+s+(scot %uv hash.v)
cass+(cass cass.v)
arak+(arak arak.v)
==
::
++ weft
|= w=^weft
%- pairs
:~ name+s+lal.w
kelvin+(numb num.w)
==
::
++ rung
|= r=^rung
%- pairs
:~ aeon+(numb aeon.r)
weft+(weft weft.r)
==
::
++ rein
|= r=^rein
%- pairs
:~ add+a+(turn ~(tap in add.r) (lead %s))
sub+a+(turn ~(tap in sub.r) (lead %s))
==
::
++ arak
|= a=^arak
%- pairs
:~ rail+?~(rail.a ~ (rail u.rail.a))
rein+(rein rein.a)
==
::
++ rail
|= r=^rail
%- pairs
:~ ship+s+(scot %p ship.r)
publisher+?~(publisher.r ~ s+(scot %p u.publisher.r))
desk+s+desk.r
paused+b+paused.r
aeon+(numb aeon.r)
next+a+(turn next.r rung)
==
--
--