Search in sources :

Example 76 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class GrpcTwoPhaseCommitTransactionOnBidirectionalStream method scan.

public List<Result> scan(Scan scan) throws CrudException {
    throwIfTransactionFinished();
    ResponseOrError responseOrError = sendRequest(TwoPhaseCommitTransactionRequest.newBuilder().setScanRequest(ScanRequest.newBuilder().setScan(ProtoUtils.toScan(scan))).build());
    throwIfErrorForCrud(responseOrError);
    TableMetadata tableMetadata = getTableMetadata(scan);
    return responseOrError.getResponse().getScanResponse().getResultList().stream().map(r -> ProtoUtils.toResult(r, tableMetadata)).collect(Collectors.toList());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) ExecutionException(com.scalar.db.exception.storage.ExecutionException) StartRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest.StartRequest) CrudException(com.scalar.db.exception.transaction.CrudException) ValidateRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest.ValidateRequest) Result(com.scalar.db.api.Result) CommitRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest.CommitRequest) ClientResponseObserver(io.grpc.stub.ClientResponseObserver) RollbackException(com.scalar.db.exception.transaction.RollbackException) Mutation(com.scalar.db.api.Mutation) CommitException(com.scalar.db.exception.transaction.CommitException) CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) ServiceTemporaryUnavailableException(com.scalar.db.util.retry.ServiceTemporaryUnavailableException) ValidationConflictException(com.scalar.db.exception.transaction.ValidationConflictException) Operation(com.scalar.db.api.Operation) BlockingQueue(java.util.concurrent.BlockingQueue) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) JoinRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest.JoinRequest) PrepareRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest.PrepareRequest) List(java.util.List) UnknownTransactionStatusException(com.scalar.db.exception.transaction.UnknownTransactionStatusException) Optional(java.util.Optional) MutateRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest.MutateRequest) ValidationException(com.scalar.db.exception.transaction.ValidationException) ScanRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest.ScanRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CrudConflictException(com.scalar.db.exception.transaction.CrudConflictException) PreparationException(com.scalar.db.exception.transaction.PreparationException) TableMetadata(com.scalar.db.api.TableMetadata) TwoPhaseCommitTransactionRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest) ScalarDbUtils(com.scalar.db.util.ScalarDbUtils) Code(io.grpc.Status.Code) ErrorCode(com.scalar.db.rpc.TwoPhaseCommitTransactionResponse.Error.ErrorCode) GetRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest.GetRequest) Nullable(javax.annotation.Nullable) GetResponse(com.scalar.db.rpc.TwoPhaseCommitTransactionResponse.GetResponse) GrpcConfig(com.scalar.db.storage.rpc.GrpcConfig) TableMetadataManager(com.scalar.db.common.TableMetadataManager) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Get(com.scalar.db.api.Get) ProtoUtils(com.scalar.db.util.ProtoUtils) StatusRuntimeException(io.grpc.StatusRuntimeException) TimeUnit(java.util.concurrent.TimeUnit) TwoPhaseCommitTransactionResponse(com.scalar.db.rpc.TwoPhaseCommitTransactionResponse) Scan(com.scalar.db.api.Scan) PreparationConflictException(com.scalar.db.exception.transaction.PreparationConflictException) TransactionException(com.scalar.db.exception.transaction.TransactionException) RollbackRequest(com.scalar.db.rpc.TwoPhaseCommitTransactionRequest.RollbackRequest) TwoPhaseCommitTransactionGrpc(com.scalar.db.rpc.TwoPhaseCommitTransactionGrpc) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe)

Example 77 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class DistributedTransactionAdminServiceTest method getTableMetadata_IsCalledWithProperArguments_AdminShouldBeCalledProperly.

@Test
public void getTableMetadata_IsCalledWithProperArguments_AdminShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    GetTableMetadataRequest request = GetTableMetadataRequest.newBuilder().setNamespace("namespace").setTable("table").build();
    @SuppressWarnings("unchecked") StreamObserver<GetTableMetadataResponse> responseObserver = mock(StreamObserver.class);
    TableMetadata tableMetadata = TableMetadata.newBuilder().addColumn("col1", DataType.INT).addColumn("col2", DataType.INT).addColumn("col3", DataType.TEXT).addPartitionKey("col1").addClusteringKey("col2").build();
    when(admin.getTableMetadata("namespace", "table")).thenReturn(tableMetadata);
    // Act
    adminService.getTableMetadata(request, responseObserver);
    // Assert
    verify(admin).getTableMetadata(any(), any());
    verify(responseObserver).onNext(GetTableMetadataResponse.newBuilder().setTableMetadata(ProtoUtils.toTableMetadata(tableMetadata)).build());
    verify(responseObserver).onCompleted();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) GetTableMetadataResponse(com.scalar.db.rpc.GetTableMetadataResponse) GetTableMetadataRequest(com.scalar.db.rpc.GetTableMetadataRequest) Test(org.junit.jupiter.api.Test)

