use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class SnapshotTransaction method getWithPostFilteringAsync.
private <T> ListenableFuture<Collection<Map.Entry<Cell, T>>> getWithPostFilteringAsync(TableReference tableRef, Map<Cell, Value> rawResults, Function<Value, T> transformer, AsyncKeyValueService asyncKeyValueService, AsyncTransactionService asyncTransactionService) {
long bytes = 0;
for (Map.Entry<Cell, Value> entry : rawResults.entrySet()) {
bytes += entry.getValue().getContents().length + Cells.getApproxSizeOfCell(entry.getKey());
}
if (bytes > TransactionConstants.WARN_LEVEL_FOR_QUEUED_BYTES && log.isWarnEnabled()) {
log.warn("A single get had quite a few bytes: {} for table {}. The number of results was {}. " + "Enable debug logging for more information.", SafeArg.of("numBytes", bytes), LoggingArgs.tableRef(tableRef), SafeArg.of("numResults", rawResults.size()));
if (log.isDebugEnabled()) {
log.debug("The first 10 results of your request were {}.", UnsafeArg.of("results", Iterables.limit(rawResults.entrySet(), 10)), new SafeRuntimeException("This exception and stack trace are provided for debugging purposes"));
}
getHistogram(AtlasDbMetricNames.SNAPSHOT_TRANSACTION_TOO_MANY_BYTES_READ, tableRef).update(bytes);
}
getCounter(AtlasDbMetricNames.SNAPSHOT_TRANSACTION_CELLS_READ, tableRef).inc(rawResults.size());
// LinkedList is chosen for fast append operation since we just add to this collection.
@SuppressWarnings("JdkObsolete") Collection<Map.Entry<Cell, T>> resultsAccumulator = new LinkedList<>();
if (AtlasDbConstants.HIDDEN_TABLES.contains(tableRef)) {
Preconditions.checkState(allowHiddenTableAccess, "hidden tables cannot be read in this transaction");
// this case is hit when reading a hidden table from console
for (Map.Entry<Cell, Value> e : rawResults.entrySet()) {
resultsAccumulator.add(Maps.immutableEntry(e.getKey(), transformer.apply(e.getValue())));
}
return Futures.immediateFuture(resultsAccumulator);
}
return Futures.transformAsync(Futures.immediateFuture(rawResults), remainingResultsToPostFilter -> getWithPostFilteringIterate(tableRef, remainingResultsToPostFilter, resultsAccumulator, transformer, asyncKeyValueService, asyncTransactionService), MoreExecutors.directExecutor());
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class SnapshotTransaction method acquireLocksForCommit.
// /////////////////////////////////////////////////////////////////////////
// / Locking
// /////////////////////////////////////////////////////////////////////////
/**
* This method should acquire any locks needed to do proper concurrency control at commit time.
*/
protected LockToken acquireLocksForCommit() {
Set<LockDescriptor> lockDescriptors = getLocksForWrites();
TransactionConfig currentTransactionConfig = transactionConfig.get();
// TODO(fdesouza): Revert this once PDS-95791 is resolved.
long lockAcquireTimeoutMillis = currentTransactionConfig.getLockAcquireTimeoutMillis();
LockRequest request = ImmutableLockRequest.of(lockDescriptors, lockAcquireTimeoutMillis, Optional.ofNullable(getStartTimestampAsClientDescription(currentTransactionConfig)));
RuntimeException stackTraceSnapshot = new SafeRuntimeException("I exist to show you the stack trace");
LockResponse lockResponse = timelockService.lock(request, ClientLockingOptions.builder().maximumLockTenure(currentTransactionConfig.commitLockTenure().toJavaDuration()).tenureExpirationCallback(() -> logCommitLockTenureExceeded(lockDescriptors, currentTransactionConfig, stackTraceSnapshot)).build());
if (!lockResponse.wasSuccessful()) {
log.error("Timed out waiting while acquiring commit locks. Timeout was {} ms. " + "First ten required locks were {}.", SafeArg.of("acquireTimeoutMs", lockAcquireTimeoutMillis), SafeArg.of("numberOfDescriptors", lockDescriptors.size()), UnsafeArg.of("firstTenLockDescriptors", Iterables.limit(lockDescriptors, 10)));
throw new TransactionLockAcquisitionTimeoutException("Timed out while acquiring commit locks.");
}
return lockResponse.getToken();
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class AllNodesDisabledNamespacesUpdaterTest method doesNotDisableIfPingFailsOnOneNode.
@Test
public void doesNotDisableIfPingFailsOnOneNode() {
when(remote2.ping(any())).thenThrow(new SafeRuntimeException("unreachable"));
DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(ImmutableSet.of(NAMESPACE)));
assertThat(response).isEqualTo(DISABLE_FAILED_SUCCESSFULLY);
verify(remote1, never()).disable(any(), any());
verify(remote2, never()).disable(any(), any());
verify(localUpdater, never()).disable(any());
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class HikariCPConnectionManager method setPassword.
@Override
public void setPassword(String newPassword) {
Preconditions.checkNotNull(newPassword, "password cannot be null");
State localState = state;
if (localState.type == StateType.ZERO) {
synchronized (this) {
// need to check again in case init just happened
localState = state;
if (localState.type == StateType.ZERO) {
// the pool is not initialized, need to set password on the config object
internalSetPassword(newPassword, hikariConfig);
return;
}
}
}
if (localState.type == StateType.NORMAL) {
// pool is initialized, need to set password directly on the pool
internalSetPassword(newPassword, localState.dataSourcePool);
} else if (localState.type == StateType.CLOSED) {
throw new SafeRuntimeException("Hikari pool is closed", localState.closeTrace);
}
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class BasicSQL method handleInterruptions.
// Existing logging behaviour where the non stacktrace part has sufficed.
@SuppressWarnings("Slf4jThrowable")
public static PalantirSqlException handleInterruptions(long startTime, SQLException cause) throws PalantirSqlException {
SqlLoggers.SQL_EXCEPTION_LOG.debug("Caught SQLException", cause);
String message = cause.getMessage().trim();
// check for oracle and postgres
if (!message.contains(ORACLE_CANCEL_ERROR) && !message.contains(POSTGRES_CANCEL_ERROR)) {
throw PalantirSqlException.create(cause);
}
String elapsedTime = "N/A";
if (startTime > 0) {
// $NON-NLS-1$
elapsedTime = String.valueOf(System.currentTimeMillis() - startTime);
}
SqlLoggers.CANCEL_LOGGER.info(// $NON-NLS-1$
"We got an execution exception that was an interrupt, most likely from someone " + "incorrectly ignoring an interrupt. ", SafeArg.of("elapsedTime", elapsedTime), // $NON-NLS-1$
SafeArg.of("errorCode", cause.getErrorCode()), // $NON-NLS-1$
SafeArg.of("SQLState", cause.getSQLState()), new SafeRuntimeException("Just for a stack trace", cause));
Thread.currentThread().interrupt();
// $NON-NLS-1$
throw new PalantirInterruptedException("SQL call interrupted", cause);
}
Aggregations