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

[Bug] graph server cache notifier mechanism is not working properly #2728

Open
1 task done
haohao0103 opened this issue Feb 13, 2025 · 1 comment · May be fixed by #2729
Open
1 task done

[Bug] graph server cache notifier mechanism is not working properly #2728

haohao0103 opened this issue Feb 13, 2025 · 1 comment · May be fixed by #2729
Labels
bug Something isn't working

Comments

@haohao0103
Copy link
Contributor

Bug Type (问题类型)

logic (逻辑设计问题)

Before submit

  • 我已经确认现有的 IssuesFAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • Server Version: 1.5.0 (Apache Release Version)

Expected & Actual behavior (期望与实际表现)

If we enable the RPC server and RPC client configurations in the rest-server.properties configuration file, intending to implement RPC communication among multiple Graph Servers to maintain cache data consistency, the current code logic does not support this functionality.

Existing Cache Notifier Mechanism:
In StandardHugegraph#registerRpcServices(), the HugeGraphCacheNotifier is registered as a service. During the construction of HugeGraphCacheNotifier, a cacheEventListener listening for Events.CACHE type events is added to the graphEventHub. This cacheEventListener specifically listens for actions of type Cache.ACTION_INVALIDATED.
In CachedGraphTransaction#listenChanges, another cacheEventListener is defined, which listens for Cache.ACTION_INVALID type events. However, when attempting to add this cacheEventListener to the graphEventHub, the current code logic checks whether there is already a listener for Events.CACHE type events in the graphEventHub. If one exists, it skips adding the new listener. As a result, the listener that should respond to Cache.ACTION_INVALID events is never added to the graphEventHub, causing the entire notifier mechanism to malfunction.

Proposed Fix:

  1. Modify the logic to allow the cacheEventListener in CachedGraphTransaction to listen for Events.CACHE events and handle
    Cache.ACTION_INVALID actions.
  2. Ensure that the cacheEventListener functions correctly in multi-graph scenarios.

Vertex/Edge example (问题点 / 边数据举例)

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

@haohao0103 haohao0103 added the bug Something isn't working label Feb 13, 2025
Copy link

dosubot bot commented Feb 13, 2025

To address the issue with the graph server cache notifier mechanism, you can follow these steps:

  1. Modify Listener Registration Logic: Ensure that the cacheEventListener in CachedGraphTransaction is registered to listen for Events.CACHE events, even if another listener is already present. This involves adjusting the logic that checks for existing listeners to allow multiple listeners for the same event type.

  2. Handle Cache.ACTION_INVALID Actions: Verify that the cacheEventListener correctly processes Cache.ACTION_INVALID actions. This involves ensuring that the listener invalidates the appropriate cache entries when such actions occur.

  3. Multi-Graph Scenario Support: Ensure that each graph instance has its own EventHub and that the cacheEventListener is correctly registered for each graph. This will help maintain cache consistency across multiple graphs.

The existing code already includes a mechanism to listen for cache events and handle invalid actions. Here is a relevant part of the code that ensures this functionality:

private void listenChanges() {
    this.cacheEventListener = event -> {
        LOG.debug("Graph {} received graph 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, Object.class);
            HugeType type = (HugeType) args[1];
            if (type.isVertex()) {
                Object arg2 = args[2];
                if (arg2 instanceof Id) {
                    Id id = (Id) arg2;
                    this.verticesCache.invalidate(id);
                } else if (arg2 != null && arg2.getClass().isArray()) {
                    int size = Array.getLength(arg2);
                    for (int i = 0; i < size; i++) {
                        Object id = Array.get(arg2, i);
                        E.checkArgument(id instanceof Id, "Expect instance of Id in array, but got '%s'", id.getClass());
                        this.verticesCache.invalidate((Id) id);
                    }
                } else {
                    E.checkArgument(false, "Expect Id or Id[], but got: %s", arg2);
                }
            } else if (type.isEdge()) {
                this.edgesCache.clear();
            }
            return true;
        } else if (Cache.ACTION_CLEAR.equals(args[0])) {
            event.checkArgs(String.class, HugeType.class);
            HugeType type = (HugeType) args[1];
            this.clearCache(type, false);
            return true;
        }
        return false;
    };
    EventHub graphEventHub = this.params().graphEventHub();
    if (!graphEventHub.containsListener(Events.CACHE)) {
        graphEventHub.listen(Events.CACHE, this.cacheEventListener);
    }
}

If the issue persists, further investigation into the event dispatching and handling logic across multiple graphs may be necessary. Ensure that the notifyChanges methods are correctly invoked to trigger the cache events [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other | Bug Report

haohao0103 added a commit to haohao0103/incubator-hugegraph that referenced this issue Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant