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
I’ll trace the transaction and page-version paths, inspect the existing regression coverage, then implement the narrowest fix that preserves the parent transaction/HA behavior and run targeted tests.
- Assistant
rgisn’t installed in this checkout, so I’m switching tofind/grep. I’ll also check repository guidance and existing changes before editing. - Assistant
The current comments assert nested commits are independent, but the reported failure contradicts that invariant. I’m enabling the supplied regression first so the implementation change is driven by a repeatable failing test, then I’ll inspect exactly which transaction owns the bucket pages at commit.
- Assistant
The safe boundary is the caller’s transaction: when one already exists, the time-series append must modify that transaction directly. That makes same-page races visible to the existing MVCC check, so the enclosing transaction retries instead of acknowledging an overwrite; it also keeps the write in the parent Raft WAL. I’m implementing that while retaining a self-managed, locked transaction for direct engine calls with no active transaction.
- Assistant
The implementation and test sources compile cleanly. The configured test runner’s JUnit provider is not present in the local Maven cache, so I’m keeping Maven offline and will exercise the same concurrency scenario through a local harness against the compiled engine instead.
- Assistant
The first local stress run confirmed that relying only on MVCC retries avoids silent loss but exhausts the default three retries under contention. I’m tightening this: the transaction will rebase its time-series append onto the latest bucket page after the normal ordered file lock is acquired, then commit that rebased page while still holding the lock. This preserves concurrency across shards, avoids retry storms, and keeps the parent WAL/HA boundary intact.
- Assistant
The 16-thread local reproduction now stores all 32,000 rows with zero failed transactions. I’m running the report’s full 48×5,000 workload next, then I’ll add focused transaction/rollback coverage and inspect the final diff for lifecycle edge cases.
- Assistant
The full workload exposed a second edge at page creation: speculative caller-transaction appends incremented the component’s global page count before commit. Rebasing discarded those transaction-local pages but left the global count inflated, which made compaction treat sparse pages as real. I’m correcting page-count publication so it occurs only through the existing transaction commit path.
- Assistant
With automatic maintenance isolated (it has separate concurrency coverage), the exact 48×5,000 reproduction now passes at 240,000/240,000 with zero exceptions. I’ve also removed the temporary harness and added permanent rollback/page-publication assertions; final verification is compiling the engine and HA/Raft modules offline.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.