sapling/eden/fs/store/BackingStore.h
Chad Austin bb1cccac89 introduce a variable-width RootId type that identifies the root of an EdenFS checkout's contents
Summary:
Backing stores differentiate between individual tree objects and the
root of a checkout. For example, Git and Mercurial roots are commit
hashes. Allow EdenFS to track variable-width roots to better support
arbitrary backing stores.

Reviewed By: genevievehelsel

Differential Revision: D28619584

fbshipit-source-id: d94f1ecd21a0c416c1b4933341c70deabf386496
2021-06-07 17:25:31 -07:00

87 lines
2.4 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.
*/
#pragma once
#include <folly/Range.h>
#include <folly/futures/Future.h>
#include <memory>
#include "eden/fs/model/RootId.h"
#include "eden/fs/store/ImportPriority.h"
#include "eden/fs/store/ObjectFetchContext.h"
namespace folly {
template <typename T>
class Future;
}
namespace facebook::eden {
class Blob;
class Hash;
class Tree;
/**
* Abstract interface for a BackingStore.
*
* A BackingStore fetches tree and blob information from an external
* authoritative data source.
*
* BackingStore implementations must be thread-safe, and perform their own
* internal locking.
*/
class BackingStore : public RootIdCodec {
public:
BackingStore() {}
virtual ~BackingStore() {}
virtual folly::SemiFuture<std::unique_ptr<Tree>> getRootTree(
const RootId& rootId,
ObjectFetchContext& context) = 0;
virtual folly::SemiFuture<std::unique_ptr<Tree>> getTree(
const Hash& id,
ObjectFetchContext& context) = 0;
virtual folly::SemiFuture<std::unique_ptr<Blob>> getBlob(
const Hash& id,
ObjectFetchContext& context) = 0;
FOLLY_NODISCARD virtual folly::SemiFuture<folly::Unit> prefetchBlobs(
const std::vector<Hash>& /*ids*/,
ObjectFetchContext& /*context*/) {
return folly::unit;
}
virtual void periodicManagementTask() {}
/**
* Subclass of BackingStore will override these functions to record file paths
* fetched. By default, recordFetch() does nothing. After
* startRecordingFetch() is called, recordFetch() starts to records fetched
* file paths. stopRecordingFetch() will disable recordFetch()'s function and
* return the fetched files since startRecordingFetch() is called and clear
* the old records.
*
* Currently implemented in HgQueuedBackingStore.
*
* Note: Only stopRecordingFetch() clears old records. Calling
* startRecordingFetch() a second time has no effect.
*/
virtual void startRecordingFetch() {}
virtual void recordFetch(folly::StringPiece) {}
virtual std::unordered_set<std::string> stopRecordingFetch() {
return {};
}
private:
// Forbidden copy constructor and assignment operator
BackingStore(BackingStore const&) = delete;
BackingStore& operator=(BackingStore const&) = delete;
};
} // namespace facebook::eden