use of com.apple.foundationdb.record.provider.foundationdb.SubspaceProvider in project fdb-record-layer by FoundationDB.
the class ReadVersionRecordStoreStateCache method get.
@Nonnull
@Override
public CompletableFuture<FDBRecordStoreStateCacheEntry> get(@Nonnull FDBRecordStore recordStore, @Nonnull FDBRecordStoreBase.StoreExistenceCheck existenceCheck) {
final FDBRecordContext context = recordStore.getContext();
validateContext(context);
if (context.hasDirtyStoreState()) {
// If a store info header has been modified during the course of this transaction's run,
// don't go to the cache as its results may be stale.
context.increment(FDBStoreTimer.Counts.STORE_STATE_CACHE_MISS);
return FDBRecordStoreStateCacheEntry.load(recordStore, existenceCheck);
} else {
return context.getReadVersionAsync().thenCompose(readVersion -> {
final SubspaceProvider subspaceProvider = recordStore.getSubspaceProvider();
CompletableFuture<FDBRecordStoreStateCacheEntry> storeStateFuture = cache.orElseGet(Pair.of(subspaceProvider, readVersion), () -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(KeyValueLogMessage.of("store state cache miss", subspaceProvider.logKey(), subspaceProvider.toString(context), LogMessageKeys.READ_VERSION, readVersion));
}
context.increment(FDBStoreTimer.Counts.STORE_STATE_CACHE_MISS);
return FDBRecordStoreStateCacheEntry.load(recordStore, existenceCheck);
}).thenCompose(storeState -> storeState.handleCachedState(context, existenceCheck).thenApply(vignore -> storeState));
if (context.getTimer() != null && MoreAsyncUtil.isCompletedNormally(storeStateFuture)) {
context.increment(FDBStoreTimer.Counts.STORE_STATE_CACHE_HIT);
}
return storeStateFuture;
});
}
}
use of com.apple.foundationdb.record.provider.foundationdb.SubspaceProvider in project fdb-record-layer by FoundationDB.
the class MetaDataVersionStampStoreStateCache method get.
@Nonnull
@Override
public CompletableFuture<FDBRecordStoreStateCacheEntry> get(@Nonnull FDBRecordStore recordStore, @Nonnull FDBRecordStoreBase.StoreExistenceCheck existenceCheck) {
final FDBRecordContext context = recordStore.getContext();
validateContext(context);
if (context.hasDirtyStoreState()) {
recordStore.increment(FDBStoreTimer.Counts.STORE_STATE_CACHE_MISS);
return FDBRecordStoreStateCacheEntry.load(recordStore, existenceCheck);
}
final SubspaceProvider subspaceProvider = recordStore.getSubspaceProvider();
final FDBRecordStoreStateCacheEntry existingEntry = cache.getIfPresent(subspaceProvider);
if (existingEntry == null) {
recordStore.increment(FDBStoreTimer.Counts.STORE_STATE_CACHE_MISS);
return FDBRecordStoreStateCacheEntry.load(recordStore, existenceCheck).whenComplete((cacheEntry, err) -> {
if (err == null && cacheEntry.getRecordStoreState().getStoreHeader().getCacheable()) {
addToCache(subspaceProvider, cacheEntry);
}
});
} else {
return recordStore.getContext().getMetaDataVersionStampAsync(IsolationLevel.SNAPSHOT).thenCompose(metaDataVersionStamp -> {
if (metaDataVersionStamp == null || existingEntry.getMetaDataVersionStamp() == null || ByteArrayUtil.compareUnsigned(metaDataVersionStamp, existingEntry.getMetaDataVersionStamp()) != 0) {
recordStore.increment(FDBStoreTimer.Counts.STORE_STATE_CACHE_MISS);
return FDBRecordStoreStateCacheEntry.load(recordStore, existenceCheck).whenComplete((cacheEntry, err) -> {
if (err == null && metaDataVersionStamp != null) {
if (cacheEntry.getRecordStoreState().getStoreHeader().getCacheable()) {
addToCache(subspaceProvider, cacheEntry);
} else {
invalidateOlderEntry(subspaceProvider, metaDataVersionStamp);
}
}
});
} else {
recordStore.increment(FDBStoreTimer.Counts.STORE_STATE_CACHE_HIT);
return existingEntry.handleCachedState(context, existenceCheck).thenApply(ignore -> existingEntry);
}
});
}
}
Aggregations