From 7113e93c67da5acc4ad920994217675bdd34c40c Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Tue, 15 Mar 2016 20:48:02 +0100 Subject: [PATCH] Finished with Shortest Path Implementation based on new TRX and VPack API --- arangod/V8Server/V8Traverser.cpp | 15 ++++++--------- arangod/V8Server/V8Traverser.h | 1 + arangod/V8Server/v8-vocbase.cpp | 9 ++++----- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/arangod/V8Server/V8Traverser.cpp b/arangod/V8Server/V8Traverser.cpp index 6f771eb064..88ea912117 100644 --- a/arangod/V8Server/V8Traverser.cpp +++ b/arangod/V8Server/V8Traverser.cpp @@ -69,7 +69,6 @@ OperationCursor EdgeCollectionInfo::getEdges(TRI_edge_direction_e direction, _searchBuilder.clear(); EdgeIndex::buildSearchValue(direction, vertexId, _searchBuilder); - LOG(INFO) << _searchBuilder.slice().toJson(); return _trx->indexScan(_collectionName, arangodb::Transaction::CursorType::INDEX, _indexId, _searchBuilder.slice(), 0, UINT64_MAX, 1000, false); @@ -146,7 +145,6 @@ class MultiCollectionEdgeExpander { auto cand = candidates.find(t); if (cand == candidates.end()) { // Add weight -#warning The third parameter has to be replaced by _id content. We need to extract the internal attribute here. Waiting for JAN result.emplace_back(new ArangoDBPathFinder::Step( t, s, currentWeight, edge.get(TRI_VOC_ATTRIBUTE_ID).copyString())); @@ -469,6 +467,7 @@ std::unique_ptr TRI_RunShortestPathSearch( std::unique_ptr TRI_RunSimpleShortestPathSearch( std::vector& collectionInfos, + arangodb::Transaction* trx, ShortestPathOptions& opts) { TRI_edge_direction_e forward; TRI_edge_direction_e backward; @@ -485,7 +484,7 @@ TRI_RunSimpleShortestPathSearch( } auto fwExpander = - [&collectionInfos, forward](std::string const& v, std::vector& res_edges, + [&collectionInfos, forward, trx](std::string const& v, std::vector& res_edges, std::vector& neighbors) { for (auto const& edgeCollection : collectionInfos) { TRI_ASSERT(edgeCollection != nullptr); @@ -498,8 +497,7 @@ TRI_RunSimpleShortestPathSearch( VPackSlice edges = edgeCursor.slice(); for (auto const& edge : VPackArrayIterator(edges)) { -#warning fucking custom type - std::string edgeId = edge.get(TRI_VOC_ATTRIBUTE_ID).copyString(); + std::string edgeId = trx->extractIdString(edge); std::string from = edge.get(TRI_VOC_ATTRIBUTE_FROM).copyString(); if (from == v) { std::string to = edge.get(TRI_VOC_ATTRIBUTE_TO).copyString(); @@ -517,7 +515,7 @@ TRI_RunSimpleShortestPathSearch( } }; auto bwExpander = - [&collectionInfos, backward](std::string const& v, std::vector& res_edges, + [&collectionInfos, backward, trx](std::string const& v, std::vector& res_edges, std::vector& neighbors) { for (auto const& edgeCollection : collectionInfos) { TRI_ASSERT(edgeCollection != nullptr); @@ -530,8 +528,7 @@ TRI_RunSimpleShortestPathSearch( VPackSlice edges = edgeCursor.slice(); for (auto const& edge : VPackArrayIterator(edges)) { -#warning fucking custom type - std::string edgeId = edge.get(TRI_VOC_ATTRIBUTE_ID).copyString(); + std::string edgeId = trx->extractIdString(edge); std::string from = edge.get(TRI_VOC_ATTRIBUTE_FROM).copyString(); if (from == v) { std::string to = edge.get(TRI_VOC_ATTRIBUTE_TO).copyString(); @@ -550,7 +547,7 @@ TRI_RunSimpleShortestPathSearch( }; ArangoDBConstDistancePathFinder pathFinder(fwExpander, bwExpander); - std::unique_ptr path; + auto path = std::make_unique(); path.reset(pathFinder.search(opts.start, opts.end)); return path; } diff --git a/arangod/V8Server/V8Traverser.h b/arangod/V8Server/V8Traverser.h index 339e4f6065..31bf68366c 100644 --- a/arangod/V8Server/V8Traverser.h +++ b/arangod/V8Server/V8Traverser.h @@ -385,6 +385,7 @@ std::unique_ptr TRI_RunShortestPathSearch( std::unique_ptr TRI_RunSimpleShortestPathSearch( std::vector& collectionInfos, + arangodb::Transaction*, arangodb::traverser::ShortestPathOptions& opts); //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 368bb24814..c67ed8d2c0 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -1714,15 +1714,14 @@ static v8::Handle VertexIdToData( TRI_ASSERT(parts.size() == 2); // All internal _id attributes VPackBuilder builder; - builder.openArray(); builder.openObject(); - builder.add(TRI_SLICE_KEY_EQUAL, VPackValue(parts[1])); - builder.close(); + builder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(parts[1])); builder.close(); OperationResult opRes = trx->document(parts[0], builder.slice(), options); - if (!opRes.successful()) { + if (opRes.failed()) { + LOG(INFO) << opRes.code; v8::EscapableHandleScope scope(isolate); return scope.Escape(v8::Null(isolate)); } @@ -2152,7 +2151,7 @@ static void JS_QueryShortestPath( std::unique_ptr path; try { - path = TRI_RunSimpleShortestPathSearch(edgeCollectionInfos, opts); + path = TRI_RunSimpleShortestPathSearch(edgeCollectionInfos, trx.get(), opts); } catch (Exception& e) { trx->finish(e.code()); TRI_V8_THROW_EXCEPTION(e.code());