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 9
#include "DB.h"
#include "MemManager.h"
X
Xu Peng 已提交
10
#include "Types.h"
G
groot 已提交
11
#include "utils/ThreadPool.h"
Z
zhiru 已提交
12
#include "MemManagerAbstract.h"
X
Xu Peng 已提交
13

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

23

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

class Env;

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

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

J
jinhai 已提交
38 39 40 41 42 43 44 45 46 47
    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 已提交
48

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

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

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

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

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

J
jinhai 已提交
64 65 66 67 68 69 70
    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 已提交
71

J
jinhai 已提交
72 73 74 75 76 77 78 79
    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 已提交
80

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

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

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

J
jinhai 已提交
87 88 89 90 91 92 93 94 95 96 97
    ~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 已提交
98

99

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

    void StartMetricTask();
104

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

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

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

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

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

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

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

G
groot 已提交
130 131 132 133 134 135 136
    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 已提交
137 138
    std::mutex build_index_mutex_;

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

141

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