Don't send null ducts in subscriptions to clay.

We were previously sending ~ as the duct to clay for our %multi
subscriptions. This caused arvo to drop events. Keep track of the
last duct which issued a subscription on a disc and cancel old
subscriptions if the duct changed.
This commit is contained in:
Elliot Glaysher 2018-06-08 11:40:15 -07:00
parent ddf0334b15
commit df008e95ae
2 changed files with 92 additions and 56 deletions

View File

@ -1040,8 +1040,6 @@
moves=~ moves=~
== ==
:: ::
:: CORRECTNESS QUESTION: Are we supposed to cancel on the first duct?
::
=^ results4 ford-gate =^ results4 ford-gate
%- test-ford-call :* %- test-ford-call :*
ford-gate ford-gate
@ -1051,7 +1049,9 @@
call-args=[duct=~[/second] type=~ %kill ~nul] call-args=[duct=~[/second] type=~ %kill ~nul]
:: ::
^= moves ^= moves
:~ :* duct=~[/second] %pass wire=/~nul/clay-sub/~nul/desk :: the cancellation should go on the duct that made it: /first
::
:~ :* duct=~[/first] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk ~ %c %warp [~nul ~nul] %desk ~
== == == == == ==
:: ::
@ -2108,7 +2108,7 @@
scry=scry scry=scry
:: ::
^= call-args ^= call-args
:* wire=/~nul/clay-sub/~nul/desk duct=~ :* wire=/~nul/clay-sub/~nul/desk duct=~[/call]
^= wrapped-sign ^- (hypo sign:ford-gate) :- *type ^= wrapped-sign ^- (hypo sign:ford-gate) :- *type
[%c %wris [%da ~1234.5.7] (sy [%x /timer]~)] [%c %wris [%da ~1234.5.7] (sy [%x /timer]~)]
== ==
@ -2137,7 +2137,7 @@
:: ::
%- expect-eq !> %- expect-eq !>
:_ i.t.moves :_ i.t.moves
:* duct=~ %pass wire=/~nul/clay-sub/~nul/desk :* duct=~[/call] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk %c %warp [~nul ~nul] %desk
`[%mult [%da ~1234.5.7] (sy [%x /timer] ~)] `[%mult [%da ~1234.5.7] (sy [%x /timer] ~)]
== == == ==
@ -2824,7 +2824,7 @@
scry=scry scry=scry
:: ::
^= take-args ^= take-args
:* wire=/~nul/clay-sub/~nul/desk duct=~ :* wire=/~nul/clay-sub/~nul/desk duct=~[/post-a]
^= wrapped-sign ^- (hypo sign:ford-gate) :- *type ^= wrapped-sign ^- (hypo sign:ford-gate) :- *type
[%c %wris [%da ~1234.5.8] (sy [%x /posts/a]~)] [%c %wris [%da ~1234.5.8] (sy [%x /posts/a]~)]
== ==
@ -3056,6 +3056,9 @@
:~ :* duct=~[/alts] %give %made ~1234.5.7 %complete :~ :* duct=~[/alts] %give %made ~1234.5.7 %complete
%success %alts %success %scry %noun scry-type 'scry-two' %success %alts %success %scry %noun scry-type 'scry-two'
== ==
:* duct=~[/same] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk ~
==
:* duct=~[/alts] %pass wire=/~nul/clay-sub/~nul/desk :* duct=~[/alts] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk %c %warp [~nul ~nul] %desk
`[%mult [%da ~1234.5.7] (sy [%x /scry/two] [%x /scry/one] ~)] `[%mult [%da ~1234.5.7] (sy [%x /scry/two] [%x /scry/one] ~)]
@ -3100,7 +3103,10 @@
call-args=[duct=~[/same] type=~ %kill ~nul] call-args=[duct=~[/same] type=~ %kill ~nul]
:: ::
^= moves ^= moves
:~ :* duct=~[/same] %pass wire=/~nul/clay-sub/~nul/desk :~ :* duct=~[/alts] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk ~
==
:* duct=~[/same] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk %c %warp [~nul ~nul] %desk
`[%mult [%da ~1234.5.8] (sy [%x /scry/one] ~)] `[%mult [%da ~1234.5.8] (sy [%x /scry/one] ~)]
== == == == == ==
@ -3114,7 +3120,7 @@
call-args=[duct=~[/alts] type=~ %kill ~nul] call-args=[duct=~[/alts] type=~ %kill ~nul]
:: ::
^= moves ^= moves
:~ :* duct=~[/alts] %pass wire=/~nul/clay-sub/~nul/desk :~ :* duct=~[/same] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk ~ %c %warp [~nul ~nul] %desk ~
== == == == == ==
:: ::
@ -3198,6 +3204,9 @@
:~ :* duct=~[/second] %give %made ~1234.5.7 %complete :~ :* duct=~[/second] %give %made ~1234.5.7 %complete
%success %alts %success %scry %noun scry-type 'scry-two' %success %alts %success %scry %noun scry-type 'scry-two'
== ==
:* duct=~[/first] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk ~
==
:* duct=~[/second] %pass wire=/~nul/clay-sub/~nul/desk :* duct=~[/second] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk ~ %mult [%da ~1234.5.7] %c %warp [~nul ~nul] %desk ~ %mult [%da ~1234.5.7]
(sy [%x /scry/one] [%x /scry/two] [%x /scry/three] ~) (sy [%x /scry/one] [%x /scry/two] [%x /scry/three] ~)
@ -3258,7 +3267,10 @@
call-args=[duct=~[/first] type=~ %kill ~nul] call-args=[duct=~[/first] type=~ %kill ~nul]
:: ::
^= moves ^= moves
:~ :* duct=~[/first] %pass wire=/~nul/clay-sub/~nul/desk :~ :* duct=~[/second] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk ~
==
:* duct=~[/first] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk ~ %mult [%da ~1234.5.9] %c %warp [~nul ~nul] %desk ~ %mult [%da ~1234.5.9]
(sy [%x /scry/three] ~) (sy [%x /scry/three] ~)
== == == == == ==
@ -3272,7 +3284,7 @@
call-args=[duct=~[/second] type=~ %kill ~nul] call-args=[duct=~[/second] type=~ %kill ~nul]
:: ::
^= moves ^= moves
:~ :* duct=~[/second] %pass wire=/~nul/clay-sub/~nul/desk :~ :* duct=~[/first] %pass wire=/~nul/clay-sub/~nul/desk
%c %warp [~nul ~nul] %desk ~ %c %warp [~nul ~nul] %desk ~
== == == == == ==
:: ::
@ -3590,7 +3602,7 @@
now=~1234.5.8 now=~1234.5.8
scry=scry-is-forbidden scry=scry-is-forbidden
:: ::
call-args=[duct=~ type=~ %wipe ~] call-args=[duct=~[/wipe] type=~ %wipe ~]
moves=~ moves=~
== ==
:: ::
@ -3601,7 +3613,7 @@
scry=scry scry=scry
:: ::
^= take-args ^= take-args
:* wire=/~nul/clay-sub/~nul/desk duct=~ :* wire=/~nul/clay-sub/~nul/desk duct=~[/post-a]
^= wrapped-sign ^- (hypo sign:ford-gate) :- *type ^= wrapped-sign ^- (hypo sign:ford-gate) :- *type
[%c %wris [%da ~1234.5.9] (sy [%x /posts/a]~)] [%c %wris [%da ~1234.5.9] (sy [%x /posts/a]~)]
== ==

