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;
}
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");
}
}
Aggregations