---
title: "Backfilling Historical Log Data While Live Ingestion Continues"
description: "A reproducible Manticore lab for a historical data backfill that overlaps live log ingestion, with checkpoint recovery, idempotent writes keyed by stable IDs, and exact source-to-index reconciliation."
date: 2026-12-02
author: "Dmitrii Kuzmenkov"
image: https://manticoresearch.com/images/blog/log-backfill-live-ingestion.png
lang: en
url: https://manticoresearch.com/blog/log-backfill-live-ingestion/
translations:
  ru: https://manticoresearch.com/ru/blog/log-backfill-live-ingestion/
  zh: https://manticoresearch.com/zh/blog/log-backfill-live-ingestion/
---

# Backfilling Historical Log Data While Live Ingestion Continues

A reproducible Manticore lab for a historical data backfill that overlaps live log ingestion, with checkpoint recovery, idempotent writes keyed by stable IDs, and exact source-to-index reconciliation.

Yesterday's logs are missing from search, but today's events keep arriving. Pausing log ingestion would make the gap larger. The awkward part starts when an archive importer stops halfway through, or both workers reach the same event.

After recovery, each source event should have one document with the expected contents. This walkthrough uses Manticore Search as the destination and a replayable, immutable log as the source. It deliberately interrupts the backfill, resumes from an older checkpoint, and checks every resulting ID and the stored attributes. A separate producer appends new events while the archive worker and live consumer write to the same table.

In the reference run on Manticore 29.9.0, all 600 source events ended as 600 documents, with no missing, extra, mismatched or duplicate rows. That held after an interrupted archive worker, a deleted document, a server restart and a rewound live checkpoint.

This is a correctness exercise with 600 synthetic events, deliberately paced to make overlap observable. It is not a bulk-loading benchmark or a production capacity estimate.

## A Source Contract Before an Importer

The fixture's source is an append-only log with one partition and contiguous integer offsets starting at 1. Offset 400 means every event through 400 is committed and available; a larger observed offset alone would not establish that. A real source with gaps needs its own successor and committed-position rules instead of this lab’s `offset + 1` arithmetic. Once an offset exists, its event ID and payload never change. The archive and live stream expose the same canonical event at the same offset. The source stays available for replay throughout recovery.

