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

fix(server): avoid duplicate registration of StoreEventListener #2620

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

haohao0103
Copy link
Contributor

close #2618

Define initialization identifiers for storeEventListeners in AbstractBackendStoreProvider to ensure that storeEventListeners are not registered repeatedly

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. store Store module labels Aug 6, 2024
Comment on lines 73 to 74
if (schemaCacheClearListened.compareAndSet(false, true) ||
vertexEdgeCacheClearListened.compareAndSet(false, true)) {
Copy link
Member

@imbajin imbajin Aug 10, 2024

Choose a reason for hiding this comment

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

Some questions:

  • we define 2 automic_param boolean A & B and try to set them to true, when to reset it?
  • why we need 2 flag to mark it? (in this context)
  • since assignment operations (=) for primitive types are atomic by default(64bit), it seems that we only need to use a volatile boolean flag to achieve the desired effect?

@Pengzna @VGalaxies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1、define 2 automic_param boolean A & B;this operation is to ensure that storeEventListener does not deliver to storeEventHub of storeProvider once in each thread. I understand that there is no need to re register during the entire Hugegraph lifecycle, so there is no reset operation; Will this miss other necessary scenarios?
2、schemaCacheClearListened for schemaCache clear , vertexEdgeCacheClearListened for vertex&edge cache;
3、 I have modified it to use the volatile+synchronized,thanks

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Aug 12, 2024
Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.

Project coverage is 0.08%. Comparing base (a038d23) to head (17d3f08).
Report is 260 commits behind head on master.

Files with missing lines Patch % Lines
...ph/backend/store/AbstractBackendStoreProvider.java 0.00% 16 Missing ⚠️
...graph/backend/cache/CachedSchemaTransactionV2.java 0.00% 2 Missing ⚠️
.../hugegraph/backend/store/BackendStoreProvider.java 0.00% 2 Missing ⚠️
...ugegraph/backend/cache/CachedGraphTransaction.java 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (a038d23) and HEAD (17d3f08). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (a038d23) HEAD (17d3f08)
5 1
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #2620       +/-   ##
============================================
- Coverage     45.17%   0.08%   -45.09%     
+ Complexity      583      22      -561     
============================================
  Files           718     723        +5     
  Lines         58434   57564      -870     
  Branches       7491    7223      -268     
============================================
- Hits          26396      51    -26345     
- Misses        29318   57511    +28193     
+ Partials       2720       2     -2718     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…raph/backend/store/AbstractBackendStoreProvider.java

Co-authored-by: imbajin <[email protected]>
@imbajin imbajin requested review from javeme and zyxxoo August 15, 2024 10:01
@zyxxoo
Copy link
Contributor

zyxxoo commented Aug 15, 2024

thanks for you push code for solve the problem, this is a great code, but i have some different advise for that. ohh, the transaction monitor some event happen, meawhile, the code change the state local, every instance maybe need care the event, so we should allow repeated event register; for the problem, i think the main problem maybe is the threadlocal not correct release, that make the listen not be remove

Copy link
Contributor

@javeme javeme 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 your contribution, some tiny comments

@@ -105,7 +105,8 @@ private void listenChanges() {
}
return false;
};
this.graphParams().loadGraphStore().provider().listen(this.storeEventListener);
this.graphParams().loadGraphStore().provider()
.listenSchemaCacheClear(this.storeEventListener);

// Listen cache event: "cache"(invalid cache item)
this.cacheEventListener = event -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

@imbajin can you share some context why we added CachedSchemaTransactionV2.java? not sure it's used in what scenarios, and can we merge V1+V2 into one class?

Copy link
Contributor

Choose a reason for hiding this comment

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

CachedSchemaTransactionV2 is the CachedSchemaTransaction corresponding to the SchemaTransaction of the pd-store version. We added a V2 to distinguish it from the previous version. Due to the inconsistency of the parameters required for construction, it is currently not easy to reuse, will be merged later...

