Skip to content

Commit 134a06d

Browse files
muirdmfacebook-github-bot
authored andcommitted
backingstore: use nullptr for aux-not-found
Summary: Use nullptr intead of exceptions to represent the low level "not found" state for file and tree aux data. liubov-dmitrieva discovered through profiling that we spend a lot of CPU time on exceptions. In particular, we first try a local-only fetch, and if the aux data doesn't exist, we raise an exception and then enqueue the aux data to be fetched in allow-remote mode. I changed the low level SaplingNativeBackingStore::get{Blob,Tree}AuxData to use nullptr to mean not-found, and then updated callers. Note that I did not change the batch aux codepaths. Since these typically fetch remotely, "not found" results are not expected (so it is okay to keep using exceptions). Reviewed By: liubov-dmitrieva Differential Revision: D67545966 fbshipit-source-id: 73e8fa7a2584192faa13295870bff6c38eec0727
1 parent 06bd894 commit 134a06d

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

eden/fs/store/hg/SaplingBackingStore.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ SaplingBackingStore::getTreeAuxData(
11691169
ObjectFetchContext::ObjectType::TreeAuxData);
11701170

11711171
auto auxData = getLocalTreeAuxData(proxyHash);
1172-
if (auxData.hasValue()) {
1172+
if (auxData.hasValue() && auxData.value()) {
11731173
stats_->increment(&SaplingBackingStoreStats::fetchTreeAuxDataSuccess);
11741174
stats_->increment(&SaplingBackingStoreStats::fetchTreeAuxDataLocal);
11751175
return folly::makeSemiFuture(GetTreeAuxResult{
@@ -1241,10 +1241,14 @@ folly::Try<TreeAuxDataPtr> SaplingBackingStore::getLocalTreeAuxData(
12411241
using GetTreeAuxDataResult = folly::Try<TreeAuxDataPtr>;
12421242

12431243
if (auxData.hasValue()) {
1244-
return GetTreeAuxDataResult{
1245-
std::make_shared<TreeAuxDataPtr::element_type>(TreeAuxData{
1246-
Hash32{std::move(auxData.value()->digest_hash)},
1247-
auxData.value()->digest_size})};
1244+
if (auxData.value()) {
1245+
return GetTreeAuxDataResult{
1246+
std::make_shared<TreeAuxDataPtr::element_type>(TreeAuxData{
1247+
Hash32{std::move(auxData.value()->digest_hash)},
1248+
auxData.value()->digest_size})};
1249+
} else {
1250+
return GetTreeAuxDataResult{nullptr};
1251+
}
12481252
} else {
12491253
return GetTreeAuxDataResult{auxData.exception()};
12501254
}
@@ -1495,7 +1499,7 @@ SaplingBackingStore::getBlobAuxData(
14951499
ObjectFetchContext::ObjectType::BlobAuxData);
14961500

14971501
auto auxData = getLocalBlobAuxData(proxyHash);
1498-
if (auxData.hasValue()) {
1502+
if (auxData.hasValue() && auxData.value()) {
14991503
stats_->increment(&SaplingBackingStoreStats::fetchBlobAuxDataSuccess);
15001504
stats_->increment(&SaplingBackingStoreStats::fetchBlobAuxDataLocal);
15011505
return folly::makeSemiFuture(GetBlobAuxResult{
@@ -1572,11 +1576,15 @@ folly::Try<BlobAuxDataPtr> SaplingBackingStore::getLocalBlobAuxData(
15721576
using GetBlobAuxDataResult = folly::Try<BlobAuxDataPtr>;
15731577

15741578
if (auxData.hasValue()) {
1575-
return GetBlobAuxDataResult{
1576-
std::make_shared<BlobAuxDataPtr::element_type>(BlobAuxData{
1577-
Hash20{std::move(auxData.value()->content_sha1)},
1578-
Hash32{std::move(auxData.value()->content_blake3)},
1579-
auxData.value()->total_size})};
1579+
if (auxData.value()) {
1580+
return GetBlobAuxDataResult{
1581+
std::make_shared<BlobAuxDataPtr::element_type>(BlobAuxData{
1582+
Hash20{std::move(auxData.value()->content_sha1)},
1583+
Hash32{std::move(auxData.value()->content_blake3)},
1584+
auxData.value()->total_size})};
1585+
} else {
1586+
return GetBlobAuxDataResult{nullptr};
1587+
}
15801588
} else {
15811589
return GetBlobAuxDataResult{auxData.exception()};
15821590
}

eden/scm/lib/backingstore/src/SaplingNativeBackingStore.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,10 @@ SaplingNativeBackingStore::getTreeAuxData(NodeId node, bool local) {
118118
"Importing tree aux data node={} from hgcache",
119119
folly::hexlify(node));
120120
return folly::makeTryWith([&] {
121-
auto auxData = sapling_backingstore_get_tree_aux(
121+
return sapling_backingstore_get_tree_aux(
122122
*store_.get(),
123123
rust::Slice<const uint8_t>{node.data(), node.size()},
124124
fetch_mode);
125-
XCHECK(
126-
auxData.get(),
127-
"sapling_backingstore_get_tree_aux returned a nullptr, but did not throw an exception.");
128-
return auxData;
129125
});
130126
}
131127

@@ -220,14 +216,10 @@ SaplingNativeBackingStore::getBlobAuxData(NodeId node, bool local) {
220216
"Importing blob aux data node={} from hgcache",
221217
folly::hexlify(node));
222218
return folly::makeTryWith([&] {
223-
auto auxData = sapling_backingstore_get_file_aux(
219+
return sapling_backingstore_get_file_aux(
224220
*store_.get(),
225221
rust::Slice<const uint8_t>{node.data(), node.size()},
226222
fetch_mode);
227-
XCHECK(
228-
auxData.get(),
229-
"sapling_backingstore_get_file_aux returned a nullptr, but did not throw an exception.");
230-
return auxData;
231223
});
232224
}
233225

eden/scm/lib/backingstore/src/ffi.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,10 @@ pub fn sapling_backingstore_get_tree_aux(
303303
node: &[u8],
304304
fetch_mode: ffi::FetchMode,
305305
) -> Result<SharedPtr<ffi::TreeAuxData>> {
306-
Ok(SharedPtr::new(
307-
store
308-
.get_tree_aux(node, FetchMode::from(fetch_mode))
309-
.and_then(|opt| opt.ok_or_else(|| Error::msg("no tree aux data found")))?
310-
.into(),
311-
))
306+
match store.get_tree_aux(node, FetchMode::from(fetch_mode))? {
307+
Some(aux) => Ok(SharedPtr::new(aux.into())),
308+
None => Ok(SharedPtr::null()),
309+
}
312310
}
313311

314312
pub fn sapling_backingstore_get_tree_aux_batch(
@@ -373,12 +371,10 @@ pub fn sapling_backingstore_get_file_aux(
373371
node: &[u8],
374372
fetch_mode: ffi::FetchMode,
375373
) -> Result<SharedPtr<ffi::FileAuxData>> {
376-
Ok(SharedPtr::new(
377-
store
378-
.get_file_aux(node, FetchMode::from(fetch_mode))
379-
.and_then(|opt| opt.ok_or_else(|| Error::msg("no file aux data found")))?
380-
.into(),
381-
))
374+
match store.get_file_aux(node, FetchMode::from(fetch_mode))? {
375+
Some(aux) => Ok(SharedPtr::new(aux.into())),
376+
None => Ok(SharedPtr::null()),
377+
}
382378
}
383379

384380
pub fn sapling_backingstore_get_file_aux_batch(

0 commit comments

Comments
 (0)