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

refactor: Make rootstore require Batching and TxnDatastore #940

Merged
merged 9 commits into from
Dec 19, 2022

Conversation

fredcarle
Copy link
Collaborator

Relevant issue(s)

Resolves #683

Description

This PR change the requirement for our supported datastore to implement both ds.Batching and ds.TxnDatastore. This means that the map datastore is no longer supported.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

make test

Specify the platform(s) on which this was tested:

  • MacOS

@fredcarle fredcarle added area/datastore Related to the datastore / storage engine system action/no-benchmark Skips the action that runs the benchmark. labels Nov 13, 2022
@fredcarle fredcarle added this to the DefraDB v0.4 milestone Nov 13, 2022
@fredcarle fredcarle requested a review from a team November 13, 2022 20:27
@fredcarle fredcarle self-assigned this Nov 13, 2022
@@ -431,7 +420,6 @@ func (vf *VersionedFetcher) getDAGNode(c cid.Cid) (*dag.ProtoNode, error) {
}

func (vf *VersionedFetcher) Close() error {
vf.store.Discard(vf.ctx)
if err := vf.root.Close(); err != nil {
return err
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thought: I'm not quite sure if there are any negative impact to that change. What I do know is that keeping it there cause a Unclosed iterator at time of Txn.Discard error.

Copy link
Member

Choose a reason for hiding this comment

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

I think its OK to remove this, likely here accidentally since the vf.store is a transaction that isn't "owned" by the VersionFetcher, so I don't think it should be responsbile to Discard it.

I am intrigued why its suddenly causing this issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It did this when trying to switch to a transactional datastore when using the old map db. If I add it back now it works fine. I'll leave it out though as like you mentioned, it was probably added there by accident.

@fredcarle fredcarle changed the title refactor: Make our rootstore require Batching and TxnDatastore refactor: Make rootstore require Batching and TxnDatastore Nov 13, 2022
db/fetcher/versioned.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Code change is simple and I am happy with it, but this is a new restriction on Defra and should be approved by John (product-decision, not technical)

@fredcarle fredcarle force-pushed the fredcarle/refactor/I683-remove-batchable branch from f60e17c to 01ffc86 Compare December 16, 2022 05:40
@codecov
Copy link

codecov bot commented Dec 16, 2022

Codecov Report

Merging #940 (829ad47) into develop (2e5626f) will increase coverage by 0.04%.
The diff coverage is 96.29%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #940      +/-   ##
===========================================
+ Coverage    57.73%   57.77%   +0.04%     
===========================================
  Files          171      172       +1     
  Lines        19478    19455      -23     
===========================================
- Hits         11246    11241       -5     
+ Misses        7239     7225      -14     
+ Partials       993      989       -4     
Impacted Files Coverage Δ
cli/serverdump.go 15.78% <0.00%> (ø)
db/collection.go 66.61% <ø> (+0.40%) ⬆️
db/collection_update.go 59.01% <ø> (+0.54%) ⬆️
cli/start.go 43.44% <100.00%> (ø)
datastore/memory/errors.go 100.00% <100.00%> (ø)
datastore/memory/memory.go 88.73% <100.00%> (ø)
datastore/memory/txn.go 88.88% <100.00%> (-0.14%) ⬇️
datastore/txn.go 62.06% <100.00%> (-1.01%) ⬇️
datastore/wrappedStore.go 66.01% <100.00%> (ø)
db/db.go 73.00% <100.00%> (ø)
... and 2 more

Copy link
Member

@jsimnz jsimnz left a comment

Choose a reason for hiding this comment

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

LGTM.

Some small notes/questions. Most notably in the db/db_test.go we prob want to keep the badger inmemory store for those tests (or both)

db/db_test.go Outdated Show resolved Hide resolved
@@ -431,7 +420,6 @@ func (vf *VersionedFetcher) getDAGNode(c cid.Cid) (*dag.ProtoNode, error) {
}

func (vf *VersionedFetcher) Close() error {
vf.store.Discard(vf.ctx)
if err := vf.root.Close(); err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

I think its OK to remove this, likely here accidentally since the vf.store is a transaction that isn't "owned" by the VersionFetcher, so I don't think it should be responsbile to Discard it.

I am intrigued why its suddenly causing this issue.

datastore/txn.go Show resolved Hide resolved
db/fetcher/versioned.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Got to run, so submitting a few comments now

cli/start.go Show resolved Hide resolved
@@ -208,20 +208,19 @@ func (t *basicTxn) Commit(ctx context.Context) error {
if t.discarded {
return ErrTxnDiscarded
}
if t.readOnly {
return ErrReadOnlyTxn
Copy link
Contributor

Choose a reason for hiding this comment

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

question: My brain is blanking here now - why are you removing this error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because our collection api does a commit (c.commitImplicitTxn) on Get which is probably used to discard the transaction but nonetheless expects no errors of committing a read only transaction. Committing on a read only transaction now simply discards the transaction without error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any (other) protection against mutations made during a read only transaction?

Copy link
Member

Choose a reason for hiding this comment

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

The actual Put method checks if its readonly before doing the operation.

The commitImplicitTxn is unrelated to this kind of stuff tho. Not sure how I missed this line, its def not an error to Commit a readonly transaction, its just basically a no-op.

datastore/txn.go Show resolved Hide resolved
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Looks good! I really think DEFRA_IN_MEMORY needs to be added to the CI tests though

db/db_test.go Outdated Show resolved Hide resolved
@@ -171,8 +171,6 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.
},
},
},

DisableMapStore: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: Didnt realise we had so many of these now 😅 Really nice to lose them

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😄

Copy link
Member

Choose a reason for hiding this comment

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

💯

tests/integration/utils.go Show resolved Hide resolved
@fredcarle fredcarle force-pushed the fredcarle/refactor/I683-remove-batchable branch from f05a856 to dea44f8 Compare December 16, 2022 16:35
@fredcarle fredcarle force-pushed the fredcarle/refactor/I683-remove-batchable branch from 7617f37 to 4df2b24 Compare December 19, 2022 02:58
Height is thread safe and Len isn’t.
@fredcarle fredcarle merged commit 664d510 into develop Dec 19, 2022
@fredcarle fredcarle deleted the fredcarle/refactor/I683-remove-batchable branch December 19, 2022 19:50
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
…work#940)

Relevant issue(s)
Resolves sourcenetwork#683

Description
This PR change the requirement for our supported datastore to implement both ds.Batching and ds.TxnDatastore. This means that the map datastore is no longer supported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/datastore Related to the datastore / storage engine system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove batchable datastore support
3 participants