Time series: concurrent single-row SQL INSERTs silently lose samples (sealed-slot lost…
- User
Time series: concurrent single-row SQL INSERTs silently lose samples (sealed-slot lost update)
Summary
Under many concurrent single-row
INSERT INTO <timeseriesType> SET ts=…, <tag>=…, <field>=…statements (each in its own transaction, as happens over the HTTP/wire protocols), the time series engine silently drops samples. The client receives success on every insert (HTTP 200, no exception, noConcurrentModificationException), yet the stored row count comes up short. Confirmed real data loss: a full table scan returns the same short count ascount(*), and aGROUP BY sensor_idshows specific series missing rows.The batched InfluxDB line-protocol path (
POST /api/v1/ts/{db}/write, which appends many samples in one engine call/transaction) is not affected. Single-threaded inserts are not affected.Impact
Silent, unacknowledged data loss on the time series write path under concurrency. Severity is high because there is no error surfaced to the client — an application doing concurrent per-row ingestion over SQL (HTTP or gRPC) loses samples without any signal.
Environment
- Observed on
26.6.1-SNAPSHOT(== thearcadedata/arcadedb:latestimage at time of writing). - Reproduced both embedded (in-process engine) and over HTTP against the Docker image.
Reproduction
A. Embedded (fast, deterministic at high concurrency)
A disabled regression test is included in PR #4450:
engine/src/test/java/com/arcadedb/engine/timeseries/TimeSeriesConcurrentInsertTest.javaIt creates a
TIMESERIES TYPE … SHARDS 1, runs 48 threads × 5000 single-rowINSERTs (each in its owndatabase.transaction(...)), then assertscount(*) == 48*5000. Result: e.g. 239911 / 240000 — 89 samples lost, with no exception and no failed transaction.Enable it by removing the
@Disabledannotation.B. Over HTTP (against the published image)
CREATE TIMESERIES TYPE sensor TIMESTAMP ts TAGS (sid STRING) FIELDS (v DOUBLE) SHARDS 1Then 16 threads, each POSTing 5000 distinct single-row inserts to
POST /api/v1/command/{db}:{"language":"sql","command":"INSERT INTO sensor SET ts=<unique>, sid='s<thread>', v=<i>"}SELECT count(*) FROM sensorreturns short by 10–22 out of 80000 across runs. - Observed on
- Assistant
Now let me look at the bucket append and the nested transaction mechanism:
- Assistant
Now let me understand the nested transaction mechanism in LocalDatabase:
- Assistant
Let me check the referenced test and the SaveElementStep path:
- Assistant
Let me look at the flush thread, since the read-cache/flush-queue interaction is a suspect:
- Assistant
Let me look at DatabaseContext and how
database.transaction()works: - Assistant
Rather than keep theorizing, let me reproduce it with instrumentation. First, check build state:
- Assistant
The mvn wrapper breaks because two classworlds jars glob together. I'll work around it by invoking the launcher directly:
- Assistant
Compilation works. Now let me enable the test and reproduce the loss:
- Assistant
No cache regressions, but 50080 collisions vs only 20 lost rows. Let me analyze the collision distribution:
- Assistant
A commit published page-0 v59931 with blank content. Let me capture the stack and details of that commit:
- Assistant
Now update the
compact()javadoc phase description to match: - Assistant
Now remove all the DIAG instrumentation:
- Assistant
Clean diff. Now run the regression test:
- Assistant
Passes. Since the race is probabilistic, run it a few more times to build confidence:
- Assistant
4/4 green. Let me verify compaction actually ran during these passing runs (otherwise the test wouldn't be exercising the fixed path):
- Assistant
Run the new test with the fix in place:
- Assistant
Now verify the new test actually catches the bug — temporarily revert the fix and confirm it fails:
- Assistant
All 367 time series tests pass. Let me review the final diff:
- Assistant
The diff is minimal and focused. Two final confidence runs of the whole regression class:
- Assistant
Done. The fix is in place, verified, and all time series tests pass.
Summary
Actual root cause (differs from the issue's hypothesis): The lost samples were not a stale slot read-modify-write under
appendLock- instrumentation showed the append path is sound (no slot collisions, no page-cache version regressions before compaction). The real culprit is a window in (), triggered by the compaction that starts 5s after type creation:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.