Skip to content

Commit

Permalink
Resolved the issue where the custom database prefix was lost after th…
Browse files Browse the repository at this point in the history
…e primary cluster created the database.
  • Loading branch information
jellyliao committed Feb 10, 2025
1 parent bb3861f commit f3d9228
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ public AbstractMetaStore(
this.writableDatabaseWhitelist = writableDatabaseWhitelist;
}

public AbstractMetaStore(
String name,
String remoteMetaStoreUris,
String databasePrefix,
AccessControlType accessControlType,
List<String> writableDatabaseWhitelist) {
this.name = name;
this.remoteMetaStoreUris = remoteMetaStoreUris;
this.databasePrefix = databasePrefix;
this.accessControlType = accessControlType;
this.writableDatabaseWhitelist = writableDatabaseWhitelist;
}


public static FederatedMetaStore newFederatedInstance(String name, String remoteMetaStoreUris) {
return new FederatedMetaStore(name, remoteMetaStoreUris);
}
Expand All @@ -95,6 +109,14 @@ public static PrimaryMetaStore newPrimaryInstance(String name, String remoteMeta
return new PrimaryMetaStore(name, remoteMetaStoreUris, AccessControlType.READ_ONLY);
}

public static PrimaryMetaStore newPrimaryInstance(
String name,
String remoteMetaStoreUris,
String databasePrefix,
AccessControlType accessControlType) {
return new PrimaryMetaStore(name, remoteMetaStoreUris, databasePrefix, accessControlType);
}

public String getDatabasePrefix() {
return databasePrefix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ public PrimaryMetaStore(
super(name, remoteMetaStoreUris, accessControlType, writableDatabaseWhitelist);
}

public PrimaryMetaStore(
String name,
String remoteMetaStoreUris,
String databasePrefix,
AccessControlType accessControlType,
String... writableDatabaseWhitelist) {
this(name, remoteMetaStoreUris, databasePrefix, accessControlType, Arrays.asList(writableDatabaseWhitelist));
}

public PrimaryMetaStore(
String name,
String remoteMetaStoreUris,
String databasePrefix,
AccessControlType accessControlType,
List<String> writableDatabaseWhitelist) {
super(name, remoteMetaStoreUris, databasePrefix, accessControlType, writableDatabaseWhitelist);
}

@Override
public FederationType getFederationType() {
return FederationType.PRIMARY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ public void newPrimaryInstanceWithDefaultAccessControlType() {
assertThat(primaryMetaStore.getAccessControlType(), is(AccessControlType.READ_ONLY));
}

@Test
public void newPrimaryPrefixInstance() {
AccessControlType access = AccessControlType.READ_AND_WRITE_AND_CREATE;
String databasePrefix = "primary";
PrimaryMetaStore primaryMetaStore = AbstractMetaStore.newPrimaryInstance(name, remoteMetaStoreUri, databasePrefix, access);
assertThat(primaryMetaStore.getName(), is(name));
assertThat(primaryMetaStore.getRemoteMetaStoreUris(), is(remoteMetaStoreUri));
assertThat(primaryMetaStore.getDatabasePrefix(), is(databasePrefix));
assertThat(primaryMetaStore.getAccessControlType(), is(access));
}


@Test
public void mappedDatabases() {
List<String> mappedDatabases = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class PrimaryMetaStoreTest extends AbstractMetaStoreTest<PrimaryMetaStore
private final String remoteMetaStoreUris = "remoteMetaStoreUris";
private final List<String> whitelist = new ArrayList<>();
private final AccessControlType accessControlType = AccessControlType.READ_AND_WRITE_ON_DATABASE_WHITELIST;
private final String databasePrefix = "primary";

public PrimaryMetaStoreTest() {
super(new PrimaryMetaStore());
Expand Down Expand Up @@ -120,4 +121,29 @@ public void constructorWithArrayListForWhitelist() {
assertThat(store.getWritableDatabaseWhiteList(), is(whitelist));
}

@Test
public void nonEmptyPrefixConstructor() {
whitelist.add("databaseOne");
whitelist.add("databaseTwo");
PrimaryMetaStore store = new PrimaryMetaStore(name, remoteMetaStoreUris, databasePrefix, accessControlType, whitelist.get(0),
whitelist.get(1));
assertThat(store.getName(), is(name));
assertThat(store.getRemoteMetaStoreUris(), is(remoteMetaStoreUris));
assertThat(store.getDatabasePrefix(), is(databasePrefix));
assertThat(store.getAccessControlType(), is(accessControlType));
assertThat(store.getWritableDatabaseWhiteList(), is(whitelist));
}

@Test
public void constructorWithPrefixArrayListForWhitelist() {
whitelist.add("databaseOne");
whitelist.add("databaseTwo");
PrimaryMetaStore store = new PrimaryMetaStore(name, remoteMetaStoreUris, databasePrefix, accessControlType, whitelist);
assertThat(store.getName(), is(name));
assertThat(store.getRemoteMetaStoreUris(), is(remoteMetaStoreUris));
assertThat(store.getDatabasePrefix(), is(databasePrefix));
assertThat(store.getAccessControlType(), is(accessControlType));
assertThat(store.getWritableDatabaseWhiteList(), is(whitelist));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void databaseCreatedNotification(String name) {
AbstractMetaStore newMetaStore;
if (metaStore instanceof PrimaryMetaStore) {
newMetaStore = new PrimaryMetaStore(metaStore.getName(), metaStore.getRemoteMetaStoreUris(),
metaStore.getAccessControlType(), newWritableDatabaseWhiteList);
metaStore.getDatabasePrefix(), metaStore.getAccessControlType(), newWritableDatabaseWhiteList);
newMetaStore.setMappedDatabases(mappedDatabases);
} else {
throw new WaggleDanceException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void databaseCreatedNotification(String name) {
AbstractMetaStore newMetaStore;
if (metaStore instanceof PrimaryMetaStore) {
newMetaStore = new PrimaryMetaStore(metaStore.getName(), metaStore.getRemoteMetaStoreUris(),
metaStore.getAccessControlType());
metaStore.getDatabasePrefix(), metaStore.getAccessControlType());
newMetaStore.setMappedDatabases(mappedDatabases);
} else {
throw new WaggleDanceException(
Expand Down

0 comments on commit f3d9228

Please sign in to comment.