Skip to content

Commit 7cc768f

Browse files
Backport to branch(3.15) : Fix for admin.getNamespaceNames() when used with DynamoDB with the namespace prefix setting (#2658)
Co-authored-by: Vincent Guilpain <[email protected]>
1 parent c7579d2 commit 7cc768f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,9 @@ private Set<String> getNamespacesOfExistingTables() throws ExecutionException {
12781278

12791279
for (Map<String, AttributeValue> tableMetadata : scanResponse.items()) {
12801280
String fullTableName = tableMetadata.get(METADATA_ATTR_TABLE).s();
1281-
String namespaceName = fullTableName.substring(0, fullTableName.indexOf('.'));
1282-
nonPrefixedNamespaceNames.add(namespaceName);
1281+
String prefixedNamespaceName = fullTableName.substring(0, fullTableName.indexOf('.'));
1282+
String nonPrefixedNamespaceName = prefixedNamespaceName.substring(namespacePrefix.length());
1283+
nonPrefixedNamespaceNames.add(nonPrefixedNamespaceName);
12831284
}
12841285
} while (!lastEvaluatedKey.isEmpty());
12851286

core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,20 +1243,23 @@ public void getNamespaceNames_WithExistingTables_ShouldWorkProperly() throws Exe
12431243
when(scanResponse.lastEvaluatedKey())
12441244
.thenReturn(lastEvaluatedKeyFirstIteration)
12451245
.thenReturn(lastEvaluatedKeySecondIteration);
1246+
String ns1 = getNamespacePrefixConfig().orElse("") + "ns1";
1247+
String ns2 = getNamespacePrefixConfig().orElse("") + "ns2";
1248+
when(scanResponse.count()).thenReturn(2);
12461249
when(scanResponse.items())
12471250
.thenReturn(
12481251
ImmutableList.of(
12491252
ImmutableMap.of(
12501253
DynamoAdmin.METADATA_ATTR_TABLE,
1251-
AttributeValue.builder().s("ns1.tbl1").build())))
1254+
AttributeValue.builder().s(ns1 + ".tbl1").build())))
12521255
.thenReturn(
12531256
ImmutableList.of(
12541257
ImmutableMap.of(
12551258
DynamoAdmin.METADATA_ATTR_TABLE,
1256-
AttributeValue.builder().s("ns1.tbl2").build()),
1259+
AttributeValue.builder().s(ns1 + ".tbl2").build()),
12571260
ImmutableMap.of(
12581261
DynamoAdmin.METADATA_ATTR_TABLE,
1259-
AttributeValue.builder().s("ns2.tbl3").build())));
1262+
AttributeValue.builder().s(ns2 + ".tbl3").build())));
12601263

12611264
// Act
12621265
Set<String> actual = admin.getNamespaceNames();

0 commit comments

Comments
 (0)