Move ThriftGlobImpl to ImmediateFuture

Reviewed By: xavierd

Differential Revision: D36677284

fbshipit-source-id: 08676a6d86990e9e397b722554651b409d5e4d4c
This commit is contained in:
Yipu Miao 2022-06-08 11:27:19 -07:00 committed by Facebook GitHub Bot
parent ac3bbf4798
commit cfbd29ecb5
6 changed files with 55 additions and 52 deletions

View File

@ -1868,8 +1868,8 @@ folly::SemiFuture<folly::Unit> EdenServiceHandler::semifuture_removeRecursively(
}
namespace {
folly::Future<std::unique_ptr<Glob>> detachIfBackgrounded(
folly::Future<std::unique_ptr<Glob>> globFuture,
ImmediateFuture<std::unique_ptr<Glob>> detachIfBackgrounded(
ImmediateFuture<std::unique_ptr<Glob>> globFuture,
const std::shared_ptr<ServerState>& serverState,
bool background) {
if (!background) {
@ -1877,13 +1877,13 @@ folly::Future<std::unique_ptr<Glob>> detachIfBackgrounded(
} else {
folly::futures::detachOn(
serverState->getThreadPool().get(), std::move(globFuture).semi());
return folly::makeFuture<std::unique_ptr<Glob>>(std::make_unique<Glob>());
return ImmediateFuture<std::unique_ptr<Glob>>(std::make_unique<Glob>());
}
}
} // namespace
folly::Future<std::unique_ptr<Glob>>
EdenServiceHandler::future_predictiveGlobFiles(
folly::SemiFuture<std::unique_ptr<Glob>>
EdenServiceHandler::semifuture_predictiveGlobFiles(
std::unique_ptr<GlobParams> params) {
#ifdef EDEN_HAVE_USAGE_SERVICE
ThriftGlobImpl globber{*params};
@ -1950,31 +1950,41 @@ EdenServiceHandler::future_predictiveGlobFiles(
bool background = *params->background();
auto future =
spServiceEndpoint_
->getTopUsedDirs(
user, repo, numResults, os, startTime, endTime, sandcastleAlias)
ImmediateFuture{spServiceEndpoint_
->getTopUsedDirs(
user,
repo,
numResults,
os,
startTime,
endTime,
sandcastleAlias)
.semi()}
.thenValue([globber = std::move(globber),
edenMount = std::move(edenMount),
serverState,
&fetchContext](std::vector<std::string>&& globs) mutable {
return globber.glob(edenMount, serverState, globs, fetchContext);
})
.thenError([](folly::exception_wrapper&& ew) {
XLOG(ERR) << "Error fetching predictive file globs: "
<< folly::exceptionStr(ew);
return makeFuture<std::unique_ptr<Glob>>(std::move(ew));
})
.ensure(
[params = std::move(params), helper = std::move(helper)]() {});
return detachIfBackgrounded(std::move(future), serverState, background);
.thenTry([params = std::move(params), helper = std::move(helper)](
folly::Try<std::unique_ptr<Glob>> tryGlob) {
if (tryGlob.hasException()) {
auto& ew = tryGlob.exception();
XLOG(ERR) << "Error fetching predictive file globs: "
<< folly::exceptionStr(ew);
}
return tryGlob;
});
return detachIfBackgrounded(std::move(future), serverState, background)
.semi();
#else // !EDEN_HAVE_USAGE_SERVICE
(void)params;
NOT_IMPLEMENTED();
#endif // !EDEN_HAVE_USAGE_SERVICE
}
folly::Future<std::unique_ptr<Glob>> EdenServiceHandler::future_globFiles(
std::unique_ptr<GlobParams> params) {
folly::SemiFuture<std::unique_ptr<Glob>>
EdenServiceHandler::semifuture_globFiles(std::unique_ptr<GlobParams> params) {
ThriftGlobImpl globber{*params};
auto helper = INSTRUMENT_THRIFT_CALL_WITH_FUNCTION_NAME_AND_PID(
DBG3,
@ -1993,7 +2003,10 @@ folly::Future<std::unique_ptr<Glob>> EdenServiceHandler::future_globFiles(
context)
.ensure([helper = std::move(helper)] {});
return detachIfBackgrounded(
std::move(globFut), server_->getServerState(), *params->background());
std::move(globFut),
server_->getServerState(),
*params->background())
.semi();
}
folly::Future<Unit> EdenServiceHandler::future_chown(

View File

@ -140,10 +140,10 @@ class EdenServiceHandler : virtual public StreamingEdenServiceSvIf,
semifuture_getAttributesFromFiles(
std::unique_ptr<GetAttributesFromFilesParams> params) override;
folly::Future<std::unique_ptr<Glob>> future_globFiles(
folly::SemiFuture<std::unique_ptr<Glob>> semifuture_globFiles(
std::unique_ptr<GlobParams> params) override;
folly::Future<std::unique_ptr<Glob>> future_predictiveGlobFiles(
folly::SemiFuture<std::unique_ptr<Glob>> semifuture_predictiveGlobFiles(
std::unique_ptr<GlobParams> params) override;
folly::Future<folly::Unit> future_chown(

View File

@ -32,7 +32,7 @@ ThriftGlobImpl::ThriftGlobImpl(const GlobParams& params)
rootHashes_{*params.revisions_ref()},
searchRootUser_{*params.searchRoot_ref()} {}
folly::Future<std::unique_ptr<Glob>> ThriftGlobImpl::glob(
ImmediateFuture<std::unique_ptr<Glob>> ThriftGlobImpl::glob(
std::shared_ptr<EdenMount> edenMount,
std::shared_ptr<ServerState> serverState,
std::vector<std::string> globs,
@ -65,7 +65,7 @@ folly::Future<std::unique_ptr<Glob>> ThriftGlobImpl::glob(
// Globs will be evaluated against the specified commits or the current commit
// if none are specified. The results will be collected here.
std::vector<folly::Future<folly::Unit>> globFutures{};
std::vector<ImmediateFuture<folly::Unit>> globFutures{};
auto globResults = std::make_shared<GlobNode::ResultList>();
RelativePath searchRoot;
@ -85,8 +85,6 @@ folly::Future<std::unique_ptr<Glob>> ThriftGlobImpl::glob(
globFutures.emplace_back(
edenMount->getObjectStore()
->getRootTree(originRootId, fetchContext)
.semi()
.via(&folly::QueuedImmediateExecutor::instance())
.thenValue([edenMount, globRoot, &fetchContext, searchRoot](
std::shared_ptr<const Tree>&& rootTree) {
return resolveTree(
@ -102,16 +100,14 @@ folly::Future<std::unique_ptr<Glob>> ThriftGlobImpl::glob(
fileBlobsToPrefetch,
globResults,
&originRootId](std::shared_ptr<const Tree>&& tree) mutable {
return globRoot
->evaluate(
edenMount->getObjectStore(),
fetchContext,
RelativePathPiece(),
std::move(tree),
fileBlobsToPrefetch.get(),
*globResults,
originRootId)
.semi();
return globRoot->evaluate(
edenMount->getObjectStore(),
fetchContext,
RelativePathPiece(),
std::move(tree),
fileBlobsToPrefetch.get(),
*globResults,
originRootId);
}));
}
} else {
@ -133,13 +129,11 @@ folly::Future<std::unique_ptr<Glob>> ThriftGlobImpl::glob(
fileBlobsToPrefetch.get(),
*globResults,
originRootId);
})
.semi()
.via(&folly::QueuedImmediateExecutor::instance()));
}));
}
auto prefetchFuture =
folly::collectAllUnsafe(std::move(globFutures))
collectAll(std::move(globFutures))
.thenValue([fileBlobsToPrefetch,
globResults = std::move(globResults),
suppressFileList = suppressFileList_](
@ -218,13 +212,11 @@ folly::Future<std::unique_ptr<Glob>> ThriftGlobImpl::glob(
futures.emplace_back(store->prefetchBlobs(range, fetchContext));
}
return collectAllSafe(std::move(futures))
return collectAll(std::move(futures))
.thenValue([glob = std::move(out), fileBlobsToPrefetch](
auto&&) mutable { return std::move(glob); })
.semi()
.via(&folly::QueuedImmediateExecutor::instance());
auto&&) mutable { return std::move(glob); });
}
return folly::makeFuture(std::move(out));
return ImmediateFuture{std::move(out)};
})
.ensure([globRoot, originRootIds = std::move(originRootIds)]() {
// keep globRoot and originRootIds alive until the end

View File

@ -12,7 +12,7 @@
#include <vector>
#include <folly/Range.h>
#include <folly/futures/Future.h>
#include "eden/fs/utils/ImmediateFuture.h"
namespace facebook::eden {
@ -26,7 +26,7 @@ class ThriftGlobImpl {
public:
explicit ThriftGlobImpl(const GlobParams& params);
folly::Future<std::unique_ptr<Glob>> glob(
ImmediateFuture<std::unique_ptr<Glob>> glob(
std::shared_ptr<EdenMount> edenMount,
std::shared_ptr<ServerState> serverState,
std::vector<std::string> globs,

View File

@ -21,7 +21,7 @@ struct ResolveTreeContext {
std::vector<PathComponent> components;
};
folly::Future<std::shared_ptr<const Tree>> resolveTree(
ImmediateFuture<std::shared_ptr<const Tree>> resolveTree(
std::shared_ptr<ResolveTreeContext> ctx,
ObjectStore& objectStore,
ObjectFetchContext& fetchContext,
@ -49,8 +49,6 @@ folly::Future<std::shared_ptr<const Tree>> resolveTree(
}
return objectStore.getTree(child->second.getHash(), fetchContext)
.semi()
.via(&folly::QueuedImmediateExecutor::instance())
.thenValue([ctx = std::move(ctx), &objectStore, &fetchContext, index](
std::shared_ptr<const Tree>&& tree) mutable {
return resolveTree(
@ -60,7 +58,7 @@ folly::Future<std::shared_ptr<const Tree>> resolveTree(
} // namespace
folly::Future<std::shared_ptr<const Tree>> resolveTree(
ImmediateFuture<std::shared_ptr<const Tree>> resolveTree(
ObjectStore& objectStore,
ObjectFetchContext& fetchContext,
std::shared_ptr<const Tree> root,

View File

@ -7,8 +7,8 @@
#pragma once
#include <folly/futures/Future.h>
#include "eden/fs/store/ObjectFetchContext.h"
#include "eden/fs/utils/ImmediateFuture.h"
#include "eden/fs/utils/PathFuncs.h"
namespace facebook::eden {
@ -17,7 +17,7 @@ class ObjectFetchContext;
class ObjectStore;
class Tree;
folly::Future<std::shared_ptr<const Tree>> resolveTree(
ImmediateFuture<std::shared_ptr<const Tree>> resolveTree(
ObjectStore& objectStore,
ObjectFetchContext& fetchContext,
std::shared_ptr<const Tree> root,