Skip to content

Commit

Permalink
close apache#2618
Browse files Browse the repository at this point in the history
  • Loading branch information
haohao0103 committed Aug 12, 2024
1 parent 9a97f90 commit 8c32404
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void listenChanges() {
}
return false;
};
this.store().provider().listen(this.storeEventListener);
this.store().provider().listenDataCacheClear(this.storeEventListener);

// Listen cache event: "cache"(invalid cache item)
this.cacheEventListener = event -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +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);
volatile Boolean schemaCacheClearListened = false;
volatile Boolean vertexEdgeCacheClearListened = false;

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

@Override
public void listen(EventListener listener) {
if (schemaCacheClearListened.compareAndSet(false, true) ||
vertexEdgeCacheClearListened.compareAndSet(false, true)) {
this.storeEventHub.listen(EventHub.ANY_EVENT, listener);
this.storeEventHub.listen(EventHub.ANY_EVENT, listener);
}

@Override
public void listenSchemaCacheClear(EventListener listener) {
if (!schemaCacheClearListened) {
synchronized (this) {
if (!schemaCacheClearListened) {
listen(listener);
schemaCacheClearListened = true;
}
}
}
}

@Override
public void listenDataCacheClear(EventListener listener) {
if (!vertexEdgeCacheClearListened) {
synchronized (this) {
if (!vertexEdgeCacheClearListened) {
listen(listener);
vertexEdgeCacheClearListened = true;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public interface BackendStoreProvider {

void listen(EventListener listener);

default void listenSchemaCacheClear(EventListener listener) {
}

default void listenDataCacheClear(EventListener listener) {
}

void unlisten(EventListener listener);

EventHub storeEventHub();
Expand Down

0 comments on commit 8c32404

Please sign in to comment.