Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
ConsistentExceptions Part2: Convert UnavailableException to Insuffici…
Browse files Browse the repository at this point in the history
…entConsistencyException with actual error messages. (#2558)

* The cause of an ExecutionException is more interesting here. [no release notes]

* Throwables.unwrapAndThrowUncheckedException for all the things.

* Convert UnavailableException to InsufficientConsistencyException with actual error messages.

* Fix tests

* Address comments

* Missed cr comment

* nit fix

* ConsistentExceptions Part3: Throw AtlasDBDependencyException consistently (#2597)

* Consistently throw DependencyUnavailableException

* KeyAlreadyExistsException is not a DependencyUnavailableException

* AtlasDbDependencyException as things are are not always unavailable.

* test fixes

* Dont rewrap AtlasDbDependencyException

* cr comments

* Release note

* rename method

* refactor AtlasDbDependencyException

* Cleanup

* KeyAlreadyExistsException -> AtlasDbDependencyException

* Fix tests

* ClientCreationFailedException -> AtlasDbDependencyException

* Cleanup
  • Loading branch information
hsaraogi authored Nov 7, 2017
1 parent 47724dc commit 6e939b2
Show file tree
Hide file tree
Showing 20 changed files with 208 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package com.palantir.atlasdb.keyvalue.api;

import com.palantir.common.exception.PalantirRuntimeException;
import com.palantir.common.exception.AtlasDbDependencyException;

/**
* Thrown by a key value service when an operation could not be performed
* because the required consistency could not be met.
*/
public class InsufficientConsistencyException extends PalantirRuntimeException {
public class InsufficientConsistencyException extends AtlasDbDependencyException {
private static final long serialVersionUID = 1L;

public InsufficientConsistencyException(String msg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import java.util.Collection;

import com.google.common.collect.ImmutableList;
import com.palantir.common.exception.PalantirRuntimeException;
import com.palantir.common.exception.AtlasDbDependencyException;

public class KeyAlreadyExistsException extends PalantirRuntimeException {
public class KeyAlreadyExistsException extends AtlasDbDependencyException {
private static final long serialVersionUID = 1L;

private final ImmutableList<Cell> existingKeys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/
package com.palantir.atlasdb.transaction.api;

import com.palantir.exception.NotInitializedException;

public interface TransactionManager extends AutoCloseable {
/**
* Whether this transaction manager has established a connection to the backing store and timestamp/lock services,
* and is ready to service transactions.
*
* If an attempt is made to execute a transaction when this method returns {@code false}, a
* {@link com.palantir.exception.NotInitializedException} will be thrown.
* {@link NotInitializedException} will be thrown.
*
* This method is used for TransactionManagers that can be initialized asynchronously (i.e. those extending
* {@link com.palantir.async.initializer.AsyncInitializer}; other TransactionManagers can keep the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import org.junit.Test;

import com.google.common.collect.ImmutableMultimap;
import com.palantir.common.exception.PalantirRuntimeException;
import com.palantir.common.exception.AtlasDbDependencyException;

public class OneNodeDownDeleteTest {

@Test
public void deletingThrows() {
assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.delete(OneNodeDownTestSuite.TEST_TABLE,
ImmutableMultimap.of(OneNodeDownTestSuite.CELL_1_1, OneNodeDownTestSuite.DEFAULT_TIMESTAMP)))
.isInstanceOf(PalantirRuntimeException.class);
.isInstanceOf(AtlasDbDependencyException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.palantir.atlasdb.keyvalue.api.RowResult;
import com.palantir.atlasdb.keyvalue.api.Value;
import com.palantir.common.base.ClosableIterator;
import com.palantir.common.exception.PalantirRuntimeException;

public class OneNodeDownGetTest {

Expand Down Expand Up @@ -120,6 +119,7 @@ public void getRangeOfTimestampsThrows() {
public void getAllTimestampsThrows() {
assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.getAllTimestamps(OneNodeDownTestSuite.TEST_TABLE,
ImmutableSet.of(OneNodeDownTestSuite.CELL_1_1), Long.MAX_VALUE))
.isExactlyInstanceOf(PalantirRuntimeException.class);
.isExactlyInstanceOf(InsufficientConsistencyException.class)
.hasMessage("This get operation requires ALL Cassandra nodes to be up and available.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.palantir.atlasdb.table.description.NameMetadataDescription;
import com.palantir.atlasdb.table.description.TableMetadata;
import com.palantir.atlasdb.transaction.api.ConflictHandler;
import com.palantir.common.exception.AtlasDbDependencyException;

public class OneNodeDownMetadataTest {

Expand All @@ -51,8 +52,10 @@ public void putMetadataForTableThrows() {
TableMetadata newTableMetadata = new TableMetadata(new NameMetadataDescription(),
new ColumnMetadataDescription(), ConflictHandler.IGNORE_ALL);
assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.putMetadataForTable(OneNodeDownTestSuite.TEST_TABLE,
newTableMetadata.persistToBytes())).isExactlyInstanceOf(IllegalStateException.class)
.hasMessageContaining("At schema version UNREACHABLE");
newTableMetadata.persistToBytes()))
.isExactlyInstanceOf(AtlasDbDependencyException.class)
.hasCauseInstanceOf(IllegalStateException.class)
.hasStackTraceContaining("At schema version UNREACHABLE");

canGetMetadataForTable();
}
Expand All @@ -63,8 +66,9 @@ public void putMetadataForTablesThrows() {
new ColumnMetadataDescription(), ConflictHandler.IGNORE_ALL);
assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.putMetadataForTables(
ImmutableMap.of(OneNodeDownTestSuite.TEST_TABLE, newTableMetadata.persistToBytes())))
.isExactlyInstanceOf(IllegalStateException.class)
.hasMessageContaining("At schema version UNREACHABLE");
.isExactlyInstanceOf(AtlasDbDependencyException.class)
.hasCauseInstanceOf(IllegalStateException.class)
.hasStackTraceContaining("At schema version UNREACHABLE");

canGetMetadataForTable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.palantir.atlasdb.AtlasDbConstants;
import com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException;
import com.palantir.atlasdb.keyvalue.api.TableReference;
import com.palantir.common.exception.PalantirRuntimeException;
import com.palantir.common.exception.AtlasDbDependencyException;

public class OneNodeDownTableManipulationTest {
private static final TableReference NEW_TABLE = TableReference.createWithEmptyNamespace("new_table");
Expand Down Expand Up @@ -54,7 +55,8 @@ public void canCreateTables() {
public void dropTableThrows() {
assertThat(OneNodeDownTestSuite.kvs.getAllTableNames()).contains(OneNodeDownTestSuite.TEST_TABLE_TO_DROP);
assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.dropTable(OneNodeDownTestSuite.TEST_TABLE_TO_DROP))
.isExactlyInstanceOf(IllegalStateException.class);
.isExactlyInstanceOf(AtlasDbDependencyException.class)
.hasCauseInstanceOf(IllegalStateException.class);
// This documents and verifies the current behaviour, dropping the table in spite of the exception
// Seems to be inconsistent with the API
assertThat(OneNodeDownTestSuite.kvs.getAllTableNames()).doesNotContain(OneNodeDownTestSuite.TEST_TABLE_TO_DROP);
Expand All @@ -65,7 +67,8 @@ public void dropTablesThrows() {
assertThat(OneNodeDownTestSuite.kvs.getAllTableNames()).contains(OneNodeDownTestSuite.TEST_TABLE_TO_DROP_2);
assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.dropTables(
ImmutableSet.of(OneNodeDownTestSuite.TEST_TABLE_TO_DROP_2)))
.isExactlyInstanceOf(IllegalStateException.class);
.isExactlyInstanceOf(AtlasDbDependencyException.class)
.hasCauseInstanceOf(IllegalStateException.class);
// This documents and verifies the current behaviour, dropping the table in spite of the exception
// Seems to be inconsistent with the API
assertThat(OneNodeDownTestSuite.kvs.getAllTableNames())
Expand All @@ -85,15 +88,15 @@ public void canCleanUpSchemaMutationLockTablesState() throws Exception {
@Test
public void truncateTableThrows() {
assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.truncateTable(OneNodeDownTestSuite.TEST_TABLE))
.isExactlyInstanceOf(PalantirRuntimeException.class)
.isExactlyInstanceOf(InsufficientConsistencyException.class)
.hasMessage("Truncating tables requires all Cassandra nodes to be up and available.");
}

@Test
public void truncateTablesThrows() {
assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.truncateTables(
ImmutableSet.of(OneNodeDownTestSuite.TEST_TABLE)))
.isExactlyInstanceOf(PalantirRuntimeException.class)
.isExactlyInstanceOf(InsufficientConsistencyException.class)
.hasMessage("Truncating tables requires all Cassandra nodes to be up and available.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.google.common.collect.Maps;
import com.palantir.atlasdb.cassandra.CassandraCredentialsConfig;
import com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig;
import com.palantir.common.exception.AtlasDbDependencyException;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.UnsafeArg;
import com.palantir.remoting3.config.ssl.SslSocketFactories;
Expand Down Expand Up @@ -183,7 +184,7 @@ public void destroyObject(PooledObject<Client> client) {
SafeArg.of("cassandraClient", CassandraLogHelper.host(addr)));
}

static class ClientCreationFailedException extends RuntimeException {
static class ClientCreationFailedException extends AtlasDbDependencyException {
private static final long serialVersionUID = 1L;

ClientCreationFailedException(String message, Exception cause) {
Expand Down
Loading

0 comments on commit 6e939b2

Please sign in to comment.