Search in sources :

Example 21 with KeyValueLogMessage

use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.

the class FDBDatabase method warnAndCloseOldTrackedOpenContexts.

/**
 * Log warning and close tracked contexts that have been open for too long.
 * @param minAgeSeconds number of seconds above which to warn
 * @return number of such contexts found
 */
@VisibleForTesting
public int warnAndCloseOldTrackedOpenContexts(long minAgeSeconds) {
    long nanoTime = System.nanoTime() - TimeUnit.SECONDS.toNanos(minAgeSeconds);
    if (trackedOpenContexts.isEmpty()) {
        return 0;
    }
    try {
        if (trackedOpenContexts.firstKey() > nanoTime) {
            return 0;
        }
    } catch (NoSuchElementException ex) {
        return 0;
    }
    int count = 0;
    for (FDBRecordContext context : trackedOpenContexts.headMap(nanoTime, true).values()) {
        KeyValueLogMessage msg = KeyValueLogMessage.build("context not closed", LogMessageKeys.AGE_SECONDS, TimeUnit.NANOSECONDS.toSeconds(nanoTime - context.getTrackOpenTimeNanos()), LogMessageKeys.TRANSACTION_ID, context.getTransactionId());
        if (context.getOpenStackTrace() != null) {
            LOGGER.warn(msg.toString(), context.getOpenStackTrace());
        } else {
            LOGGER.warn(msg.toString());
        }
        context.closeTransaction(true);
        count++;
    }
    return count;
}
Also used : NoSuchElementException(java.util.NoSuchElementException) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 22 with KeyValueLogMessage

use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.

the class MergeCursor method checkNextStateTimeout.

protected void checkNextStateTimeout(long startTime) {
    long checkStateTime = System.currentTimeMillis();
    if (checkStateTime - startTime > MAX_NEXT_STATE_MILLIS) {
        KeyValueLogMessage logMessage = KeyValueLogMessage.build("time computing next state exceeded", LogMessageKeys.TIME_STARTED, startTime * 1.0e-3, LogMessageKeys.TIME_ENDED, checkStateTime * 1.0e-3, LogMessageKeys.DURATION_MILLIS, checkStateTime - startTime, LogMessageKeys.CHILD_COUNT, cursorStates.size());
        if (LOGGER.isDebugEnabled()) {
            logMessage.addKeyAndValue("child_states", cursorStates.stream().map(cursorState -> "(future=" + cursorState.getOnNextFuture() + ", result=" + (cursorState.getResult() == null ? "null" : cursorState.getResult().hasNext()) + ", cursorClass=" + cursorState.getCursor().getClass().getName() + ")").collect(Collectors.toList()));
        }
        LOGGER.warn(logMessage.toString());
        throw new RecordCoreException("time computing next state exceeded");
    }
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage)

Aggregations

KeyValueLogMessage (com.apple.foundationdb.record.logging.KeyValueLogMessage)22 Index (com.apple.foundationdb.record.metadata.Index)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 Nonnull (javax.annotation.Nonnull)8 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)6 MoreAsyncUtil (com.apple.foundationdb.async.MoreAsyncUtil)6 IndexState (com.apple.foundationdb.record.IndexState)6 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)6 LogMessageKeys (com.apple.foundationdb.record.logging.LogMessageKeys)6 Tuple (com.apple.foundationdb.tuple.Tuple)6 Function (java.util.function.Function)6 Nullable (javax.annotation.Nullable)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Range (com.apple.foundationdb.Range)5 Transaction (com.apple.foundationdb.Transaction)5 API (com.apple.foundationdb.annotation.API)5 RangeSet (com.apple.foundationdb.async.RangeSet)5