pico-engine icon indicating copy to clipboard operation
pico-engine copied to clipboard

Before actually deleting a pico, Wrangler should notify it of pending deletion

Open b1conrad opened this issue 2 years ago • 5 comments

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
    }
  }

b1conrad avatar Mar 04 '22 18:03 b1conrad

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!

b1conrad avatar Mar 04 '22 18:03 b1conrad

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.

b1conrad avatar Mar 04 '22 18:03 b1conrad

It also was wrong because it was running in the parent pico, not the pico that was about to be deleted!

b1conrad avatar Mar 04 '22 18:03 b1conrad

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:

  1. Have the pico to be deleted clean itself up completely and then raise the wrangler:ready_for_deletion event
  2. Send the parent pico the event wrangler:child_deletion_request and select on wrangler:rulesets_need_to_cleanup

Either way, the cleanup is done in the child pico before it is actually deleted.

b1conrad avatar Mar 05 '22 00:03 b1conrad

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.

b1conrad avatar Jun 24 '22 04:06 b1conrad