MySQLMetaImpl.h 4.4 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 35
    Status
    CreateTable(TableSchema& table_schema) override;
S
starlord 已提交
36

S
starlord 已提交
37 38
    Status
    DescribeTable(TableSchema& table_schema) override;
S
starlord 已提交
39

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

S
starlord 已提交
43 44
    Status
    AllTables(std::vector<TableSchema>& table_schema_array) override;
Z
zhiru 已提交
45

S
starlord 已提交
46
    Status
G
groot 已提交
47
    DropTable(const std::string& table_id) override;
S
starlord 已提交
48

S
starlord 已提交
49 50
    Status
    DeleteTableFiles(const std::string& table_id) override;
Z
update  
zhiru 已提交
51

S
starlord 已提交
52 53
    Status
    CreateTableFile(TableFileSchema& file_schema) override;
S
starlord 已提交
54

S
starlord 已提交
55
    Status
56
    GetTableFiles(const std::string& table_id, const std::vector<size_t>& ids, TableFilesSchema& table_files) override;
Z
zhiru 已提交
57

S
starlord 已提交
58
    Status
59
    GetTableFilesBySegmentId(const std::string& segment_id, TableFilesSchema& table_files) override;
Z
zhiru 已提交
60

S
starlord 已提交
61 62
    Status
    UpdateTableIndex(const std::string& table_id, const TableIndex& index) override;
63

S
starlord 已提交
64 65
    Status
    UpdateTableFlag(const std::string& table_id, int64_t flag) override;
S
starlord 已提交
66

67 68 69 70 71 72 73 74 75
    Status
    UpdateTableFlushLSN(const std::string& table_id, uint64_t flush_lsn) override;

    Status
    GetTableFlushLSN(const std::string& table_id, uint64_t& flush_lsn) override;

    Status
    GetTableFilesByFlushLSN(uint64_t flush_lsn, TableFilesSchema& table_files) override;

G
groot 已提交
76 77 78 79 80 81 82 83 84
    Status
    UpdateTableFile(TableFileSchema& file_schema) override;

    Status
    UpdateTableFilesToIndex(const std::string& table_id) override;

    Status
    UpdateTableFiles(TableFilesSchema& files) override;

S
starlord 已提交
85 86
    Status
    DescribeTableIndex(const std::string& table_id, TableIndex& index) override;
87

S
starlord 已提交
88 89
    Status
    DropTableIndex(const std::string& table_id) override;
90

S
starlord 已提交
91
    Status
92 93
    CreatePartition(const std::string& table_id, const std::string& partition_name, const std::string& tag,
                    uint64_t lsn) override;
Z
zhiru 已提交
94

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

S
starlord 已提交
98
    Status
G
groot 已提交
99
    ShowPartitions(const std::string& table_id, std::vector<meta::TableSchema>& partition_schema_array) override;
G
groot 已提交
100 101 102

    Status
    GetPartitionName(const std::string& table_id, const std::string& tag, std::string& partition_name) override;
Z
zhiru 已提交
103

S
starlord 已提交
104
    Status
105
    FilesToSearch(const std::string& table_id, const std::vector<size_t>& ids, TableFilesSchema& files) override;
Z
zhiru 已提交
106

S
starlord 已提交
107
    Status
108
    FilesToMerge(const std::string& table_id, TableFilesSchema& files) override;
Z
zhiru 已提交
109

S
starlord 已提交
110 111
    Status
    FilesToIndex(TableFilesSchema&) override;
Z
zhiru 已提交
112

G
groot 已提交
113 114
    Status
    FilesByType(const std::string& table_id, const std::vector<int>& file_types,
G
groot 已提交
115
                TableFilesSchema& table_files) override;
G
groot 已提交
116

S
starlord 已提交
117 118
    Status
    Archive() override;
Z
zhiru 已提交
119

S
starlord 已提交
120 121
    Status
    Size(uint64_t& result) override;
Z
zhiru 已提交
122

S
starlord 已提交
123
    Status
124
    CleanUpShadowFiles() override;
Z
zhiru 已提交
125

126
    Status
127
    CleanUpFilesWithTTL(uint64_t seconds /*, CleanUpFilter* filter = nullptr*/) override;
Z
zhiru 已提交
128

S
starlord 已提交
129 130
    Status
    DropAll() override;
Z
zhiru 已提交
131

S
starlord 已提交
132 133
    Status
    Count(const std::string& table_id, uint64_t& result) override;
Z
zhiru 已提交
134

135 136 137 138 139 140
    Status
    SetGlobalLastLSN(uint64_t lsn) override;

    Status
    GetGlobalLastLSN(uint64_t& lsn) override;

J
jinhai 已提交
141
 private:
S
starlord 已提交
142 143 144 145 146 147 148 149 150 151 152
    Status
    NextFileId(std::string& file_id);
    Status
    NextTableId(std::string& table_id);
    Status
    DiscardFiles(int64_t to_discard_size);

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

S
starlord 已提交
154
 private:
J
jinhai 已提交
155 156
    const DBMetaOptions options_;
    const int mode_;
Z
zhiru 已提交
157

J
jinhai 已提交
158
    std::shared_ptr<MySQLConnectionPool> mysql_connection_pool_;
S
starlord 已提交
159
    bool safe_grab_ = false;
Z
zhiru 已提交
160

G
groot 已提交
161
    std::mutex genid_mutex_;
S
starlord 已提交
162 163
    //        std::mutex connectionMutex_;
};  // DBMetaImpl
Z
zhiru 已提交
164

S
starlord 已提交
165 166 167
}  // namespace meta
}  // namespace engine
}  // namespace milvus