sapling/eden/fs/testharness/FakeObjectStore.cpp
Zeyi (Rice) Fan fff1c76996 make open calls from fuse high priority
Summary: This diff bumps the open call from FUSE to High priority (which is higher than any other blob open request atm). This has shown improvement on the user experience of EdenFS when it's importing many other things from other channels (thrift, etc.)

Reviewed By: chadaustin

Differential Revision: D20287389

fbshipit-source-id: 319bc44ef8be5c904d7cf0db7cc2f8be28b4760a
2020-03-17 02:31:25 -07:00

105 lines
2.9 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include "FakeObjectStore.h"
#include <folly/String.h>
#include <folly/futures/Future.h>
using folly::Future;
using folly::makeFuture;
using std::make_shared;
using std::shared_ptr;
namespace facebook {
namespace eden {
FakeObjectStore::FakeObjectStore() {}
FakeObjectStore::~FakeObjectStore() {}
void FakeObjectStore::addTree(Tree&& tree) {
auto treeHash = tree.getHash();
trees_.emplace(std::move(treeHash), std::move(tree));
}
void FakeObjectStore::addBlob(Blob&& blob) {
auto blobHash = blob.getHash();
blobs_.emplace(blobHash, std::move(blob));
}
void FakeObjectStore::setTreeForCommit(const Hash& commitID, Tree&& tree) {
auto ret = commits_.emplace(commitID, std::move(tree));
if (!ret.second) {
// Warn the caller that a Tree has already been specified for this commit,
// which is likely a logical error. If this turns out to be something that
// we want to do in a test, then we can change this behavior.
throw std::runtime_error(folly::to<std::string>(
"tree already added for commit with id ", commitID));
}
}
Future<std::shared_ptr<const Tree>> FakeObjectStore::getTree(
const Hash& id,
ObjectFetchContext&) const {
++accessCounts_[id];
auto iter = trees_.find(id);
if (iter == trees_.end()) {
return makeFuture<shared_ptr<const Tree>>(
std::domain_error("tree " + id.toString() + " not found"));
}
return makeFuture(make_shared<Tree>(iter->second));
}
Future<std::shared_ptr<const Blob>> FakeObjectStore::getBlob(
const Hash& id,
ObjectFetchContext&,
ImportPriority) const {
++accessCounts_[id];
auto iter = blobs_.find(id);
if (iter == blobs_.end()) {
return makeFuture<shared_ptr<const Blob>>(
std::domain_error("blob " + id.toString() + " not found"));
}
return makeFuture(make_shared<Blob>(iter->second));
}
Future<shared_ptr<const Tree>> FakeObjectStore::getTreeForCommit(
const Hash& commitID,
ObjectFetchContext&) const {
++accessCounts_[commitID];
auto iter = commits_.find(commitID);
if (iter == commits_.end()) {
return makeFuture<shared_ptr<const Tree>>(std::domain_error(
"tree data for commit " + commitID.toString() + " not found"));
}
return makeFuture(make_shared<Tree>(iter->second));
}
folly::Future<std::shared_ptr<const Tree>> FakeObjectStore::getTreeForManifest(
const Hash& commitID,
const Hash& /* manifestID */,
ObjectFetchContext&) const {
return getTreeForCommit(commitID);
}
folly::Future<folly::Unit> FakeObjectStore::prefetchBlobs(
const std::vector<Hash>&,
ObjectFetchContext&) const {
return folly::unit;
}
size_t FakeObjectStore::getAccessCount(const Hash& hash) const {
if (auto* item = folly::get_ptr(accessCounts_, hash)) {
return *item;
} else {
return 0;
}
}
} // namespace eden
} // namespace facebook