use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.
the class FDBRecordStore method rebuildIndex.
@Nonnull
// Resource usage for indexBuilder is too complicated for rule.
@SuppressWarnings("squid:S2095")
public CompletableFuture<Void> rebuildIndex(@Nonnull final Index index, @Nullable final Collection<RecordType> recordTypes, @Nonnull RebuildIndexReason reason) {
final boolean newStore = reason == RebuildIndexReason.NEW_STORE;
if (newStore ? LOGGER.isDebugEnabled() : LOGGER.isInfoEnabled()) {
final KeyValueLogMessage msg = KeyValueLogMessage.build("rebuilding index", LogMessageKeys.INDEX_NAME, index.getName(), LogMessageKeys.INDEX_VERSION, index.getLastModifiedVersion(), LogMessageKeys.REASON, reason.name(), subspaceProvider.logKey(), subspaceProvider.toString(context), LogMessageKeys.SUBSPACE_KEY, index.getSubspaceKey());
if (newStore) {
LOGGER.debug(msg.toString());
} else {
LOGGER.info(msg.toString());
}
}
long startTime = System.nanoTime();
OnlineIndexer indexBuilder = OnlineIndexer.newBuilder().setRecordStore(this).setIndex(index).setRecordTypes(recordTypes).build();
CompletableFuture<Void> future = indexBuilder.rebuildIndexAsync(this).thenCompose(vignore -> markIndexReadable(index)).handle((b, t) -> {
if (t != null) {
logExceptionAsWarn(KeyValueLogMessage.build("rebuilding index failed", LogMessageKeys.INDEX_NAME, index.getName(), LogMessageKeys.INDEX_VERSION, index.getLastModifiedVersion(), LogMessageKeys.REASON, reason.name(), subspaceProvider.logKey(), subspaceProvider.toString(context), LogMessageKeys.SUBSPACE_KEY, index.getSubspaceKey()), t);
}
// Only call method that builds in the current transaction, so never any pending work,
// so it would work to close before returning future, which would look better to SonarQube.
// But this is better if close ever does more.
indexBuilder.close();
return null;
});
return context.instrument(FDBStoreTimer.Events.REBUILD_INDEX, future, startTime);
}
use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.
the class FDBRecordStore method removeFormerIndex.
public void removeFormerIndex(FormerIndex formerIndex) {
if (LOGGER.isDebugEnabled()) {
KeyValueLogMessage msg = KeyValueLogMessage.build("removing index", subspaceProvider.logKey(), subspaceProvider.toString(context), LogMessageKeys.SUBSPACE_KEY, formerIndex.getSubspaceKey());
if (formerIndex.getFormerName() != null) {
msg.addKeyAndValue(LogMessageKeys.INDEX_NAME, formerIndex.getFormerName());
}
LOGGER.debug(msg.toString());
}
final long startTime = System.nanoTime();
Transaction tr = ensureContextActive();
tr.clear(getSubspace().range(Tuple.from(INDEX_KEY, formerIndex.getSubspaceTupleKey())));
tr.clear(getSubspace().range(Tuple.from(INDEX_SECONDARY_SPACE_KEY, formerIndex.getSubspaceTupleKey())));
tr.clear(getSubspace().range(Tuple.from(INDEX_RANGE_SPACE_KEY, formerIndex.getSubspaceTupleKey())));
tr.clear(getSubspace().pack(Tuple.from(INDEX_STATE_SPACE_KEY, formerIndex.getSubspaceTupleKey())));
tr.clear(getSubspace().range(Tuple.from(INDEX_UNIQUENESS_VIOLATIONS_KEY, formerIndex.getSubspaceTupleKey())));
if (getTimer() != null) {
getTimer().recordSinceNanoTime(FDBStoreTimer.Events.REMOVE_FORMER_INDEX, startTime);
}
}
use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.
the class FDBRecordStore method checkRebuildIndexes.
private CompletableFuture<Void> checkRebuildIndexes(@Nullable UserVersionChecker userVersionChecker, @Nonnull RecordMetaDataProto.DataStoreInfo.Builder info, int oldFormatVersion, @Nonnull RecordMetaData metaData, int oldMetaDataVersion, boolean rebuildRecordCounts, List<CompletableFuture<Void>> work) {
final boolean newStore = oldFormatVersion == 0;
final Map<Index, List<RecordType>> indexes = metaData.getIndexesToBuildSince(oldMetaDataVersion);
if (!indexes.isEmpty()) {
// If all the new indexes are only for a record type whose primary key has a type prefix, then we can scan less.
RecordType singleRecordTypeWithPrefixKey = singleRecordTypeWithPrefixKey(indexes);
final AtomicLong recordCountRef = new AtomicLong(-1);
final Supplier<CompletableFuture<Long>> lazyRecordCount = getAndRememberFutureLong(recordCountRef, () -> getRecordCountForRebuildIndexes(newStore, rebuildRecordCounts, indexes, singleRecordTypeWithPrefixKey));
AtomicLong recordsSizeRef = new AtomicLong(-1);
final Supplier<CompletableFuture<Long>> lazyRecordsSize = getAndRememberFutureLong(recordsSizeRef, () -> getRecordSizeForRebuildIndexes(singleRecordTypeWithPrefixKey));
if (singleRecordTypeWithPrefixKey == null && formatVersion >= SAVE_UNSPLIT_WITH_SUFFIX_FORMAT_VERSION && omitUnsplitRecordSuffix) {
// Check to see if the unsplit format can be upgraded on an empty store.
// Only works if singleRecordTypeWithPrefixKey is null as otherwise, the recordCount will not contain
// all records
work.add(lazyRecordCount.get().thenAccept(recordCount -> {
if (recordCount == 0) {
if (newStore ? LOGGER.isDebugEnabled() : LOGGER.isInfoEnabled()) {
KeyValueLogMessage msg = KeyValueLogMessage.build("upgrading unsplit format on empty store", LogMessageKeys.NEW_FORMAT_VERSION, formatVersion, subspaceProvider.logKey(), subspaceProvider.toString(context));
if (newStore) {
LOGGER.debug(msg.toString());
} else {
LOGGER.info(msg.toString());
}
}
omitUnsplitRecordSuffix = formatVersion < SAVE_UNSPLIT_WITH_SUFFIX_FORMAT_VERSION;
info.clearOmitUnsplitRecordSuffix();
// We used snapshot to determine emptiness, and are now acting on it.
addRecordsReadConflict();
}
}));
}
Map<Index, CompletableFuture<IndexState>> newStates = getStatesForRebuildIndexes(userVersionChecker, indexes, lazyRecordCount, lazyRecordsSize, newStore, oldMetaDataVersion, oldFormatVersion);
return rebuildIndexes(indexes, newStates, work, newStore ? RebuildIndexReason.NEW_STORE : RebuildIndexReason.FEW_RECORDS, oldMetaDataVersion).thenRun(() -> {
// Log after checking all index states
maybeLogIndexesNeedingRebuilding(newStates, recordCountRef, recordsSizeRef, rebuildRecordCounts, newStore);
context.increment(FDBStoreTimer.Counts.INDEXES_NEED_REBUILDING, newStates.entrySet().size());
});
} else {
return work.isEmpty() ? AsyncUtil.DONE : AsyncUtil.whenAll(work);
}
}
use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.
the class IndexingBase method buildIndexAsync.
// buildIndexAsync - the main indexing function. Builds and commits indexes asynchronously; throttling to avoid overloading the system.
public CompletableFuture<Void> buildIndexAsync(boolean markReadable) {
KeyValueLogMessage message = KeyValueLogMessage.build("build index online", LogMessageKeys.SHOULD_MARK_READABLE, markReadable).addKeysAndValues(indexingLogMessageKeyValues()).addKeysAndValues(common.indexLogMessageKeyValues());
final CompletableFuture<Void> buildIndexAsyncFuture;
FDBDatabaseRunner runner = common.getRunner();
Index index = common.getPrimaryIndex();
if (common.isUseSynchronizedSession()) {
buildIndexAsyncFuture = runner.runAsync(context -> openRecordStore(context).thenApply(store -> indexBuildLockSubspace(store, index)), common.indexLogMessageKeyValues("IndexingBase::indexBuildLockSubspace")).thenCompose(lockSubspace -> runner.startSynchronizedSessionAsync(lockSubspace, common.getLeaseLengthMillis())).thenCompose(synchronizedRunner -> {
message.addKeyAndValue(LogMessageKeys.SESSION_ID, synchronizedRunner.getSessionId());
return runWithSynchronizedRunnerAndEndSession(synchronizedRunner, () -> handleStateAndDoBuildIndexAsync(markReadable, message));
});
} else {
message.addKeyAndValue(LogMessageKeys.SESSION_ID, "none");
common.setSynchronizedSessionRunner(null);
buildIndexAsyncFuture = handleStateAndDoBuildIndexAsync(markReadable, message);
}
return buildIndexAsyncFuture.whenComplete((vignore, ex) -> {
if (LOGGER.isWarnEnabled() && (ex != null)) {
message.addKeyAndValue(LogMessageKeys.RESULT, "failure");
LOGGER.warn(message.toString(), ex);
} else if (LOGGER.isInfoEnabled()) {
message.addKeyAndValue(LogMessageKeys.RESULT, "success");
LOGGER.info(message.toString());
}
});
}
use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.
the class TransformedRecordSerializerTest method logMetrics.
private void logMetrics(@Nonnull String staticMessage, @Nullable Object... keysAndValues) {
KeyValueLogMessage message = KeyValueLogMessage.build(staticMessage, keysAndValues);
message.addKeysAndValues(storeTimer.getKeysAndValues());
LOGGER.info(message.toString());
resetTimer();
}
Aggregations