From ca030ff12b66ab63ed3d486a62bb469c763dcf72 Mon Sep 17 00:00:00 2001 From: Simone Rondelli Date: Fri, 27 Aug 2021 15:59:15 -0400 Subject: [PATCH 1/5] [GAIAPLAT-1236] db_server - better error message when 'Address already in use' --- production/db/core/src/db_server.cpp | 12 ++++++++++++ production/db/core/src/db_server_exec.cpp | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/production/db/core/src/db_server.cpp b/production/db/core/src/db_server.cpp index 674ee5a36723..74e55a395c1f 100644 --- a/production/db/core/src/db_server.cpp +++ b/production/db/core/src/db_server.cpp @@ -927,6 +927,14 @@ void server_t::init_listening_socket(const std::string& socket_name) socklen_t server_addr_size = sizeof(server_addr.sun_family) + 1 + ::strlen(&server_addr.sun_path[1]); if (-1 == ::bind(listening_socket, reinterpret_cast(&server_addr), server_addr_size)) { + // TODO it would be nice to have a common error handler that can handle common errors. + if (errno == EADDRINUSE) + { + cerr << "ERROR: bind() failed! - " << (::strerror(errno)) << endl; + cerr << "The Gaia Database Server cannot start because another instance is already running. Please stop any instances of the server that are running." << endl; + exit(1); + } + throw_system_error("bind() failed!"); } if (-1 == ::listen(listening_socket, 0)) @@ -2596,3 +2604,7 @@ void server_t::run(server_config_t server_conf) } } } + +void server_t::handle_common_errors() +{ +} diff --git a/production/db/core/src/db_server_exec.cpp b/production/db/core/src/db_server_exec.cpp index f8d5deb830a6..263b17b8ce2b 100644 --- a/production/db/core/src/db_server_exec.cpp +++ b/production/db/core/src/db_server_exec.cpp @@ -309,6 +309,8 @@ static server_config_t process_command_line(int argc, char* argv[]) } } + std::cerr << "Starting " << c_db_server_name << "..." << std::endl; + gaia_config_fallback_t gaia_conf{conf_file_path}; data_dir = gaia_conf.get_value( @@ -374,7 +376,7 @@ int main(int argc, char* argv[]) { auto server_conf = process_command_line(argc, argv); - std::cerr << "Starting " << c_db_server_exec_name << "..." << std::endl; + std::cerr << c_db_server_name << " started!" << std::endl; gaia::db::server_t::run(server_conf); } From 5be63093c169432e387d854ad577223b72b6c06d Mon Sep 17 00:00:00 2001 From: Simone Rondelli Date: Fri, 27 Aug 2021 16:09:13 -0400 Subject: [PATCH 2/5] Fix error message: --- production/db/core/src/db_server.cpp | 29 +++++++++------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/production/db/core/src/db_server.cpp b/production/db/core/src/db_server.cpp index 74e55a395c1f..cd15ed7af5b5 100644 --- a/production/db/core/src/db_server.cpp +++ b/production/db/core/src/db_server.cpp @@ -373,9 +373,7 @@ void server_t::handle_decide_txn( // returned, but we don't close the log fd (even for an abort decision), // because GC needs the log in order to properly deallocate all allocations // made by this txn when they become obsolete. - auto cleanup = make_scope_guard([&]() { - s_txn_id = c_invalid_gaia_txn_id; - }); + auto cleanup = make_scope_guard([&]() { s_txn_id = c_invalid_gaia_txn_id; }); FlatBufferBuilder builder; build_server_reply(builder, event, old_state, new_state, s_txn_id); @@ -485,12 +483,8 @@ void server_t::handle_request_stream( // The client socket should unconditionally be closed on exit because it's // duplicated when passed to the client and we no longer need it on the // server. - auto client_socket_cleanup = make_scope_guard([&]() { - close_fd(client_socket); - }); - auto server_socket_cleanup = make_scope_guard([&]() { - close_fd(server_socket); - }); + auto client_socket_cleanup = make_scope_guard([&]() { close_fd(client_socket); }); + auto server_socket_cleanup = make_scope_guard([&]() { close_fd(server_socket); }); auto request = static_cast(event_data); @@ -931,7 +925,10 @@ void server_t::init_listening_socket(const std::string& socket_name) if (errno == EADDRINUSE) { cerr << "ERROR: bind() failed! - " << (::strerror(errno)) << endl; - cerr << "The Gaia Database Server cannot start because another instance is already running. Please stop any instances of the server that are running." << endl; + cerr << "The " << c_db_server_name + << " cannot start because another instance is already running.\n" + "Please stop any running instance of the server." + << endl; exit(1); } @@ -1046,9 +1043,7 @@ void server_t::client_dispatch_handler(const std::string& socket_name) // so no new sessions can be established while we wait for all session // threads to exit (we assume they received the same server shutdown // notification that we did). - auto listener_cleanup = make_scope_guard([&]() { - close_fd(s_listening_socket); - }); + auto listener_cleanup = make_scope_guard([&]() { close_fd(s_listening_socket); }); // Set up the epoll loop. int epoll_fd = ::epoll_create1(0); @@ -2409,9 +2404,7 @@ void server_t::txn_rollback() // We need to unconditionally close the log fd because we're not registering // it in a txn metadata entry, so it won't be closed by GC. - auto cleanup_log_fd = make_scope_guard([&]() { - close_fd(log_fd); - }); + auto cleanup_log_fd = make_scope_guard([&]() { close_fd(log_fd); }); // Free any deallocated objects (don't bother for read-only txns). if (!is_log_empty) @@ -2604,7 +2597,3 @@ void server_t::run(server_config_t server_conf) } } } - -void server_t::handle_common_errors() -{ -} From d0dffa015917a427c70ce0dd17eb1bd1465a89ca Mon Sep 17 00:00:00 2001 From: Simone Rondelli Date: Fri, 27 Aug 2021 16:10:11 -0400 Subject: [PATCH 3/5] Revert formatting --- production/db/core/src/db_server.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/production/db/core/src/db_server.cpp b/production/db/core/src/db_server.cpp index cd15ed7af5b5..63dcbbb23c38 100644 --- a/production/db/core/src/db_server.cpp +++ b/production/db/core/src/db_server.cpp @@ -373,7 +373,9 @@ void server_t::handle_decide_txn( // returned, but we don't close the log fd (even for an abort decision), // because GC needs the log in order to properly deallocate all allocations // made by this txn when they become obsolete. - auto cleanup = make_scope_guard([&]() { s_txn_id = c_invalid_gaia_txn_id; }); + auto cleanup = make_scope_guard([&]() { + s_txn_id = c_invalid_gaia_txn_id; + }); FlatBufferBuilder builder; build_server_reply(builder, event, old_state, new_state, s_txn_id); @@ -483,8 +485,12 @@ void server_t::handle_request_stream( // The client socket should unconditionally be closed on exit because it's // duplicated when passed to the client and we no longer need it on the // server. - auto client_socket_cleanup = make_scope_guard([&]() { close_fd(client_socket); }); - auto server_socket_cleanup = make_scope_guard([&]() { close_fd(server_socket); }); + auto client_socket_cleanup = make_scope_guard([&]() { + close_fd(client_socket); + }); + auto server_socket_cleanup = make_scope_guard([&]() { + close_fd(server_socket); + }); auto request = static_cast(event_data); @@ -1043,7 +1049,9 @@ void server_t::client_dispatch_handler(const std::string& socket_name) // so no new sessions can be established while we wait for all session // threads to exit (we assume they received the same server shutdown // notification that we did). - auto listener_cleanup = make_scope_guard([&]() { close_fd(s_listening_socket); }); + auto listener_cleanup = make_scope_guard([&]() { + close_fd(s_listening_socket); + }); // Set up the epoll loop. int epoll_fd = ::epoll_create1(0); @@ -2404,7 +2412,9 @@ void server_t::txn_rollback() // We need to unconditionally close the log fd because we're not registering // it in a txn metadata entry, so it won't be closed by GC. - auto cleanup_log_fd = make_scope_guard([&]() { close_fd(log_fd); }); + auto cleanup_log_fd = make_scope_guard([&]() { + close_fd(log_fd); + }); // Free any deallocated objects (don't bother for read-only txns). if (!is_log_empty) From 081c5fcb76749cf1cd2a8bdb768b4ac34ea5c673 Mon Sep 17 00:00:00 2001 From: Simone Rondelli Date: Fri, 27 Aug 2021 16:19:36 -0400 Subject: [PATCH 4/5] Imporve messages --- production/db/core/src/db_server_exec.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/production/db/core/src/db_server_exec.cpp b/production/db/core/src/db_server_exec.cpp index 263b17b8ce2b..dad4f11e0f8a 100644 --- a/production/db/core/src/db_server_exec.cpp +++ b/production/db/core/src/db_server_exec.cpp @@ -376,7 +376,5 @@ int main(int argc, char* argv[]) { auto server_conf = process_command_line(argc, argv); - std::cerr << c_db_server_name << " started!" << std::endl; - gaia::db::server_t::run(server_conf); } From c7c03c1370c9f8634afe8c1f63bc31496facdc2d Mon Sep 17 00:00:00 2001 From: Simone Rondelli Date: Fri, 27 Aug 2021 19:47:12 -0400 Subject: [PATCH 5/5] Address PR feedback --- production/db/core/src/db_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/production/db/core/src/db_server.cpp b/production/db/core/src/db_server.cpp index 63dcbbb23c38..36fd3eb4a128 100644 --- a/production/db/core/src/db_server.cpp +++ b/production/db/core/src/db_server.cpp @@ -933,7 +933,7 @@ void server_t::init_listening_socket(const std::string& socket_name) cerr << "ERROR: bind() failed! - " << (::strerror(errno)) << endl; cerr << "The " << c_db_server_name << " cannot start because another instance is already running.\n" - "Please stop any running instance of the server." + "Stop any instances of the server and try again." << endl; exit(1); }