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

Tow/implement new cassandra exception #7353

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bf9b64b
Added CassandraTException
tillyow Oct 15, 2024
fcfcdd4
Adding missedTExceptions
tillyow Oct 15, 2024
73922f5
spotlessApply
tillyow Oct 15, 2024
5ca86f7
Added UnavailableException catches
tillyow Oct 15, 2024
e49373c
Add generated changelog entries
svc-changelog Oct 15, 2024
a64466c
Ammended the CassadraException to include args as the other PR will i…
tillyow Oct 15, 2024
6907c90
Merge branch 'tow/implement-new-cassandra-exception' of https://githu…
tillyow Oct 15, 2024
4ece409
Amended compileTime
tillyow Oct 18, 2024
d0d672f
explainer for compile time suppression
tillyow Oct 18, 2024
cb31c35
Merge branch 'develop' into tow/implement-new-cassandra-exception
tillyow Oct 18, 2024
a7cc461
typo
tillyow Oct 18, 2024
d269d60
Api break confirmation not a break as break has been fixed via same PR
tillyow Oct 18, 2024
b0ee926
spoteless
tillyow Oct 18, 2024
86d55f3
Added a catch for a TEXception
tillyow Oct 21, 2024
fda40b5
change exception caught
tillyow Oct 23, 2024
49fb7e1
Change to catch AtlasDbDependency excpetion
tillyow Oct 23, 2024
bebe35e
Exception now throws AtlasDbException so adapting the integration test
tillyow Oct 23, 2024
fd5737b
Merge branch 'develop' into tow/implement-new-cassandra-exception
tillyow Oct 23, 2024
2245e01
test changed for new exception thrown
tillyow Oct 24, 2024
97c2bde
Merge branch 'tow/implement-new-cassandra-exception' of https://githu…
tillyow Oct 24, 2024
87149e6
added requested changes:
tillyow Oct 25, 2024
185f04e
Change the compaction wording
tillyow Oct 25, 2024
cd6fbfa
spotlessApply
tillyow Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .palantir/revapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,22 @@ acceptedBreaks:
new: "method void com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException::<init>(java.lang.String,\
\ java.lang.Throwable, com.palantir.logsafe.Arg<?>[])"
justification: "I have fixed all the implementations and it is not used externally"
"0.1169.0":
com.palantir.atlasdb:atlasdb-api:
- code: "java.method.parameterTypeChanged"
old: "parameter void com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException::<init>(===java.lang.String===,\
\ java.lang.Throwable)"
new: "parameter void com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException::<init>(===java.lang.Throwable===,\
\ com.palantir.logsafe.Arg<?>[])"
justification: "Not a break as I have handle the implementation in the same\
\ PR"
- code: "java.method.parameterTypeChanged"
old: "parameter void com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException::<init>(java.lang.String,\
\ ===java.lang.Throwable===)"
new: "parameter void com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException::<init>(java.lang.Throwable,\
\ ===com.palantir.logsafe.Arg<?>[]===)"
justification: "Not a break as I have handle the implementation in the same\
\ PR"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This would be true for truly internal APIs. However, this exception is actually used in the internal backup and restore product's tests. It's probably not a major issue, but we will want to make sure that we fix their tests and bump their Atlas version accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a sourcegraph check, and I couldn't find anything. How would I see the usages of "internal backup and restore product's tests" if not using sourcegraph?

