Repository navigation
Description
Summary
Concurrent transactions that each run MERGE (c:C {id: id}) ... ON MATCH SET c.n = c.n + 1 can lose an
increment. Two transactions write the same new value to the same record, and the server confirms
both commits (CommitTransactionResponse.committed = true). No call fails, no error is logged, and
the server's own update stats count both increments. The final value is lower than the number of
committed increments.
It happens with the default isolation of the Python gRPC driver (client.transaction(db), which sends
isolation 0 = READ_UNCOMMITTED, mapped by the server to READ_COMMITTED) and with explicit READ_COMMITTED.
It does not happen with REPEATABLE_READ (0 losses in 100 runs).
Seen on 26.9.1 and on 26.10.1-SNAPSHOT (main 0ce6fa7ce5294a53716f2b2531af7edc554e7670).
Environment
- ArcadeDB 26.9.1 (build
9cea8e848fa57d275b8d614328245508cd76614a), image
arcadedata/arcadedb@sha256:02a1a74fcef3c9d91e680262ddb7fde05ff9cfb356b366e7faf8e41d80995a70 - ArcadeDB 26.10.1-SNAPSHOT (build
0ce6fa7ce5294a53716f2b2531af7edc554e7670), image
arcadedata/arcadedb@sha256:82f823a1bf44e6bc79dbfe9a41e114be4d55da4527723d546328f3af043d7587 - Server settings: defaults plus the gRPC plugin (
-Darcadedb.server.plugins=gRPC:com.arcadedb.server.grpc.GrpcServerPlugin),-Xms256m -Xmx768m - Client: Python 3.12,
arcadedb-driver-grpc0.1.0 (grpcio 1.84.0, protobuf 7.36.2) - Host: macOS arm64, Docker 29.8.0 (linux/arm64)
Steps to reproduce
docker run -d --name arcadedb-lostupdate -p 50051:50051 -p 2480:2480 \
-e ARCADEDB_SETTINGS="-Darcadedb.server.rootPassword=playwithdata -Darcadedb.server.plugins=gRPC:com.arcadedb.server.grpc.GrpcServerPlugin" \
arcadedata/arcadedb:26.9.1
python3.12 -m venv .venv && .venv/bin/pip install arcadedb-driver-grpc
.venv/bin/python repro_lost_update.py --target localhost:50051 --password playwithdata --runs 50The script (below) does this in a fresh database per run:
CREATE VERTEX TYPE C; CREATE PROPERTY C.id STRING; CREATE INDEX ON C (id) UNIQUE;- 8 threads start together. Each thread runs 10 explicit transactions (
BeginTransaction→
ExecuteCommand→CommitTransaction). Each transaction runs one Cypher command over the ids
c0..c99:A transaction that fails withUNWIND $ids AS id MERGE (c:C {id: id}) ON CREATE SET c.n = 1 ON MATCH SET c.n = c.n + 1 RETURN c.id AS id, c.n AS n
ABORTEDorALREADY_EXISTSis retried in a new transaction. - It checks the result: every committed transaction increments every id once, so every
nmust
equal the number of committed transactions (80), andsum(n)must be 8000.
The script keeps the value that each committed transaction wrote (from RETURN). For one record, the
committed values must be 1..80, each once.
Expected
For every record, n = number of committed transactions that incremented it (80). Two committed
transactions never write the same value of n. If two transactions update the same record
concurrently, one of them must fail at commit (as most of them do: ABORTED "Slot rebase not possible
... concurrent change to the same record").
Actual
In 36-56 % of the runs (table below), one record ends at 79 (sometimes 78). Its value history shows one value
written by two committed transactions, and the top value never written:
run 2: committed tx=80 expected sum(n)=8000 actual sum(n)=7999 lost silently=1 (server-reported increments=8000) conflict retries=185 visible failures=0 0.24s
LOST UPDATE: {"id": "c0", "rid": "#5:14336", "final_n": 79, "committed_transactions_that_wrote_it": 80, "values_written_by_two_or_more_committed_tx": {"35": ["tx_e8bed6de-9442-46bd-af46-68639a5ba83f", "tx_9644085d-5bfc-4b32-a739-7d4098936f84"]}, "values_never_written": [80]}
Both tx_e8bed6de… and tx_9644085d… wrote n = 35 to c0, and both commits returned committed=true.
| Server | Shape | Isolation | Runs | Runs with a silent loss | Increments lost |
|---|---|---|---|---|---|
| 26.9.1 | 8 writers × 10 tx × 100 ids | default (client.transaction) |
50 | 24 | 33 |
| 26.9.1 | same | READ_COMMITTED | 50 | 18 | 20 |
| 26.9.1 | same | REPEATABLE_READ | 50 | 0 | 0 |
| 26.10.1-SNAPSHOT | 8 writers × 10 tx × 100 ids | default (client.transaction) |
50 | 21 | 24 |
| 26.10.1-SNAPSHOT | same | READ_COMMITTED | 50 | 28 | 33 |
| 26.10.1-SNAPSHOT | same | REPEATABLE_READ | 50 | 0 | 0 |
| 26.10.1-SNAPSHOT | 1 id only | default | 30 | 15 | 25 |
| 26.10.1-SNAPSHOT | 2 writers × 40 tx × 100 ids | default | 30 | 9 | 11 |
| 26.10.1-SNAPSHOT | nodes pre-created with n = 0 (every MERGE takes ON MATCH) |
default | 30 | 11 | 15 |
| 26.10.1-SNAPSHOT | pre-created, ids sent in reverse order | default | 30 | 13 | 17 |
No run had a visible failure (every batch committed within 50 retries).
Observations that may help
- The lost record is always the first record that the transaction updates (the first id in the
UNWINDlist). With the default order it is alwaysc0. With the list reversed (records still
createdc0first) it is alwaysc99(#5:99). With pre-created nodes, all 100 records are on page 0,
and still only the first record in the list loses. The other 99 records in the same transactions
never lose an increment. - The create path of MERGE is not needed: with pre-created nodes every MERGE only matches, and the
loss still happens. One record and 8 writers is enough. - The server's command stats (
properties_set − nodes_created) of the committed transactions add up to
the full count (for example 8000), but the storedsum(n)is lower. - The server detects most of the concurrent changes: 26.9.1 logged 27,085
ABORTED"Commit failed: Slot
rebase not possible on page ... (concurrent change to the same record)" and 714ALREADY_EXISTS
"Duplicated key" commit failures during the runs. The two confirmed commits that lose the update are
not logged (only failed calls are logged). - REPEATABLE_READ has 0 losses with about the same number of conflicts (mean ~185 retries per run).
- An independent client shows the same: our .NET gRPC driver (2,080 runs on both images) sees the same
loss on the first record. Its wire log shows, for every traced loss, two different transactions where
the second one'sExecuteCommandstarts while the first one'sCommitTransactionis still running;
both commits returnsuccess=true, committed=true, and both commands carry their own transaction id.
In the same .NET runs, SQLUPDATE C SET n = n + 1 WHERE id IN :idsand Cypher
MATCH (c:C) WHERE c.id IN $ids SET c.n = c.n + 1(nodes created first) had 0 silent losses in 240
runs each.
Impact
Silent data loss for read-modify-write work under the default isolation. A client cannot detect it:
every call succeeds and every commit is confirmed. The Python gRPC driver's client.transaction(db)
has no isolation argument, so its users always get READ_COMMITTED.
Workaround: begin the transaction with isolation = REPEATABLE_READ.
Reproduction script
repro_lost_update.py (Python 3.10+, pip install arcadedb-driver-grpc)
#!/usr/bin/env python3
"""Reproduces a lost update in ArcadeDB: two concurrent transactions both commit, one increment is gone.
Uses the official Python gRPC driver (`pip install arcadedb-driver-grpc`, docs:
https://docs.arcadedb.com/arcadedb/how-to/connectivity/drivers/python-grpc).
One run, in a fresh database:
1. Schema: CREATE VERTEX TYPE C; CREATE PROPERTY C.id STRING; CREATE INDEX ON C (id) UNIQUE;
2. WRITERS threads start together. Each thread runs BATCHES explicit transactions. Each transaction
runs ONE Cypher command over the same ids ("c0" .. "c99") and then commits:
UNWIND $ids AS id
MERGE (c:C {id: id}) ON CREATE SET c.n = 1 ON MATCH SET c.n = c.n + 1
RETURN c.id AS id, c.n AS n
A transaction that fails with ABORTED or ALREADY_EXISTS (the server's write-write conflict
codes) is retried in a new transaction, up to RETRIES times.
3. Expected: every committed transaction increments every id once, so each C.n equals the number of
committed transactions (WRITERS * BATCHES when no batch gives up), and
sum(n) == committed transactions * IDS.
The script keeps, for every COMMITTED transaction (the driver's commit returned committed=true), the
value that the transaction wrote to each id (from RETURN). With no lost update, the committed values
of one id are exactly 1 .. k (k = committed transactions), each once. A lost update shows as one value
written by TWO committed transactions and the top value never written. "lost silently" counts only
increments of committed transactions; a batch that gives up after RETRIES conflicts is reported as a
visible failure and is not counted as a loss.
Isolation modes:
default -> client.transaction(db) exactly as documented (BeginTransaction sends isolation 0;
the server maps it to READ_COMMITTED)
read_committed -> BeginTransaction with isolation=READ_COMMITTED
repeatable_read -> BeginTransaction with isolation=REPEATABLE_READ (control)
Shape options:
--ids 1 one record only
--precreate create every node with n = 0 first, so every MERGE takes the ON MATCH path
--reverse writers send the ids in reverse order (the lost record follows the first id sent)
Server under test (example):
docker run -d --name arcadedb-lostupdate -p 50051:50051 -p 2480:2480 \\
-e ARCADEDB_SETTINGS="-Darcadedb.server.rootPassword=playwithdata \\
-Darcadedb.server.plugins=gRPC:com.arcadedb.server.grpc.GrpcServerPlugin" \\
arcadedata/arcadedb:26.9.1
python repro_lost_update.py --target localhost:50051 --password playwithdata --runs 50
Exit code: 0 when no run lost an update, 1 when at least one run lost an update, 2 on a setup error.
"""
from __future__ import annotations
import argparse
import collections
import json
import sys
import threading
import time
import uuid
from concurrent.futures import ThreadPoolExecutor
import grpc
from arcadedb_driver_grpc import Transaction, TransactionHandle, create_client, messages, password_auth
from arcadedb_driver_grpc._generated.arcadedb_server_pb2_grpc import ArcadeDbAdminServiceStub
MERGE = (
"UNWIND $ids AS id "
"MERGE (c:C {id: id}) ON CREATE SET c.n = 1 ON MATCH SET c.n = c.n + 1 "
"RETURN c.id AS id, c.n AS n"
)
SCHEMA = "CREATE VERTEX TYPE C; CREATE PROPERTY C.id STRING; CREATE INDEX ON C (id) UNIQUE;"
CONFLICT_CODES = (grpc.StatusCode.ABORTED, grpc.StatusCode.ALREADY_EXISTS)
class IsolatedTransaction(Transaction):
"""The driver's Transaction, but BeginTransaction carries an explicit isolation level.
The driver's `client.transaction(db)` has no isolation argument, so this subclass sends the same
BeginTransactionRequest plus `isolation`. Commit, rollback and the committed=true check are the
driver's own code.
"""
def __init__(self, raw, database: str, isolation: int) -> None:
super().__init__(raw, database)
self._isolation = isolation
def __enter__(self):
begun = self._raw.BeginTransaction(
messages.BeginTransactionRequest(database=self._database, isolation=self._isolation)
)
if not begun.transaction_id.strip():
raise RuntimeError("BeginTransaction returned no transaction id")
self._transaction_id = begun.transaction_id
return TransactionHandle(self._raw, self._database, self._transaction_id)
def value_of(v: messages.GrpcValue):
kind = v.WhichOneof(v.DESCRIPTOR.oneofs[0].name)
if kind is None:
return None
if kind == "link_value":
return v.link_value.rid
return getattr(v, kind)
def string_list(values: list[str]) -> messages.GrpcValue:
return messages.GrpcValue(list_value=messages.GrpcList(values=[messages.GrpcValue(string_value=s) for s in values]))
def run_once(client, admin, creds, run_no: int, args) -> dict:
database = f"lu{run_no:04d}_{uuid.uuid4().hex[:6]}"
admin.CreateDatabase(messages.CreateDatabaseRequest(credentials=creds, name=database, type="graph"))
try:
client.raw.ExecuteCommand(messages.ExecuteCommandRequest(database=database, command=SCHEMA, language="sqlscript"))
ids = [f"c{i}" for i in range(args.ids)]
if args.precreate:
# Every node exists with n = 0 before the writers start, so every MERGE takes the ON MATCH path.
create = messages.ExecuteCommandRequest(
database=database, command="UNWIND $ids AS id CREATE (:C {id: id, n: 0})", language="cypher"
)
create.parameters["ids"].CopyFrom(string_list(ids))
client.raw.ExecuteCommand(create)
isolation = {
"read_committed": messages.TransactionIsolation.Value("READ_COMMITTED"),
"repeatable_read": messages.TransactionIsolation.Value("REPEATABLE_READ"),
}.get(args.isolation)
def new_transaction():
if isolation is None:
return client.transaction(database) # documented API, default isolation
return IsolatedTransaction(client.raw, database, isolation)
lock = threading.Lock()
committed: list[dict] = [] # one entry per committed transaction
conflicts = collections.Counter()
failures: list[str] = []
start = threading.Barrier(args.writers)
def writer(w: int) -> None:
start.wait()
for b in range(args.batches):
for attempt in range(1, args.retries + 2):
request = messages.ExecuteCommandRequest(command=MERGE, language="cypher", return_rows=True)
request.parameters["ids"].CopyFrom(string_list(list(reversed(ids)) if args.reverse else ids))
try:
with new_transaction() as tx:
tx_id = tx._transaction_id
response = tx.execute_command(request)
written = {value_of(r.properties["id"]): value_of(r.properties["n"]) for r in response.records}
stats = response.stats
# The driver's __exit__ committed and checked committed=true.
with lock:
committed.append({
"writer": w, "batch": b, "attempt": attempt, "tx": tx_id, "written": written,
"increments_reported": stats.properties_set - stats.nodes_created,
})
break
except grpc.RpcError as error:
code = error.code()
if code in CONFLICT_CODES and attempt <= args.retries:
with lock:
conflicts[code.name] += 1
continue
with lock:
failures.append(f"w{w} b{b} a{attempt}: {code.name}: {error.details()}")
break
except Exception as error: # noqa: BLE001 - a non-gRPC failure is reported, never hidden
with lock:
failures.append(f"w{w} b{b} a{attempt}: {type(error).__name__}: {error}")
break
started = time.monotonic()
with ThreadPoolExecutor(max_workers=args.writers) as pool:
list(pool.map(writer, range(args.writers)))
elapsed = time.monotonic() - started
result = client.raw.ExecuteQuery(
messages.ExecuteQueryRequest(database=database, query="SELECT @rid AS rid, id, n FROM C", language="sql")
)
rows = {}
for batch in result.results:
for record in batch.records:
rows[value_of(record.properties["id"])] = (value_of(record.properties["n"]), value_of(record.properties["rid"]) or record.rid)
# Every committed transaction incremented every id once, so each id must end at the number of
# committed transactions that wrote it. A batch that failed visibly (not committed) is not counted.
total = sum(n for n, _ in rows.values())
writes_per_id = collections.Counter(i for entry in committed for i in entry["written"])
expected_sum = sum(writes_per_id.values())
# For a wrong id, the values written by its committed transactions must be 1..k, each once.
evidence = []
for i in ids:
final_n, rid = rows.get(i, (None, None))
k = writes_per_id[i]
if final_n == k:
continue
by_value = collections.defaultdict(list)
for entry in committed:
if i in entry["written"]:
by_value[entry["written"][i]].append(entry["tx"])
evidence.append({
"id": i,
"rid": rid,
"final_n": final_n,
"committed_transactions_that_wrote_it": k,
"values_written_by_two_or_more_committed_tx": {v: txs for v, txs in sorted(by_value.items()) if len(txs) > 1},
"values_never_written": sorted(set(range(1, k + 1)) - set(by_value)),
})
return {
"run": run_no,
"database": database,
"isolation": args.isolation,
"seconds": round(elapsed, 2),
"nodes": len(rows),
"committed_transactions": len(committed),
"expected_sum": expected_sum,
"sum_n": total,
"lost_silently": expected_sum - total,
"increments_reported_by_server": sum(e["increments_reported"] for e in committed),
"conflict_retries": dict(conflicts),
"failures": failures,
"evidence": evidence,
}
finally:
if not args.keep_databases:
admin.DropDatabase(messages.DropDatabaseRequest(credentials=creds, name=database))
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--target", default="localhost:50051", help="gRPC host:port")
parser.add_argument("--user", default="root")
parser.add_argument("--password", required=True)
parser.add_argument("--runs", type=int, default=100)
parser.add_argument("--writers", type=int, default=8)
parser.add_argument("--batches", type=int, default=10)
parser.add_argument("--ids", type=int, default=100)
parser.add_argument("--retries", type=int, default=50)
parser.add_argument("--isolation", choices=["default", "read_committed", "repeatable_read"], default="default")
parser.add_argument("--precreate", action="store_true",
help="create every node with n = 0 before the writers start (MERGE then only matches)")
parser.add_argument("--reverse", action="store_true",
help="writers send the ids in reverse order (c99 first); records are still created c0 first")
parser.add_argument("--keep-databases", action="store_true", help="do not drop the database after each run")
parser.add_argument("--jsonl", help="also write one JSON line per run to this file")
args = parser.parse_args()
creds = messages.DatabaseCredentials(username=args.user, password=args.password)
admin = ArcadeDbAdminServiceStub(grpc.insecure_channel(args.target))
try:
info = admin.GetServerInfo(messages.GetServerInfoRequest(credentials=creds))
except grpc.RpcError as error:
print(f"setup error: GetServerInfo failed: {error.code().name}: {error.details()}", file=sys.stderr)
return 2
print(f"ArcadeDB {info.version} ({info.edition}) at {args.target}; isolation={args.isolation}; "
f"{args.writers} writers x {args.batches} transactions x {args.ids} ids; retries<={args.retries}; runs={args.runs}")
out = open(args.jsonl, "a", encoding="utf-8") if args.jsonl else None
loss_runs = 0
total_lost = 0
failed_runs = 0
with create_client(args.target, insecure=True, auth=password_auth(args.user, args.password)) as client:
for run_no in range(1, args.runs + 1):
result = run_once(client, admin, creds, run_no, args)
if out:
out.write(json.dumps(result) + "\n")
out.flush()
retries = sum(result["conflict_retries"].values())
line = (f"run {run_no:4d}: committed tx={result['committed_transactions']} expected sum(n)={result['expected_sum']} "
f"actual sum(n)={result['sum_n']} lost silently={result['lost_silently']} "
f"(server-reported increments={result['increments_reported_by_server']}) "
f"conflict retries={retries} visible failures={len(result['failures'])} {result['seconds']}s")
if result["failures"]:
failed_runs += 1
line += "\n VISIBLE FAILURE (not a lost update; the batch was not committed): " + "; ".join(result["failures"][:3])
if result["lost_silently"] != 0:
loss_runs += 1
total_lost += result["lost_silently"]
for item in result["evidence"]:
line += "\n LOST UPDATE: " + json.dumps(item)
print(line, flush=True)
print(f"SUMMARY: ArcadeDB {info.version}; isolation={args.isolation}; runs={args.runs}; "
f"runs with a silent lost update={loss_runs}; increments lost silently={total_lost}; "
f"runs with a visible (non-silent) failure={failed_runs}")
return 1 if loss_runs else 0
if __name__ == "__main__":
sys.exit(main())
Activity
shlomiassaf commentedon Sep 27, 2026
Lost update reproduction — results (2026-09-27)
Script:
repro_lost_update.py(Python 3.12,arcadedb-driver-grpc0.1.0, grpcio 1.84.0, protobuf 7.36.2).Host: macOS arm64, Docker 29.8.0 (linux/arm64). One container per server, default settings plus the gRPC plugin,
-Xms256m -Xmx768m. Retries on ABORTED / ALREADY_EXISTS: up to 50 per transaction.Servers:
arcadedata/arcadedb@sha256:02a1a74fcef3c9d91e680262ddb7fde05ff9cfb356b366e7faf8e41d80995a709cea8e848fa57d275b8d614328245508cd76614aarcadedata/arcadedb@sha256:82f823a1bf44e6bc79dbfe9a41e114be4d55da4527723d546328f3af043d75870ce6fa7ce5294a53716f2b2531af7edc554e7670(main, 2026-09-27)Runs
"Lost silently" = (committed transactions × ids) − sum(n). Only transactions whose commit returned
committed=trueare counted. Visible failures (a batch that gave up) were 0 in every set below.client.transaction)c0c0client.transaction)c0c0--ids 1)c0c0--precreate), 100 idsc0(#5:0)c0(#5:0)--reverse)c99(#5:99)Observations:
transactions and the top value never written. Both transactions' commits returned
committed=true; no call failed.properties_set − nodes_created) of the committedtransactions add up to the full expected count (for example 8000), but
sum(n)is lower (7999).UNWINDlist). With the list reversed, the loss moves fromc0toc99. With pre-created nodes, all100 records share page 0 and still only the first one in the list loses.
ABORTED"Commit failed: Slot rebase not possible on page ... (concurrentchange to the same record)" and 714
ALREADY_EXISTS"Duplicated key" commit failures; the snapshot wrote47,093 and 939. The server logs only failed calls, so there is no line for the two confirmed commits that
lost the update.
Sample output
26.10.1-SNAPSHOT, READ_COMMITTED, 8 writers × 10 tx × 100 ids:
26.9.1, default (
client.transaction(db)exactly as documented):26.10.1-SNAPSHOT, one pre-created record, 8 writers × 10 tx (two increments lost in one run):
26.10.1-SNAPSHOT, pre-created, ids reversed (the loss moves to the first id sent):
Raw per-run data:
results-*.jsonl; full console output:output-*.txt; server logs:server-*.log.fix(#8538): reload expression and label-write targets, review follow-ups
fix(#8538): reload every target a reload turns into a write
style(#8538): re-wrap Javadoc, scope the PROPERTY case, drop a double…
fix(#8538): settle SET reloads per record, align aliases, reset dynam…
test(#8538): review follow-ups
test(#8538): pin the modify() buffer contract, tag the stress test slow
15 remaining items
lvca commentedon Sep 29, 2026
Our CI builds the snapshot in about 10 minutes from the commit. Sometimes snapshot are cached in your computer, so make sure you are downloading the latest (remove the previous one if you want to be sure).
fix(#8538): MERGE ON MATCH SET no longer loses a concurrent increment
fix(#8538): reload expression and label-write targets, review follow-ups
fix(#8538): reload every target a reload turns into a write
style(#8538): re-wrap Javadoc, scope the PROPERTY case, drop a double…
fix(#8538): settle SET reloads per record, align aliases, reset dynam…
test(#8538): review follow-ups
test(#8538): pin the modify() buffer contract, tag the stress test slow
fix(#8538): an identity-less target never asks for another reload round
docs(#8538): pin the buffer-replacement contract of pinPageAndReloadI…
test(#8538): cover a relationship MERGE ON MATCH SET under a concurre…
test(#8538): class-level hang detector for the interleaving tests
perf(#8538): re-evaluate a SET right-hand side only when the reload c…
fix(#8538): a label write on a concurrently deleted vertex is a retry…
fix(#11818): conditional UPDATE/DELETE and openCypher SET/REMOVE/DELE…