sapling/eden/fs/store/BlobAccess.h
Chad Austin 0d634a1296 add a BlobAccess API for stateless blob reading
Summary: In support of making Eden's file access stateless, add a facade that connects the BlobCache and ObjectStore, allowing FileInode to fetch blobs, minimizing reloads and memory usage.

Reviewed By: strager

Differential Revision: D10850143

fbshipit-source-id: 4307f7c1143aecad1284ea3cadf3e4efca9a3925
2018-11-26 10:46:51 -08:00

73 lines
2.3 KiB
C++

/*
* Copyright (c) 2018-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#pragma once
#include <folly/futures/Future.h>
#include <memory>
#include "eden/fs/store/BlobCache.h"
namespace facebook {
namespace eden {
class Blob;
class Hash;
class IObjectStore;
/**
* File access in Eden is stateless - we do not receive notifications from the
* kernel for open() and close(). However, it's inefficient to load blobs from
* cache for every read() request that makes into the edenfs process. Thus,
* centralize blob access through this interface.
*
* TODO: To support large files, they should be split into a series of blobs,
* and those blobs should get their own blob IDs, which could then be used
* in this API. Splitting large blobs into a series of smaller blobs has the
* benefit of helping bound Eden's memory usage here.
*/
class BlobAccess {
public:
/**
* Creates a new BlobAccess with specified cache parameters.
*
* - cacheSizeBytes attempts to restrict the number of blobs kept in memory to
* the specified number of bytes.
* - recentBlobCacheLength specifies how many recently-accessed blobs should
* be kept around, even if they are larger than cacheSizeBytes. This is
* important to avoid reloading large files.
*/
BlobAccess(
std::shared_ptr<IObjectStore> objectStore,
std::shared_ptr<BlobCache> blobCache);
~BlobAccess();
/**
* Loads and returns the entire blob's contents.
*
* If the accessPolicy is NotNeededAgain, the associated blob will not be
* cached.
*
* Returns both the blob and an interest handle from the BlobCache that can
* be dropped when the blob is no longer needed.
*/
folly::Future<BlobCache::GetResult> getBlob(
const Hash& hash,
BlobCache::Interest interest = BlobCache::Interest::LikelyNeededAgain);
private:
BlobAccess(const BlobAccess&) = delete;
BlobAccess& operator=(const BlobAccess&) = delete;
const std::shared_ptr<IObjectStore> objectStore_;
const std::shared_ptr<BlobCache> blobCache_;
};
} // namespace eden
} // namespace facebook