store: use ImmediateFuture in ObjectStore::getBlobSha1

Summary:
This allows the ImmediateFuture to be used as is in FileInode::getSha1 to
reduce the transition from folly::Future to ImmediateFuture

Reviewed By: chadaustin, kmancini

Differential Revision: D31667901

fbshipit-source-id: 3985e256d3c29c334d7e542ea8a2ce4e89528773
This commit is contained in:
Xavier Deguillard 2021-10-20 15:29:57 -07:00 committed by Facebook GitHub Bot
parent 81e1b6385e
commit ec28ba0065
5 changed files with 33 additions and 16 deletions

View File

@ -249,10 +249,15 @@ class ModifiedBlobDiffEntry : public DeferredDiffEntry {
currentBlobHash_{currentBlobHash} {}
folly::Future<folly::Unit> run() override {
auto f1 = context_->store->getBlobSha1(
scmEntry_.getHash(), context_->getFetchContext());
auto f2 = context_->store->getBlobSha1(
currentBlobHash_, context_->getFetchContext());
auto f1 =
context_->store
->getBlobSha1(scmEntry_.getHash(), context_->getFetchContext())
.semi()
.via(&folly::QueuedImmediateExecutor::instance());
auto f2 = context_->store
->getBlobSha1(currentBlobHash_, context_->getFetchContext())
.semi()
.via(&folly::QueuedImmediateExecutor::instance());
return collectSafe(f1, f2).thenValue(
[this](const std::tuple<Hash20, Hash20>& info) {
const auto& [info1, info2] = info;

View File

@ -597,7 +597,11 @@ folly::Future<bool> FileInode::isSameAs(
auto f1 = getSha1(fetchContext)
.semi()
.via(&folly::QueuedImmediateExecutor::instance());
auto f2 = getMount()->getObjectStore()->getBlobSha1(blobID, fetchContext);
auto f2 = getMount()
->getObjectStore()
->getBlobSha1(blobID, fetchContext)
.semi()
.via(&folly::QueuedImmediateExecutor::instance());
return folly::collectUnsafe(f1, f2).thenTry(
[](folly::Try<std::tuple<Hash20, Hash20>>&& try_) {
if (try_.hasException()) {
@ -692,9 +696,8 @@ ImmediateFuture<Hash20> FileInode::getSha1(ObjectFetchContext& fetchContext) {
case State::BLOB_NOT_LOADING:
case State::BLOB_LOADING:
// If a file is not materialized, it should have a hash value.
return getObjectStore()
->getBlobSha1(state->nonMaterializedState->hash, fetchContext)
.semi();
return getObjectStore()->getBlobSha1(
state->nonMaterializedState->hash, fetchContext);
case State::MATERIALIZED_IN_OVERLAY:
#ifdef _WIN32
return makeImmediateFutureWith(
@ -1084,7 +1087,7 @@ void FileInode::materializeNow(
state->nonMaterializedState->hash, *context);
std::optional<Hash20> blobSha1;
if (blobSha1Future.isReady()) {
blobSha1 = blobSha1Future.value();
blobSha1 = std::move(blobSha1Future).get();
}
getOverlayFileAccess(state)->createFile(getNodeId(), *blob, blobSha1);

View File

@ -560,10 +560,18 @@ void processBothPresent(
entryPath = currentPath + scmEntry.getName(),
&scmEntry,
&wdEntry] {
auto scmFuture = context->store->getBlobSha1(
scmEntry.getHash(), context->getFetchContext());
auto wdFuture = context->store->getBlobSha1(
wdEntry.getHash(), context->getFetchContext());
auto scmFuture =
context->store
->getBlobSha1(
scmEntry.getHash(), context->getFetchContext())
.semi()
.via(&folly::QueuedImmediateExecutor::instance());
auto wdFuture =
context->store
->getBlobSha1(
wdEntry.getHash(), context->getFetchContext())
.semi()
.via(&folly::QueuedImmediateExecutor::instance());
return collectSafe(scmFuture, wdFuture)
.thenValue([entryPath = entryPath.copy(),
context](const std::tuple<Hash20, Hash20>& info) {

View File

@ -314,11 +314,12 @@ Future<BlobMetadata> ObjectStore::getBlobMetadata(
});
}
Future<Hash20> ObjectStore::getBlobSha1(
ImmediateFuture<Hash20> ObjectStore::getBlobSha1(
const ObjectId& id,
ObjectFetchContext& context) const {
return getBlobMetadata(id, context)
.thenValue([](const BlobMetadata& metadata) { return metadata.sha1; });
.thenValue([](const BlobMetadata& metadata) { return metadata.sha1; })
.semi();
}
Future<uint64_t> ObjectStore::getBlobSize(

View File

@ -186,7 +186,7 @@ class ObjectStore : public IObjectStore,
/**
* Returns the SHA-1 hash of the contents of the blob with the given ID.
*/
folly::Future<Hash20> getBlobSha1(
ImmediateFuture<Hash20> getBlobSha1(
const ObjectId& id,
ObjectFetchContext& context) const;