/root/doris/be/src/olap/olap_meta.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <rocksdb/iterator.h> |
21 | | |
22 | | #include <functional> |
23 | | #include <memory> |
24 | | #include <string> |
25 | | #include <vector> |
26 | | |
27 | | #include "common/status.h" |
28 | | |
29 | | namespace rocksdb { |
30 | | class ColumnFamilyHandle; |
31 | | class DB; |
32 | | class WriteBatch; |
33 | | } // namespace rocksdb |
34 | | |
35 | | namespace doris { |
36 | | |
37 | | class OlapMeta final { |
38 | | public: |
39 | | struct BatchEntry { |
40 | | const std::string& key; |
41 | | const std::string& value; |
42 | | |
43 | | BatchEntry(const std::string& key_arg, const std::string& value_arg) |
44 | 0 | : key(key_arg), value(value_arg) {} |
45 | | }; |
46 | | |
47 | | OlapMeta(const std::string& root_path); |
48 | | ~OlapMeta(); |
49 | | |
50 | | Status init(); |
51 | | |
52 | | Status get(const int column_family_index, const std::string& key, std::string* value); |
53 | | |
54 | | bool key_may_exist(const int column_family_index, const std::string& key, std::string* value); |
55 | | |
56 | | Status put(const int column_family_index, const std::string& key, const std::string& value); |
57 | | Status put(const int column_family_index, const std::vector<BatchEntry>& entries); |
58 | | Status put(rocksdb::WriteBatch* batch); |
59 | | |
60 | | Status remove(const int column_family_index, const std::string& key); |
61 | | Status remove(const int column_family_index, const std::vector<std::string>& keys); |
62 | | |
63 | | Status iterate(const int column_family_index, const std::string& prefix, |
64 | | std::function<bool(const std::string&, const std::string&)> const& func); |
65 | | |
66 | | Status iterate(const int column_family_index, const std::string& seek_key, |
67 | | const std::string& prefix, |
68 | | std::function<bool(const std::string&, const std::string&)> const& func); |
69 | | |
70 | 1 | [[nodiscard]] std::string get_root_path() const { return _root_path; } |
71 | | |
72 | 0 | rocksdb::ColumnFamilyHandle* get_handle(const int column_family_index) { |
73 | 0 | return _handles[column_family_index].get(); |
74 | 0 | } |
75 | | |
76 | | private: |
77 | | Status get_iterator(const int column_family_index, const std::string& seek_key, |
78 | | const std::string& prefix, rocksdb::Iterator*); |
79 | | |
80 | | std::string _root_path; |
81 | | // keep order of _db && _handles, we need destroy _handles before _db |
82 | | std::unique_ptr<rocksdb::DB, std::function<void(rocksdb::DB*)>> _db; |
83 | | std::vector<std::unique_ptr<rocksdb::ColumnFamilyHandle>> _handles; |
84 | | }; |
85 | | |
86 | | } // namespace doris |