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: Make Consensus Services WritableTopicStore WritableKVState Key to be comparable. #10495

Closed
wants to merge 21 commits into from

Conversation

iwsimon
Copy link
Contributor

@iwsimon iwsimon commented Dec 13, 2023

Description:

Related issue(s):

Fixes #10396

Notes for reviewer:

Discussed this at Jan 9th modularization call, don't pass in Comparator, use PBJ Comparable ID as SortedMap key for WritableKVStateBase.modifications. This has to wait for PBJ Key to implement Comparable.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@iwsimon iwsimon requested a review from a team December 13, 2023 22:19
@iwsimon iwsimon requested a review from a team as a code owner December 13, 2023 22:19
@iwsimon iwsimon self-assigned this Dec 13, 2023
Copy link

github-actions bot commented Dec 13, 2023

Node: HAPI Test (Token) Results

189 tests   189 ✔️  17m 7s ⏱️
  13 suites      0 💤
  13 files        0

Results for commit 14cf705.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Dec 13, 2023

Node: HAPI Test (Crypto) Results

211 tests   210 ✔️  23m 17s ⏱️
  22 suites      1 💤
  22 files        0

Results for commit 14cf705.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Dec 13, 2023

Node: E2E Test Results

    1 files      1 suites   23m 4s ⏱️
311 tests 311 ✔️ 0 💤 0
333 runs  333 ✔️ 0 💤 0

Results for commit 14cf705.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Dec 13, 2023

Node: Unit Test Results

    2 291 files  +1      2 291 suites  +1   57m 12s ⏱️ - 2m 4s
118 864 tests +3  118 829 ✔️ +3  35 💤 ±0  0 ±0 
127 268 runs  +3  127 233 ✔️ +3  35 💤 ±0  0 ±0 

Results for commit 14cf705. ± Comparison against base commit e9a4d50.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Dec 13, 2023

Node: HAPI Test (Time Consuming) Results

20 tests   20 ✔️  54m 9s ⏱️
  2 suites    0 💤
  2 files      0

Results for commit 14cf705.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Dec 13, 2023

Node: HAPI Test (Misc) Results

422 tests   405 ✔️  33m 56s ⏱️
  73 suites    17 💤
  73 files        0

Results for commit 14cf705.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Dec 13, 2023

Codecov Report

Attention: Patch coverage is 52.72727% with 26 lines in your changes missing coverage. Please review.

Project coverage is 63.49%. Comparing base (e9a4d50) to head (14cf705).
Report is 1251 commits behind head on develop.

Files Patch % Lines
...p/workflows/handle/stack/WritableKVStateStack.java 14.28% 6 Missing ⚠️
...era/node/app/spi/state/FilteredReadableStates.java 0.00% 4 Missing ⚠️
...era/node/app/spi/state/FilteredWritableStates.java 0.00% 4 Missing ⚠️
...era/node/app/spi/state/WrappedWritableKVState.java 0.00% 3 Missing ⚠️
...hedera/node/app/spi/state/EmptyReadableStates.java 0.00% 2 Missing ⚠️
...hedera/node/app/spi/state/EmptyWritableStates.java 0.00% 2 Missing ⚠️
...m/hedera/node/app/state/WrappedWritableStates.java 0.00% 2 Missing ⚠️
.../com/hedera/node/app/spi/state/ReadableStates.java 0.00% 1 Missing ⚠️
...m/hedera/node/app/state/ReadonlyStatesWrapper.java 0.00% 1 Missing ⚠️
...pp/workflows/handle/stack/WritableStatesStack.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10495      +/-   ##
=============================================
- Coverage      63.49%   63.49%   -0.01%     
- Complexity     31141    31155      +14     
=============================================
  Files           3382     3383       +1     
  Lines         136059   136103      +44     
  Branches       14180    14187       +7     
=============================================
+ Hits           86392    86418      +26     
- Misses         46216    46237      +21     
+ Partials        3451     3448       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Dec 13, 2023

Node: Integration Test Results

294 tests  ±0   294 ✔️ ±0   1h 4m 3s ⏱️ -3s
    5 suites ±0       0 💤 ±0 
    5 files   ±0       0 ±0 

