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)
codeCREATE 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}:json - Observed on
- Assistant
Investigating the time-series concurrent-insert race and implementing a fix. Exploring the relevant code paths.
- Assistant
Running the regression test to confirm the failure, then tracing transaction behavior.
- Assistant
Implementing explicit nested transaction context for appends and stripping stale bucket pages from the enclosing transaction so outer commits can't overwrite published samples.
- Assistant
In-memory append slot cache under
appendLock— page reads can be stale across nested commits; the shard lock serializes writers but not slot visibility. - Assistant
Using a monotonic per-shard sample index under
appendLockinstead of per-page sample counts. - Assistant
Moving allocation to a monotonic index on
TimeSeriesShard(underappendLock) and appending by global index in the bucket. - Assistant
Holding
appendLockuntil the enclosing SQL transaction commits so a late outer commit can't overwrite pages published by the nested append. - Assistant
Reverting global-index allocation and testing whether deferred lock alone fixes concurrency without breaking single-threaded inserts.
- Assistant
Re-implementing global-index allocation with shard-level counter and
clearFromTransaction(no deferred lock). - Assistant
Implementing detach/adopt so enclosing transactions publish bucket pages via a nested commit without outer commit overwriting them.
- Assistant
Fixing data loss when nested publish fails after detaching pages from the outer transaction. Using nested-only appends with deferred lock release.
- Assistant
Fixing
appendSamples(tx)— it was re-reading the header for each batch, causing overlapping global indices under concurrency. - Assistant
Fixing unlock callback registration:
addAfterCommitCallbackIfAbsentused a fixed key per shard, so only the first insert in a process registered an unlock callback. - Assistant
Investigating the current implementation and transaction flow to find a reliable fix.
- Assistant
Implementing commit-time purge of time-series bucket pages published via nested transactions, and simplifying the shard/bucket logic.
- Assistant
Writing directly into the enclosing transaction while holding the append lock until commit, so the slot RMW and publish happen atomically per shard.
- Assistant
Restoring nested publish with global index allocation, commit-time purge, and deferred lock release—the approach that came closest to passing.
- Assistant
Holding the compaction read lock until the enclosing transaction finishes so compaction can't clear the mutable bucket mid-commit.
- Assistant
Fixing header updates: absolute
writeHeaderSampleCountcan regress when the transaction's header page snapshot is stale. - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.