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

feat: Add support for branchable collection time-traveling #3260

Merged
merged 8 commits into from
Nov 20, 2024

Conversation

AndrewSisley
Copy link
Contributor

Relevant issue(s)

Resolves #3257

Description

Add support for branchable collection time-traveling.

Also fixes the docID param which was misbehaving (see commit Create document with actual docID not user provided value).

Suggest reviewing commit by commit, it should be easier to follow.

Do not review the first commit here - this branch is based of off #3256 - please review that PR first.

@AndrewSisley AndrewSisley added bug Something isn't working feature New feature or request area/query Related to the query component labels Nov 20, 2024
@AndrewSisley AndrewSisley added this to the DefraDB v0.15 milestone Nov 20, 2024
@AndrewSisley AndrewSisley requested a review from a team November 20, 2024 03:00
@AndrewSisley AndrewSisley self-assigned this Nov 20, 2024
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.62%. Comparing base (c45b07e) to head (c7e5f55).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
internal/db/fetcher/versioned.go 93.18% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3260      +/-   ##
===========================================
+ Coverage    77.47%   77.62%   +0.14%     
===========================================
  Files          382      382              
  Lines        35294    35290       -4     
===========================================
+ Hits         27344    27391      +47     
+ Misses        6317     6278      -39     
+ Partials      1633     1621      -12     
Flag Coverage Δ
all-tests 77.62% <93.33%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/planner/select.go 84.62% <100.00%> (-0.23%) ⬇️
internal/db/fetcher/versioned.go 81.87% <93.18%> (+9.49%) ⬆️

... and 20 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c45b07e...c7e5f55. Read the comment docs.

---- 🚨 Try these New Features:

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with two thoughts that aren't todos because the underlying issue wasn't introduced in this PR.

Comment on lines 267 to 268
if len(n.selectReq.DocIDs.Value()) > 0 {
docID = n.selectReq.DocIDs.Value()[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: Passing the docID for a timetravel query is unnecessary as it will never be used. Even worst, it's confusing the reader by pretending to be useful for the query. One can pass an invalid docID and still get a valid response. We should probably remove references to docID in this block.

tought: It might be more appropriate to allow setting CID or docID but not both in the query params.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I forgot to test that, sorry.

There is a small chance it is still used within the planner nodes, and I actually want it to be so, so that a docID can be provided alongside a collection cid - otherwise there is a gap in the query syntax like you said. Also, IIRC John really likes being able to set the docID and cid in the same query (for doc-cids), even though the docID has always been somewhat pointless from an external perspective.

That said, even then the docID in Spans is almost certainly irrelevant (I didn't notice I'd removed it completely from the versionedFetcher) - and so this block deserves a revisit for being highly misleading like you said.

I'll have a play, if it looks like it'll take a bit more effort to get collection-cids with docIDs working I might add a temp error and we can add support whenever it becomes high enough priority.

  • col-cid/docID interplay stuff

Copy link
Contributor Author

@AndrewSisley AndrewSisley Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It worked with the prod code unchanged, test is TestQuerySimpleWithCidOfBranchableCollectionAndDocID.

I think I remember actually thinking this through, and saw that the span is passed on to the backing document fetcher. But looking through the code I don't see that atm. It might be that the split logic refuses to split the filter as the first fetcher is not a doc-fetcher, leaving the span/select node to handle the docID filter.

Where this happens is not really important now though, I'll see if I can remove the block here without stuff breaking :)

  • Remove docID from prefix (it isn't actually a prefix either)

Copy link
Contributor Author

@AndrewSisley AndrewSisley Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing it was problem free. I've documented the oddness in the code, and will merge this PR once the CI is done.

if err != nil {
return err
}
var mcrdt merklecrdt.MerkleCRDT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: I really like the changes in this method 🙂

This is a bug I accidentally fixed (originally in another commit), we should probably have more tests that cover this, but I'm not interested in adding them in this PR.
The contents are very cheap, possibly more so than the cache.
@AndrewSisley AndrewSisley merged commit fa0d92b into sourcenetwork:develop Nov 20, 2024
42 of 43 checks passed
@AndrewSisley AndrewSisley deleted the 3257-col-level-tt branch November 20, 2024 10:54
ChrisBQu pushed a commit to ChrisBQu/defradb that referenced this pull request Feb 21, 2025
…work#3260)

## Relevant issue(s)

Resolves sourcenetwork#3257

## Description

Add support for branchable collection time-traveling.

Also fixes the docID param which was misbehaving (see commit `Create
document with actual docID not user provided value`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/query Related to the query component bug Something isn't working feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for time travel with collection-level cids
2 participants