Skip to content

Commit 70628d8

Browse files
janezhang10meta-codesync[bot]
authored andcommitted
Add EdenServiceHandler::co_getSHA1Impl
Summary: Add co_getSHA1Impl as a coroutine implementation of the getSHA1 thrift handler, plus a config-gated co_invoke bridge in semifuture_getSHA1. - Created co_getSHA1Impl following the co_getBlake3Impl pattern, using co_applyToVirtualInode with a .semi() bridge for VirtualInode::getSHA1 - Updated semifuture_getSHA1 with enableCoroutinesPhase6 config gate and co_invoke bridge - Preserves all side effects from the futures-based implementation Reviewed By: SBones Differential Revision: D103754393 fbshipit-source-id: 8245e1d4ca7f679e178b1a1fab5243b5ac21f106
1 parent dc8185c commit 70628d8

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

eden/fs/inodes/VirtualInodeLoader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ auto applyToVirtualInode(
280280
*
281281
* Both inode resolution and func application are parallelized: resolution
282282
* via the loader's tree-shaped plan, func via collectAllRange.
283+
*
284+
* CONTRACT: The result of invoking func is immediately co_awaited within the
285+
* same expression via co_awaitTry. This is critical when func returns
286+
* now_task<T>: now_task requires immediate awaiting to guarantee reference
287+
* safety for captured references. Do not store, move, or defer the result of
288+
* func.
283289
*/
284290
template <typename Func>
285291
folly::coro::now_task<std::vector<folly::Try<VirtualInodeResult<Func>>>>

eden/fs/service/EdenServiceHandler.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,11 +1343,73 @@ EdenServiceHandler::semifuture_getSHA1Impl(
13431343
.semi();
13441344
}
13451345

1346+
folly::coro::now_task<std::unique_ptr<std::vector<SHA1Result>>>
1347+
EdenServiceHandler::co_getSHA1Impl(
1348+
std::unique_ptr<std::string> mountPoint,
1349+
std::unique_ptr<std::vector<std::string>> paths,
1350+
std::unique_ptr<SyncBehavior> sync) {
1351+
TraceBlock block("getSHA1");
1352+
auto helper = INSTRUMENT_THRIFT_CALL(
1353+
DBG3, *mountPoint, getSyncTimeout(*sync), toLogArg(*paths));
1354+
auto& fetchContext = helper->getFetchContext();
1355+
auto mountHandle = lookupMount(mountPoint);
1356+
auto objectStore = mountHandle.getObjectStorePtr();
1357+
1358+
co_await co_waitForPendingWrites(mountHandle.getEdenMount(), *sync);
1359+
1360+
auto results = co_await co_applyToVirtualInode(
1361+
mountHandle.getRootInode(),
1362+
*paths,
1363+
[mountHandle, fetchContext = fetchContext.copy()](
1364+
VirtualInode inode,
1365+
RelativePath path) -> folly::coro::now_task<Hash20> {
1366+
co_return co_await inode
1367+
.getSHA1(path, mountHandle.getObjectStorePtr(), fetchContext)
1368+
.semi();
1369+
},
1370+
objectStore,
1371+
fetchContext);
1372+
1373+
auto out = std::make_unique<std::vector<SHA1Result>>();
1374+
out->reserve(results.size());
1375+
1376+
for (auto& result : results) {
1377+
auto& sha1Result = out->emplace_back();
1378+
if (result.hasValue()) {
1379+
sha1Result.sha1() = thriftHash20(result.value());
1380+
} else {
1381+
sha1Result.error() = newEdenError(result.exception());
1382+
}
1383+
}
1384+
1385+
co_return out;
1386+
}
1387+
13461388
folly::SemiFuture<std::unique_ptr<std::vector<SHA1Result>>>
13471389
EdenServiceHandler::semifuture_getSHA1(
13481390
std::unique_ptr<string> mountPoint,
13491391
std::unique_ptr<vector<string>> paths,
13501392
std::unique_ptr<SyncBehavior> sync) {
1393+
if (server_->getServerState()
1394+
->getEdenConfig()
1395+
->enableCoroutinesPhase6.getValue()) {
1396+
auto result = ImmediateFuture{
1397+
// @lint-ignore CLANGTIDY facebook-folly-coro-return-captures-local-var
1398+
folly::coro::co_invoke(
1399+
[self = shared_from_this()](
1400+
std::unique_ptr<std::string> mountPoint,
1401+
std::unique_ptr<std::vector<std::string>> paths,
1402+
std::unique_ptr<SyncBehavior> sync)
1403+
-> folly::coro::Task<std::unique_ptr<std::vector<SHA1Result>>> {
1404+
co_return co_await self->co_getSHA1Impl(
1405+
std::move(mountPoint), std::move(paths), std::move(sync));
1406+
},
1407+
std::move(mountPoint),
1408+
std::move(paths),
1409+
std::move(sync))
1410+
.semi()};
1411+
return std::move(result).semi();
1412+
}
13511413
return semifuture_getSHA1Impl(
13521414
std::move(mountPoint), std::move(paths), std::move(sync));
13531415
}

eden/fs/service/EdenServiceHandler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ class EdenServiceHandler
206206
std::unique_ptr<std::vector<std::string>> paths,
207207
std::unique_ptr<SyncBehavior> sync);
208208

209+
folly::coro::now_task<std::unique_ptr<std::vector<SHA1Result>>>
210+
co_getSHA1Impl(
211+
std::unique_ptr<std::string> mountPoint,
212+
std::unique_ptr<std::vector<std::string>> paths,
213+
std::unique_ptr<SyncBehavior> sync);
214+
209215
folly::SemiFuture<std::unique_ptr<std::vector<Blake3Result>>>
210216
semifuture_getBlake3(
211217
std::unique_ptr<std::string> mountPoint,

0 commit comments

Comments
 (0)