1
0
Fork 0

Merge branch 'sharding' of https://github.com/triAGENS/ArangoDB into sharding

This commit is contained in:
Jan Steemann 2013-12-11 18:37:58 +01:00
commit c3132997b3
3 changed files with 267 additions and 20 deletions

View File

@ -0,0 +1,45 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief Library for intra-cluster communications
///
/// @file ClusterComm.cpp
///
/// DISCLAIMER
///
/// Copyright 2010-2013 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 Max Neunhoeffer
/// @author Copyright 2013, triagens GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include <arangod/Cluster/ClusterComm.h>
using namespace triagens::arango;
// -----------------------------------------------------------------------------
// --SECTION--
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief
////////////////////////////////////////////////////////////////////////////////
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -0,0 +1,196 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief Library for intra-cluster communications
///
/// @file ClusterComm.h
///
/// DISCLAIMER
///
/// Copyright 2010-2013 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 Max Neunhoeffer
/// @author Copyright 2013, triagens GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_CLUSTER_COMM_H
#define TRIAGENS_CLUSTER_COMM_H 1
#include "Basics/Common.h"
#include "Basics/ReadWriteLock.h"
#include "Rest/HttpRequest.h"
#ifdef __cplusplus
extern "C" {
#endif
namespace triagens {
namespace arango {
typedef string ClientTID;
typedef string CoordTID;
typedef int32_t OpID;
typedef string ShardID;
typedef string ServerID;
class ClusterCommResult {
OpID opID;
// All the stuff from the HTTP request result
};
class ClusterCommCallback {
// The idea is that one inherits from this class and implements
// the callback.
ClusterCommCallback();
~ClusterCommCallback();
// Result indicates whether or not the returned result shall be queued
virtual bool operator() (ClusterCommResult *);
};
typedef uint64_t ClusterCommTimeout; // in microseconds
// -----------------------------------------------------------------------------
// --SECTION-- ClusterComm
// -----------------------------------------------------------------------------
class ClusterComm {
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises library
////////////////////////////////////////////////////////////////////////////////
ClusterComm ( );
////////////////////////////////////////////////////////////////////////////////
/// @brief shuts down library
////////////////////////////////////////////////////////////////////////////////
~ClusterComm ( );
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief produces an operation ID which is unique in this process
////////////////////////////////////////////////////////////////////////////////
OpID getOpID ( );
////////////////////////////////////////////////////////////////////////////////
/// @brief submit an HTTP request to a shard synchronously
////////////////////////////////////////////////////////////////////////////////
int request (const ClientTID& clientTID,
const CoordTID& coordTID,
const OpID& opID,
const ShardID& shardID,
rest::HttpRequest::HttpRequestType reqtype,
const string& path,
const char* body,
size_t bodyLength,
const map<string, string>& headerFields,
ClusterCommCallback* callback,
ClusterCommTimeout& timeout);
////////////////////////////////////////////////////////////////////////////////
/// @brief poll one answer for a given opID
////////////////////////////////////////////////////////////////////////////////
ClusterCommResult* poll (const ClientTID& clientTID,
const CoordTID& coordTID,
const OpID& opID,
const ShardID& shardID,
bool blocking = false,
ClusterCommTimeout timeout = 0);
////////////////////////////////////////////////////////////////////////////////
/// @brief poll many answers for some given opIDs
////////////////////////////////////////////////////////////////////////////////
vector<ClusterCommResult*> multipoll (
const ClientTID& clientTID,
const CoordTID& coordTID,
const OpID& opID,
const ShardID& shardID,
int maxanswers = 0,
bool blocking = false,
ClusterCommTimeout timeout = 0);
////////////////////////////////////////////////////////////////////////////////
/// @brief ignore and drop current and future answers
////////////////////////////////////////////////////////////////////////////////
void drop (const ClientTID& clientTID,
const CoordTID& coordTID,
const OpID& opID,
const ShardID& shardID);
////////////////////////////////////////////////////////////////////////////////
/// @brief send an answer HTTP request to a coordinator
////////////////////////////////////////////////////////////////////////////////
int answer (rest::HttpRequest& request,
rest::HttpRequest::HttpRequestType reqtype,
const string& path,
const char* body,
size_t bodyLength,
const map<string, string>& headerFields,
ClusterCommTimeout& timeout);
// -----------------------------------------------------------------------------
// --SECTION-- private data
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief process global last used operation ID
////////////////////////////////////////////////////////////////////////////////
static OpID _lastUsedOpID;
////////////////////////////////////////////////////////////////////////////////
/// @brief global lock to protect _lastUsedOpID
////////////////////////////////////////////////////////////////////////////////
static triagens::basics::ReadWriteLock _lock;
}; // end of class ClusterComm
} // namespace arango
} // namespace triagens
#ifdef __cplusplus
}
#endif
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -3,7 +3,7 @@
CURL="curl -s -S --fail "
AGENCY="http://localhost:4001"
PREFIX=""
PREFIX="/"
if [ "$1" == "-a" ] ; then
export AGENCY=$2
@ -16,7 +16,9 @@ if [ "$1" == "-p" ] ; then
fi
if [ "$1" == "help" -o "$1" == "-h" -o "$1" == "--help" ] ; then
echo Usage: "arangom [-a AGENCY] [-p PREFIX] help|init"
echo "Usage: arangom [-a AGENCY] [-p PREFIX] help|init"
echo " where AGENCY is an URL not ending in a slash"
echo " and PREFIX is a path starting and ending with a slash"
exit 0
fi
@ -27,31 +29,35 @@ function set() {
value=$2
if [ "x$value" == "x" ] ; then
echo "Creating directory $PREFIX$key"
$CURL -X PUT "$URL$key?dir=true" > /dev/null || exit 1
$CURL -X PUT "$URL$PREFIX$key?dir=true" > /dev/null || exit 1
else
echo "Setting key $PREFIX$key to value $value"
$CURL -X PUT "$URL$key" -d "value=$value" > /dev/null || exit 1
$CURL -X PUT "$URL$PREFIX$key" -d "value=$value" > /dev/null || exit 1
fi
}
if [ "$1" == "init" ] ; then
$CURL -X DELETE "$URL/?recursive=true" > /dev/null
set /Config/MapLocalToID
set /Config/MapIDToEndpoint
set /TmpConfig/DBServers
set /TmpConfig/Coordinators
set /TmpConfig/Databases
set /TmpConfig/Collections
set /TmpConfig/ShardsCurrent
set /TmpConfig/ShardsWanted
set /State/ServersRegistered
set /State/ServerStates
set /State/ShardsCopied
set /State/Problems
set /State/ClusterManager none
set /State/LatestID 0
set /Commands
$CURL -X DELETE "$URL$PREFIX?recursive=true" > /dev/null
set Config/Version 1
set Config/MapLocalToID
set Config/MapIDToEndpoint
set Config/DBServers
set Config/Coordinators
set Config/Shards
set TmpConfig/DBServers
set TmpConfig/Coordinators
set TmpConfig/Databases
set TmpConfig/Collections
set TmpConfig/Shards
set State/ServersRegistered
set State/ServerStates
set State/Shards
set State/ShardsCopied
set State/Problems
set State/ClusterManager none
set State/LatestID 0
set Commands
echo Initialisation complete.
fi