Search in sources :

Example 6 with SafeRuntimeException

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());
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Value(com.palantir.atlasdb.keyvalue.api.Value) Map(java.util.Map) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) LinkedList(java.util.LinkedList)

Example 7 with SafeRuntimeException

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();
}
Also used : AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) LockResponse(com.palantir.lock.v2.LockResponse) TransactionLockAcquisitionTimeoutException(com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException) TransactionConfig(com.palantir.atlasdb.transaction.TransactionConfig) LockRequest(com.palantir.lock.v2.LockRequest) ImmutableLockRequest(com.palantir.lock.v2.ImmutableLockRequest)

Example 8 with SafeRuntimeException

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());
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Test(org.junit.Test)

Example 9 with SafeRuntimeException

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);
    }
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException)

Example 10 with SafeRuntimeException

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);
}
Also used : PalantirInterruptedException(com.palantir.exception.PalantirInterruptedException) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) FinalSQLString(com.palantir.nexus.db.sql.BasicSQLString.FinalSQLString)

Aggregations

SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)43 IOException (java.io.IOException)13 Test (org.junit.jupiter.api.Test)7 Path (java.nio.file.Path)6 Response (com.palantir.dialogue.Response)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 TestResponse (com.palantir.dialogue.TestResponse)3 DefaultInvocationContext (com.palantir.tritium.event.DefaultInvocationContext)3 InvocationContext (com.palantir.tritium.event.InvocationContext)3 File (java.io.File)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Value (com.palantir.atlasdb.keyvalue.api.Value)2 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)2 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)2 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)2 Channel (com.palantir.dialogue.Channel)2