Skip to content

Commit c8f6bda

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

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
@@ -1261,8 +1261,9 @@ private Set<String> getNamespacesOfExistingTables() throws ExecutionException {
12611261

12621262
for (Map<String, AttributeValue> tableMetadata : scanResponse.items()) {
12631263
String fullTableName = tableMetadata.get(METADATA_ATTR_TABLE).s();
1264-
String namespaceName = fullTableName.substring(0, fullTableName.indexOf('.'));
1265-
nonPrefixedNamespaceNames.add(namespaceName);
1264+
String prefixedNamespaceName = fullTableName.substring(0, fullTableName.indexOf('.'));
1265+
String nonPrefixedNamespaceName = prefixedNamespaceName.substring(namespacePrefix.length());
1266+
nonPrefixedNamespaceNames.add(nonPrefixedNamespaceName);
12661267
}
12671268
} while (!lastEvaluatedKey.isEmpty());
12681269

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
@@ -1222,20 +1222,23 @@ public void getNamespaceNames_WithExistingTables_ShouldWorkProperly() throws Exe
12221222
when(scanResponse.lastEvaluatedKey())
12231223
.thenReturn(lastEvaluatedKeyFirstIteration)
12241224
.thenReturn(lastEvaluatedKeySecondIteration);
1225+
String ns1 = getNamespacePrefixConfig().orElse("") + "ns1";
1226+
String ns2 = getNamespacePrefixConfig().orElse("") + "ns2";
1227+
when(scanResponse.count()).thenReturn(2);
12251228
when(scanResponse.items())
12261229
.thenReturn(
12271230
ImmutableList.of(
12281231
ImmutableMap.of(
12291232
DynamoAdmin.METADATA_ATTR_TABLE,
1230-
AttributeValue.builder().s("ns1.tbl1").build())))
1233+
AttributeValue.builder().s(ns1 + ".tbl1").build())))
12311234
.thenReturn(
12321235
ImmutableList.of(
12331236
ImmutableMap.of(
12341237
DynamoAdmin.METADATA_ATTR_TABLE,
1235-
AttributeValue.builder().s("ns1.tbl2").build()),
1238+
AttributeValue.builder().s(ns1 + ".tbl2").build()),
12361239
ImmutableMap.of(
12371240
DynamoAdmin.METADATA_ATTR_TABLE,
1238-
AttributeValue.builder().s("ns2.tbl3").build())));
1241+
AttributeValue.builder().s(ns2 + ".tbl3").build())));
12391242

12401243
// Act
12411244
Set<String> actual = admin.getNamespaceNames();

0 commit comments

Comments
 (0)