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: Persist p2p replicators #960

Merged
merged 11 commits into from
Dec 15, 2022

Conversation

fredcarle
Copy link
Collaborator

@fredcarle fredcarle commented Dec 6, 2022

Relevant issue(s)

Resolves #462
Resolves #955
Resolves #954
Resolves #952

Description

This PR adds the ability to persist P2P replicators. It change to RPC part of the CLI to have a new sub command which is replicator.

Using that sub command, we can add, delete and getAll to operate on the replicator store.

Note: Using the config file to add replicators will be done in a future PR. Will most likely add integration test before merging this PR.

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?

manual tests

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

  • MacOS

@fredcarle fredcarle added feature New feature or request area/p2p Related to the p2p networking system action/no-benchmark Skips the action that runs the benchmark. area/cli Related to the CLI binary labels Dec 6, 2022
@fredcarle fredcarle added this to the DefraDB v0.4 milestone Dec 6, 2022
@fredcarle fredcarle requested a review from a team December 6, 2022 17:50
@fredcarle fredcarle self-assigned this Dec 6, 2022
@codecov
Copy link

codecov bot commented Dec 6, 2022

Codecov Report

Merging #960 (ae48085) into develop (f835e27) will decrease coverage by 2.72%.
The diff coverage is 10.57%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #960      +/-   ##
===========================================
- Coverage    59.83%   57.11%   -2.73%     
===========================================
  Files          160      164       +4     
  Lines        17724    19020    +1296     
===========================================
+ Hits         10605    10863     +258     
- Misses        6165     7173    +1008     
- Partials       954      984      +30     
Impacted Files Coverage Δ
net/api/client/client.go 0.00% <0.00%> (ø)
net/api/service.go 4.16% <0.00%> (-4.53%) ⬇️
net/api/pb/api.pb.go 0.86% <0.76%> (-0.48%) ⬇️
cli/replicator_getall.go 4.54% <4.76%> (ø)
cli/replicator_delete.go 11.11% <11.11%> (ø)
cli/replicator_set.go 11.53% <11.53%> (ø)
net/peer.go 44.01% <21.59%> (+11.82%) ⬆️
core/crdt/composite.go 73.33% <72.72%> (-2.73%) ⬇️
db/replicator.go 78.82% <78.82%> (ø)
core/key.go 87.60% <91.30%> (+0.09%) ⬆️
... and 11 more

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.

I've added a few comments (all fairly localized) - I've not finished the peer.go stuff though as my brain is slowing down and I'm fairly unfamiliar with this part of the codebase

db/replicator.go Outdated Show resolved Hide resolved
db/replicator.go Outdated Show resolved Hide resolved
client/db.go Outdated Show resolved Hide resolved
net/peer.go Outdated Show resolved Hide resolved
net/peer.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.

Looks good Fred - a few localized comments, but it makes sense (I think 😁).

net/peer.go Outdated Show resolved Hide resolved
client/db.go Outdated
@@ -39,6 +40,10 @@ type DB interface {
Events() events.Events

PrintDump(ctx context.Context) error

AddReplicator(ctx context.Context, rep Replicator) error
Copy link
Contributor

Choose a reason for hiding this comment

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

thought: It might be nice if anything persisted via these calls gets automagically picked up by the P2P code (mid run, not just on restart), have you had any thoughts around that?

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'm not sure I understand what you are saying here. When a call to add replicator is received, the replicator is immediately picked up.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is? It looked like db.AddReplicator only persists the replicator config to store, and the peer code only ever checks the store for saved configs on defra startup?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If it was as you say the tests wouldn't pass :)

Copy link
Contributor

Choose a reason for hiding this comment

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

😁 Which bit am I misunderstanding? The peer stuff will pick up new stuff in the db (polling?)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The entry point when adding a replicator is line 280 in net/peer.go. If you start there you'll have a clearer view of what is happening.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah but that is what I mean - client.DB is a public interface, and users are free to call these members as and when they like. This function signature suggests (albeit much less so after renaming) that calling Add/SetReplicator would cause it to be active (and picked up auto magically by the peer code).

It would be nice if it did this at some point in the future.

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'm not sure I agree here. The functionality is available from the peer and the method should be called from peer. Nothing guarantees that peer exists and the interactions with the db are only to operate on the datastore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ideally these methods would be internal. But that might be a change for future me lol.

Copy link
Contributor

Choose a reason for hiding this comment

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

😁 That would also solve this lol

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.

Actually, I can approve as the only todos I added ask for documentation (if you dont want changes)

db/replicator_test.go Outdated Show resolved Hide resolved

err = db.AddReplicator(ctx, client.Replicator{
Info: *info,
Schemas: []string{"test", "test2", "test3"},
Copy link
Member

Choose a reason for hiding this comment

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

question: If we have an already existing test schema for the same info then it is just ignored or overwritten in a way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If will be ignored. It's a cumulative add to ensure the user doesn't to remember all schemas that are replicated in order to just add one.

net/api/pb/Makefile Outdated Show resolved Hide resolved
@fredcarle fredcarle force-pushed the fredcarle/feat/I462-persist-p2p-replicators branch from df313d1 to 2ba7fdf Compare December 15, 2022 20:17
Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

Thanks for the changes.

@fredcarle fredcarle merged commit 0261377 into develop Dec 15, 2022
@fredcarle fredcarle deleted the fredcarle/feat/I462-persist-p2p-replicators branch December 15, 2022 21:21
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
Relevant issue(s) 
sourcenetwork#462
sourcenetwork#955
sourcenetwork#954
sourcenetwork#952

Description
This PR adds the ability to persist P2P replicators. It change to RPC part of the CLI to have a new sub command which is replicator.

Using that sub command, we can add, delete and getAll to operate on the replicator store.

Note: Using the config file to add replicators will be done in a future PR. Will most likely add integration test before merging this PR.
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/cli Related to the CLI binary area/p2p Related to the p2p networking system feature New feature or request
Projects
None yet
4 participants