1
0
Fork 0

EdgeCollections are now evaluated to cids later in TraversalBlock. This change was necessary for the Cluster

This commit is contained in:
Michael Hackstein 2015-11-16 09:09:34 +01:00
parent eec9c02a36
commit 3923c7936e
6 changed files with 40 additions and 35 deletions

View File

@ -59,32 +59,30 @@ TraversalBlock::TraversalBlock (ExecutionEngine* engine,
triagens::arango::traverser::TraverserOptions opts;
ep->fillTraversalOptions(opts);
auto cids = ep->edgeCids();
auto edgeColls = ep->edgeColls();
_resolver = new CollectionNameResolver(_trx->vocbase());
if (triagens::arango::ServerState::instance()->isCoordinator()) {
std::vector<std::string> edgeCollections;
for (auto const& cid : cids) {
edgeCollections.push_back(_resolver->getCollectionNameCluster(cid));
}
_traverser.reset(new triagens::arango::traverser::ClusterTraverser(
edgeCollections,
edgeColls,
opts,
std::string(_trx->vocbase()->_name, strlen(_trx->vocbase()->_name))
std::string(_trx->vocbase()->_name, strlen(_trx->vocbase()->_name)),
_resolver
));
} else {
std::vector<TRI_document_collection_t*> edgeCollections;
for (auto const& cid : cids) {
for (auto const& coll : edgeColls) {
TRI_voc_cid_t cid = _resolver->getCollectionId(coll);
edgeCollections.push_back(_trx->documentCollection(cid));
}
_traverser.reset(new triagens::arango::traverser::DepthFirstTraverser(edgeCollections, opts));
}
_resolver = new CollectionNameResolver(_trx->vocbase());
if (!ep->usesInVariable()) {
_vertexId = ep->getStartVertex();
auto pos = _vertexId.find("/");
_startId = VertexId(
_resolver->getCollectionId(_vertexId.substr(0, pos).c_str()),
_resolver->getCollectionIdCluster(_vertexId.substr(0, pos).c_str()),
_vertexId.c_str() + pos + 1
);
}

View File

@ -79,10 +79,10 @@ TraversalNode::TraversalNode (ExecutionPlan* plan,
if (edgeStruct->_type != TRI_COL_TYPE_EDGE) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_TYPE_INVALID);
}
_edgeCids.push_back(edgeStruct->_cid);
_edgeColls.push_back(eColName);
}
} else {
if (_edgeCids.size() == 0) {
if (_edgeColls.size() == 0) {
if (graph->isStringValue()) {
_graphName = graph->getStringValue();
_graphObj = plan->getAst()->query()->lookupGraphByName(_graphName);
@ -90,8 +90,7 @@ TraversalNode::TraversalNode (ExecutionPlan* plan,
auto eColls = _graphObj->edgeCollections();
for (const auto& n: eColls) {
TRI_voc_cid_t cid = resolver->getCollectionId(n);
_edgeCids.push_back(cid);
_edgeColls.push_back(n);
}
}
}
@ -174,7 +173,7 @@ TraversalNode::TraversalNode (ExecutionPlan* plan,
TraversalNode::TraversalNode (ExecutionPlan* plan,
size_t id,
TRI_vocbase_t* vocbase,
std::vector<TRI_voc_cid_t> const& edgeCids,
std::vector<std::string> const& edgeColls,
Variable const* inVariable,
std::string const& vertexId,
TRI_edge_direction_e direction,
@ -192,8 +191,8 @@ TraversalNode::TraversalNode (ExecutionPlan* plan,
_direction(direction),
_condition(nullptr)
{
for (auto& it : edgeCids) {
_edgeCids.push_back(it);
for (auto& it : edgeColls) {
_edgeColls.push_back(it);
}
}
@ -338,7 +337,7 @@ void TraversalNode::toJsonHelper (triagens::basics::Json& nodes,
ExecutionNode* TraversalNode::clone (ExecutionPlan* plan,
bool withDependencies,
bool withProperties) const {
auto c = new TraversalNode(plan, _id, _vocbase, _edgeCids, _inVariable,
auto c = new TraversalNode(plan, _id, _vocbase, _edgeColls, _inVariable,
_vertexId, _direction, _minDepth, _maxDepth);
if (usesVertexOutVariable()) {

View File

@ -91,7 +91,7 @@ namespace triagens {
TraversalNode (ExecutionPlan* plan,
size_t id,
TRI_vocbase_t* vocbase,
std::vector<TRI_voc_cid_t> const& edgeCids,
std::vector<std::string> const& edgeColls,
Variable const* inVariable,
std::string const& vertexId,
TRI_edge_direction_e direction,
@ -280,8 +280,8 @@ namespace triagens {
void fillTraversalOptions (triagens::arango::traverser::TraverserOptions& opts) const;
std::vector<TRI_voc_cid_t> const edgeCids () const {
return _edgeCids;
std::vector<std::string> const edgeColls () const {
return _edgeColls;
}
////////////////////////////////////////////////////////////////////////////////
@ -418,7 +418,7 @@ namespace triagens {
/// @brief the edge collection cid
////////////////////////////////////////////////////////////////////////////////
std::vector<TRI_voc_cid_t> _edgeCids;
std::vector<std::string> _edgeColls;
////////////////////////////////////////////////////////////////////////////////

View File

@ -37,7 +37,6 @@
#include "Basics/StringUtils.h"
#include "Indexes/Index.h"
#include "VocBase/server.h"
#include <iostream>
using namespace std;
using namespace triagens::basics;
@ -1103,7 +1102,6 @@ int getAllEdgesOnCoordinator (
triagens::basics::Json& result ) {
TRI_ASSERT(result.isObject());
TRI_ASSERT(result.members() == 0);
std::cout << "Requestung: " << dbname << " / " << collname << " / " << vertex << " / " << direction << "\n";
// Set a few variables needed for our work:
ClusterInfo* ci = ClusterInfo::instance();
@ -1122,10 +1120,10 @@ int getAllEdgesOnCoordinator (
CoordTransactionID coordTransactionID = TRI_NewTickServer();
std::string queryParameters = "?vertex=" + StringUtils::urlEncode(vertex);
if (direction == TRI_EDGE_IN) {
queryParameters += "in";
queryParameters += "&direction=in";
}
else if (direction == TRI_EDGE_OUT) {
queryParameters += "out";
queryParameters += "&direction=out";
}
for (it = shards.begin(); it != shards.end(); ++it) {
map<string, string>* headers = new map<string, string>;
@ -1164,7 +1162,7 @@ int getAllEdgesOnCoordinator (
return TRI_ERROR_INTERNAL;
}
auto docs = TRI_LookupObjectJson(shardResult.get(), "documents");
auto docs = TRI_LookupObjectJson(shardResult.get(), "edges");
if (! TRI_IsArrayJson(docs)) {
delete res;
@ -1184,7 +1182,7 @@ int getAllEdgesOnCoordinator (
delete res;
}
result("documents", documents);
result("edges", documents);
return TRI_ERROR_NO_ERROR;
}

View File

@ -94,10 +94,17 @@ void ClusterTraverser::EdgeGetter::operator() (std::string const& startVertex,
contentType,
result);
if (res != TRI_ERROR_NO_ERROR) {
std::cout << "Result:" << res << std::endl;
THROW_ARANGO_EXCEPTION(res);
}
triagens::basics::Json edgesJson = result.get("edges");
_traverser->_iteratorCache.emplace();
auto stack = _traverser->_iteratorCache.top();
for (size_t i = 0; i < edgesJson.size(); ++i) {
triagens::basics::Json edge = edgesJson.at(i);
std::string edgeId = triagens::basics::JsonHelper::getStringValue(edge.json(), "_id", "");
stack.push(edgeId);
_traverser->_edges.emplace(edgeId, edge.steal());
}
std::cout << result << std::endl;
TRI_ASSERT(false);
}
else {
std::stack<std::string> tmp = _traverser->_iteratorCache.top();
@ -139,8 +146,7 @@ void ClusterTraverser::defineInternalFunctions () {
*/
void ClusterTraverser::setStartVertex (VertexId& v) {
// TODO
std::string id = "";
std::string id = v.toString(_resolver);
_enumerator.reset(new triagens::basics::PathEnumerator<std::string, std::string, size_t> (_edgeGetter, _vertexGetter, id));
_done = false;
}

View File

@ -47,12 +47,14 @@ namespace triagens {
ClusterTraverser (
std::vector<std::string> edgeCollections,
TraverserOptions& opts,
std::string dbname
std::string dbname,
CollectionNameResolver const* resolver
) : Traverser(opts),
_edgeCols(edgeCollections),
_dbname(dbname),
_vertexGetter(&_edges),
_edgeGetter(this) {
_edgeGetter(this),
_resolver(resolver) {
}
~ClusterTraverser () {
@ -123,6 +125,8 @@ namespace triagens {
EdgeGetter _edgeGetter;
CollectionNameResolver const* _resolver;
////////////////////////////////////////////////////////////////////////////////
/// @brief internal cursor to enumerate the paths of a graph
////////////////////////////////////////////////////////////////////////////////