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: Add peerstore to multistore #1980

Merged
merged 2 commits into from
Oct 18, 2023

Conversation

fredcarle
Copy link
Collaborator

Relevant issue(s)

Resolves #1680

Description

This small refactor adds the peerstore to the multistore. In doing so, we broaden the types of stores that can be part of the multistore by starting from a ds.Datastore instead of the more restrictive DSReaderWriter

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 showed no change in behaviour.

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

  • MacOS

@fredcarle fredcarle added area/datastore Related to the datastore / storage engine system refactor This issue specific to or requires *notable* refactoring of existing codebases and components code quality Related to improving code quality labels Oct 18, 2023
@fredcarle fredcarle added this to the DefraDB v0.8 milestone Oct 18, 2023
@fredcarle fredcarle requested a review from a team October 18, 2023 19:35
@fredcarle fredcarle self-assigned this Oct 18, 2023
root: rootRW,
data: prefix(rootRW, dataStoreKey),
head: prefix(rootRW, headStoreKey),
peer: namespace.Wrap(rootstore, rootStoreKey),
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Why is the peerstore not prefixed like the rest of the stores?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I pushed the documentation of this at the same time you commented.

Copy link
Contributor

Choose a reason for hiding this comment

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

😁 I thought I had gone mad/blind when I refreshed to add another comment and saw it lol.

question: Why do we want to rely on the libp2p peerstore to assign the prefix?

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 it's hard coded in the libp2p pstoreds package. If we assign a prefix of peers here we end up with what we had before /db/peers/peers/addr/...

Copy link
Contributor

Choose a reason for hiding this comment

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

Might it be safer to prefix it with extern or something then, instead of giving an external package full access to the root store?

e.g.
/db/extern/peers/addr/...
/db/extern/foo/bar/ // I have no idea what else we might use this for, hopefully such cases are rare.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a fair observation. What if we make it specific? db/ps/peers/...

Copy link
Contributor

Choose a reason for hiding this comment

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

Totally happy with that :) I know it seems unlikely to ever cause problems, but it feels a bit wrong to rely on just giving it the root.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

✅ done

@fredcarle fredcarle force-pushed the fredcarle/refactor/I1680-peerstore-in-multistore branch from 3754d13 to c5a95c6 Compare October 18, 2023 19:40
dataStoreKey = rootStoreKey.ChildString("/data")
headStoreKey = rootStoreKey.ChildString("/heads")
blockStoreKey = rootStoreKey.ChildString("/blocks")
rootStoreKey = ds.NewKey("db")
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Is this a bug fix? Were we adding // to our keys instead of / here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ChildString does NewKey(k.string + "/" + s) and the NewKey function adds a / prefix if none are present and cleans the // that would have been present. Removing the / from the passed param makes it more "correct" according to what the function is doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah nice - thanks Fred :)

@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (9cfd33f) 74.76% compared to head (4ec2aff) 74.54%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1980      +/-   ##
===========================================
- Coverage    74.76%   74.54%   -0.22%     
===========================================
  Files          246      246              
  Lines        24298    24306       +8     
===========================================
- Hits         18166    18118      -48     
- Misses        4918     4989      +71     
+ Partials      1214     1199      -15     
Flag Coverage Δ
all-tests 74.54% <67.86%> (-0.22%) ⬇️

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

Files Coverage Δ
datastore/concurrent_txn.go 100.00% <100.00%> (ø)
datastore/multi.go 100.00% <100.00%> (+9.52%) ⬆️
datastore/txn.go 95.38% <100.00%> (-0.07%) ⬇️
db/db.go 64.29% <100.00%> (+0.26%) ⬆️
net/node.go 87.95% <100.00%> (-0.19%) ⬇️
http/client.go 42.75% <0.00%> (-0.33%) ⬇️
http/client_tx.go 37.21% <0.00%> (-1.82%) ⬇️
merkle/crdt/factory.go 78.69% <0.00%> (-7.03%) ⬇️

... and 10 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 9cfd33f...4ec2aff. Read the comment docs.

@@ -66,7 +66,7 @@ func NewTxnFrom(ctx context.Context, rootstore ds.TxnDatastore, id uint64, reado
if err != nil {
return nil, err
}
multistore := MultiStoreFrom(rootTxn)
multistore := MultiStoreFrom(ShimTxnStore{rootTxn})
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Why have you made this change? There should be no need for it root is IterableTxnDatastore

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IterableTxnDatastore does not implement Close and MultiStoreFrom now requires a ds.Datastore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah okay - thanks for clarifying :)

@fredcarle fredcarle force-pushed the fredcarle/refactor/I1680-peerstore-in-multistore branch from 5c4dedf to 4ec2aff Compare October 18, 2023 20:05
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.

LGTM - thanks Fred :)

@fredcarle fredcarle merged commit 2dbfbd6 into develop Oct 18, 2023
30 checks passed
@fredcarle fredcarle deleted the fredcarle/refactor/I1680-peerstore-in-multistore branch October 18, 2023 20:27
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
## Relevant issue(s)

Resolves sourcenetwork#1680

## Description

This small refactor adds the `peerstore` to the `multistore`. In doing
so, we broaden the types of stores that can be part of the `multistore`
by starting from a `ds.Datastore` instead of the more restrictive
`DSReaderWriter`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/datastore Related to the datastore / storage engine system code quality Related to improving code quality refactor This issue specific to or requires *notable* refactoring of existing codebases and components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make peerstore part of multistore
2 participants