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 how nested transactions work in
LocalDatabaseandTransactionContextto understand why the nested commit's writes aren't visible. - Assistant
Wrapper works. Now enable the regression test and run it to reproduce:
- Assistant
Now let me check other callers of the compaction read/clear methods to scope the fix:
- Assistant
Compile the changes:
- Assistant
While the baseline runs, let me add a deterministic regression test for the Phase-4b hole. I'll check the existing shard test style first:
- Assistant
I need to wait for the baseline to finish before touching the tree again (the earlier race taught that lesson). Let me monitor:
- Assistant
The baseline test is running in the background (48 threads × 5000 single-row INSERTs against the unfixed code). While it runs, here's a summary of what I've found and done so far:
Root cause identified: The loss is not in the append path itself. In embedded mode the per-shard nested-tx commit publishes pages synchronously under
appendLock, so appends can't lose against each other. The real hole is inTimeSeriesShard.compactInternal():- The maintenance scheduler fires
compactAll()5 seconds afterCREATE TIMESERIES TYPE(and every 60s after), so it always runs concurrently with a sustained insert load. - Phase 4a snapshots pages
lastFullPage+1..phase4aPageCountunder the write lock, including the last page (say it had K rows), then releases the lock.
- The maintenance scheduler fires
- Assistant
Now add the deterministic regression test to
TimeSeriesShardTest: - Assistant
Passes with the fix. Now verify the test actually catches the bug - temporarily revert just the Phase 4c read logic:
- Assistant
Definitive confirmation: with the old logic, exactly the 5 Phase-4b appends are lost (10 of 15). Restore the fix:
- Assistant
Now run the full-scale concurrent insert regression test with the fix:
- Assistant
The full-scale test is running. While waiting, let me double-check the final diff of the fix:
- Assistant
One stale comment above Phase 4c to update:
- Assistant
Waiting for the full-scale test to complete before running the broader suite.
- Assistant
Full-scale test passes: all 240,000 samples present. Now run the entire time-series test package to check for regressions:
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.