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

PubsubValueStore should handle arbitrary merge functions #36

Open
aschmahmann opened this issue Aug 12, 2019 · 0 comments
Open

PubsubValueStore should handle arbitrary merge functions #36

aschmahmann opened this issue Aug 12, 2019 · 0 comments
Labels
kind/enhancement A net-new feature or improvement to an existing feature

Comments

@aschmahmann
Copy link
Contributor

Currently the PubsubValueStore assumes Pubsub is distributing a single Key-Value pair which is updating by utilizing a best function that is passed in via the Validator interface.

This looks like:

bestVal, updated := best(currentVal, receivedVal)
if updated {
   data[key]=bestVal
   Publish(bestVal)
}

Instead it would be better to use an interface that allows for:

updatedState, delta := merge(currentState, receivedState)
if delta != nil {
   data[key]=updatedState
   Publish(delta)
}

Given that the PubsubValueStore assumes Get and Put of full data records (as opposed to deltas) it's probably fine to assume that the types of the state and deltas are the same. However, if we wanted we could also add a diff function that takes the states and computes a delta.

Some example merge functions:

  • Best (as we have now)
  • Union (if the record type is a set take the union of the set)
  • BestN (do a union, but only keep the best N records)

Having this (and landing #33) would make an implementation of the suggestion at libp2p/go-libp2p#694 (comment) fairly straightforward.

@aschmahmann aschmahmann added the kind/enhancement A net-new feature or improvement to an existing feature label Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A net-new feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant