DBImpl.h 2.2 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 23 24
class DBImpl : public DB {
public:
    DBImpl(const Options& options_, const std::string& name_);

X
Xu Peng 已提交
25
    virtual Status add_group(const GroupOptions& options_,
X
Xu Peng 已提交
26
            const std::string& group_id_,
27 28
            meta::GroupSchema& group_info_) override;
    virtual Status get_group(const std::string& group_id_, meta::GroupSchema& group_info_) override;
29 30 31 32
    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_,
33
                                   meta::GroupFilesSchema& group_files_info_) override;
X
Xu Peng 已提交
34

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

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

X
Xu Peng 已提交
41
    virtual ~DBImpl();
42

X
Xu Peng 已提交
43
private:
X
Xu Peng 已提交
44
    void background_build_index();
X
Xu Peng 已提交
45 46
    Status build_index(const meta::GroupFileSchema&);
    Status try_build_index();
47 48 49 50
    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 已提交
51

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

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

X
Xu Peng 已提交
60
    const std::string& _dbname;
X
Xu Peng 已提交
61 62 63
    Env* const _env;
    const Options _options;

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

X
Xu Peng 已提交
70 71
    bool bg_build_index_started_;

72
    std::shared_ptr<meta::Meta> _pMeta;
73
    std::shared_ptr<MemManager> _pMemMgr;
X
Xu Peng 已提交
74

X
Xu Peng 已提交
75 76
}; // DBImpl

X
Xu Peng 已提交
77 78 79
} // namespace engine
} // namespace vecwise
} // namespace zilliz