db_impl.h 1.8 KB
Newer Older
X
Xu Peng 已提交
1
#pragma once
X
Xu Peng 已提交
2

X
Xu Peng 已提交
3 4
#include <mutex>
#include <condition_variable>
X
Xu Peng 已提交
5
#include <memory>
X
Xu Peng 已提交
6
#include <atomic>
X
Xu Peng 已提交
7
#include "db.h"
X
Xu Peng 已提交
8
#include "memvectors.h"
9
#include "types.h"
X
Xu Peng 已提交
10

X
Xu Peng 已提交
11 12 13
namespace zilliz {
namespace vecwise {
namespace engine {
X
Xu Peng 已提交
14 15 16 17 18 19 20

class Env;

class DBImpl : public DB {
public:
    DBImpl(const Options& options_, const std::string& name_);

X
Xu Peng 已提交
21
    virtual Status add_group(const GroupOptions& options_,
X
Xu Peng 已提交
22
            const std::string& group_id_,
23 24 25 26 27 28 29
            GroupSchema& group_info_) override;
    virtual Status get_group(const std::string& group_id_, 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_,
                                   const int date_delta_,
                                   GroupFilesSchema& group_files_info_) override;
X
Xu Peng 已提交
30

31 32
    virtual Status add_vectors(const std::string& group_id_,
            size_t n, const float* vectors, IDNumbers& vector_ids_) override;
X
Xu Peng 已提交
33

X
Xu Peng 已提交
34 35 36
    virtual Status search(const std::string& group_id, size_t k, size_t nq,
            const float* vectors, QueryResults& results) override;

X
Xu Peng 已提交
37
    virtual ~DBImpl();
38

X
Xu Peng 已提交
39
private:
X
Xu Peng 已提交
40

41
    void try_schedule_compaction();
X
Xu Peng 已提交
42 43
    void start_timer_task(int interval_);
    void background_timer_task(int interval_);
44

X
Xu Peng 已提交
45 46 47 48
    static void BGWork(void* db);
    void background_call();
    void background_compaction();

X
Xu Peng 已提交
49
    const std::string& _dbname;
X
Xu Peng 已提交
50 51 52
    Env* const _env;
    const Options _options;

X
Xu Peng 已提交
53 54 55 56
    std::mutex _mutex;
    std::condition_variable _bg_work_finish_signal;
    bool _bg_compaction_scheduled;
    Status _bg_error;
X
Xu Peng 已提交
57
    std::atomic<bool> _shutting_down;
X
Xu Peng 已提交
58

59
    std::shared_ptr<Meta> _pMeta;
60
    std::shared_ptr<MemManager> _pMemMgr;
X
Xu Peng 已提交
61

X
Xu Peng 已提交
62 63
}; // DBImpl

X
Xu Peng 已提交
64 65 66
} // namespace engine
} // namespace vecwise
} // namespace zilliz