Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite the Directory Layer Cache implementation to use value-checks #105

Merged
merged 2 commits into from
May 14, 2020

Conversation

KrzysFR
Copy link
Member

@KrzysFR KrzysFR commented May 13, 2020

I tried using the \xff/metadataVersion key to implement caching in the directory layer but the experiment showed the following drawbacks:

  • The DL is sensitive to outside "noise" from layers that would frequently touch the metadata version key, and requires its own key to re-validate the cache.
  • The DL needs to be versioned to support this new key, which creates an issue of compatibility with other bindings.
  • Even with this, the cache is discarded for unrelated changes, like creating a new subspace, or changing subspaces that were not in the cache.

Using the new Deferred Value Checks features (cf #103) we can use another approach to handle caching:

  • Each subspace maintains the list of all the nodes (from the root) that were used to resolve it (ie: /Foo/Bar/Baz keeps the list of the k/v that were used to resolve Foo, then Bar, then Baz).
  • Every-time a cached subspace is used in a transaction, this list of nodes will be added as deferred value-checks, but the transaction will optimistically continue (betting that nothing changed)
  • Before the retry loop completes, it will resolve pending value checks. If any of the checked node was modified (by another transaction), then a fake not_committed error induce a retry.
  • On the next attempt, the Directory Layer checks if there was at least one failed check using its tag, and if it was the case, discard the cache and starts over.

For the moment, we use a single tag for all the value-checks performed by the DL, so we are still discarding the whole cache even if a single subspace is changed. We may in the future be more precise?

Since we are not relying on additional keys anymore, this means that this implementation is compatible with the existing v1.0 format of the DL, and can also co-exist with scripts and programs using other bindings!

…instead of metadata version

- Use value-checks to protect transactions against obsolete cached data instead of checking the metadata version key
- Revert DL to version 1.0 and remove the metadata key
- Cache is now more precise (ie: reacts to change to subspaces that were cached, and ignore the noise coming from the rest of the db)
- Downside is that cache busting will trigger at least one retry of the transaction.
@KrzysFR KrzysFR added enhancement api Issues or changes related to the client API layer:directory Directory Subspace Layer labels May 13, 2020
@KrzysFR KrzysFR merged commit a1d849d into master May 14, 2020
@KrzysFR KrzysFR deleted the refac_directory_cache branch April 17, 2022 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues or changes related to the client API enhancement layer:directory Directory Subspace Layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant