javeme commented on code in PR #2619:
URL:
https://github.com/apache/incubator-hugegraph/pull/2619#discussion_r1729822244
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/cache/CachedSchemaTransactionV2.java:
##########
@@ -107,44 +107,11 @@ private void listenChanges() {
};
this.graphParams().loadGraphStore().provider().listen(this.storeEventListener);
- // Listen cache event: "cache"(invalid cache item)
- this.cacheEventListener = event -> {
- LOG.debug("Graph {} received schema cache event: {}",
- this.graph(), event);
- Object[] args = event.args();
- E.checkArgument(args.length > 0 && args[0] instanceof String,
- "Expect event action argument");
- if (Cache.ACTION_INVALID.equals(args[0])) {
- event.checkArgs(String.class, HugeType.class, Id.class);
- HugeType type = (HugeType) args[1];
- Id id = (Id) args[2];
- this.arrayCaches.remove(type, id);
-
- id = generateId(type, id);
- Object value = this.idCache.get(id);
- if (value != null) {
- // Invalidate id cache
- this.idCache.invalidate(id);
-
- // Invalidate name cache
- SchemaElement schema = (SchemaElement) value;
- Id prefixedName = generateId(schema.type(),
- schema.name());
- this.nameCache.invalidate(prefixedName);
- }
- this.resetCachedAll(type);
- return true;
- } else if (Cache.ACTION_CLEAR.equals(args[0])) {
- event.checkArgs(String.class, HugeType.class);
- this.clearCache(false);
- return true;
- }
- return false;
- };
- EventHub schemaEventHub = this.graphParams().schemaEventHub();
- if (!schemaEventHub.containsListener(Events.CACHE)) {
- schemaEventHub.listen(Events.CACHE, this.cacheEventListener);
- }
+ // Listen cache event: "cache.clear", ...
+ MetaManager.instance().listenSchemaCacheClear((e) -> {
Review Comment:
removing this.cacheEventListener will cause resource leak when
unlistenChanges()
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/meta/MetaManager.java:
##########
@@ -242,7 +251,19 @@ public <T> void listenGraphClear(Consumer<T> consumer) {
}
public <T> void listenSchemaCacheClear(Consumer<T> consumer) {
- this.graphMetaManager.listenSchemaCacheClear(consumer);
+ if (isListenerInitialized(SCHEMA_CLEAR_KEY)) {
Review Comment:
not sure why registering listener when isListenerInitialized(), do you mean
isListenerNotInitialized()?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]