提交 64b0f375 编写于 作者: S superjom

rename InformationMaintainer to IM

上级 00156734
......@@ -25,20 +25,18 @@ int ReserviorSample(int num_samples, int num_records) {
return -1;
}
void InformationMaintainer::SetPersistDest(const std::string &path) {
void IM::SetPersistDest(const std::string &path) {
CHECK(storage_->mutable_data()->dir().empty())
<< "duplicate set storage's path";
storage_->mutable_data()->set_dir(path);
}
storage::Tablet *InformationMaintainer::AddTablet(const std::string &tag,
int num_samples) {
storage::Tablet *IM::AddTablet(const std::string &tag, int num_samples) {
auto tablet = storage_->NewTablet(tag, num_samples);
return tablet;
}
void InformationMaintainer::AddRecord(const std::string &tag,
const storage::Record &data) {
void IM::AddRecord(const std::string &tag, const storage::Record &data) {
auto *tablet = storage_->tablet(tag);
CHECK(tablet) << "no tablet called " << tag;
......@@ -65,14 +63,14 @@ void InformationMaintainer::AddRecord(const std::string &tag,
tablet->set_total_records(num_records + 1);
}
void InformationMaintainer::Clear() {
void IM::Clear() {
auto *data = storage().mutable_data();
data->clear_tablets();
data->clear_dir();
data->clear_timestamp();
}
void InformationMaintainer::PersistToDisk() {
void IM::PersistToDisk() {
CHECK(!storage_->data().dir().empty()) << "path of storage should be set";
// TODO make dir first
// MakeDir(storage_.data().dir());
......
......@@ -10,7 +10,7 @@
namespace visualdl {
/*
* InformationMaintainer(IM) maintain the Storage singleton in memory,
* IM(IM) maintain the Storage singleton in memory,
* pre-compute some the statistical information to help visualizaton.
*
* There should be two processes and each have an IM, one is the web server
......@@ -24,9 +24,9 @@ namespace visualdl {
* The SDK's IM will maintain the changes and periodically write to disk, and
* the web server's IM will periodically read latest storage from disk.
*/
class InformationMaintainer final {
class IM final {
public:
InformationMaintainer(StorageBase::Type type = StorageBase::Type::kMemory) {
IM(StorageBase::Type type = StorageBase::Type::kMemory) {
switch (type) {
case StorageBase::Type::kMemory:
storage_.reset(new MemoryStorage);
......@@ -36,8 +36,8 @@ public:
}
}
static InformationMaintainer &Global() {
static InformationMaintainer *x = new InformationMaintainer();
static IM &Global() {
static IM *x = new IM();
return *x;
}
......
......@@ -8,7 +8,7 @@ class ImTester : public ::testing::Test {
protected:
void SetUp() override {}
InformationMaintainer &im = InformationMaintainer::Global();
IM &im = IM::Global();
};
TEST_F(ImTester, AddTablet) {
......
......@@ -60,9 +60,7 @@ std::string TabletHelper::human_readable_buffer() const {
return buffer;
}
void ImHelper::PersistToDisk() const {
InformationMaintainer::Global().PersistToDisk();
}
void ImHelper::PersistToDisk() const { IM::Global().PersistToDisk(); }
// implementations for components
namespace components {
......
......@@ -94,18 +94,16 @@ public:
ImHelper() {}
StorageHelper storage() {
return StorageHelper(
InformationMaintainer::Global().storage().mutable_data());
return StorageHelper(IM::Global().storage().mutable_data());
}
TabletHelper tablet(const std::string &tag) {
return TabletHelper(InformationMaintainer::Global().storage().tablet(tag));
return TabletHelper(IM::Global().storage().tablet(tag));
}
TabletHelper AddTablet(const std::string &tag, int num_samples) {
return TabletHelper(
InformationMaintainer::Global().AddTablet(tag, num_samples));
return TabletHelper(IM::Global().AddTablet(tag, num_samples));
}
void ClearTablets() {
InformationMaintainer::Global().storage().mutable_data()->clear_tablets();
IM::Global().storage().mutable_data()->clear_tablets();
}
void PersistToDisk() const;
......
#include <glog/logging.h>
#include <visualdl/backend/utils/concurrency.h>
#include <fstream>
#include "visualdl/backend/storage/storage.h"
......@@ -72,4 +73,21 @@ void MemoryStorage::LoadFromDisk(const std::string &dir) {
}
}
void MemoryStorage::StartReadService() {
cc::PeriodExector::task_t task = [this] {
LOG(INFO) << "loading from " << storage_.dir();
LoadFromDisk(storage_.dir());
return true;
};
cc::PeriodExector::Global()(std::move(task), 2512);
}
void MemoryStorage::StartWriteSerice() {
cc::PeriodExector::task_t task = [this] {
LOG(INFO) << "writing to " << storage_.dir();
PersistToDisk();
return true;
};
cc::PeriodExector::Global()(std::move(task), 2000);
}
} // namespace visualdl
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册