MySQLMetaImpl.h 3.8 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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
//
//   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.

Z
zhiru 已提交
18 19 20
#pragma once

#include "Meta.h"
S
starlord 已提交
21
#include "db/Options.h"
Z
zhiru 已提交
22
#include "MySQLConnectionPool.h"
Z
zhiru 已提交
23

Z
zhiru 已提交
24 25 26
#include "mysql++/mysql++.h"
#include <mutex>

J
jinhai 已提交
27

Z
zhiru 已提交
28 29 30 31 32 33
namespace zilliz {
namespace milvus {
namespace engine {
namespace meta {

//    auto StoragePrototype(const std::string& path);
J
jinhai 已提交
34
using namespace mysqlpp;
Z
zhiru 已提交
35

J
jinhai 已提交
36 37 38
class MySQLMetaImpl : public Meta {
 public:
    MySQLMetaImpl(const DBMetaOptions &options_, const int &mode);
39
    ~MySQLMetaImpl();
Z
zhiru 已提交
40

J
jinhai 已提交
41
    Status CreateTable(TableSchema &table_schema) override;
S
starlord 已提交
42

J
jinhai 已提交
43
    Status DescribeTable(TableSchema &group_info_) override;
S
starlord 已提交
44

J
jinhai 已提交
45
    Status HasTable(const std::string &table_id, bool &has_or_not) override;
S
starlord 已提交
46

J
jinhai 已提交
47
    Status AllTables(std::vector<TableSchema> &table_schema_array) override;
Z
zhiru 已提交
48

J
jinhai 已提交
49
    Status DeleteTable(const std::string &table_id) override;
S
starlord 已提交
50

J
jinhai 已提交
51
    Status DeleteTableFiles(const std::string &table_id) override;
Z
update  
zhiru 已提交
52

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

J
jinhai 已提交
55 56
    Status DropPartitionsByDates(const std::string &table_id,
                                 const DatesT &dates) override;
Z
zhiru 已提交
57

J
jinhai 已提交
58 59 60
    Status GetTableFiles(const std::string &table_id,
                         const std::vector<size_t> &ids,
                         TableFilesSchema &table_files) override;
Z
zhiru 已提交
61

62 63 64
    Status FilesByType(const std::string &table_id,
                       const std::vector<int> &file_types,
                       std::vector<std::string> &file_ids) override;
P
peng.xu 已提交
65

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

Z
zhiru 已提交
68
    Status UpdateTableFlag(const std::string &table_id, int64_t flag) override;
S
starlord 已提交
69

70 71 72 73
    Status DescribeTableIndex(const std::string &table_id, TableIndex& index) override;

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

J
jinhai 已提交
74
    Status UpdateTableFile(TableFileSchema &file_schema) override;
Z
zhiru 已提交
75

J
jinhai 已提交
76
    Status UpdateTableFilesToIndex(const std::string &table_id) override;
P
peng.xu 已提交
77

J
jinhai 已提交
78
    Status UpdateTableFiles(TableFilesSchema &files) override;
Z
zhiru 已提交
79

X
xj.lin 已提交
80 81 82 83
    Status FilesToSearch(const std::string &table_id,
                         const std::vector<size_t> &ids,
                         const DatesT &partition,
                         DatePartionedTableFilesSchema &files) override;
Z
zhiru 已提交
84

J
jinhai 已提交
85 86
    Status FilesToMerge(const std::string &table_id,
                        DatePartionedTableFilesSchema &files) override;
Z
zhiru 已提交
87

J
jinhai 已提交
88
    Status FilesToIndex(TableFilesSchema &) override;
Z
zhiru 已提交
89

J
jinhai 已提交
90
    Status Archive() override;
Z
zhiru 已提交
91

J
jinhai 已提交
92
    Status Size(uint64_t &result) override;
Z
zhiru 已提交
93

J
jinhai 已提交
94
    Status CleanUp() override;
Z
zhiru 已提交
95

J
jinhai 已提交
96
    Status CleanUpFilesWithTTL(uint16_t seconds) override;
Z
zhiru 已提交
97

J
jinhai 已提交
98
    Status DropAll() override;
Z
zhiru 已提交
99

J
jinhai 已提交
100
    Status Count(const std::string &table_id, uint64_t &result) override;
Z
zhiru 已提交
101

J
jinhai 已提交
102 103 104 105
 private:
    Status NextFileId(std::string &file_id);
    Status NextTableId(std::string &table_id);
    Status DiscardFiles(long long to_discard_size);
106 107

    void ValidateMetaSchema();
J
jinhai 已提交
108
    Status Initialize();
Z
zhiru 已提交
109

110
private:
J
jinhai 已提交
111 112
    const DBMetaOptions options_;
    const int mode_;
Z
zhiru 已提交
113

J
jinhai 已提交
114 115
    std::shared_ptr<MySQLConnectionPool> mysql_connection_pool_;
    bool safe_grab = false;
Z
zhiru 已提交
116

Z
zhiru 已提交
117
//        std::mutex connectionMutex_;
J
jinhai 已提交
118
}; // DBMetaImpl
Z
zhiru 已提交
119 120 121 122 123

} // namespace meta
} // namespace engine
} // namespace milvus
} // namespace zilliz