diff --git a/api/src/main/java/org/apache/iceberg/actions/ActionsProvider.java b/api/src/main/java/org/apache/iceberg/actions/ActionsProvider.java index 2d6ff2679a17..928dae89bcba 100644 --- a/api/src/main/java/org/apache/iceberg/actions/ActionsProvider.java +++ b/api/src/main/java/org/apache/iceberg/actions/ActionsProvider.java @@ -70,4 +70,10 @@ default RewritePositionDeleteFiles rewritePositionDeletes(Table table) { throw new UnsupportedOperationException( this.getClass().getName() + " does not implement rewritePositionDeletes"); } + + /** Instantiates an action to check snapshot integrity. */ + default CheckSnapshotIntegrity checkSnapshotIntegrity(Table table) { + throw new UnsupportedOperationException( + this.getClass().getName() + " does not implement checkSnapshotIntegrity"); + } } diff --git a/api/src/main/java/org/apache/iceberg/actions/CheckSnapshotIntegrity.java b/api/src/main/java/org/apache/iceberg/actions/CheckSnapshotIntegrity.java new file mode 100644 index 000000000000..b3bea2233503 --- /dev/null +++ b/api/src/main/java/org/apache/iceberg/actions/CheckSnapshotIntegrity.java @@ -0,0 +1,53 @@ +/* + * 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.actions; + +import java.util.concurrent.ExecutorService; + +public interface CheckSnapshotIntegrity + extends Action { + + /** + * Passes an alternative executor service that will be used for snapshot integrity checking. If + * this method is not called, snapshot integrity checker will still be running by a single + * threaded executor service. + * + * @param executorService an executor service to parallelize tasks to check snapshot integrity + * @return this for method chaining + */ + CheckSnapshotIntegrity executeWith(ExecutorService executorService); + + /** + * Pass the target version to check. The action checks the snapshots in the target version, not in + * the current version of the table. + * + * @param targetVersion the target version file to be checked. Either a file name or a file path + * is acceptable. For example, it could be either + * "00001-8893aa9e-f92e-4443-80e7-cfa42238a654.metadata.json" or + * "/path/to/00001-8893aa9e-f92e-4443-80e7-cfa42238a654.metadata.json". + * @return this for method chaining + */ + CheckSnapshotIntegrity targetVersion(String targetVersion); + + /** The action result that contains a summary of the execution. */ + interface Result { + /** Returns locations of missing metadata/data files. */ + Iterable missingFileLocations(); + } +} diff --git a/core/src/main/java/org/apache/iceberg/actions/BaseCheckSnapshotIntegrityResult.java b/core/src/main/java/org/apache/iceberg/actions/BaseCheckSnapshotIntegrityResult.java new file mode 100644 index 000000000000..b0660bca8c8f --- /dev/null +++ b/core/src/main/java/org/apache/iceberg/actions/BaseCheckSnapshotIntegrityResult.java @@ -0,0 +1,32 @@ +/* + * 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.actions; + +public class BaseCheckSnapshotIntegrityResult implements CheckSnapshotIntegrity.Result { + private final Iterable missingFileLocations; + + public BaseCheckSnapshotIntegrityResult(Iterable missingFileLocations) { + this.missingFileLocations = missingFileLocations; + } + + @Override + public Iterable missingFileLocations() { + return missingFileLocations; + } +}