sapling/eden/fs/config/ReloadableConfig.h
Katie Mancini 8a1a529fcc use custom in memory tree cache
Summary:
Chad first noted that deserializing trees from the local store can be expensive.
From the thrift side EdenFS does not have a copy of trees in memory. This
means for glob files each of the trees that have not been materialized will be
read from the local store. Since reading an deserializing trees from the local
store can be expensive lets add an in memory cache so that some of these
reads can be satisfied from here instead.

Here we actually start to use the cache!

Reviewed By: chadaustin

Differential Revision: D27050310

fbshipit-source-id: e35db193fea0af7f387b6f44c49b5bcc2a902858
2021-04-27 17:38:40 -07:00

61 lines
1.6 KiB
C++

/*
* 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 <chrono>
#include <memory>
#include <folly/Synchronized.h>
#include "eden/fs/config/gen-cpp2/eden_config_types.h"
namespace facebook {
namespace eden {
class EdenConfig;
/**
* An interface that defines how to obtain a possibly reloaded EdenConfig
* instance.
*/
class ReloadableConfig {
public:
explicit ReloadableConfig(std::shared_ptr<const EdenConfig> config);
ReloadableConfig(
std::shared_ptr<const EdenConfig> config,
ConfigReloadBehavior reload);
~ReloadableConfig();
/**
* Get the EdenConfig data.
*
* The config data may be reloaded from disk depending on the value of the
* reload parameter.
*/
std::shared_ptr<const EdenConfig> getEdenConfig(
ConfigReloadBehavior reload = ConfigReloadBehavior::AutoReload);
private:
struct ConfigState {
explicit ConfigState(const std::shared_ptr<const EdenConfig>& config)
: config{config} {}
std::shared_ptr<const EdenConfig> config;
};
folly::Synchronized<ConfigState> state_;
std::atomic<std::chrono::steady_clock::time_point::rep> lastCheck_{};
// Reload behavior, when set this overrides reload behavior passed to methods
// This is used in tests where we want to set the manually set the EdenConfig
// and avoid reloading it from disk.
std::optional<ConfigReloadBehavior> reloadBehavior_{std::nullopt};
};
} // namespace eden
} // namespace facebook