提交 b8224f7d 编写于 作者: S superjom

set num_records to total_records

上级 6ffdf7fb
...@@ -16,7 +16,6 @@ link_directories(${PROJECT_SOURCE_DIR}/thirdparty/local/lib) ...@@ -16,7 +16,6 @@ link_directories(${PROJECT_SOURCE_DIR}/thirdparty/local/lib)
add_library(storage add_library(storage
${PROJECT_SOURCE_DIR}/visualdl/backend/storage/storage.cc ${PROJECT_SOURCE_DIR}/visualdl/backend/storage/storage.cc
${PROJECT_SOURCE_DIR}/visualdl/backend/storage/storage.pb.cc) ${PROJECT_SOURCE_DIR}/visualdl/backend/storage/storage.pb.cc)
add_library(c_api ${PROJECT_SOURCE_DIR}/visualdl/backend/logic/c_api.cc)
add_library(sdk ${PROJECT_SOURCE_DIR}/visualdl/backend/logic/sdk.cc) add_library(sdk ${PROJECT_SOURCE_DIR}/visualdl/backend/logic/sdk.cc)
add_library(im ${PROJECT_SOURCE_DIR}/visualdl/backend/logic/im.cc) add_library(im ${PROJECT_SOURCE_DIR}/visualdl/backend/logic/im.cc)
...@@ -29,4 +28,3 @@ add_executable(vl_test ...@@ -29,4 +28,3 @@ add_executable(vl_test
${PROJECT_SOURCE_DIR}/visualdl/backend/test.cc ${PROJECT_SOURCE_DIR}/visualdl/backend/test.cc
${PROJECT_SOURCE_DIR}/visualdl/backend/logic/im_test.cc) ${PROJECT_SOURCE_DIR}/visualdl/backend/logic/im_test.cc)
target_link_libraries(vl_test storage im gtest glog protobuf gflags) target_link_libraries(vl_test storage im gtest glog protobuf gflags)
#include <ctime>
#include <glog/logging.h> #include <glog/logging.h>
#include <ctime>
#include "visualdl/backend/logic/im.h" #include "visualdl/backend/logic/im.h"
...@@ -45,15 +45,14 @@ void InformationMaintainer::AddRecord(const std::string &tag, ...@@ -45,15 +45,14 @@ void InformationMaintainer::AddRecord(const std::string &tag,
auto *tablet = storage_.Find(tag); auto *tablet = storage_.Find(tag);
CHECK(tablet); CHECK(tablet);
auto num_records = tablet->num_records(); auto num_records = tablet->total_records();
const auto num_samples = tablet->num_samples(); const auto num_samples = tablet->num_samples();
int offset; int offset;
// use reservoir sampling or not // use reservoir sampling or not
if (num_samples > 0) { if (num_samples > 0) {
offset = ReserviorSample(num_samples, num_records + 1); offset = ReserviorSample(num_samples, num_records + 1);
if (offset < 0) if (offset < 0) return;
return;
} else { } else {
offset = num_records; offset = num_records;
} }
...@@ -66,11 +65,11 @@ void InformationMaintainer::AddRecord(const std::string &tag, ...@@ -66,11 +65,11 @@ void InformationMaintainer::AddRecord(const std::string &tag,
} }
*record = data; *record = data;
tablet->set_num_records(num_records + 1); tablet->set_total_records(num_records + 1);
} }
void InformationMaintainer::Clear() { void InformationMaintainer::Clear() {
auto* data = storage().mutable_data(); auto *data = storage().mutable_data();
data->clear_tablets(); data->clear_tablets();
data->clear_dir(); data->clear_dir();
data->clear_timestamp(); data->clear_timestamp();
...@@ -79,8 +78,8 @@ void InformationMaintainer::Clear() { ...@@ -79,8 +78,8 @@ void InformationMaintainer::Clear() {
void InformationMaintainer::PersistToDisk() { void InformationMaintainer::PersistToDisk() {
CHECK(!storage_.data().dir().empty()) << "path of storage should be set"; CHECK(!storage_.data().dir().empty()) << "path of storage should be set";
// TODO make dir first // TODO make dir first
//MakeDir(storage_.data().dir()); // MakeDir(storage_.data().dir());
storage_.Save(storage_.data().dir() + "/storage.pb"); storage_.Save(storage_.data().dir() + "/storage.pb");
} }
} // namespace visualdl } // namespace visualdl
#include <fstream>
#include <glog/logging.h> #include <glog/logging.h>
#include <fstream>
#include "visualdl/backend/storage/storage.h" #include "visualdl/backend/storage/storage.h"
...@@ -24,15 +24,15 @@ storage::Record *Storage::NewRecord(const std::string &tag) { ...@@ -24,15 +24,15 @@ storage::Record *Storage::NewRecord(const std::string &tag) {
CHECK(tablet) << "Tablet" << tag << " should be create first"; CHECK(tablet) << "Tablet" << tag << " should be create first";
auto *record = tablet->mutable_records()->Add(); auto *record = tablet->mutable_records()->Add();
// increase num_records // increase num_records
int num_records = tablet->num_records(); int num_records = tablet->total_records();
tablet->set_num_records(num_records + 1); tablet->set_total_records(num_records + 1);
return record; return record;
} }
storage::Record *Storage::GetRecord(const std::string &tag, int offset) { storage::Record *Storage::GetRecord(const std::string &tag, int offset) {
auto *tablet = Find(tag); auto *tablet = Find(tag);
CHECK(tablet) << "Tablet" << tag << " should be create first"; CHECK(tablet) << "Tablet" << tag << " should be create first";
auto num_records = tablet->num_records(); auto num_records = tablet->total_records();
CHECK_LT(offset, num_records) << "invalid offset"; CHECK_LT(offset, num_records) << "invalid offset";
return tablet->mutable_records()->Mutable(offset); return tablet->mutable_records()->Mutable(offset);
} }
...@@ -60,4 +60,4 @@ void Storage::DeSerialize(const std::string &data) { ...@@ -60,4 +60,4 @@ void Storage::DeSerialize(const std::string &data) {
proto_.ParseFromString(data); proto_.ParseFromString(data);
} }
} // namespace visualdl } // namespace visualdl
...@@ -2,47 +2,48 @@ syntax = "proto3"; ...@@ -2,47 +2,48 @@ syntax = "proto3";
package storage; package storage;
enum DataType { enum DataType {
// single entry // single entry
kInt32 = 0; kInt32 = 0;
kInt64 = 1; kInt64 = 1;
kFloat = 2; kFloat = 2;
kDouble = 3; kDouble = 3;
kString = 4; kString = 4;
kBool = 5; kBool = 5;
// entrys // entrys
kInt64s = 6; kInt64s = 6;
kFloats = 7; kFloats = 7;
kDoubles = 8; kDoubles = 8;
kStrings = 9; kStrings = 9;
kInt32s = 10; kInt32s = 10;
kBools = 11; kBools = 11;
kUnknown = 12; kUnknown = 12;
} }
// A data array, which type is `type`. // A data array, which type is `type`.
message Entry { message Entry {
// if all the entries in a record share the same data type, ignore this field // if all the entries in a record share the same data type, ignore this field
// and store type to `dtype` in `Record`. // and store type to `dtype` in `Record`.
DataType dtype = 1; DataType dtype = 1;
// single element // single element
int32 i32 = 2; int32 i32 = 2;
int64 i64 = 3; int64 i64 = 3;
string s = 4; string s = 4;
float f = 5; float f = 5;
double d = 6; double d = 6;
bool b = 7; bool b = 7;
// array // array
repeated int64 i64s = 8; repeated int64 i64s = 8;
repeated float fs = 9; repeated float fs = 9;
repeated double ds = 10; repeated double ds = 10;
repeated int32 i32s = 11; repeated int32 i32s = 11;
repeated string ss = 12; repeated string ss = 12;
repeated bool bs = 13; repeated bool bs = 13;
} }
/* /*
The Record proto is designed to represent any data structure for any component, for The Record proto is designed to represent any data structure for any component,
for
example, to store a record of Scalar component example, to store a record of Scalar component
Record { Record {
...@@ -63,62 +64,73 @@ Record { ...@@ -63,62 +64,73 @@ Record {
meta = [100, 200] meta = [100, 200]
} }
for other complex structure which have more fields than `timestamp`, `id` and meta, the additional fields for other complex structure which have more fields than `timestamp`, `id` and
can store in the `data` field, for it can store a list of values in different basic data types. meta, the additional fields
can store in the `data` field, for it can store a list of values in different
basic data types.
A component handlers in logic layer should know how to write or load a record for the corresponding component. A component handlers in logic layer should know how to write or load a record
for the corresponding component.
*/ */
message Record { message Record {
// one record might have multiple fields, one specific component should know how // one record might have multiple fields, one specific component should know
// to parse the records. // how
repeated Entry data = 1; // to parse the records.
// NOTE the timestamp, id, dtype might be useless for that all the meta info can repeated Entry data = 1;
// be stored in `data` field. // NOTE the timestamp, id, dtype might be useless for that all the meta info
int64 timestamp = 2; // can
// store the count of writing operations to the tablet. // be stored in `data` field.
int64 id = 3; int64 timestamp = 2;
DataType dtype = 4; int64 id = 3;
// shape or some other meta infomation for this record, if all the records DataType dtype = 4;
// share the same meta, just store one copy of meta in `Storage`, or create // shape or some other meta infomation for this record, if all the records
// a unique copy for each `Record`. // share the same meta, just store one copy of meta in `Storage`, or create
Entry meta = 5; // a unique copy for each `Record`.
Entry meta = 5;
} }
/* /*
A Tablet stores the records of a component which type is `component` and indidates as `tag`. A Tablet stores the records of a component which type is `component` and
The records will be saved in a file which name contains `tag`. During the running period, indidates as `tag`.
`num_records` will be accumulated, and `num_samples` indicates the size of sample set the The records will be saved in a file which name contains `tag`. During the
running period,
`num_records` will be accumulated, and `num_samples` indicates the size of
sample set the
reservoir sampling algorithm will collect. reservoir sampling algorithm will collect.
*/ */
message Tablet { message Tablet {
// the kinds of the components that supported // the kinds of the components that supported
enum Type { enum Type {
kScalar = 0; kScalar = 0;
kHistogram = 1; kHistogram = 1;
kGraph = 2; kGraph = 2;
} }
// type of the component, different component should have different storage format. // type of the component, different component should have different storage
Type component = 1; // format.
// records the total count of records, each Write operation should increate this value. Type component = 1;
int64 num_records = 2; // records the total count of records, each Write operation should increate
// indicate the number of instances to sample, this should be a constant value. // this value.
int32 num_samples = 3; int64 total_records = 2;
repeated Record records = 4; // indicate the number of instances to sample, this should be a constant
// store a meta infomation if all the records share. // value.
Entry meta = 5; int32 num_samples = 3;
// the unique identification for this `Tablet`. repeated Record records = 4;
string tag = 6; // store a meta infomation if all the records share.
// one tablet might have multiple captions, for example, a scalar component might have Entry meta = 5;
// two plots labeled "train" and "test". // the unique identification for this `Tablet`.
repeated string captions = 7; string tag = 6;
// one tablet might have multiple captions, for example, a scalar component
// might have
// two plots labeled "train" and "test".
repeated string captions = 7;
} }
/* /*
The Storage stores all the records. The Storage stores all the records.
*/ */
message Storage { message Storage {
// tags to Tablet, should be thread safe if fix the keys after initialization. // tags to Tablet, should be thread safe if fix the keys after initialization.
map<string, Tablet> tablets = 1; map<string, Tablet> tablets = 1;
string dir = 2; string dir = 2;
int64 timestamp = 3; int64 timestamp = 3;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册