From a976f1b2b9da66b0f1a1cd0e7b29b39380ea0c8f Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 5 Dec 2013 14:28:52 +0100 Subject: [PATCH] added stubs for communication layer --- arangod/Makefile.files | 2 + arangod/Sharding/AgencyComm.cpp | 188 +++++++++++++++++++++++++++ arangod/Sharding/AgencyComm.h | 83 +++++++++++- arangod/Sharding/HeartbeatThread.cpp | 86 ++++++++++++ arangod/Sharding/HeartbeatThread.h | 111 ++++++++++++++++ 5 files changed, 465 insertions(+), 5 deletions(-) create mode 100644 arangod/Sharding/AgencyComm.cpp create mode 100644 arangod/Sharding/HeartbeatThread.cpp create mode 100644 arangod/Sharding/HeartbeatThread.h diff --git a/arangod/Makefile.files b/arangod/Makefile.files index 17ca804d8c..e11a56a344 100644 --- a/arangod/Makefile.files +++ b/arangod/Makefile.files @@ -74,7 +74,9 @@ bin_arangod_SOURCES = \ arangod/RestServer/ArangoServer.cpp \ arangod/RestServer/VocbaseContext.cpp \ arangod/RestServer/arango.cpp \ + arangod/Sharding/AgencyComm.cpp \ arangod/Sharding/server-state.cpp \ + arangod/Sharding/HeartbeatThread.cpp \ arangod/SkipLists/skiplistIndex.c \ arangod/Utils/DocumentHelper.cpp \ arangod/V8Server/ApplicationV8.cpp \ diff --git a/arangod/Sharding/AgencyComm.cpp b/arangod/Sharding/AgencyComm.cpp new file mode 100644 index 0000000000..8f332a2ff8 --- /dev/null +++ b/arangod/Sharding/AgencyComm.cpp @@ -0,0 +1,188 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief communication with agency node(s) +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2012 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 triAGENS GmbH, Cologne, Germany +/// +/// @author Jan Steemann +/// @author Copyright 2013, triagens GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#include "Sharding/AgencyComm.h" +#include "BasicsC/logging.h" + +//using namespace triagens::basics; +using namespace triagens::arango; + +// ----------------------------------------------------------------------------- +// --SECTION-- Agent +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// --SECTION-- constructors and destructors +// ----------------------------------------------------------------------------- + +Agent::Agent () { +} + +Agent::~Agent () { +} + +// ----------------------------------------------------------------------------- +// --SECTION-- AgencyCommResult +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// --SECTION-- constructors and destructors +// ----------------------------------------------------------------------------- + +AgencyCommResult::AgencyCommResult () { +} + +AgencyCommResult::~AgencyCommResult () { +} + +// ----------------------------------------------------------------------------- +// --SECTION-- AgencyComm +// ----------------------------------------------------------------------------- + +std::string AgencyComm::_prefix; + +// ----------------------------------------------------------------------------- +// --SECTION-- constructors and destructors +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief constructs an agency communication object +//////////////////////////////////////////////////////////////////////////////// + +AgencyComm::AgencyComm () { +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief destroys an agency communication object +//////////////////////////////////////////////////////////////////////////////// + +AgencyComm::~AgencyComm () { +} + +// ----------------------------------------------------------------------------- +// --SECTION-- public static methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief sets the global prefix for all operations +//////////////////////////////////////////////////////////////////////////////// + +void AgencyComm::setPrefix (std::string const& prefix) { + _prefix = prefix; +} + +// ----------------------------------------------------------------------------- +// --SECTION-- public methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief establishes the communication channels +//////////////////////////////////////////////////////////////////////////////// + +int AgencyComm::connect () { + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief disconnects all communication channels +//////////////////////////////////////////////////////////////////////////////// + +int AgencyComm::disconnect () { + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief adds an agent to the agents list +//////////////////////////////////////////////////////////////////////////////// + +int AgencyComm::addAgent (Agent agent) { + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief removes an agent from the agents list +//////////////////////////////////////////////////////////////////////////////// + +int AgencyComm::removeAgent (Agent agent) { + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief removes an agent from the agents list +//////////////////////////////////////////////////////////////////////////////// + +int AgencyComm::setValue (std::string const& key, + std::string const& value) { + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief gets one or multiple values from the back end +//////////////////////////////////////////////////////////////////////////////// + +AgencyCommResult AgencyComm::getValues (std::string const& key, + bool recursive) { + AgencyCommResult result; + + return result; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief removes one or multiple values from the back end +//////////////////////////////////////////////////////////////////////////////// + +int AgencyComm::removeValues (std::string const& key, + bool recursive) { + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief compares and swaps a single value in the back end +//////////////////////////////////////////////////////////////////////////////// + +int AgencyComm::casValue (std::string const& key, + std::string const& oldValue, + std::string const& newValue) { + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief blocks on a change of a single value in the back end +//////////////////////////////////////////////////////////////////////////////// + +AgencyCommResult AgencyComm::watchValues (std::string const& key, + double timeout) { + AgencyCommResult result; + + return result; +} + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" +// End: + diff --git a/arangod/Sharding/AgencyComm.h b/arangod/Sharding/AgencyComm.h index 8e1855753f..e6cdc016a8 100644 --- a/arangod/Sharding/AgencyComm.h +++ b/arangod/Sharding/AgencyComm.h @@ -44,6 +44,9 @@ namespace triagens { // ----------------------------------------------------------------------------- struct Agent { + Agent (); + ~Agent (); + std::string _name; std::string _endpoint; @@ -76,22 +79,92 @@ namespace triagens { ~AgencyComm (); +// ----------------------------------------------------------------------------- +// --SECTION-- public static methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief sets the global prefix for all operations +//////////////////////////////////////////////////////////////////////////////// + + void setPrefix (std::string const&); + +// ----------------------------------------------------------------------------- +// --SECTION-- public methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief establishes the communication channels +//////////////////////////////////////////////////////////////////////////////// + + int connect (); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief disconnects all communication channels +//////////////////////////////////////////////////////////////////////////////// + + int disconnect (); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief adds an agent to the agents list +//////////////////////////////////////////////////////////////////////////////// + int addAgent (Agent); +//////////////////////////////////////////////////////////////////////////////// +/// @brief removes an agent from the agents list +//////////////////////////////////////////////////////////////////////////////// + int removeAgent (Agent); +//////////////////////////////////////////////////////////////////////////////// +/// @brief removes an agent from the agents list +//////////////////////////////////////////////////////////////////////////////// - int setValue (std::string const& key, std::string const& value); + int setValue (std::string const& key, + std::string const& value); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief gets one or multiple values from the back end +//////////////////////////////////////////////////////////////////////////////// - AgencyCommResult getValues (std::string const& key, bool recursive); + AgencyCommResult getValues (std::string const& key, + bool recursive); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief removes one or multiple values from the back end +//////////////////////////////////////////////////////////////////////////////// - int removeValue (std::string const& key, bool recursive); + int removeValues (std::string const& key, + bool recursive); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief compares and swaps a single value in the back end +//////////////////////////////////////////////////////////////////////////////// - int casValue (std::string const& key, std::string const& oldValue, std::string const& newValue); + int casValue (std::string const& key, + std::string const& oldValue, + std::string const& newValue); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief blocks on a change of a single value in the back end +//////////////////////////////////////////////////////////////////////////////// - AgencyCommResult watchValues (std::string const& key, double timeout); + AgencyCommResult watchValues (std::string const& key, + double timeout); + +// ----------------------------------------------------------------------------- +// --SECTION-- private static variables +// ----------------------------------------------------------------------------- private: + +//////////////////////////////////////////////////////////////////////////////// +/// @brief the global prefix +//////////////////////////////////////////////////////////////////////////////// + + static std::string _prefix; + }; } diff --git a/arangod/Sharding/HeartbeatThread.cpp b/arangod/Sharding/HeartbeatThread.cpp new file mode 100644 index 0000000000..e7d5352724 --- /dev/null +++ b/arangod/Sharding/HeartbeatThread.cpp @@ -0,0 +1,86 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief heartbeat thread +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2012 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 triAGENS GmbH, Cologne, Germany +/// +/// @author Jan Steemann +/// @author Copyright 2013, triagens GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#include "HeartbeatThread.h" +#include "BasicsC/logging.h" + +using namespace triagens::basics; +using namespace triagens::arango; + +// ----------------------------------------------------------------------------- +// --SECTION-- HeartbeatThread +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// --SECTION-- constructors and destructors +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief constructs a heartbeat thread +//////////////////////////////////////////////////////////////////////////////// + +HeartbeatThread::HeartbeatThread () + : Thread("heartbeat") { + + allowAsynchronousCancelation(); + + _agency.connect(); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief destroys a heartbeat thread +//////////////////////////////////////////////////////////////////////////////// + +HeartbeatThread::~HeartbeatThread () { + _agency.disconnect(); +} + +// ----------------------------------------------------------------------------- +// --SECTION-- Thread methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief heartbeat main loop +//////////////////////////////////////////////////////////////////////////////// + +void HeartbeatThread::run () { + LOG_INFO("starting heartbeat thread"); + + while (1) { + sleep(5); + + LOG_INFO("heartbeat"); + } + + LOG_INFO("stopping heartbeat thread"); +} + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" +// End: + diff --git a/arangod/Sharding/HeartbeatThread.h b/arangod/Sharding/HeartbeatThread.h new file mode 100644 index 0000000000..eb187e83fd --- /dev/null +++ b/arangod/Sharding/HeartbeatThread.h @@ -0,0 +1,111 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief heartbeat thread +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2012 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 triAGENS GmbH, Cologne, Germany +/// +/// @author Jan Steemann +/// @author Copyright 2013, triagens GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#ifndef TRIAGENS_SHARDING_HEARTBEAT_THREAD_H +#define TRIAGENS_SHARDING_HEARTBEAT_THREAD_H 1 + +#include "Basics/Common.h" +#include "Basics/Thread.h" +#include "Sharding/AgencyComm.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +namespace triagens { + namespace arango { + +// ----------------------------------------------------------------------------- +// --SECTION-- HeartbeatThread +// ----------------------------------------------------------------------------- + + class HeartbeatThread : public basics::Thread { + +// ----------------------------------------------------------------------------- +// --SECTION-- constructors and destructors +// ----------------------------------------------------------------------------- + + private: + HeartbeatThread (HeartbeatThread const&); + HeartbeatThread& operator= (HeartbeatThread const&); + + public: + +//////////////////////////////////////////////////////////////////////////////// +/// @brief constructs a heartbeat thread +//////////////////////////////////////////////////////////////////////////////// + + HeartbeatThread (); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief destroys a heartbeat thread +//////////////////////////////////////////////////////////////////////////////// + + ~HeartbeatThread (); + +// ----------------------------------------------------------------------------- +// --SECTION-- Thread methods +// ----------------------------------------------------------------------------- + + protected: + +//////////////////////////////////////////////////////////////////////////////// +/// @brief heartbeat main loop +//////////////////////////////////////////////////////////////////////////////// + + void run (); + +// ----------------------------------------------------------------------------- +// --SECTION-- private variables +// ----------------------------------------------------------------------------- + + private: + +//////////////////////////////////////////////////////////////////////////////// +/// @brief AgencyComm instance +//////////////////////////////////////////////////////////////////////////////// + + AgencyComm _agency; + + }; + + } +} + + +#ifdef __cplusplus +} +#endif + +#endif + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" +// End: +