-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade pending segments when a concurrent replace happens #15097
Closed
+678
−208
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f93fbd3
Add CommitRealtimeSegmentsAndMetadataAction
kfaraz ec9df24
Merge branch 'master' of github.com:apache/druid into upgrade_pending…
kfaraz 1182c74
Add IndexerMetadataStorageCoordinator.commitAppendSegmentsAndMetadata
kfaraz 9ddfd5e
Remove extra task action
kfaraz e19b2ca
Upgrade pending segments
kfaraz 260d7bd
Use correct jdbi query object
kfaraz b7a7e6f
Remove extra index on pending_segments table
kfaraz 46a1b1e
Fix SegmentTransactionalReplaceAction
kfaraz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
...ava/org/apache/druid/indexing/common/actions/CommitRealtimeSegmentsAndMetadataAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.indexing.common.actions; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.google.common.base.Preconditions; | ||
import org.apache.druid.indexing.common.task.IndexTaskUtils; | ||
import org.apache.druid.indexing.common.task.Task; | ||
import org.apache.druid.indexing.overlord.CriticalAction; | ||
import org.apache.druid.indexing.overlord.DataSourceMetadata; | ||
import org.apache.druid.indexing.overlord.SegmentPublishResult; | ||
import org.apache.druid.segment.SegmentUtils; | ||
import org.apache.druid.timeline.DataSegment; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Task action to commit realtime segments and metadata when using APPEND task locks. | ||
* <p> | ||
* This action performs the following operations in a single transaction: | ||
* <ul> | ||
* <li>Commit the append segments</li> | ||
* <li>Upgrade the append segments to all visible REPLACE versions</li> | ||
* <li>Commit start and end {@link DataSourceMetadata}.</li> | ||
* </ul> | ||
* This action differs from {@link SegmentTransactionalInsertAction} as it is used | ||
* only with APPEND locks and also upgrades segments as needed. | ||
*/ | ||
public class CommitRealtimeSegmentsAndMetadataAction implements TaskAction<SegmentPublishResult> | ||
{ | ||
/** | ||
* Set of segments to be inserted into metadata storage | ||
*/ | ||
private final Set<DataSegment> segments; | ||
|
||
private final DataSourceMetadata startMetadata; | ||
private final DataSourceMetadata endMetadata; | ||
|
||
public static CommitRealtimeSegmentsAndMetadataAction create( | ||
Set<DataSegment> segments, | ||
DataSourceMetadata startMetadata, | ||
DataSourceMetadata endMetadata | ||
) | ||
{ | ||
return new CommitRealtimeSegmentsAndMetadataAction(segments, startMetadata, endMetadata); | ||
} | ||
|
||
@JsonCreator | ||
private CommitRealtimeSegmentsAndMetadataAction( | ||
@JsonProperty("segments") Set<DataSegment> segments, | ||
@JsonProperty("startMetadata") DataSourceMetadata startMetadata, | ||
@JsonProperty("endMetadata") DataSourceMetadata endMetadata | ||
) | ||
{ | ||
Preconditions.checkArgument( | ||
segments != null && !segments.isEmpty(), | ||
"Segments to commit should not be empty" | ||
); | ||
this.segments = segments; | ||
this.startMetadata = startMetadata; | ||
this.endMetadata = endMetadata; | ||
} | ||
|
||
@JsonProperty | ||
public Set<DataSegment> getSegments() | ||
{ | ||
return segments; | ||
} | ||
|
||
@JsonProperty | ||
public DataSourceMetadata getStartMetadata() | ||
{ | ||
return startMetadata; | ||
} | ||
|
||
@JsonProperty | ||
public DataSourceMetadata getEndMetadata() | ||
{ | ||
return endMetadata; | ||
} | ||
|
||
@Override | ||
public TypeReference<SegmentPublishResult> getReturnTypeReference() | ||
{ | ||
return new TypeReference<SegmentPublishResult>() | ||
{ | ||
}; | ||
} | ||
|
||
/** | ||
* Performs some sanity checks and publishes the given segments. | ||
*/ | ||
@Override | ||
public SegmentPublishResult perform(Task task, TaskActionToolbox toolbox) | ||
{ | ||
final SegmentPublishResult publishResult; | ||
|
||
TaskLocks.checkLockCoversSegments(task, toolbox.getTaskLockbox(), segments); | ||
|
||
try { | ||
publishResult = toolbox.getTaskLockbox().doInCriticalSection( | ||
task, | ||
segments.stream().map(DataSegment::getInterval).collect(Collectors.toSet()), | ||
CriticalAction.<SegmentPublishResult>builder() | ||
.onValidLocks( | ||
// TODO: this might need to call a new method which does the following in the same transaction | ||
// - commit append segments | ||
// - upgrade append segments to replace versions | ||
// - commit metadata | ||
() -> toolbox.getIndexerMetadataStorageCoordinator().commitSegmentsAndMetadata( | ||
segments, | ||
startMetadata, | ||
endMetadata | ||
) | ||
) | ||
.onInvalidLocks( | ||
() -> SegmentPublishResult.fail( | ||
"Invalid task locks. Maybe they are revoked by a higher priority task." | ||
+ " Please check the overlord log for details." | ||
) | ||
) | ||
.build() | ||
); | ||
} | ||
catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
IndexTaskUtils.emitSegmentPublishMetrics(publishResult, task, toolbox); | ||
return publishResult; | ||
} | ||
|
||
@Override | ||
public boolean isAudited() | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "CommitRealtimeSegmentsAndMetadataAction{" + | ||
", segments=" + SegmentUtils.commaSeparatedIdentifiers(segments) + | ||
", startMetadata=" + startMetadata + | ||
", endMetadata=" + endMetadata + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we not re-use SegmentTransactionAppendAction with the metadata being null for batch and the required values for streaming ingestion (similar to the original insert action)?
Is there anything besides the metadata commit that this action does that the transactional append action doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was thinking the same. Let me see what we can do.