Skip to content

feat(indexing): support per-task V10 segments and unarchived deep storage - #20900

Open
somiljain2006 wants to merge 16 commits into
apache:masterfrom
somiljain2006:v10
Open

somiljain2006 wants to merge 16 commits into
apache:masterfrom
somiljain2006:v10

Conversation

@somiljain2006

Copy link
Copy Markdown
Contributor

Fixes #20768

Description

Support per-task V10 segment generation

Currently, V10 segment generation is controlled by the global druid.indexer.task.buildV10 configuration. This makes it difficult to migrate individual ingestion workloads to V10 without changing the behavior of the entire cluster.

This PR introduces a task-context override named buildV10, allowing individual ingestion tasks to select V9 or V10 segment generation independently of the global configuration.

The task-context value takes precedence over the global setting. When the context key is absent, the existing global configuration remains the fallback.

Store V10 segments unarchived

V10 segments are now pushed as unarchived segment directories regardless of the configured deep-storage compression format.

This behavior is applied to:

  • Local storage
  • S3
  • Azure
  • Google Cloud Storage
  • HDFS

V9 segment compression behavior remains unchanged and continues to respect the configured compression format.

For S3, Azure, and Google Cloud Storage, the existing range-read support is retained for unarchived V10 segments. Existing archived V10 segments remain compatible with the previous full-download and decompression loading path.

For local storage and HDFS, the existing directory-based segment layouts are reused.

Propagate the configuration through MSQ

The buildV10 task-context key is included in MSQ worker-task context propagation, allowing SQL ingestion queries to select the segment version through query context.

The setting is resolved when the task toolbox selects the V9 or V10 index merger, ensuring consistent behavior across ingestion tasks.

Tests

Added or updated regression tests covering:

  • V9/V10 merger selection for all four combinations of global configuration and task-context override.
  • Parallel indexing generating V10 segments when requested through task context.
  • MSQ ingestion generating V10 segments when buildV10=true is supplied through query context.
  • MSQ worker-task context propagation.
  • Storage backend behavior for archived and unarchived segments.

The existing compression utility size checks are retained; V10 segments avoid the archive-compression paths instead.

Release note

Ingestion tasks can now override the cluster-wide V10 segment generation setting using the buildV10 task-context key. V10 segments are always stored unarchived in deep storage, independently of the configured compression format, while V9 compression behavior remains unchanged.


Key changed/added classes in this PR
  • TaskToolboxFactory
  • Tasks
  • IndexerControllerContext
  • LocalDataSegmentPusher
  • S3DataSegmentPusher
  • AzureDataSegmentPusher
  • GoogleDataSegmentPusher
  • HdfsDataSegmentPusher
  • TaskToolboxTest
  • IngestionTestBase
  • AbstractParallelIndexSupervisorTaskTest
  • SinglePhaseParallelIndexingTest
  • MSQTestBase
  • MSQInsertTest
  • IndexerControllerContextTest

This PR has:

  • been self-reviewed.
  • using the concurrency checklist.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods, where applicable.
  • added or updated version, license, or notice information in licenses.yaml.
  • added comments explaining the intent of non-obvious changes, where applicable.
  • added unit tests or modified existing tests to cover new code paths.
  • added integration tests.
  • been tested in a test Druid cluster.

@github-actions github-actions Bot added Area - Documentation Area - Batch Ingestion Area - Ingestion Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 labels Nov 13, 2026
Comment thread docs/ingestion/tasks.md Resolved
@FrankChen021
FrankChen021 self-requested a review November 14, 2026 10:32

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The per-task override is resolved at toolbox construction and propagated through native parallel and MSQ workers. I also checked the five core deep-storage pushers and their load/kill paths; the findings below are limited to HDFS lifecycle cleanup and metrics.

Reviewed 17 of 17 changed files.

Validation: git diff 2b71ffb375210db4905240f36d150b690bc9a85f..HEAD --check passed. No Maven or integration tests were run.

Severity Findings
P0 0
P1 0
P2 0
P3 0
2 2
Total 2

