pico-engine
pico-engine copied to clipboard
Before actually deleting a pico, Wrangler should notify it of pending deletion
This would best be done by raising an event, say wrangler:rulesets_need_to_cleanup
, and only then doing the actual deletion.
Suggestion (that won't work (see below)): that the existing rule
rule deleteOneChild {
select when wrangler child_deletion_request
eci re#^(.+)$# setting(eci)
ctx:delPico(eci)
fired {
raise wrangler event "child_deleted"
attributes event:attrs
}
}
be replaced by two rules
rule deleteOneChild {
select when wrangler child_deletion_request
eci re#^(.+)$#
fired {
raise wrangler event "rulesets_need_to_cleanup"
raise wrangler event "internal_pico_deletion"
attributes event:attrs
}
}
rule irrevocablyDeleteOneChild {
select when wrangler internal_pico_deletion
eci re#^(.+)$# setting(eci)
ctx:delPico(eci)
fired {
raise wrangler event "child_deleted"
attributes event:attrs
}
}
This would actually also address issue #511 because the subscription ruleset already does the needful by selecting on the wrangler:rulesets_need_to_cleanup
event!
Note that rulesets selecting on the wrangler:rulesets_need_to_cleanup
event MUST complete anything needed within the confines of the existing schedule. Oh, which means the suggestion won't work. Sigh.
It also was wrong because it was running in the parent pico, not the pico that was about to be deleted!
How about this?
rule deleteOneChild {
select when wrangler child_deletion_request
eci re#^(.+)$#
every {
event:send({"eci":eci,"domain":"wrangler","type":"rulesets_need_to_cleanup"})
event:send({"eci":eci,"domain":"wrangler","type":"ready_for_deletion"})
}
}
along with modifying the child_initiates_deletion
rule to send its parent the wrangler:internal_pico_deletion
event, and NOT the wrangler:child_deletion_request
else we'd have an infinite loop of events and nothing would ever get deleted!
The idea is, you as a KRL developer do one of two things:
- Have the pico to be deleted clean itself up completely and then raise the
wrangler:ready_for_deletion
event - Send the parent pico the event
wrangler:child_deletion_request
and select onwrangler:rulesets_need_to_cleanup
Either way, the cleanup is done in the child pico before it is actually deleted.
Here is a ruleset taking care of this: https://github.com/Picolab/fully-sharded-database/blob/main/krl/byu.hr.oit.krl#L454-L455
Suggest giving this some thought and then incorporating it into Wrangler.