-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Bump Nessie to 0.15.1 + related changes #3257
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -41,25 +41,27 @@ | |
| import org.apache.iceberg.exceptions.NoSuchTableException; | ||
| import org.apache.iceberg.hadoop.HadoopFileIO; | ||
| import org.apache.iceberg.io.FileIO; | ||
| import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Joiner; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
| import org.apache.iceberg.util.Tasks; | ||
| import org.projectnessie.api.TreeApi; | ||
| import org.projectnessie.api.params.EntriesParams; | ||
| import org.projectnessie.client.NessieClient; | ||
| import org.projectnessie.client.NessieConfigConstants; | ||
| import org.projectnessie.client.api.CommitMultipleOperationsBuilder; | ||
| import org.projectnessie.client.api.NessieApiV1; | ||
| import org.projectnessie.client.http.HttpClientBuilder; | ||
| import org.projectnessie.client.http.HttpClientException; | ||
| import org.projectnessie.error.BaseNessieClientServerException; | ||
| import org.projectnessie.error.NessieConflictException; | ||
| import org.projectnessie.error.NessieNotFoundException; | ||
| import org.projectnessie.model.Branch; | ||
| import org.projectnessie.model.Contents; | ||
| import org.projectnessie.model.Content; | ||
| import org.projectnessie.model.ContentKey; | ||
| import org.projectnessie.model.IcebergTable; | ||
| import org.projectnessie.model.ImmutableDelete; | ||
| import org.projectnessie.model.ImmutableOperations; | ||
| import org.projectnessie.model.ImmutablePut; | ||
| import org.projectnessie.model.Operations; | ||
| import org.projectnessie.model.Operation; | ||
| import org.projectnessie.model.Reference; | ||
| import org.projectnessie.model.TableReference; | ||
| import org.projectnessie.model.Tag; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -75,7 +77,7 @@ | |
| public class NessieCatalog extends BaseMetastoreCatalog implements AutoCloseable, SupportsNamespaces, Configurable { | ||
| private static final Logger logger = LoggerFactory.getLogger(NessieCatalog.class); | ||
| private static final Joiner SLASH = Joiner.on("/"); | ||
| private NessieClient client; | ||
| private NessieApiV1 api; | ||
|
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.
|
||
| private String warehouseLocation; | ||
| private Configuration config; | ||
| private UpdateableReference reference; | ||
|
|
@@ -95,7 +97,8 @@ public void initialize(String inputName, Map<String, String> options) { | |
| // remove nessie prefix | ||
| final Function<String, String> removePrefix = x -> x.replace("nessie.", ""); | ||
|
|
||
| this.client = NessieClient.builder().fromConfig(x -> options.get(removePrefix.apply(x))).build(); | ||
| this.api = HttpClientBuilder.builder().fromConfig(x -> options.get(removePrefix.apply(x))) | ||
| .build(NessieApiV1.class); | ||
|
|
||
| this.warehouseLocation = options.get(CatalogProperties.WAREHOUSE_LOCATION); | ||
| if (warehouseLocation == null) { | ||
|
|
@@ -120,12 +123,12 @@ public void initialize(String inputName, Map<String, String> options) { | |
| throw new IllegalStateException("Parameter 'warehouse' not set, Nessie can't store data."); | ||
| } | ||
| final String requestedRef = options.get(removePrefix.apply(NessieConfigConstants.CONF_NESSIE_REF)); | ||
| this.reference = loadReference(requestedRef); | ||
| this.reference = loadReference(requestedRef, null); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| client.close(); | ||
| api.close(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -135,15 +138,17 @@ public String name() { | |
|
|
||
| @Override | ||
| protected TableOperations newTableOps(TableIdentifier tableIdentifier) { | ||
| TableReference pti = TableReference.parse(tableIdentifier); | ||
| TableReference tr = TableReference.parse(tableIdentifier.name()); | ||
| Preconditions.checkArgument(!tr.hasTimestamp(), "Invalid table name: # is only allowed for hashes (reference by " + | ||
| "timestamp is not supported)"); | ||
| UpdateableReference newReference = this.reference; | ||
| if (pti.reference() != null) { | ||
| newReference = loadReference(pti.reference()); | ||
| if (tr.getReference() != null) { | ||
| newReference = loadReference(tr.getReference(), tr.getHash()); | ||
| } | ||
| return new NessieTableOperations( | ||
| NessieUtil.toKey(pti.tableIdentifier()), | ||
| ContentKey.of(org.projectnessie.model.Namespace.of(tableIdentifier.namespace().levels()), tr.getName()), | ||
| newReference, | ||
| client, | ||
| api, | ||
| fileIO, | ||
| catalogOptions); | ||
| } | ||
|
|
@@ -170,23 +175,27 @@ public boolean dropTable(TableIdentifier identifier, boolean purge) { | |
| return false; | ||
| } | ||
|
|
||
| Operations contents = ImmutableOperations.builder() | ||
| .addOperations(ImmutableDelete.builder().key(NessieUtil.toKey(identifier)).build()) | ||
| .commitMeta(NessieUtil.buildCommitMetadata(String.format("iceberg delete table '%s'", identifier), | ||
| if (purge) { | ||
| logger.info("Purging data for table {} was set to true but is ignored", identifier.toString()); | ||
| } | ||
|
|
||
| CommitMultipleOperationsBuilder commitBuilderBase = api.commitMultipleOperations() | ||
rymurr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .commitMeta(NessieUtil.buildCommitMetadata(String.format("Iceberg delete table %s", identifier), | ||
| catalogOptions)) | ||
| .build(); | ||
| .operation(Operation.Delete.of(NessieUtil.toKey(identifier))); | ||
|
|
||
| // We try to drop the table. Simple retry after ref update. | ||
| boolean threw = true; | ||
| try { | ||
| Tasks.foreach(contents) | ||
| Tasks.foreach(commitBuilderBase) | ||
| .retry(5) | ||
| .stopRetryOn(NessieNotFoundException.class) | ||
| .throwFailureWhenFinished() | ||
| .onFailure((c, exception) -> refresh()) | ||
| .run(c -> { | ||
| Branch branch = client.getTreeApi().commitMultipleOperations(reference.getAsBranch().getName(), | ||
| reference.getHash(), c); | ||
| .onFailure((o, exception) -> refresh()) | ||
| .run(commitBuilder -> { | ||
| Branch branch = commitBuilder | ||
| .branch(reference.getAsBranch()) | ||
| .commit(); | ||
| reference.updateReference(branch); | ||
| }, BaseNessieClientServerException.class); | ||
| threw = false; | ||
|
|
@@ -215,24 +224,22 @@ public void renameTable(TableIdentifier from, TableIdentifier toOriginal) { | |
| throw new AlreadyExistsException("table %s already exists", to.name()); | ||
| } | ||
|
|
||
| Operations contents = ImmutableOperations.builder() | ||
| .addOperations( | ||
| ImmutablePut.builder().key(NessieUtil.toKey(to)).contents(existingFromTable).build(), | ||
| ImmutableDelete.builder().key(NessieUtil.toKey(from)).build()) | ||
| .commitMeta(NessieUtil.buildCommitMetadata(String.format("iceberg rename table from '%s' to '%s'", | ||
| from, to), | ||
| catalogOptions)) | ||
| .build(); | ||
| CommitMultipleOperationsBuilder operations = api.commitMultipleOperations() | ||
| .commitMeta(NessieUtil.buildCommitMetadata(String.format("Iceberg rename table from '%s' to '%s'", | ||
| from, to), catalogOptions)) | ||
| .operation(Operation.Put.of(NessieUtil.toKey(to), existingFromTable, existingFromTable)) | ||
| .operation(Operation.Delete.of(NessieUtil.toKey(from))); | ||
|
|
||
| try { | ||
| Tasks.foreach(contents) | ||
| Tasks.foreach(operations) | ||
| .retry(5) | ||
| .stopRetryOn(NessieNotFoundException.class) | ||
| .throwFailureWhenFinished() | ||
| .onFailure((c, exception) -> refresh()) | ||
| .run(c -> { | ||
| Branch branch = client.getTreeApi().commitMultipleOperations(reference.getAsBranch().getName(), | ||
| reference.getHash(), c); | ||
| .onFailure((o, exception) -> refresh()) | ||
| .run(ops -> { | ||
| Branch branch = ops | ||
| .branch(reference.getAsBranch()) | ||
| .commit(); | ||
| reference.updateReference(branch); | ||
| }, BaseNessieClientServerException.class); | ||
| } catch (NessieNotFoundException e) { | ||
|
|
@@ -322,37 +329,46 @@ public Configuration getConf() { | |
| return config; | ||
| } | ||
|
|
||
| TreeApi getTreeApi() { | ||
| return client.getTreeApi(); | ||
| } | ||
|
|
||
| public void refresh() throws NessieNotFoundException { | ||
| reference.refresh(); | ||
| reference.refresh(api); | ||
| } | ||
|
|
||
| public String currentHash() { | ||
| return reference.getHash(); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| String currentRefName() { | ||
| return reference.getName(); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| FileIO fileIO() { | ||
rymurr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return fileIO; | ||
| } | ||
|
|
||
| private IcebergTable table(TableIdentifier tableIdentifier) { | ||
| try { | ||
| Contents table = client.getContentsApi() | ||
| .getContents(NessieUtil.toKey(tableIdentifier), reference.getName(), reference.getHash()); | ||
| return table.unwrap(IcebergTable.class).orElse(null); | ||
| ContentKey key = NessieUtil.toKey(tableIdentifier); | ||
| Content table = api.getContent().key(key).reference(reference.getReference()).get().get(key); | ||
| return table != null ? table.unwrap(IcebergTable.class).orElse(null) : null; | ||
| } catch (NessieNotFoundException e) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private UpdateableReference loadReference(String requestedRef) { | ||
| private UpdateableReference loadReference(String requestedRef, String hash) { | ||
| try { | ||
| Reference ref = requestedRef == null ? client.getTreeApi().getDefaultBranch() | ||
| : client.getTreeApi().getReferenceByName(requestedRef); | ||
| return new UpdateableReference(ref, client.getTreeApi()); | ||
| Reference ref = requestedRef == null ? api.getDefaultBranch() | ||
| : api.getReference().refName(requestedRef).get(); | ||
| if (hash != null) { | ||
| if (ref instanceof Branch) { | ||
| ref = Branch.of(ref.getName(), hash); | ||
| } else { | ||
| ref = Tag.of(ref.getName(), hash); | ||
| } | ||
| } | ||
| return new UpdateableReference(ref, hash != null); | ||
| } catch (NessieNotFoundException ex) { | ||
| if (requestedRef != null) { | ||
| throw new IllegalArgumentException(String.format( | ||
|
|
@@ -369,8 +385,9 @@ private UpdateableReference loadReference(String requestedRef) { | |
|
|
||
| private Stream<TableIdentifier> tableStream(Namespace namespace) { | ||
| try { | ||
| return client.getTreeApi() | ||
| .getEntries(reference.getName(), EntriesParams.builder().hashOnRef(reference.getHash()).build()) | ||
| return api.getEntries() | ||
| .reference(reference.getReference()) | ||
| .get() | ||
| .getEntries() | ||
| .stream() | ||
| .filter(NessieUtil.namespacePredicate(namespace)) | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
@rymurr, I'm just catching up on this PR, sorry to be late.
I'm curious why this uses a
Functionpassed into refresh rather than defining a load metadata method. The function passed in fromNessieTableOperationsis actually a method reference, so couldn't this just be a call to that method,loadTableMetadata?