Skip to content

Commit 39eac51

Browse files
committed
convert StorageCredentialCacheKey to immutables
1 parent fabd523 commit 39eac51

File tree

3 files changed

+29
-89
lines changed

3 files changed

+29
-89
lines changed

polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public AccessConfig getOrGenerateSubScopeCreds(
119119
.fail("entity_type_not_suppported_to_scope_creds", "type={}", polarisEntity.getType());
120120
}
121121
StorageCredentialCacheKey key =
122-
new StorageCredentialCacheKey(
122+
StorageCredentialCacheKey.of(
123123
callCtx.getRealmContext().getRealmIdentifier(),
124124
polarisEntity,
125125
allowListOperation,
@@ -132,12 +132,12 @@ public AccessConfig getOrGenerateSubScopeCreds(
132132
ScopedCredentialsResult scopedCredentialsResult =
133133
credentialVendor.getSubscopedCredsForEntity(
134134
callCtx,
135-
k.getCatalogId(),
135+
k.catalogId(),
136136
polarisEntity.getId(),
137137
polarisEntity.getType(),
138-
k.isAllowedListAction(),
139-
k.getAllowedReadLocations(),
140-
k.getAllowedWriteLocations());
138+
k.allowedListAction(),
139+
k.allowedReadLocations(),
140+
k.allowedWriteLocations());
141141
if (scopedCredentialsResult.isSuccess()) {
142142
long maxCacheDurationMs = maxCacheDurationMs(callCtx.getRealmContext());
143143
return new StorageCredentialCacheEntry(scopedCredentialsResult, maxCacheDurationMs);

polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheKey.java

Lines changed: 23 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -18,105 +18,45 @@
1818
*/
1919
package org.apache.polaris.core.storage.cache;
2020

21-
import java.util.Objects;
21+
import jakarta.annotation.Nullable;
2222
import java.util.Set;
2323
import org.apache.polaris.core.entity.PolarisEntity;
2424
import org.apache.polaris.core.entity.PolarisEntityConstants;
25+
import org.apache.polaris.immutables.PolarisImmutable;
2526

26-
public final class StorageCredentialCacheKey {
27+
@PolarisImmutable
28+
public interface StorageCredentialCacheKey {
2729

28-
private final String realmId;
29-
private final long catalogId;
30+
String realmId();
3031

31-
/** The serialized string of the storage config. */
32-
private final String storageConfigSerializedStr;
32+
long catalogId();
3333

34-
private final boolean allowedListAction;
35-
private final Set<String> allowedReadLocations;
34+
@Nullable
35+
String storageConfigSerializedStr();
3636

37-
private final Set<String> allowedWriteLocations;
37+
boolean allowedListAction();
3838

39-
public StorageCredentialCacheKey(
39+
Set<String> allowedReadLocations();
40+
41+
Set<String> allowedWriteLocations();
42+
43+
static StorageCredentialCacheKey of(
4044
String realmId,
4145
PolarisEntity entity,
4246
boolean allowedListAction,
4347
Set<String> allowedReadLocations,
4448
Set<String> allowedWriteLocations) {
45-
this.realmId = realmId;
46-
this.catalogId = entity.getCatalogId();
47-
this.storageConfigSerializedStr =
49+
String storageConfigSerializedStr =
4850
entity
4951
.getInternalPropertiesAsMap()
5052
.get(PolarisEntityConstants.getStorageConfigInfoPropertyName());
51-
this.allowedListAction = allowedListAction;
52-
this.allowedReadLocations = allowedReadLocations;
53-
this.allowedWriteLocations = allowedWriteLocations;
54-
}
55-
56-
public String getRealmId() {
57-
return realmId;
58-
}
59-
60-
public long getCatalogId() {
61-
return catalogId;
62-
}
63-
64-
public String getStorageConfigSerializedStr() {
65-
return storageConfigSerializedStr;
66-
}
67-
68-
public boolean isAllowedListAction() {
69-
return allowedListAction;
70-
}
71-
72-
public Set<String> getAllowedReadLocations() {
73-
return allowedReadLocations;
74-
}
75-
76-
public Set<String> getAllowedWriteLocations() {
77-
return allowedWriteLocations;
78-
}
79-
80-
@Override
81-
public boolean equals(Object o) {
82-
if (this == o) return true;
83-
if (o == null || getClass() != o.getClass()) return false;
84-
StorageCredentialCacheKey cacheKey = (StorageCredentialCacheKey) o;
85-
return Objects.equals(realmId, cacheKey.getRealmId())
86-
&& catalogId == cacheKey.getCatalogId()
87-
&& Objects.equals(storageConfigSerializedStr, cacheKey.getStorageConfigSerializedStr())
88-
&& allowedListAction == cacheKey.allowedListAction
89-
&& Objects.equals(allowedReadLocations, cacheKey.allowedReadLocations)
90-
&& Objects.equals(allowedWriteLocations, cacheKey.allowedWriteLocations);
91-
}
92-
93-
@Override
94-
public int hashCode() {
95-
return Objects.hash(
96-
realmId,
97-
catalogId,
98-
storageConfigSerializedStr,
99-
allowedListAction,
100-
allowedReadLocations,
101-
allowedWriteLocations);
102-
}
103-
104-
@Override
105-
public String toString() {
106-
return "StorageCredentialCacheKey{"
107-
+ "realmId="
108-
+ realmId
109-
+ ", catalogId="
110-
+ catalogId
111-
+ ", storageConfigSerializedStr='"
112-
+ storageConfigSerializedStr
113-
+ '\''
114-
+ ", allowedListAction="
115-
+ allowedListAction
116-
+ ", allowedReadLocations="
117-
+ allowedReadLocations
118-
+ ", allowedWriteLocations="
119-
+ allowedWriteLocations
120-
+ '}';
53+
return ImmutableStorageCredentialCacheKey.builder()
54+
.realmId(realmId)
55+
.catalogId(entity.getCatalogId())
56+
.storageConfigSerializedStr(storageConfigSerializedStr)
57+
.allowedListAction(allowedListAction)
58+
.allowedReadLocations(allowedReadLocations)
59+
.allowedWriteLocations(allowedWriteLocations)
60+
.build();
12161
}
12262
}

polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void testCacheEvict() throws InterruptedException {
177177
1, 2, PolarisEntityType.CATALOG, PolarisEntitySubType.ICEBERG_TABLE, 0, "name");
178178
PolarisEntity polarisEntity = new PolarisEntity(baseEntity);
179179
StorageCredentialCacheKey cacheKey =
180-
new StorageCredentialCacheKey(
180+
StorageCredentialCacheKey.of(
181181
callCtx.getRealmContext().getRealmIdentifier(),
182182
polarisEntity,
183183
true,

0 commit comments

Comments
 (0)