hermits-grove/hermitdb

data::Prim::Nil breaks associativty

Opened this issue · 0 comments

Exanding on this after digging into it a bit:

the root of our problem comes from crdts::Map<Key, Value, Actor> requiring Value to implement Default.

crdts::Map needs Default because we may receive an Update op that is updating a key that doesn't exist. It needs a way to create an instance of Value so that we can apply the update to it.

In HermitDB, Map keys have type (String, Kind). This gives us enough information to create a default Data for a missing key (using Kind::default_data() -> Data) but in crdts::Map we rely on Type parameters, not Key's to tell us the default value.

Potential fixes:

  • edit crdts::Map to have smarter keys: This has performance implications since we move to the equivalent of dynamic dispatch. As a library I would like crdts to stay as static as possible.
  • re-implement a special case of crdts::Map for HermitDB, we already have an implementation of Map that has the semantics we need but it uses sled as it's backing datastore. If we can abstract over the storage layer, we can re-use this implementation with a HashMap in place of sled.
  • Re-introduce Nil
    • merge(Nil, A) = A forall A
    • Make a bunch of runtime checks to ensure Nil never ends up in the database or things can go bad