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"
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>
20

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

class Env;

27 28 29 30
namespace meta {
    class Meta;
}

X
Xu Peng 已提交
31 32
class DBImpl : public DB {
public:
33
    using MetaPtr = meta::Meta::Ptr;
G
groot 已提交
34
    using MemManagerPtr = typename MemManager::Ptr;
X
Xu Peng 已提交
35

X
Xu Peng 已提交
36
    DBImpl(const Options& options);
X
Xu Peng 已提交
37

X
Xu Peng 已提交
38
    virtual Status CreateTable(meta::TableSchema& table_schema) override;
G
groot 已提交
39
    virtual Status DeleteTable(const std::string& table_id, const meta::DatesT& dates) override;
X
Xu Peng 已提交
40 41
    virtual Status DescribeTable(meta::TableSchema& table_schema) override;
    virtual Status HasTable(const std::string& table_id, bool& has_or_not) override;
G
groot 已提交
42 43
    virtual Status AllTables(std::vector<meta::TableSchema>& table_schema_array) override;
    virtual Status GetTableRowCount(const std::string& table_id, uint64_t& row_count) override;
44

X
Xu Peng 已提交
45
    virtual Status InsertVectors(const std::string& table_id,
G
groot 已提交
46
                                 uint64_t n, const float* vectors, IDNumbers& vector_ids) override;
X
Xu Peng 已提交
47

G
groot 已提交
48
    virtual Status Query(const std::string& table_id, uint64_t k, uint64_t nq,
X
Xu Peng 已提交
49 50
            const float* vectors, QueryResults& results) override;

G
groot 已提交
51
    virtual Status Query(const std::string& table_id, uint64_t k, uint64_t nq,
X
Xu Peng 已提交
52 53
            const float* vectors, const meta::DatesT& dates, QueryResults& results) override;

54 55 56 57
    virtual 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 已提交
58
    virtual Status DropAll() override;
X
Xu Peng 已提交
59

G
groot 已提交
60
    virtual Status Size(uint64_t& result) override;
X
Xu Peng 已提交
61

X
Xu Peng 已提交
62
    virtual ~DBImpl();
63

X
Xu Peng 已提交
64
private:
G
groot 已提交
65
    Status QuerySync(const std::string& table_id, uint64_t k, uint64_t nq,
G
groot 已提交
66 67
            const float* vectors, const meta::DatesT& dates, QueryResults& results);

68 69 70
    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 已提交
71

72

G
groot 已提交
73 74 75 76
    void StartTimerTasks();
    void BackgroundTimerTask();

    void StartMetricTask();
77

G
groot 已提交
78 79 80 81 82 83 84 85 86 87
    void StartCompactionTask();
    Status MergeFiles(const std::string& table_id,
                      const meta::DateT& date,
                      const meta::TableFilesSchema& files);
    Status BackgroundMergeFiles(const std::string& table_id);
    void BackgroundCompaction(std::set<std::string> table_ids);

    void StartBuildIndexTask();
    void BackgroundBuildIndex();
    Status BuildIndex(const meta::TableFileSchema&);
X
Xu Peng 已提交
88

X
Xu Peng 已提交
89
    const Options options_;
X
Xu Peng 已提交
90

X
Xu Peng 已提交
91 92
    Status bg_error_;
    std::atomic<bool> shutting_down_;
X
Xu Peng 已提交
93

X
Xu Peng 已提交
94 95
    std::thread bg_timer_thread_;

X
Xu Peng 已提交
96 97
    MetaPtr pMeta_;
    MemManagerPtr pMemMgr_;
X
Xu Peng 已提交
98

G
groot 已提交
99 100 101 102 103 104 105
    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 已提交
106 107
}; // DBImpl

108

X
Xu Peng 已提交
109
} // namespace engine
J
jinhai 已提交
110
} // namespace milvus
X
Xu Peng 已提交
111
} // namespace zilliz