mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into aql2
This commit is contained in:
commit
94a0d29d46
|
@ -2048,13 +2048,13 @@ int ClusterInfo::getResponsibleShard (CollectionID const& collectionID,
|
|||
// Note that currently we take the number of shards and the shardKeys
|
||||
// from Plan, since they are immutable. Later we will have to switch
|
||||
// this to Current, when we allow to add and remove shards.
|
||||
if (!_collectionsValid) {
|
||||
if (! _collectionsValid) {
|
||||
loadPlannedCollections();
|
||||
}
|
||||
|
||||
int tries = 0;
|
||||
shared_ptr<vector<string> > shardKeysPtr;
|
||||
char const** shardKeys = 0;
|
||||
char const** shardKeys = nullptr;
|
||||
shared_ptr<vector<ShardID> > shards;
|
||||
bool found = false;
|
||||
|
||||
|
@ -2071,7 +2071,7 @@ int ClusterInfo::getResponsibleShard (CollectionID const& collectionID,
|
|||
if (it2 != _shardKeys.end()) {
|
||||
shardKeysPtr = it2->second;
|
||||
shardKeys = new char const* [shardKeysPtr->size()];
|
||||
if (shardKeys != 0) {
|
||||
if (shardKeys != nullptr) {
|
||||
size_t i;
|
||||
for (i = 0; i < shardKeysPtr->size(); ++i) {
|
||||
shardKeys[i] = shardKeysPtr->at(i).c_str();
|
||||
|
|
|
@ -95,14 +95,17 @@ string const& RestShardHandler::queue () const {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
triagens::rest::HttpHandler::status_t RestShardHandler::execute () {
|
||||
// Deactivated to allow for asynchronous cluster internal communication
|
||||
// between two DBservers. 30.7.2014 Max.
|
||||
#if 0
|
||||
ServerState::RoleEnum role = ServerState::instance()->getRole();
|
||||
|
||||
if (role != ServerState::ROLE_COORDINATOR) {
|
||||
generateError(triagens::rest::HttpResponse::BAD,
|
||||
(int) triagens::rest::HttpResponse::BAD,
|
||||
"this API is meant to be called on a coordinator node");
|
||||
return status_t(HANDLER_DONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool found;
|
||||
char const* _coordinator = _request->header("x-arango-coordinator", found);
|
||||
|
|
|
@ -877,11 +877,59 @@ static v8::Handle<v8::Value> JS_GetResponsibleServerClusterInfo (v8::Arguments c
|
|||
TRI_V8_EXCEPTION_USAGE(scope, "getResponsibleServer(<shard-id>)");
|
||||
}
|
||||
|
||||
const std::string result = ClusterInfo::instance()->getResponsibleServer(TRI_ObjectToString(argv[0]));
|
||||
std::string const result = ClusterInfo::instance()->getResponsibleServer(TRI_ObjectToString(argv[0]));
|
||||
|
||||
return scope.Close(v8::String::New(result.c_str(), (int) result.size()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the responsible shard
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static v8::Handle<v8::Value> JS_GetResponsibleShardClusterInfo (v8::Arguments const& argv) {
|
||||
v8::HandleScope scope;
|
||||
|
||||
if (argv.Length() < 2 || argv.Length() > 3) {
|
||||
TRI_V8_EXCEPTION_USAGE(scope, "getResponsibleShard(<collection-id>, <document>, <documentIsComplete>)");
|
||||
}
|
||||
|
||||
if (! argv[0]->IsString() && ! argv[0]->IsStringObject()) {
|
||||
TRI_V8_TYPE_ERROR(scope, "expecting a string for <collection-id>)");
|
||||
}
|
||||
|
||||
if (! argv[1]->IsObject()) {
|
||||
TRI_V8_TYPE_ERROR(scope, "expecting an object for <document>)");
|
||||
}
|
||||
|
||||
bool documentIsComplete = true;
|
||||
if (argv.Length() > 2) {
|
||||
documentIsComplete = TRI_ObjectToBoolean(argv[2]);
|
||||
}
|
||||
|
||||
TRI_json_t* json = TRI_ObjectToJson(argv[1]);
|
||||
|
||||
if (json == nullptr) {
|
||||
TRI_V8_EXCEPTION_MEMORY(scope);
|
||||
}
|
||||
|
||||
ShardID shardId;
|
||||
CollectionID collectionId = TRI_ObjectToString(argv[0]);
|
||||
bool usesDefaultShardingAttributes;
|
||||
int res = ClusterInfo::instance()->getResponsibleShard(collectionId, json, documentIsComplete, shardId, usesDefaultShardingAttributes);
|
||||
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
TRI_V8_EXCEPTION(scope, res);
|
||||
}
|
||||
|
||||
v8::Handle<v8::Object> result = v8::Object::New();
|
||||
result->Set(TRI_V8_STRING("shardId"), v8::String::New(shardId.c_str(), (int) shardId.size()));
|
||||
result->Set(TRI_V8_STRING("usesDefaultShardingAttributes"), v8::Boolean::New(usesDefaultShardingAttributes));
|
||||
|
||||
return scope.Close(result);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the server endpoint for a server
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1812,6 +1860,7 @@ void TRI_InitV8Cluster (v8::Handle<v8::Context> context) {
|
|||
TRI_AddMethodVocbase(rt, "getCollectionInfo", JS_GetCollectionInfoClusterInfo);
|
||||
TRI_AddMethodVocbase(rt, "getCollectionInfoCurrent", JS_GetCollectionInfoCurrentClusterInfo);
|
||||
TRI_AddMethodVocbase(rt, "getResponsibleServer", JS_GetResponsibleServerClusterInfo);
|
||||
TRI_AddMethodVocbase(rt, "getResponsibleShard", JS_GetResponsibleShardClusterInfo);
|
||||
TRI_AddMethodVocbase(rt, "getServerEndpoint", JS_GetServerEndpointClusterInfo);
|
||||
TRI_AddMethodVocbase(rt, "getDBServers", JS_GetDBServers);
|
||||
TRI_AddMethodVocbase(rt, "reloadDBServers", JS_ReloadDBServers);
|
||||
|
|
|
@ -4851,7 +4851,9 @@ function RESOLVE_GRAPH_TO_COLLECTIONS(graph, options) {
|
|||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "GRAPH_EDGES");
|
||||
}
|
||||
});
|
||||
|
||||
collections.orphanCollections = FILTER_RESTRICTION(
|
||||
graph.orphanCollections, options.orphanCollectionRestriction
|
||||
);
|
||||
return collections;
|
||||
}
|
||||
|
||||
|
@ -4866,7 +4868,9 @@ function RESOLVE_GRAPH_TO_FROM_VERTICES (graphname, options) {
|
|||
var removeDuplicates = function(elem, pos, self) {
|
||||
return self.indexOf(elem) === pos;
|
||||
};
|
||||
|
||||
if (options.includeOrphans) {
|
||||
collections.fromCollections = collections.fromCollections.concat(collections.orphanCollections);
|
||||
}
|
||||
return DOCUMENTS_BY_EXAMPLE(
|
||||
collections.fromCollections.filter(removeDuplicates), options.fromVertexExample
|
||||
);
|
||||
|
@ -6121,17 +6125,22 @@ function GENERAL_GRAPH_VERTICES (
|
|||
if (! options.direction) {
|
||||
options.direction = 'any';
|
||||
}
|
||||
|
||||
if (options.direction === 'any') {
|
||||
options.includeOrphans = true;
|
||||
}
|
||||
if (options.vertexCollectionRestriction) {
|
||||
if (options.direction === "inbound") {
|
||||
options.endVertexCollectionRestriction = options.vertexCollectionRestriction;
|
||||
} else {
|
||||
} else if (options.direction === "outbound") {
|
||||
options.startVertexCollectionRestriction = options.vertexCollectionRestriction;
|
||||
} else {
|
||||
options.endVertexCollectionRestriction = options.vertexCollectionRestriction;
|
||||
options.startVertexCollectionRestriction = options.vertexCollectionRestriction;
|
||||
options.orphanCollectionRestriction = options.vertexCollectionRestriction;
|
||||
}
|
||||
}
|
||||
|
||||
options.fromVertexExample = vertexExamples;
|
||||
|
||||
return RESOLVE_GRAPH_TO_FROM_VERTICES(graphName, options);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
db._drop("UnitTestsAhuacatlVertex4");
|
||||
db._drop("UnitTestsAhuacatlEdge1");
|
||||
db._drop("UnitTestsAhuacatlEdge2");
|
||||
db._drop("UnitTestsAhuacatlOrphan");
|
||||
|
||||
vertex1 = db._create("UnitTestsAhuacatlVertex1");
|
||||
vertex2 = db._create("UnitTestsAhuacatlVertex2");
|
||||
|
@ -58,6 +59,7 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
vertex4 = db._create("UnitTestsAhuacatlVertex4");
|
||||
edge1 = db._createEdgeCollection("UnitTestsAhuacatlEdge1");
|
||||
edge2 = db._createEdgeCollection("UnitTestsAhuacatlEdge2");
|
||||
oprhan = db._create("UnitTestsAhuacatlOrphan");
|
||||
|
||||
vertex1.save({ _key: "v1", hugo: true});
|
||||
vertex1.save({ _key: "v2", hugo: true});
|
||||
|
@ -67,6 +69,7 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
vertex3.save({ _key: "v6" });
|
||||
vertex4.save({ _key: "v7" });
|
||||
vertex4.save({ _key: "v8", heinz: 1});
|
||||
oprhan.save({ _key: "orphan" });
|
||||
|
||||
function makeEdge(from, to, collection) {
|
||||
collection.save(from, to, { what: from.split("/")[1] + "->" + to.split("/")[1] });
|
||||
|
@ -93,7 +96,8 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"],
|
||||
["UnitTestsAhuacatlVertex3", "UnitTestsAhuacatlVertex4"]
|
||||
)
|
||||
)
|
||||
),
|
||||
["UnitTestsAhuacatlOrphan"]
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -108,6 +112,7 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
db._drop("UnitTestsAhuacatlVertex4");
|
||||
db._drop("UnitTestsAhuacatlEdge1");
|
||||
db._drop("UnitTestsAhuacatlEdge2");
|
||||
db._drop("UnitTestsAhuacatlOrphan");
|
||||
db._collection("_graphs").remove("_graphs/bla3");
|
||||
},
|
||||
|
||||
|
@ -121,6 +126,9 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
actual = getRawQueryResults("FOR e IN GRAPH_VERTICES('bla3', 'UnitTestsAhuacatlVertex1/v1', {direction : 'any'}) RETURN e");
|
||||
assertEqual(actual[0]._id, 'UnitTestsAhuacatlVertex1/v1');
|
||||
|
||||
actual = getRawQueryResults("FOR e IN GRAPH_VERTICES('bla3', {}, {direction : 'any', vertexCollectionRestriction : 'UnitTestsAhuacatlOrphan'}) RETURN e");
|
||||
assertEqual(actual[0]._id, 'UnitTestsAhuacatlOrphan/orphan');
|
||||
|
||||
var actual;
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES('bla3', 'UnitTestsAhuacatlVertex1/v1', {direction : 'any'}) SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v1->v2", "v1->v5", "v2->v1" ]);
|
||||
|
|
Loading…
Reference in New Issue