-
Notifications
You must be signed in to change notification settings - Fork 271
Make StorageCredentialCache safe for multi-realm usage #2021
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,16 +18,14 @@ | |
*/ | ||
package org.apache.polaris.core.storage.cache; | ||
|
||
import jakarta.annotation.Nullable; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import org.apache.polaris.core.PolarisCallContext; | ||
import org.apache.polaris.core.context.CallContext; | ||
import org.apache.polaris.core.entity.PolarisEntity; | ||
import org.apache.polaris.core.entity.PolarisEntityConstants; | ||
|
||
public class StorageCredentialCacheKey { | ||
|
||
private final String realmId; | ||
private final long catalogId; | ||
|
||
/** The serialized string of the storage config. */ | ||
|
@@ -44,18 +42,13 @@ public class StorageCredentialCacheKey { | |
|
||
private final Set<String> allowedWriteLocations; | ||
|
||
/** | ||
* The callContext is passed to be used to fetch subscoped creds, but is not used to hash/equals | ||
* as part of the cache key. | ||
*/ | ||
private @Nullable PolarisCallContext callContext; | ||
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. I suspect the removal of this field is the key of this PR? It totally makes sense to not keep per-request state around. 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. yes but also removal of the |
||
|
||
public StorageCredentialCacheKey( | ||
String realmId, | ||
PolarisEntity entity, | ||
boolean allowedListAction, | ||
Set<String> allowedReadLocations, | ||
Set<String> allowedWriteLocations, | ||
@Nullable PolarisCallContext callContext) { | ||
Set<String> allowedWriteLocations) { | ||
this.realmId = realmId; | ||
this.catalogId = entity.getCatalogId(); | ||
this.storageConfigSerializedStr = | ||
entity | ||
|
@@ -65,10 +58,10 @@ public StorageCredentialCacheKey( | |
this.allowedListAction = allowedListAction; | ||
this.allowedReadLocations = allowedReadLocations; | ||
this.allowedWriteLocations = allowedWriteLocations; | ||
this.callContext = callContext; | ||
if (this.callContext == null) { | ||
this.callContext = CallContext.getCurrentContext().getPolarisCallContext(); | ||
} | ||
} | ||
|
||
public String getRealmId() { | ||
return realmId; | ||
} | ||
|
||
public long getCatalogId() { | ||
|
@@ -95,16 +88,13 @@ public Set<String> getAllowedWriteLocations() { | |
return allowedWriteLocations; | ||
} | ||
|
||
public @Nullable PolarisCallContext getCallContext() { | ||
return callContext; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
StorageCredentialCacheKey cacheKey = (StorageCredentialCacheKey) o; | ||
return catalogId == cacheKey.getCatalogId() | ||
return Objects.equals(realmId, cacheKey.getRealmId()) | ||
&& catalogId == cacheKey.getCatalogId() | ||
&& Objects.equals(storageConfigSerializedStr, cacheKey.getStorageConfigSerializedStr()) | ||
&& allowedListAction == cacheKey.allowedListAction | ||
&& Objects.equals(allowedReadLocations, cacheKey.allowedReadLocations) | ||
|
@@ -114,6 +104,7 @@ public boolean equals(Object o) { | |
@Override | ||
public int hashCode() { | ||
return Objects.hash( | ||
realmId, | ||
catalogId, | ||
storageConfigSerializedStr, | ||
allowedListAction, | ||
|
@@ -124,7 +115,9 @@ public int hashCode() { | |
@Override | ||
public String toString() { | ||
return "StorageCredentialCacheKey{" | ||
+ "catalogId=" | ||
+ "realmId=" | ||
+ realmId | ||
+ ", catalogId=" | ||
+ catalogId | ||
+ ", storageConfigSerializedStr='" | ||
+ storageConfigSerializedStr | ||
|
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.
Unrelated: this field is unused