/root/doris/be/src/olap/olap_meta.h
| Line | Count | Source | 
| 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 | 6 |                 : 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, std::string_view prefix, | 
| 64 |  |                    std::function<bool(std::string_view, std::string_view)> const& func); | 
| 65 |  |  | 
| 66 |  |     Status iterate(const int column_family_index, std::string_view seek_key, | 
| 67 |  |                    std::string_view prefix, | 
| 68 |  |                    std::function<bool(std::string_view, std::string_view)> 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 |  |     std::string _root_path; | 
| 78 |  |     // keep order of _db && _handles, we need destroy _handles before _db | 
| 79 |  |     std::unique_ptr<rocksdb::DB, std::function<void(rocksdb::DB*)>> _db; | 
| 80 |  |     std::vector<std::unique_ptr<rocksdb::ColumnFamilyHandle>> _handles; | 
| 81 |  | }; | 
| 82 |  |  | 
| 83 |  | } // namespace doris |