fix tree import when local store loses its cache

Summary:
If a GC ran at the same time as HgBackingStore imported a commit, the
import would fail. Rather than round-tripping the tree through the
LocalStore, just return it.

Reviewed By: genevievehelsel

Differential Revision: D19167798

fbshipit-source-id: eddb280def349483289d2e300a58eff3ad7416e1
This commit is contained in:
Chad Austin 2019-12-19 13:35:55 -08:00 committed by Facebook Github Bot
parent f6cfa5f229
commit 0d67cc3833
2 changed files with 11 additions and 14 deletions

View File

@ -655,7 +655,8 @@ std::unique_ptr<Tree> HgBackingStore::processTree(
return tree;
}
folly::Future<Hash> HgBackingStore::importTreeManifest(const Hash& commitId) {
folly::Future<std::unique_ptr<Tree>> HgBackingStore::importTreeManifest(
const Hash& commitId) {
return folly::via(
importThreadPool_.get(),
[commitId] {
@ -678,7 +679,7 @@ folly::Future<Hash> HgBackingStore::importTreeManifest(const Hash& commitId) {
HgProxyHash::store(info, batch.get());
batch->flush();
return tree->getHash();
return tree;
});
});
}
@ -820,20 +821,18 @@ folly::Future<unique_ptr<Tree>> HgBackingStore::getTreeForRootTreeImpl(
});
}
folly::Future<Hash> HgBackingStore::importManifest(Hash commitId) {
return importTreeManifest(commitId);
}
folly::SemiFuture<unique_ptr<Tree>> HgBackingStore::importTreeForCommit(
Hash commitID) {
return importManifest(commitID).thenValue(
[this, commitID](Hash rootTreeHash) {
return importTreeManifest(commitID).thenValue(
[this, commitID](std::unique_ptr<Tree> rootTree) {
XLOG(DBG1) << "imported mercurial commit " << commitID.toString()
<< " as tree " << rootTreeHash.toString();
<< " as tree " << rootTree->getHash().toString();
localStore_->put(
KeySpace::HgCommitToTreeFamily, commitID, rootTreeHash.getBytes());
return localStore_->getTree(rootTreeHash);
KeySpace::HgCommitToTreeFamily,
commitID,
rootTree->getHash().getBytes());
return rootTree;
});
}

View File

@ -88,7 +88,7 @@ class HgBackingStore : public BackingStore {
* Import the manifest for the specified revision using mercurial
* treemanifest data.
*/
folly::Future<Hash> importTreeManifest(const Hash& commitId);
folly::Future<std::unique_ptr<Tree>> importTreeManifest(const Hash& commitId);
private:
// Forbidden copy constructor and assignment operator
@ -188,8 +188,6 @@ class HgBackingStore : public BackingStore {
RelativePathPiece path,
LocalStore::WriteBatch* writeBatch);
folly::Future<Hash> importManifest(Hash commitId);
LocalStore* localStore_{nullptr};
std::shared_ptr<EdenStats> stats_;
// A set of threads owning HgImporter instances