From a0c32e90d7ac4d31a300408f2ac8b44aac5d67d7 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 27 Feb 2014 13:14:02 +0100 Subject: [PATCH] fixed edge access in coordinator --- arangod/Cluster/ClusterMethods.cpp | 10 ++++----- arangod/RestHandler/RestEdgeHandler.cpp | 3 +-- arangod/V8Server/v8-vocbase.cpp | 27 ++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/arangod/Cluster/ClusterMethods.cpp b/arangod/Cluster/ClusterMethods.cpp index acacfc745d..e09595d19e 100644 --- a/arangod/Cluster/ClusterMethods.cpp +++ b/arangod/Cluster/ClusterMethods.cpp @@ -1112,12 +1112,12 @@ int createEdgeOnCoordinator ( // Send a synchronous request to that shard using ClusterComm: ClusterCommResult* res; map headers; - res = cc->syncRequest("", TRI_NewTickServer(), "shard:"+shardID, + res = cc->syncRequest("", TRI_NewTickServer(), "shard:" + shardID, triagens::rest::HttpRequest::HTTP_REQUEST_POST, - "/_db/"+dbname+"/_api/edge?collection="+ - StringUtils::urlEncode(shardID)+"&waitForSync="+ - (waitForSync ? "true" : "false")+ - "&from="+StringUtils::urlEncode(from)+"&to="+StringUtils::urlEncode(to), + "/_db/" + dbname + "/_api/edge?collection=" + + StringUtils::urlEncode(shardID) + "&waitForSync=" + + (waitForSync ? "true" : "false") + + "&from=" + StringUtils::urlEncode(from) + "&to=" + StringUtils::urlEncode(to), body, headers, 60.0); if (res->status == CL_COMM_TIMEOUT) { diff --git a/arangod/RestHandler/RestEdgeHandler.cpp b/arangod/RestHandler/RestEdgeHandler.cpp index 5348390d28..33f9099173 100644 --- a/arangod/RestHandler/RestEdgeHandler.cpp +++ b/arangod/RestHandler/RestEdgeHandler.cpp @@ -229,8 +229,7 @@ bool RestEdgeHandler::createDocument () { #ifdef TRI_ENABLE_CLUSTER if (ServerState::instance()->isCoordinator()) { // json will be freed inside! - return createDocumentCoordinator(collection, waitForSync, json, - from, to); + return createDocumentCoordinator(collection, waitForSync, json, from, to); } #endif diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 65624bfe87..180e305170 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -7687,6 +7687,24 @@ static v8::Handle SaveVocbaseColCoordinator (TRI_vocbase_col_t* colle } #endif +//////////////////////////////////////////////////////////////////////////////// +/// @brief extract a key from a v8 object +//////////////////////////////////////////////////////////////////////////////// + +static string GetId (v8::Handle const& arg) { + if (arg->IsObject() && ! arg->IsArray()) { + v8::Local obj = arg->ToObject(); + + TRI_v8_global_t* v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); + + if (obj->Has(v8g->_IdKey)) { + return TRI_ObjectToString(obj->Get(v8g->_IdKey)); + } + } + + return TRI_ObjectToString(arg); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief saves an edge, coordinator case in a cluster //////////////////////////////////////////////////////////////////////////////// @@ -7706,11 +7724,14 @@ static v8::Handle SaveEdgeColCoordinator (TRI_vocbase_col_t* collecti if (argv.Length() < 3 || argv.Length() > 4) { TRI_V8_EXCEPTION_USAGE(scope, "save(, , , [])"); } - string _from = TRI_ObjectToString(argv[0]); - string _to = TRI_ObjectToString(argv[1]); + + string _from = GetId(argv[0]); + string _to = GetId(argv[1]); + TRI_json_t* json = TRI_ObjectToJson(argv[2]); + const bool waitForSync = ExtractForceSync(argv, 3); - if (!TRI_IsArrayJson(json)) { + if (! TRI_IsArrayJson(json)) { if (0 != json) { TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); }