2018-11-26 21:44:26 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-11-26 21:44:26 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2018-11-26 21:44:26 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2018-11-26 21:44:26 +03:00
|
|
|
#include "eden/fs/store/BlobAccess.h"
|
|
|
|
#include <folly/MapUtil.h>
|
|
|
|
#include "eden/fs/model/Blob.h"
|
|
|
|
#include "eden/fs/store/BlobCache.h"
|
|
|
|
#include "eden/fs/store/IObjectStore.h"
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
BlobAccess::BlobAccess(
|
|
|
|
std::shared_ptr<IObjectStore> objectStore,
|
|
|
|
std::shared_ptr<BlobCache> blobCache)
|
|
|
|
: objectStore_{std::move(objectStore)}, blobCache_{std::move(blobCache)} {}
|
|
|
|
|
|
|
|
BlobAccess::~BlobAccess() {}
|
|
|
|
|
|
|
|
folly::Future<BlobCache::GetResult> BlobAccess::getBlob(
|
|
|
|
const Hash& hash,
|
2020-02-06 00:13:11 +03:00
|
|
|
ObjectFetchContext& context,
|
2020-07-02 21:58:46 +03:00
|
|
|
BlobCache::Interest interest) {
|
2018-11-26 21:44:26 +03:00
|
|
|
auto result = blobCache_->get(hash, interest);
|
2021-04-28 03:37:23 +03:00
|
|
|
if (result.object) {
|
2020-05-21 01:46:29 +03:00
|
|
|
return folly::Future<BlobCache::GetResult>{std::move(result)};
|
2018-11-26 21:44:26 +03:00
|
|
|
}
|
|
|
|
|
2020-07-02 21:58:46 +03:00
|
|
|
return objectStore_->getBlob(hash, context)
|
2020-02-06 00:13:11 +03:00
|
|
|
.thenValue([blobCache = blobCache_,
|
|
|
|
interest](std::shared_ptr<const Blob> blob) {
|
2018-11-26 21:44:26 +03:00
|
|
|
auto interestHandle = blobCache->insert(blob, interest);
|
|
|
|
return BlobCache::GetResult{std::move(blob), std::move(interestHandle)};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|