/* * 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 #include #include "eden/fs/store/ImportPriority.h" namespace folly { template class Future; struct Unit; } // namespace folly namespace facebook { namespace eden { class Blob; class BlobMetadata; class Hash; class Tree; /** * ObjectStore calls methods on this context when fetching objects. * It's primarily used to track when and why source control objects are fetched. */ class ObjectFetchContext { public: /** * Which object type was fetched. * * Suitable for use as an index into an array of size kObjectTypeEnumMax */ enum ObjectType : unsigned { Blob, BlobMetadata, Tree, kObjectTypeEnumMax, }; /** * Which cache satisfied a lookup request. * * Suitable for use as an index into an array of size kOriginEnumMax. */ enum Origin : unsigned { FromMemoryCache, FromDiskCache, FromBackingStore, kOriginEnumMax, }; ObjectFetchContext() = default; virtual ~ObjectFetchContext() = default; virtual void didFetch(ObjectType, const Hash&, Origin) {} /** * Return a no-op fetch context suitable when no tracking is desired. */ static ObjectFetchContext& getNullContext(); private: ObjectFetchContext(const ObjectFetchContext&) = delete; ObjectFetchContext& operator=(const ObjectFetchContext&) = delete; }; class IObjectStore { public: virtual ~IObjectStore() {} /* * Object access APIs. * * The given ObjectFetchContext must remain valid at least until the * resulting future is complete. */ virtual folly::Future> getTree( const Hash& id, ObjectFetchContext& context) const = 0; virtual folly::Future> getBlob( const Hash& id, ObjectFetchContext& context, ImportPriority priority = ImportPriority::kNormal()) const = 0; virtual folly::Future> getTreeForCommit( const Hash& commitID, ObjectFetchContext& context) const = 0; virtual folly::Future> getTreeForManifest( const Hash& commitID, const Hash& manifestID, ObjectFetchContext& context) const = 0; virtual folly::Future prefetchBlobs( const std::vector& ids, ObjectFetchContext& context) const = 0; }; } // namespace eden } // namespace facebook