Skip to content

Commit

Permalink
Merge branch 'develop' into dependency-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
hsaraogi committed Jan 13, 2017
2 parents da9f746 + 0dbf52f commit 751937f
Show file tree
Hide file tree
Showing 117 changed files with 6,649 additions and 896 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ generated_testSrc/
.factorypath
out/
atlasdb-cli/var/data/
*.hprof

# Common text-editor temp files
# emacs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,10 @@ <T, E extends Exception> T runTaskThrowOnConflict(TransactionTask<T, E> task)
* @throws IllegalStateException if the transaction manager has been closed.
*/
long getUnreadableTimestamp();

/**
* Clear the timestamp cache. This is mostly useful for tests that perform operations that would invalidate
* the cache, although this can also be used to free up some memory.
*/
void clearTimestampCache();
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public void testIsRetriableException() {
public void testIsRetriableWithBackoffException() {
assertTrue(CassandraClientPool.isRetriableWithBackoffException(new NoSuchElementException()));
assertTrue(CassandraClientPool.isRetriableWithBackoffException(new UnavailableException()));
assertTrue(CassandraClientPool.isRetriableWithBackoffException(
new TTransportException(new SocketTimeoutException())));
assertTrue(CassandraClientPool.isRetriableWithBackoffException(
new TTransportException(new UnavailableException())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ public void getRangeOfTimestampsThrows() {
ClosableIterator<RowResult<Set<Long>>> it = OneNodeDownTestSuite.db.getRangeOfTimestamps(
OneNodeDownTestSuite.TEST_TABLE, range, Long.MAX_VALUE);
assertThatThrownBy(() -> it.next())
.isInstanceOf(InsufficientConsistencyException.class)
.isExactlyInstanceOf(InsufficientConsistencyException.class)
.hasMessage("This operation requires all Cassandra nodes to be up and available.");
}

@Test
public void getAllTimestampsThrows() {
assertThatThrownBy(() -> OneNodeDownTestSuite.db.getAllTimestamps(OneNodeDownTestSuite.TEST_TABLE,
ImmutableSet.of(OneNodeDownTestSuite.CELL_1_1), Long.MAX_VALUE))
.isInstanceOf(PalantirRuntimeException.class);
.isExactlyInstanceOf(PalantirRuntimeException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public void putMetadataForTableThrows() {
TableMetadata newTableMetadata = new TableMetadata(new NameMetadataDescription(),
new ColumnMetadataDescription(), ConflictHandler.IGNORE_ALL);
assertThatThrownBy(() -> OneNodeDownTestSuite.db.putMetadataForTable(OneNodeDownTestSuite.TEST_TABLE,
newTableMetadata.persistToBytes())).isInstanceOf(IllegalStateException.class);
newTableMetadata.persistToBytes())).isExactlyInstanceOf(IllegalStateException.class)
.hasMessageContaining("At schema version UNREACHABLE");

canGetMetadataForTable();
}

@Test
Expand All @@ -60,6 +63,9 @@ public void putMetadataForTablesThrows() {
new ColumnMetadataDescription(), ConflictHandler.IGNORE_ALL);
assertThatThrownBy(() -> OneNodeDownTestSuite.db.putMetadataForTables(
ImmutableMap.of(OneNodeDownTestSuite.TEST_TABLE, newTableMetadata.persistToBytes())))
.isInstanceOf(IllegalStateException.class);
.isExactlyInstanceOf(IllegalStateException.class)
.hasMessageContaining("At schema version UNREACHABLE");

canGetMetadataForTable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.palantir.cassandra.multinode;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -74,8 +75,13 @@ public void canPutUnlessExists() {
@Test
public void putUnlessExistsThrowsOnExists() {
assertThatThrownBy(() -> OneNodeDownTestSuite.db.putUnlessExists(OneNodeDownTestSuite.TEST_TABLE,
ImmutableMap.of(OneNodeDownTestSuite.CELL_1_1, OneNodeDownTestSuite.DEFAULT_CONTENTS))).isInstanceOf(
KeyAlreadyExistsException.class);
ImmutableMap.of(OneNodeDownTestSuite.CELL_1_1, OneNodeDownTestSuite.DEFAULT_CONTENTS)))
.isInstanceOf(KeyAlreadyExistsException.class);

Map<Cell, Value> result = OneNodeDownTestSuite.db.get(OneNodeDownTestSuite.TEST_TABLE,
ImmutableMap.of(OneNodeDownTestSuite.CELL_1_1, AtlasDbConstants.TRANSACTION_TS));
assertThat(Value.create(OneNodeDownTestSuite.DEFAULT_CONTENTS, AtlasDbConstants.TRANSACTION_TS))
.isNotEqualTo(result.get(OneNodeDownTestSuite.CELL_1_1));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.palantir.cassandra.multinode;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.junit.Test;
Expand All @@ -31,29 +32,48 @@ public class OneNodeDownTableManipulationTest {

@Test
public void createTableThrows() {
assertThat(OneNodeDownTestSuite.db.getAllTableNames()).doesNotContain(NEW_TABLE);
assertThatThrownBy(
() -> OneNodeDownTestSuite.db.createTable(NEW_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA))
.isExactlyInstanceOf(IllegalStateException.class);
.isExactlyInstanceOf(IllegalStateException.class)
.hasMessageContaining("At schema version UNREACHABLE");
// This documents and verifies the current behaviour, creating the table in spite of the exception
// Seems to be inconsistent with the API
assertThat(OneNodeDownTestSuite.db.getAllTableNames()).contains(NEW_TABLE);
}

@Test
public void createTablesThrows() {
assertThat(OneNodeDownTestSuite.db.getAllTableNames()).doesNotContain(NEW_TABLE2);
assertThatThrownBy(() -> OneNodeDownTestSuite.db.createTables(
ImmutableMap.of(NEW_TABLE2, AtlasDbConstants.GENERIC_TABLE_METADATA)))
.isExactlyInstanceOf(IllegalStateException.class);
.isExactlyInstanceOf(IllegalStateException.class)
.hasMessageContaining("At schema version UNREACHABLE");
// This documents and verifies the current behaviour, creating the table in spite of the exception
// Seems to be inconsistent with the API
assertThat(OneNodeDownTestSuite.db.getAllTableNames()).contains(NEW_TABLE2);
}

@Test
public void dropTableThrows() {
assertThat(OneNodeDownTestSuite.db.getAllTableNames()).contains(OneNodeDownTestSuite.TEST_TABLE_TO_DROP);
assertThatThrownBy(() -> OneNodeDownTestSuite.db.dropTable(OneNodeDownTestSuite.TEST_TABLE_TO_DROP))
.isExactlyInstanceOf(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.db.getAllTableNames()).doesNotContain(OneNodeDownTestSuite.TEST_TABLE_TO_DROP);
}

@Test
public void dropTablesThrows() {
ImmutableSet<TableReference> tablesToDrop = ImmutableSet.of(OneNodeDownTestSuite.TEST_TABLE_TO_DROP_2);
assertThatThrownBy(() -> OneNodeDownTestSuite.db.dropTables(tablesToDrop))
assertThat(OneNodeDownTestSuite.db.getAllTableNames()).contains(OneNodeDownTestSuite.TEST_TABLE_TO_DROP_2);
assertThatThrownBy(() -> OneNodeDownTestSuite.db.dropTables(
ImmutableSet.of(OneNodeDownTestSuite.TEST_TABLE_TO_DROP_2)))
.isExactlyInstanceOf(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.db.getAllTableNames())
.doesNotContain(OneNodeDownTestSuite.TEST_TABLE_TO_DROP_2);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import com.palantir.atlasdb.spi.AtlasDbFactory;
import com.palantir.atlasdb.spi.KeyValueServiceConfig;
import com.palantir.atlasdb.versions.AtlasDbVersion;
import com.palantir.timestamp.DebugLogger;
import com.palantir.timestamp.PersistentTimestampService;
import com.palantir.timestamp.TimestampService;
import com.palantir.util.DebugLogger;

@AutoService(AtlasDbFactory.class)
public class CassandraAtlasDbFactory implements AtlasDbFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class CassandraKeyValueServiceConfig implements KeyValueServiceC

@Value.Default
public int poolSize() {
return 20;
return 30;
}

/**
Expand All @@ -54,7 +54,7 @@ public int poolSize() {
*/
@Value.Default
public int maxConnectionBurstSize() {
return 5 * poolSize();
return 100;
}

/**
Expand Down Expand Up @@ -208,7 +208,7 @@ protected final void check() {
}
Preconditions.checkNotNull(keyspace(), "'keyspace' must be specified");
double evictionCheckProportion = proportionConnectionsToCheckPerEvictionRun();
Preconditions.checkArgument(evictionCheckProportion > 0 && evictionCheckProportion <= 1,
"'proportionConnectionsToCheckPerEvictionRun' must be between 0 and 1");
Preconditions.checkArgument(evictionCheckProportion > 0.01 && evictionCheckProportion <= 1,
"'proportionConnectionsToCheckPerEvictionRun' must be between 0.01 and 1");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ public <V, K extends Exception> V runWithRetryOnHost(
if (isRetriableWithBackoffException(e)) {
log.warn("Retrying with backoff a query intended for host {}.", hostPool.getHost(), e);
try {
Thread.sleep(numTries * 1000);
// And value between -500 and +500ms to backoff to better spread load on failover
Thread.sleep(numTries * 1000 + (ThreadLocalRandom.current().nextInt(1000) - 500));
} catch (InterruptedException i) {
throw new RuntimeException(i);
}
Expand Down Expand Up @@ -653,6 +654,8 @@ static boolean isRetriableWithBackoffException(Throwable ex) {
&& (ex instanceof NoSuchElementException
// remote cassandra node couldn't talk to enough other remote cassandra nodes to answer
|| ex instanceof UnavailableException
// tcp socket timeout, possibly indicating network flake, long GC, or restarting server
|| isConnectionException(ex)
|| isRetriableWithBackoffException(ex.getCause()));
}

Expand Down
Loading

0 comments on commit 751937f

Please sign in to comment.