From ee9e7c7787d8caa7b3f8b4d1f55f1142d9036c50 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 25 May 2012 14:16:56 +0200 Subject: [PATCH] issue #94: removed unfriendly log message --- SimpleHttpClient/SimpleHttpClient.cpp | 13 ++++++--- SimpleHttpClient/SimpleHttpClient.h | 4 ++- V8Client/V8ClientConnection.cpp | 5 ++-- V8Client/V8ClientConnection.h | 3 +- V8Client/arangoimp.cpp | 7 +++-- V8Client/arangosh.cpp | 40 +++++++++++++++++++++------ 6 files changed, 53 insertions(+), 19 deletions(-) diff --git a/SimpleHttpClient/SimpleHttpClient.cpp b/SimpleHttpClient/SimpleHttpClient.cpp index 5198df95a3..04225e5fa1 100644 --- a/SimpleHttpClient/SimpleHttpClient.cpp +++ b/SimpleHttpClient/SimpleHttpClient.cpp @@ -58,12 +58,14 @@ namespace triagens { int port, double requestTimeout, double connectTimeout, - size_t connectRetries) : + size_t connectRetries, + bool warn = true) : _hostname(hostname), _port(port), _requestTimeout(requestTimeout), _connectTimeout(connectTimeout), _connectRetries(connectRetries), + _warn(warn), _writeBuffer(TRI_UNKNOWN_MEM_ZONE), _readBuffer(TRI_UNKNOWN_MEM_ZONE) { @@ -129,7 +131,9 @@ namespace triagens { } if (isWorking() && _errorMessage=="" ) { - LOGGER_ERROR << "Request timeout reached."; + if (_warn) { + LOGGER_WARNING << "Request timeout reached."; + } _errorMessage = "Request timeout reached."; } @@ -153,14 +157,15 @@ namespace triagens { _numConnectRetries++; } else { - LOGGER_ERROR << "Could not connect to '" << _hostname << ":" << _port << "'! Connection is dead"; + if (_warn) { + LOGGER_WARNING << "Could not connect to '" << _hostname << ":" << _port << "'! Connection is dead"; + } _state = DEAD; return; } if (_hostname == "" || _port == 0) { _errorMessage = "Could not connect to '" + _hostname + ":" + StringUtils::itoa(_port) + "'"; - LOGGER_ERROR << "Could not connect to '" << _hostname << ":" << _port << "'! Connection is dead"; _state = DEAD; return; } diff --git a/SimpleHttpClient/SimpleHttpClient.h b/SimpleHttpClient/SimpleHttpClient.h index a9b3d5ac5b..5b1cc30f94 100644 --- a/SimpleHttpClient/SimpleHttpClient.h +++ b/SimpleHttpClient/SimpleHttpClient.h @@ -90,7 +90,8 @@ namespace triagens { int port, double requestTimeout, double connectTimeout, - size_t connectRetries); + size_t connectRetries, + bool warn); //////////////////////////////////////////////////////////////////////////////// /// @brief destructs a http client @@ -302,6 +303,7 @@ namespace triagens { double _requestTimeout; double _connectTimeout; size_t _connectRetries; + bool _warn; socket_t _socket; diff --git a/V8Client/V8ClientConnection.cpp b/V8Client/V8ClientConnection.cpp index e2218786a8..3a941914da 100644 --- a/V8Client/V8ClientConnection.cpp +++ b/V8Client/V8ClientConnection.cpp @@ -66,12 +66,13 @@ namespace triagens { int port, double requestTimeout, size_t retries, - double connectionTimeout) : _client(0), _httpResult(0) { + double connectionTimeout, + bool warn) : _client(0), _httpResult(0) { _connected = false; _lastHttpReturnCode = 0; _lastErrorMessage = ""; - _client = new SimpleHttpClient(hostname, port, requestTimeout, retries, connectionTimeout); + _client = new SimpleHttpClient(hostname, port, requestTimeout, retries, connectionTimeout, warn); // connect to server and get version number map headerFields; diff --git a/V8Client/V8ClientConnection.h b/V8Client/V8ClientConnection.h index 762b61fcb5..31e54bcaef 100644 --- a/V8Client/V8ClientConnection.h +++ b/V8Client/V8ClientConnection.h @@ -81,7 +81,8 @@ namespace triagens { int port, double requestTimeout, size_t retries, - double connectionTimeout); + double connectionTimeout, + bool warn); //////////////////////////////////////////////////////////////////////////////// /// @brief destructor diff --git a/V8Client/arangoimp.cpp b/V8Client/arangoimp.cpp index ff613a952c..d5fe960b47 100644 --- a/V8Client/arangoimp.cpp +++ b/V8Client/arangoimp.cpp @@ -64,9 +64,9 @@ using namespace triagens::v8client; static string DEFAULT_SERVER_NAME = "localhost"; static int DEFAULT_SERVER_PORT = 8529; -static double DEFAULT_REQUEST_TIMEOUT = 300; +static int64_t DEFAULT_REQUEST_TIMEOUT = 300; static size_t DEFAULT_RETRIES = 5; -static double DEFAULT_CONNECTION_TIMEOUT = 5; +static int64_t DEFAULT_CONNECTION_TIMEOUT = 5; //////////////////////////////////////////////////////////////////////////////// /// @brief server address @@ -255,7 +255,8 @@ int main (int argc, char* argv[]) { DEFAULT_SERVER_PORT, (double) requestTimeout, DEFAULT_RETRIES, - (double) connectTimeout); + (double) connectTimeout, + true); if (clientConnection->isConnected()) { printf("Connected to Arango DB %s:%d Version %s\n", diff --git a/V8Client/arangosh.cpp b/V8Client/arangosh.cpp index 4f6c893f87..813608bfcc 100644 --- a/V8Client/arangosh.cpp +++ b/V8Client/arangosh.cpp @@ -83,9 +83,9 @@ using namespace triagens::arango; static string DEFAULT_SERVER_NAME = "localhost"; static int DEFAULT_SERVER_PORT = 8529; -static double DEFAULT_REQUEST_TIMEOUT = 10.0; +static int64_t DEFAULT_REQUEST_TIMEOUT = 300; static size_t DEFAULT_RETRIES = 5; -static double DEFAULT_CONNECTION_TIMEOUT = 1.0; +static int64_t DEFAULT_CONNECTION_TIMEOUT = 5; //////////////////////////////////////////////////////////////////////////////// /// @brief quite start @@ -189,6 +189,18 @@ regex_t intRegex; static uint64_t maxUploadSize = 500000; +//////////////////////////////////////////////////////////////////////////////// +/// @brief connect timeout (in s) +//////////////////////////////////////////////////////////////////////////////// + +static int64_t connectTimeout = DEFAULT_CONNECTION_TIMEOUT; + +//////////////////////////////////////////////////////////////////////////////// +/// @brief request timeout (in s) +//////////////////////////////////////////////////////////////////////////////// + +static int64_t requestTimeout = DEFAULT_REQUEST_TIMEOUT; + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// @@ -534,6 +546,8 @@ static void ParseProgramOptions (int argc, char* argv[]) { ("pretty-print", "pretty print values") ("no-colors", "deactivate color support") ("no-auto-complete", "disable auto completion") + ("connect-timeout", &connectTimeout, "connect timeout in seconds") + ("request-timeout", &requestTimeout, "request timeout in seconds") ("unit-tests", &UnitTests, "do not start as shell, run unit tests instead") ("max-upload-size", &maxUploadSize, "maximum size of import chunks") (hidden, true) @@ -649,10 +663,8 @@ static v8::Handle ClientConnection_ConstructorCallback (v8::Arguments string server = DEFAULT_SERVER_NAME; int port = DEFAULT_SERVER_PORT; - double requestTimeout = DEFAULT_REQUEST_TIMEOUT; size_t retries = DEFAULT_RETRIES; - double connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; - + if (argv.Length() > 0 && argv[0]->IsString()) { string definition = TRI_ObjectToString(argv[0]); @@ -663,7 +675,7 @@ static v8::Handle ClientConnection_ConstructorCallback (v8::Arguments } - V8ClientConnection* connection = new V8ClientConnection(server, port, requestTimeout, retries, connectionTimeout); + V8ClientConnection* connection = new V8ClientConnection(server, port, (double) requestTimeout, retries, (double) connectTimeout, false); if (connection->isConnected()) { printf("Connected to Arango DB %s:%d Version %s\n", @@ -1153,6 +1165,17 @@ int main (int argc, char* argv[]) { // parse the program options ParseProgramOptions(argc, argv); + + // check connection args + if (connectTimeout <= 0) { + cout << "invalid value for connect-timeout." << endl; + return EXIT_FAILURE; + } + + if (requestTimeout <= 0) { + cout << "invalid value for request-timeout." << endl; + return EXIT_FAILURE; + } v8::HandleScope handle_scope; @@ -1193,9 +1216,10 @@ int main (int argc, char* argv[]) { clientConnection = new V8ClientConnection( DEFAULT_SERVER_NAME, DEFAULT_SERVER_PORT, - DEFAULT_REQUEST_TIMEOUT, + (double) requestTimeout, DEFAULT_RETRIES, - DEFAULT_CONNECTION_TIMEOUT); + (double) connectTimeout, + false); } // .............................................................................