"0.1168.0":
com.palantir.atlasdb:atlasdb-api:
- code: "java.method.numberOfParametersChanged"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public InsufficientConsistencyException(@CompileTimeConstant String msg, Arg<?>.
public InsufficientConsistencyException(@CompileTimeConstant String msg, Throwable ex, Arg<?>... args) {
super(msg, ex, args);
}

public InsufficientConsistencyException(Throwable ex, Arg<?>... args) {
super(ex, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ void testSetup(CassandraKeyValueService kvs) {

@Test
public void deletingThrows() {
assertThrowsInsufficientConsistencyExceptionAndDoesNotChangeCassandraSchema(
assertThrowsAtlasDbDependencyExceptionAndDoesNotChangeCassandraSchema(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems odd - why do we need to change this? We should still be throwing InsufficientConsistencyExceptions here.

() -> getTestKvs().delete(TEST_TABLE, ImmutableMultimap.of(CELL_1_1, TIMESTAMP)));
}

@Test
public void deleteAllTimestampsThrows() {
assertThrowsInsufficientConsistencyExceptionAndDoesNotChangeCassandraSchema(() -> getTestKvs()
assertThrowsAtlasDbDependencyExceptionAndDoesNotChangeCassandraSchema(() -> getTestKvs()
.deleteAllTimestamps(
TEST_TABLE,
ImmutableMap.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,14 @@ private CassandraClient instrumentClient(Client rawClient) {
return client;
}

private Cassandra.Client getRawClientWithKeyspaceSet() throws TException {
Client ret = getRawClientWithTimedCreation();
private Cassandra.Client getRawClientWithKeyspaceSet() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be changing the signature here - this should be an invisible refactor, and changing the fact that this no longer throws the checked exception is changing the signature.

Do double check whether you actually want to modify here to remap the exception, or at the caller (and let me know what you believe to be the case)

Client ret;
try {
ret = getRawClientWithTimedCreation();
} catch (TException e) {
throw CassandraTExceptions.mapToUncheckedException(e);
}

try {
ret.set_keyspace(clientConfig.keyspace());
if (log.isDebugEnabled()) {
Expand All @@ -154,7 +160,10 @@ private Cassandra.Client getRawClientWithKeyspaceSet() throws TException {
return ret;
} catch (TException e) {
ret.getOutputProtocol().getTransport().close();
throw e;
throw CassandraTExceptions.mapToUncheckedException(
"Failed to create new client for: {}",
e,
SafeArg.of("address", CassandraLogHelper.host(cassandraServer.proxy())));
}
}

Expand Down Expand Up @@ -228,8 +237,8 @@ private static Cassandra.Client getRawClient(
addr);
} catch (TException e) {
client.getOutputProtocol().getTransport().close();
log.error("Exception thrown attempting to authenticate with config provided credentials", e);
throw e;
throw CassandraTExceptions.mapToUncheckedException(
"Exception thrown attempting to authenticate with config provided credentials", e);
}

return client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
import org.apache.cassandra.thrift.KsDef;
import org.apache.cassandra.thrift.Mutation;
import org.apache.cassandra.thrift.SlicePredicate;
import org.apache.cassandra.thrift.TimedOutException;
import org.apache.thrift.TException;

/**
Expand Down Expand Up @@ -717,14 +718,18 @@ public Map<ByteBuffer, List<ColumnOrSuperColumn>> apply(CassandraClient client)
SafeArg.of("startTs", startTs),
SafeArg.of("host", host));
}
Map<ByteBuffer, List<List<ColumnOrSuperColumn>>> results = Collections.emptyMap();
try {
results = wrappingQueryRunner.multiget_multislice(
"getRows",
client,
tableRef,
query,
readConsistencyProvider.getConsistency(tableRef));

Map<ByteBuffer, List<List<ColumnOrSuperColumn>>> results =
wrappingQueryRunner.multiget_multislice(
"getRows",
client,
tableRef,
query,
readConsistencyProvider.getConsistency(tableRef));
} catch (TException e) {
throw CassandraTExceptions.mapToUncheckedException(e, SafeArg.of("tableRef", tableRef));
}

return Maps.transformValues(results, CellLoader::flattenReadOnlyLists);
}
Expand Down Expand Up @@ -966,14 +971,18 @@ public RowColumnRangeResult apply(CassandraClient client) throws Exception {
startTs);
Limit limit = Limit.of(batchColumnRangeSelection.getBatchHint());
SlicePredicate pred = SlicePredicates.create(range, limit);

Map<ByteBuffer, List<ColumnOrSuperColumn>> results = wrappingQueryRunner.multiget(
"getRowsColumnRange",
client,
tableRef,
wrap(rows),
pred,
readConsistencyProvider.getConsistency(tableRef));
Map<ByteBuffer, List<ColumnOrSuperColumn>> results = Collections.emptyMap();
try {
results = wrappingQueryRunner.multiget(
"getRowsColumnRange",
client,
tableRef,
wrap(rows),
pred,
readConsistencyProvider.getConsistency(tableRef));
} catch (TException e) {
throw new TimedOutException();
}

return RowColumnRangeExtractor.extract(rows, results, startTs, metricsManager);
}
Expand All @@ -985,6 +994,8 @@ public String toString() {
+ " max columns)";
}
});
} catch (TimedOutException e) {
throw CassandraTExceptions.mapToUncheckedException(e, SafeArg.of("tableRef", tableRef));
} catch (Exception e) {
throw Throwables.unwrapAndThrowAtlasDbDependencyException(e);
}
Expand Down Expand Up @@ -1029,15 +1040,19 @@ public TokenBackedBasicResultsPage<Map.Entry<Cell, Value>, byte[]> apply(

ByteBuffer rowByteBuffer = ByteBuffer.wrap(row);

Map<ByteBuffer, List<ColumnOrSuperColumn>> results =
wrappingQueryRunner.multiget(
"getRowsColumnRange",
client,
tableRef,
ImmutableList.of(rowByteBuffer),
pred,
readConsistencyProvider.getConsistency(tableRef));

Map<ByteBuffer, List<ColumnOrSuperColumn>> results = Collections.emptyMap();
try {
results = wrappingQueryRunner.multiget(
"getRowsColumnRange",
client,
tableRef,
ImmutableList.of(rowByteBuffer),
pred,
readConsistencyProvider.getConsistency(tableRef));
} catch (TException e) {
throw CassandraTExceptions.mapToUncheckedException(
e, SafeArg.of("tableRef", tableRef));
}
if (results.isEmpty()) {
return SimpleTokenBackedResultsPage.create(
startCol, ImmutableList.of(), false);
Expand Down Expand Up @@ -1715,7 +1730,7 @@ public void deleteRange(final TableReference tableRef, final RangeRequest range)
} catch (RetryLimitReachedException e) {
throw CassandraUtils.wrapInIceForDeleteOrRethrow(e);
} catch (TException e) {
throw Throwables.unwrapAndThrowAtlasDbDependencyException(e);
throw CassandraTExceptions.mapToUncheckedException(e);
}
} else {
super.deleteRange(tableRef, range);
Expand Down Expand Up @@ -1753,7 +1768,7 @@ public void deleteRows(TableReference tableRef, Iterable<byte[]> rows) {
} catch (RetryLimitReachedException e) {
throw CassandraUtils.wrapInIceForDeleteOrRethrow(e);
} catch (TException e) {
throw Throwables.unwrapAndThrowAtlasDbDependencyException(e);
throw CassandraTExceptions.mapToUncheckedException(e);
}
}

Expand Down Expand Up @@ -1891,7 +1906,7 @@ public void deleteFromAtomicTable(TableReference tableRef, Set<Cell> cells) {
try {
atomicTableCellDeleter.deleteFromAtomicTable(client, tableRef, cell);
} catch (TException e) {
throw Throwables.unwrapAndThrowAtlasDbDependencyException(e);
throw CassandraTExceptions.mapToUncheckedException(e);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public boolean isNamespaceDeletedSuccessfully() {
} catch (NotFoundException e) {
return true;
} catch (TException e) {
throw Throwables.throwUncheckedException(e);
throw CassandraTExceptions.mapToUncheckedException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.palantir.atlasdb.namespacedeleter.NamespaceDeleterFactory;
import com.palantir.atlasdb.spi.KeyValueServiceConfig;
import com.palantir.atlasdb.spi.KeyValueServiceRuntimeConfig;
import com.palantir.common.base.Throwables;
import com.palantir.refreshable.Refreshable;
import java.net.InetSocketAddress;
import java.util.Optional;
Expand Down Expand Up @@ -66,7 +65,7 @@ private static CassandraClient createClient(
.orElseThrow();
return CassandraClientFactory.getClientInternal(CassandraServer.of(host), CassandraClientConfig.of(config));
} catch (TException e) {
throw Throwables.rewrapAndThrowUncheckedException(e);
throw CassandraTExceptions.mapToUncheckedException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.atlasdb.keyvalue.cassandra;

import com.google.errorprone.annotations.CompileTimeConstant;
import com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException;
import com.palantir.common.exception.AtlasDbDependencyException;
import com.palantir.logsafe.Arg;
import org.apache.cassandra.thrift.TimedOutException;
import org.apache.cassandra.thrift.UnavailableException;

public final class CassandraTExceptions {
private CassandraTExceptions() {}

public static AtlasDbDependencyException mapToUncheckedException(
@CompileTimeConstant final String logMessage, Throwable throwable, Arg<?>... args) {
if (throwable instanceof TimedOutException) {
return new CassandraTimedOutException(throwable, args);
}
if (throwable instanceof UnavailableException) {
return new InsufficientConsistencyException(logMessage, throwable);
}
if (throwable instanceof InsufficientConsistencyException) {
return new InsufficientConsistencyException(logMessage, throwable);
}
return new AtlasDbDependencyException(throwable);
}

public static AtlasDbDependencyException mapToUncheckedException(Throwable throwable, Arg<?>... args) {
if (throwable instanceof TimedOutException) {
return new CassandraTimedOutException(throwable, args);
}
if (throwable instanceof UnavailableException) {
return new InsufficientConsistencyException(throwable, args);
}
return new AtlasDbDependencyException(throwable, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.palantir.atlasdb.keyvalue.api.TableReference;
import com.palantir.common.base.FunctionCheckedException;
import com.palantir.common.base.Throwables;
import java.util.Collection;
import org.apache.thrift.TException;

Expand All @@ -36,7 +35,7 @@ void truncateTables(Collection<TableReference> tablesToTruncate) {
try {
runTruncateInternal(tablesToTruncate);
} catch (TException e) {
throw Throwables.unwrapAndThrowAtlasDbDependencyException(e);
throw CassandraTExceptions.mapToUncheckedException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.atlasdb.keyvalue.cassandra;

import com.palantir.common.exception.AtlasDbDependencyException;
import com.palantir.logsafe.Arg;
import com.palantir.logsafe.exceptions.SafeExceptions;

// Added the below suppression because the Runtime class compileTime string check sees the + in the static final as
// non compile time safe. But no other way to achieve as we are using a java version that does not have text blocks.
@SuppressWarnings("CompileTimeConstant")
public class CassandraTimedOutException extends AtlasDbDependencyException {
private static final long serialVersionUID = 1L;

private static final String LOG_MESSAGE =
"Cassandra query threw a TimedOut exception. Possible reasons and actions to resolve include:\n"
+ "1. Reason: AtlasDB clients are requesting too much data from Cassandra.\n"
+ " Resolution: Change the query to request less data.\n"
+ "2. Reason: Data that has been deleted is being read in the query (e.g. A large amount of"
+ " tombstones).\n"
+ " Resolution: Check the status of sweep for your client, and if required run a compaction on your"
+ " Cassandra server.\n"
+ "3. Reason: Cassandra is struggling, possibly due to another large query, server health issues, or a"
+ " network outage.\n"
+ " Resolution: Ask your CassandraOps to check the state of the Cassandra server.";

public CassandraTimedOutException(Throwable throwable, Arg<?>... args) {
super(SafeExceptions.renderMessage(LOG_MESSAGE, args), throwable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.palantir.atlasdb.AtlasDbConstants;
import com.palantir.atlasdb.encoding.PtBytes;
import com.palantir.common.annotation.Idempotent;
import com.palantir.common.base.Throwables;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.logger.SafeLogger;
Expand Down Expand Up @@ -185,7 +184,7 @@ private CqlResult executeQueryUnchecked(CassandraClient client, CqlQuery query)
AtlasDbConstants.TIMESTAMP_TABLE,
() -> client.execute_cql3_query(query, Compression.NONE, ConsistencyLevel.QUORUM));
} catch (TException e) {
throw Throwables.rewrapAndThrowUncheckedException(e);
throw CassandraTExceptions.mapToUncheckedException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public static FunctionCheckedException<CassandraClient, List<TokenRange>, Except

public static AtlasDbDependencyException wrapInIceForDeleteOrRethrow(RetryLimitReachedException ex) {
if (ex.suppressed(UnavailableException.class) || ex.suppressed(InsufficientConsistencyException.class)) {
throw new InsufficientConsistencyException("Deleting requires all Cassandra nodes to be available.", ex);
throw CassandraTExceptions.mapToUncheckedException(
"Deleting requires all Cassandra nodes to be available.", ex);
}
throw ex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.palantir.atlasdb.keyvalue.cassandra.CassandraClientFactory.CassandraClientConfig;
import com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer;
import com.palantir.common.base.FunctionCheckedException;
import com.palantir.common.base.Throwables;
import com.palantir.logsafe.DoNotLog;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.SafeArg;
Expand Down Expand Up @@ -90,7 +89,7 @@ static Set<String> sanityCheckDatacenters(CassandraClient client, CassandraVerif
return sanityCheckDatacentersInternal(
client, verifierConfig.replicationFactor(), verifierConfig.ignoreNodeTopologyChecks());
} catch (TException e) {
throw Throwables.throwUncheckedException(e);
throw CassandraTExceptions.mapToUncheckedException(e);
}
});
}
Expand Down
Loading