Skip to content

Commit 7d31ba5

Browse files
authored
NoSQL: realm-management minor fixes (#69)
* always set the `updated` `Instant` of a realm (do not rely on the caller doing this) * fix issue that transition from `INACTIVE` to `ACTIVE` _is_ intended and definitely allowed * let `PersistenceMetaStoreManagerFactory#bootstrapRealm` handle the `CREATED` state as well for bootstrapping a realm
1 parent e00f6db commit 7d31ba5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

extension/persistence/nosql/persistence/metastore/src/main/java/org/apache/polaris/persistence/nosql/metastore/PersistenceMetaStoreManagerFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ private PrincipalSecretsResult bootstrapRealm(
290290
return desc;
291291
});
292292

293+
if (realmDesc.status() == RealmDefinition.RealmStatus.CREATED) {
294+
realmDesc =
295+
realmManagement.update(
296+
realmDesc,
297+
RealmDefinition.builder()
298+
.from(realmDesc)
299+
.status(RealmDefinition.RealmStatus.INITIALIZING)
300+
.build());
301+
}
302+
293303
checkState(
294304
realmDesc.status() == RealmDefinition.RealmStatus.INITIALIZING,
295305
"Unexpected status '%s' for realm '%s'",

extension/persistence/nosql/realms/impl/src/main/java/org/apache/polaris/realms/impl/RealmManagementImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class RealmManagementImpl implements RealmManagement {
4646
private final RealmStore store;
4747
private final Supplier<Instant> clock;
4848

49+
@SuppressWarnings("CdiInjectionPointsInspection")
4950
@Inject
5051
RealmManagementImpl(RealmStore store, MonotonicClock clock) {
5152
this(store, clock::currentInstant);
@@ -122,7 +123,9 @@ private void verifyStateTransition(RealmDefinition expected, RealmDefinition upd
122123
update.status());
123124
case INACTIVE ->
124125
checkArgument(
125-
update.status() == INACTIVE || update.status() == PURGING,
126+
update.status() == ACTIVE
127+
|| update.status() == INACTIVE
128+
|| update.status() == PURGING,
126129
"Invalid realm state transition from %s to %s",
127130
expected.status(),
128131
update.status());
@@ -160,7 +163,8 @@ public RealmDefinition update(
160163
throw new RealmExpectedStateMismatchException(
161164
"Realm does not match the expected state");
162165
}
163-
return update;
166+
var now = clock.get();
167+
return ImmutableRealmDefinition.builder().from(update).updated(now).build();
164168
});
165169
}
166170

0 commit comments

Comments
 (0)