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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
haohao0103 marked this conversation as resolved.
Show resolved Hide resolved

import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.raft.StoreSnapshotFile;
Expand All @@ -44,6 +45,8 @@ public abstract class AbstractBackendStoreProvider
private final EventHub storeEventHub = new EventHub("store");

protected Map<String, BackendStore> stores = null;
AtomicBoolean schemaCacheClearListened = new AtomicBoolean(false);
AtomicBoolean vertexEdgeCacheClearListened = new AtomicBoolean(false);

protected final void notifyAndWaitEvent(String event) {
Future<?> future = this.storeEventHub.notify(event, this);
Expand All @@ -67,7 +70,10 @@ protected final void checkOpened() {

@Override
public void listen(EventListener listener) {
this.storeEventHub.listen(EventHub.ANY_EVENT, listener);
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

this.storeEventHub.listen(EventHub.ANY_EVENT, listener);
}
}

@Override
Expand Down
Loading