Loading...
Searching...
No Matches
kv_service.cpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#include <glog/logging.h>
21
27#ifdef ENABLE_LEVELDB
29#endif
30#ifdef ENABLE_ROCKSDB
32#endif
33
34using namespace resdb;
35using namespace resdb::storage;
36
37void ShowUsage() {
38 printf("<config> <private_key> <cert_file> [logging_dir]\n");
39}
40
41std::unique_ptr<Storage> NewStorage(const std::string& db_path,
42 const ResConfigData& config_data) {
43#ifdef ENABLE_ROCKSDB
44 LOG(INFO) << "use rocksdb storage.";
45 return NewResRocksDB(db_path, config_data);
46#endif
47
48#ifdef ENABLE_LEVELDB
49 LOG(INFO) << "use leveldb storage.";
50 return NewResLevelDB(db_path, config_data);
51#endif
52
53 LOG(INFO) << "use memory storage.";
54 return NewMemoryDB();
55}
56
57int main(int argc, char** argv) {
58 if (argc < 4) {
59 ShowUsage();
60 exit(0);
61 }
62 google::InitGoogleLogging(argv[0]);
63
64 char* config_file = argv[1];
65 char* private_key_file = argv[2];
66 char* cert_file = argv[3];
67
68 if (argc == 5) {
69 std::string grafana_port = argv[4];
70 std::string grafana_address = "0.0.0.0:" + grafana_port;
71
72 auto monitor_port = Stats::GetGlobalStats(5);
73 monitor_port->SetPrometheus(grafana_address);
74 LOG(ERROR) << "monitoring prot:" << grafana_address;
75 }
76
77 std::unique_ptr<ResDBConfig> config =
78 GenerateResDBConfig(config_file, private_key_file, cert_file);
79 ResConfigData config_data = config->GetConfigData();
80
81 std::string db_path = std::to_string(config->GetSelfInfo().port()) + "_db/";
82 LOG(INFO) << "db path:" << db_path;
83
84 auto server = GenerateResDBServer(
85 config_file, private_key_file, cert_file,
86 std::make_unique<KVExecutor>(NewStorage(db_path, config_data)), nullptr);
87 server->Run();
88}
static Stats * GetGlobalStats(int sleep_seconds=5)
Definition stats.cpp:29
int main(int argc, char **argv)
std::unique_ptr< Storage > NewStorage(const std::string &db_path, const ResConfigData &config_data)
void ShowUsage()
std::unique_ptr< Storage > NewResRocksDB(const std::string &path, std::optional< RocksDBInfo > config)
Definition rocksdb.cpp:29
std::unique_ptr< Storage > NewResLevelDB(const std::string &path, std::optional< LevelDBInfo > config)
Definition leveldb.cpp:29
std::unique_ptr< Storage > NewMemoryDB()
Definition memory_db.cpp:27
std::unique_ptr< ServiceNetwork > GenerateResDBServer(char *config_file, char *private_key_file, char *cert_file, std::unique_ptr< TransactionManager > executor, char *logging_dir, std::function< void(ResDBConfig *config)> config_handler)
std::unique_ptr< ResDBConfig > GenerateResDBConfig(const std::string &config_file, const std::string &private_key_file, const std::string &cert_file, std::optional< ReplicaInfo > self_info, std::optional< ConfigGenFunc > gen_func)