-
Notifications
You must be signed in to change notification settings - Fork 125
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
Enforce globally unique table locations #67
Closed
eric-maynard
wants to merge
21
commits into
apache:main
from
eric-maynard:enforce-globally-unique-table-location
Closed
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d7a6acc
initial commit
eric-maynard bdc92c5
semi-stable
eric-maynard ce5b0fd
add check
eric-maynard 97a1700
wip
eric-maynard 5c656a3
start implementing test
eric-maynard 9919f80
progress on test
eric-maynard 279bb64
entity locations are null
eric-maynard daae37b
check in
eric-maynard 834696a
try fixing loation routing
eric-maynard 3d24bd8
getting close
eric-maynard def7330
stable
eric-maynard 88f9cfb
ENFORCE_TABLE_LOCATIONS_INSIDE_NAMESPACE_LOCATIONS; stable
eric-maynard 2230a93
stable
eric-maynard 3103f91
fix an existing test
eric-maynard 092cffa
debugging
eric-maynard a95bcde
Merge branch 'main' of github.com:polaris-catalog/polaris into enforc…
eric-maynard e91d45e
progress on refactor
eric-maynard 797d467
pause for now
eric-maynard e8e7fe2
push location check into PolarisBaseEntity
eric-maynard 38eb126
somewhat optimize query
eric-maynard 2d3e886
harden query
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 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 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 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
37 changes: 37 additions & 0 deletions
37
polaris-core/src/main/java/io/polaris/core/PolarisUtils.java
This file contains 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,37 @@ | ||
/* | ||
* Copyright (c) 2024 Snowflake Computing Inc. | ||
* | ||
* Licensed 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 io.polaris.core; | ||
|
||
/** | ||
* A collection of utilities for polaris-core | ||
*/ | ||
public class PolarisUtils { | ||
|
||
/** | ||
* Given some path, append a `/` if it doesn't already end with one | ||
*/ | ||
public static String terminateWithSlash(String path) { | ||
if (path == null) { | ||
return null; | ||
} else if (!path.endsWith("/")) { | ||
return path + "/"; | ||
} else { | ||
return path; | ||
} | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.
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.
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.
Doesn't the 2nd condition cause a full-table-scan?
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.
Yes, as written it unfortunately will.
Of course, this is all dependent on the metastore manager implementation (and in this case the backing database's implementation).
In any event if this check was always being done, I think there are some easy ways to optimize this. But since the check is optional, we may need to check every path. I'm still testing ways to improve performance of this optional check.
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.
I was thinking about this problem a bit. It's a tricky-fun one ;)
Just brain-dumping some thoughts:
There are a few things that play a role here - respectively w/ locations in general.
I think we can rely on
/
as a separator. With that in mind, a location is a duple of "bucket" (S3/GCS bucket or ADSL fs-name) plus a list of path elements. If we distinguish parent directories from table directories, the check becomes easier. I.e. a separate metastore entity that is only used to track locations.When you want to add/check for a new
location
likes3://bucket/my/path/my-table
, the followingINSERT
s could do the trick:If the last one fails -> location already used -> fail hard. If any of the parents did not succeed, verify that those are all
kind = 'parent'
.I suspect, this needs some more thought around race conditions (two tables with conflicting locations).