DBImpl.h 2.0 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 8
#include "DB.h"
#include "MemManager.h"
X
Xu Peng 已提交
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

class Env;

17 18 19 20
namespace meta {
    class Meta;
}

X
Xu Peng 已提交
21 22
class DBImpl : public DB {
public:
X
Xu Peng 已提交
23
    DBImpl(const Options& options);
X
Xu Peng 已提交
24

25 26
    virtual Status add_group(meta::GroupSchema& group_info) override;
    virtual Status get_group(meta::GroupSchema& group_info) override;
27 28 29 30
    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_,
31
                                   meta::GroupFilesSchema& group_files_info_) override;
X
Xu Peng 已提交
32

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

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

X
Xu Peng 已提交
39
    virtual ~DBImpl();
40

X
Xu Peng 已提交
41
private:
X
Xu Peng 已提交
42
    void background_build_index();
X
Xu Peng 已提交
43 44
    Status build_index(const meta::GroupFileSchema&);
    Status try_build_index();
45 46 47 48
    Status merge_files(const std::string& group_id,
            const meta::DateT& date,
            const meta::GroupFilesSchema& files);
    Status background_merge_files(const std::string& group_id);
X
Xu Peng 已提交
49

50
    void try_schedule_compaction();
X
Xu Peng 已提交
51 52
    void start_timer_task(int interval_);
    void background_timer_task(int interval_);
53

X
Xu Peng 已提交
54 55 56 57
    static void BGWork(void* db);
    void background_call();
    void background_compaction();

X
Xu Peng 已提交
58 59 60
    Env* const _env;
    const Options _options;

X
Xu Peng 已提交
61 62 63 64
    std::mutex _mutex;
    std::condition_variable _bg_work_finish_signal;
    bool _bg_compaction_scheduled;
    Status _bg_error;
X
Xu Peng 已提交
65
    std::atomic<bool> _shutting_down;
X
Xu Peng 已提交
66

X
Xu Peng 已提交
67 68
    bool bg_build_index_started_;

69
    std::shared_ptr<meta::Meta> _pMeta;
70
    std::shared_ptr<MemManager> _pMemMgr;
X
Xu Peng 已提交
71

X
Xu Peng 已提交
72 73
}; // DBImpl

X
Xu Peng 已提交
74 75 76
} // namespace engine
} // namespace vecwise
} // namespace zilliz