|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.polaris.storage.files.api; |
| 21 | + |
| 22 | +import jakarta.annotation.Nonnull; |
| 23 | +import java.util.stream.Stream; |
| 24 | + |
| 25 | +/** |
| 26 | + * Object storage file operations, used to find files below a given prefix, to purge files, to |
| 27 | + * identify referenced files, etc. |
| 28 | + * |
| 29 | + * <p>All functions of this interface rather yield incomplete results and continue over throwing |
| 30 | + * exceptions. |
| 31 | + */ |
| 32 | +public interface FileOperations { |
| 33 | + /** |
| 34 | + * Find files that match the given prefix and filter. |
| 35 | + * |
| 36 | + * <p>Whether existing but inaccessible files are included in the result depends on the object |
| 37 | + * store. |
| 38 | + * |
| 39 | + * <p>Call sites should consider rate-limiting the scan operations, for example, by using Guava's |
| 40 | + * {@code RateLimiter} via a {@code Stream.map(x -> { rateLimiter.acquire(); return x; }} step on |
| 41 | + * the returned stream. |
| 42 | + * |
| 43 | + * @param prefix full object storage URI prefix, including scheme and bucket. |
| 44 | + * @param filter file filter |
| 45 | + * @return a stream of file specs with the {@link FileSpec#createdAtMillis()} and {@link |
| 46 | + * FileSpec#size()} attributes populated with the information provided by the object store. |
| 47 | + * The {@link FileSpec#fileType() file type} attribute is not populated, it may be {@link |
| 48 | + * FileSpec#guessTypeFromName() guessed}. |
| 49 | + */ |
| 50 | + Stream<FileSpec> findFiles(@Nonnull String prefix, @Nonnull FileFilter filter); |
| 51 | + |
| 52 | + /** |
| 53 | + * Identifies all files referenced by the given table-metadata. |
| 54 | + * |
| 55 | + * <p>In case "container" files, like the metadata, manifest-list or manifest files, are not |
| 56 | + * readable, the returned stream will just not include those. |
| 57 | + * |
| 58 | + * <p>Rate-limiting the returned stream is recommended when identifying multiple tables and/or |
| 59 | + * views. Rate-limiting on a single invocation may not be effective as expected. |
| 60 | + * |
| 61 | + * @param tableMetadataLocation Iceberg table-metadata location |
| 62 | + * @param deduplicate if true, attempt to deduplicate files by their location, adding additional |
| 63 | + * heap pressure to the operation. Implementations may ignore this parameter or may not |
| 64 | + * deduplicate all identified files. |
| 65 | + * @return a stream of {@link FileSpec file specs}. The {@link FileSpec#createdAtMillis()} |
| 66 | + * attribute is usually not populated, as it would have to be derived from user-provided |
| 67 | + * information in metadata or snapshot. The {@link FileSpec#fileType()} attribute is populated |
| 68 | + * based on where a file appears during identification. |
| 69 | + */ |
| 70 | + Stream<FileSpec> identifyIcebergTableFiles( |
| 71 | + @Nonnull String tableMetadataLocation, boolean deduplicate); |
| 72 | + |
| 73 | + /** |
| 74 | + * Identifies all files referenced by the given view-metadata. |
| 75 | + * |
| 76 | + * <p>In case "container" files like the metadata are not readable, the returned stream will just |
| 77 | + * not include those. |
| 78 | + * |
| 79 | + * <p>Rate-limiting the returned stream is recommended when identifying multiple tables and/or |
| 80 | + * views. Rate-limiting on a single invocation may not be effective as expected. |
| 81 | + * |
| 82 | + * @param viewMetadataLocation Iceberg view-metadata location |
| 83 | + * @param deduplicate if true, attempt to deduplicate files by their location, adding additional |
| 84 | + * heap pressure to the operation. Implementations may ignore this parameter or may not |
| 85 | + * deduplicate all identified files. |
| 86 | + * @return a stream of {@link FileSpec file specs}. The {@link FileSpec#createdAtMillis()} |
| 87 | + * attribute is usually not populated, as it would have been derived from user-provided |
| 88 | + * information in metadata or snapshot. The {@link FileSpec#fileType()} attribute is populated |
| 89 | + * based on where a file appears during identification. |
| 90 | + */ |
| 91 | + Stream<FileSpec> identifyIcebergViewFiles( |
| 92 | + @Nonnull String viewMetadataLocation, boolean deduplicate); |
| 93 | + |
| 94 | + /** |
| 95 | + * Purges all files that are referenced by the given table-metadata, respecting the given filter. |
| 96 | + * |
| 97 | + * <p>In case "container" files, like the metadata, manifest-list or manifest files, are not |
| 98 | + * readable, those files are just ignored. |
| 99 | + * |
| 100 | + * <p>This is effectively a convenience for {@code |
| 101 | + * purge(identifyIcebergTableFiles(tableMetadataLocation).filter(purgeSpec.fileFilter()))} |
| 102 | + * |
| 103 | + * @see #purge(Stream, PurgeSpec) |
| 104 | + * @see #identifyIcebergTableFiles(String, boolean) |
| 105 | + * @see #findFiles(String, FileFilter) |
| 106 | + */ |
| 107 | + PurgeStats purgeIcebergTable(@Nonnull String tableMetadataLocation, PurgeSpec purgeSpec); |
| 108 | + |
| 109 | + /** |
| 110 | + * Purges all files that are within the base location of the given table-metadata, purge only |
| 111 | + * files that match the given filter. |
| 112 | + * |
| 113 | + * <p>In case "container" files, like the metadata, manifest-list or manifest files, are not |
| 114 | + * readable, those files are just ignored. |
| 115 | + * |
| 116 | + * <p>This is effectively a convenience for {@code |
| 117 | + * purge(findFiles(tableMetadata.baseLocation()).filter(purgeSpec.fileFilter()))} |
| 118 | + * |
| 119 | + * @see #purge(Stream, PurgeSpec) |
| 120 | + * @see #findFiles(String, FileFilter) |
| 121 | + */ |
| 122 | + PurgeStats purgeIcebergTableBaseLocation( |
| 123 | + @Nonnull String tableMetadataLocation, PurgeSpec purgeSpec); |
| 124 | + |
| 125 | + /** |
| 126 | + * Purges all files that are referenced by the given view-metadata, respecting the given filter. * |
| 127 | + * |
| 128 | + * <p>In case "container" files like the metadata are not readable, those files are just ignored. |
| 129 | + * |
| 130 | + * <p>This is effectively a convenience for {@code |
| 131 | + * purge(identifyIcebergViewFiles(tableMetadataLocation).filter(fileFilter))} |
| 132 | + * |
| 133 | + * @see #purge(Stream, PurgeSpec) |
| 134 | + * @see #identifyIcebergViewFiles(String, boolean) |
| 135 | + * @see #findFiles(String, FileFilter) |
| 136 | + */ |
| 137 | + PurgeStats purgeIcebergView(@Nonnull String viewMetadataLocation, PurgeSpec purgeSpec); |
| 138 | + |
| 139 | + /** |
| 140 | + * Purges all files that are within the base location of the given view-metadata, purge only files |
| 141 | + * that match the given filter. * |
| 142 | + * |
| 143 | + * <p>In case "container" files like the metadata are not readable, those files are just ignored. |
| 144 | + * |
| 145 | + * <p>This is effectively a convenience for {@code |
| 146 | + * purge(findFiles(viewMetadata.baseLocation()).filter(fileFilter))} |
| 147 | + * |
| 148 | + * @see #purge(Stream, PurgeSpec) |
| 149 | + * @see #findFiles(String, FileFilter) |
| 150 | + */ |
| 151 | + PurgeStats purgeIcebergViewBaseLocation( |
| 152 | + @Nonnull String viewMetadataLocation, PurgeSpec purgeSpec); |
| 153 | + |
| 154 | + /** |
| 155 | + * Purges all files that match the given stream of locations. The {@link Stream} will be fully |
| 156 | + * consumed. |
| 157 | + * |
| 158 | + * <p>This is a convenience for {@link #purgeFiles(Stream, PurgeSpec) |
| 159 | + * purgeFiles(locationStream.map(FileSpec::location))} |
| 160 | + */ |
| 161 | + PurgeStats purge(@Nonnull Stream<FileSpec> locationStream, PurgeSpec purgeSpec); |
| 162 | + |
| 163 | + /** |
| 164 | + * Purges all files from the given stream of locations. The {@link Stream} will be fully consumed. |
| 165 | + * |
| 166 | + * <p>Non-existing files and other deletion errors will not let the call fail, which makes it |
| 167 | + * resilient against transient or irrelevant errors. |
| 168 | + */ |
| 169 | + PurgeStats purgeFiles(@Nonnull Stream<String> locationStream, PurgeSpec purgeSpec); |
| 170 | +} |
0 commit comments