-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implement arbitrary Queryable interface. #3
Open
leehambley
wants to merge
13
commits into
master
Choose a base branch
from
implement-arbitrary-queryable-on-depot
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ary queries, copy and tweak code from Repo.Rehydrate as a basis
Demonstrates the simplest case of ranging over parents and collecting more and more and more matches. An alwaysMatches helper has been added to the tests to allow me to test that in a naive case we'll always match everything ensuring we do a proper full walk of the storage. Test setup had a mistake too as the head ref pointed at a checkpoint which referenced an affix which doesn't exist, easily corrected.
Modify existing codepaths (all tests pass now) to handle the new types. Fix a few package naming issues (matcher can't import retro can't import matcher) by making sure that retro.PartitionName isn't required in the matcher package (the caller can cast to a string, first)
This genericise the behaviour of collecting a historical record from a given ref backwards and linerarizing the result. The implementation is sub optimal, with a full tree walk from ref to the first ancestorless checkpoint. Sometimes twice, if a merge checkpoint is present in the history. Worse, for each checkpoint discovered the list of all hitherto discovered checkpoints will be binary-searched to find the correct index at which to insert the incoming checkpoint. Aside from practical concerns about realworld performance, the implementation itself leaves a little to be desired. Waitgroups, blocking returns, and conditional branching seem like I may have missed a more elegant solution in the Chronological#run() function. One noteworthy remark: we can reach "the beginning" 1+n times given no cyclic histories. Possibly some of this book-keeping can be moved to the tocCPs type where the slice can maybe converted to a single-use sized, and buffered channel. This would eliminate a lot of the book-keeping from the Chronological index.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Status Quo
There are presently two ways to "query" a
Depot
/Repo
.Repo
, concerned with the "Repository Pattern" inspired by DDD allows looking up and rehydration of a specific named aggregate. (repo.Rehydrate("users/123") => User<id: 123.....>
).Depo
, a ES specific storage concern allows subscriptions to simple matchers (globs against partition names (e.gdepot.Watch("users/123")
ordepot.Watch("users/*")
).This PR
A new
Matching()
API will be added to theDepot
as it is more a storage related concern than a DDD concern and I would not expect it to see widespread use in the context of aCommand
. (this may change, and bothDepot
andRepo
may implement if it is useful in both places)The
Matching()
API will run synchronously and will take aMatcher
instance. TheMatcher
will get a chance to explore the entire storage space. Implementations of theMatching()
API will be expected to gatherCheckpoints
with some meta-data about what they matched and why.The new API is exposed through a new named interface named
Queryable
, this reflects that maybeRepo
andDepot
are both queryable, depending on the implementation.No thought has been given on whether the API should support limiting runtime (other than through respecting the given
context.Context
or depth in terms of numbers ofCheckpoints
or distance into the past.Examples of
Matcher
s may include:SessionID("0x00")
used to look up anyCheckpoints
which reference thatSessionID
in their headers.Glob("partition/*")
used to look up anyCheckpoint
referencing anAffix
where a partition matching the globbed pattern is named.Attribute("partition/*", "$.store.book[?(@.price < 10)]")
This would likely be extremely slow in reality but may expose interesting possibilities. The syntax in this contrived example is (likely invalid) JSONPath but some annotation language for pulling values out of the serialized JSON objects would be handy in some instances I think.Filters
The
Matching()
API is likely to pushCheckpoint
hashes onto a stack whilst walking the Merkle tree but I believe the use-cases will prefer consuming events, bounded by affixes in many cases.I suspect
Matching()
will return some kind ofResultSet
which gives an option of iterating overCheckpoints
, orAffixes
orEvents
.For anti-fraud knowing the metadata about the distribution of Checkpoints where
Orders
were created over time may be relevant, but one may also legitimately just want to fetch a list of things created in a given session, in which case walking the events without caring about time spans, or the affix boundaries is sufficient.Combining Matchers
It may turn out to be simple enough to create some boolean combinators for matchers which create new matchers so that one can combine
SessionID
andGlob()
matchers for e.g but this isn't really a concern of changing theDepot
/Repo
API.