Repository navigation
Description
Split out of #5492. Found while building a reproduction for that issue; it is not attributable to materialized views (the A/B control with no view fails identically), so it is filed on its own.
Summary
On a 3-node Raft cluster, issuing concurrent single-record transactions against a follower's embedded Database handle corrupts records and loses a large fraction of committed writes. The engine logs invalid record sizes and silently deletes the affected records:
SEVER [LocalBucket] Invalid record size 570425357 for record #29:20: deleting record
SEVER [LocalBucket] Invalid record size 536870925 for record #28:27: deleting record
Typical outcome: 450 transactions all report success, and a node ends up holding 138-175 of them, with 200+ corruption log lines per run.
Scope - what does and does not fail
Three variants, same 3-node in-process harness (BaseRaftHATest, getServerCount() == 3):
| Writers | Target | Result |
|---|---|---|
| 3 threads, shared handle | follower | fails - 138-175 of 450 records, 200+ Invalid record size |
| 1 thread | follower | passes - 200/200 on all three nodes, zero corruption |
| 3 threads, shared handle | leader | passes - all records present, zero corruption |
So it needs concurrency and a follower. Concurrency alone against the leader is fine, and a follower alone is fine.
Ruled out:
- Not the materialized view: an identical control arm with no view over the type fails the same way.
- Not indexes: removing the
UNIQUEindex on the written type changed nothing (219 corruption lines without it).
Reproduction
Attached below. Extends BaseRaftHATest, 3 nodes, 3 threads x 150 single-record transactions through getServer((leaderIndex + 1) % 3).getDatabase(...), then compares per-node counts.
Reproduction test
final int leaderIndex = findLeaderIndex();
final Database leader = getServer(leaderIndex).getDatabase(getDatabaseName());
leader.command("sql", "CREATE DOCUMENT TYPE Unviewed");
waitForAllServers();
// Writes go through a FOLLOWER, from 3 concurrent threads sharing this handle.
final Database follower = getServer((leaderIndex + 1) % getServerCount()).getDatabase(getDatabaseName());
// ... 3 threads x 150 iterations of:
// follower.transaction(() -> follower.newDocument("Unviewed").set("value", v).save());
waitForAllServers();
for (int i = 0; i < getServerCount(); i++)
assertThat(countType(getServer(i).getDatabase(getDatabaseName()), "Unviewed")).isEqualTo(450L);
// -> AssertionFailedError: expected 450L but was 173LOpen question
It is not established whether sharing a single embedded Database handle across threads against a follower is a supported pattern. If it is not, the defect is arguably that it corrupts data instead of rejecting the usage - committed transactions reporting success while their records are later deleted as malformed is a bad failure mode either way.
The Invalid record size values (536870925, 570425357) look like a length field read from the wrong offset rather than random garbage, which would point at the follower-side forwarding path writing or reading a record frame inconsistently under concurrency.
Activity
address review: warn when the apply wait times out, cover the logInde…
address review: suppress the restart-window false alarm, tag the IT slow
fix(#5503): lock the modified files on replicas and hold them until t…
fix(#5503): lock the modified files on replicas and hold them until t…
fix(ArcadeData#6964): replay queued index changes on every commit1stP…
fix(#7641): wait for a replicated drop to actually apply locally befo…
address review: replica MAJORITY-committed path, index survives the h…
address review: reject over-long log index, reword the shared #5503 c…