-
Notifications
You must be signed in to change notification settings - Fork 333
Allow BasePolarisTableOperations to skip refreshing metadata after a commit #1378
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1eef525
rebase
eric-maynard 08e78e7
autolint
eric-maynard 37c22c4
autolint
eric-maynard 7ebf9b0
fix other tests
eric-maynard 455e231
autolint
eric-maynard 453f108
semistable
eric-maynard a6c342d
touch up
eric-maynard c318521
autolint
eric-maynard b06c6ea
superstable
eric-maynard 08783ac
autolint
eric-maynard 34b6e28
static block per review
eric-maynard f62da00
doc change
eric-maynard f7e11c3
changes per review
eric-maynard 5aeb961
move
eric-maynard 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
104 changes: 104 additions & 0 deletions
104
...c/main/java/org/apache/polaris/service/catalog/iceberg/TableOperationsReflectionUtil.java
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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * 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.polaris.service.catalog.iceberg; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.util.ArrayList; | ||
| import org.apache.iceberg.BaseMetastoreTableOperations; | ||
| import org.apache.iceberg.MetadataUpdate; | ||
| import org.apache.iceberg.TableMetadata; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import sun.misc.Unsafe; | ||
|
|
||
| /** | ||
| * Used to handle reflection-related fields for TableOperations and TableMetadata TODO remove the | ||
| * following if the Iceberg library allows us to do this without reflection For more details see <a | ||
| * href="https://github.com/apache/polaris/pull/1378">#1378</a> | ||
| */ | ||
| public final class TableOperationsReflectionUtil { | ||
| private static Logger LOGGER = LoggerFactory.getLogger(TableOperationsReflectionUtil.class); | ||
|
|
||
| private static class Instance { | ||
| private static TableOperationsReflectionUtil instance = new TableOperationsReflectionUtil(); | ||
| } | ||
|
|
||
| static TableOperationsReflectionUtil getInstance() { | ||
| return Instance.instance; | ||
| } | ||
|
|
||
| public void setMetadataFileLocation(TableMetadata tableMetadata, String metadataFileLocation) { | ||
| try { | ||
| tableMetadataField.set(tableMetadata, metadataFileLocation); | ||
| unsafe.putObject(tableMetadata, changesFieldOffset, new ArrayList<MetadataUpdate>()); | ||
| } catch (IllegalAccessException e) { | ||
| LOGGER.error( | ||
| "Encountered an unexpected error while attempting to access private fields" | ||
| + " in TableMetadata", | ||
| e); | ||
| } | ||
| } | ||
|
|
||
| public void setCurrentMetadata( | ||
| BaseMetastoreTableOperations tableOperations, | ||
| TableMetadata tableMetadata, | ||
| String metadataFileLocation) { | ||
| try { | ||
| currentMetadataLocationField.set(tableOperations, metadataFileLocation); | ||
| currentMetadataField.set(tableOperations, tableMetadata); | ||
| } catch (IllegalAccessException e) { | ||
| LOGGER.error( | ||
| "Encountered an unexpected error while attempting to access private fields" | ||
| + " in BaseMetastoreTableOperations", | ||
| e); | ||
| } | ||
| } | ||
|
|
||
| private final Unsafe unsafe; | ||
| private final Field tableMetadataField; | ||
| private final long changesFieldOffset; | ||
| private final Field currentMetadataLocationField; | ||
| private final Field currentMetadataField; | ||
|
|
||
| private TableOperationsReflectionUtil() { | ||
| try { | ||
| tableMetadataField = TableMetadata.class.getDeclaredField("metadataFileLocation"); | ||
| tableMetadataField.setAccessible(true); | ||
|
|
||
| Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); | ||
| unsafeField.setAccessible(true); | ||
| unsafe = (Unsafe) unsafeField.get(null); | ||
| Field changesField = TableMetadata.class.getDeclaredField("changes"); | ||
| changesField.setAccessible(true); | ||
| changesFieldOffset = unsafe.objectFieldOffset(changesField); | ||
|
|
||
| currentMetadataLocationField = | ||
| BaseMetastoreTableOperations.class.getDeclaredField("currentMetadataLocation"); | ||
| currentMetadataLocationField.setAccessible(true); | ||
|
|
||
| currentMetadataField = BaseMetastoreTableOperations.class.getDeclaredField("currentMetadata"); | ||
| currentMetadataField.setAccessible(true); | ||
| } catch (IllegalAccessException | NoSuchFieldException e) { | ||
| LOGGER.error( | ||
| "Encountered an unexpected error while attempting to access private fields in TableMetadata", | ||
| e); | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
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.
Why not do the same for views?
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.
In the current iteration of the PR I'm making a judgement call between the complexity of the change and consistency across views & tables. Ideally we can contribute this upstream to Iceberg and then the reflection hack goes away. In the meantime, views tend to have much less metadata than tables (and also to get updated less frequently) and so I'm less concerned about the extra round trip to object storage.