That contract makes duplicate delivery manageable. The document ID is `100000 + source_offset`, so both workers assign the same ID to the same event. In a real multi-partition source, use a persisted, collision-free mapping that includes the source identity and partition; offsets alone are not globally unique. Document IDs must be non-zero and fit in an unsigned 64-bit integer ([manual](https://manual.manticoresearch.com/Creating_a_table/Data_types#Document-ID)). Bind the mapping to the source lineage so a recreated source cannot reuse old IDs for different events. Replays must use the same transformation and contents. Do not assign fresh IDs on retries.

The lab uses [REPLACE](https://manual.manticoresearch.com/Data_creation_and_modification/Updating_documents/REPLACE) to write the complete document under that stable ID. Repeating an identical event leaves one document with the same contents. This is at-least-once delivery with an idempotent final state. It is not an atomic transaction between a source checkpoint and Manticore.

Immutability is essential: an old archive record could otherwise replace a newer version. This example does not implement version ordering, CDC, updates, or source deletes. The later deletion test deliberately damages the destination to test reconciliation; it does not implement delete propagation.

## An Overlapping Boundary

Capture the source's committed high-water mark before exporting the archive, using the same source lineage for both paths. Here it is offset **400**, inclusive. The archive contains offsets **1–400**. Start the live consumer at **381**, inclusive, retaining a deliberate 20-event overlap. Meanwhile, the producer appends offsets **401–600**.

![Archive offsets 1–400 overlap live consumption at 381–400; new events continue through offset 600. Both workers write stable IDs into one table.](./log-backfill-live-ingestion/handoff.png)

The boundary is a source position, not an event timestamp. Every seventeenth fixture event has an old timestamp, including events appended after offset 400. Routing by event time would confuse late events with historical data. The live consumer reads source offsets regardless of those timestamps.

For an actual archive export, establish that its manifest covers every offset through the recorded high-water mark before accepting it. Persist the source identity, partition, inclusive boundary, archive checksum, and transformation version with the job. Retain the stream from the overlap position before starting a long export. A timestamped file without a replayable source position is insufficient for this protocol.

The fixture’s `boundary.json` records the source identity, partition, transformation version, high-water mark, live start, and archive SHA-256. Each archive worker checks the manifest, checksum, contiguous offset range, and canonical fixture payload before replay. Checkpoints carry the same lineage and boundary fields; malformed or incompatible checkpoints stop the run. This validates one fixed fixture, rather than making the harness a connector for arbitrary archives.

## Running the Lab

You need Docker with Compose, Python 3.10 or later, a filesystem that supports directory `fsync` (tested on Linux), and an available loopback port **18809**. No Python packages are required. The first Docker run may download the image. The tested image is Manticore **29.9.0**, pinned to this digest:

```text
manticoresearch/manticore@sha256:461b419739a2bbbffb4be0b32db26c41d7b435bf7fd1fce95b414ca5ccbb3775
```

Download the [runnable lab](https://manticoresearch.com/downloads/article09/backfill-lab.tar.gz) and [checksum manifest](https://manticoresearch.com/downloads/article09/SHA256SUMS). The separate [reference evidence](https://manticoresearch.com/downloads/article09/reference-evidence.tar.gz) contains the captured SQL requests and responses, source fixture, checkpoints, and reconciliation results from the final fresh run.

```bash
sha256sum -c SHA256SUMS --ignore-missing
tar -xzf backfill-lab.tar.gz
cd backfill-lab
./run.sh
cat evidence/summary.json
```

Run it in a fresh directory. The script creates only the `manticore-article09` container and its Compose network, limits the container to one CPU and 1 GiB RAM, and publishes HTTP only on `127.0.0.1:18809`. It refuses to run if that container name already exists. On exit it removes its container and network; generated source files, checkpoints, evidence, and the bind-mounted `data/` directory remain for inspection. A new extraction is required for a clean rerun.

The `data/` directory is written by the container user, so removing an old extraction may need `sudo`. The harness gives each HTTP call a 15-second timeout. After the archive process finishes, it waits at most 60 seconds for the producer and then 60 seconds for the live consumer. Both call `fsync` after every event, so on a slow disk they can run past that limit. On a busy shared host we saw a `TimeoutError` in 2 of 10 runs: once while waiting for the producer, and once, with added disk writes, while waiting for the live consumer. The other eight runs passed with the same archive. If you see the error, rerun in a new extraction when the disk is less busy.

The harness creates a [real-time table](https://manual.manticoresearch.com/Creating_a_table/Local_tables/Real-time_table) with ordinary SQL writes. It does not enable `bulk_import` or rely on writes being allowed through a bulk-import lock.

```sql
CREATE TABLE logs (
  src_offset bigint,
  event_ts timestamp,
  service string,
  message string,
  body text
);

REPLACE INTO logs
  (id, src_offset, event_ts, service, message, body)
VALUES
  (100381, 381, 1700000381, 'api', 'log event 381', 'log event 381');
```

The `message` attribute lets reconciliation compare the original message, while `body` provides the full-text field. The harness submits SQL through [SQL over HTTP](https://manual.manticoresearch.com/Connecting_to_the_server/HTTP#SQL-over-HTTP), requires one result with empty SQL error and warning fields, and records the response before acknowledging a write. It rejects rows that differ from the generated fixture before constructing SQL. External messages, services, IDs, and timestamps are not accepted inputs; adapting this code requires proper SQL escaping and validation.

## Checkpointing After Acknowledgment

The archive checkpoint records the last saved contiguous source offset acknowledged by the destination. Its next read starts at that offset plus one. It advances every 100 archive events; the live consumer advances its own checkpoint after each acknowledged event.

The local checkpoint writer flushes and synchronizes a temporary file, atomically replaces the checkpoint, and synchronizes the parent directory. Readers see the old or new checkpoint rather than a partially written file. A directory-sync failure still stops the worker: atomic visibility does not by itself prove persistence after power loss. Each consumer has one checkpoint writer; this is not a multi-writer coordination scheme. It does not make the checkpoint atomic with the database write.

The safe order is:

1. Read the next source event.
2. Write the complete document with its stable ID.
3. Check the SQL response for success.
4. Persist the acknowledged source offset.

Advancing the checkpoint before step 2 risks skipping an unwritten event. A crash between steps 3 and 4 instead causes replay, which this immutable-ID contract can tolerate. An ambiguous network response should likewise leave the checkpoint unchanged and trigger replay. The harness tests the acknowledged-write crash window; it does not inject a dropped network response.

The archive worker runs in a separate process. Immediately after receiving the acknowledgment for offset **150**, it exits with code **23**, without saving another checkpoint. The persisted checkpoint is still **100**. The parent requires that exit code and checkpoint value, then launches another archive worker, which resumes at **101**. Offsets **101–150** are written again.

During this interruption, the live consumer continues independently. It neither waits for the archive checkpoint nor adopts it as its own cursor. The producer is also independent of both consumers.

## Evidence of Concurrent Activity

The download records monotonic timestamps for producer appends, worker acknowledgments, and the start and end of each write request. The summary requires a shared interval containing producer appends, archive acknowledgments, and live acknowledgments. Before repair begins, it also requires at least one archive/live HTTP pair with overlapping request-to-response intervals inside that shared activity interval, with the live offset above 400. That live write must therefore be an event appended by the producer, rather than an older event from the overlap range. The timestamps bracket the HTTP calls themselves, excluding later evidence logging.

The captured offsets must also show archive delivery of 1–150 followed by 101–400, and live delivery of 381–600. Together these checks establish concurrent client activity during the initial backfill. They do not establish that Manticore executes both requests in parallel internally. The counts and interval are reported in `evidence/summary.json`; scheduling-dependent overlap measurements can vary between runs.

## Data Reconciliation Before Handoff

A finished archive checkpoint does not prove a complete index. The lab reconciles against the complete source prefix through offset **600**, after the finite producer and both consumers finish. This final producer stop gives the test a fixed acceptance boundary; it is not a test of an indefinitely running stream.

With all writers stopped, the checker uses keyset pagination: it reads indexed rows in ascending-ID pages of 100, using the last ID as the next page boundary. It compares exact ID sets and the `src_offset`, `event_ts`, `service`, and `message` attributes for every event. It separately reports missing IDs, unexpected IDs, payload mismatches, and duplicate rows. It does not merely compare row counts or sums. The full-text `body` field is written from the same message but is not independently validated by this checker.

```sql
SELECT id, src_offset, event_ts, service, message
FROM logs
WHERE id > 0
ORDER BY id ASC
LIMIT 100;
```

The first handoff check requires:

```json
{
  "source": 600,
  "indexed": 600,
  "missing": [],
  "extra": [],
  "mismatched": [],
  "duplicate_rows": 0
}
```

The acceptance condition has two parts: the archive covers its immutable boundary through 400, and the live consumer has covered the source through 600. The shared region 381–400 is intentionally written by both. The interrupted archive also replays 50 acknowledged events. All those deliveries must still reconcile to 600 distinct source IDs.

For a continuing service, choose another committed source high-water mark, wait for contiguous sink acknowledgment through it, and bound both sides of reconciliation to that prefix. Keyset pagination alone does not create a snapshot. The bounded rows must remain unchanged throughout the scan, or the checker needs a consistent snapshot. Concurrent repair, deletion, or source mutation could invalidate the comparison. This finite harness supplies neither a snapshot mechanism nor a continuing-prefix checker. Do not remove source replay data merely because the importer reached the end of a file.

## Deliberate Damage and Recovery

The harness then tests why checkpoints and data reconciliation are separate concerns:

| Test | Required Observation | Recovery |
| --- | --- | --- |
| Archive process exits after acknowledgment 150 | Checkpoint remains 100 | Resume at 101; identical IDs absorb replay |
| Destination document `100250` is deliberately deleted | Exact missing-ID list is `[100250]` | Explicitly rewind the archive checkpoint to 200 and replay 201–400 |
| Manticore receives a normal Docker restart | All 600 source IDs and checked attributes still match | Reconnect and reconcile |
| Live checkpoint is deliberately rewound to 580 after restart | Events 581–600 are delivered again | Replay and require the same exact final state |

The gap test keeps the archive's completed checkpoint intact until reconciliation discovers the missing document. A checkpoint alone would miss this damage. Repair is an explicit rewind from retained source data, followed by another full comparison.

The restart test uses `docker restart --time 10` after ingestion has finished, with the same data directory. It verifies a normal server restart and subsequent replay. It does not test writes during a server outage, disk loss, power failure, or replication failover. Acknowledgment durability depends on the database's [binary-log settings](https://manual.manticoresearch.com/Server_settings/Searchd#binlog_flush) and storage. With the default `binlog_flush = 2`, the manual says committed transactions survive a server crash, while an OS or hardware crash can lose up to one second of them. This lab does not establish power-loss durability.

The archived lab also does not kill the server. In a separate one-off check on the same pinned image with default settings, we sent 50 `REPLACE` statements, waited for every response, ran `docker kill` (SIGKILL) and `docker start`, then counted rows: all 50 documents were present. That covers a killed Manticore process on a host that stays up. It says nothing about an OS crash or power loss, and its script is not part of the download.

After repair, after restart, and after the final live replay, reconciliation must again produce the same clean 600-row result. The reference evidence includes each stage, including the intentionally failing gap check.

## Applying the Protocol to Your Source

Keep a replayable source, freeze an explicit archive boundary, use idempotent writes with identical IDs and contents in both paths, persist only acknowledged contiguous offsets, and reconcile a defined source prefix before declaring the backfill complete.

For several partitions, keep a boundary and contiguous checkpoint per partition. If writes are processed concurrently within a partition, the largest acknowledged offset is not necessarily the largest contiguous acknowledged offset. A failed lower offset must prevent the checkpoint from jumping past it. This lab uses sequential writes within each consumer and does not implement that acknowledgment tracker.

The [Fluent Bit integration](/blog/integration-of-manticore-with-fluentbit/) covers getting collected logs into Manticore, and the [OpenSearch Dashboards integration](/blog/manticore-opensearch-dashboards-integration/) covers exploring them. For this backfill, handoff requires the archive boundary at 400, the live checkpoint at 600, and a clean comparison of the stopped source and destination. Retain replay data until those checks pass and the recovery policy allows its removal.
