From 0a0076090727613017ae57bd48208d1836c54c83 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 14 Feb 2013 17:18:28 +0100 Subject: [PATCH 01/11] performance patch, improving parallelity for concurrent document creation --- arangod/Utils/Transaction.h | 28 +++++++++++++++- arangod/VocBase/document-collection.c | 47 --------------------------- arangod/VocBase/primary-collection.h | 14 +------- 3 files changed, 28 insertions(+), 61 deletions(-) diff --git a/arangod/Utils/Transaction.h b/arangod/Utils/Transaction.h index 11631efc5d..73bb46d67b 100644 --- a/arangod/Utils/Transaction.h +++ b/arangod/Utils/Transaction.h @@ -608,20 +608,46 @@ namespace triagens { void const* data, const bool forceSync, const bool lock) { + TRI_voc_key_t key = 0; + + // check if _key is present + if (json != NULL && json->_type == TRI_JSON_ARRAY) { + // _key is there + TRI_json_t* k = TRI_LookupArrayJson((TRI_json_t*) json, "_key"); + if (k != NULL) { + if (k->_type == TRI_JSON_STRING) { + // _key is there and a string + key = k->_value._string.data; + } + else { + // _key is there but not a string + return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD; + } + } + } + + TRI_shaped_json_t* shaped = TRI_ShapedJsonJson(primary->_shaper, json); + if (shaped == 0) { + return TRI_ERROR_ARANGO_SHAPER_FAILED; + } + TRI_doc_operation_context_t context; TRI_InitContextPrimaryCollection(&context, primary, TRI_DOC_UPDATE_ERROR, forceSync); + if (lock) { // WRITE-LOCK START this->lockExplicit(primary, TRI_TRANSACTION_WRITE); } - int res = primary->createJson(&context, markerType, mptr, json, data); + int res = primary->create(&context, markerType, mptr, shaped, data, key); if (lock) { this->unlockExplicit(primary, TRI_TRANSACTION_WRITE); // WRITE-LOCK END } + + TRI_FreeShapedJson(primary->_shaper, shaped); return res; } diff --git a/arangod/VocBase/document-collection.c b/arangod/VocBase/document-collection.c index 07d3700c26..1d8c1aaa82 100644 --- a/arangod/VocBase/document-collection.c +++ b/arangod/VocBase/document-collection.c @@ -846,52 +846,6 @@ static int DeleteDocument (TRI_doc_operation_context_t* context, return TRI_ERROR_NO_ERROR; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a new document in the collection from json -//////////////////////////////////////////////////////////////////////////////// - -static int CreateJson (TRI_doc_operation_context_t* context, - TRI_df_marker_type_e type, - TRI_doc_mptr_t** mptr, - TRI_json_t const* json, - void const* data) { - TRI_shaped_json_t* shaped; - TRI_primary_collection_t* primary; - TRI_voc_key_t key; - int res; - - key = 0; - primary = context->_collection; - - shaped = TRI_ShapedJsonJson(primary->_shaper, json); - - if (shaped == 0) { - return TRI_ERROR_ARANGO_SHAPER_FAILED; - } - - if (json != NULL && json->_type == TRI_JSON_ARRAY) { - // _key is there - TRI_json_t* k = TRI_LookupArrayJson((TRI_json_t*) json, "_key"); - if (k != NULL) { - if (k->_type == TRI_JSON_STRING) { - // _key is there and a string - key = k->_value._string.data; - } - else { - // _key is there but not a string - TRI_FreeShapedJson(primary->_shaper, shaped); - return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD; - } - } - } - - res = primary->create(context, type, mptr, shaped, data, key); - - TRI_FreeShapedJson(primary->_shaper, shaped); - - return res; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief updates a document in the collection from json //////////////////////////////////////////////////////////////////////////////// @@ -1892,7 +1846,6 @@ static bool InitDocumentCollection (TRI_document_collection_t* collection, collection->base.update = UpdateShapedJson; collection->base.destroy = DeleteShapedJson; - collection->base.createJson = CreateJson; collection->base.updateJson = UpdateJson; collection->cleanupIndexes = CleanupIndexes; diff --git a/arangod/VocBase/primary-collection.h b/arangod/VocBase/primary-collection.h index 6bb879ffe5..cf062e1bd3 100644 --- a/arangod/VocBase/primary-collection.h +++ b/arangod/VocBase/primary-collection.h @@ -189,7 +189,7 @@ TRI_doc_collection_info_t; /// as the object is not deleted. /// /// It is important to use locks for create, read, update, and delete. The -/// functions @FN{create}, @FN{createJson}, @FN{update}, @FN{updateJson}, and +/// functions @FN{create}, @FN{update}, @FN{updateJson}, and /// @FN{destroy} are only allowed within a @FN{beginWrite} and /// @FN{endWrite}. The function @FN{read} is only allowed within a /// @FN{beginRead} and @FN{endRead}. Note that @FN{read} returns a copy of the @@ -230,7 +230,6 @@ TRI_doc_collection_info_t; /// @LIT{beginWrite}. /// /// @FUN{TRI_doc_mptr_t const create (TRI_primary_collection_t*, TRI_df_marker_type_e, TRI_shaped_json_t const*, bool @FA{release})} -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// /// Adds a new document to the collection and returns the master pointer of the /// newly created entry. In case of an error, the attribute @LIT{_did} of the @@ -238,16 +237,6 @@ TRI_doc_collection_info_t; /// NOT acquire a write lock. This must be done by the caller. If @FA{release} /// is true, it will release the write lock as soon as possible. /// -/// @FUN{TRI_doc_mptr_t const createJson (TRI_primary_collection_t*, TRI_df_marker_type_e, TRI_json_t const*, bool @FA{release})} -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/// -/// As before, but instead of a shaped json a json object must be given. -/// -/// @FUN{TRI_voc_key_t createLock (TRI_primary_collection_t*, TRI_df_marker_type_e, TRI_shaped_json_t const*)} -////////////////////////////////////////////////////////////////////////////////////////////////////////// -/// -/// As before, but the function will acquire and release the write lock. -/// /// @FUN{TRI_doc_mptr_t const read (TRI_primary_collection_t*, TRI_voc_key_t)} ////////////////////////////////////////////////////////////////////////// /// @@ -338,7 +327,6 @@ typedef struct TRI_primary_collection_s { void (*updateHeader) (struct TRI_primary_collection_s*, TRI_datafile_t*, TRI_df_marker_t const*, size_t, TRI_doc_mptr_t const*, TRI_doc_mptr_t*); int (*create) (struct TRI_doc_operation_context_s*, TRI_df_marker_type_e, TRI_doc_mptr_t**, TRI_shaped_json_t const*, void const*, TRI_voc_key_t key); - int (*createJson) (struct TRI_doc_operation_context_s*, TRI_df_marker_type_e, TRI_doc_mptr_t**, TRI_json_t const*, void const*); int (*read) (struct TRI_doc_operation_context_s*, TRI_doc_mptr_t**, TRI_voc_key_t); int (*update) (struct TRI_doc_operation_context_s*, TRI_doc_mptr_t**, TRI_shaped_json_t const*, TRI_voc_key_t); From d1f40bc8cfddf2837167219d4136130c9f06a393 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 14 Feb 2013 22:24:52 +0100 Subject: [PATCH 02/11] fixed memory zone mismatch in arangosh --- arangosh/V8Client/arangosh.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arangosh/V8Client/arangosh.cpp b/arangosh/V8Client/arangosh.cpp index 878822374e..c3421dfea8 100755 --- a/arangosh/V8Client/arangosh.cpp +++ b/arangosh/V8Client/arangosh.cpp @@ -954,13 +954,16 @@ static void RunShell (v8::Handle context, bool promptError) { string i = triagens::basics::StringUtils::trim(input); if (i == "exit" || i == "quit" || i == "exit;" || i == "quit;") { - TRI_FreeString(TRI_CORE_MEM_ZONE, input); + TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, input); break; } if (i == "help" || i == "help;") { - TRI_FreeString(TRI_CORE_MEM_ZONE, input); - input = TRI_DuplicateString("help()"); + TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, input); + input = TRI_DuplicateStringZ(TRI_UNKNOWN_MEM_ZONE, "help()"); + if (input == 0) { + LOGGER_FATAL_AND_EXIT("out of memory"); + } } console.addHistory(input); From 637ed65e09449b0d6d905172062e0d7480e7d12a Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 15 Feb 2013 10:22:31 +0100 Subject: [PATCH 03/11] expose reserve function --- lib/Basics/StringBuffer.h | 8 ++++++++ lib/BasicsC/string-buffer.c | 10 +++++++++- lib/BasicsC/string-buffer.h | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Basics/StringBuffer.h b/lib/Basics/StringBuffer.h index 2763175656..cfc7dcbfe8 100644 --- a/lib/Basics/StringBuffer.h +++ b/lib/Basics/StringBuffer.h @@ -120,6 +120,14 @@ namespace triagens { TRI_AnnihilateStringBuffer(&_buffer); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief frees the string buffer and cleans the buffer +//////////////////////////////////////////////////////////////////////////////// + + int reserve (const size_t length) { + return TRI_ReserveStringBuffer(&_buffer, length); + } + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/string-buffer.c b/lib/BasicsC/string-buffer.c index d2d9b7989d..0a445e11b1 100644 --- a/lib/BasicsC/string-buffer.c +++ b/lib/BasicsC/string-buffer.c @@ -58,7 +58,7 @@ static size_t Remaining (TRI_string_buffer_t * self) { /// @brief reserve space //////////////////////////////////////////////////////////////////////////////// -static int Reserve (TRI_string_buffer_t * self, size_t size) { +static int Reserve (TRI_string_buffer_t * self, const size_t size) { char* ptr; if (size < 1) { @@ -214,6 +214,14 @@ void TRI_FreeStringBuffer (TRI_memory_zone_t* zone, TRI_string_buffer_t * self) /// @{ //////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +/// @brief ensure the string buffer has a specific capacity +//////////////////////////////////////////////////////////////////////////////// + +int TRI_ReserveStringBuffer (TRI_string_buffer_t* self, const size_t length) { + return Reserve(self, length); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief swaps content with another string buffer //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/string-buffer.h b/lib/BasicsC/string-buffer.h index 8871aa9865..5cf8cea4c4 100644 --- a/lib/BasicsC/string-buffer.h +++ b/lib/BasicsC/string-buffer.h @@ -134,6 +134,12 @@ void TRI_FreeStringBuffer (TRI_memory_zone_t*, TRI_string_buffer_t *); /// @{ //////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +/// @brief ensure the string buffer has a specific capacity +//////////////////////////////////////////////////////////////////////////////// + +int TRI_ReserveStringBuffer (TRI_string_buffer_t* self, const size_t length); + //////////////////////////////////////////////////////////////////////////////// /// @brief swaps content with another string buffer //////////////////////////////////////////////////////////////////////////////// From 8b7a5d264960b1635b9b6298ea725b0bd183b16b Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 15 Feb 2013 10:22:47 +0100 Subject: [PATCH 04/11] slighty optimise duplicates check --- lib/BasicsC/json-utilities.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/BasicsC/json-utilities.c b/lib/BasicsC/json-utilities.c index a61a4350d3..6ef50beaf6 100644 --- a/lib/BasicsC/json-utilities.c +++ b/lib/BasicsC/json-utilities.c @@ -666,14 +666,13 @@ TRI_json_t* TRI_SortListJson (TRI_json_t* const list) { bool TRI_HasDuplicateKeyJson (const TRI_json_t* const object) { if (object && object->_type == TRI_JSON_ARRAY) { - size_t n; + const size_t n = object->_value._objects._length; // if we don't have attributes, we do not need to check for duplicates // if we only have one attribute, we don't need to check for duplicates in // the array, but we need to recursively validate the array values (if // array value itself is an array) - n = object->_value._objects._length; - if (n > 0) { + if (n > 2) { TRI_associative_pointer_t hash; size_t i; From 2543eeca2ddd55b0f213320cf336ea04feb02e63 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 15 Feb 2013 10:26:02 +0100 Subject: [PATCH 05/11] moved containsMore member --- arangod/RestHandler/RestBatchHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arangod/RestHandler/RestBatchHandler.h b/arangod/RestHandler/RestBatchHandler.h index a80e3a51f8..7887017397 100644 --- a/arangod/RestHandler/RestBatchHandler.h +++ b/arangod/RestHandler/RestBatchHandler.h @@ -77,9 +77,9 @@ namespace triagens { char* searchStart; char* foundStart; size_t foundLength; - bool containsMore; char* contentId; size_t contentIdLength; + bool containsMore; }; //////////////////////////////////////////////////////////////////////////////// From d321f3252346a8808172a3da0e679e394653e5f5 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 15 Feb 2013 11:35:48 +0100 Subject: [PATCH 06/11] moved some const value out of loop --- arangod/RestHandler/RestDocumentHandler.cpp | 14 ++-- .../RestHandler/RestVocbaseBaseHandler.cpp | 70 ++++--------------- arangod/RestHandler/RestVocbaseBaseHandler.h | 42 ++++++----- arangod/Utils/DocumentHelper.h | 6 +- arangod/Utils/Transaction.h | 10 ++- arangod/VocBase/document-collection.c | 29 -------- arangod/VocBase/primary-collection.h | 12 +--- lib/BasicsC/json-utilities.c | 28 +++++--- lib/Rest/HttpRequest.cpp | 5 +- 9 files changed, 80 insertions(+), 136 deletions(-) diff --git a/arangod/RestHandler/RestDocumentHandler.cpp b/arangod/RestHandler/RestDocumentHandler.cpp index 4ed7676bfc..b2017d2f7b 100644 --- a/arangod/RestHandler/RestDocumentHandler.cpp +++ b/arangod/RestHandler/RestDocumentHandler.cpp @@ -408,8 +408,8 @@ bool RestDocumentHandler::readSingleDocument (bool generateBody) { TRI_voc_rid_t ifRid = extractRevision("if-match", "rev"); // split the document reference - string collection = suffix[0]; - string key = suffix[1]; + const string& collection = suffix[0]; + const string& key = suffix[1]; // find and load collection given by name or identifier SingleCollectionReadOnlyTransaction > trx(_vocbase, _resolver, collection); @@ -463,7 +463,7 @@ bool RestDocumentHandler::readSingleDocument (bool generateBody) { } else if (ifNoneRid == rid) { if (ifRid == 0 || ifRid == rid) { - generateNotModified(StringUtils::itoa(rid)); + generateNotModified(rid); } else { generatePreconditionFailed(cid, document->_key, rid); @@ -760,8 +760,8 @@ bool RestDocumentHandler::modifyDocument (bool isPatch) { } // split the document reference - string collection = suffix[0]; - string key = suffix[1]; + const string& collection = suffix[0]; + const string& key = suffix[1]; // auto-ptr that will free JSON data when scope is left ResourceHolder holder; @@ -930,8 +930,8 @@ bool RestDocumentHandler::deleteDocument () { } // split the document reference - string collection = suffix[0]; - string key = suffix[1]; + const string& collection = suffix[0]; + const string& key = suffix[1]; // extract the revision TRI_voc_rid_t revision = extractRevision("if-match", "rev"); diff --git a/arangod/RestHandler/RestVocbaseBaseHandler.cpp b/arangod/RestHandler/RestVocbaseBaseHandler.cpp index 37917f8788..8752ebec66 100644 --- a/arangod/RestHandler/RestVocbaseBaseHandler.cpp +++ b/arangod/RestHandler/RestVocbaseBaseHandler.cpp @@ -170,9 +170,14 @@ bool RestVocbaseBaseHandler::checkCreateCollection (const string& name, const TRI_col_type_e type) { bool found; char const* valueStr = _request->value("createCollection", found); - bool create = found ? StringUtils::boolean(valueStr) : false; - if (! create) { + if (! found) { + // "createCollection" parameter not specified + return true; + } + + if (! StringUtils::boolean(valueStr)) { + // "createCollection" parameter specified, but with non-true value return true; } @@ -191,8 +196,8 @@ bool RestVocbaseBaseHandler::checkCreateCollection (const string& name, void RestVocbaseBaseHandler::generate20x (const HttpResponse::HttpResponseCode responseCode, const string& collectionName, - TRI_voc_key_t key, - TRI_voc_rid_t rid) { + const TRI_voc_key_t key, + const TRI_voc_rid_t rid) { const string handle = DocumentHelper::assembleDocumentId(collectionName, key); const string rev = StringUtils::itoa(rid); @@ -206,7 +211,7 @@ void RestVocbaseBaseHandler::generate20x (const HttpResponse::HttpResponseCode r // handle does not need to be RFC 2047-encoded _response->setHeader("location", DOCUMENT_PATH + "/" + handle); } - + // _id and _key are safe and do not need to be JSON-encoded _response->body() .appendText("{\"error\":false,\"_id\":\"") @@ -218,55 +223,6 @@ void RestVocbaseBaseHandler::generate20x (const HttpResponse::HttpResponseCode r .appendText("\"}"); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief generates ok message without content -//////////////////////////////////////////////////////////////////////////////// - -void RestVocbaseBaseHandler::generateOk () { - _response = createResponse(HttpResponse::NO_CONTENT); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief generates created message -//////////////////////////////////////////////////////////////////////////////// - -void RestVocbaseBaseHandler::generateCreated (const TRI_voc_cid_t cid, - TRI_voc_key_t key, - TRI_voc_rid_t rid) { - - generate20x(HttpResponse::CREATED, _resolver.getCollectionName(cid), key, rid); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief generates accepted message -//////////////////////////////////////////////////////////////////////////////// - -void RestVocbaseBaseHandler::generateAccepted (const TRI_voc_cid_t cid, - TRI_voc_key_t key, - TRI_voc_rid_t rid) { - generate20x(HttpResponse::ACCEPTED, _resolver.getCollectionName(cid), key, rid); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief generates deleted message -//////////////////////////////////////////////////////////////////////////////// - -void RestVocbaseBaseHandler::generateDeleted (const TRI_voc_cid_t cid, - TRI_voc_key_t key, - TRI_voc_rid_t rid) { - generate20x(HttpResponse::OK, _resolver.getCollectionName(cid), key, rid); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief generates updated message -//////////////////////////////////////////////////////////////////////////////// - -void RestVocbaseBaseHandler::generateUpdated (const TRI_voc_cid_t cid, - TRI_voc_key_t key, - TRI_voc_rid_t rid) { - generate20x(HttpResponse::OK, _resolver.getCollectionName(cid), key, rid); -} - //////////////////////////////////////////////////////////////////////////////// /// @brief generates document not found error message //////////////////////////////////////////////////////////////////////////////// @@ -337,9 +293,11 @@ void RestVocbaseBaseHandler::generatePreconditionFailed (const TRI_voc_cid_t cid /// @brief generates not modified //////////////////////////////////////////////////////////////////////////////// -void RestVocbaseBaseHandler::generateNotModified (const string& etag) { +void RestVocbaseBaseHandler::generateNotModified (const TRI_voc_rid_t rid) { + const string rev = StringUtils::itoa(rid); + _response = createResponse(HttpResponse::NOT_MODIFIED); - _response->setHeader("ETag", "\"" + etag + "\""); + _response->setHeader("ETag", "\"" + rev + "\""); } //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/RestHandler/RestVocbaseBaseHandler.h b/arangod/RestHandler/RestVocbaseBaseHandler.h index a2b0e747fe..d412c832b0 100644 --- a/arangod/RestHandler/RestVocbaseBaseHandler.h +++ b/arangod/RestHandler/RestVocbaseBaseHandler.h @@ -183,46 +183,56 @@ namespace triagens { void generate20x (const rest::HttpResponse::HttpResponseCode, const string&, - TRI_voc_key_t, - TRI_voc_rid_t); + const TRI_voc_key_t, + const TRI_voc_rid_t); //////////////////////////////////////////////////////////////////////////////// /// @brief generates ok message without content //////////////////////////////////////////////////////////////////////////////// - void generateOk (); + void generateOk () { + _response = createResponse(rest::HttpResponse::NO_CONTENT); + } //////////////////////////////////////////////////////////////////////////////// /// @brief generates created message //////////////////////////////////////////////////////////////////////////////// - void generateCreated (const TRI_voc_cid_t, - TRI_voc_key_t, - TRI_voc_rid_t); + void generateCreated (const TRI_voc_cid_t cid, + TRI_voc_key_t key, + TRI_voc_rid_t rid) { + generate20x(rest::HttpResponse::CREATED, _resolver.getCollectionName(cid), key, rid); + } //////////////////////////////////////////////////////////////////////////////// /// @brief generates accepted message //////////////////////////////////////////////////////////////////////////////// - void generateAccepted (const TRI_voc_cid_t, - TRI_voc_key_t, - TRI_voc_rid_t); + void generateAccepted (const TRI_voc_cid_t cid, + const TRI_voc_key_t key, + const TRI_voc_rid_t rid) { + generate20x(rest::HttpResponse::ACCEPTED, _resolver.getCollectionName(cid), key, rid); + } //////////////////////////////////////////////////////////////////////////////// /// @brief generates deleted message //////////////////////////////////////////////////////////////////////////////// - void generateDeleted (const TRI_voc_cid_t, - TRI_voc_key_t, - TRI_voc_rid_t); + void generateDeleted (const TRI_voc_cid_t cid, + const TRI_voc_key_t key, + const TRI_voc_rid_t rid) { + generate20x(rest::HttpResponse::OK, _resolver.getCollectionName(cid), key, rid); + } //////////////////////////////////////////////////////////////////////////////// /// @brief generates updated message //////////////////////////////////////////////////////////////////////////////// - void generateUpdated (const TRI_voc_cid_t, - TRI_voc_key_t, - TRI_voc_rid_t); + void generateUpdated (const TRI_voc_cid_t cid, + const TRI_voc_key_t key, + const TRI_voc_rid_t rid) { + generate20x(rest::HttpResponse::OK, _resolver.getCollectionName(cid), key, rid); + } //////////////////////////////////////////////////////////////////////////////// /// @brief generates document not found error message @@ -255,7 +265,7 @@ namespace triagens { /// @brief generates not modified //////////////////////////////////////////////////////////////////////////////// - void generateNotModified (const string&); + void generateNotModified (const TRI_voc_rid_t); //////////////////////////////////////////////////////////////////////////////// /// @brief generates first entry from a result set diff --git a/arangod/Utils/DocumentHelper.h b/arangod/Utils/DocumentHelper.h index 99e15ecc13..468039b841 100644 --- a/arangod/Utils/DocumentHelper.h +++ b/arangod/Utils/DocumentHelper.h @@ -82,13 +82,11 @@ namespace triagens { static inline string assembleDocumentId (const string& collectionName, const TRI_voc_key_t key) { - static const string UnknownKey = "_deleted"; - if (key == 0) { - return assembleDocumentId(collectionName, UnknownKey); + return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + "_deleted"; } - return assembleDocumentId(collectionName, string(key)); + return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + key; } //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/Utils/Transaction.h b/arangod/Utils/Transaction.h index 73bb46d67b..eb7993e9b8 100644 --- a/arangod/Utils/Transaction.h +++ b/arangod/Utils/Transaction.h @@ -695,6 +695,12 @@ namespace triagens { TRI_voc_rid_t* actualRevision, const bool forceSync, const bool lock) { + + TRI_shaped_json_t* shaped = TRI_ShapedJsonJson(primary->_shaper, json); + if (shaped == 0) { + return TRI_ERROR_ARANGO_SHAPER_FAILED; + } + TRI_doc_operation_context_t context; TRI_InitContextPrimaryCollection(&context, primary, policy, forceSync); context._expectedRid = expectedRevision; @@ -705,12 +711,14 @@ namespace triagens { this->lockExplicit(primary, TRI_TRANSACTION_WRITE); } - int res = primary->updateJson(&context, mptr, json, (TRI_voc_key_t) key.c_str()); + int res = primary->update(&context, mptr, shaped, (TRI_voc_key_t) key.c_str()); if (lock) { this->unlockExplicit(primary, TRI_TRANSACTION_WRITE); // WRITE-LOCK END } + + TRI_FreeShapedJson(primary->_shaper, shaped); return res; } diff --git a/arangod/VocBase/document-collection.c b/arangod/VocBase/document-collection.c index 1d8c1aaa82..68c6122488 100644 --- a/arangod/VocBase/document-collection.c +++ b/arangod/VocBase/document-collection.c @@ -846,33 +846,6 @@ static int DeleteDocument (TRI_doc_operation_context_t* context, return TRI_ERROR_NO_ERROR; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief updates a document in the collection from json -//////////////////////////////////////////////////////////////////////////////// - -static int UpdateJson (TRI_doc_operation_context_t* context, - TRI_doc_mptr_t** mptr, - TRI_json_t const* json, - TRI_voc_key_t key) { - TRI_shaped_json_t* shaped; - TRI_primary_collection_t* primary; - int res; - - primary = context->_collection; - - shaped = TRI_ShapedJsonJson(primary->_shaper, json); - - if (shaped == 0) { - return TRI_ERROR_ARANGO_SHAPER_FAILED; - } - - res = primary->update(context, mptr, shaped, key); - - TRI_FreeShapedJson(primary->_shaper, shaped); - - return res; -} - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// @@ -1846,8 +1819,6 @@ static bool InitDocumentCollection (TRI_document_collection_t* collection, collection->base.update = UpdateShapedJson; collection->base.destroy = DeleteShapedJson; - collection->base.updateJson = UpdateJson; - collection->cleanupIndexes = CleanupIndexes; return true; diff --git a/arangod/VocBase/primary-collection.h b/arangod/VocBase/primary-collection.h index cf062e1bd3..48136b4d35 100644 --- a/arangod/VocBase/primary-collection.h +++ b/arangod/VocBase/primary-collection.h @@ -189,7 +189,7 @@ TRI_doc_collection_info_t; /// as the object is not deleted. /// /// It is important to use locks for create, read, update, and delete. The -/// functions @FN{create}, @FN{update}, @FN{updateJson}, and +/// functions @FN{create}, @FN{update}, and /// @FN{destroy} are only allowed within a @FN{beginWrite} and /// @FN{endWrite}. The function @FN{read} is only allowed within a /// @FN{beginRead} and @FN{endRead}. Note that @FN{read} returns a copy of the @@ -261,16 +261,8 @@ TRI_doc_collection_info_t; /// performed if the current revision matches the given. In any case the current /// revision after the updated of the document is returned in @FA{current}. /// -/// @FUN{TRI_doc_mptr_t const updateJson (TRI_primary_collection_t*, TRI_json_t const*, TRI_voc_key_t, TRI_voc_rid_t @FA{rid}, TRI_voc_rid_t* @FA{current}, TRI_doc_update_policy_e, bool @FA{release})} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// -/// As before, but instead of a shaped json a json object must be given. -/// -/// @FUN{int updateLock (TRI_primary_collection_t*, TRI_shaped_json_t const*, TRI_voc_key_t, TRI_voc_rid_t @FA{rid}, TRI_voc_rid_t* @FA{current}, TRI_doc_update_policy_e)} -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/// -/// As before, but the function will acquire and release the write lock. -/// /// @FUN{int destroy (TRI_primary_collection_t*, TRI_voc_key_t, TRI_voc_rid_t, TRI_voc_rid_t @FA{rid}, TRI_voc_rid_t* @FA{current}, TRI_doc_update_policy_e, bool @FA{release})} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// @@ -330,8 +322,6 @@ typedef struct TRI_primary_collection_s { int (*read) (struct TRI_doc_operation_context_s*, TRI_doc_mptr_t**, TRI_voc_key_t); int (*update) (struct TRI_doc_operation_context_s*, TRI_doc_mptr_t**, TRI_shaped_json_t const*, TRI_voc_key_t); - int (*updateJson) (struct TRI_doc_operation_context_s*, TRI_doc_mptr_t**, TRI_json_t const*, TRI_voc_key_t); - int (*destroy) (struct TRI_doc_operation_context_s*, TRI_voc_key_t); TRI_doc_collection_info_t* (*figures) (struct TRI_primary_collection_s* collection); diff --git a/lib/BasicsC/json-utilities.c b/lib/BasicsC/json-utilities.c index 6ef50beaf6..ead74b25df 100644 --- a/lib/BasicsC/json-utilities.c +++ b/lib/BasicsC/json-utilities.c @@ -667,26 +667,28 @@ TRI_json_t* TRI_SortListJson (TRI_json_t* const list) { bool TRI_HasDuplicateKeyJson (const TRI_json_t* const object) { if (object && object->_type == TRI_JSON_ARRAY) { const size_t n = object->_value._objects._length; + const bool hasMultipleElements = (n > 2); // if we don't have attributes, we do not need to check for duplicates // if we only have one attribute, we don't need to check for duplicates in // the array, but we need to recursively validate the array values (if // array value itself is an array) - if (n > 2) { + if (n > 0) { TRI_associative_pointer_t hash; size_t i; - TRI_InitAssociativePointer(&hash, + if (hasMultipleElements) { + TRI_InitAssociativePointer(&hash, TRI_UNKNOWN_MEM_ZONE, &TRI_HashStringKeyAssociativePointer, &TRI_HashStringKeyAssociativePointer, &TRI_EqualStringKeyAssociativePointer, 0); + } for (i = 0; i < n; i += 2) { TRI_json_t* key; TRI_json_t* value; - void* previous; key = TRI_AtVector(&object->_value._objects, i); @@ -699,21 +701,27 @@ bool TRI_HasDuplicateKeyJson (const TRI_json_t* const object) { // recursively check sub-array elements if (value->_type == TRI_JSON_ARRAY && TRI_HasDuplicateKeyJson(value)) { // duplicate found in sub-array - TRI_DestroyAssociativePointer(&hash); + if (hasMultipleElements) { + TRI_DestroyAssociativePointer(&hash); + } return true; } - previous = TRI_InsertKeyAssociativePointer(&hash, key->_value._string.data, key->_value._string.data, false); - if (previous != NULL) { - // duplicate found - TRI_DestroyAssociativePointer(&hash); + if (hasMultipleElements) { + void* previous = TRI_InsertKeyAssociativePointer(&hash, key->_value._string.data, key->_value._string.data, false); + if (previous != NULL) { + // duplicate found + TRI_DestroyAssociativePointer(&hash); - return true; + return true; + } } } - TRI_DestroyAssociativePointer(&hash); + if (hasMultipleElements) { + TRI_DestroyAssociativePointer(&hash); + } } } diff --git a/lib/Rest/HttpRequest.cpp b/lib/Rest/HttpRequest.cpp index a5d6f16a3b..fc93a86897 100644 --- a/lib/Rest/HttpRequest.cpp +++ b/lib/Rest/HttpRequest.cpp @@ -540,6 +540,7 @@ HttpRequest::HttpRequestType HttpRequest::getRequestType (const char* ptr, const void HttpRequest::parseHeader (char* ptr, size_t length) { char* start = ptr; char* end = start + length; + const size_t versionLength = strlen("http/1.x"); // current line number int lineNum = 0; @@ -628,7 +629,7 @@ void HttpRequest::parseHeader (char* ptr, size_t length) { ++e; } - if ((size_t)(end - e) > strlen("http/1.x")) { + if ((size_t)(end - e) > versionLength) { if ((e[0] == 'h' || e[0] == 'H') && (e[1] == 't' || e[1] == 'T') && (e[2] == 't' || e[2] == 'T') && @@ -643,7 +644,7 @@ void HttpRequest::parseHeader (char* ptr, size_t length) { _version = HTTP_1_0; } - e += strlen("http/1.x"); + e += versionLength; } } From c64208de2542bb0b3707c223a3516d746f46234b Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 15 Feb 2013 11:36:53 +0100 Subject: [PATCH 07/11] disable some statistics that are never queried --- lib/Basics/AssociativeArray.h | 48 +++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/Basics/AssociativeArray.h b/lib/Basics/AssociativeArray.h index 1933299fb5..0a97ffec24 100644 --- a/lib/Basics/AssociativeArray.h +++ b/lib/Basics/AssociativeArray.h @@ -122,6 +122,7 @@ namespace triagens { : _desc(), _nrAlloc(0), _nrUsed(0), +#ifdef TRI_INTERNAL_STATS _table(0), _nrFinds(0), _nrAdds(0), @@ -131,6 +132,9 @@ namespace triagens { _nrProbesA(0), _nrProbesD(0), _nrProbesR(0) { +#else + _table(0) { +#endif initialise(size); } @@ -142,6 +146,7 @@ namespace triagens { _desc(desc), _nrAlloc(0), _nrUsed(0), +#ifdef TRI_INTERNAL_STATS _table(0), _nrFinds(0), _nrAdds(0), @@ -151,6 +156,9 @@ namespace triagens { _nrProbesA(0), _nrProbesD(0), _nrProbesR(0) { +#else + _table(0) { +#endif initialise(size); } @@ -194,6 +202,7 @@ namespace triagens { _nrUsed = other->_nrUsed; other->_nrUsed = tmpInt; +#ifdef TRI_INTERNAL_STATS tmpInt = _nrFinds; _nrFinds = other->_nrFinds; other->_nrFinds = tmpInt; @@ -229,6 +238,7 @@ namespace triagens { tmpInt = _nrProbesR; _nrProbesR = other->_nrProbesR; other->_nrProbesR = tmpInt; +#endif ELEMENT* tmpTable = _table; _table = other->_table; @@ -289,9 +299,10 @@ namespace triagens { ELEMENT const& findKey (KEY const& key) const { +#ifdef TRI_INTERNAL_STATS // update statistics _nrFinds++; - +#endif // compute the hash uint32_t hash = _desc.hashKey(key); @@ -300,7 +311,9 @@ namespace triagens { while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualKeyElement(key, _table[i])) { i = (i + 1) % _nrAlloc; +#ifdef TRI_INTERNAL_STATS _nrProbesF++; +#endif } // return whatever we found @@ -313,9 +326,10 @@ namespace triagens { ELEMENT const& findElement (ELEMENT const& element) const { +#ifdef TRI_INTERNAL_STATS // update statistics _nrFinds++; - +#endif // compute the hash uint32_t hash = _desc.hashElement(element); @@ -324,7 +338,9 @@ namespace triagens { while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualElementElement(element, _table[i])) { i = (i + 1) % _nrAlloc; +#ifdef TRI_INTERNAL_STATS _nrProbesF++; +#endif } // return whatever we found @@ -337,8 +353,10 @@ namespace triagens { bool addElement (ELEMENT const& element, bool overwrite = true) { +#ifdef TRI_INTERNAL_STATS // update statistics _nrAdds++; +#endif // search the table uint32_t hash = _desc.hashElement(element); @@ -346,7 +364,9 @@ namespace triagens { while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualElementElement(element, _table[i])) { i = (i + 1) % _nrAlloc; +#ifdef TRI_INTERNAL_STATS _nrProbesA++; +#endif } // if we found an element, return @@ -373,7 +393,9 @@ namespace triagens { _nrAlloc = 2 * _nrAlloc + 1; _nrUsed = 0; +#ifdef TRI_INTERNAL_STATS _nrResizes++; +#endif _table = new ELEMENT[_nrAlloc]; @@ -399,8 +421,10 @@ namespace triagens { bool addElement (KEY const& key, ELEMENT const& element, bool overwrite = true) { +#ifdef TRI_INTERNAL_STATS // update statistics _nrAdds++; +#endif // search the table uint32_t hash = _desc.hashKey(key); @@ -408,7 +432,9 @@ namespace triagens { while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualKeyElement(key, _table[i])) { i = (i + 1) % _nrAlloc; +#ifdef TRI_INTERNAL_STATS _nrProbesA++; +#endif } // if we found an element, return @@ -435,7 +461,9 @@ namespace triagens { _nrAlloc = 2 * _nrAlloc + 1; _nrUsed = 0; +#ifdef TRI_INTERNAL_STATS _nrResizes++; +#endif _table = new ELEMENT[_nrAlloc]; @@ -461,8 +489,10 @@ namespace triagens { ELEMENT removeKey (KEY const& key) { +#ifdef TRI_INTERNAL_STATS // update statistics _nrRems++; +#endif // search the table uint32_t hash = _desc.hashKey(key); @@ -470,7 +500,9 @@ namespace triagens { while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualKeyElement(key, _table[i])) { i = (i + 1) % _nrAlloc; +#ifdef TRI_INTERNAL_STATS _nrProbesD++; +#endif } // if we did not find such an item @@ -510,8 +542,10 @@ namespace triagens { bool removeElement (ELEMENT const& element) { +#ifdef TRI_INTERNAL_STATS // update statistics _nrRems++; +#endif // search the table uint32_t hash = _desc.hashElement(element); @@ -519,7 +553,9 @@ namespace triagens { while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualElementElement(element, _table[i])) { i = (i + 1) % _nrAlloc; +#ifdef TRI_INTERNAL_STATS _nrProbesD++; +#endif } // if we did not find such an item return false @@ -578,6 +614,7 @@ namespace triagens { _nrAlloc = size; _nrUsed = 0; +#ifdef TRI_INTERNAL_STATS _nrFinds = 0; _nrAdds = 0; _nrRems = 0; @@ -586,6 +623,7 @@ namespace triagens { _nrProbesA = 0; _nrProbesD = 0; _nrProbesR = 0; +#endif } //////////////////////////////////////////////////////////////////////////////// @@ -602,7 +640,9 @@ namespace triagens { while (!_desc.isEmptyElement(_table[i])) { i = (i + 1) % _nrAlloc; +#ifdef TRI_INTERNAL_STATS _nrProbesR++; +#endif } // add a new element to the associative array @@ -649,6 +689,8 @@ namespace triagens { ELEMENT * _table; +#ifdef TRI_INTERNAL_STATS + //////////////////////////////////////////////////////////////////////////////// /// @brief number of executed finds //////////////////////////////////////////////////////////////////////////////// @@ -696,6 +738,8 @@ namespace triagens { //////////////////////////////////////////////////////////////////////////////// mutable uint64_t _nrProbesR; +#endif + }; } } From e4d1c8a6bdba670f6cf7574943f82862b6f43ddf Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 15 Feb 2013 11:50:05 +0100 Subject: [PATCH 08/11] partly fix for issue #333: [debian] Group arangodb is not used when starting vie init.d script --- arangod/RestServer/ArangoServer.cpp | 32 +--- lib/ApplicationServer/ApplicationServer.cpp | 106 +++++++------ lib/ApplicationServer/ApplicationServer.h | 2 +- lib/BasicsC/init.c | 2 +- lib/BasicsC/logging.c | 10 +- lib/BasicsC/operating-system.h | 22 ++- lib/BasicsC/process-utils.c | 35 ++++- lib/Rest/AnyServer.cpp | 158 +++++--------------- 8 files changed, 148 insertions(+), 219 deletions(-) diff --git a/arangod/RestServer/ArangoServer.cpp b/arangod/RestServer/ArangoServer.cpp index f424607cfd..cd1494ba6d 100644 --- a/arangod/RestServer/ArangoServer.cpp +++ b/arangod/RestServer/ArangoServer.cpp @@ -241,7 +241,6 @@ void ArangoServer::buildApplicationServer () { _applicationServer->addFeature(_applicationScheduler); - // ............................................................................. // dispatcher // ............................................................................. @@ -249,7 +248,6 @@ void ArangoServer::buildApplicationServer () { _applicationDispatcher = new ApplicationDispatcher(_applicationScheduler); _applicationServer->addFeature(_applicationDispatcher); - // ............................................................................. // V8 engine // ............................................................................. @@ -306,7 +304,6 @@ void ArangoServer::buildApplicationServer () { additional[ApplicationServer::OPTIONS_HIDDEN] ("no-upgrade", "skip a database upgrade") - ("show-markers", "show offset and sizes of markers") ; #ifdef TRI_ENABLE_MRUBY @@ -489,7 +486,7 @@ void ArangoServer::buildApplicationServer () { if (absoluteFile != 0) { _pidFile = string(absoluteFile); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, absoluteFile); + TRI_Free(TRI_CORE_MEM_ZONE, absoluteFile); LOGGER_DEBUG("using absolute pid file '" << _pidFile << "'"); } @@ -497,7 +494,6 @@ void ArangoServer::buildApplicationServer () { LOGGER_FATAL_AND_EXIT("cannot determine current directory"); } } - } //////////////////////////////////////////////////////////////////////////////// @@ -580,22 +576,6 @@ int ArangoServer::startupServer () { TRI_InitialiseStatistics(); - // ............................................................................. - // show markers - // ............................................................................. - - if (_applicationServer->programOptions().has("show-markers")) { - LOGGER_INFO("sizeof(TRI_df_marker_t): " << sizeof(TRI_df_marker_t)); - LOGGER_INFO("sizeof(TRI_df_header_marker_t): " << sizeof(TRI_df_header_marker_t)); - LOGGER_INFO("sizeof(TRI_df_footer_marker_t): " << sizeof(TRI_df_footer_marker_t)); - LOGGER_INFO("sizeof(TRI_df_document_marker_t): " << sizeof(TRI_df_document_marker_t)); - LOGGER_INFO("sizeof(TRI_df_skip_marker_t): " << sizeof(TRI_df_skip_marker_t)); - LOGGER_INFO("sizeof(TRI_doc_document_key_marker_s): " << sizeof(TRI_doc_document_key_marker_s)); - LOGGER_INFO("sizeof(TRI_doc_edge_key_marker_s): " << sizeof(TRI_doc_edge_key_marker_s)); - LOGGER_INFO("sizeof(TRI_doc_deletion_key_marker_s): " << sizeof(TRI_doc_deletion_key_marker_s)); - } - - // ............................................................................. // start the main event loop // ............................................................................. @@ -639,11 +619,6 @@ int ArangoServer::startupServer () { int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) { bool ok; - // only simple logging - TRI_ShutdownLogging(); - TRI_InitialiseLogging(false); - TRI_CreateLogAppenderFile("+"); - // open the database openDatabase(); @@ -967,11 +942,6 @@ mrb_value MR_ArangoDatabase_Collection (mrb_state* mrb, mrb_value self) { int ArangoServer::executeRubyConsole () { bool ok; - // only simple logging - TRI_ShutdownLogging(); - TRI_InitialiseLogging(false); - TRI_CreateLogAppenderFile("+"); - // open the database openDatabase(); diff --git a/lib/ApplicationServer/ApplicationServer.cpp b/lib/ApplicationServer/ApplicationServer.cpp index 104695655a..1ef5e03b82 100644 --- a/lib/ApplicationServer/ApplicationServer.cpp +++ b/lib/ApplicationServer/ApplicationServer.cpp @@ -107,6 +107,7 @@ string const ApplicationServer::OPTIONS_SERVER = "Server Options"; //////////////////////////////////////////////////////////////////////////////// #ifdef _WIN32 + ApplicationServer::ApplicationServer (std::string const& name, std::string const& title, std::string const& version) : _options(), _description(), @@ -142,7 +143,9 @@ ApplicationServer::ApplicationServer (std::string const& name, std::string const _logLineNumber(false), _randomGenerator(5) { } + #else + ApplicationServer::ApplicationServer (std::string const& name, std::string const& title, std::string const& version) : _options(), _description(), @@ -177,7 +180,9 @@ ApplicationServer::ApplicationServer (std::string const& name, std::string const _logThreadId(false), _logLineNumber(false), _randomGenerator(3) { + storeRealPrivileges(); } + #endif //////////////////////////////////////////////////////////////////////////////// @@ -247,9 +252,8 @@ string const& ApplicationServer::getName () const { /// @brief sets up the logging //////////////////////////////////////////////////////////////////////////////// -void ApplicationServer::setupLogging () { - bool threaded = TRI_ShutdownLogging(); - +void ApplicationServer::setupLogging (bool threaded, bool daemon) { + TRI_ShutdownLogging(); TRI_InitialiseLogging(threaded); Logger::setApplicationName(_logApplicationName); @@ -279,17 +283,26 @@ void ApplicationServer::setupLogging () { TRI_SetFileToLog(i->c_str()); } - if (NULL == TRI_CreateLogAppenderFile(_logFile.c_str())) { - if (_logFile.length() > 0) { - // the user specified a log file to use but it could not be created. bail out - LOGGER_FATAL_AND_EXIT("failed to create logfile '" << _logFile << "'. Please check the path and permissions."); - } - } #ifdef TRI_ENABLE_SYSLOG if (_logSyslog != "") { TRI_CreateLogAppenderSyslog(_logPrefix.c_str(), _logSyslog.c_str()); } #endif + + if (_logFile.length() > 0) { + string filename = _logFile; + + if (daemon && filename != "+" && filename != "-") { + filename = filename + ".daemon"; + } + + struct TRI_log_appender_s* appender = TRI_CreateLogAppenderFile(filename.c_str()); + + // the user specified a log file to use but it could not be created. bail out + if (appender == 0) { + LOGGER_FATAL_AND_EXIT("failed to create logfile '" << filename << "'. Please check the path and permissions."); + } + } } //////////////////////////////////////////////////////////////////////////////// @@ -378,21 +391,6 @@ bool ApplicationServer::parse (int argc, exit(EXIT_SUCCESS); } - // ............................................................................. - // UID and GID - // ............................................................................. - - - storeRealPrivileges(); - extractPrivileges(); - dropPrivileges(); - - // ............................................................................. - // setup logging - // ............................................................................. - - setupLogging(); - // ............................................................................. // parse phase 1 // ............................................................................. @@ -415,8 +413,18 @@ bool ApplicationServer::parse (int argc, return false; } - // re-set logging using the additional config file entries - setupLogging(); + // ............................................................................. + // UID and GID + // ............................................................................. + + extractPrivileges(); + dropPrivileges(); + + // ............................................................................. + // setup logging + // ............................................................................. + + setupLogging(false, false); // ............................................................................. // parse phase 2 @@ -718,6 +726,20 @@ void ApplicationServer::dropPrivilegesPermanently () { #endif } +//////////////////////////////////////////////////////////////////////////////// +/// @brief saves the logging privileges +//////////////////////////////////////////////////////////////////////////////// + +void ApplicationServer::storeRealPrivileges () { +#ifdef TRI_HAVE_SETGID + _realGid = getgid(); +#endif + +#ifdef TRI_HAVE_SETUID + _realUid = getuid(); +#endif +} + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// @@ -746,12 +768,6 @@ void ApplicationServer::setupOptions (map& op #if defined(TRI_HAVE_SETUID) || defined(TRI_HAVE_SETGID) options[OPTIONS_CMDLINE + ":help-extended"] -#ifdef TRI_HAVE_SETUID - ("uid", &_uid, "switch to user-id after reading config files") -#endif -#ifdef TRI_HAVE_SETGID - ("gid", &_gid, "switch to group-id after reading config files") -#endif #ifdef TRI_HAVE_GETPPID ("exit-on-parent-death", &_exitOnParentDeath, "exit if parent dies") #endif @@ -784,6 +800,12 @@ void ApplicationServer::setupOptions (map& op options[OPTIONS_HIDDEN] ("log", &_logLevel, "log level for severity 'human'") +#ifdef TRI_HAVE_SETUID + ("uid", &_uid, "switch to user-id after reading config files") +#endif +#ifdef TRI_HAVE_SETGID + ("gid", &_gid, "switch to group-id after reading config files") +#endif ; // ............................................................................. @@ -793,6 +815,12 @@ void ApplicationServer::setupOptions (map& op options[OPTIONS_SERVER + ":help-extended"] ("random.no-seed", "do not seed the random generator") ("random.generator", &_randomGenerator, "1 = mersenne, 2 = random, 3 = urandom, 4 = combined") +#ifdef TRI_HAVE_SETUID + ("server.uid", &_uid, "switch to user-id after reading config files") +#endif +#ifdef TRI_HAVE_SETGID + ("server.gid", &_gid, "switch to group-id after reading config files") +#endif ; } @@ -1124,20 +1152,6 @@ void ApplicationServer::extractPrivileges() { #endif } -//////////////////////////////////////////////////////////////////////////////// -/// @brief saves the logging privileges -//////////////////////////////////////////////////////////////////////////////// - -void ApplicationServer::storeRealPrivileges () { -#ifdef TRI_HAVE_SETGID - _realGid = getgid(); -#endif - -#ifdef TRI_HAVE_SETUID - _realUid = getuid(); -#endif -} - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/ApplicationServer/ApplicationServer.h b/lib/ApplicationServer/ApplicationServer.h index 2f7a68adbb..0d921aa22e 100644 --- a/lib/ApplicationServer/ApplicationServer.h +++ b/lib/ApplicationServer/ApplicationServer.h @@ -183,7 +183,7 @@ namespace triagens { /// @brief sets up the logging //////////////////////////////////////////////////////////////////////////////// - void setupLogging (); + void setupLogging (bool thread, bool daemon); //////////////////////////////////////////////////////////////////////////////// /// @brief returns the command line options diff --git a/lib/BasicsC/init.c b/lib/BasicsC/init.c index 7c8b1a7ad0..5b8463747b 100644 --- a/lib/BasicsC/init.c +++ b/lib/BasicsC/init.c @@ -53,7 +53,7 @@ void TRI_InitialiseC (int argc, char* argv[]) { TRI_InitialiseMemory(); TRI_InitialiseMersenneTwister(); TRI_InitialiseError(); - TRI_InitialiseLogging(true); + TRI_InitialiseLogging(false); TRI_InitialiseHashes(); TRI_InitialiseRandom(); TRI_InitialiseProcess(argc, argv); diff --git a/lib/BasicsC/logging.c b/lib/BasicsC/logging.c index 6e394bbd80..983833e429 100644 --- a/lib/BasicsC/logging.c +++ b/lib/BasicsC/logging.c @@ -254,7 +254,7 @@ static sig_atomic_t ShowFunction = 1; /// @brief show thread identifier //////////////////////////////////////////////////////////////////////////////// -static sig_atomic_t ShowThreadIdentifier = 1; +static sig_atomic_t ShowThreadIdentifier = 0; //////////////////////////////////////////////////////////////////////////////// /// @brief output prefix @@ -541,8 +541,8 @@ static void OutputMessage (TRI_log_level_e level, size_t length, bool copy) { if (! LoggingActive) { - write(2, message, length); - write(2, "\n", 1); + write(STDERR_FILENO, message, length); + write(STDERR_FILENO, "\n", 1); if (! copy) { TRI_FreeString(TRI_CORE_MEM_ZONE, message); @@ -558,8 +558,8 @@ static void OutputMessage (TRI_log_level_e level, TRI_LockSpin(&AppendersLock); if (Appenders._length == 0) { - write(2, message, length); - write(2, "\n", 1); + write(STDERR_FILENO, message, length); + write(STDERR_FILENO, "\n", 1); if (! copy) { TRI_FreeString(TRI_CORE_MEM_ZONE, message); diff --git a/lib/BasicsC/operating-system.h b/lib/BasicsC/operating-system.h index bfc4d5c14d..016e3ae796 100755 --- a/lib/BasicsC/operating-system.h +++ b/lib/BasicsC/operating-system.h @@ -41,10 +41,6 @@ /// @{ //////////////////////////////////////////////////////////////////////////////// -#define TRI_HAVE_GETGRGID 1 -#define TRI_HAVE_GETPWNAM 1 -#define TRI_HAVE_GETPWUID 1 - #define GLOBAL_TIMEZONE timezone #ifndef __STDC_LIMIT_MACROS @@ -110,6 +106,11 @@ #define TRI_HAVE_SETGID 1 #define TRI_HAVE_SETUID 1 +#define TRI_HAVE_GETGRGID 1 +#define TRI_HAVE_GETPWNAM 1 +#define TRI_HAVE_GETPWUID 1 +#define TRI_HAVE_GETGRNAM 1 + #define TRI_HAVE_STRTOLL 1 #define TRI_HAVE_STRTOULL 1 @@ -332,6 +333,11 @@ typedef int socket_t; #define TRI_HAVE_SETGID 1 #define TRI_HAVE_SETUID 1 +#define TRI_HAVE_GETGRGID 1 +#define TRI_HAVE_GETPWNAM 1 +#define TRI_HAVE_GETPWUID 1 +#define TRI_HAVE_GETGRNAM 1 + #define TRI_HAVE_STRTOLL 1 #define TRI_HAVE_STRTOULL 1 @@ -395,6 +401,7 @@ typedef int socket_t; // This directive below suppresses warnings about using the 'new' more secure CRT // functions. // .............................................................................. + #define _CRT_SECURE_NO_WARNINGS 1 // .............................................................................. @@ -402,6 +409,7 @@ typedef int socket_t; // for example, strcpy is automatically converted to strcpy_s. This is enabled // by default. We have disabled it here. // .............................................................................. + //#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 #include @@ -479,10 +487,8 @@ typedef unsigned char bool; #define false 0 #endif - #define va_copy(d,s) ((d) = (s)) - // we do not have owner read and owner write under windows // so map these to global read, global write // these are used when creating a file @@ -516,6 +522,7 @@ typedef unsigned char bool; // security identifiers (SID) which is a variable length structure // which can (should) not be accessed directly. // ........................................................................... + #define TRI_uid_t void* #define TRI_gid_t void* @@ -523,11 +530,13 @@ typedef unsigned char bool; // windows does not like the keyword inline -- but only if it uses the c compiler // weird. _inline should work for both I hope // ........................................................................... + #define inline _inline // ........................................................................... // windows uses _alloca instead of alloca // ........................................................................... + #define alloca _alloca @@ -537,7 +546,6 @@ typedef SOCKET socket_t; #define STDOUT_FILENO 1; #define STDERR_FILENO 2; - #endif //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/process-utils.c b/lib/BasicsC/process-utils.c index aa1347a628..7220965dfa 100644 --- a/lib/BasicsC/process-utils.c +++ b/lib/BasicsC/process-utils.c @@ -27,6 +27,10 @@ #include "process-utils.h" +#ifdef TRI_HAVE_SYS_PRCTL_H +#include +#endif + #include "BasicsC/strings.h" #include "BasicsC/logging.h" @@ -145,7 +149,17 @@ static char** ARGV = 0; /// @brief true, if environment has been copied already //////////////////////////////////////////////////////////////////////////////// +#ifdef TRI_TAMPER_WITH_ENVIRON static bool IsEnvironmentEnlarged = false; +#endif + +//////////////////////////////////////////////////////////////////////////////// +/// @brief do we need to free the copy of the environ data on shutdown +//////////////////////////////////////////////////////////////////////////////// + +#ifdef TRI_TAMPER_WITH_ENVIRON +static bool MustFreeEnvironment = false; +#endif //////////////////////////////////////////////////////////////////////////////// /// @brief maximal size of the process title @@ -153,12 +167,6 @@ static bool IsEnvironmentEnlarged = false; static size_t MaximalProcessTitleSize = 0; -//////////////////////////////////////////////////////////////////////////////// -/// @brief do we need to free the copy of the environ data on shutdown -//////////////////////////////////////////////////////////////////////////////// - -static bool MustFreeEnvironment = false; - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// @@ -322,8 +330,11 @@ uint64_t TRI_ProcessSize (TRI_pid_t pid) { extern char** environ; void TRI_SetProcessTitle (char const* title) { +#if TRI_TAMPER_WITH_ENVIRON + if (! IsEnvironmentEnlarged) { size_t size; + int envLen = -1; if (environ) { @@ -358,12 +369,22 @@ void TRI_SetProcessTitle (char const* title) { MaximalProcessTitleSize = size; } +#else + + MaximalProcessTitleSize = ARGV[ARGC - 1] + strlen(ARGV[ARGC - 1]) - ARGV[0]; + +#endif + if (0 < MaximalProcessTitleSize) { char* args = ARGV[0]; memset(args, '\0', MaximalProcessTitleSize); snprintf(args, MaximalProcessTitleSize - 1, "%s", title); } + +#ifdef TRI_HAVE_SYS_PRCTL_H + prctl(PR_SET_NAME, title, 0, 0, 0); +#endif } //////////////////////////////////////////////////////////////////////////////// @@ -404,6 +425,7 @@ void TRI_InitialiseProcess (int argc, char* argv[]) { void TRI_ShutdownProcess () { TRI_FreeString(TRI_CORE_MEM_ZONE, ProcessName); +#ifdef TRI_TAMPER_WITH_ENVIRON if (MustFreeEnvironment) { size_t i = 0; @@ -416,6 +438,7 @@ void TRI_ShutdownProcess () { } TRI_Free(TRI_CORE_MEM_ZONE, environ); } +#endif } //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Rest/AnyServer.cpp b/lib/Rest/AnyServer.cpp index 5c668697ed..658b639e0b 100644 --- a/lib/Rest/AnyServer.cpp +++ b/lib/Rest/AnyServer.cpp @@ -58,14 +58,24 @@ using namespace triagens::rest; /// @{ //////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +/// @brief writes a pid file +//////////////////////////////////////////////////////////////////////////////// -#ifdef TRI_HAVE_FORK +static void WritePidFile (string const& pidFile, int pid) { + ofstream out(pidFile.c_str(), ios::trunc); + + if (! out) { + LOGGER_FATAL_AND_EXIT("cannot write pid-file \"" << pidFile << "\"\n"); + } + + out << pid; +} //////////////////////////////////////////////////////////////////////////////// /// @brief checks a pid file //////////////////////////////////////////////////////////////////////////////// - static void CheckPidFile (string const& pidFile) { // check if the pid-file exists @@ -90,7 +100,12 @@ static void CheckPidFile (string const& pidFile) { LOGGER_DEBUG("found old pid: " << oldPid); +#ifdef TRI_HAVE_FORK int r = kill(oldPid, 0); +#else + int r = 0; // TODO for windows use TerminateProcess +#endif + if (r == 0) { LOGGER_FATAL_AND_EXIT("pid-file '" << pidFile << "' exists and process with pid " << oldPid << " is still running"); } @@ -121,25 +136,13 @@ static void CheckPidFile (string const& pidFile) { } } -//////////////////////////////////////////////////////////////////////////////// -/// @brief writes a pid file -//////////////////////////////////////////////////////////////////////////////// - -static void WritePidFile (string const& pidFile, int pid) { - ofstream out(pidFile.c_str(), ios::trunc); - - if (! out) { - LOGGER_FATAL_AND_EXIT("cannot write pid-file \"" << pidFile << "\"\n"); - } - - out << pid; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief forks a new process //////////////////////////////////////////////////////////////////////////////// -static int forkProcess (string const& workingDirectory, string& current, ApplicationServer* applicationServer) { +#ifdef TRI_HAVE_FORK + +static int forkProcess (string const& workingDirectory, string& current) { // fork off the parent process TRI_pid_t pid = fork(); @@ -157,10 +160,6 @@ static int forkProcess (string const& workingDirectory, string& current, Applica return pid; } - // reset the logging - TRI_InitialiseLogging(TRI_ShutdownLogging()); - applicationServer->setupLogging(); - // change the file mode mask umask(0); @@ -185,7 +184,7 @@ static int forkProcess (string const& workingDirectory, string& current, Applica LOGGER_FATAL_AND_EXIT("cannot change into working directory '" << workingDirectory << "'"); } else { - LOGGER_INFO("changed into working directory '" << workingDirectory << "'"); + LOGGER_INFO("changed working directory for child process to '" << workingDirectory << "'"); } } @@ -195,91 +194,11 @@ static int forkProcess (string const& workingDirectory, string& current, Applica #else -//////////////////////////////////////////////////////////////////////////////// -/// @brief checks a pid file -//////////////////////////////////////////////////////////////////////////////// - - -static void CheckPidFile (string const& pidFile) { - - // check if the pid-file exists - if (! pidFile.empty()) { - if (FileUtils::isDirectory(pidFile)) { - LOGGER_FATAL_AND_EXIT("pid-file '" << pidFile << "' is a directory"); - } - else if (FileUtils::exists(pidFile) && FileUtils::size(pidFile) > 0) { - LOGGER_INFO("pid-file '" << pidFile << "' already exists, verifying pid"); - - ifstream f(pidFile.c_str()); - - // file can be opened - if (f) { - TRI_pid_t oldPid; - - f >> oldPid; - - if (oldPid == 0) { - LOGGER_FATAL_AND_EXIT("pid-file '" << pidFile << "' is unreadable"); - } - - LOGGER_DEBUG("found old pid: " << oldPid); - - int r = 0; - // for windows use TerminateProcess - //int r = kill(oldPid, 0); - if (r == 0) { - LOGGER_FATAL_AND_EXIT("pid-file '" << pidFile << "' exists and process with pid " << oldPid << " is still running"); - } - else if (errno == EPERM) { - LOGGER_FATAL_AND_EXIT("pid-file '" << pidFile << "' exists and process with pid " << oldPid << " is still running"); - } - else if (errno == ESRCH) { - LOGGER_ERROR("pid-file '" << pidFile << "' exists, but no process with pid " << oldPid << " exists"); - - if (! FileUtils::remove(pidFile)) { - LOGGER_FATAL_AND_EXIT("pid-file '" << pidFile << "' exists, no process with pid " << oldPid << " exists, but pid-file cannot be removed"); - } - - LOGGER_INFO("removed stale pid-file '" << pidFile << "'"); - } - else { - LOGGER_FATAL_AND_EXIT("pid-file '" << pidFile << "' exists and kill " << oldPid << " failed"); - } - } - - // failed to open file - else { - LOGGER_FATAL_AND_EXIT("pid-file '" << pidFile << "' exists, but cannot be opened"); - } - } - - LOGGER_DEBUG("using pid-file '" << pidFile << "'"); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief writes a pid file -//////////////////////////////////////////////////////////////////////////////// - -static void WritePidFile (string const& pidFile, int pid) { - ofstream out(pidFile.c_str(), ios::trunc); - - if (! out) { - LOGGER_FATAL_AND_EXIT << "cannot write pid-file \"" << pidFile << "\""; - } - - out << pid; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief forks a new process -//////////////////////////////////////////////////////////////////////////////// - // .............................................................................. // TODO: use windows API CreateProcess & CreateThread to minic fork() // .............................................................................. -static int forkProcess (string const& workingDirectory, string& current, ApplicationServer* applicationServer) { +static int forkProcess (string const& workingDirectory, string& current) { // fork off the parent process TRI_pid_t pid = -1; // fork(); @@ -346,7 +265,6 @@ AnyServer::~AnyServer () { //////////////////////////////////////////////////////////////////////////////// int AnyServer::start () { - if (_applicationServer == 0) { buildApplicationServer(); } @@ -358,6 +276,8 @@ int AnyServer::start () { return startupDaemon(); } else { + _applicationServer->setupLogging(true, false); + if (! _pidFile.empty()) { CheckPidFile(_pidFile); WritePidFile(_pidFile, TRI_CurrentProcessId()); @@ -421,8 +341,10 @@ int AnyServer::startupSupervisor () { CheckPidFile(_pidFile); + _applicationServer->setupLogging(false, true); + string current; - int result = forkProcess(_workingDirectory, current, safe_cast(_applicationServer)); + int result = forkProcess(_workingDirectory, current); // main process if (result != 0) { @@ -447,13 +369,8 @@ int AnyServer::startupSupervisor () { // parent if (0 < pid) { - char const* title = "arangodb [supervisor]"; - - TRI_SetProcessTitle(title); - -#ifdef TRI_HAVE_SYS_PRCTL_H - prctl(PR_SET_NAME, title, 0, 0, 0); -#endif + _applicationServer->setupLogging(false, true); + TRI_SetProcessTitle("arangodb [supervisor]"); int status; waitpid(pid, &status, 0); @@ -523,14 +440,11 @@ int AnyServer::startupSupervisor () { // child else { + _applicationServer->setupLogging(true, false); // write the pid file WritePidFile(_pidFile, TRI_CurrentProcessId()); - // reset logging - TRI_InitialiseLogging(TRI_ShutdownLogging()); - safe_cast(_applicationServer)->setupLogging(); - // force child to stop if supervisor dies #ifdef TRI_HAVE_PRCTL prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0); @@ -563,20 +477,20 @@ int AnyServer::startupDaemon () { CheckPidFile(_pidFile); + _applicationServer->setupLogging(false, true); + string current; - int result = forkProcess(_workingDirectory, current, safe_cast(_applicationServer)); + int result = forkProcess(_workingDirectory, current); // main process if (result != 0) { -#ifdef TRI_HAVE_SYS_PRCTL_H - prctl(PR_SET_NAME, "arangodb [daemon]", 0, 0, 0); -#endif - + TRI_SetProcessTitle("arangodb [daemon]"); WritePidFile(_pidFile, result); } // child process else { + _applicationServer->setupLogging(true, false); // and startup server prepareServer(); @@ -609,5 +523,5 @@ int AnyServer::startupDaemon () { // Local Variables: // mode: outline-minor -// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" +// outline-regexp: "^/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}" // End: From b1bd5827ad245611c534e1f417dd1232e6aa05f3 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 15 Feb 2013 11:52:17 +0100 Subject: [PATCH 09/11] fixed issue #333: [debian] Group arangodb is not used when starting vie init.d script --- CHANGELOG | 2 ++ Installation/Linux/rc.arangod.Centos | 2 +- Installation/Linux/rc.arangod.Debian | 2 +- Installation/Linux/rc.arangod.OpenSuSE | 2 +- Installation/Linux/rc.arangod.Ubuntu | 2 +- etc/arangodb/arangod.conf.in | 2 ++ 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 94196f5524..bd66d96c9c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ v1.2.alpha (XXXX-XX-XX) ----------------------- +* fixed issue #333: [debian] Group "arangodb" is not used when starting vie init.d script + * added AQL functions KEEP() and UNSET() * fixed issue #348: "HTTP Interface for Administration and Monitoring" diff --git a/Installation/Linux/rc.arangod.Centos b/Installation/Linux/rc.arangod.Centos index c25b4132f3..eebe09dfab 100644 --- a/Installation/Linux/rc.arangod.Centos +++ b/Installation/Linux/rc.arangod.Centos @@ -29,7 +29,7 @@ start() { ARANGO_PIDDIR=`dirname $pidfile` test -d $ARANGO_PIDDIR || (mkdir $ARANGO_PIDDIR && chown arangodb $ARANGO_PIDDIR) - $ARANGO_BIN -c $ARANGO_SYSCONFIG --pid-file "$pidfile" --supervisor --uid arangodb $@ + $ARANGO_BIN -c $ARANGO_SYSCONFIG --pid-file "$pidfile" --supervisor --uid arangodb --gid arangodb $@ RETVAL=$? echo diff --git a/Installation/Linux/rc.arangod.Debian b/Installation/Linux/rc.arangod.Debian index b361af7f8f..db983e4441 100644 --- a/Installation/Linux/rc.arangod.Debian +++ b/Installation/Linux/rc.arangod.Debian @@ -33,7 +33,7 @@ start () { ARANGO_PIDDIR=`dirname $PIDFILE` test -d $ARANGO_PIDDIR || (mkdir $ARANGO_PIDDIR && chown arangodb $ARANGO_PIDDIR) - $DAEMON -c $CONF --pid-file "$PIDFILE" --supervisor --uid arangodb $@ + $DAEMON -c $CONF --pid-file "$PIDFILE" --supervisor --uid arangodb --gid arangodb $@ log_end_msg $? } diff --git a/Installation/Linux/rc.arangod.OpenSuSE b/Installation/Linux/rc.arangod.OpenSuSE index 6a8d5954c4..ab449102b2 100644 --- a/Installation/Linux/rc.arangod.OpenSuSE +++ b/Installation/Linux/rc.arangod.OpenSuSE @@ -47,7 +47,7 @@ start () { ARANGO_PIDDIR=`dirname $ARANGO_PIDFILE` test -d $ARANGO_PIDDIR || (mkdir $ARANGO_PIDDIR && chown arangodb $ARANGO_PIDDIR) - startproc $ARANGO_BIN -c $ARANGO_SYSCONFIG --pid-file "$ARANGO_PIDFILE" --supervisor --uid arangodb $@ + startproc $ARANGO_BIN -c $ARANGO_SYSCONFIG --pid-file "$ARANGO_PIDFILE" --supervisor --uid arangodb --gid arangodb $@ # Remember status and be verbose rc_status -v diff --git a/Installation/Linux/rc.arangod.Ubuntu b/Installation/Linux/rc.arangod.Ubuntu index e42243fb30..e64eea1d0f 100644 --- a/Installation/Linux/rc.arangod.Ubuntu +++ b/Installation/Linux/rc.arangod.Ubuntu @@ -27,7 +27,7 @@ start () { test -d $PIDDIR || mkdir $PIDDIR chown arangodb $PIDDIR - $DAEMON -c $CONF --pid-file "$PIDFILE" --supervisor --uid arangodb $@ + $DAEMON -c $CONF --pid-file "$PIDFILE" --supervisor --uid arangodb --gid arangodb $@ log_end_msg $? } diff --git a/etc/arangodb/arangod.conf.in b/etc/arangodb/arangod.conf.in index 681f7c7931..eb7b0543e4 100644 --- a/etc/arangodb/arangod.conf.in +++ b/etc/arangodb/arangod.conf.in @@ -31,6 +31,8 @@ disable-admin-interface = no disable-authentication = yes admin-directory= @PKGDATADIR@/html/admin threads = 5 +uid = arangodb +gid = arangodb [scheduler] threads = 3 From 7b92dcc9bc8b10fc27828f0102160672080b8d2a Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 15 Feb 2013 11:57:35 +0100 Subject: [PATCH 10/11] fixed issue #405: 1.2 compile warnings --- CHANGELOG | 2 ++ lib/BasicsC/logging.c | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cbe50c2c57..5861727488 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ v1.2.alpha (XXXX-XX-XX) ----------------------- +* fixed issue #405: 1.2 compile warnings + * fixed issue #333: [debian] Group "arangodb" is not used when starting vie init.d script * added optional parameter 'excludeSystem' to GET /_api/collection diff --git a/lib/BasicsC/logging.c b/lib/BasicsC/logging.c index 983833e429..da4a9c2180 100644 --- a/lib/BasicsC/logging.c +++ b/lib/BasicsC/logging.c @@ -531,6 +531,25 @@ static int GenerateMessage (char* buffer, return m + n; } +//////////////////////////////////////////////////////////////////////////////// +/// @brief write to stderr +//////////////////////////////////////////////////////////////////////////////// + +void writeStderr (char const* line, size_t len) { + ssize_t n; + + while (0 < len) { + n = TRI_WRITE(STDERR_FILENO, line, len); + + if (n <= 0) { + return; + } + + line += n; + len -= n; + } +} + //////////////////////////////////////////////////////////////////////////////// /// @brief outputs a message string to all appenders //////////////////////////////////////////////////////////////////////////////// @@ -541,8 +560,8 @@ static void OutputMessage (TRI_log_level_e level, size_t length, bool copy) { if (! LoggingActive) { - write(STDERR_FILENO, message, length); - write(STDERR_FILENO, "\n", 1); + writeStderr(message, length); + writeStderr("\n", 1); if (! copy) { TRI_FreeString(TRI_CORE_MEM_ZONE, message); @@ -558,8 +577,8 @@ static void OutputMessage (TRI_log_level_e level, TRI_LockSpin(&AppendersLock); if (Appenders._length == 0) { - write(STDERR_FILENO, message, length); - write(STDERR_FILENO, "\n", 1); + writeStderr(message, length); + writeStderr("\n", 1); if (! copy) { TRI_FreeString(TRI_CORE_MEM_ZONE, message); From 45c815b7eb59a1dd62e84debf8ea4faca98d5a90 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 15 Feb 2013 12:19:09 +0100 Subject: [PATCH 11/11] fixed issue #403: Usage of exit() etc. --- arangod/MRServer/ApplicationMR.cpp | 44 +++++++++------------ arangod/MRServer/mr-actions.cpp | 6 +-- arangod/RestServer/arango.cpp | 7 +++- arangod/V8Server/ApplicationV8.cpp | 3 +- arangod/VocBase/shape-collection.c | 3 +- arangoirb/MRClient/arangoirb.cpp | 20 +++++----- arangosh/ArangoShell/ArangoClient.cpp | 14 +++---- arangosh/Benchmark/arangob.cpp | 7 ++-- arangosh/V8Client/arangosh.cpp | 4 ++ lib/ApplicationServer/ApplicationServer.cpp | 4 +- lib/BasicsC/application-exit.c | 2 +- lib/BasicsC/error.c | 6 +-- lib/BasicsC/locks-win32.c | 33 ++++++---------- lib/BasicsC/memory.c | 4 +- lib/MRuby/MRLoader.cpp | 2 +- lib/Rest/AnyServer.cpp | 4 +- lib/Scheduler/ApplicationScheduler.cpp | 5 +-- 17 files changed, 73 insertions(+), 95 deletions(-) diff --git a/arangod/MRServer/ApplicationMR.cpp b/arangod/MRServer/ApplicationMR.cpp index 8fa170640a..cfb7c98a4d 100644 --- a/arangod/MRServer/ApplicationMR.cpp +++ b/arangod/MRServer/ApplicationMR.cpp @@ -183,11 +183,11 @@ ApplicationMR::MRContext* ApplicationMR::enterContext () { CONDITION_LOCKER(guard, _contextCondition); while (_freeContexts.empty()) { - LOGGER_DEBUG << "waiting for unused MRuby context"; + LOGGER_DEBUG("waiting for unused MRuby context"); guard.wait(); } - LOGGER_TRACE << "found unused MRuby context"; + LOGGER_TRACE("found unused MRuby context"); MRContext* context = _freeContexts.back(); _freeContexts.pop_back(); @@ -210,11 +210,11 @@ void ApplicationMR::exitContext (MRContext* context) { CONDITION_LOCKER(guard, _contextCondition); if (context->_lastGcStamp + _gcFrequency < lastGc) { - LOGGER_TRACE << "periodic gc interval reached"; + LOGGER_TRACE("periodic gc interval reached"); _dirtyContexts.push_back(context); } else if (context->_dirt >= _gcInterval) { - LOGGER_TRACE << "maximum number of requests reached"; + LOGGER_TRACE("maximum number of requests reached"); _dirtyContexts.push_back(context); } else { @@ -224,7 +224,7 @@ void ApplicationMR::exitContext (MRContext* context) { guard.broadcast(); } - LOGGER_TRACE << "returned dirty MR context"; + LOGGER_TRACE("returned dirty MR context"); } //////////////////////////////////////////////////////////////////////////////// @@ -270,7 +270,7 @@ void ApplicationMR::collectGarbage () { gc->updateGcStamp(lastGc); if (context != 0) { - LOGGER_TRACE << "collecting MR garbage"; + LOGGER_TRACE("collecting MR garbage"); mrb_garbage_collect(context->_mrb); @@ -333,35 +333,31 @@ bool ApplicationMR::prepare () { // check the startup modules if (_startupModules.empty()) { - LOGGER_FATAL << "no 'ruby.modules-path' has been supplied, giving up"; - TRI_FlushLogging(); - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("no 'ruby.modules-path' has been supplied, giving up"); } else { - LOGGER_INFO << "using Ruby modules path '" << _startupModules << "'"; + LOGGER_INFO("using Ruby modules path '" << _startupModules << "'"); } // set up the startup loader if (_startupPath.empty()) { - LOGGER_INFO << "using built-in Ruby startup files"; + LOGGER_INFO("using built-in Ruby startup files"); _startupLoader.defineScript("common/bootstrap/error.rb", MR_common_bootstrap_error); _startupLoader.defineScript("server/server.rb", MR_server_server); } else { - LOGGER_INFO << "using Ruby startup files at '" << _startupPath << "'"; + LOGGER_INFO("using Ruby startup files at '" << _startupPath << "'"); _startupLoader.setDirectory(_startupPath); } // set up action loader if (_actionPath.empty()) { - LOGGER_FATAL << "no 'ruby.modules-path' has been supplied, giving up"; - TRI_FlushLogging(); - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("no 'ruby.modules-path' has been supplied, giving up"); } else { - LOGGER_INFO << "using Ruby action files at '" << _actionPath << "'"; + LOGGER_INFO("using Ruby action files at '" << _actionPath << "'"); _actionLoader.setDirectory(_actionPath); } @@ -435,7 +431,7 @@ bool ApplicationMR::prepareMRInstance (size_t i) { "server/server.rb" }; - LOGGER_TRACE << "initialising MR context #" << i; + LOGGER_TRACE("initialising MR context #" << i); MRContext* context = _contexts[i] = new MRContext(); @@ -453,9 +449,7 @@ bool ApplicationMR::prepareMRInstance (size_t i) { bool ok = _startupLoader.loadScript(context->_mrb, files[i]); if (! ok) { - LOGGER_FATAL << "cannot load Ruby utilities from file '" << files[i] << "'"; - - return false; + LOGGER_FATAL_AND_EXIT("cannot load Ruby utilities from file '" << files[i] << "'"); } } @@ -464,16 +458,14 @@ bool ApplicationMR::prepareMRInstance (size_t i) { bool ok = _actionLoader.executeAllScripts(context->_mrb); if (! ok) { - LOGGER_FATAL << "cannot load Ruby actions from directory '" << _actionLoader.getDirectory() << "'"; - - return false; + LOGGER_FATAL_AND_EXIT("cannot load Ruby actions from directory '" << _actionLoader.getDirectory() << "'"); } } context->_lastGcStamp = TRI_microtime(); // and return from the context - LOGGER_TRACE << "initialised MR context #" << i; + LOGGER_TRACE("initialised MR context #" << i); _freeContexts.push_back(context); @@ -485,7 +477,7 @@ bool ApplicationMR::prepareMRInstance (size_t i) { //////////////////////////////////////////////////////////////////////////////// void ApplicationMR::shutdownMRInstance (size_t i) { - LOGGER_TRACE << "shutting down MR context #" << i; + LOGGER_TRACE("shutting down MR context #" << i); MRContext* context = _contexts[i]; mrb_state* mrb = context->_mrb; @@ -494,7 +486,7 @@ void ApplicationMR::shutdownMRInstance (size_t i) { MR_CloseShell(mrb); - LOGGER_TRACE << "closed MR context #" << i; + LOGGER_TRACE("closed MR context #" << i); } //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/MRServer/mr-actions.cpp b/arangod/MRServer/mr-actions.cpp index 4ef8665d7e..618a23fd51 100644 --- a/arangod/MRServer/mr-actions.cpp +++ b/arangod/MRServer/mr-actions.cpp @@ -138,7 +138,7 @@ class mr_action_t : public TRI_action_t { map< mrb_state*, mrb_value >::iterator i = _callbacks.find(mrb); if (i == _callbacks.end()) { - LOGGER_WARNING << "no callback function for Ruby action '" << _url.c_str() << "'"; + LOGGER_WARNING("no callback function for Ruby action '" << _url.c_str() << "'"); return new HttpResponse(HttpResponse::NOT_FOUND); } @@ -441,12 +441,12 @@ static mrb_value MR_Mount (mrb_state* mrb, mrb_value self) { return mrb_false_value(); } else { - LOGGER_ERROR << "cannot create callback for MRuby action"; + LOGGER_ERROR("cannot create callback for MRuby action"); return mrb_true_value(); } } else { - LOGGER_ERROR << "cannot define MRuby action"; + LOGGER_ERROR("cannot define MRuby action"); return mrb_false_value(); } } diff --git a/arangod/RestServer/arango.cpp b/arangod/RestServer/arango.cpp index eba033def8..f3a8c238ad 100755 --- a/arangod/RestServer/arango.cpp +++ b/arangod/RestServer/arango.cpp @@ -59,6 +59,7 @@ static void arangodExitFunction (int, void*); // ............................................................................. // Call this function to do various initialistions for windows only // ............................................................................. + void arangodEntryFunction() { int maxOpenFiles = 2048; // upper hard limit for windows int res = 0; @@ -71,16 +72,19 @@ void arangodEntryFunction() { //res = initialiseWindows(TRI_WIN_INITIAL_SET_DEBUG_FLAG, 0); res = initialiseWindows(TRI_WIN_INITIAL_SET_INVALID_HANLE_HANDLER, 0); + if (res != 0) { _exit(1); } res = initialiseWindows(TRI_WIN_INITIAL_SET_MAX_STD_IO,(const char*)(&maxOpenFiles)); + if (res != 0) { _exit(1); } res = initialiseWindows(TRI_WIN_INITIAL_WSASTARTUP_FUNCTION_CALL, 0); + if (res != 0) { _exit(1); } @@ -89,7 +93,7 @@ void arangodEntryFunction() { } -static void arangodExitFunction(int exitCode, void* data) { +static void arangodExitFunction (int exitCode, void* data) { int res = 0; // ........................................................................... // TODO: need a terminate function for windows to be called and cleanup @@ -104,6 +108,7 @@ static void arangodExitFunction(int exitCode, void* data) { _exit(exitCode); } + #else static void arangodEntryFunction() { diff --git a/arangod/V8Server/ApplicationV8.cpp b/arangod/V8Server/ApplicationV8.cpp index 5da7cbaf86..cde0bb233d 100644 --- a/arangod/V8Server/ApplicationV8.cpp +++ b/arangod/V8Server/ApplicationV8.cpp @@ -723,8 +723,7 @@ bool ApplicationV8::prepareV8Instance (const size_t i) { context->_isolate->Exit(); delete context->_locker; - TRI_ShutdownLogging(); - exit(EXIT_SUCCESS); + TRI_EXIT_FUNCTION(EXIT_SUCCESS, NULL); } // load all actions diff --git a/arangod/VocBase/shape-collection.c b/arangod/VocBase/shape-collection.c index cb354c01ef..850275d366 100644 --- a/arangod/VocBase/shape-collection.c +++ b/arangod/VocBase/shape-collection.c @@ -111,9 +111,8 @@ static bool CreateJournal (TRI_shape_collection_t* collection) { ok = TRI_RenameDatafile(journal, filename); if (! ok) { - LOG_WARNING("failed to rename the journal to '%s': %s", filename, TRI_last_error()); // TODO: remove disastrous call to exit() here - exit(1); + LOG_FATAL_AND_EXIT("failed to rename the journal to '%s': %s", filename, TRI_last_error()); } else { LOG_TRACE("renamed journal to '%s'", filename); diff --git a/arangoirb/MRClient/arangoirb.cpp b/arangoirb/MRClient/arangoirb.cpp index 656529828f..873299ba2e 100644 --- a/arangoirb/MRClient/arangoirb.cpp +++ b/arangoirb/MRClient/arangoirb.cpp @@ -45,6 +45,7 @@ #include "BasicsC/files.h" #include "BasicsC/init.h" #include "BasicsC/logging.h" +#include "BasicsC/shell-colors.h" #include "BasicsC/strings.h" #include "BasicsC/terminal-utils.h" #include "Logger/Logger.h" @@ -206,8 +207,7 @@ static void ParseProgramOptions (int argc, char* argv[]) { // check module path if (StartupModules.empty()) { - LOGGER_FATAL << "module path not known, please use '--ruby.modules-path'"; - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("module path not known, please use '--ruby.modules-path'"); } } @@ -350,8 +350,7 @@ int main (int argc, char* argv[]) { BaseClient.createEndpoint(); if (BaseClient.endpointServer() == 0) { - cerr << "invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')" << endl; - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')"); } ClientConnection = createConnection(mrb); @@ -364,9 +363,9 @@ int main (int argc, char* argv[]) { // http://www.network-science.de/ascii/ Font: ogre if (! BaseClient.quiet()) { - char const* g = ArangoClient::COLOR_GREEN; - char const* r = ArangoClient::COLOR_RED; - char const* z = ArangoClient::COLOR_RESET; + char const* g = TRI_SHELL_COLOR_GREEN; + char const* r = TRI_SHELL_COLOR_RED; + char const* z = TRI_SHELL_COLOR_RESET; if (! BaseClient.colors()) { g = ""; @@ -418,7 +417,7 @@ int main (int argc, char* argv[]) { StartupLoader.defineScript("common/bootstrap/error.rb", MR_common_bootstrap_error); } else { - LOGGER_DEBUG << "using Ruby startup files at '" << StartupPath << "'"; + LOGGER_DEBUG("using Ruby startup files at '" << StartupPath << "'"); StartupLoader.setDirectory(StartupPath); } @@ -431,11 +430,10 @@ int main (int argc, char* argv[]) { bool ok = StartupLoader.loadScript(mrb, files[i]); if (ok) { - LOGGER_TRACE << "loaded ruby file '" << files[i] << "'"; + LOGGER_TRACE("loaded ruby file '" << files[i] << "'"); } else { - LOGGER_ERROR << "cannot load ruby file '" << files[i] << "'"; - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("cannot load ruby file '" << files[i] << "'"); } } diff --git a/arangosh/ArangoShell/ArangoClient.cpp b/arangosh/ArangoShell/ArangoClient.cpp index a3c8401410..79ba7c951f 100755 --- a/arangosh/ArangoShell/ArangoClient.cpp +++ b/arangosh/ArangoShell/ArangoClient.cpp @@ -268,8 +268,7 @@ void ArangoClient::parse (ProgramOptions& options, char* argv[], string const& initFilename) { if (! options.parse(description, argc, argv)) { - cerr << options.lastError() << "\n"; - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT(options.lastError()); } // check for help @@ -277,7 +276,7 @@ void ArangoClient::parse (ProgramOptions& options, if (! help.empty()) { cout << description.usage(help) << endl; - exit(EXIT_SUCCESS); + TRI_EXIT_FUNCTION(EXIT_SUCCESS, NULL); } // setup the logging @@ -381,19 +380,16 @@ void ArangoClient::parse (ProgramOptions& options, // check connection args if (_connectTimeout <= 0) { - cerr << "invalid value for --server.connect-timeout, must be positive" << endl; - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("invalid value for --server.connect-timeout, must be positive"); } if (_requestTimeout <= 0) { - cerr << "invalid value for --server.request-timeout, must be positive" << endl; - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("invalid value for --server.request-timeout, must be positive"); } // must specify a user name if (_username.size() == 0) { - cerr << "no value specified for --server.username" << endl; - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("no value specified for --server.username"); } // no password given on command-line diff --git a/arangosh/Benchmark/arangob.cpp b/arangosh/Benchmark/arangob.cpp index 9aeb8d021d..cba1d4b103 100644 --- a/arangosh/Benchmark/arangob.cpp +++ b/arangosh/Benchmark/arangob.cpp @@ -454,8 +454,7 @@ int main (int argc, char* argv[]) { BaseClient.createEndpoint(); if (BaseClient.endpointServer() == 0) { - cerr << "invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')" << endl; - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')"); } BenchmarkOperation* testCase; @@ -470,8 +469,8 @@ int main (int argc, char* argv[]) { testCase = new CollectionCreationTest(); } else { - cerr << "invalid test case name " << TestCase << endl; - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("invalid test case name " << TestCase); + return EXIT_FAILURE; // will not be reached } Status("starting threads..."); diff --git a/arangosh/V8Client/arangosh.cpp b/arangosh/V8Client/arangosh.cpp index c3421dfea8..89da28995f 100755 --- a/arangosh/V8Client/arangosh.cpp +++ b/arangosh/V8Client/arangosh.cpp @@ -1145,6 +1145,7 @@ static void arangoshExitFunction (int, void*); // ............................................................................. // Call this function to do various initialistions for windows only // ............................................................................. + void arangoshEntryFunction() { int maxOpenFiles = 1024; int res = 0; @@ -1157,16 +1158,19 @@ void arangoshEntryFunction() { //res = initialiseWindows(TRI_WIN_INITIAL_SET_DEBUG_FLAG, 0); res = initialiseWindows(TRI_WIN_INITIAL_SET_INVALID_HANLE_HANDLER, 0); + if (res != 0) { _exit(1); } res = initialiseWindows(TRI_WIN_INITIAL_SET_MAX_STD_IO,(const char*)(&maxOpenFiles)); + if (res != 0) { _exit(1); } res = initialiseWindows(TRI_WIN_INITIAL_WSASTARTUP_FUNCTION_CALL, 0); + if (res != 0) { _exit(1); } diff --git a/lib/ApplicationServer/ApplicationServer.cpp b/lib/ApplicationServer/ApplicationServer.cpp index 1ef5e03b82..05e97c120e 100644 --- a/lib/ApplicationServer/ApplicationServer.cpp +++ b/lib/ApplicationServer/ApplicationServer.cpp @@ -382,13 +382,13 @@ bool ApplicationServer::parse (int argc, if (! help.empty()) { cout << argv[0] << " " << _title << "\n\n" << _description.usage(help) << endl; - exit(EXIT_SUCCESS); + TRI_EXIT_FUNCTION(EXIT_SUCCESS, NULL); } // check for version request if (_options.has("version")) { cout << _version << endl; - exit(EXIT_SUCCESS); + TRI_EXIT_FUNCTION(EXIT_SUCCESS, NULL); } // ............................................................................. diff --git a/lib/BasicsC/application-exit.c b/lib/BasicsC/application-exit.c index 96a79ef48c..399d600bc2 100644 --- a/lib/BasicsC/application-exit.c +++ b/lib/BasicsC/application-exit.c @@ -45,7 +45,7 @@ void defaultExitFunction (int exitCode, void* data) { _exit(exitCode); } -void TRI_Application_Exit_SetExit(TRI_ExitFunction_t exitFunction) { +void TRI_Application_Exit_SetExit (TRI_ExitFunction_t exitFunction) { if (exitFunction != NULL) { TRI_EXIT_FUNCTION = exitFunction; } diff --git a/lib/BasicsC/error.c b/lib/BasicsC/error.c index 26f2777e18..e188b18593 100644 --- a/lib/BasicsC/error.c +++ b/lib/BasicsC/error.c @@ -297,10 +297,8 @@ void TRI_set_errno_string (int error, char const* msg) { // logic error, error number is redeclared printf("Error: duplicate declaration of error code %i in %s:%i\n", - error, - __FILE__, - __LINE__); - exit(EXIT_FAILURE); + error, __FILE__, __LINE__); + TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL); } entry = (TRI_error_t*) TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_error_t), false); diff --git a/lib/BasicsC/locks-win32.c b/lib/BasicsC/locks-win32.c index e0b249d279..4ac0b7b60d 100644 --- a/lib/BasicsC/locks-win32.c +++ b/lib/BasicsC/locks-win32.c @@ -50,8 +50,7 @@ void TRI_InitMutex (TRI_mutex_t* mutex) { mutex->_mutex = CreateMutex(NULL, FALSE, NULL); if (mutex->_mutex == NULL) { - LOG_FATAL("cannot create the mutex"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("cannot create the mutex"); } } @@ -84,8 +83,7 @@ void TRI_LockMutex (TRI_mutex_t* mutex) { DWORD result = WaitForSingleObject(mutex->_mutex, INFINITE); if (result != WAIT_OBJECT_0) { - LOG_FATAL("could not lock the mutex"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("could not lock the mutex"); } } @@ -97,8 +95,7 @@ void TRI_UnlockMutex (TRI_mutex_t* mutex) { BOOL ok = ReleaseMutex(mutex->_mutex); if (! ok) { - LOG_FATAL("could not unlock the mutex"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("could not unlock the mutex"); } } @@ -292,8 +289,7 @@ static void DecrementReaders (TRI_read_write_lock_t* lock) { SetEvent(lock->_readersEvent); } else if (lock->_readers < 0) { - LOG_FATAL("reader count is negative"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("reader count is negative"); } } @@ -385,8 +381,7 @@ void TRI_ReadUnlockReadWriteLock (TRI_read_write_lock_t* lock) { /* this is wrong since it is possible for the write locker to block this event // a write lock eists if (WaitForSingleObject(lock->_writerEvent, 0) != WAIT_OBJECT_0) { - LOG_FATAL("write lock, but trying to unlock read"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("write lock, but trying to unlock read"); } // at least one reader exists @@ -397,8 +392,7 @@ void TRI_ReadUnlockReadWriteLock (TRI_read_write_lock_t* lock) { // ups, no writer and no reader else { LeaveCriticalSection(&lock->_lockReaders); - LOG_FATAL("no reader and no writer, but trying to unlock"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("no reader and no writer, but trying to unlock"); } */ @@ -409,8 +403,7 @@ void TRI_ReadUnlockReadWriteLock (TRI_read_write_lock_t* lock) { // oops no reader else { LeaveCriticalSection(&lock->_lockReaders); - LOG_FATAL("no reader, but trying to unlock read lock"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("no reader, but trying to unlock read lock"); } LeaveCriticalSection(&lock->_lockReaders); @@ -555,8 +548,7 @@ void TRI_WriteUnlockReadWriteLock (TRI_read_write_lock_t* lock) { else if (0 < lock->_readers) { LeaveCriticalSection(&lock->_lockReaders); - LOG_FATAL("read lock, but trying to unlock write"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("read lock, but trying to unlock write"); } @@ -567,8 +559,7 @@ void TRI_WriteUnlockReadWriteLock (TRI_read_write_lock_t* lock) { else { LeaveCriticalSection(&lock->_lockReaders); - LOG_FATAL("no reader and no writer, but trying to unlock"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("no reader and no writer, but trying to unlock"); } @@ -855,8 +846,7 @@ void TRI_LockCondition (TRI_condition_t* cond) { DWORD result = WaitForSingleObject(cond->_mutex, INFINITE); if (result != WAIT_OBJECT_0) { - LOG_FATAL("could not lock the mutex"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("could not lock the mutex"); } } @@ -868,8 +858,7 @@ void TRI_UnlockCondition (TRI_condition_t* cond) { BOOL ok = ReleaseMutex(cond->_mutex); if (! ok) { - LOG_FATAL("could not unlock the mutex"); - exit(EXIT_FAILURE); + LOG_FATAL_AND_EXIT("could not unlock the mutex"); } } diff --git a/lib/BasicsC/memory.c b/lib/BasicsC/memory.c index e4ac98e89b..e400300090 100644 --- a/lib/BasicsC/memory.c +++ b/lib/BasicsC/memory.c @@ -204,7 +204,7 @@ void* TRI_Allocate (TRI_memory_zone_t* zone, uint64_t n, bool set) { (unsigned long long) n, (int) zone->_zid ZONE_DEBUG_PARAMS); - exit(EXIT_FAILURE); + TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL); } free(CoreReserve); @@ -292,7 +292,7 @@ void* TRI_Reallocate (TRI_memory_zone_t* zone, void* m, uint64_t n) { (unsigned long long) n, zone->_zid ZONE_DEBUG_PARAMS); - exit(EXIT_FAILURE); + TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL); } free(CoreReserve); diff --git a/lib/MRuby/MRLoader.cpp b/lib/MRuby/MRLoader.cpp index dee6d85994..28884bd191 100644 --- a/lib/MRuby/MRLoader.cpp +++ b/lib/MRuby/MRLoader.cpp @@ -77,7 +77,7 @@ bool MRLoader::loadScript (mrb_state* mrb, string const& name) { map::iterator i = _scripts.find(name); if (i == _scripts.end()) { - LOGGER_ERROR << "unknown script '" << name << "'"; + LOGGER_ERROR("unknown script '" << name << "'"); return false; } diff --git a/lib/Rest/AnyServer.cpp b/lib/Rest/AnyServer.cpp index 658b639e0b..2de5d5a13c 100644 --- a/lib/Rest/AnyServer.cpp +++ b/lib/Rest/AnyServer.cpp @@ -364,7 +364,7 @@ int AnyServer::startupSupervisor () { TRI_pid_t pid = fork(); if (pid < 0) { - exit(EXIT_FAILURE); + TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL); } // parent @@ -460,7 +460,7 @@ int AnyServer::startupSupervisor () { } // and stop - exit(result); + TRI_EXIT_FUNCTION(result, NULL); } } } diff --git a/lib/Scheduler/ApplicationScheduler.cpp b/lib/Scheduler/ApplicationScheduler.cpp index ef14e6abb8..c5af6b4e98 100644 --- a/lib/Scheduler/ApplicationScheduler.cpp +++ b/lib/Scheduler/ApplicationScheduler.cpp @@ -113,8 +113,7 @@ static SignalTask* localSignalTask; _server->beginShutdown(); } else { - LOGGER_INFO("control-c received, terminating"); - exit(EXIT_FAILURE); + LOGGER_FATAL_AND_EXIT("control-c received again, terminating"); } ++_seen; @@ -440,7 +439,7 @@ bool ApplicationScheduler::parsePhase1 (triagens::basics::ProgramOptions& option // show io backends if (options.has("show-io-backends")) { cout << "available io backends are: " << SchedulerLibev::availableBackends() << endl; - exit(EXIT_SUCCESS); + TRI_EXIT_FUNCTION(EXIT_SUCCESS, NULL); } return true;