Search in sources :

Example 11 with CrudException

use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.

the class DistributedTransactionIntegrationTestBase method populateRecords.

private void populateRecords() throws TransactionException {
    DistributedTransaction transaction = manager.start();
    IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
        Key partitionKey = new Key(ACCOUNT_ID, i);
        Key clusteringKey = new Key(ACCOUNT_TYPE, j);
        Put put = new Put(partitionKey, clusteringKey).forNamespace(namespace).forTable(TABLE).withIntValue(BALANCE, INITIAL_BALANCE).withIntValue(SOME_COLUMN, i * j);
        try {
            transaction.put(put);
        } catch (CrudException e) {
            throw new RuntimeException(e);
        }
    }));
    transaction.commit();
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) IntColumn(com.scalar.db.io.IntColumn) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) TestUtils.assertResultsAreASubsetOf(com.scalar.db.util.TestUtils.assertResultsAreASubsetOf) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Value(com.scalar.db.io.Value) TestUtils(com.scalar.db.util.TestUtils) CrudException(com.scalar.db.exception.transaction.CrudException) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) TestInstance(org.junit.jupiter.api.TestInstance) ImmutableList(com.google.common.collect.ImmutableList) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) CommitException(com.scalar.db.exception.transaction.CommitException) DataType(com.scalar.db.io.DataType) CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) Key(com.scalar.db.io.Key) Properties(java.util.Properties) ExpectedResultBuilder(com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder) TestUtils.assertResultsContainsExactlyInAnyOrder(com.scalar.db.util.TestUtils.assertResultsContainsExactlyInAnyOrder) TransactionFactory(com.scalar.db.service.TransactionFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Ordering(com.scalar.db.api.Scan.Ordering) Optional(java.util.Optional) TransactionException(com.scalar.db.exception.transaction.TransactionException) Collections(java.util.Collections) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Key(com.scalar.db.io.Key) CrudException(com.scalar.db.exception.transaction.CrudException)

Example 12 with CrudException

use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.

the class JdbcTransaction method put.

@Override
public void put(Put put) throws CrudException {
    put = copyAndSetTargetToIfNot(put);
    // Ignore the condition in the put
    if (put.getCondition().isPresent()) {
        LOGGER.warn("ignoring the condition of the mutation: {}", put);
        put.withCondition(null);
    }
    try {
        jdbcService.put(put, connection);
    } catch (SQLException e) {
        throw createCrudException(e, "put operation failed");
    } catch (ExecutionException e) {
        throw new CrudException("put operation failed", e);
    }
}
Also used : SQLException(java.sql.SQLException) ExecutionException(com.scalar.db.exception.storage.ExecutionException) CrudException(com.scalar.db.exception.transaction.CrudException)

Example 13 with CrudException

use of com.scalar.db.exception.transaction.CrudException 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 14 with CrudException

use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.

the class JdbcTransactionIntegrationTest method populateRecords.

private void populateRecords() throws TransactionException {
    JdbcTransaction transaction = manager.start();
    IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
        Key partitionKey = new Key(ACCOUNT_ID, i);
        Key clusteringKey = new Key(ACCOUNT_TYPE, j);
        Put put = new Put(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(TABLE).withValue(BALANCE, INITIAL_BALANCE);
        try {
            transaction.put(put);
        } catch (CrudException e) {
            throw new RuntimeException(e);
        }
    }));
    transaction.commit();
}
Also used : IntStream(java.util.stream.IntStream) DatabaseConfig(com.scalar.db.config.DatabaseConfig) IntValue(com.scalar.db.io.IntValue) BeforeClass(org.junit.BeforeClass) Consistency(com.scalar.db.api.Consistency) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Value(com.scalar.db.io.Value) StorageFactory(com.scalar.db.service.StorageFactory) JdbcConfig(com.scalar.db.storage.jdbc.JdbcConfig) DistributedStorageAdmin(com.scalar.db.api.DistributedStorageAdmin) TableMetadata(com.scalar.db.api.TableMetadata) CrudException(com.scalar.db.exception.transaction.CrudException) ArrayList(java.util.ArrayList) Result(com.scalar.db.api.Result) TestUtils(com.scalar.db.storage.TestUtils) DataType(com.scalar.db.io.DataType) Before(org.junit.Before) Key(com.scalar.db.io.Key) AfterClass(org.junit.AfterClass) Test(org.junit.Test) Put(com.scalar.db.api.Put) Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) List(java.util.List) JdbcEnv(com.scalar.db.storage.jdbc.JdbcEnv) Scan(com.scalar.db.api.Scan) Optional(java.util.Optional) TransactionException(com.scalar.db.exception.transaction.TransactionException) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) CrudException(com.scalar.db.exception.transaction.CrudException)

Aggregations

CrudException (com.scalar.db.exception.transaction.CrudException)14 ExecutionException (com.scalar.db.exception.storage.ExecutionException)12 List (java.util.List)7 Optional (java.util.Optional)7 Get (com.scalar.db.api.Get)6 TransactionException (com.scalar.db.exception.transaction.TransactionException)6 Result (com.scalar.db.api.Result)5 Scan (com.scalar.db.api.Scan)5 TableMetadata (com.scalar.db.api.TableMetadata)5 DataType (com.scalar.db.io.DataType)5 Key (com.scalar.db.io.Key)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 CommitException (com.scalar.db.exception.transaction.CommitException)4 CrudConflictException (com.scalar.db.exception.transaction.CrudConflictException)4 IntValue (com.scalar.db.io.IntValue)4 Value (com.scalar.db.io.Value)4 ArrayList (java.util.ArrayList)4 IntStream (java.util.stream.IntStream)4 Delete (com.scalar.db.api.Delete)3 Test (org.junit.jupiter.api.Test)3