2020-01-21 20:59:17 +03:00
|
|
|
/*
|
|
|
|
* 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 <glog/logging.h>
|
2020-01-22 06:40:14 +03:00
|
|
|
#include <variant>
|
|
|
|
#include "eden/fs/config/EdenConfig.h"
|
2020-01-21 20:59:17 +03:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
2020-01-22 06:40:14 +03:00
|
|
|
/**
|
|
|
|
* Indicates the key space is safe to clear at any moment. The key space's disk
|
|
|
|
* usage should be kept under the size specified by `cacheLimit`.
|
|
|
|
*/
|
|
|
|
struct Ephemeral {
|
|
|
|
ConfigSetting<uint64_t> EdenConfig::*cacheLimit;
|
2020-01-21 20:59:17 +03:00
|
|
|
};
|
|
|
|
|
2020-01-22 06:40:14 +03:00
|
|
|
/**
|
|
|
|
* Indicates the key space contains persistent data and should never be cleared.
|
|
|
|
*/
|
|
|
|
struct Persistent {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The key space is no longer used. It should be cleared on startup.
|
|
|
|
*/
|
|
|
|
struct Deprecated {};
|
|
|
|
|
|
|
|
using Persistence = std::variant<Ephemeral, Persistent, Deprecated>;
|
|
|
|
|
2020-01-21 20:59:17 +03:00
|
|
|
/**
|
|
|
|
* Which key space (and thus column family for the RocksDbLocalStore) should be
|
|
|
|
* used to store a specific key. The `name` value must be stable across builds
|
|
|
|
* as it is used to identify the table names in RocksDbLocalStore and
|
|
|
|
* SqliteLocalStore.
|
|
|
|
*/
|
|
|
|
struct KeySpaceRecord {
|
|
|
|
uint8_t index;
|
|
|
|
folly::StringPiece name;
|
|
|
|
Persistence persistence;
|
2020-01-21 21:22:40 +03:00
|
|
|
|
2020-01-22 06:40:14 +03:00
|
|
|
constexpr bool isEphemeral() const noexcept {
|
|
|
|
return std::holds_alternative<Ephemeral>(persistence);
|
|
|
|
}
|
|
|
|
|
2020-01-21 21:22:40 +03:00
|
|
|
constexpr bool isDeprecated() const noexcept {
|
2020-01-22 06:40:14 +03:00
|
|
|
return std::holds_alternative<Deprecated>(persistence);
|
2020-01-21 21:22:40 +03:00
|
|
|
}
|
2020-01-21 20:59:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class KeySpace {
|
|
|
|
public:
|
|
|
|
/* implicit */ constexpr KeySpace(const KeySpaceRecord& record)
|
|
|
|
: record_{&record} {}
|
|
|
|
|
|
|
|
/* implicit */ KeySpace(const KeySpaceRecord* record) : record_{record} {
|
|
|
|
CHECK_NOTNULL(record);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr const KeySpaceRecord* operator->() const {
|
|
|
|
return record_;
|
|
|
|
}
|
|
|
|
|
2020-01-22 06:40:14 +03:00
|
|
|
static constexpr KeySpaceRecord BlobFamily{
|
|
|
|
0,
|
|
|
|
"blob",
|
|
|
|
Ephemeral{&EdenConfig::localStoreBlobSizeLimit}};
|
|
|
|
static constexpr KeySpaceRecord BlobMetaDataFamily{
|
|
|
|
1,
|
|
|
|
"blobmeta",
|
|
|
|
Ephemeral{&EdenConfig::localStoreBlobMetaSizeLimit}};
|
2020-01-21 20:59:17 +03:00
|
|
|
// It is too costly to have trees be deleted by automatic
|
|
|
|
// background GC when there are programs that cause every
|
|
|
|
// tree in the repo to be fetched. Make ephemeral when GC
|
|
|
|
// is smarter and when Eden can more efficiently read from
|
|
|
|
// the hg cache. This would also be better if programs
|
|
|
|
// weren't scanning the entire repo for filenames, causing
|
|
|
|
// every tree to be loaded.
|
2020-01-22 06:40:14 +03:00
|
|
|
static constexpr KeySpaceRecord TreeFamily{2, "tree", Persistent{}};
|
2020-01-21 20:59:17 +03:00
|
|
|
// Proxy hashes are required to fetch objects from hg from a hash.
|
|
|
|
// Deleting them breaks re-importing after an inode is unloaded.
|
|
|
|
static constexpr KeySpaceRecord HgProxyHashFamily{3,
|
|
|
|
"hgproxyhash",
|
2020-01-22 06:40:14 +03:00
|
|
|
Persistent{}};
|
|
|
|
static constexpr KeySpaceRecord HgCommitToTreeFamily{
|
|
|
|
4,
|
|
|
|
"hgcommit2tree",
|
|
|
|
Ephemeral{&EdenConfig::localStoreHgCommit2TreeSizeLimit}};
|
|
|
|
static constexpr KeySpaceRecord BlobSizeFamily{5, "blobsize", Deprecated{}};
|
2020-01-21 20:59:17 +03:00
|
|
|
|
|
|
|
static constexpr const KeySpaceRecord* kAll[] = {&BlobFamily,
|
|
|
|
&BlobMetaDataFamily,
|
|
|
|
&TreeFamily,
|
|
|
|
&HgProxyHashFamily,
|
|
|
|
&HgCommitToTreeFamily,
|
|
|
|
&BlobSizeFamily};
|
|
|
|
static constexpr size_t kTotalCount = std::size(kAll);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const KeySpaceRecord* record_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|