DB.h 4.6 KB
Newer Older
1
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
J
jinhai 已提交
2
//
3 4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
J
jinhai 已提交
5
//
6 7 8 9 10
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
J
jinhai 已提交
11

X
Xu Peng 已提交
12
#pragma once
X
Xu Peng 已提交
13

Z
Zhiru Zhu 已提交
14 15 16 17
#include <memory>
#include <string>
#include <vector>

X
Xu Peng 已提交
18
#include "Options.h"
X
Xu Peng 已提交
19
#include "Types.h"
S
starlord 已提交
20
#include "meta/Meta.h"
Z
Zhiru Zhu 已提交
21
#include "server/context/Context.h"
S
starlord 已提交
22
#include "utils/Status.h"
X
Xu Peng 已提交
23

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

class Env;

class DB {
S
starlord 已提交
30
 public:
S
starlord 已提交
31
    DB() = default;
32

S
starlord 已提交
33
    DB(const DB&) = delete;
34

S
starlord 已提交
35 36
    DB&
    operator=(const DB&) = delete;
S
starlord 已提交
37 38

    virtual ~DB() = default;
X
Xu Peng 已提交
39

S
starlord 已提交
40 41
    virtual Status
    Start() = 0;
42

S
starlord 已提交
43 44 45 46
    virtual Status
    Stop() = 0;

    virtual Status
J
Jin Hai 已提交
47
    CreateTable(meta::CollectionSchema& table_schema_) = 0;
G
groot 已提交
48

S
starlord 已提交
49
    virtual Status
J
Jin Hai 已提交
50
    DropTable(const std::string& collection_id) = 0;
G
groot 已提交
51

S
starlord 已提交
52
    virtual Status
J
Jin Hai 已提交
53
    DescribeTable(meta::CollectionSchema& table_schema_) = 0;
G
groot 已提交
54

S
starlord 已提交
55
    virtual Status
J
Jin Hai 已提交
56
    HasTable(const std::string& collection_id, bool& has_or_not_) = 0;
G
groot 已提交
57

58
    virtual Status
J
Jin Hai 已提交
59
    HasNativeTable(const std::string& collection_id, bool& has_or_not_) = 0;
60

S
starlord 已提交
61
    virtual Status
J
Jin Hai 已提交
62
    AllTables(std::vector<meta::CollectionSchema>& table_schema_array) = 0;
G
groot 已提交
63

64
    virtual Status
J
Jin Hai 已提交
65
    GetTableInfo(const std::string& collection_id, TableInfo& table_info) = 0;
66

S
starlord 已提交
67
    virtual Status
J
Jin Hai 已提交
68
    GetTableRowCount(const std::string& collection_id, uint64_t& row_count) = 0;
G
groot 已提交
69

S
starlord 已提交
70
    virtual Status
J
Jin Hai 已提交
71
    PreloadTable(const std::string& collection_id) = 0;
G
groot 已提交
72

S
starlord 已提交
73
    virtual Status
J
Jin Hai 已提交
74
    UpdateTableFlag(const std::string& collection_id, int64_t flag) = 0;
S
starlord 已提交
75 76

    virtual Status
J
Jin Hai 已提交
77
    CreatePartition(const std::string& collection_id, const std::string& partition_name,
G
groot 已提交
78 79 80 81
                    const std::string& partition_tag) = 0;

    virtual Status
    DropPartition(const std::string& partition_name) = 0;
S
starlord 已提交
82 83

    virtual Status
J
Jin Hai 已提交
84
    DropPartitionByTag(const std::string& collection_id, const std::string& partition_tag) = 0;
S
starlord 已提交
85 86

    virtual Status
J
Jin Hai 已提交
87
    ShowPartitions(const std::string& collection_id, std::vector<meta::CollectionSchema>& partition_schema_array) = 0;
S
starlord 已提交
88 89

    virtual Status
J
Jin Hai 已提交
90
    InsertVectors(const std::string& collection_id, const std::string& partition_tag, VectorsData& vectors) = 0;
G
groot 已提交
91 92

    virtual Status
J
Jin Hai 已提交
93
    DeleteVector(const std::string& collection_id, IDNumber vector_id) = 0;
94 95

    virtual Status
J
Jin Hai 已提交
96
    DeleteVectors(const std::string& collection_id, IDNumbers vector_ids) = 0;
97 98

    virtual Status
J
Jin Hai 已提交
99
    Flush(const std::string& collection_id) = 0;
100 101 102 103 104

    virtual Status
    Flush() = 0;

    virtual Status
J
Jin Hai 已提交
105
    Compact(const std::string& collection_id) = 0;
106 107

    virtual Status
J
Jin Hai 已提交
108
    GetVectorByID(const std::string& collection_id, const IDNumber& vector_id, VectorsData& vector) = 0;
109 110

    virtual Status
J
Jin Hai 已提交
111
    GetVectorIDs(const std::string& collection_id, const std::string& segment_id, IDNumbers& vector_ids) = 0;
112 113 114 115 116

    //    virtual Status
    //    Merge(const std::set<std::string>& table_ids) = 0;

    virtual Status
J
Jin Hai 已提交
117
    QueryByID(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
118 119
              const std::vector<std::string>& partition_tags, uint64_t k, const milvus::json& extra_params,
              IDNumber vector_id, ResultIds& result_ids, ResultDistances& result_distances) = 0;
G
groot 已提交
120 121

    virtual Status
J
Jin Hai 已提交
122
    Query(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
123 124
          const std::vector<std::string>& partition_tags, uint64_t k, const milvus::json& extra_params,
          const VectorsData& vectors, ResultIds& result_ids, ResultDistances& result_distances) = 0;
G
groot 已提交
125 126

    virtual Status
127 128 129
    QueryByFileID(const std::shared_ptr<server::Context>& context, const std::vector<std::string>& file_ids, uint64_t k,
                  const milvus::json& extra_params, const VectorsData& vectors, ResultIds& result_ids,
                  ResultDistances& result_distances) = 0;
S
starlord 已提交
130 131 132 133 134

    virtual Status
    Size(uint64_t& result) = 0;

    virtual Status
J
Jin Hai 已提交
135
    CreateIndex(const std::string& collection_id, const TableIndex& index) = 0;
G
groot 已提交
136

S
starlord 已提交
137
    virtual Status
J
Jin Hai 已提交
138
    DescribeIndex(const std::string& collection_id, TableIndex& index) = 0;
G
groot 已提交
139

S
starlord 已提交
140
    virtual Status
J
Jin Hai 已提交
141
    DropIndex(const std::string& collection_id) = 0;
S
starlord 已提交
142 143 144 145

    virtual Status
    DropAll() = 0;
};  // DB
X
Xu Peng 已提交
146

S
starlord 已提交
147 148
using DBPtr = std::shared_ptr<DB>;

S
starlord 已提交
149 150
}  // namespace engine
}  // namespace milvus