Repository navigation
Description
Summary
On a 3-node Raft HA cluster, the presence of a materialized view on a database causes the leader to ship a TX_ENTRY whose page version is ahead of what followers hold. Followers throw WALVersionGapException, trigger a full snapshot resync, and the resync does not repair it - the next entry gaps again on a different file. The cluster enters a resync loop, every request routed to a resyncing follower is deflected with a 503, and the run ends with committed writes permanently missing from one node.
This is lost data, not split-brain: the affected node's id set is a strict subset of the others.
Scope note (2026-07-29). This issue originally bundled two defects. The second one - materialized view refresh requests being dropped rather than queued when a refresh was already running - was confirmed, fixed and merged in #5502 (
6642e203e). That half is done and has been removed from this description. What remains, and what this issue now tracks exclusively, is the replication defect below.
Evidence: controlled A/B
Same load, same cluster, same client. The only difference is whether the schema contains a materialized view.
| Arm | Result |
|---|---|
With CREATE MATERIALIZED VIEW UserStats ... REFRESH INCREMENTAL |
2041/3000 user writes fail, 12 snapshot-resync cycles in ~9 s, nodes freeze at 1120/1122/1122 users and never converge |
| Without the view | 3000/3000 users, 30000/30000 photos, zero errors, all three nodes converge immediately |
Reproduced twice locally against arcadedata/arcadedb:latest. The view is the trigger, not the load and not the client.
Causal chain
- The leader ships a
TX_ENTRYwhose page version is 2 ahead of what followers hold. The first occurrence is identical and simultaneous on both followers:PageId(/142/0) version in WAL (1648) does not match with existent version (1646). Identical on both followers points at a leader-side replication-completeness defect, not a follower race. File 142 is the materialized view's own backing bucket (UserStats_1.142.65536.v0.bucket, confirmed by creating the same schema standalone and reading the file names). - The follower throws
WALVersionGapException->ReplicationException: WAL version gap detected - snapshot resync requiredand starts a full snapshot resync. - The resync does not fix it. The very next entry gaps on a different file (
User_0, fileId 1, WAL 304 vs local 302). This loops 12 times. - While resyncing,
AbstractServerHttpHandler.handleRequestdeflects every request with503 Server is installing a snapshot, please retry. A client writing exclusively through that follower loses those writes. - Final state: one node's User id set is a strict subset of the other two, missing specific ids plus their dependent records.
Leading candidate: recordFileChanges drops buffered WAL entries
RaftReplicatedDatabase.recordFileChanges buffers WAL produced by commits that run inside the DDL callback, then decides whether to ship it:
// ha-raft/.../RaftReplicatedDatabase.java
final List<byte[]> walEntries = new ArrayList<>(schemaWalBuffer.get());
final List<Map<Integer, Integer>> bucketDeltas = new ArrayList<>(schemaBucketDeltaBuffer.get());
schemaWalBuffer.get().clear();
schemaBucketDeltaBuffer.get().clear();
if (!addFiles.isEmpty() || !removeFiles.isEmpty() || schemaChanged) { // <-- walEntries NOT in the condition
...replicateSchema(..., walEntries, bucketDeltas);
}walEntries is omitted from the guard, and the finally block clears the buffers unconditionally. So when a callback commits pages but creates/removes no file and leaves the schema version unchanged, the leader applies those pages locally and never ships them. Follower page versions then trail the leader's by exactly the number of dropped page writes, which is the shape reported above (leader 1648 vs follower 1646).
The sibling method runWithCompactionReplication guards the same buffers correctly:
if (addFiles.isEmpty() && removeFiles.isEmpty() && walEntries.isEmpty() && sealedBlobs.isEmpty())
return result;That asymmetry is a genuine leader-side "applied locally, never replicated" hole regardless of materialized views. It has not been shown to be the path the MV refresh takes, so fixing it may not by itself close the A/B gap - but it is a real correctness defect on the Raft leader path and should be closed on its own merits.
What is NOT the cause
Please do not re-propose these; they were checked and ruled out:
- "The refresh commits on the inner
LocalDatabase, bypassing replication." Wrong.LocalSchemais constructed withwrappedDatabaseInstance(LocalDatabase.java:2423), so the refresh does go throughRaftReplicatedDatabase. - The
SCHEMA_ENTRY/ file-creation ordering race of Multiple warning over lost indexes on massive insert with gRPC #4083. The backing type has 10 buckets and no indexes. - Follower-side race. The first gap is byte-identical and simultaneous on both followers.
- HA: concurrent transactions on a shared follower Database handle corrupt records and lose committed writes #5503 (concurrent writes on a shared follower handle corrupting records). Found and fixed separately (
0f414e877). It is a different failure mode -Invalid record size ... deleting record, no version gap - and the no-view control arm was clean, so it does not explain the A/B difference.
Not reproduced in-process
A 3-node in-process Raft harness built on BaseRaftHATest (whose consistency check routes through DatabaseComparator and fails on any cross-node page-version mismatch) produced zero WALVersionGapException and zero resync loops across every configuration tried: writes on the leader, writes through a follower, with and without a UNIQUE index on the source type, at 180 and 450 records. The container-based A/B remains the only known reproduction.
Still unproven: the exact leader-side path by which the refresh's page mutation escapes replication. The refresh runs TRUNCATE TYPE ... UNSAFE (which commits the enclosing transaction mid-scan, TruncateTypeStatement.java:112-114) plus a full re-run of the defining query inside a dedicated transaction (joinCurrentTx=false), started from an after-commit callback of the source transaction on concurrent writer threads.
Reproduction
load-tests/src/test/java/com/arcadedb/test/load/ThreeNodesLoadTestIT.java is the closest existing harness (3-node Raft HA, 3 threads x 1000 users x 10 photos, Awaitility convergence check). To reproduce, add a REFRESH INCREMENTAL materialized view over the User type to the schema setup and run both arms. Diffing the per-node id sets from /api/v1/server?mode=cluster distinguishes the two failure modes: a subset means lag or loss, a mutual difference means divergence.
Note that the numbers in the A/B table above were measured before #5502 and #5503 were fixed; a re-run on current main is worthwhile to confirm the symptom is unchanged.
Impact
Silent loss of committed writes on any HA cluster whose database carries a materialized view, plus a sustained 503 storm while the resync loop runs. Worth treating as a correctness bug rather than a performance one.
Activity
robfrank commentedon Jul 28, 2026
Picked this up. Taking you up on the offer to split: PR #5502 fixes the second defect, and deliberately does not close this issue - the replication half is still open.
Second defect: fixed (#5502)
Confirmed and fixed the dropped-refresh half, though the mechanism is slightly different from the framing in the report. The harm is not just that a concurrent refresh is skipped - it is that the refresh is triggered from a post-commit callback, so the request that gets dropped belongs to a transaction that has already committed, and the in-flight refresh it defers to started before that commit. Nothing reschedules, so the view stays missing those records indefinitely.
Reproduced with no HA involved at all, as you suspected: a 3-node run showed the leader's own view holding 449 of 450 committed records.
The fix coalesces requests onto the running refresh rather than dropping them. Releasing ownership and testing for a pending request had to become one atomic step - split in two, a request registered in between is seen by neither the outgoing owner nor the requester, which is the same lost-wakeup in a narrower window.
I did not implement true incremental maintenance.
MaterializedViewChangeListenerstill schedules a full refresh regardless ofREFRESH INCREMENTAL. Per-record maintenance is a feature with real correctness risk (wrong view contents rather than merely slow ones), and coalescing already removes the redundant rebuilds that made the with-view arm collapse.Replication half: not reproduced, staying open
Built a 3-node in-process Raft harness (
BaseRaftHATest, whose consistency check routes throughDatabaseComparatorand fails on any cross-node page-version mismatch). Got zeroWALVersionGapExceptionand zero resync loops across every configuration: writes on the leader, writes through a follower, with and without a UNIQUE index on the source type, at 180 and 450 records. Since the root cause is unproven, I did not want to ship a speculative change to the Raft commit path.Two notes on the analysis in your report:
LocalSchemapoint.LocalSchemais constructed withwrappedDatabaseInstance(LocalDatabase.java:2423), so the refresh does go throughRaftReplicatedDatabase. Worth keeping that ruled out.RaftReplicatedDatabase.recordFileChangesdrains buffered WAL intowalEntries, but its replication guard omitswalEntriesfrom the condition and thefinallythen clears the buffer. Its siblingrunWithCompactionReplicationguards correctly against exactly that. If the leader really is applying pages it never ships, that shape is worth a look.Unrelated defect found on the way: #5503
Concurrent single-record transactions through a follower's handle corrupt records and lose 60-70% of committed writes, logging
Invalid record size ... deleting record. Your A/B methodology caught it: the control arm with no view fails identically, so it is not view-related. Single-threaded follower writes are clean, and concurrent writes against the leader are clean. Filed as #5503 with the repro.fix(#5492): coalesce materialized view refresh requests instead of dr…
docs: record PR, split-out issue and review history for #5492
docs: record the second review cycle for #5492
fix(#5492): coalesce materialized view refresh requests instead of dr…
robfrank commentedon Jul 29, 2026
Scope trimmed. The second defect (dropped refresh requests) is fixed and merged in #5502 (
6642e203e) and has been removed from the description - this issue now tracks the replication half only.Promoted the one provable leader-side defect out of the "not yet proven" section into its own heading:
RaftReplicatedDatabase.recordFileChangesomitswalEntriesfrom its replication guard while thefinallyclears the buffer unconditionally, so a DDL callback that commits pages without creating a file or bumping the schema version has those pages applied on the leader and never shipped.runWithCompactionReplicationguards the identical buffers correctly. That produces exactly the reported shape - follower page versions trailing the leader's - and is a correctness defect on the Raft leader path whether or not it turns out to be the materialized view's route.Also ruled out #5503 explicitly (different failure mode, and the no-view control arm was clean) so it does not get re-proposed.
Picking up the
recordFileChangesfix now.fix(#5492): recordFileChanges ships the WAL its callback committed (#…
docs(ha-raft): replace the #5492 sharp-edge note with the wrapper-vs-…
address review: fix the analyze() execution path too, repair orphaned…
address review: decide the load test on scanned counts, not the drift…
fix(engine) #5492: execute SQL statements against the replicated data…
fix(#5492): coalesce materialized view refresh requests instead of dr…
fix(#5492): recordFileChanges ships the WAL its callback committed (#…
fix(engine) #5492: execute SQL statements against the replicated data…
fix(#10220): a Gremlin write run through Database.command() with no t…