MySQLMetaImpl.h 4.0 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 14
#pragma once

#include "Meta.h"
Z
zhiru 已提交
15
#include "MySQLConnectionPool.h"
S
starlord 已提交
16
#include "db/Options.h"
Z
zhiru 已提交
17

S
starlord 已提交
18
#include <mysql++/mysql++.h>
S
starlord 已提交
19
#include <memory>
Z
zhiru 已提交
20
#include <mutex>
S
starlord 已提交
21
#include <string>
S
starlord 已提交
22
#include <vector>
J
jinhai 已提交
23

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

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

S
starlord 已提交
33 34
    Status
    CreateTable(TableSchema& table_schema) override;
S
starlord 已提交
35

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

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

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

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

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

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

S
starlord 已提交
54
    Status
G
groot 已提交
55
    DropDataByDate(const std::string& table_id, const DatesT& dates) override;
Z
zhiru 已提交
56

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

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

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

G
groot 已提交
66 67 68 69 70 71 72 73 74
    Status
    UpdateTableFile(TableFileSchema& file_schema) override;

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

    Status
    UpdateTableFiles(TableFilesSchema& files) override;

S
starlord 已提交
75 76
    Status
    DescribeTableIndex(const std::string& table_id, TableIndex& index) override;
77

S
starlord 已提交
78 79
    Status
    DropTableIndex(const std::string& table_id) override;
80

S
starlord 已提交
81
    Status
G
groot 已提交
82
    CreatePartition(const std::string& table_id, const std::string& partition_name, const std::string& tag) override;
Z
zhiru 已提交
83

S
starlord 已提交
84
    Status
G
groot 已提交
85
    DropPartition(const std::string& partition_name) override;
P
peng.xu 已提交
86

S
starlord 已提交
87
    Status
G
groot 已提交
88
    ShowPartitions(const std::string& table_id, std::vector<meta::TableSchema>& partition_schema_array) override;
G
groot 已提交
89 90 91

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

S
starlord 已提交
93
    Status
94
    FilesToSearch(const std::string& table_id, const std::vector<size_t>& ids, const DatesT& dates,
S
starlord 已提交
95
                  DatePartionedTableFilesSchema& files) override;
Z
zhiru 已提交
96

S
starlord 已提交
97 98
    Status
    FilesToMerge(const std::string& table_id, DatePartionedTableFilesSchema& files) override;
Z
zhiru 已提交
99

S
starlord 已提交
100 101
    Status
    FilesToIndex(TableFilesSchema&) override;
Z
zhiru 已提交
102

G
groot 已提交
103 104
    Status
    FilesByType(const std::string& table_id, const std::vector<int>& file_types,
G
groot 已提交
105
                TableFilesSchema& table_files) override;
G
groot 已提交
106

S
starlord 已提交
107 108
    Status
    Archive() override;
Z
zhiru 已提交
109

S
starlord 已提交
110 111
    Status
    Size(uint64_t& result) override;
Z
zhiru 已提交
112

S
starlord 已提交
113
    Status
114
    CleanUpShadowFiles() override;
Z
zhiru 已提交
115

116
    Status
G
groot 已提交
117
    CleanUpFilesWithTTL(uint64_t seconds, CleanUpFilter* filter = nullptr) override;
Z
zhiru 已提交
118

S
starlord 已提交
119 120
    Status
    DropAll() override;
Z
zhiru 已提交
121

S
starlord 已提交
122 123
    Status
    Count(const std::string& table_id, uint64_t& result) override;
Z
zhiru 已提交
124

J
jinhai 已提交
125
 private:
S
starlord 已提交
126 127 128 129 130 131 132 133 134 135 136
    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 已提交
137

S
starlord 已提交
138
 private:
J
jinhai 已提交
139 140
    const DBMetaOptions options_;
    const int mode_;
Z
zhiru 已提交
141

J
jinhai 已提交
142
    std::shared_ptr<MySQLConnectionPool> mysql_connection_pool_;
S
starlord 已提交
143
    bool safe_grab_ = false;
Z
zhiru 已提交
144

G
groot 已提交
145
    std::mutex genid_mutex_;
S
starlord 已提交
146 147
    //        std::mutex connectionMutex_;
};  // DBMetaImpl
Z
zhiru 已提交
148

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