From 4de5e41044dff3da3efb2bc6103d0eb5c9cc6a8e Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 4 Mar 2016 17:48:27 +0100 Subject: [PATCH] simplifications --- arangod/CMakeLists.txt | 1 - arangod/Cluster/ClusterInfo.cpp | 4 +- .../RestHandler/RestVocbaseBaseHandler.cpp | 21 ++- arangod/RestHandler/RestVocbaseBaseHandler.h | 9 +- arangod/RestServer/VocbaseContext.h | 1 - arangod/Utils/CollectionKeys.cpp | 1 - arangod/Utils/DocumentHelper.cpp | 120 ------------------ arangod/Utils/DocumentHelper.h | 77 ----------- arangod/Utils/Transaction.h | 6 - arangod/V8Server/v8-util.cpp | 1 - arangod/VocBase/DatafileHelper.h | 7 + arangod/VocBase/document-collection.h | 8 +- arangod/VocBase/transaction.h | 1 - arangod/VocBase/voc-types.h | 1 - 14 files changed, 37 insertions(+), 221 deletions(-) delete mode 100644 arangod/Utils/DocumentHelper.cpp delete mode 100644 arangod/Utils/DocumentHelper.h diff --git a/arangod/CMakeLists.txt b/arangod/CMakeLists.txt index e3a7d6479c..667ba2642c 100644 --- a/arangod/CMakeLists.txt +++ b/arangod/CMakeLists.txt @@ -222,7 +222,6 @@ add_executable(${BIN_ARANGOD} Utils/CollectionKeysRepository.cpp Utils/Cursor.cpp Utils/CursorRepository.cpp - Utils/DocumentHelper.cpp Utils/OperationCursor.cpp Utils/ShapedJsonTransformer.cpp Utils/StandaloneTransactionContext.cpp diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 9712807195..1daf30b8ac 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -22,8 +22,7 @@ /// @author Jan Steemann //////////////////////////////////////////////////////////////////////////////// -#include "Cluster/ClusterInfo.h" - +#include "ClusterInfo.h" #include "Basics/json.h" #include "Basics/Logger.h" #include "Basics/json-utilities.h" @@ -33,6 +32,7 @@ #include "Basics/StringUtils.h" #include "Basics/VelocyPackHelper.h" #include "Basics/WriteLocker.h" +#include "Cluster/ServerState.h" #include "VocBase/document-collection.h" #include diff --git a/arangod/RestHandler/RestVocbaseBaseHandler.cpp b/arangod/RestHandler/RestVocbaseBaseHandler.cpp index f0d47c2963..ed5c581292 100644 --- a/arangod/RestHandler/RestVocbaseBaseHandler.cpp +++ b/arangod/RestHandler/RestVocbaseBaseHandler.cpp @@ -23,13 +23,12 @@ #include "RestVocbaseBaseHandler.h" #include "Basics/conversions.h" -#include "Basics/StringUtils.h" #include "Basics/StringBuffer.h" +#include "Basics/StringUtils.h" #include "Basics/tri-strings.h" #include "Basics/VelocyPackHelper.h" #include "Basics/VPackStringBufferAdapter.h" #include "Rest/HttpRequest.h" -#include "Utils/DocumentHelper.h" #include "VocBase/document-collection.h" #include @@ -127,6 +126,20 @@ RestVocbaseBaseHandler::RestVocbaseBaseHandler(HttpRequest* request) RestVocbaseBaseHandler::~RestVocbaseBaseHandler() {} +//////////////////////////////////////////////////////////////////////////////// +/// @brief assemble a document id from a string and a string +/// optionally url-encodes +//////////////////////////////////////////////////////////////////////////////// + +std::string RestVocbaseBaseHandler::assembleDocumentId( + std::string const& collectionName, std::string const& key, bool urlEncode) { + if (urlEncode) { + return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + + StringUtils::urlEncode(key); + } + return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + key; +} + //////////////////////////////////////////////////////////////////////////////// /// @brief Generate a result for successful save //////////////////////////////////////////////////////////////////////////////// @@ -215,7 +228,7 @@ void RestVocbaseBaseHandler::generate20x( if (slice.isObject()) { _response->setHeader("etag", 4, "\"" + slice.get(TRI_VOC_ATTRIBUTE_REV).copyString() + "\""); // pre 1.4 location headers withdrawn for >= 3.0 - std::string escapedHandle(DocumentHelper::assembleDocumentId( + std::string escapedHandle(assembleDocumentId( collectionName, slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString(), true)); if (type == TRI_COL_TYPE_EDGE) { _response->setHeader("location", 8, @@ -305,7 +318,7 @@ void RestVocbaseBaseHandler::generatePreconditionFailed( VPackBuilder builder; builder.openObject(); - builder.add(TRI_VOC_ATTRIBUTE_ID, VPackValue(DocumentHelper::assembleDocumentId(collectionName, key))); + builder.add(TRI_VOC_ATTRIBUTE_ID, VPackValue(assembleDocumentId(collectionName, key, false))); builder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(std::to_string(rev))); builder.add(TRI_VOC_ATTRIBUTE_REV, VPackValue(key)); builder.close(); diff --git a/arangod/RestHandler/RestVocbaseBaseHandler.h b/arangod/RestHandler/RestVocbaseBaseHandler.h index 3ff9fe6a58..3081b0bdbd 100644 --- a/arangod/RestHandler/RestVocbaseBaseHandler.h +++ b/arangod/RestHandler/RestVocbaseBaseHandler.h @@ -28,7 +28,6 @@ #include "Rest/HttpResponse.h" #include "RestHandler/RestBaseHandler.h" #include "RestServer/VocbaseContext.h" -#include "Utils/SingleCollectionTransaction.h" #include "Utils/transactions.h" struct TRI_vocbase_t; @@ -125,6 +124,14 @@ class RestVocbaseBaseHandler : public RestBaseHandler { ~RestVocbaseBaseHandler(); protected: + + ////////////////////////////////////////////////////////////////////////////// + /// @brief assemble a document id from a string and a string + /// optionally url-encodes + ////////////////////////////////////////////////////////////////////////////// + + std::string assembleDocumentId(std::string const&, std::string const&, bool); + ////////////////////////////////////////////////////////////////////////////// /// @brief check if a collection needs to be created on the fly /// diff --git a/arangod/RestServer/VocbaseContext.h b/arangod/RestServer/VocbaseContext.h index 64ba0ed38c..2072c6759d 100644 --- a/arangod/RestServer/VocbaseContext.h +++ b/arangod/RestServer/VocbaseContext.h @@ -25,7 +25,6 @@ #define ARANGOD_REST_SERVER_VOCBASE_CONTEXT_H 1 #include "Basics/Common.h" - #include "Rest/HttpRequest.h" #include "Rest/HttpResponse.h" #include "Rest/RequestContext.h" diff --git a/arangod/Utils/CollectionKeys.cpp b/arangod/Utils/CollectionKeys.cpp index 19e57ad0c7..1cd6ff9723 100644 --- a/arangod/Utils/CollectionKeys.cpp +++ b/arangod/Utils/CollectionKeys.cpp @@ -23,7 +23,6 @@ #include "CollectionKeys.h" #include "Utils/CollectionGuard.h" -#include "Utils/DocumentHelper.h" #include "Utils/transactions.h" #include "VocBase/compactor.h" #include "VocBase/DatafileHelper.h" diff --git a/arangod/Utils/DocumentHelper.cpp b/arangod/Utils/DocumentHelper.cpp deleted file mode 100644 index ee74fdbf2f..0000000000 --- a/arangod/Utils/DocumentHelper.cpp +++ /dev/null @@ -1,120 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// DISCLAIMER -/// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Jan Steemann -//////////////////////////////////////////////////////////////////////////////// - -#include "DocumentHelper.h" -#include "Basics/json.h" -#include "Basics/StringUtils.h" -#include "VocBase/vocbase.h" - -using namespace arangodb; -using namespace arangodb::basics; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief assemble a document id from a string and a string -//////////////////////////////////////////////////////////////////////////////// - -std::string DocumentHelper::assembleDocumentId( - std::string const& collectionName, std::string const& key, bool urlEncode) { - if (urlEncode) { - return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + - StringUtils::urlEncode(key); - } - return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + key; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief assemble a document id from a string and a char* key -//////////////////////////////////////////////////////////////////////////////// - -std::string DocumentHelper::assembleDocumentId( - std::string const& collectionName, const TRI_voc_key_t key, - bool urlEncode) { - if (key == nullptr) { - return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + "_unknown"; - } - - if (urlEncode) { - return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + - StringUtils::urlEncode(key); - } - - return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + key; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief extract the collection id and document key from an id -//////////////////////////////////////////////////////////////////////////////// - -bool DocumentHelper::parseDocumentId(CollectionNameResolver const& resolver, - char const* input, TRI_voc_cid_t& cid, - char** key) { - if (input == nullptr) { - return false; - } - - char const* pos = strchr(input, TRI_DOCUMENT_HANDLE_SEPARATOR_CHR); - - if (pos == nullptr) { - return false; - } - - cid = resolver.getCollectionIdCluster(std::string(input, pos - input)); - *key = (char*)(pos + 1); - - if (cid == 0 || **key == '\0') { - // unknown collection or empty key - return false; - } - - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief extract the "_key" attribute from a JSON object -//////////////////////////////////////////////////////////////////////////////// - -int DocumentHelper::getKey(TRI_json_t const* json, TRI_voc_key_t* key) { - *key = 0; - - // check type of json - if (!TRI_IsObjectJson(json)) { - return TRI_ERROR_NO_ERROR; - } - - // check if _key is there - TRI_json_t const* k = TRI_LookupObjectJson(json, TRI_VOC_ATTRIBUTE_KEY); - - if (k == nullptr) { - return TRI_ERROR_NO_ERROR; - } - - if (!TRI_IsStringJson(k)) { - // _key is there but not a string - return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD; - } - - // _key is there and a string - *key = k->_value._string.data; - - return TRI_ERROR_NO_ERROR; -} diff --git a/arangod/Utils/DocumentHelper.h b/arangod/Utils/DocumentHelper.h deleted file mode 100644 index a1f6b8eab2..0000000000 --- a/arangod/Utils/DocumentHelper.h +++ /dev/null @@ -1,77 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// DISCLAIMER -/// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Jan Steemann -//////////////////////////////////////////////////////////////////////////////// - -#ifndef ARANGOD_UTILS_DOCUMENT_HELPER_H -#define ARANGOD_UTILS_DOCUMENT_HELPER_H 1 - -#include "Basics/Common.h" -#include "Utils/CollectionNameResolver.h" -#include "VocBase/voc-types.h" - -struct TRI_json_t; - -namespace arangodb { - -class DocumentHelper { - private: - DocumentHelper() = delete; - - ~DocumentHelper() = delete; - - public: - - ////////////////////////////////////////////////////////////////////////////// - /// @brief assemble a document id from a string and a string - /// TODO: remove - ////////////////////////////////////////////////////////////////////////////// - - static std::string assembleDocumentId(std::string const&, - std::string const& key, - bool urlEncode = false); - - ////////////////////////////////////////////////////////////////////////////// - /// @brief assemble a document id from a string and a char* key - /// TODO: remove - ////////////////////////////////////////////////////////////////////////////// - - static std::string assembleDocumentId(std::string const&, const TRI_voc_key_t, - bool urlEncode = false); - - ////////////////////////////////////////////////////////////////////////////// - /// @brief extract the collection id and document key from an id - /// TODO: remove - ////////////////////////////////////////////////////////////////////////////// - - static bool parseDocumentId(arangodb::CollectionNameResolver const&, - char const*, TRI_voc_cid_t&, char**); - - ////////////////////////////////////////////////////////////////////////////// - /// @brief extract the "_key" attribute from a JSON object - /// TODO: remove - ////////////////////////////////////////////////////////////////////////////// - - static int getKey(struct TRI_json_t const*, TRI_voc_key_t*); -}; -} - -#endif diff --git a/arangod/Utils/Transaction.h b/arangod/Utils/Transaction.h index 099f5a576a..425bf6b904 100644 --- a/arangod/Utils/Transaction.h +++ b/arangod/Utils/Transaction.h @@ -25,14 +25,8 @@ #define ARANGOD_UTILS_TRANSACTION_H 1 #include "Basics/Common.h" -//#include "Basics/tri-strings.h" -//#include "Basics/VelocyPackHelper.h" -//#include "Utils/CollectionNameResolver.h" #include "Utils/OperationOptions.h" #include "Utils/OperationResult.h" -//#include "Utils/TransactionContext.h" -//#include "VocBase/collection.h" -//#include "VocBase/document-collection.h" #include "VocBase/transaction.h" #include "VocBase/vocbase.h" #include "VocBase/voc-types.h" diff --git a/arangod/V8Server/v8-util.cpp b/arangod/V8Server/v8-util.cpp index 8bd0401fc4..bf514d8b9b 100644 --- a/arangod/V8Server/v8-util.cpp +++ b/arangod/V8Server/v8-util.cpp @@ -25,7 +25,6 @@ #include "Basics/conversions.h" #include "VocBase/KeyGenerator.h" #include "V8/v8-conv.h" -#include "Utils/DocumentHelper.h" using namespace arangodb; using namespace arangodb::basics; diff --git a/arangod/VocBase/DatafileHelper.h b/arangod/VocBase/DatafileHelper.h index d280842c39..ab6a6d7cfd 100644 --- a/arangod/VocBase/DatafileHelper.h +++ b/arangod/VocBase/DatafileHelper.h @@ -30,6 +30,13 @@ namespace arangodb { namespace DatafileHelper { +//////////////////////////////////////////////////////////////////////////////// +/// @brief bit mask for datafile ids (fids) that indicates whether a file is +/// a WAL file (bit set) or a datafile (bit not set) +//////////////////////////////////////////////////////////////////////////////// + +constexpr uint64_t WalFileBitmask() { return 0x8000000000000000ULL; } + //////////////////////////////////////////////////////////////////////////////// /// @brief maximal size of a marker //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/VocBase/document-collection.h b/arangod/VocBase/document-collection.h index 98d6c294c1..6c87094c75 100644 --- a/arangod/VocBase/document-collection.h +++ b/arangod/VocBase/document-collection.h @@ -55,8 +55,6 @@ class Slice; } } -#define TRI_WAL_FILE_BITMASK 0x8000000000000000ULL - //////////////////////////////////////////////////////////////////////////////// /// @brief master pointer //////////////////////////////////////////////////////////////////////////////// @@ -105,7 +103,7 @@ struct TRI_doc_mptr_t { // return the datafile id. inline TRI_voc_fid_t getFid() const { // unmask the WAL bit - return (_fid & ~TRI_WAL_FILE_BITMASK); + return (_fid & ~arangodb::DatafileHelper::WalFileBitmask()); } // sets datafile id. note that the highest bit of the file id must @@ -117,7 +115,7 @@ struct TRI_doc_mptr_t { // set the WAL bit if required _fid = fid; if (isWal) { - _fid |= TRI_WAL_FILE_BITMASK; + _fid |= arangodb::DatafileHelper::WalFileBitmask(); } } @@ -142,7 +140,7 @@ struct TRI_doc_mptr_t { // the _fid value is set, and to a datafile otherwise inline bool pointsToWal() const { // check whether the WAL bit is set - return ((_fid & TRI_WAL_FILE_BITMASK) == 1); + return ((_fid & arangodb::DatafileHelper::WalFileBitmask()) == 1); } // return the marker's revision id diff --git a/arangod/VocBase/transaction.h b/arangod/VocBase/transaction.h index 11ea3e74ea..5633ada521 100644 --- a/arangod/VocBase/transaction.h +++ b/arangod/VocBase/transaction.h @@ -26,7 +26,6 @@ #include "Basics/Common.h" #include "Basics/vector.h" -//#include "VocBase/datafile.h" #include "VocBase/voc-types.h" namespace arangodb { diff --git a/arangod/VocBase/voc-types.h b/arangod/VocBase/voc-types.h index 4256c7c7e9..9bf141e3be 100644 --- a/arangod/VocBase/voc-types.h +++ b/arangod/VocBase/voc-types.h @@ -25,7 +25,6 @@ #define ARANGOD_VOC_BASE_VOC_TYPES_H 1 #include "Basics/Common.h" -#include "Cluster/ServerState.h" #include #include