View File

@ -194,7 +194,7 @@
latest-by-disc=(map disc @da) latest-by-disc=(map disc @da)
:: clay-subscriptions: ducts we'll use to cancel existing clay requests :: clay-subscriptions: ducts we'll use to cancel existing clay requests
:: ::
clay-subscriptions=(set disc) clay-subscriptions=(map disc duct)
:: resource-updates: all clay updates we need to know about :: resource-updates: all clay updates we need to know about
:: ::
:: resource-updates stores all Clay changes at dates that :: resource-updates stores all Clay changes at dates that
@ -1009,7 +1009,7 @@
=/ =disc [ship desk] =/ =disc [ship desk]
:: delete the now-dead clay subscription :: delete the now-dead clay subscription
:: ::
=. clay-subscriptions.state (~(del in clay-subscriptions.state) disc) =. clay-subscriptions.state (~(del by clay-subscriptions.state) disc)
:: ::
=/ resources=(list resource) =/ resources=(list resource)
%+ turn ~(tap in care-paths) %+ turn ~(tap in care-paths)
@ -4872,27 +4872,25 @@
:: ::
=/ resources=(set resource) =/ resources=(set resource)
(fall (~(get by resources-by-disc.state) disc) ~) (fall (~(get by resources-by-disc.state) disc) ~)
:: subscription-duct: if any, the duct that previously made a subscription
::
=/ subscription-duct
(~(get by original-clay-subscriptions) disc)
:: if no resources on :disc, don't make a new clay subscription :: if no resources on :disc, don't make a new clay subscription
:: ::
?~ resources ?~ resources
:: cancel clay subscriptions when we don't have any resources left :: no resources, no subscriptions, no action.
:: ::
?: (~(has in original-clay-subscriptions) disc) ?~ subscription-duct
=+ [their desk]=disc
=/ =note
:^ %c %warp sock=[our their]
^- riff:clay
[desk ~]
::
=. moves :_ moves
^- move
[duct [%pass wire=(clay-sub-wire disc) note]]
::
=. clay-subscriptions.state (~(del in clay-subscriptions.state) disc)
::
=. latest-by-disc.state (~(del by latest-by-disc.state) disc)
::
$(discs t.discs) $(discs t.discs)
:: cancel any clay subscriptions since we don't have any resources left
::
=. moves :_ moves
(clay-cancel-subscription-move u.subscription-duct disc)
::
=. clay-subscriptions.state (~(del by clay-subscriptions.state) disc)
::
=. latest-by-disc.state (~(del by latest-by-disc.state) disc)
:: ::
$(discs t.discs) $(discs t.discs)
:: prevent thrashing; don't unsubscribe then immediately resubscribe :: prevent thrashing; don't unsubscribe then immediately resubscribe
@ -4902,43 +4900,26 @@
:: canceling and then resubscribing might cause the foreign ship :: canceling and then resubscribing might cause the foreign ship
:: to send the response twice, which would be extra network traffic. :: to send the response twice, which would be extra network traffic.
:: ::
?: ?& (~(has in original-clay-subscriptions) disc) ?: ?& (~(has by original-clay-subscriptions) disc)
:: ::
(~(has in clay-subscriptions.state) disc) (~(has by clay-subscriptions.state) disc)
:: ::
.= (~(get by original-resources-by-disc) disc) .= (~(get by original-resources-by-disc) disc)
(~(get by resources-by-disc.state) disc) (~(get by resources-by-disc.state) disc)
== ==
:: ::
$(discs t.discs) $(discs t.discs)
:: request-contents: the set of [care path]s to subscribe to in clay :: if we had a previous subscription on a different duct, send a cancel.
:: ::
=/ request-contents=(set [care:clay path]) =? moves &(?=(^ subscription-duct) !=(duct u.subscription-duct))
%- sy ^- (list [care:clay path]) :_ moves
%+ murn ~(tap in `(set resource)`resources) (clay-cancel-subscription-move u.subscription-duct disc)
|= =resource ^- (unit [care:clay path]) :: send a new clay request using the current duct
::
?. ?=(%c -.resource) ~
::
`[care.resource (flop spur.rail.resource)]
:: if :request-contents is `~`, this code is incorrect
::
?< ?=(~ request-contents)
:: their: requestee +ship
::
=+ [their desk]=disc
=/ latest-date (~(got by latest-by-disc.state) disc)
::
=/ =note
:^ %c %warp sock=[our their]
^- riff:clay
[desk `[%mult case=[%da latest-date] request-contents]]
:: ::
=. moves :_ moves =. moves :_ moves
^- move (clay-add-subscription-move disc resources)
[duct [%pass wire=(clay-sub-wire disc) note]]
:: ::
=. clay-subscriptions.state (~(put in clay-subscriptions.state) disc) =. clay-subscriptions.state (~(put by clay-subscriptions.state) disc duct)
:: ::
$(discs t.discs) $(discs t.discs)
:: +cleanup: try to clean up a build and its sub-builds :: +cleanup: try to clean up a build and its sub-builds
@ -5051,6 +5032,49 @@
=+ [their desk]=disc =+ [their desk]=disc
:: ::
/(scot %p our)/clay-sub/(scot %p their)/[desk] /(scot %p our)/clay-sub/(scot %p their)/[desk]
:: +clay-add-subscription-move: subscribes to :resources
::
++ clay-add-subscription-move
|= [=disc resources=(set resource)]
^- move
:: request-contents: the set of [care path]s to subscribe to in clay
::
=/ request-contents=(set [care:clay path])
%- sy ^- (list [care:clay path])
%+ murn ~(tap in `(set resource)`resources)
|= =resource ^- (unit [care:clay path])
::
?. ?=(%c -.resource) ~
::
`[care.resource (flop spur.rail.resource)]
:: if :request-contents is `~`, this code is incorrect
::
?< ?=(~ request-contents)
:: their: requestee +ship
::
=+ [their desk]=disc
=/ latest-date (~(got by latest-by-disc.state) disc)
::
=/ =note
:^ %c %warp sock=[our their]
^- riff:clay
[desk `[%mult case=[%da latest-date] request-contents]]
::
[duct [%pass wire=(clay-sub-wire disc) note]]
:: +clay-cancel-subscription-move: builds a cancel move
::
++ clay-cancel-subscription-move
|= [old-duct=^duct =disc]
^- move
::
=+ [their desk]=disc
=/ =note
:^ %c %warp sock=[our their]
^- riff:clay
[desk ~]
::
[old-duct [%pass wire=(clay-sub-wire disc) note]]
-- --
-- --
:: ::