This is an automated email from the ASF dual-hosted git repository.
dimas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 9ecf29be1 Use PolarisImmutable for StorageCredentialCacheKey (#2029)
9ecf29be1 is described below
commit 9ecf29be1906d77aad3f0b4961327a38ace2c496
Author: Christopher Lambert <[email protected]>
AuthorDate: Tue Jul 15 18:43:08 2025 +0200
Use PolarisImmutable for StorageCredentialCacheKey (#2029)
* remove unused entityId from StorageCredentialCacheKey
* convert StorageCredentialCacheKey to immutables
---
.../core/storage/cache/StorageCredentialCache.java | 12 +--
.../storage/cache/StorageCredentialCacheKey.java | 113 +++++----------------
.../storage/cache/StorageCredentialCacheTest.java | 2 +-
3 files changed, 30 insertions(+), 97 deletions(-)
diff --git
a/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java
b/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java
index 14b696389..44b41afb3 100644
---
a/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java
+++
b/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java
@@ -112,7 +112,7 @@ public class StorageCredentialCache {
.fail("entity_type_not_suppported_to_scope_creds", "type={}",
polarisEntity.getType());
}
StorageCredentialCacheKey key =
- new StorageCredentialCacheKey(
+ StorageCredentialCacheKey.of(
callCtx.getRealmContext().getRealmIdentifier(),
polarisEntity,
allowListOperation,
@@ -125,12 +125,12 @@ public class StorageCredentialCache {
ScopedCredentialsResult scopedCredentialsResult =
credentialVendor.getSubscopedCredsForEntity(
callCtx,
- k.getCatalogId(),
- k.getEntityId(),
+ k.catalogId(),
+ polarisEntity.getId(),
polarisEntity.getType(),
- k.isAllowedListAction(),
- k.getAllowedReadLocations(),
- k.getAllowedWriteLocations());
+ k.allowedListAction(),
+ k.allowedReadLocations(),
+ k.allowedWriteLocations());
if (scopedCredentialsResult.isSuccess()) {
long maxCacheDurationMs =
maxCacheDurationMs(callCtx.getRealmConfig());
return new StorageCredentialCacheEntry(scopedCredentialsResult,
maxCacheDurationMs);
diff --git
a/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheKey.java
b/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheKey.java
index 26c2115d9..79eba7d1d 100644
---
a/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheKey.java
+++
b/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheKey.java
@@ -18,118 +18,51 @@
*/
package org.apache.polaris.core.storage.cache;
-import java.util.Objects;
+import jakarta.annotation.Nullable;
import java.util.Set;
import org.apache.polaris.core.entity.PolarisEntity;
import org.apache.polaris.core.entity.PolarisEntityConstants;
+import org.apache.polaris.immutables.PolarisImmutable;
+import org.immutables.value.Value;
-public class StorageCredentialCacheKey {
+@PolarisImmutable
+public interface StorageCredentialCacheKey {
- private final String realmId;
- private final long catalogId;
+ @Value.Parameter(order = 1)
+ String realmId();
- /** The serialized string of the storage config. */
- private final String storageConfigSerializedStr;
+ @Value.Parameter(order = 2)
+ long catalogId();
- /**
- * The entity id is passed to be used to fetch subscoped creds, but is not
used to do hash/equals
- * as part of the cache key.
- */
- private final long entityId;
+ @Value.Parameter(order = 3)
+ @Nullable
+ String storageConfigSerializedStr();
- private final boolean allowedListAction;
- private final Set<String> allowedReadLocations;
+ @Value.Parameter(order = 4)
+ boolean allowedListAction();
- private final Set<String> allowedWriteLocations;
+ @Value.Parameter(order = 5)
+ Set<String> allowedReadLocations();
- public StorageCredentialCacheKey(
+ @Value.Parameter(order = 6)
+ Set<String> allowedWriteLocations();
+
+ static StorageCredentialCacheKey of(
String realmId,
PolarisEntity entity,
boolean allowedListAction,
Set<String> allowedReadLocations,
Set<String> allowedWriteLocations) {
- this.realmId = realmId;
- this.catalogId = entity.getCatalogId();
- this.storageConfigSerializedStr =
+ String storageConfigSerializedStr =
entity
.getInternalPropertiesAsMap()
.get(PolarisEntityConstants.getStorageConfigInfoPropertyName());
- this.entityId = entity.getId();
- this.allowedListAction = allowedListAction;
- this.allowedReadLocations = allowedReadLocations;
- this.allowedWriteLocations = allowedWriteLocations;
- }
-
- public String getRealmId() {
- return realmId;
- }
-
- public long getCatalogId() {
- return catalogId;
- }
-
- public String getStorageConfigSerializedStr() {
- return storageConfigSerializedStr;
- }
-
- public long getEntityId() {
- return entityId;
- }
-
- public boolean isAllowedListAction() {
- return allowedListAction;
- }
-
- public Set<String> getAllowedReadLocations() {
- return allowedReadLocations;
- }
-
- public Set<String> getAllowedWriteLocations() {
- return allowedWriteLocations;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- StorageCredentialCacheKey cacheKey = (StorageCredentialCacheKey) o;
- return Objects.equals(realmId, cacheKey.getRealmId())
- && catalogId == cacheKey.getCatalogId()
- && Objects.equals(storageConfigSerializedStr,
cacheKey.getStorageConfigSerializedStr())
- && allowedListAction == cacheKey.allowedListAction
- && Objects.equals(allowedReadLocations, cacheKey.allowedReadLocations)
- && Objects.equals(allowedWriteLocations,
cacheKey.allowedWriteLocations);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(
+ return ImmutableStorageCredentialCacheKey.of(
realmId,
- catalogId,
+ entity.getCatalogId(),
storageConfigSerializedStr,
allowedListAction,
allowedReadLocations,
allowedWriteLocations);
}
-
- @Override
- public String toString() {
- return "StorageCredentialCacheKey{"
- + "realmId="
- + realmId
- + ", catalogId="
- + catalogId
- + ", storageConfigSerializedStr='"
- + storageConfigSerializedStr
- + '\''
- + ", entityId="
- + entityId
- + ", allowedListAction="
- + allowedListAction
- + ", allowedReadLocations="
- + allowedReadLocations
- + ", allowedWriteLocations="
- + allowedWriteLocations
- + '}';
- }
}
diff --git
a/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java
b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java
index 1460b71cf..bf1cf1fcf 100644
---
a/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java
+++
b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java
@@ -176,7 +176,7 @@ public class StorageCredentialCacheTest {
1, 2, PolarisEntityType.CATALOG,
PolarisEntitySubType.ICEBERG_TABLE, 0, "name");
PolarisEntity polarisEntity = new PolarisEntity(baseEntity);
StorageCredentialCacheKey cacheKey =
- new StorageCredentialCacheKey(
+ StorageCredentialCacheKey.of(
callCtx.getRealmContext().getRealmIdentifier(),
polarisEntity,
true,