This is an automated review by Codex GPT-5.6 Luna(Max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The per-task V10 merger selection and query-context propagation were reviewed together with all five deep-storage pushers, their load/kill paths, the updated HDFS cleanup and metrics logic, and the changed tests. The two findings below remain on the current head: HDFS sibling cleanup can race across concurrent V9/V10 pushes, and local deep storage leaves the old representation after a V9/V10 replacement.

Reviewed 17 of 17 changed files; findings in 2 files.

Validation: git diff --check 2b71ffb375210db4905240f36d150b690bc9a85f..89e4aabbd5b722ff8b70d76321068bd3efb43017 passed. No Maven or integration tests were run.

Severity Findings
P0 0
P1 1
P2 1
P3 0
Total 2

This is an automated review by Codex GPT-5.6 Luna(Max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The HDFS V10 transition still needs a concurrency-safe publication boundary: the new sibling cleanup runs after rename but is not serialized with another format's publish, so a mixed V9/V10 race can remove both representations. The object-store pushers also clean stale objects only on the unzipped path; a normal V10-to-V9 replacement leaves orphaned V10 objects behind. The earlier local stale-representation finding is addressed by the current lock and atomic replacement logic.

Reviewed 20 of 20 changed files. This updated-since-review pass started with the incremental diff, then rechecked the full merge-base diff, relevant pusher/puller/killer call sites, task-context and MSQ propagation, and the changed tests.

Validation: git diff --check 2b71ffb375210db4905240f36d150b690bc9a85f0...HEAD passed. No Maven or integration tests were run.

Severity Findings
P0 0
P1 1
P2 1
P3 0
Total 2

This is an automated review by Codex GPT-5.6 Luna(Max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

public DataSegment pushToPath(File indexFilesDir, DataSegment inSegment, String storageDirSuffix) throws IOException
{
if (zip) {
final boolean shouldZip = zip && SegmentUtils.getVersionFromDir(indexFilesDir) != IndexIO.V10_VERSION;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Zip repush leaves the previous V10 objects orphaned

Finding: When ZIP is configured and a segment previously written as V10 under the non-unique prefix is repushed as V9, this new ZIP branch uploads only index.zip and never removes the old unarchived objects. Killing the resulting V9 loadSpec removes only index.zip, so the V10 objects remain indefinitely; the equivalent pushZip paths in Google Cloud Storage and Azure have the same gap.

Suggestion: Reconcile the opposite representation during the zipped transition while preserving publication safety, and add V10-to-V9 replacement and cleanup tests for S3, Google, and Azure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid observation. However, adding cleanup to the ZIP push path is not safe with the current shared-prefix storage layout.

The uncompressed push paths in S3, GCS, and Azure already perform prefix-wide stale-object cleanup. With concurrent pushes, one task could delete objects published by another task, invalidating its returned loadSpec. Adding symmetric cleanup to the ZIP path would introduce the same race in the opposite direction.

Simply removing the existing uncompressed cleanup also isn't safe because uncompressed pullers read the entire segment prefix and could ingest stale objects.

Safely solving this requires a broader storage lifecycle change, such as generation-specific prefixes or manifest-based publication, rather than cleanup inside the push methods.

For this PR, I'm keeping the changes focused on V10 compression behavior and avoiding additional cross-representation deletion that could introduce concurrency regressions.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The per-task buildV10 override is resolved at toolbox creation and propagated through native parallel and MSQ workers. I reviewed the storage changes across all five pushers, their pull and kill paths, the task-context call sites, and all 20 changed files. The current head still has a cross-representation publication race in the object-store pushers, and switching between V9 and V10 leaves stale deep-storage representations that the current loadSpec cleanup cannot reclaim.

Reviewed 20 of 20 changed files; findings in 2 files.

Validation: git diff --check 2b71ffb375210db4905240f36d150b690bc9a85f 0b9d00950d6fdb188733d3465e95b4c2ae9ee00a passed. No Maven or integration tests were run.

Severity Findings
P0 0
P1 1
P2 1
P3 0
Total 2

This is an automated review by Codex GPT-5.6 Luna(Max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

final String storageDir = this.getStorageDir(segment, false);

final String uniquePrefix = useUniquePath ? DataSegmentPusher.generateUniquePath() + "_" : "";
final CompressionUtils.Format format = compressionFormatFor(inDir);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] V9/V10 transitions leave orphaned deep-storage data

Finding: A V10 push now selects the uncompressed sibling path while V9 remains at the compressed path, but the pusher does not retire the previous representation and HdfsDataSegmentKiller deletes only the exact path in the current loadSpec. Re-pushing the same segment after a task-level buildV10 change therefore leaves a complete old copy permanently unreachable; the same transition leaves old V10 prefixes behind when S3, Google, or Azure later receives a V9 zipped push, since zip pushes do not remove the unzipped prefix.

Suggestion: Add generation-aware representation retirement or a manifest-based lifecycle that removes obsolete V9/V10 siblings only after the replacement loadSpec is durably published and safe for active readers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The finding is valid, but I investigated the existing Druid metadata lifecycle before making changes. For different SegmentIds, the existing unused-segment cleanup can eventually remove the old representation. However, for the same SegmentId, IndexerSQLMetadataStorageCoordinator.insertSegments() skips the new segment when that ID already exists. This means the newly uploaded generation may not be persisted in metadata, leaving it without an owner that the existing killer lifecycle can use.

Simply deleting the sibling path during a push would be unsafe because concurrent V9/V10 pushes could delete each other's active data. A complete fix for this case appears to require generation ownership tracking and coordination with metadata publication.

I've kept the implementation focused on isolated generation paths and exact-generation deletion rather than introducing unsafe sibling cleanup. The same ' SegmentId` orphan-cleanup case remains a limitation that needs a separate lifecycle-level solution.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The per-task buildV10 override is resolved at toolbox construction and propagated through native parallel and MSQ workers. The new object-store generation paths remove the earlier cross-representation publication race, and local deep storage now serializes representation replacement; the remaining issues are stale representation ownership on same-ID repushes in cloud backends and HDFS.

Reviewed all 36 changed files, including the full and incremental diffs, all storage pusher/puller/killer paths, task-context and MSQ propagation, publication call sites, metadata insertion behavior, and the changed lifecycle tests. The open HDFS lifecycle thread was rechecked against the current head.

Validation: git diff --check 2b71ffb375210db4905240f36d150b690bc9a85f 9fbc243738bd606d8b969605138aaae17ea76242 passed. No Maven or integration tests were run.

Severity Findings
P0 0
P1 0
P2 2
P3 0
Total 2

This is an automated review by Codex GPT-5.6 Luna(Max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there're some unneccessary changes in this PR.

and documents should also need to be updated. for compression format configuration, now we should say they don't take effect if the v10 format is used

and the new buildV10 task context parameter should also be documented

if (files == null) {
throw new IOE("Cannot list directory [%s]", indexFilesDir);
}
boolean uploadAttempted = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to make changes to this method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is intended to handle partial uploads in the uncompressed path. Unlike the ZIP path, pushNoZip() uploads multiple blobs individually. If an upload fails after some files have already been uploaded, those blobs would remain under the unique generation path even though no valid DataSegment/loadSpec is returned.

The uploadAttempted flag ensures we clean up that incomplete generation on failure, while avoiding an unnecessary cleanup request if validation fails before any upload starts. Since each push has an isolated generation path, this cleanup only affects the generation created by the current push.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The per-task buildV10 override, native parallel and MSQ propagation, V9/V10 storage selection, all five storage backends, and the relevant load, kill, move, and publication call sites were reviewed across the full current head. I started with the three reply threads and the incremental diff, then rechecked the complete merge-base diff and surrounding code; the two prior storage-lifecycle findings remain unresolved, and the newly unarchived V10 path exposes the S3 mover regression described in the findings.

Reviewed 44 of 44 changed files; findings in 3 files.

Validation: git diff --check 2b71ffb375210db4905240f36d150b690bc9a85f c8df6be6ed9d442f8da3e51b0246b60f996e4bca passed. No Maven, unit, integration, or cluster tests were run.

Severity Findings
P0 0
P1 1
P2 2
P3 0
Total 3

This is an automated review by Codex GPT-5.6 Luna(Max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

@clintropolis

Copy link
Copy Markdown
Member

This PR got a lot bigger than i last looked at it.. why? I see a bunch of bot comments talking about V9/V10 transitions of like the same SegmentId.. which I'm not sure how that should happen in practice? Is that why all of this complexity was added? If so, I think that it is certainly not worth it for something that I'm not sure how can happen in the first place.

If this stuff really is a problem, I suggest decoupling what the PR description says this is doing (adding context flag, making v10 ignore compression and even those could be 2 PRs) from the "bug" fixes (if they are real, but I still am unsure how in normal operation we could run into the things the bot is concerned about). This would make everything a lot easier to review since this PR is now almost 3k lines and has a lot going on.

Also, I still think this PR should remove any mention of V10 segments in any documentation added, since V10 itself is not documented anywhere. I feel more strongly about this than my prior comment since there are a lot more mentions now, and this is likely to finish before I finish the docs PR.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Reviewed the updated-since-previous-review diff from c8df6be to f1d0a04 and the complete current PR diff from merge base ca3a950. I rechecked the prior findings against the current code; the earlier S3 uncompressed-move finding is fixed by paginated listing and moving the actual object keys. The current findings cover S3 archive/restore validation, cloud shuffle cleanup, publication cleanup failure handling, and HDFS representation retirement.

Reviewed all 51 changed files, including storage implementations, callers, cleanup and publication lifecycle, context propagation, documentation, and tests.

Validation: git diff --check ca3a950044d7ecfa7a74867e1ce114667c45d2b8 HEAD passed. No Maven or test suite was run; this was a static review.

Severity Findings
P0 0
P1 0
P2 0
P3 0
1 1
2 3
Total 4

This is an automated review by Codex GPT-5.6 Luna(Max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

if (targetS3Bucket == null || targetS3Bucket.isEmpty()) {
throw new SegmentLoadingException("Target S3 bucket is not specified");
}
if (targetS3BaseKey == null || targetS3BaseKey.isEmpty()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 Allow root-prefix archive and restore targets

Finding: This new unconditional check rejects an empty target baseKey, but both S3DataSegmentPusherConfig.baseKey and S3DataSegmentArchiverConfig.archiveBaseKey default to "", and S3Utils.constructSegmentBasePath intentionally maps an empty base key to a valid bucket-root segment path. ArchiveTask and RestoreTask targeting a bucket root will now fail before moving any object.

Suggestion: Allow an empty base key and validate the computed target path (or only require the target bucket), with coverage for archive and restore to a bucket root.

final String s3Path = S3Utils.constructSegmentPath(config.getBaseKey(), storageDirSuffix);
final int binaryVersion = SegmentUtils.getVersionFromDir(indexFilesDir);
final boolean shouldZip = zip && IndexIO.isExternalCompressionSupported(binaryVersion);
final String generationPath = S3Utils.constructGenerationBasePath(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 Keep deep-storage shuffle cleanup under its documented prefix

Finding: This generation prefix is added to every pushToPath call, including DeepStorageIntermediaryDataManager.addSegment's shuffle-data//... suffix. ParallelIndexSupervisorTask cleanup still calls killRecursively on shuffle-data/, but cloud killers inherit the no-op default and the documented cloud lifecycle prefix is also shuffle-data; Azure and Google use the same generation wrapper. Cloud deep-storage shuffle objects therefore accumulate and lifecycle rules miss them.

Suggestion: Keep shuffle pushToPath objects under the requested shuffle-data prefix, or make cleanup and lifecycle configuration target the generated prefix consistently across S3, Azure, and Google.

try {
authoritativeSegments = publishedSegmentRetriever.findPublishedSegments(notAdoptedSegmentIds);
}
catch (IOException e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 Keep metadata lookup failures best-effort

Finding: This helper runs after a successful metadata publication and is intended to retain uploads when authoritative lookup fails, but it catches only IOException. LocalTaskActionClient wraps action failures in RuntimeException, and metadata queries can throw unchecked DruidException, so an unchecked lookup error escapes and can retry or fail an already-committed publish instead of retaining the generation.

Suggestion: Catch the unchecked lookup failures as well, log them, and retain the uploaded generations whenever authoritative metadata cannot be read.

final String storageDir = this.getStorageDir(segment, false);

final String uniquePrefix = useUniquePath ? DataSegmentPusher.generateUniquePath() + "_" : "";
final CompressionUtils.Format format = compressionFormatFor(inDir);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 Schedule cleanup of superseded HDFS representations

Finding: Selecting NONE for V10 makes same-ID V9-to-V10 and V10-to-V9 transitions possible, but copyFilesWithChecks treats an existing target as success and the new tests explicitly retain the old sibling. HdfsDataSegmentKiller.kill deletes only the path in the current loadSpec, so after the second representation is published the first path is unreachable and never deleted; repeated format transitions leak full segment copies.

Suggestion: Keep the old representation while readers may need it, but add retryable or deferred cleanup tied to durable publication (or otherwise record both representations) instead of retaining it indefinitely.

@FrankChen021

Copy link
Copy Markdown
Member

This PR got a lot bigger than i last looked at it.. why? I see a bunch of bot comments talking about V9/V10 transitions of like the same SegmentId.. which I'm not sure how that should happen in practice? Is that why all of this complexity was added? If so, I think that it is certainly not worth it for something that I'm not sure how can happen in the first place.

If this stuff really is a problem, I suggest decoupling what the PR description says this is doing (adding context flag, making v10 ignore compression and even those could be 2 PRs) from the "bug" fixes (if they are real, but I still am unsure how in normal operation we could run into the things the bot is concerned about). This would make everything a lot easier to review since this PR is now almost 3k lines and has a lot going on.

Also, I still think this PR should remove any mention of V10 segments in any documentation added, since V10 itself is not documented anywhere. I feel more strongly about this than my prior comment since there are a lot more mentions now, and this is likely to finish before I finish the docs PR.

Correct, it's getting bigger and bigger and hard to review. And it also introduces some unexpected changes.
It's better to split the changes

  • a PR for context key
  • bypass the compression for v10 format for different deep storages one by one

@clintropolis

Copy link
Copy Markdown
Member

bypass the compression for v10 format for different deep storages one by one

Actually, i do think it makes more sense to flip all of these across all implementations at once so that they remain behaviorally consistent with each other, rather I was thinking that if there are any additional bugs those should be fixed separately from the change that makes them ignore zip/compressionFormat, since such bugs should be unrelated to that change directly (though i'm still not sure how at least the v9/v10 to same path are actually bugs, they seem like over-engineering for a problem that i'm not sure is likely to happen)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: push V10 segments to deep storage without an archive, and add a per-task buildV10 context key

4 participants