Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Namespaces management #989

Merged
merged 31 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
891a9db
Add method to retrieve the namespace names for the Jdbc Admin (#674)
Torch3333 Sep 1, 2022
2bdb499
Add method to retrieve the namespace names for Cosmos Admin (#678)
Torch3333 Sep 8, 2022
ba3a94d
Add method to retrieve the namespace names for the Dynamo Admin (#679)
Torch3333 Sep 8, 2022
67bd54f
Add method to retrieve the namespace names for Cassandra Admin (#687)
Torch3333 Sep 8, 2022
0518eb6
Update JdbcAdmin.namespaceExists() (#693)
Torch3333 Sep 13, 2022
674165c
Merge branch 'master' of github.com:scalar-labs/scalardb into feat/na…
Sep 15, 2022
3e86d4e
Add upgrade method to jdbc admin (#696)
Torch3333 Sep 16, 2022
0a6f8b6
Merge branch 'master' of github.com:scalar-labs/scalardb into feat/na…
Sep 22, 2022
a999048
Implement `CosmosAdmin.upgrade()` (#707)
Torch3333 Sep 26, 2022
0cdb491
Implement `DynamoAdmin.upgrade()` (#708)
Torch3333 Sep 26, 2022
32bc263
Add upgrade() method to the Cassandra Admin (#709)
Torch3333 Sep 26, 2022
f4e8bfe
Merge branch 'master' of github.com:scalar-labs/scalardb into feat/na…
Nov 1, 2022
9fce068
Make ConsensusCommitAdmin.getNamespaceNames() to not return the coord…
Torch3333 Nov 5, 2022
9e58068
Add upgrade command to schema loader (#736)
Torch3333 Nov 9, 2022
44f7c4a
Merge branch 'master' of github.com:scalar-labs/scalardb into feat/na…
May 12, 2023
4ebfe75
Fix tests
May 12, 2023
e914462
Merge branch 'master' of github.com:scalar-labs/scalardb into feat/na…
Jul 27, 2023
a1fecd1
Increase wait time to fix Cassandra integration test
Jul 27, 2023
531a472
Throws UnsupportedOperationException when admin.getNamespaceNames() a…
Jul 27, 2023
2197649
Fix import table integration test
Torch3333 Aug 1, 2023
6a6d3ff
Merge remote-tracking branch 'origin/do_not_support_upgrade_and_getNa…
Torch3333 Aug 2, 2023
e8a0e0f
Support sqlite
Torch3333 Aug 2, 2023
d382b29
Fix [-skip ci]
Torch3333 Aug 4, 2023
c2c5684
Fix
Torch3333 Aug 7, 2023
2468962
Fix typo in doc [skip ci]
Torch3333 Aug 7, 2023
fc2def1
Fix komamitsu comments
Torch3333 Aug 14, 2023
7e670ed
Fix brfrn169 comments
Torch3333 Aug 14, 2023
dd4e280
Merge branch 'master' of github.com:scalar-labs/scalardb into namespa…
Torch3333 Aug 14, 2023
38bd49d
Fix variable name
Torch3333 Aug 16, 2023
2d6ed87
Add @Immutable annotation to the CosmosNamespace marshalling object
Torch3333 Aug 16, 2023
6ca1144
Merge branch 'master' into namespaces_management
brfrn169 Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Throws UnsupportedOperationException when admin.getNamespaceNames() a…
…nd admin.upgrade() is executed on ScalarDB server
  • Loading branch information
Vincent Guilpain committed Jul 28, 2023
commit 531a472fdf7c8807d9e8a5b20bccc98abdefbd6e
18 changes: 4 additions & 14 deletions core/src/main/java/com/scalar/db/storage/rpc/GrpcAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import com.scalar.db.rpc.DropIndexRequest;
import com.scalar.db.rpc.DropNamespaceRequest;
import com.scalar.db.rpc.DropTableRequest;
import com.scalar.db.rpc.GetNamespaceNamesRequest;
import com.scalar.db.rpc.GetNamespaceNamesResponse;
import com.scalar.db.rpc.GetNamespaceTableNamesRequest;
import com.scalar.db.rpc.GetNamespaceTableNamesResponse;
import com.scalar.db.rpc.GetTableMetadataRequest;
Expand All @@ -25,7 +23,6 @@
import com.scalar.db.rpc.NamespaceExistsResponse;
import com.scalar.db.rpc.RepairTableRequest;
import com.scalar.db.rpc.TruncateTableRequest;
import com.scalar.db.rpc.UpgradeRequest;
import com.scalar.db.util.ProtoUtils;
import com.scalar.db.util.ThrowableSupplier;
import io.grpc.ManagedChannel;
Expand Down Expand Up @@ -325,21 +322,14 @@ public void addNewColumnToTable(

@Override
public Set<String> getNamespaceNames() throws ExecutionException {
return execute(
() -> {
GetNamespaceNamesResponse response =
stub.withDeadlineAfter(config.getDeadlineDurationMillis(), TimeUnit.MILLISECONDS)
.getNamespaceNames(GetNamespaceNamesRequest.newBuilder().build());
return new HashSet<>(response.getNamespaceNamesList());
});
throw new UnsupportedOperationException(
"retrieving the namespace names is not supported in ScalarDB Server");
}

@Override
public void upgrade(Map<String, String> options) throws ExecutionException {
execute(
() ->
stub.withDeadlineAfter(config.getDeadlineDurationMillis(), TimeUnit.MILLISECONDS)
.upgrade(UpgradeRequest.newBuilder().putAllOptions(options).build()));
throw new UnsupportedOperationException(
"upgrading the ScalarDB environment is not supported in ScalarDB Server");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import com.scalar.db.rpc.DropIndexRequest;
import com.scalar.db.rpc.DropNamespaceRequest;
import com.scalar.db.rpc.DropTableRequest;
import com.scalar.db.rpc.GetNamespaceNamesRequest;
import com.scalar.db.rpc.GetNamespaceNamesResponse;
import com.scalar.db.rpc.GetNamespaceTableNamesRequest;
import com.scalar.db.rpc.GetNamespaceTableNamesResponse;
import com.scalar.db.rpc.GetTableMetadataRequest;
Expand All @@ -31,7 +29,6 @@
import com.scalar.db.rpc.RepairTableRequest;
import com.scalar.db.rpc.TruncateCoordinatorTablesRequest;
import com.scalar.db.rpc.TruncateTableRequest;
import com.scalar.db.rpc.UpgradeRequest;
import com.scalar.db.storage.rpc.GrpcAdmin;
import com.scalar.db.storage.rpc.GrpcConfig;
import com.scalar.db.storage.rpc.GrpcUtils;
Expand Down Expand Up @@ -405,21 +402,14 @@ public void importTable(String namespace, String table) {

@Override
public Set<String> getNamespaceNames() throws ExecutionException {
return execute(
() -> {
GetNamespaceNamesResponse response =
stub.withDeadlineAfter(config.getDeadlineDurationMillis(), TimeUnit.MILLISECONDS)
.getNamespaceNames(GetNamespaceNamesRequest.newBuilder().build());
return new HashSet<>(response.getNamespaceNamesList());
});
throw new UnsupportedOperationException(
"retrieving the namespace names is not supported in ScalarDB Server");
}

@Override
public void upgrade(Map<String, String> options) throws ExecutionException {
execute(
() ->
stub.withDeadlineAfter(config.getDeadlineDurationMillis(), TimeUnit.MILLISECONDS)
.upgrade(UpgradeRequest.newBuilder().putAllOptions(options).build()));
throw new UnsupportedOperationException(
"upgrading the ScalarDB environment is not supported in ScalarDB Server");
}

private static <T> T execute(ThrowableSupplier<T, ExecutionException> supplier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.description;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -3031,15 +3029,6 @@ public void importTable_ForSQLite_ShouldThrowUnsupportedOperationException() {
assertThat(thrown).isInstanceOf(UnsupportedOperationException.class);
}

private PreparedStatement prepareStatementForNamespaceCheck(boolean exists) throws SQLException {
PreparedStatement statement = mock(PreparedStatement.class);
ResultSet results = mock(ResultSet.class);
doNothing().when(statement).setString(anyInt(), anyString());
when(statement.executeQuery()).thenReturn(results);
when(results.next()).thenReturn(exists);
return statement;
}

private String prepareSqlForMetadataTableCheck(RdbEngine rdbEngine) {
return prepareSqlForTableCheck(rdbEngine, metadataSchemaName, "metadata");
}
Expand Down
38 changes: 4 additions & 34 deletions core/src/test/java/com/scalar/db/storage/rpc/GrpcAdminTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.scalar.db.rpc.DropIndexRequest;
import com.scalar.db.rpc.DropNamespaceRequest;
import com.scalar.db.rpc.DropTableRequest;
import com.scalar.db.rpc.GetNamespaceNamesRequest;
import com.scalar.db.rpc.GetNamespaceNamesResponse;
import com.scalar.db.rpc.GetNamespaceTableNamesRequest;
import com.scalar.db.rpc.GetNamespaceTableNamesResponse;
import com.scalar.db.rpc.GetTableMetadataRequest;
Expand All @@ -33,7 +31,6 @@
import com.scalar.db.rpc.NamespaceExistsResponse;
import com.scalar.db.rpc.RepairTableRequest;
import com.scalar.db.rpc.TruncateTableRequest;
import com.scalar.db.rpc.UpgradeRequest;
import com.scalar.db.util.ProtoUtils;
import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -336,37 +333,6 @@ public void addNewColumnToTable_CalledWithProperArguments_StubShouldBeCalledProp
.build());
}

@Test
public void getNamespaceNames_StubShouldBeCalledProperly() throws ExecutionException {
// Arrange

LazyStringArrayList namespaceNames = new LazyStringArrayList();
namespaceNames.add("n1");
namespaceNames.add("n2");
GetNamespaceNamesResponse response = mock(GetNamespaceNamesResponse.class);
when(response.getNamespaceNamesList()).thenReturn(namespaceNames);
when(stub.getNamespaceNames(any())).thenReturn(response);

// Act
Set<String> actualNamespaces = admin.getNamespaceNames();

// Assert
verify(stub).getNamespaceNames(GetNamespaceNamesRequest.newBuilder().build());
assertThat(actualNamespaces).containsOnly("n1", "n2");
}

@Test
public void upgrade_StubShouldBeCalledProperly() throws ExecutionException {
// Arrange
Map<String, String> options = ImmutableMap.of("foo", "bar");

// Act
admin.upgrade(options);

// Assert
verify(stub).upgrade(UpgradeRequest.newBuilder().putAllOptions(options).build());
}

@Test
public void unsupportedOperations_ShouldThrowUnsupportedException() {
// Arrange
Expand All @@ -379,10 +345,14 @@ public void unsupportedOperations_ShouldThrowUnsupportedException() {
Throwable thrown2 =
catchThrowable(() -> admin.addRawColumnToTable(namespace, table, column, DataType.INT));
Throwable thrown3 = catchThrowable(() -> admin.importTable(namespace, table));
Throwable thrown4 = catchThrowable(() -> admin.upgrade(Collections.emptyMap()));
Throwable thrown5 = catchThrowable(() -> admin.getNamespaceNames());

// Assert
assertThat(thrown1).isInstanceOf(UnsupportedOperationException.class);
assertThat(thrown2).isInstanceOf(UnsupportedOperationException.class);
assertThat(thrown3).isInstanceOf(UnsupportedOperationException.class);
assertThat(thrown4).isInstanceOf(UnsupportedOperationException.class);
assertThat(thrown5).isInstanceOf(UnsupportedOperationException.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.scalar.db.transaction.rpc;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.mock;
Expand All @@ -26,8 +27,6 @@
import com.scalar.db.rpc.DropIndexRequest;
import com.scalar.db.rpc.DropNamespaceRequest;
import com.scalar.db.rpc.DropTableRequest;
import com.scalar.db.rpc.GetNamespaceNamesRequest;
import com.scalar.db.rpc.GetNamespaceNamesResponse;
import com.scalar.db.rpc.GetNamespaceTableNamesRequest;
import com.scalar.db.rpc.GetNamespaceTableNamesResponse;
import com.scalar.db.rpc.GetTableMetadataRequest;
Expand All @@ -38,7 +37,6 @@
import com.scalar.db.rpc.RepairTableRequest;
import com.scalar.db.rpc.TruncateCoordinatorTablesRequest;
import com.scalar.db.rpc.TruncateTableRequest;
import com.scalar.db.rpc.UpgradeRequest;
import com.scalar.db.storage.rpc.GrpcConfig;
import com.scalar.db.util.ProtoUtils;
import java.util.Collections;
Expand Down Expand Up @@ -416,32 +414,17 @@ public void addNewColumnToTable_CalledWithProperArguments_StubShouldBeCalledProp
}

@Test
public void getNamespaceNames_StubShouldBeCalledProperly() throws ExecutionException {
public void unsupportedOperations_ShouldThrowUnsupportedException() {
// Arrange
LazyStringArrayList namespaceNames = new LazyStringArrayList();
namespaceNames.add("n1");
namespaceNames.add("n2");
GetNamespaceNamesResponse response = mock(GetNamespaceNamesResponse.class);
when(response.getNamespaceNamesList()).thenReturn(namespaceNames);
when(stub.getNamespaceNames(any())).thenReturn(response);

// Act
Set<String> actualNamespaces = admin.getNamespaceNames();

// Assert
verify(stub).getNamespaceNames(GetNamespaceNamesRequest.newBuilder().build());
assertThat(actualNamespaces).containsOnly("n1", "n2");
}

@Test
public void upgrade_StubShouldBeCalledProperly() throws ExecutionException {
// Arrange
Map<String, String> options = ImmutableMap.of("foo", "bar");

// Act
admin.upgrade(options);

// Assert
verify(stub).upgrade(UpgradeRequest.newBuilder().putAllOptions(options).build());
String namespace = "sample_ns";
String table = "tbl";

// Act Assert
assertThatThrownBy(() -> admin.importTable(namespace, table))
.isInstanceOf(UnsupportedOperationException.class);
assertThatThrownBy(() -> admin.upgrade(Collections.emptyMap()))
.isInstanceOf(UnsupportedOperationException.class);
assertThatThrownBy(() -> admin.getNamespaceNames())
.isInstanceOf(UnsupportedOperationException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ public void createNamespace_ForNonExistingNamespace_ShouldCreateNamespaceProperl

// Assert
assertThat(admin.namespaceExists(namespace3)).isTrue();
assertThat(admin.getNamespaceNames()).contains(namespace3);
} finally {
admin.dropNamespace(namespace3, true);
}
Expand Down Expand Up @@ -251,7 +250,6 @@ public void dropNamespace_ForNonExistingNamespace_ShouldDropNamespaceProperly()

// Assert
assertThat(admin.namespaceExists(namespace3)).isFalse();
assertThat(admin.getNamespaceNames()).doesNotContain(namespace3);
} finally {
admin.dropNamespace(namespace3, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public void createNamespace_ForNonExistingNamespace_ShouldCreateNamespaceProperl

// Assert
assertThat(admin.namespaceExists(namespace3)).isTrue();
assertThat(admin.getNamespaceNames()).contains(namespace3);
} finally {
admin.dropNamespace(namespace3, true);
}
Expand Down Expand Up @@ -255,7 +254,6 @@ public void dropNamespace_ForNonExistingNamespace_ShouldDropNamespaceProperly()

// Assert
assertThat(admin.namespaceExists(namespace3)).isFalse();
assertThat(admin.getNamespaceNames()).doesNotContain(namespace3);
} finally {
admin.dropNamespace(namespace3, true);
}
Expand Down
Loading