DBImpl.h 3.7 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"
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;
G
groot 已提交
36
    using MemManagerPtr = typename MemManager::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

J
jinhai 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    ~DBImpl() override;

 private:
    Status
    QuerySync(const std::string &table_id,
              uint64_t k,
              uint64_t nq,
              const float *vectors,
              const meta::DatesT &dates,
              QueryResults &results);

    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 已提交
104

105

G
groot 已提交
106 107 108 109
    void StartTimerTasks();
    void BackgroundTimerTask();

    void StartMetricTask();
110

G
groot 已提交
111
    void StartCompactionTask();
J
jinhai 已提交
112 113 114 115
    Status MergeFiles(const std::string &table_id,
                      const meta::DateT &date,
                      const meta::TableFilesSchema &files);
    Status BackgroundMergeFiles(const std::string &table_id);
G
groot 已提交
116 117 118 119
    void BackgroundCompaction(std::set<std::string> table_ids);

    void StartBuildIndexTask();
    void BackgroundBuildIndex();
J
jinhai 已提交
120 121 122 123 124

    Status
    BuildIndex(const meta::TableFileSchema &);

 private:
X
Xu Peng 已提交
125

X
Xu Peng 已提交
126
    const Options options_;
X
Xu Peng 已提交
127

X
Xu Peng 已提交
128 129
    Status bg_error_;
    std::atomic<bool> shutting_down_;
X
Xu Peng 已提交
130

X
Xu Peng 已提交
131 132
    std::thread bg_timer_thread_;

G
groot 已提交
133 134
    MetaPtr meta_ptr_;
    MemManagerPtr mem_mgr_;
X
Xu Peng 已提交
135

G
groot 已提交
136 137 138 139 140 141 142
    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_;

X
Xu Peng 已提交
143 144
}; // DBImpl

145

X
Xu Peng 已提交
146
} // namespace engine
J
jinhai 已提交
147
} // namespace milvus
X
Xu Peng 已提交
148
} // namespace zilliz