dosubot[bot] commented on issue #2617:
URL:
https://github.com/apache/incubator-hugegraph/issues/2617#issuecomment-2270258314
<!-- Answer -->
The issue you're experiencing with the `cacheEventListener` in
`CachedSchemaTransactionV2` not clearing the local schema cache on other
servers in a multi-server environment is due to the fact that it only listens
to local events and does not propagate cache invalidation events across
different servers. The `cacheEventListener` is registered to listen for cache
events within the same instance, but there is no mechanism to broadcast these
events to other servers in the cluster.
Here's a snippet from the `CachedSchemaTransactionV2` class that illustrates
this:
```java
private void listenChanges() {
// Listen store event: "store.init", "store.clear", ...
Set<String> storeEvents = ImmutableSet.of(Events.STORE_INIT,
Events.STORE_CLEAR,
Events.STORE_TRUNCATE);
this.storeEventListener = event -> {
if (storeEvents.contains(event.name())) {
LOG.debug("Graph {} clear schema cache on event '{}'",
this.graph(), event.name());
this.clearCache(true);
return true;
}
return false;
};
this.store().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.invalidateCache(type, id);
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.params().schemaEventHub();
if (!schemaEventHub.containsListener(Events.CACHE)) {
schemaEventHub.listen(Events.CACHE, this.cacheEventListener);
}
}
```
The `cacheEventListener` is only listening to events from the local
`EventHub` and does not have a mechanism to communicate with other servers'
`EventHub` instances. Therefore, when a client creates a graph schema on one
server, the cache invalidation event is not propagated to other servers,
resulting in stale cache data on those servers
<sup>[[1]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/cache/CachedSchemaTransaction.java)</sup>.
To address this, you would need to implement a distributed event
notification system to propagate events across all instances of the application
running on different servers. This could involve using a message broker or a
distributed event bus to propagate events to all servers in the cluster.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
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]