incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

[Bug] Stale schema caches on HStore Servers: updates stay invisible, appends get overwritten, new indexes miss data

Open bitflicker64 opened this issue 2 months ago • 0 comments

Bug Type (问题类型)

logic (逻辑设计问题)

Before submit

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

Environment (环境信息)

  • Server Version: master 8828d8238 (built from source, 2026-11-13). First reported on 83ef9f3fa (2026-09-24, 3 Server pods on kind) with the same result for updates.
  • Backend: HStore, 1 PD + 1 Store + 3 Servers (S0, S1, S2) as local processes on one host
  • OS: 12 CPUs, 15 GB RAM, Ubuntu 24.04, Java 17

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

Rewritten on 2026-11-13. The first version of this issue described only the missing update notification and proposed a polling design, which review rejected in #3237. This version adds what was measured since and replaces the proposal.

With several Servers on HStore, a schema change made through one Server should reach the others within a bounded time, and a Server should never act on a schema copy that another Server has already replaced. Today neither holds.

CachedSchemaTransactionV2 keeps per-graph schema caches with expiry turned off. Another Server drops its cache only when a PD event arrives on the schema-cache-clear key. Four gaps follow from the code:

  1. updateSchema() publishes nothing. That covers a property append, user_data, the index list of a base label, and every status change (REBUILDING, CREATED, INVALID, DELETING, UNDELETED).
  2. removeSchema() and store clear or truncate publish only when task.sync_deletion=false (the default). Read from the code, not measured.
  3. An update writes the whole element from the writer's cached copy (SchemaTransactionV2.saveSchema()). A Server holding an old copy therefore overwrites what another Server committed.
  4. Events are delivered at most once. PD pushes an event to the watchers registered at that moment. After a disconnect KvClient waits one second before it subscribes again, the new subscription starts from "now", and the listener is not told, so nothing clears the cache afterwards.

What was measured

All four cases ran on the setup above on 2026-11-13 through the REST API, with no code changes.

Case Steps Result
Add, then update Create a property key through S0, then append user_data to another one through S0 The add showed up on S1 and S2 after 0.03 to 0.04 s. The update was still missing on both after 30 s.
Overwrite from an old copy S0 appends property p1 to a vertex label. Five seconds later S1 appends p2 to the same label. PD ends with [a, p2], so p1 is gone. S2 shows this after a reload and S0 shows it after a restart. A vertex write that sets p1 returns 201 on S0 and 400 Invalid property on S2.
Index creation, status Create 30 secondary indexes through S0, one at a time, while S1 and S2 each serve label scans and schema reads S1 and S2 keep the index at CREATING in 30 of 30 runs. Queries that use the index fail there with Can't query by label index ... in status CREATING.
Index creation, base label Same 30 runs S1 keeps a base label without the new index in 14 of 30 runs, S2 in 15 of 30. Every vertex written through a Server in that state (29 of 29) is missing from the index.
PD restart Restart PD, then commit one add through S0 as soon as PD accepts it (retried every 50 ms) In 3 of 3 runs S1 and S2 still do not list the key after 60 s. One more add brings them back.

For one of those 29 vertices, a label scan returns it, while the same index query returns 0 results on S0 (index CREATED), status CREATING on S1 and not indexed on S2. The S0 answer is wrong without any error.

Limits of these numbers: everything ran on one host with sub-millisecond latency, so the rates say that the cases happen, not how often they happen in production. With only schema reads as load on the other Servers, the base label case did not occur in 4 runs. The PD restart case forces the timing on purpose. A leader change among several PD nodes was not tested.

Why index creation goes wrong

addIndexLabel() writes the index label, publishes the add event, and only then writes the base label with the new index id. The base label write and the later status change to CREATED publish nothing (gap 1).

  • The add event makes the other Servers reload while the index is still CREATING. No later event corrects that, so the status result is the same on every run.
  • A busy Server can reload between the event and the base label write. It then keeps a base label without the index, and its vertex writes skip that index (GraphIndexTransaction.indexLabelIds() takes the list from the cached label).

Proposed fix for 1.8.0, pending maintainer confirmation

One Server-side change that completes the existing clear event. No change to PD's raft, store or kv.proto; the only PD code touched is the client library.

Change Gap it closes
Publish after updateSchema(), and always on remove and on store clear or truncate 1, 2 and the index status case. The base label case too, except for the window described below.
A callback in KvClient that fires when a watch starts or restarts. The Server clears its V2 schema caches when it fires. 4
A publish that fails after the schema write no longer fails the call. The graph goes into a pending set and is published again with backoff and whenever the watch restarts. Each Server also publishes once when it opens a graph. A committed change whose event was never sent
A generation counter and a short lock on the shared cache. A read, a listing or a write-through that started before a clear cannot put its value into the cache afterwards. An older value cached again after a clear

Every event clears at once. Events are not delayed or merged, because a delayed clear leaves a Server on the old base label for longer (see the index window below).

What this change guarantees

  1. Every committed add, update, status change and remove is published after its write. Every Server with a live watch drops its copy and reads PD on the next use.
  2. A Server whose watch was down drops all its copies when the watch is back, so nothing missed in between survives.
  3. A value read from PD before a clear is never cached after that clear. This covers single reads, full listings and the writer's own write-through.
  4. A change whose publish failed is published again as soon as the writer reaches PD, or when the writer restarts.

These hold once every Server runs the new version. A reload right after a PD leader change also needs #3383, so the read cannot be served by a leader that has not applied its log yet.

What it does not guarantee

These need Servers to confirm a change before an operation continues, a conditional write in PD, or a transport change. They are proposed as later work.

  • Writes during index creation. A write is missing from a new index when both of these hold:

    • The Server handling the write prepares it from a base label that does not list the index. GraphTransaction.prepareCommit() takes the index list from the cached label, and a Server has the old label until it has handled the base label event.
    • The write reaches the Store after the rebuild has read that part of the label. IndexLabelRebuildJob reads the label once, in pages, and starts as soon as the task is scheduled.

    Writes that meet the first condition but commit before the rebuild reaches them are indexed by the rebuild. What can still be lost is a write on another Server that is prepared before that Server handles the event and committed after the rebuild has passed. Normally that is a write in flight during those few milliseconds. It grows when a Server handles the event late: after a long pause, or when its watch is down while the index is created (a reconnect takes at least one second). Nothing forces the rebuild to wait, so this cannot be ruled out without a barrier: the rebuild would have to start only after every Server has confirmed the new base label. Adds and property updates lose their entry. This is derived from the code and was not reproduced.

  • A writer that stops for good between its schema write and its publish. The other Servers keep the old copy until the next event for that graph or their next watch restart. If the writer restarts, its publish on graph open repairs this.

  • Two Servers changing the same schema element at the same time. An update still writes the whole element from the writer's copy, so one change can be lost. That needs a conditional write in PD (#3376 is the transactional write).

  • A Server that cannot reach PD keeps serving its cached schema until it reconnects. Refusing requests in that state is an availability decision.

  • A watch stream that dies without an error is noticed only when another PD call from that Server fails. The PD client channels have no keepalive.

Two notes for the release:

  • A Server on the old version still publishes nothing on update, so the guarantees start when the last Server is upgraded.
  • Index entries skipped before the fix stay missing. An index created on a cluster with several Servers needs a rebuild after the upgrade.

Related: discussion #3205 (background), #2617 (original report), #3011 (the current event path), #3157 (watch recovery), #3237 (the polling attempt, closed), #3383 (ReadIndex before PD reads).

bitflicker64 avatar Sep 24 '26 10:09 bitflicker64