mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
make HgProxyHash::getBatch return HgProxyHash instead of pair
Summary: It's a little weird to have get batch returns a pair of `RelativePath` and `Hash`. Reviewed By: chadaustin Differential Revision: D20844545 fbshipit-source-id: c0c823e0aca6ea2326cb637226dc0de43fd4f3cd
This commit is contained in:
parent
81eb3a1549
commit
5758b21cde
@ -735,12 +735,11 @@ SemiFuture<folly::Unit> HgBackingStore::prefetchBlobs(
|
||||
const std::vector<Hash>& ids) {
|
||||
return HgProxyHash::getBatch(localStore_, ids)
|
||||
.via(importThreadPool_.get())
|
||||
.thenValue(
|
||||
[&liveImportPrefetchWatches = liveImportPrefetchWatches_](
|
||||
std::vector<std::pair<RelativePath, Hash>>&& hgPathHashes) {
|
||||
RequestMetricsScope queueTracker{&liveImportPrefetchWatches};
|
||||
return getThreadLocalImporter().prefetchFiles(hgPathHashes);
|
||||
})
|
||||
.thenValue([&liveImportPrefetchWatches = liveImportPrefetchWatches_](
|
||||
std::vector<HgProxyHash>&& hgPathHashes) {
|
||||
RequestMetricsScope queueTracker{&liveImportPrefetchWatches};
|
||||
return getThreadLocalImporter().prefetchFiles(hgPathHashes);
|
||||
})
|
||||
.via(serverThreadPool_);
|
||||
}
|
||||
|
||||
|
@ -386,8 +386,7 @@ unique_ptr<Blob> HgImporter::importFileContents(
|
||||
return make_unique<Blob>(blobHash, std::move(buf));
|
||||
}
|
||||
|
||||
void HgImporter::prefetchFiles(
|
||||
const std::vector<std::pair<RelativePath, Hash>>& files) {
|
||||
void HgImporter::prefetchFiles(const std::vector<HgProxyHash>& files) {
|
||||
auto requestID = sendPrefetchFilesRequest(files);
|
||||
|
||||
// Read the response; throws if there was any error.
|
||||
@ -553,7 +552,7 @@ HgImporter::TransactionID HgImporter::sendFileRequest(
|
||||
}
|
||||
|
||||
HgImporter::TransactionID HgImporter::sendPrefetchFilesRequest(
|
||||
const std::vector<std::pair<RelativePath, Hash>>& files) {
|
||||
const std::vector<HgProxyHash>& files) {
|
||||
stats_->getHgImporterStatsForCurrentThread().prefetchFiles.addValue(1);
|
||||
|
||||
auto txnID = nextRequestID_++;
|
||||
@ -564,8 +563,8 @@ HgImporter::TransactionID HgImporter::sendPrefetchFilesRequest(
|
||||
|
||||
// Compute the length of the body
|
||||
size_t dataLength = sizeof(uint32_t);
|
||||
for (const auto& pair : files) {
|
||||
dataLength += sizeof(uint32_t) + pair.first.stringPiece().size() +
|
||||
for (const auto& file : files) {
|
||||
dataLength += sizeof(uint32_t) + file.path().stringPiece().size() +
|
||||
(Hash::RAW_SIZE * 2);
|
||||
}
|
||||
if (dataLength > std::numeric_limits<uint32_t>::max()) {
|
||||
@ -584,17 +583,17 @@ HgImporter::TransactionID HgImporter::sendPrefetchFilesRequest(
|
||||
IOBuf buf(IOBuf::CREATE, dataLength);
|
||||
Appender appender(&buf, 0);
|
||||
appender.writeBE<uint32_t>(folly::to_narrow(files.size()));
|
||||
for (const auto& pair : files) {
|
||||
auto fileName = pair.first.stringPiece();
|
||||
for (const auto& file : files) {
|
||||
auto fileName = file.path().stringPiece();
|
||||
appender.writeBE<uint32_t>(folly::to_narrow(fileName.size()));
|
||||
}
|
||||
for (const auto& pair : files) {
|
||||
auto fileName = pair.first.stringPiece();
|
||||
for (const auto& file : files) {
|
||||
auto fileName = file.path().stringPiece();
|
||||
appender.push(fileName);
|
||||
// TODO: It would be nice to have a function that can hexlify the hash
|
||||
// data directly into the IOBuf without making a copy in a temporary string.
|
||||
// This isn't really that big of a deal though.
|
||||
appender.push(StringPiece(pair.second.toString()));
|
||||
appender.push(StringPiece(file.revHash().toString()));
|
||||
}
|
||||
DCHECK_EQ(buf.length(), dataLength);
|
||||
|
||||
@ -769,8 +768,7 @@ unique_ptr<Blob> HgImporterManager::importFileContents(
|
||||
});
|
||||
}
|
||||
|
||||
void HgImporterManager::prefetchFiles(
|
||||
const std::vector<std::pair<RelativePath, Hash>>& files) {
|
||||
void HgImporterManager::prefetchFiles(const std::vector<HgProxyHash>& files) {
|
||||
return retryOnError(
|
||||
[&](HgImporter* importer) { return importer->prefetchFiles(files); });
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ class Hash;
|
||||
class HgManifestImporter;
|
||||
class StoreResult;
|
||||
class Tree;
|
||||
class HgProxyHash;
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef HANDLE edenfd_t;
|
||||
@ -93,8 +94,7 @@ class Importer {
|
||||
RelativePathPiece path,
|
||||
Hash blobHash) = 0;
|
||||
|
||||
virtual void prefetchFiles(
|
||||
const std::vector<std::pair<RelativePath, Hash>>& files) = 0;
|
||||
virtual void prefetchFiles(const std::vector<HgProxyHash>& files) = 0;
|
||||
|
||||
/**
|
||||
* Import tree and store it in the datapack
|
||||
@ -140,8 +140,7 @@ class HgImporter : public Importer {
|
||||
std::unique_ptr<Blob> importFileContents(
|
||||
RelativePathPiece path,
|
||||
Hash blobHash) override;
|
||||
void prefetchFiles(
|
||||
const std::vector<std::pair<RelativePath, Hash>>& files) override;
|
||||
void prefetchFiles(const std::vector<HgProxyHash>& files) override;
|
||||
void fetchTree(RelativePathPiece path, Hash pathManifestNode) override;
|
||||
|
||||
const ImporterOptions& getOptions() const;
|
||||
@ -267,8 +266,7 @@ class HgImporter : public Importer {
|
||||
// Note: intentional RelativePath rather than RelativePathPiece here because
|
||||
// HgProxyHash is not movable and it was less work to make a copy here than
|
||||
// to implement its move constructor :-p
|
||||
TransactionID sendPrefetchFilesRequest(
|
||||
const std::vector<std::pair<RelativePath, Hash>>& files);
|
||||
TransactionID sendPrefetchFilesRequest(const std::vector<HgProxyHash>& files);
|
||||
|
||||
#ifndef _WIN32
|
||||
folly::Subprocess helper_;
|
||||
@ -324,8 +322,7 @@ class HgImporterManager : public Importer {
|
||||
std::unique_ptr<Blob> importFileContents(
|
||||
RelativePathPiece path,
|
||||
Hash blobHash) override;
|
||||
void prefetchFiles(
|
||||
const std::vector<std::pair<RelativePath, Hash>>& files) override;
|
||||
void prefetchFiles(const std::vector<HgProxyHash>& files) override;
|
||||
void fetchTree(RelativePathPiece path, Hash pathManifestNode) override;
|
||||
|
||||
private:
|
||||
|
@ -41,7 +41,7 @@ HgProxyHash::HgProxyHash(
|
||||
validate(edenBlobHash);
|
||||
}
|
||||
|
||||
folly::Future<std::vector<std::pair<RelativePath, Hash>>> HgProxyHash::getBatch(
|
||||
folly::Future<std::vector<HgProxyHash>> HgProxyHash::getBatch(
|
||||
LocalStore* store,
|
||||
const std::vector<Hash>& blobHashes) {
|
||||
auto hashCopies = std::make_shared<std::vector<Hash>>(blobHashes);
|
||||
@ -51,13 +51,11 @@ folly::Future<std::vector<std::pair<RelativePath, Hash>>> HgProxyHash::getBatch(
|
||||
}
|
||||
return store->getBatch(KeySpace::HgProxyHashFamily, byteRanges)
|
||||
.thenValue([blobHashes = hashCopies](std::vector<StoreResult>&& data) {
|
||||
std::vector<std::pair<RelativePath, Hash>> results;
|
||||
std::vector<HgProxyHash> results;
|
||||
|
||||
for (size_t i = 0; i < blobHashes->size(); ++i) {
|
||||
HgProxyHash hgInfo(
|
||||
blobHashes->at(i), data[i], "prefetchFiles getBatch");
|
||||
|
||||
results.emplace_back(hgInfo.path().copy(), hgInfo.revHash());
|
||||
results.emplace_back(HgProxyHash{
|
||||
blobHashes->at(i), data[i], "prefetchFiles getBatch"});
|
||||
}
|
||||
|
||||
return results;
|
||||
|
@ -69,7 +69,7 @@ class HgProxyHash {
|
||||
|
||||
Hash revHash() const;
|
||||
|
||||
static folly::Future<std::vector<std::pair<RelativePath, Hash>>> getBatch(
|
||||
static folly::Future<std::vector<HgProxyHash>> getBatch(
|
||||
LocalStore* store,
|
||||
const std::vector<Hash>& blobHashes);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user