Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/redis_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class RedisServiceImpl : public brpc::RedisService

bool Init(brpc::Server &brpc_server);

// Second phase of initialization, to be called after DataSubstrate::Start()
bool Start(brpc::Server &brpc_server);

void Stop();

// The number of master nodes serving at least one hash slot in the cluster.
Expand Down
36 changes: 32 additions & 4 deletions src/redis_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,16 @@ int main(int argc, char *argv[])
// Convert eloqkv flags to tx flags
ConvertEloqkvFlagsToTxFlags(&config_reader);

if (!DataSubstrate::InitializeGlobal(config_file))
// Step 1: Initialize DataSubstrate
if (!DataSubstrate::Instance().Init(config_file))
{
LOG(ERROR) << "Failed to initialize DataSubstrate.";
return -1;
}

// Step 2: Initialize and register EloqKv engine
LOG(INFO) << "Starting EloqKV Server ...";
DataSubstrate::Instance().EnableEngine(txservice::TableEngine::EloqKv);
brpc::Server server;
brpc::ServerOptions server_options;
auto redis_service_impl =
Expand All @@ -463,13 +467,37 @@ int main(int argc, char *argv[])
{
LOG(ERROR) << "Failed to start EloqKV server.";
redis_service_impl->Stop();
DataSubstrate::GetGlobal()->Shutdown();
DataSubstrate::Instance().Shutdown();
#if BRPC_WITH_GLOG
google::ShutdownGoogleLogging();
#endif
return -1;
}

// Step 3: Start DataSubstrate
if (!DataSubstrate::Instance().Start())
{
LOG(ERROR) << "Failed to start DataSubstrate.";
redis_service_impl->Stop();
DataSubstrate::Instance().Shutdown();
#if BRPC_WITH_GLOG
google::ShutdownGoogleLogging();
#endif
return -1;
}

// Step 4: Start Redis service
EloqKV::RedisServiceImpl *redis_service_ptr = redis_service_impl.get();
if (!redis_service_ptr->Start(server))
{
LOG(ERROR) << "Failed to start Redis service.";
redis_service_ptr->Stop();
DataSubstrate::Instance().Shutdown();
#if BRPC_WITH_GLOG
google::ShutdownGoogleLogging();
#endif
return -1;
}
std::string n_bthreads;
GFLAGS_NAMESPACE::GetCommandLineOption("bthread_concurrency", &n_bthreads);
server_options.num_threads = std::stoi(n_bthreads);
Expand All @@ -480,7 +508,7 @@ int main(int argc, char *argv[])
{
LOG(ERROR) << "Failed to start EloqKV server.";
redis_service_ptr->Stop();
DataSubstrate::GetGlobal()->Shutdown();
DataSubstrate::Instance().Shutdown();
#if BRPC_WITH_GLOG
google::ShutdownGoogleLogging();
#endif
Expand All @@ -503,7 +531,7 @@ int main(int argc, char *argv[])
{
std::cout << "\nEloqKV Server Stopping..." << std::endl;
}
DataSubstrate::GetGlobal()->Shutdown();
DataSubstrate::Instance().Shutdown();
redis_service_ptr->Stop();

if (!FLAGS_alsologtostderr)
Expand Down
Loading