MySQLMetaImpl.h 4.7 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

Z
zhiru 已提交
12 13
#pragma once

S
starlord 已提交
14
#include <mysql++/mysql++.h>
15

S
starlord 已提交
16
#include <memory>
Z
zhiru 已提交
17
#include <mutex>
S
starlord 已提交
18
#include <string>
S
starlord 已提交
19
#include <vector>
J
jinhai 已提交
20

21 22 23 24
#include "Meta.h"
#include "MySQLConnectionPool.h"
#include "db/Options.h"

Z
zhiru 已提交
25 26 27 28
namespace milvus {
namespace engine {
namespace meta {

J
jinhai 已提交
29 30
class MySQLMetaImpl : public Meta {
 public:
S
starlord 已提交
31
    MySQLMetaImpl(const DBMetaOptions& options, const int& mode);
32
    ~MySQLMetaImpl();
Z
zhiru 已提交
33

S
starlord 已提交
34
    Status
G
groot 已提交
35
    CreateCollection(CollectionSchema& collection_schema) override;
S
starlord 已提交
36

S
starlord 已提交
37
    Status
G
groot 已提交
38
    DescribeCollection(CollectionSchema& collection_schema) override;
S
starlord 已提交
39

S
starlord 已提交
40
    Status
41
    HasCollection(const std::string& collection_id, bool& has_or_not) override;
S
starlord 已提交
42

S
starlord 已提交
43
    Status
G
groot 已提交
44
    AllCollections(std::vector<CollectionSchema>& collection_schema_array) override;
Z
zhiru 已提交
45

S
starlord 已提交
46
    Status
47
    DropCollection(const std::string& collection_id) override;
S
starlord 已提交
48

S
starlord 已提交
49
    Status
G
groot 已提交
50
    DeleteCollectionFiles(const std::string& collection_id) override;
Z
update  
zhiru 已提交
51

S
starlord 已提交
52
    Status
53
    CreateCollectionFile(SegmentSchema& file_schema) override;
S
starlord 已提交
54

S
starlord 已提交
55
    Status
G
groot 已提交
56 57
    GetCollectionFiles(const std::string& collection_id, const std::vector<size_t>& ids,
                       SegmentsSchema& collection_files) override;
Z
zhiru 已提交
58

S
starlord 已提交
59
    Status
G
groot 已提交
60
    GetCollectionFilesBySegmentId(const std::string& segment_id, SegmentsSchema& collection_files) override;
Z
zhiru 已提交
61

S
starlord 已提交
62
    Status
63
    UpdateCollectionIndex(const std::string& collection_id, const CollectionIndex& index) override;
64

S
starlord 已提交
65
    Status
66
    UpdateCollectionFlag(const std::string& collection_id, int64_t flag) override;
S
starlord 已提交
67

68
    Status
G
groot 已提交
69
    UpdateCollectionFlushLSN(const std::string& collection_id, uint64_t flush_lsn) override;
70 71

    Status
72
    GetCollectionFlushLSN(const std::string& collection_id, uint64_t& flush_lsn) override;
73

G
groot 已提交
74
    Status
75
    UpdateCollectionFile(SegmentSchema& file_schema) override;
G
groot 已提交
76 77

    Status
78
    UpdateCollectionFilesToIndex(const std::string& collection_id) override;
G
groot 已提交
79 80

    Status
81
    UpdateCollectionFiles(SegmentsSchema& files) override;
G
groot 已提交
82

83
    Status
84
    UpdateCollectionFilesRowCount(SegmentsSchema& files) override;
85

S
starlord 已提交
86
    Status
87
    DescribeCollectionIndex(const std::string& collection_id, CollectionIndex& index) override;
88

S
starlord 已提交
89
    Status
90
    DropCollectionIndex(const std::string& collection_id) override;
91

S
starlord 已提交
92
    Status
J
Jin Hai 已提交
93
    CreatePartition(const std::string& collection_id, const std::string& partition_name, const std::string& tag,
94
                    uint64_t lsn) override;
Z
zhiru 已提交
95

S
starlord 已提交
96
    Status
G
groot 已提交
97
    DropPartition(const std::string& partition_name) override;
P
peng.xu 已提交
98

S
starlord 已提交
99
    Status
J
Jin Hai 已提交
100 101
    ShowPartitions(const std::string& collection_id,
                   std::vector<meta::CollectionSchema>& partition_schema_array) override;
G
groot 已提交
102 103

    Status
J
Jin Hai 已提交
104
    GetPartitionName(const std::string& collection_id, const std::string& tag, std::string& partition_name) override;
Z
zhiru 已提交
105

S
starlord 已提交
106
    Status
J
Jin Hai 已提交
107
    FilesToSearch(const std::string& collection_id, SegmentsSchema& files) override;
Z
zhiru 已提交
108

S
starlord 已提交
109
    Status
J
Jin Hai 已提交
110
    FilesToMerge(const std::string& collection_id, SegmentsSchema& files) override;
Z
zhiru 已提交
111

S
starlord 已提交
112
    Status
J
Jin Hai 已提交
113
    FilesToIndex(SegmentsSchema&) override;
Z
zhiru 已提交
114

G
groot 已提交
115
    Status
J
Jin Hai 已提交
116
    FilesByType(const std::string& collection_id, const std::vector<int>& file_types, SegmentsSchema& files) override;
117 118

    Status
G
groot 已提交
119
    FilesByID(const std::vector<size_t>& ids, SegmentsSchema& collection_files) override;
G
groot 已提交
120

S
starlord 已提交
121 122
    Status
    Archive() override;
Z
zhiru 已提交
123

S
starlord 已提交
124 125
    Status
    Size(uint64_t& result) override;
Z
zhiru 已提交
126

S
starlord 已提交
127
    Status
128
    CleanUpShadowFiles() override;
Z
zhiru 已提交
129

130
    Status
131
    CleanUpFilesWithTTL(uint64_t seconds /*, CleanUpFilter* filter = nullptr*/) override;
Z
zhiru 已提交
132

S
starlord 已提交
133 134
    Status
    DropAll() override;
Z
zhiru 已提交
135

S
starlord 已提交
136
    Status
J
Jin Hai 已提交
137
    Count(const std::string& collection_id, uint64_t& result) override;
Z
zhiru 已提交
138

139 140 141 142 143 144
    Status
    SetGlobalLastLSN(uint64_t lsn) override;

    Status
    GetGlobalLastLSN(uint64_t& lsn) override;

J
jinhai 已提交
145
 private:
S
starlord 已提交
146 147 148
    Status
    NextFileId(std::string& file_id);
    Status
G
groot 已提交
149
    NextCollectionId(std::string& collection_id);
S
starlord 已提交
150 151 152 153 154 155 156
    Status
    DiscardFiles(int64_t to_discard_size);

    void
    ValidateMetaSchema();
    Status
    Initialize();
Z
zhiru 已提交
157

S
starlord 已提交
158
 private:
J
jinhai 已提交
159 160
    const DBMetaOptions options_;
    const int mode_;
Z
zhiru 已提交
161

J
jinhai 已提交
162
    std::shared_ptr<MySQLConnectionPool> mysql_connection_pool_;
S
starlord 已提交
163
    bool safe_grab_ = false;
Z
zhiru 已提交
164

J
Jin Hai 已提交
165
    std::mutex meta_mutex_;
G
groot 已提交
166
    std::mutex genid_mutex_;
S
starlord 已提交
167 168
    //        std::mutex connectionMutex_;
};  // DBMetaImpl
Z
zhiru 已提交
169

S
starlord 已提交
170 171 172
}  // namespace meta
}  // namespace engine
}  // namespace milvus