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: Remove indirection from crdt packages #3192

Merged

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented Oct 28, 2024

Relevant issue(s)

Resolves #3191

Description

Removes various items of indirection from the merkle/crdt and core/crdt packages that was making the code quite a lot harder to follow than it need to be.

Done as part of #3038 but broken out for quicker merge and a more focused review (of both).

I suggest reviewing commit by commit, it should be easier to follow the changes, and there are explanations in the commit bodies.

It only ever references itself
Was causing so much indirection and seriously inhibited the readability of the code by losing the known type in the Merge function.  Now we can at least go from merkle.lwwr.Merge to core.lwwr.Merge without chasing down all implementations of the interface and wondering if they can all form part of a merkle.lwwr...
There is only one implementation, and by intefacing it out with the same name, it makes tracking down the data flow much harder than it needs to be
The funcs held on it only ever used the 'store' prop and ignored the rest.  Not all the types inheriting from it used all of the props on it (e.g. composite was forced to pass an empty string to the mandatory arg it ignores in the constructor).  Inheritance is not required to remove code duplication, and it hides important properties from people reading the inheriting types. It also makes the code appear more complicated than it is, especially when introducing new types, as it *looks* like it contains important business logic that must be consistent, but it does not (private funcs do not enforce consistency).
It is never actually used, and instead makes implementations of the MerkleCRDT have this weird self referencing hack via the clock, as well as doubling the implmentations of the already complicated core.ReplicatedData making it appear to be more complex than it actually is.
@AndrewSisley AndrewSisley added area/crdt Related to the (Merkle) CRDT system refactor This issue specific to or requires *notable* refactoring of existing codebases and components code quality Related to improving code quality labels Oct 28, 2024
@AndrewSisley AndrewSisley added this to the DefraDB v0.15 milestone Oct 28, 2024
@AndrewSisley AndrewSisley requested a review from a team October 28, 2024 19:11
@AndrewSisley AndrewSisley self-assigned this Oct 28, 2024
@AndrewSisley AndrewSisley changed the title refactor: Remove indirection from merkle/crdt packages refactor: Remove indirection from crdt packages Oct 28, 2024
Copy link

codecov bot commented Oct 28, 2024

Codecov Report

Attention: Patch coverage is 97.72727% with 1 line in your changes missing coverage. Please review.

Project coverage is 77.43%. Comparing base (3a3baac) to head (2684699).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
internal/merkle/crdt/counter.go 88.89% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3192      +/-   ##
===========================================
- Coverage    77.44%   77.43%   -0.01%     
===========================================
  Files          357      357              
  Lines        34809    34801       -8     
===========================================
- Hits         26957    26948       -9     
+ Misses        6237     6236       -1     
- Partials      1615     1617       +2     
Flag Coverage Δ
all-tests 77.43% <97.73%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
internal/core/crdt/base.go 66.67% <100.00%> (-8.33%) ⬇️
internal/core/crdt/composite.go 71.08% <100.00%> (-0.52%) ⬇️
internal/core/crdt/counter.go 66.67% <100.00%> (+6.14%) ⬆️
internal/core/crdt/lwwreg.go 78.87% <100.00%> (+3.53%) ⬆️
internal/merkle/crdt/composite.go 80.65% <100.00%> (+0.65%) ⬆️
internal/merkle/crdt/lwwreg.go 71.43% <100.00%> (+3.01%) ⬆️
internal/merkle/crdt/merklecrdt.go 96.00% <ø> (+12.13%) ⬆️
internal/merkle/crdt/counter.go 62.50% <88.89%> (+3.41%) ⬆️

... and 11 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 3a3baac...2684699. Read the comment docs.

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.

I'm quite happy with this change. I wish we had done this before. Not for lack of trying though... I think it will make adding new CRDT types much simpler.

@AndrewSisley AndrewSisley merged commit b4b2bf2 into sourcenetwork:develop Oct 29, 2024
46 of 47 checks passed
@AndrewSisley AndrewSisley deleted the 3191-crdt-merkle-indirection branch October 29, 2024 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/crdt Related to the (Merkle) CRDT 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.

Remove indirection from merkle/crdt packages
2 participants