refactor(db): change get_group and add_group apis

Former-commit-id: c235588d9c2901e5065997dc1917cc30df9ae623
This commit is contained in:
Xu Peng 2019-04-17 20:46:40 +08:00
parent 608c5692b4
commit e47b6cf9cc
9 changed files with 40 additions and 57 deletions

View File

@ -17,10 +17,8 @@ class DB {
public:
static DB* Open(const Options& options);
virtual Status add_group(const GroupOptions& options_,
const std::string& group_id_,
meta::GroupSchema& group_info_) = 0;
virtual Status get_group(const std::string& group_id_, meta::GroupSchema& group_info_) = 0;
virtual Status add_group(meta::GroupSchema& group_info_) = 0;
virtual Status get_group(meta::GroupSchema& group_info_) = 0;
virtual Status has_group(const std::string& group_id_, bool& has_or_not_) = 0;
virtual Status get_group_files(const std::string& group_id_,
const int date_delta_,

View File

@ -26,17 +26,12 @@ DBImpl::DBImpl(const Options& options)
start_timer_task(_options.memory_sync_interval);
}
Status DBImpl::add_group(const GroupOptions& options,
const std::string& group_id,
meta::GroupSchema& group_info) {
assert((!options.has_id) ||
(options.has_id && ("" != group_id)));
return _pMeta->add_group(options, group_id, group_info);
Status DBImpl::add_group(meta::GroupSchema& group_info) {
return _pMeta->add_group(group_info);
}
Status DBImpl::get_group(const std::string& group_id_, meta::GroupSchema& group_info_) {
return _pMeta->get_group(group_id_, group_info_);
Status DBImpl::get_group(meta::GroupSchema& group_info) {
return _pMeta->get_group(group_info);
}
Status DBImpl::has_group(const std::string& group_id_, bool& has_or_not_) {

View File

@ -22,10 +22,8 @@ class DBImpl : public DB {
public:
DBImpl(const Options& options);
virtual Status add_group(const GroupOptions& options_,
const std::string& group_id_,
meta::GroupSchema& group_info_) override;
virtual Status get_group(const std::string& group_id_, meta::GroupSchema& group_info_) override;
virtual Status add_group(meta::GroupSchema& group_info) override;
virtual Status get_group(meta::GroupSchema& group_info) override;
virtual Status has_group(const std::string& group_id_, bool& has_or_not_) override;
virtual Status get_group_files(const std::string& group_id_,

View File

@ -52,25 +52,26 @@ Status DBMetaImpl::initialize() {
return Status::OK();
}
Status DBMetaImpl::add_group(const GroupOptions& options_,
const std::string& group_id_,
GroupSchema& group_info_) {
group_info_.dimension = options_.dimension;
group_info_.group_id = group_id_;
group_info_.files_cnt = 0;
group_info_.id = -1;
Status DBMetaImpl::add_group(GroupSchema& group_info) {
if (group_info.group_id == "") {
std::stringstream ss;
SimpleIDGenerator g;
ss << g.getNextIDNumber();
group_info.group_id = ss.str();
}
group_info.files_cnt = 0;
group_info.id = -1;
try {
auto id = ConnectorPtr->insert(group_info_);
auto id = ConnectorPtr->insert(group_info);
std::cout << "id=" << id << std::endl;
group_info_.id = id;
group_info.id = id;
} catch(std::system_error& e) {
return Status::GroupError("Add Group " + group_id_ + " Error");
return Status::GroupError("Add Group " + group_info.group_id + " Error");
}
return Status::OK();
}
Status DBMetaImpl::get_group(const std::string& group_id_, GroupSchema& group_info_) {
Status DBMetaImpl::get_group(GroupSchema& group_info_) {
return Status::OK();
}

View File

@ -15,10 +15,8 @@ class DBMetaImpl : public Meta {
public:
DBMetaImpl(const DBMetaOptions& options_);
virtual Status add_group(const GroupOptions& options_,
const std::string& group_id_,
GroupSchema& group_info_) override;
virtual Status get_group(const std::string& group_id_, GroupSchema& group_info_) override;
virtual Status add_group(GroupSchema& group_info) override;
virtual Status get_group(GroupSchema& group_info_) override;
virtual Status has_group(const std::string& group_id_, bool& has_or_not_) override;
virtual Status add_group_file(const std::string& group_id,

View File

@ -85,17 +85,15 @@ Status LocalMetaImpl::initialize() {
return Status::OK();
}
Status LocalMetaImpl::add_group(const GroupOptions& options,
const std::string& group_id,
GroupSchema& group_info) {
Status LocalMetaImpl::add_group(GroupSchema& group_info) {
std::string real_gid;
size_t id = SimpleIDGenerator().getNextIDNumber();
if (group_id == "") {
if (group_info.group_id == "") {
std::stringstream ss;
ss << id;
real_gid = ss.str();
} else {
real_gid = group_id;
real_gid = group_info.group_id;
}
bool group_exist;
@ -111,7 +109,6 @@ Status LocalMetaImpl::add_group(const GroupOptions& options,
group_info.files_cnt = 0;
group_info.id = 0;
group_info.location = GetGroupPath(real_gid);
group_info.dimension = options.dimension;
boost::property_tree::ptree out;
out.put("files_cnt", group_info.files_cnt);
@ -121,14 +118,14 @@ Status LocalMetaImpl::add_group(const GroupOptions& options,
return Status::OK();
}
Status LocalMetaImpl::get_group(const std::string& group_id, GroupSchema& group_info) {
Status LocalMetaImpl::get_group(GroupSchema& group_info) {
bool group_exist;
has_group(group_id, group_exist);
has_group(group_info.group_id, group_exist);
if (!group_exist) {
return Status::NotFound("Group " + group_id + " Not Found");
return Status::NotFound("Group " + group_info.group_id + " Not Found");
}
return GetGroupMetaInfo(group_id, group_info);
return GetGroupMetaInfo(group_info.group_id, group_info);
}
Status LocalMetaImpl::has_group(const std::string& group_id, bool& has_or_not) {
@ -147,7 +144,7 @@ Status LocalMetaImpl::add_group_file(const std::string& group_id,
GroupFileSchema& group_file_info,
GroupFileSchema::FILE_TYPE file_type) {
GroupSchema group_info;
auto status = get_group(group_id, group_info);
auto status = get_group(group_info);
if (!status.ok()) {
return status;
}

View File

@ -14,10 +14,8 @@ public:
const size_t INDEX_TRIGGER_SIZE = 1024*1024*500;
LocalMetaImpl(const DBMetaOptions& options_);
virtual Status add_group(const GroupOptions& options_,
const std::string& group_id_,
GroupSchema& group_info_) override;
virtual Status get_group(const std::string& group_id_, GroupSchema& group_info_) override;
virtual Status add_group(GroupSchema& group_info_) override;
virtual Status get_group(GroupSchema& group_info_) override;
virtual Status has_group(const std::string& group_id_, bool& has_or_not_) override;
virtual Status add_group_file(const std::string& group_id,

View File

@ -48,10 +48,8 @@ typedef std::map<DateT, GroupFilesSchema> DatePartionedGroupFilesSchema;
class Meta {
public:
virtual Status add_group(const GroupOptions& options_,
const std::string& group_id_,
GroupSchema& group_info_) = 0;
virtual Status get_group(const std::string& group_id_, GroupSchema& group_info_) = 0;
virtual Status add_group(GroupSchema& group_info) = 0;
virtual Status get_group(GroupSchema& group_info) = 0;
virtual Status has_group(const std::string& group_id_, bool& has_or_not_) = 0;
virtual Status add_group_file(const std::string& group_id_,

View File

@ -43,11 +43,10 @@ VecServiceHandler::add_group(const VecGroup &group) {
<< ", group.index_type = " << group.index_type;
try {
engine::GroupOptions gopt;
gopt.dimension = (size_t)group.dimension;
gopt.has_id = !group.id.empty();
engine::meta::GroupSchema group_info;
engine::Status stat = DB()->add_group(gopt, group.id, group_info);
group_info.dimension = (size_t)group.dimension;
group_info.group_id = group.id;
engine::Status stat = DB()->add_group(group_info);
if(!stat.ok()) {
SERVER_LOG_ERROR << "Engine failed: " << stat.ToString();
}
@ -65,7 +64,8 @@ VecServiceHandler::get_group(VecGroup &_return, const std::string &group_id) {
try {
engine::meta::GroupSchema group_info;
engine::Status stat = DB()->get_group(group_id, group_info);
group_info.group_id = group_id;
engine::Status stat = DB()->get_group(group_info);
if(!stat.ok()) {
SERVER_LOG_ERROR << "Engine failed: " << stat.ToString();
} else {