-
Notifications
You must be signed in to change notification settings - Fork 3k
Add mixin interface to support commit validation #14503
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,7 @@ | |
| * and {@link TableProperties#COMMIT_NUM_RETRIES_DEFAULT} properties. | ||
| */ | ||
| @SuppressWarnings("UnnecessaryAnonymousClass") | ||
| abstract class SnapshotProducer<ThisT> implements SnapshotUpdate<ThisT> { | ||
| abstract class SnapshotProducer<ThisT> implements SnapshotUpdate<ThisT>, SupportsCommitValidation { | ||
| private static final Logger LOG = LoggerFactory.getLogger(SnapshotProducer.class); | ||
| static final int MIN_FILE_GROUP_SIZE = 10_000; | ||
| static final Set<ManifestFile> EMPTY_SET = Sets.newHashSet(); | ||
|
|
@@ -421,8 +421,13 @@ protected TableMetadata refresh() { | |
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("checkstyle:CyclomaticComplexity") | ||
| public void commit() { | ||
| commit(NON_VALIDATING); | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("checkstyle:CyclomaticComplexity") | ||
| public void commit(CommitValidator validator) { | ||
| // this is always set to the latest commit attempt's snapshot | ||
| AtomicReference<Snapshot> stagedSnapshot = new AtomicReference<>(); | ||
| try (Timed ignore = commitMetrics().totalDuration().start()) { | ||
|
|
@@ -464,6 +469,7 @@ public void commit() { | |
| // this operation retries | ||
| // to ensure that if a concurrent operation assigns the UUID, this operation will | ||
| // not fail. | ||
| validator.accept(base, updated); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be close to the other |
||
| taskOps.commit(base, updated.withUUID()); | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * 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.iceberg; | ||
|
|
||
| import java.util.function.BiConsumer; | ||
| import org.apache.iceberg.exceptions.CommitFailedException; | ||
|
|
||
| public interface SupportsCommitValidation { | ||
| CommitValidator NON_VALIDATING = (base, metadata) -> {}; | ||
|
|
||
| @FunctionalInterface | ||
| interface CommitValidator extends BiConsumer<TableMetadata, TableMetadata> { | ||
| @Override | ||
| void accept(TableMetadata base, TableMetadata current); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this accept /**
* Validate the current metadata.
*
* <p>Child operations can override this to add custom validation.
*
* @param currentMetadata current table metadata to validate
* @param snapshot ending snapshot on the lineage which is being validated
*/
protected void validate(TableMetadata currentMetadata, Snapshot snapshot) {} |
||
| } | ||
|
|
||
| /** | ||
| * Commits the updated metadata to the table taking a validator that will be called with the | ||
| * refreshed metadata and pending metadata. | ||
danielcweeks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * <p> | ||
| * The validator should throw a {@link CommitFailedException} if validation fails. Retries will still | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not throw a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We retry on
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It makes sense to retry a I think the |
||
| * apply so subsequent attempts to commit will be validated until retries are exhausted. | ||
| * | ||
| * @param validator | ||
| */ | ||
| void commit(CommitValidator validator); | ||
danielcweeks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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.
[optional] may be move this above comment since the comment is for line below