fix(db): fix db compile errors

Former-commit-id: 8c013a54ad53efcce47f4f9480164052ecfa9249
This commit is contained in:
Xu Peng 2019-04-15 14:56:40 +08:00 committed by xj.lin
parent d4dae8127b
commit 424b938c82
10 changed files with 60 additions and 32 deletions

View File

@ -5,6 +5,7 @@
#include "options.h"
#include "db_meta.h"
#include "status.h"
#include "types.h"
namespace zilliz {
namespace vecwise {
@ -16,7 +17,7 @@ class DB {
public:
static DB* Open(const Options& options_, const std::string& name_);
virtual Status add_group(GroupOptions options_,
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;
@ -26,7 +27,7 @@ public:
GroupFilesSchema& group_files_info_) = 0;
virtual Status add_vectors(const std::string& group_id_,
size_t n, const float* vectors) = 0;
size_t n, const float* vectors, IDNumbers& vector_ids_) = 0;
DB() = default;
DB(const DB&) = delete;

View File

@ -1,28 +1,32 @@
#include <assert.h>
#include <chrono>
#include <thread>
#include "db_impl.h"
#include "db_meta_impl.h"
#include "env.h"
namespace vecengine {
namespace zilliz {
namespace vecwise {
namespace engine {
DBImpl::DBImpl(const Options& options_, const std::string& name_)
: _dbname(name_),
_env(options_.env),
_options(options_),
_bg_work_finish_signal(_mutex),
_bg_compaction_scheduled(false),
_shutting_down(false),
_pMeta(new DBMetaImpl(*(_options.pMetaOptions))),
_pMemMgr(new MemManager(_pMeta)) {
start_timer_task(Options.memory_sync_interval);
start_timer_task(options_.memory_sync_interval);
}
Status DBImpl::add_group(const GroupOptions& options_,
const std::string& group_id_,
GroupSchema& group_info_) {
assert((!options_.has_id) ||
(options_.has_id && ("" != group_id_)));
Status DBImpl::add_group(const GroupOptions& options,
const std::string& group_id,
GroupSchema& group_info) {
assert((!options.has_id) ||
(options.has_id && ("" != group_id)));
return _pMeta->add_group(options_, group_id, group_info_);
return _pMeta->add_group(options, group_id, group_info);
}
Status DBImpl::get_group(const std::string& group_id_, GroupSchema& group_info_) {
@ -33,10 +37,10 @@ Status DBImpl::has_group(const std::string& group_id_, bool& has_or_not_) {
return _pMeta->has_group(group_id_, has_or_not_);
}
Status DBImpl::get_group_files(const std::string& group_id_,
const int date_delta_,
GroupFilesSchema& group_files_info_) {
return _pMeta->get_group_files(group_id_, date_delta_, group_file_info_);
Status DBImpl::get_group_files(const std::string& group_id,
const int date_delta,
GroupFilesSchema& group_files_info) {
return _pMeta->get_group_files(group_id, date_delta, group_files_info);
}
@ -94,10 +98,10 @@ void DBImpl::background_compaction() {
}
DBImpl::~DBImpl() {
std::lock_guard<std::mutex> _mutex;
std::unique_lock<std::mutex> lock(_mutex);
_shutting_down.store(true, std::memory_order_release);
while (_bg_compaction_scheduled) {
_bg_work_finish_signal.wait();
_bg_work_finish_signal.wait(lock);
}
}
@ -112,4 +116,6 @@ DB* DB::Open(const Options& options_, const std::string& name_) {
return impl;
}
} // namespace vecengine
} // namespace engine
} // namespace vecwise
} // namespace zilliz

View File

@ -1,9 +1,9 @@
#ifndef VECENGINE_DB_IMPL_H_
#define VECENGINE_DB_IMPL_H_
#pragma once
#include <mutex>
#include <condition_variable>
#include <memory>
#include <atomic>
#include "db.h"
#include "memvectors.h"
#include "types.h"
@ -18,7 +18,7 @@ class DBImpl : public DB {
public:
DBImpl(const Options& options_, const std::string& name_);
virtual Status add_group(GroupOptions 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;
@ -36,12 +36,14 @@ public:
private:
void try_schedule_compaction();
void start_timer_task(int interval_);
void background_timer_task(int interval_);
static void BGWork(void* db);
void background_call();
void background_compaction();
const _dbname;
const std::string& _dbname;
Env* const _env;
const Options _options;
@ -59,7 +61,3 @@ private:
} // namespace engine
} // namespace vecwise
} // namespace zilliz
#endif // VECENGINE_DB_META_IMPL_H_
#endif // VECENGINE_DB_IMPL_H_

View File

@ -4,8 +4,8 @@ namespace zilliz {
namespace vecwise {
namespace engine {
DBMetaImpl::DBMetaImpl(const DBMetaOptions& options_)
: _options(options_) {
DBMetaImpl::DBMetaImpl(const MetaOptions& options_)
: _options(static_cast<const DBMetaOptions&>(options_)) {
initialize();
}

View File

@ -10,7 +10,7 @@ namespace engine {
class DBMetaImpl : public Meta {
public:
DBMetaImpl(const DBMetaOptions& options_);
DBMetaImpl(const MetaOptions& options_);
virtual Status add_group(const GroupOptions& options_,
const std::string& group_id_,
@ -36,7 +36,7 @@ private:
Status initialize();
const DBMetaOptions _options;
const DBMetaOptions& _options;
}; // DBMetaImpl

View File

@ -43,6 +43,11 @@ void Env::backgroud_thread_main() {
Env::~Env() {}
Env* Env::Default() {
static Env env;
return &env;
}
} // namespace engine
} // namespace vecwise
} // namespace zilliz

View File

@ -21,6 +21,8 @@ public:
virtual ~Env();
static Env* Default();
protected:
void backgroud_thread_main();
static void BackgroundThreadEntryPoint(Env* env) {

View File

@ -7,8 +7,10 @@
#include "id_generators.h"
#include "status.h"
class faiss::IndexIDMap;
class faiss::Index;
namespace faiss {
class IndexIDMap;
class Index;
}
namespace zilliz {

13
cpp/src/db/options.cpp Normal file
View File

@ -0,0 +1,13 @@
#include "options.h"
namespace zilliz {
namespace vecwise {
namespace engine {
Options::Options()
: env(Env::Default()) {
}
} // namespace engine
} // namespace vecwise
} // namespace zilliz

View File

@ -16,6 +16,7 @@ struct Options {
uint16_t raw_file_merge_trigger_number = 100;
size_t raw_to_index_trigger_size = 100000;
std::shared_ptr<MetaOptions> pMetaOptions;
Env* env;
}; // Options