diff --git a/bin/dsn.cmake b/bin/dsn.cmake index 66085c4a5f..6186b13943 100644 --- a/bin/dsn.cmake +++ b/bin/dsn.cmake @@ -1,5 +1,10 @@ include(${CMAKE_CURRENT_LIST_DIR}/compiler_info.cmake) +# Always generate the compilation database file (compile_commands.json) for use +# with various development tools, such as IWYU and Vim's YouCompleteMe plugin. +# See http://clang.llvm.org/docs/JSONCompilationDatabase.html +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) + function(ms_add_project PROJ_LANG PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PROJ_LIBS PROJ_LIB_PATH PROJ_BINPLACES PROJ_BINDIRS DO_INSTALL) if(DEFINED DSN_DEBUG_CMAKE) message(STATUS "PROJ_LANG = ${PROJ_LANG}") diff --git a/include/dsn/dist/replication/replication_ddl_client.h b/include/dsn/dist/replication/replication_ddl_client.h index 5d29b5ea6b..c1d0a33f1b 100644 --- a/include/dsn/dist/replication/replication_ddl_client.h +++ b/include/dsn/dist/replication/replication_ddl_client.h @@ -79,6 +79,8 @@ class replication_ddl_client list_nodes(const dsn::replication::node_status::type status, std::map &nodes); + dsn::error_code cluster_name(int64_t timeout_ms, std::string &cluster_name); + dsn::error_code cluster_info(const std::string &file_name, bool resolve_ip = false); dsn::error_code list_app(const std::string &app_name, diff --git a/src/core/tests/string_conv_test.cpp b/src/core/tests/string_conv_test.cpp index 9196d7e91c..e22b391a3d 100644 --- a/src/core/tests/string_conv_test.cpp +++ b/src/core/tests/string_conv_test.cpp @@ -29,7 +29,7 @@ TEST(string_conv, buf2bool) { - bool result; + bool result = false; ASSERT_TRUE(dsn::buf2bool("true", result)); ASSERT_EQ(result, true); @@ -60,7 +60,7 @@ TEST(string_conv, buf2bool) TEST(string_conv, buf2int32) { - int32_t result; + int32_t result = -1; ASSERT_TRUE(dsn::buf2int32(std::to_string(0), result)); ASSERT_EQ(result, 0); @@ -98,7 +98,7 @@ TEST(string_conv, buf2int32) TEST(string_conv, buf2int64) { - int64_t result; + int64_t result = -1; ASSERT_TRUE(dsn::buf2int64(std::to_string(0), result)); ASSERT_EQ(result, 0); @@ -143,7 +143,7 @@ TEST(string_conv, buf2int64) TEST(string_conv, buf2uint64) { - uint64_t result; + uint64_t result = 1; ASSERT_TRUE(dsn::buf2uint64(std::to_string(0), result)); ASSERT_EQ(result, 0); @@ -185,7 +185,7 @@ TEST(string_conv, buf2uint64) TEST(string_conv, int64_partial) { - int64_t result; + int64_t result = 0; ASSERT_FALSE(dsn::buf2int64("", result)); ASSERT_FALSE(dsn::buf2int64(" ", result)) << result; ASSERT_FALSE(dsn::buf2int64("-", result)) << result; @@ -201,7 +201,7 @@ TEST(string_conv, int64_partial) TEST(string_conv, uint64_partial) { - uint64_t result; + uint64_t result = 0; ASSERT_FALSE(dsn::buf2uint64("", result)); ASSERT_FALSE(dsn::buf2uint64(" ", result)) << result; ASSERT_FALSE(dsn::buf2uint64("-", result)) << result; @@ -216,7 +216,7 @@ TEST(string_conv, uint64_partial) TEST(string_conv, buf2double) { - double result; + double result = 0; ASSERT_TRUE(dsn::buf2double("1.1", result)); ASSERT_DOUBLE_EQ(result, 1.1); diff --git a/src/dist/replication/ddl_lib/replication_ddl_client.cpp b/src/dist/replication/ddl_lib/replication_ddl_client.cpp index a4557deb78..db4387d672 100644 --- a/src/dist/replication/ddl_lib/replication_ddl_client.cpp +++ b/src/dist/replication/ddl_lib/replication_ddl_client.cpp @@ -602,6 +602,38 @@ dsn::error_code replication_ddl_client::list_nodes(const dsn::replication::node_ #undef RESOLVE } +dsn::error_code replication_ddl_client::cluster_name(int64_t timeout_ms, std::string &cluster_name) +{ + std::shared_ptr req( + new configuration_cluster_info_request()); + + auto resp_task = request_meta(RPC_CM_CLUSTER_INFO, req, timeout_ms); + resp_task->wait(); + if (resp_task->error() != dsn::ERR_OK) { + return resp_task->error(); + } + + configuration_cluster_info_response resp; + ::dsn::unmarshall(resp_task->get_response(), resp); + if (resp.err != dsn::ERR_OK) { + return resp.err; + } + + std::string zk_root; + for (int i = 0; i < resp.keys.size(); ++i) { + if (resp.keys[i] == "zookeeper_root") { + zk_root = resp.values[i]; + } + } + + cluster_name.clear(); + if (!zk_root.empty() && zk_root.find("/pegasus/") == 0) { + cluster_name = zk_root.substr(9); + } + + return cluster_name.empty() ? dsn::ERR_UNKNOWN : dsn::ERR_OK; +} + dsn::error_code replication_ddl_client::cluster_info(const std::string &file_name, bool resolve_ip) { std::shared_ptr req(