DBImpl.h 3.6 KB
Newer Older
X
Xu Peng 已提交
1 2 3 4 5
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/
X
Xu Peng 已提交
6
#pragma once
X
Xu Peng 已提交
7

X
Xu Peng 已提交
8
#include "DB.h"
X
Xu Peng 已提交
9
#include "Types.h"
G
groot 已提交
10
#include "utils/ThreadPool.h"
Z
zhiru 已提交
11
#include "MemManagerAbstract.h"
X
Xu Peng 已提交
12

13 14 15 16
#include <mutex>
#include <condition_variable>
#include <memory>
#include <atomic>
G
groot 已提交
17
#include <thread>
G
groot 已提交
18 19
#include <list>
#include <set>
J
jinhai 已提交
20 21
#include "scheduler/context/SearchContext.h"

22

X
Xu Peng 已提交
23
namespace zilliz {
J
jinhai 已提交
24
namespace milvus {
X
Xu Peng 已提交
25
namespace engine {
X
Xu Peng 已提交
26 27 28

class Env;

29
namespace meta {
J
jinhai 已提交
30
class Meta;
31 32
}

X
Xu Peng 已提交
33
class DBImpl : public DB {
J
jinhai 已提交
34
 public:
35
    using MetaPtr = meta::Meta::Ptr;
X
Xu Peng 已提交
36

J
jinhai 已提交
37 38 39 40 41 42 43 44 45 46
    explicit DBImpl(const Options &options);

    Status
    CreateTable(meta::TableSchema &table_schema) override;

    Status
    DeleteTable(const std::string &table_id, const meta::DatesT &dates) override;

    Status
    DescribeTable(meta::TableSchema &table_schema) override;
X
Xu Peng 已提交
47

J
jinhai 已提交
48 49
    Status
    HasTable(const std::string &table_id, bool &has_or_not) override;
50

J
jinhai 已提交
51 52
    Status
    AllTables(std::vector<meta::TableSchema> &table_schema_array) override;
X
Xu Peng 已提交
53

J
jinhai 已提交
54 55
    Status
    GetTableRowCount(const std::string &table_id, uint64_t &row_count) override;
X
Xu Peng 已提交
56

J
jinhai 已提交
57 58
    Status
    InsertVectors(const std::string &table_id, uint64_t n, const float *vectors, IDNumbers &vector_ids) override;
X
Xu Peng 已提交
59

J
jinhai 已提交
60 61
    Status
    Query(const std::string &table_id, uint64_t k, uint64_t nq, const float *vectors, QueryResults &results) override;
62

J
jinhai 已提交
63 64 65 66 67 68 69
    Status
    Query(const std::string &table_id,
          uint64_t k,
          uint64_t nq,
          const float *vectors,
          const meta::DatesT &dates,
          QueryResults &results) override;
X
Xu Peng 已提交
70

J
jinhai 已提交
71 72 73 74 75 76 77 78
    Status
    Query(const std::string &table_id,
          const std::vector<std::string> &file_ids,
          uint64_t k,
          uint64_t nq,
          const float *vectors,
          const meta::DatesT &dates,
          QueryResults &results) override;
X
Xu Peng 已提交
79

J
jinhai 已提交
80
    Status DropAll() override;
81

J
jinhai 已提交
82
    Status Size(uint64_t &result) override;
G
groot 已提交
83

P
peng.xu 已提交
84 85
    Status BuildIndex(const std::string& table_id) override;

J
jinhai 已提交
86 87 88 89 90 91 92 93 94 95 96
    ~DBImpl() override;

 private:
    Status
    QueryAsync(const std::string &table_id,
               const meta::TableFilesSchema &files,
               uint64_t k,
               uint64_t nq,
               const float *vectors,
               const meta::DatesT &dates,
               QueryResults &results);
G
groot 已提交
97

98

G
groot 已提交
99 100 101 102
    void StartTimerTasks();
    void BackgroundTimerTask();

    void StartMetricTask();
103

G
groot 已提交
104
    void StartCompactionTask();
J
jinhai 已提交
105 106 107 108
    Status MergeFiles(const std::string &table_id,
                      const meta::DateT &date,
                      const meta::TableFilesSchema &files);
    Status BackgroundMergeFiles(const std::string &table_id);
G
groot 已提交
109 110
    void BackgroundCompaction(std::set<std::string> table_ids);

P
peng.xu 已提交
111
    void StartBuildIndexTask(bool force=false);
G
groot 已提交
112
    void BackgroundBuildIndex();
J
jinhai 已提交
113

P
peng.xu 已提交
114
    Status
P
peng.xu 已提交
115
    BuildIndexByTable(const std::string& table_id);
J
jinhai 已提交
116 117 118 119
    Status
    BuildIndex(const meta::TableFileSchema &);

 private:
X
Xu Peng 已提交
120
    const Options options_;
X
Xu Peng 已提交
121

X
Xu Peng 已提交
122
    std::atomic<bool> shutting_down_;
X
Xu Peng 已提交
123

X
Xu Peng 已提交
124 125
    std::thread bg_timer_thread_;

G
groot 已提交
126
    MetaPtr meta_ptr_;
Z
zhiru 已提交
127
    MemManagerAbstractPtr mem_mgr_;
X
Xu Peng 已提交
128

G
groot 已提交
129 130 131 132 133 134 135
    server::ThreadPool compact_thread_pool_;
    std::list<std::future<void>> compact_thread_results_;
    std::set<std::string> compact_table_ids_;

    server::ThreadPool index_thread_pool_;
    std::list<std::future<void>> index_thread_results_;

P
peng.xu 已提交
136 137
    std::mutex build_index_mutex_;

X
Xu Peng 已提交
138 139
}; // DBImpl

140

X
Xu Peng 已提交
141
} // namespace engine
J
jinhai 已提交
142
} // namespace milvus
X
Xu Peng 已提交
143
} // namespace zilliz