OpenSearch icon indicating copy to clipboard operation
OpenSearch copied to clipboard

[Feature Request] Support index rollover with pull-based ingestion

Open joluc opened this issue 5 months ago • 3 comments

Is your feature request related to a problem? Please describe

Pull-based ingestion is bound to a single concrete index, each index runs its own poller, with no notion of an ingestion lifecycle that spans an alias or a data stream. The docs explicitly list this under Limitations:

Index rollover is not supported.

The practical effect is that pull-based ingestion is restricted to a single static index for the entire life of the data. That makes it unworkable for high-volume log/audit pipelines, where rollover-based retention is a hard requirement:

  • _delete_by_query is rejected on pull-based indices (IngestionEngine.java#L274-L276), so per-document time-based retention is not available.
  • Resharding requires a _split / _clone migration that breaks consumer continuity.
  • Without rollover, the only retention strategy is "let the index grow until you manually cut over to a new one and delete the old," which doesn't compose with ISM and doesn't scale to high ingest rates.

Implementing rollover support would unlock pull-based ingestion for the dominant Kafka-to-OpenSearch use case (logs, audit with rollover-based retention) and for data streams more generally, data streams use rollover internally, so rollover support is also the prerequisite for making pull-based ingestion work with data_stream: {} templates.

Describe the solution you'd like

Add an ingestion-aware rollover path. When MetadataRolloverService rolls over an alias or a data stream whose write index uses index.ingestion_source, the operation should atomically:

  1. Pause the old write index's poller.
  2. Persist its per-partition pointers (current source offsets per shard) to cluster state, scoped to the alias/data-stream rather than the concrete index.
  3. Create the new write index initialized from those persisted pointers (instead of the template's pointer.init.reset policy, which would otherwise re-read or skip data depending on the policy).
  4. Resume the new write index's poller, only.

User-facing result: rollover behaves the same way it does for push-based indices. Old indices remain queryable but stop polling. The Kafka offset is logically owned by the alias / data stream, not the concrete index. Existing pull-based settings keep working unchanged for static-index users.

A possible implementation shape:

  • An alias-or-data-stream-scoped ingestion-state object (perhaps an extension of IndexAbstraction.DataStream or a sibling in cluster state).
  • A handoff path in MetadataRolloverService that performs the pause / persist / initialize / resume sequence as part of (or tightly coupled to) the rollover transaction.
  • A reset mode in IngestionSource / KafkaPartitionConsumer (and equivalents for Kinesis) that initializes from explicit per-partition offsets supplied by cluster state.

The pause API (POST /<idx>/ingestion/_pause) and offset state (batch_start_pointer exposed via GET /<idx>/ingestion/_state) already provide the runtime primitives for the pause/inspect side. Pause state is already persisted in IndexMetadata.INGESTION_STATUS_KEY, so it survives cluster restarts and rollovers.

Related component

Indexing

Describe alternatives you've considered

These are workarounds while the feature does not exist,

  1. Validation rejection (filed separately as a bug): refuse the unsupported configuration outright. Safer than silent duplication, but does not enable rollover.

  2. Reactive pause via the _pause API called from an external controller after rollover. Verified, it works and persists across rollovers, but the rollover boundary is non-atomic, between rollover and the pause call, both the old and new write indices poll Kafka concurrently. Reduces duplication but does not eliminate it.

  3. An OpenSearch plugin that hooks rollover and pauses the previous write index as part of the rollover transaction. Closer to atomic, but the plugin still cannot atomically transfer offsets without the API surface this feature would add. Without it, the new index either re-reads from pointer.init.reset (causing overlap) or skips ahead (causing a gap).

Additional context

The pull-based ingestion META roadmap (#16930) does not currently list rollover or data streams in scope.

joluc avatar Jun 17 '26 09:06 joluc

Thanks @joluc for the detailed issue. I've been working on this and wanted to share the design here before opening the PR, since it touches rollover, the pause/resume APIs and the poller. @varunbharadwaj I'd appreciate your thoughts.

The rollover handoff works like this:

  1. When the write index of an alias or data stream uses ingestion_source, rollover first pauses it and waits until every primary has stopped polling (via get ingestion state), bounded by the rollover's cluster manager timeout. dry_run and unmet conditions never pause.
  2. Each primary reports the last pointer it read. The new write index is created in the same cluster state update as the rollover, with those positions in its metadata, and each new shard starts strictly after its counterpart's last pointer. With auto-generated ids any overlap at the boundary is a real duplicate, so the start is exclusive. The new index's pointer.init.reset is ignored when a handoff position exists, and its committed batch start takes over after the first commit.
  3. The old index is marked as handed off. It finishes processing what it already polled, so nothing is skipped, then closes its consumer. It stays paused across restarts and snapshot restores, and rejects resume.
  4. If anything fails after the pause, the old index is resumed, unless the user had already paused it. A retried rollover (for example from ISM) adopts the existing pause.
  5. Rejected before the pause: a target with a different source type, topic or shard count, all_active indices, a source_partition_strategy other than simple (the handoff stores one position per shard), and clusters with nodes before 3.10.0 (the new get-state fields are version gated).
  6. Pause, resume and get ingestion state accept data stream names, since data streams are the main use case.

The logic stays in the rollover action, IngestionEngine and DefaultStreamPoller. IndexShard only gets a small hook next to the existing ingestion state update. The existing at-least-once replay from batchStartPointer on restart and replica promotion is unchanged.

Testing: unit tests for each part, an ingestion-fs test, and a KafkaRolloverIT suite on KafkaIngestionBaseIT (data stream and alias handoff under load with exact counts, consecutive rollovers, rollback on an incompatible target, resume rejection, full cluster restart). I also ran it in docker with Kafka and three nodes, rolling a data stream over three times while producing 20k messages without ids: exact count with 0 and 1 replicas, and every old shard closed its consumer after the handoff.

While testing I found that restoring an ingestion index as a searchable snapshot fails on main, which matters for moving old backing indices to a warm tier after rollover. That fix is independent of this issue, so I opened it separately: #23368.

Things I'd do in follow-ups: stopping the idle poller thread on handed-off shards (the consumer is already closed), and a per-partition handoff once the modulo strategy is wired into the consumers.

Related PRs: #22256 also targets this issue but hasn't been updated since June, and it starts the new index from the inclusive batch start pointer, which re-reads messages at the boundary. #22780 (@chishui) rejects rollover and data streams for ingestion indices. This would replace those two checks; the other validations there still apply.

Does this direction look reasonable? I can open the PR once we agree on it.

notque avatar Oct 17 '26 18:10 notque

Thanks @joluc for creating the issue and @notque for continuing the discussion.

This is a summary of how I understood the solution -

  1. We pause the ingestion on index A.
  2. We wait for the already consumed messages to be processed (wait for drain).
  3. We commit the changes on indexA, so each primary shard's batchStartPointer is persisted.
  4. The new index after rollover (index B) will start consuming from the batchStartPointer (inclusive, or can be exclusive when previous primary is completely drained).
  5. The old index is marked as 'handed off' as you described it.

This approach seems fine to me, and should mostly work. I'm trying to think of the following scenarios:

  1. Replica promotion: In the case where index A has 1 primary shard and 2 replica shards and the primary shard goes down, a replica shard may be promoted to be the new primary. If we pause the ingestion and the replica is yet to catch up (doesn't have all updates from primary yet), indexA may lose some data if indexB starts from the initial primary's batchStartPointer. Today, this is not a problem as the new primary on index A can resume ingestion and catch up when there is no pause due to rollover. We may have to consider this case for index rollover.
  2. All_active ingestion mode: The all-active ingestion mode is a unique mode to pull-based ingestion. In this mode, each shard (primary and replica) independently ingest from the stream and index the documents. This means primary and replica shards may be processing different messages with eventual consistency guarantees. Similar to the replica promotion case above, a replica promotion here may result in losing some messages if the ingestion is paused and we rollover to index B.

I think in both scenarios, we will have to ensure primary and replica shards are in sync to avoid this problem.

One possible modification to above solution could be to use the hand-off point (batchStartPointer) as an ingestion upper-bound on index A and lower bound (start point) on index B.

  1. Index A shards will consume till batchStartPointer and then stop (will not consume beyond)
  2. Index B shards will begin consuming at batchStartPointer.
  3. We do not explicitly pause ingestion in this case and let the shards decide when to stop consuming. We could later think of optimizations and stop the consumer threads after a shard has consumed till the batchStartPointer to avoid having unnecessary polls.

I think this will solve the replica promotion problem, as the index A shards will still consume till the defined upper bound before pausing / stopping ingestion, and can be eventually consistent.

Let me know your thoughts.

Also tagging few others who are familiar with pull-based ingestion for any other ideas / comments - @msfroh @philiplhchan @andrross

varunbharadwaj avatar Oct 20 '26 05:10 varunbharadwaj

One possible modification to above solution could be to use the hand-off point (batchStartPointer) as an ingestion upper-bound on index A and lower bound (start point) on index B.

I personally like this idea and (IMO), it's one of the strengths of pull-based ingestion. By setting some cut-off point in the (near) future and persisting it in the cluster state atomically, we can get a deterministic rollover regardless of any shard failover.

msfroh avatar Oct 22 '26 18:10 msfroh