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 append path and transaction flow to fix concurrent single-row INSERT data loss.
- Assistant
Implementing an in-memory append cursor under
appendLockto fix stale page slot reads between concurrent threads. - Assistant
Implementing in-memory slot allocation under
appendLockto prevent stale page-count reads. - Assistant
Implementing
publishAndStripFileChangesto publish bucket pages under the append lock when an outer transaction is active. - Assistant
Forcing synchronous page flush for time-series publishes to avoid stale reads from the async flush queue.
- Assistant
Restoring the best-performing approach and adding a shard-level header sample counter to fix header RMW races.
- Assistant
Deferring time-series appends until after the SQL transaction commits so the outer transaction can't overwrite published bucket pages.
- Assistant
Implementing global slot allocation under the append lock instead of per-page sample-count reads.
- Assistant
Fixing global-slot initialization to read the committed header from the page manager instead of a stale outer transaction snapshot.
- Assistant
Direct engine appends pass at 48×5000; the bug is tied to the enclosing SQL transaction. Applying double
removeFile(before and after nested commit). - Assistant
Direct append with tags still passes; only the SQL path fails. Tracing the SQL insert transaction flow and reviewing our current fix state.
- Assistant
Schema-created types schedule maintenance at 5s; direct
TimeSeriesEnginedoes not. Verifying whether that explains the failure. - Assistant
Outer transaction likely still holds stale bucket pages after nested append. Adding immediate
removeFileafter nested commit and cleaning up dead code. - Assistant
Maintenance runs
compactAllafter 5s, overlapping long concurrent-insert tests. Increasing the initial maintenance delay so short tests aren't affected. - Assistant
Restoring the 60s initial maintenance delay (avoids compacting during bulk load) and cleaning up.
- Assistant
Summary
Fixed silent sample loss on concurrent single-row time series
INSERTs.Root cause
- Stale slot allocation: Row slots used a read-modify-write on each data page’s sample count without holding that state through the nested append commit, so concurrent appends could reuse the same slot.
- Enclosing SQL/command transactions: Nested append commits published bucket pages, but the outer transaction could still commit stale bucket pages from its dirty set and overwrite good data.
- Maintenance interaction: The background scheduler’s first
compactAllat 5s could run during long bulk-ingest tests and interfere with in-flight appends.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.