2016-06-14 01:15:32 +03:00
|
|
|
/*
|
2017-01-21 09:02:33 +03:00
|
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
2016-06-14 01:15:32 +03:00
|
|
|
* 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
|
|
|
|
|
2018-09-25 21:08:41 +03:00
|
|
|
#include "eden/fs/eden-config.h"
|
2016-06-14 01:15:32 +03:00
|
|
|
#include "eden/fs/store/BackingStore.h"
|
2018-09-25 21:08:41 +03:00
|
|
|
#include "eden/fs/store/LocalStore.h"
|
|
|
|
#include "eden/fs/store/mononoke/MononokeBackingStore.h"
|
2017-06-24 01:09:49 +03:00
|
|
|
#include "eden/fs/utils/PathFuncs.h"
|
2016-06-14 01:15:32 +03:00
|
|
|
|
2017-11-15 20:46:11 +03:00
|
|
|
#include <folly/Executor.h>
|
2016-06-14 01:15:32 +03:00
|
|
|
#include <folly/Range.h>
|
|
|
|
#include <folly/Synchronized.h>
|
2018-10-24 03:03:12 +03:00
|
|
|
#include <optional>
|
2016-06-14 01:15:32 +03:00
|
|
|
|
2018-09-25 21:08:41 +03:00
|
|
|
#if EDEN_HAVE_HG_TREEMANIFEST
|
|
|
|
/* forward declare support classes from mercurial */
|
|
|
|
class ConstantStringRef;
|
|
|
|
class DatapackStore;
|
|
|
|
class UnionDatapackStore;
|
|
|
|
#endif // EDEN_HAVE_HG_TREEMANIFEST
|
|
|
|
|
2016-06-14 01:15:32 +03:00
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
2018-09-25 21:08:41 +03:00
|
|
|
class Importer;
|
|
|
|
class ImporterOptions;
|
2016-06-14 01:15:32 +03:00
|
|
|
class LocalStore;
|
2018-08-03 23:08:37 +03:00
|
|
|
class UnboundedQueueExecutor;
|
2016-06-14 01:15:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A BackingStore implementation that loads data out of a mercurial repository.
|
|
|
|
*/
|
|
|
|
class HgBackingStore : public BackingStore {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a new HgBackingStore.
|
|
|
|
*
|
|
|
|
* The LocalStore object is owned by the EdenServer (which also owns this
|
|
|
|
* HgBackingStore object). It is guaranteed to be valid for the lifetime of
|
|
|
|
* the HgBackingStore object.
|
|
|
|
*/
|
2017-11-15 20:46:11 +03:00
|
|
|
HgBackingStore(
|
|
|
|
AbsolutePathPiece repository,
|
|
|
|
LocalStore* localStore,
|
2018-08-20 21:07:34 +03:00
|
|
|
UnboundedQueueExecutor* serverThreadPool,
|
2018-10-24 03:03:12 +03:00
|
|
|
std::optional<AbsolutePath> clientCertificate = std::nullopt,
|
2018-10-11 00:44:49 +03:00
|
|
|
bool useMononoke = false,
|
|
|
|
folly::StringPiece mononokeTierName = folly::StringPiece());
|
2018-06-07 00:32:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an HgBackingStore suitable for use in unit tests. It uses an inline
|
|
|
|
* executor to process loaded objects rather than the thread pools used in
|
|
|
|
* production Eden.
|
|
|
|
*/
|
|
|
|
HgBackingStore(Importer* importer, LocalStore* localStore);
|
|
|
|
|
2017-05-24 02:08:03 +03:00
|
|
|
~HgBackingStore() override;
|
2016-06-14 01:15:32 +03:00
|
|
|
|
2016-12-14 05:11:05 +03:00
|
|
|
folly::Future<std::unique_ptr<Tree>> getTree(const Hash& id) override;
|
|
|
|
folly::Future<std::unique_ptr<Blob>> getBlob(const Hash& id) override;
|
|
|
|
folly::Future<std::unique_ptr<Tree>> getTreeForCommit(
|
|
|
|
const Hash& commitID) override;
|
2018-06-15 07:32:45 +03:00
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> prefetchBlobs(
|
2018-05-25 23:47:49 +03:00
|
|
|
const std::vector<Hash>& ids) const override;
|
2018-08-24 00:12:10 +03:00
|
|
|
|
2018-09-25 21:08:41 +03:00
|
|
|
#if EDEN_HAVE_HG_TREEMANIFEST
|
|
|
|
/**
|
|
|
|
* Import the manifest for the specified revision using mercurial
|
|
|
|
* treemanifest data.
|
|
|
|
*/
|
|
|
|
folly::Future<Hash> importTreeManifest(const Hash& commitId);
|
|
|
|
#endif // EDEN_HAVE_HG_TREEMANIFEST
|
|
|
|
|
2016-06-14 01:15:32 +03:00
|
|
|
private:
|
|
|
|
// Forbidden copy constructor and assignment operator
|
|
|
|
HgBackingStore(HgBackingStore const&) = delete;
|
|
|
|
HgBackingStore& operator=(HgBackingStore const&) = delete;
|
|
|
|
|
2018-09-25 21:08:41 +03:00
|
|
|
/**
|
|
|
|
* Initialize the unionStore_ needed for treemanifest import support.
|
|
|
|
*
|
|
|
|
* This leaves unionStore_ null if treemanifest import is not supported in
|
|
|
|
* this repository.
|
|
|
|
*/
|
|
|
|
void initializeTreeManifestImport(
|
|
|
|
const ImporterOptions& options,
|
|
|
|
AbsolutePathPiece repoPath);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the mononoke_ needed for Mononoke API Server support.
|
|
|
|
*
|
|
|
|
* This leaves mononoke_ null if mononoke does not support the repository.
|
|
|
|
*/
|
|
|
|
void initializeMononoke(
|
|
|
|
const ImporterOptions& options,
|
|
|
|
bool useMononoke,
|
2018-10-24 03:03:12 +03:00
|
|
|
std::optional<AbsolutePath> clientCertificate,
|
2018-10-11 00:44:49 +03:00
|
|
|
folly::StringPiece tierName);
|
2018-09-25 21:08:41 +03:00
|
|
|
|
|
|
|
folly::Future<std::unique_ptr<Tree>> getTreeForCommitImpl(Hash commitID);
|
2016-12-14 05:11:05 +03:00
|
|
|
|
2018-07-09 21:57:54 +03:00
|
|
|
// Import the Tree from Hg and cache it in the LocalStore before returning it.
|
2018-09-25 21:08:41 +03:00
|
|
|
folly::Future<std::unique_ptr<Tree>> importTreeForCommit(Hash commitID);
|
|
|
|
|
|
|
|
#if EDEN_HAVE_HG_TREEMANIFEST
|
|
|
|
folly::Future<std::unique_ptr<Tree>> importTreeImpl(
|
|
|
|
const Hash& manifestNode,
|
|
|
|
const Hash& edenTreeID,
|
|
|
|
RelativePathPiece path,
|
|
|
|
std::shared_ptr<LocalStore::WriteBatch> writeBatch);
|
|
|
|
folly::Future<std::unique_ptr<Tree>> fetchTreeFromImporter(
|
|
|
|
Hash manifestNode,
|
|
|
|
Hash edenTreeID,
|
|
|
|
RelativePath path,
|
|
|
|
std::shared_ptr<LocalStore::WriteBatch> writeBatch);
|
|
|
|
std::unique_ptr<Tree> processTree(
|
|
|
|
ConstantStringRef& content,
|
|
|
|
const Hash& manifestNode,
|
|
|
|
const Hash& edenTreeID,
|
|
|
|
RelativePathPiece path,
|
|
|
|
LocalStore::WriteBatch* writeBatch);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
folly::Future<Hash> importManifest(Hash commitId);
|
|
|
|
|
|
|
|
folly::Future<Hash> importFlatManifest(Hash commitId);
|
2018-07-09 21:57:54 +03:00
|
|
|
|
2016-06-14 01:15:32 +03:00
|
|
|
LocalStore* localStore_{nullptr};
|
2017-11-15 20:46:11 +03:00
|
|
|
// A set of threads owning HgImporter instances
|
|
|
|
std::unique_ptr<folly::Executor> importThreadPool_;
|
|
|
|
// The main server thread pool; we push the Futures back into
|
|
|
|
// this pool to run their completion code to avoid clogging
|
2017-12-12 23:23:57 +03:00
|
|
|
// the importer pool. Queuing in this pool can never block (which would risk
|
|
|
|
// deadlock) or throw an exception when full (which would incorrectly fail the
|
|
|
|
// load).
|
2018-06-07 00:32:41 +03:00
|
|
|
folly::Executor* serverThreadPool_;
|
2018-09-25 21:08:41 +03:00
|
|
|
#if EDEN_HAVE_HG_TREEMANIFEST
|
|
|
|
// These DatapackStore objects are never referenced once UnionDatapackStore
|
|
|
|
// is allocated. They are here solely so their lifetime persists while the
|
|
|
|
// UnionDatapackStore is alive.
|
|
|
|
std::vector<std::unique_ptr<DatapackStore>> dataPackStores_;
|
|
|
|
std::unique_ptr<folly::Synchronized<UnionDatapackStore>> unionStore_;
|
|
|
|
|
2018-09-28 20:04:44 +03:00
|
|
|
#ifndef EDEN_WIN_NOMONONOKE
|
2018-09-25 21:08:41 +03:00
|
|
|
std::unique_ptr<MononokeBackingStore> mononoke_;
|
2018-09-28 20:04:44 +03:00
|
|
|
#endif // EDEN_WIN_NOMONONOKE
|
2018-09-25 21:08:41 +03:00
|
|
|
#endif // EDEN_HAVE_HG_TREEMANIFEST
|
2016-06-14 01:15:32 +03:00
|
|
|
};
|
2017-11-04 01:58:04 +03:00
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|