storage/kv_engine/engine_selector.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <set> | ||
| 4 | #include <stdexcept> | ||
| 5 | #include <string> | ||
| 6 | |||
| 7 | #include "base_kv.h" | ||
| 8 | |||
| 9 | namespace base { | ||
| 10 | |||
| 11 | struct EngineResolved { | ||
| 12 | std::string engine; | ||
| 13 | BaseKVConfig cfg; | ||
| 14 | }; | ||
| 15 | |||
| 16 | 1112 | inline EngineResolved ResolveEngine(BaseKVConfig cfg) { | |
| 17 | 1112 | auto& j = cfg.json_config_; | |
| 18 | |||
| 19 | 1112 | if (j.contains("external_engine_type")) { | |
| 20 | 2 | throw std::invalid_argument( | |
| 21 | 4 | "external_engine_type is removed; use engine_type"); | |
| 22 | } | ||
| 23 | const std::string engine = | ||
| 24 | 1110 | j.contains("engine_type") | |
| 25 | 1072 | ? j.at("engine_type").get<std::string>() | |
| 26 | 2182 | : "KVEngineComposite"; | |
| 27 | static const std::set<std::string> kKnownEngines = { | ||
| 28 | "KVEngineComposite", | ||
| 29 | "KVEnginePetKV", | ||
| 30 | "KVEngineDETable", | ||
| 31 | "KVEngineFasterKV", | ||
| 32 | "KVEngineHPSHashMap", | ||
| 33 | "KVEngineHPSRocksDB", | ||
| 34 | 1158 | }; | |
| 35 | 1110 | if (!kKnownEngines.count(engine)) { | |
| 36 | 2 | throw std::invalid_argument("unknown engine_type: " + engine); | |
| 37 | } | ||
| 38 | |||
| 39 | 2216 | return EngineResolved{engine, std::move(cfg)}; | |
| 40 | 1110 | } | |
| 41 | |||
| 42 | } // namespace base | ||
| 43 |