Search in sources :

Example 1 with CommitException

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

the class ConsensusCommitIntegrationTestBase method populateRecords.

private void populateRecords(String namespace, String table) throws CommitException, UnknownTransactionStatusException {
    ConsensusCommit 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);
        transaction.put(put);
    }));
    transaction.commit();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) DatabaseConfig(com.scalar.db.config.DatabaseConfig) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) 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) Mockito.spy(org.mockito.Mockito.spy) 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) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TestUtils(com.scalar.db.storage.TestUtils) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) CommitException(com.scalar.db.exception.transaction.CommitException) DataType(com.scalar.db.io.DataType) CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) Before(org.junit.Before) Key(com.scalar.db.io.Key) AfterClass(org.junit.AfterClass) NoMutationException(com.scalar.db.exception.storage.NoMutationException) TransactionState(com.scalar.db.api.TransactionState) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Put(com.scalar.db.api.Put) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) Mockito.verify(org.mockito.Mockito.verify) DistributedStorage(com.scalar.db.api.DistributedStorage) Mockito.never(org.mockito.Mockito.never) List(java.util.List) Selection(com.scalar.db.api.Selection) Scan(com.scalar.db.api.Scan) UnknownTransactionStatusException(com.scalar.db.exception.transaction.UnknownTransactionStatusException) Optional(java.util.Optional) Collections(java.util.Collections) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put)

Example 2 with CommitException

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

the class ConsensusCommitSpecificIntegrationTestBase method populateRecords.

private void populateRecords(String namespace, String table) throws CommitException, UnknownTransactionStatusException {
    ConsensusCommit 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);
        transaction.put(put);
    }));
    transaction.commit();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) Consistency(com.scalar.db.api.Consistency) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) StorageFactory(com.scalar.db.service.StorageFactory) CrudException(com.scalar.db.exception.transaction.CrudException) AfterAll(org.junit.jupiter.api.AfterAll) Result(com.scalar.db.api.Result) TestInstance(org.junit.jupiter.api.TestInstance) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) CommitException(com.scalar.db.exception.transaction.CommitException) CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) TransactionState(com.scalar.db.api.TransactionState) Put(com.scalar.db.api.Put) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Delete(com.scalar.db.api.Delete) Test(org.junit.jupiter.api.Test) List(java.util.List) UnknownTransactionStatusException(com.scalar.db.exception.transaction.UnknownTransactionStatusException) Optional(java.util.Optional) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Value(com.scalar.db.io.Value) Mockito.spy(org.mockito.Mockito.spy) DistributedStorageAdmin(com.scalar.db.api.DistributedStorageAdmin) TestUtils(com.scalar.db.util.TestUtils) TableMetadata(com.scalar.db.api.TableMetadata) ArrayList(java.util.ArrayList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ScanAll(com.scalar.db.api.ScanAll) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataType(com.scalar.db.io.DataType) Key(com.scalar.db.io.Key) Properties(java.util.Properties) NoMutationException(com.scalar.db.exception.storage.NoMutationException) Mockito.times(org.mockito.Mockito.times) Get(com.scalar.db.api.Get) Mockito.verify(org.mockito.Mockito.verify) DistributedStorage(com.scalar.db.api.DistributedStorage) Mockito.never(org.mockito.Mockito.never) Selection(com.scalar.db.api.Selection) Scan(com.scalar.db.api.Scan) Collections(java.util.Collections) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put)

Example 3 with CommitException

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

the class TwoPhaseConsensusCommit method prepare.

@Override
public void prepare() throws PreparationException {
    checkStatus("The transaction is not active", Status.ACTIVE);
    beforePrepareHook.run();
    try {
        commit.prepare(crud.getSnapshot(), false);
        status = Status.PREPARED;
    } catch (CommitConflictException e) {
        status = Status.PREPARE_FAILED;
        throw new PreparationConflictException("prepare failed", e);
    } catch (CommitException e) {
        status = Status.PREPARE_FAILED;
        throw new PreparationException("prepare failed", e);
    } catch (UnknownTransactionStatusException e) {
    // Should not be reached here because CommitHandler.prepare() with abortIfError=false won't
    // throw UnknownTransactionStatusException
    }
}
Also used : CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) CommitException(com.scalar.db.exception.transaction.CommitException) PreparationException(com.scalar.db.exception.transaction.PreparationException) UnknownTransactionStatusException(com.scalar.db.exception.transaction.UnknownTransactionStatusException) PreparationConflictException(com.scalar.db.exception.transaction.PreparationConflictException)

Example 4 with CommitException

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

the class CommitHandler method commitState.

public void commitState(Snapshot snapshot) throws CommitException, UnknownTransactionStatusException {
    String id = snapshot.getId();
    try {
        commitState(snapshot.getId());
    } catch (CoordinatorException e) {
        TransactionState state = abort(id);
        if (state.equals(TransactionState.ABORTED)) {
            rollbackRecords(snapshot);
            throw new CommitException("committing state in coordinator failed. the transaction is aborted", e);
        }
    }
    LOGGER.debug("transaction {} is committed successfully at {}", id, System.currentTimeMillis());
}
Also used : TransactionState(com.scalar.db.api.TransactionState) CommitException(com.scalar.db.exception.transaction.CommitException)

Example 5 with CommitException

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

the class TwoPhaseConsensusCommit method validate.

@Override
public void validate() throws ValidationException {
    checkStatus("The transaction is not prepared", Status.PREPARED);
    try {
        commit.preCommitValidation(crud.getSnapshot(), false);
        status = Status.VALIDATED;
    } catch (CommitConflictException e) {
        status = Status.VALIDATION_FAILED;
        throw new ValidationConflictException("validation failed", e);
    } catch (CommitException e) {
        status = Status.VALIDATION_FAILED;
        throw new ValidationException("validation failed", e);
    } catch (UnknownTransactionStatusException e) {
    // Should not be reached here because CommitHandler.prepare() with abortIfError=false won't
    // throw UnknownTransactionStatusException
    }
}
Also used : CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) CommitException(com.scalar.db.exception.transaction.CommitException) ValidationException(com.scalar.db.exception.transaction.ValidationException) UnknownTransactionStatusException(com.scalar.db.exception.transaction.UnknownTransactionStatusException) ValidationConflictException(com.scalar.db.exception.transaction.ValidationConflictException)

Aggregations

CommitException (com.scalar.db.exception.transaction.CommitException)5 CommitConflictException (com.scalar.db.exception.transaction.CommitConflictException)4 UnknownTransactionStatusException (com.scalar.db.exception.transaction.UnknownTransactionStatusException)4 TransactionState (com.scalar.db.api.TransactionState)3 Consistency (com.scalar.db.api.Consistency)2 Delete (com.scalar.db.api.Delete)2 DistributedStorage (com.scalar.db.api.DistributedStorage)2 DistributedStorageAdmin (com.scalar.db.api.DistributedStorageAdmin)2 Get (com.scalar.db.api.Get)2 Put (com.scalar.db.api.Put)2 Result (com.scalar.db.api.Result)2 Scan (com.scalar.db.api.Scan)2 Selection (com.scalar.db.api.Selection)2 TableMetadata (com.scalar.db.api.TableMetadata)2 DatabaseConfig (com.scalar.db.config.DatabaseConfig)2 ExecutionException (com.scalar.db.exception.storage.ExecutionException)2 NoMutationException (com.scalar.db.exception.storage.NoMutationException)2 CrudException (com.scalar.db.exception.transaction.CrudException)2 DataType (com.scalar.db.io.DataType)2 IntValue (com.scalar.db.io.IntValue)2