Results for commit 14cf705. ± Comparison against base commit e9a4d50.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Dec 13, 2023

Node: HAPI Test (Smart Contract) Results

411 tests   411 ✔️  53m 2s ⏱️
  55 suites      0 💤
  55 files        0

Results for commit 14cf705.

♻️ This comment has been updated with latest results.

* This should be called on each writable store constructor until all other types of Key Comparator are implemented.
* */
@Override
public final void updateComparator(@NonNull final Comparator<K> comparator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the Comparator should be set during construction and never changed again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Each store is responsible to update their comparator.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for not being clear. I would have expected that the Comparator is immutable. There is probably no valid use case where we want to change the Comparator later, or is there? If the Comparator is immutable, the code should reflect that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method has been removed. WritableTopicStore uses a private static final Comparator.

public final void updateComparator(@NonNull final Comparator<K> comparator) {
final var tmp = new TreeMap<K, V>(comparator);
tmp.putAll(modifications);
this.modifications = tmp;
Copy link
Contributor

@netopyr netopyr Dec 14, 2023

Choose a reason for hiding this comment

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

I am afraid I am missing something very essential here. If we update the Comparator, we are not changing the order of the elements in the data structure but the order of modifications, right? Why is this necessary? I assume that if any code is executed deterministically and single-threaded, the modifications should always be in the same order. Why is it necessary to sort them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You have a linkedhashmap with put, remove options. If not sorted, how can you guarantee a deterministic order? We care about the writableKVState to be deterministic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A TreeMap is created in WritableKVStateBase constructor to enforce the Key order of modification when every service calls its' WritableXXXStore.put().

@iwsimon iwsimon marked this pull request as draft January 2, 2024 20:05
…te a TreeMap for modifications. Updated all the related Writable/Readable classes for the related change.

Added unit tests and updated all the unit tests.

Signed-off-by: Iris Simon <[email protected]>
@iwsimon iwsimon marked this pull request as ready for review January 4, 2024 15:50
Signed-off-by: Iris Simon <[email protected]>
Comment on lines +41 to +42
if (comparator != null) modifications = new TreeMap<>(comparator);
else modifications = new LinkedHashMap<>();
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 we might have missed on additional case here, but it isn't clear how to add it in (darn Erasure behaviors!).
Basically, if K is a Comparable, then we should use the TreeMap in that case as well, without an explicit comparator. We don't have an instance of K to test here, however, so I'm unsure how to test the type (or if we even could).
Probably not worth worrying about at this time, but something perhaps to note as a future issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree we should use TreeMap when K is Comparable. Generics Type Erasure is hard to check here. We will make comparator @nonnull when all services have implemented their comparator key. That will cover all cases. We should stick to either Comparator or Comparable, not mix.

Copy link

github-actions bot commented Jan 5, 2024

Node: HAPI Test (Node Death Reconnect) Results

1 tests   1 ✔️  7m 9s ⏱️
1 suites  0 💤
1 files    0

Results for commit 14cf705.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jan 5, 2024

Node: HAPI Test (Restart) Results

1 tests   1 ✔️  4m 52s ⏱️
1 suites  0 💤
1 files    0

Results for commit 14cf705.

♻️ This comment has been updated with latest results.

@iwsimon iwsimon marked this pull request as draft January 9, 2024 16:53
@jsync-swirlds
Copy link
Member

jsync-swirlds commented Jan 16, 2024

A PR merged to develop in PBJ that now allows Messages to be marked as "Comparable" (with some limitations). This PR will need to be updated once the proto files are updated and the latest PBJ version is incorporated.
Initial draft for adding Comparable is in protobufs on branch add-comparable-to-state-messages.

Note: Comparable support in PBJ is blocked by a somewhat complex defect in the initial implementation which prevents it from working in services.

@Neeharika-Sompalli
Copy link
Member

Seems this is no more valid. Can we close this @iwsimon ?

@iwsimon
Copy link
Contributor Author

iwsimon commented Aug 20, 2024

Closed as it's not needed any more.

@iwsimon iwsimon closed this Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Consensus Services WritableTopicStore WritableKVState Key to be comparable.
4 participants