Graph Cache Invalidation#
Overview#
HugeGraph maintains two independent cache layers per graph: graph caches (vertex/edge data, in CachedGraphTransaction) and schema caches (property keys, vertex/edge/index labels, in CachedSchemaTransactionV2). In multi-server deployments backed by HStore/PD, these two layers have fundamentally different cross-replica invalidation strategies โ and the graph cache layer has a documented gap in its clear/truncate path.
Graph (Vertex/Edge) Cache Invalidation#
CachedGraphTransaction holds per-graph verticesCache and edgesCache . Local invalidation happens in two ways:
- Per-commit: after
commitMutation2Backend, changed vertex IDs are invalidated individually; any edge or vertex change causes a fulledgesCache.clear(). - Store events (
store.init,store.clear,store.truncate): aStoreListenerHolderfiresclearCache(null, true)to wipe both caches and notify peer transactions on the same JVM .
Cross-replica gap: notifyGraphCacheClear and notifyGraphVertexCacheClear/notifyGraphEdgeCacheClear exist in GraphMetaManager and are published via metaDriver.put() to PD/etcd. However, neither clearBackend() nor truncateBackend() in StandardHugeGraph calls any of these . After a clear or truncate, other HStore replicas receive no PD notification and their graph caches remain stale until the entries expire or a new write arrives.
Similarly, GraphMetaManager.notifyGraphClear() โ which writes to the graphClearKey โ is never invoked from the clear/truncate call chain in the current codebase.
Schema Cache Invalidation#
Schema caches (CachedSchemaTransactionV2, HStore-only) use a PD-based meta-event mechanism:
- On
addSchema: always callsnotifySchemaCacheClear(), which writes a JSON payload containing the graph name and a per-JVM UUID (SCHEMA_CACHE_CLEAR_SOURCE) to theschemaCacheClearKeyin PD . - On
removeSchema: callsmaybeNotifySchemaCacheClear(), which suppresses the notification only whenTASK_SYNC_DELETION=true. - On
updateSchema(status flips): no notification is sent โ intentional to avoid a broadcast storm onupdateSchemaStatus()calls from background jobs . - On
clear()(used byclearBackend): callsclearCache(false)thennotifySchemaCacheClear().
Peer servers subscribe to the schemaCacheClearKey watch via listenSchemaCacheClear() . When a PD event arrives, handleSchemaCacheClearEvent filters out the originator's own events by matching SCHEMA_CACHE_CLEAR_SOURCE, then calls clearSchemaCache(graphName) on the name and id caches .
Schema Cache Convergence via PD Polling (PR #3237)#
The event-based path has two known failure modes: updateSchema/updateSchemaStatus never publishes an event (deliberate), and PD watch reconnects start from "now" and can miss events published during the gap (#3157).
PR #3237 (open, changes requested) addresses this by adding a SchemaVersionReconciler โ a periodic background poller that reads a per-graph version key (HUGEGRAPH/{cluster}/SCHEMA_VERSION/{graphspace}/{graph}) from PD every schema.sync.reconcile_interval seconds (default 10). Each schema mutation bumps the version key; when a peer's reconciler detects a version change it calls clearAllSchema(). This bounds worst-case convergence time to ceil(D/T)+1 ticks regardless of missed events. Configuration options schema.sync.enabled (default true) and schema.sync.reconcile_interval (default 10) control the behavior.
A key concern from review: the schema mutation writes to the backend before the version bump via a separate PD write. If the writer exits between those two calls, peer reconcilers will not detect the change until another mutation occurs or the graph restarts.
Key Source Files#
| File | Role |
|---|---|
CachedGraphTransaction | Vertex/edge cache; local event-based invalidation |
CachedSchemaTransactionV2 | Schema cache (HStore); PD meta-event invalidation |
GraphMetaManager | Publishes notifyGraphClear, notifyGraphCacheClear, notifySchemaCacheClear to PD/etcd |
StandardHugeGraph.clearBackend / truncateBackend | Does NOT call notifyGraphClear or notifyGraphCacheClear |
| PR #3237 | Schema cache convergence via PD polling (SchemaVersionReconciler) |
| Discussion #3205 | Design discussion for schema sync |
| Issue #3235 | Tracks known limits and configuration override options |