@@ -133,7 +133,7 @@ private void listenChanges() {
}
return false;
};
this.store().provider().listen(this.storeEventListener);
this.store().provider().listenDataCacheClear(this.storeEventListener);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I have read the issue, but I still don't quite understand in what scenarios.the problem is encountered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

simply put,i found that registering a listener for each transaction instance is redundant because each transaction receives events and then performs a clear operation on the schema/vertex/edge cache , i think that this is redundant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note each provider has multiple listeners, which is our design intention, because each listener wants to get notifications.
This modification looks a bit special at the moment, and we will propose a solution after we figure out the problem. Could you post the error stack if there is an error?

@@ -67,6 +67,12 @@ public interface BackendStoreProvider {

void listen(EventListener listener);

default void listenSchemaCacheClear(EventListener listener) {
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer listenSchemaCacheAtMostOnce

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks , you mean to update the method name to listenSchemaCacheAtMostOnce?

default void listenSchemaCacheClear(EventListener listener) {
}

default void listenDataCacheClear(EventListener listener) {
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer listenGraphCacheAtMostOnce

@haohao0103
Copy link
Contributor Author

haohao0103 commented Aug 19, 2024

thanks for you push code for solve the problem, this is a great code, but i have some different advise for that. ohh, the transaction monitor some event happen, meawhile, the code change the state local, every instance maybe need care the event, so we should allow repeated event register; for the problem, i think the main problem maybe is the threadlocal not correct release, that make the listen not be remove

thanks , i try to understand what you mean , Indeed, there some issues with threadlocal processing,and my code did not address this problem. In addition ,I think it is indeed valuable to pay attention to events for each transaction instance; But in the current scenario,based on my understanding,this operation seems redundant because schema and vertex/edge cache are both global singleton, and it seems unnecessay to execute their operations on every transaction instance. of course ,if there are personalized scenarios that allow for reregistration of listener,it is indeed necessary and valuable.this is my idea, welcome to correct it.

Copy link

Due to the lack of activity, the current pr is marked as stale and will be closed after 180 days, any update will remove the stale label

@github-actions github-actions bot closed this Mar 22, 2025
@github-project-automation github-project-automation bot moved this from In progress to Done in HugeGraph PD-Store Tasks Mar 22, 2025
@imbajin imbajin reopened this Mar 30, 2025
@github-project-automation github-project-automation bot moved this from Done to In progress in HugeGraph PD-Store Tasks Mar 30, 2025
@imbajin imbajin requested a review from Copilot March 30, 2025 11:46
@imbajin imbajin changed the title fix(server) Avoid duplicate registration of StoreEventListener fix(server): avoid duplicate registration of StoreEventListener Mar 30, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request addresses duplicate registration of StoreEventListener by introducing initialization identifiers in AbstractBackendStoreProvider to guarantee that listeners are registered only once.

  • Introduces two new default methods (listenSchemaCacheClear and listenDataCacheClear) in BackendStoreProvider.
  • Implements conditional listener registration in AbstractBackendStoreProvider using static volatile flags.
  • Updates CachedSchemaTransactionV2 and CachedGraphTransaction to use the new listener registration methods.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendStoreProvider.java Added default methods for schema and data cache clear listener registration.
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/AbstractBackendStoreProvider.java Introduced static flags and synchronized blocks for one-time listener registration.
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/cache/CachedSchemaTransactionV2.java Updated listener registration from listen() to listenSchemaCacheClear().
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/cache/CachedGraphTransaction.java Updated listener registration from listen() to listenDataCacheClear().

haohao0103 and others added 2 commits April 1, 2025 09:39
…raph/backend/store/AbstractBackendStoreProvider.java

Co-authored-by: Copilot <[email protected]>
…raph/backend/store/AbstractBackendStoreProvider.java

Co-authored-by: Copilot <[email protected]>
@haohao0103 haohao0103 marked this pull request as draft April 1, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive size:M This PR changes 30-99 lines, ignoring generated files. store Store module
Projects
Status: In progress
5 participants