Manages dumps of a cache-like component.
The class is thread-safe.
Used in components::CachingComponentBase
.
Automatically subscribes to:
dynamic config updates from USERVER_DUMPS
under dumper_name
statistics under cache.{dumper_name}.dump
Dumps will be stored in {dump-root}/{dumper_name}
, where dump-root
is taken from components::DumpConfigurator
.
Here, dumper_name
is the name of the parent component.
Dynamic config
Static config
Name Type Description Default value
enable
boolean
Whether this Dumper
should actually read and write dumps (required)
world-readable
boolean
If true
, dumps are created with access 0444
, otherwise with access 0400
(required)
format-version
integer
Allows to ignore dumps written with an obsolete format-version
(required)
max-age
optional string
(duration) Overdue dumps are ignored null
max-count
optional integer
Old dumps over the limit are removed from disk 1
min-interval
string
(duration) WriteDumpAsync
calls performed in a fast succession are ignored 0s
fs-task-processor
string
TaskProcessor
for blocking disk IO fs-task-processor
encrypted
boolean
Whether to encrypt the dump false
first-update-mode
string
specifies whether required or best-effort first update will be used skip
first-update-type
string
specifies whether incremental and/or full first update will be used full
Sample usage
public :
static constexpr auto kName = "component-with-dumps" ;
: LoggableComponentBase(config, context),
dumper_(config, context, *this) {
dumper_.ReadDump();
}
~SampleComponentWithDumps() override {
dumper_.CancelWriteTaskAndWait();
}
std::string Get(const std::string& key) {
if (auto existing_value = data_.Get(key)) return *existing_value;
auto value = key + "foo" ;
data_.Emplace(key, value);
dumper_.OnUpdateCompleted();
return value;
}
}
private :
writer.
Write (data_.GetSnapshot());
}
using Map = std::unordered_map<std::string, std::shared_ptr<std::string>>;
data_.Assign(reader.
Read <Map>());
}
};
See also components::DumpConfigurator
Definition at line 96 of file dumper.hpp .