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
Investigating the time series append path and concurrent-insert behavior to implement a fix.
- Assistant
Running the concurrent insert test to reproduce the issue.
- Assistant
Trying synchronous page flush on nested append commits to fix visibility.
- Assistant
Suspending the enclosing transaction during append so bucket writes commit in a standalone transaction instead of a nested one that defers publication until the outer commit.
- Assistant
Deferring
appendLockrelease until the enclosing transaction commits, since nested appends publish only on outer commit. - Assistant
Reverting to the suspend approach (standalone append commit) without deferred lock release.
- Assistant
Implementing authoritative slot allocation under
appendLockusing a monotonic global sample index. - Assistant
Using monotonic global slot allocation under
appendLockso writes don't rely on a stale per-page sample count. Reverting suspend logic and TransactionContext rollback callbacks. - Assistant
Fixing header sample-count updates to use the reserved global index (same stale-read issue as per-page slots).
- Assistant
Combining global index allocation with suspending the enclosing transaction so bucket pages publish immediately and aren't overwritten on outer commit.
- Assistant
Moving global index initialization into the suspended standalone append transaction to avoid nested reads while the outer transaction is active.
- Assistant
Stripping time-series bucket pages from the suspended outer transaction on resume so outer commit can't overwrite with stale pages.
- Assistant
Re-adding rollback callbacks and holding the append lock until the enclosing transaction completes.
- Assistant
Evicting time-series bucket pages from the caller's transaction after append in
SaveElementStep. - Assistant
Re-applying TimeSeriesShard changes after accidental overwrite.
- Assistant
Summary
Implemented a multi-part fix for concurrent single-row time series SQL inserts losing samples. The disabled regression test
TimeSeriesConcurrentInsertTeststill does not pass when enabled (roughly 20–200 missing rows out of 240,000 under 48 threads); other time series tests pass.Root cause (addressed in design)
Concurrent per-row inserts run a append while the SQL transaction can still hold or later commit a view of mutable-bucket pages. Slot allocation via could then reuse the same row.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.