feat(db): add merge files

Former-commit-id: 9673339417ce0eb4f4d767420e4a87aa551b1edc
This commit is contained in:
Xu Peng 2019-04-16 16:05:46 +08:00
parent 162bd5af3d
commit 3917084e01
4 changed files with 33 additions and 5 deletions

View File

@ -136,11 +136,11 @@ Status DBImpl::merge_files(const std::string& group_id, const meta::DateT& date,
Status DBImpl::background_merge_files(const std::string& group_id) {
meta::DatePartionedGroupFilesSchema raw_files;
/* auto status = _pMeta->get_small_raw_files(group_id, raw_files); */
/* if (!status.ok()) { */
/* _bg_error = status; */
/* return status; */
/* } */
auto status = _pMeta->files_to_merge(group_id, raw_files);
if (!status.ok()) {
_bg_error = status;
return status;
}
if (raw_files.size() == 0) {
return Status::OK();

View File

@ -74,6 +74,9 @@ public:
virtual Status update_files(const GroupFilesSchema& files) = 0;
virtual Status files_to_merge(const std::string& group_id,
DatePartionedGroupFilesSchema& files) = 0;
static DateT GetDate(const std::time_t& t);
static DateT GetDate();

View File

@ -1,5 +1,6 @@
#include <sstream>
#include <iostream>
#include <boost/filesystem.hpp>
#include "db_meta_impl.h"
#include "id_generators.h"
@ -56,6 +57,27 @@ Status DBMetaImpl::add_group_file(const std::string& group_id,
return Status::OK();
}
Status DBMetaImpl::files_to_merge(const std::string& group_id,
DatePartionedGroupFilesSchema& files) {
//PXU TODO
files.clear();
std::stringstream ss;
ss << "/tmp/test/" << Meta::GetDate();
boost::filesystem::path path(ss.str().c_str());
boost::filesystem::directory_iterator end_itr;
GroupFilesSchema gfiles;
DateT date = Meta::GetDate();
files[date] = gfiles;
for (boost::filesystem::directory_iterator itr(path); itr != end_itr; ++itr) {
std::cout << itr->path().string() << std::endl;
GroupFileSchema f;
f.location = itr->path().string();
files[date].push_back(f);
}
return Status::OK();
}
Status DBMetaImpl::has_group_file(const std::string& group_id_,
const std::string& file_id_,
bool& has_or_not_) {

View File

@ -38,6 +38,9 @@ public:
virtual Status update_files(const GroupFilesSchema& files) override;
virtual Status files_to_merge(const std::string& group_id,
DatePartionedGroupFilesSchema& files) override;
private:
Status initialize();