Example 78 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class DistributedStorageService method get.

@Override
public void get(GetRequest request, StreamObserver<GetResponse> responseObserver) {
    execute(() -> {
        TableMetadata metadata = tableMetadataManager.getTableMetadata(request.getGet().getNamespace(), request.getGet().getTable());
        if (metadata == null) {
            throw new IllegalArgumentException("the specified table is not found");
        }
        Get get = ProtoUtils.toGet(request.getGet(), metadata);
        Optional<Result> result = storage.get(get);
        GetResponse.Builder builder = GetResponse.newBuilder();
        result.ifPresent(r -> builder.setResult(ProtoUtils.toResult(r)));
        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }, responseObserver, "get");
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Get(com.scalar.db.api.Get) GetResponse(com.scalar.db.rpc.GetResponse) Result(com.scalar.db.api.Result)

Example 79 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class SchemaOperatorTest method createTables_WithTransactionalTables_ShouldCallProperMethods.

@Test
public void createTables_WithTransactionalTables_ShouldCallProperMethods() throws Exception {
    // Arrange
    List<TableSchema> tableSchemaList = Arrays.asList(tableSchema, tableSchema, tableSchema);
    when(tableSchema.getNamespace()).thenReturn("ns");
    when(tableSchema.getOptions()).thenReturn(options);
    when(tableSchema.isTransactionalTable()).thenReturn(true);
    when(tableSchema.getTable()).thenReturn("tb");
    TableMetadata tableMetadata = mock(TableMetadata.class);
    when(tableSchema.getTableMetadata()).thenReturn(tableMetadata);
    // Act
    operator.createTables(tableSchemaList);
    // Assert
    verify(admin, times(3)).createNamespace("ns", true, options);
    verify(admin, times(3)).tableExists("ns", "tb");
    verify(consensusCommitAdmin, times(3)).createTable("ns", "tb", tableMetadata, options);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 80 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class SchemaOperatorTest method createTables_WithNonTransactionalTables_ShouldCallProperMethods.

@Test
public void createTables_WithNonTransactionalTables_ShouldCallProperMethods() throws Exception {
    // Arrange
    List<TableSchema> tableSchemaList = Arrays.asList(tableSchema, tableSchema, tableSchema);
    when(tableSchema.getNamespace()).thenReturn("ns");
    when(tableSchema.getOptions()).thenReturn(options);
    when(tableSchema.isTransactionalTable()).thenReturn(false);
    when(tableSchema.getTable()).thenReturn("tb");
    TableMetadata tableMetadata = mock(TableMetadata.class);
    when(tableSchema.getTableMetadata()).thenReturn(tableMetadata);
    // Act
    operator.createTables(tableSchemaList);
    // Assert
    verify(admin, times(3)).createNamespace("ns", true, options);
    verify(admin, times(3)).tableExists("ns", "tb");
    verify(admin, times(3)).createTable("ns", "tb", tableMetadata, options);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

TableMetadata (com.scalar.db.api.TableMetadata)101 Test (org.junit.jupiter.api.Test)39 Get (com.scalar.db.api.Get)11 PreparedStatement (java.sql.PreparedStatement)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Key (com.scalar.db.io.Key)6 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)6 Mutation (com.scalar.db.api.Mutation)5 Result (com.scalar.db.api.Result)5 GetTableMetadataResponse (com.scalar.db.rpc.GetTableMetadataResponse)5 ResultSet (java.sql.ResultSet)5 Nonnull (javax.annotation.Nonnull)5 HashMap (java.util.HashMap)4 Options (com.datastax.driver.core.schemabuilder.Create.Options)3 KeyspaceOptions (com.datastax.driver.core.schemabuilder.KeyspaceOptions)3 TableOptions (com.datastax.driver.core.schemabuilder.TableOptions)3 ScanAll (com.scalar.db.api.ScanAll)3 NoMutationException (com.scalar.db.exception.storage.NoMutationException)3