db_impl.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
#include "db.h"
X
Xu Peng 已提交
8
#include "memvectors.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:
44 45 46 47
    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 已提交
48

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

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

X
Xu Peng 已提交
57
    const std::string& _dbname;
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

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

X
Xu Peng 已提交
70 71
}; // DBImpl

X
Xu Peng 已提交
72 73 74
} // namespace engine
} // namespace vecwise
} // namespace zilliz