1
0
Fork 0
This commit is contained in:
Jan 2019-03-13 15:24:55 +01:00 committed by GitHub
parent dd4938598c
commit 3156e481de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 40 additions and 36 deletions

View File

@ -72,7 +72,7 @@ ClusterEdgeCursor::ClusterEdgeCursor(arangodb::velocypack::StringRef vertexId, b
*(leased.get()), _cache->insertedDocuments());
}
bool ClusterEdgeCursor::next(std::function<void(EdgeDocumentToken&&, VPackSlice, size_t)> callback) {
bool ClusterEdgeCursor::next(EdgeCursor::Callback const& callback) {
if (_position < _edgeList.size()) {
VPackSlice edge = _edgeList[_position];
callback(EdgeDocumentToken(edge), edge, _position);
@ -82,7 +82,7 @@ bool ClusterEdgeCursor::next(std::function<void(EdgeDocumentToken&&, VPackSlice,
return false;
}
void ClusterEdgeCursor::readAll(std::function<void(EdgeDocumentToken&&, VPackSlice, size_t)> callback) {
void ClusterEdgeCursor::readAll(EdgeCursor::Callback const& callback) {
for (VPackSlice const& edge : _edgeList) {
callback(EdgeDocumentToken(edge), edge, _position);
}

View File

@ -48,9 +48,9 @@ class ClusterEdgeCursor : public graph::EdgeCursor {
~ClusterEdgeCursor() {}
bool next(std::function<void(graph::EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)> callback) override;
bool next(EdgeCursor::Callback const& callback) override;
void readAll(std::function<void(graph::EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)> callback) override;
void readAll(EdgeCursor::Callback const& callback) override;
private:
std::vector<arangodb::velocypack::Slice> _edgeList;

View File

@ -25,7 +25,6 @@
#define ARANGOD_GRAPH_EDGECURSOR_H 1
#include "Basics/Common.h"
#include <velocypack/StringRef.h>
namespace arangodb {
@ -45,10 +44,13 @@ class EdgeCursor {
public:
EdgeCursor() {}
virtual ~EdgeCursor() {}
using Callback =
std::function<void(EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)>;
virtual bool next(std::function<void(EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)> callback) = 0;
virtual bool next(std::function<void(EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)> const& callback) = 0;
virtual void readAll(std::function<void(EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)>) = 0;
virtual void readAll(std::function<void(EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)> const& callback) = 0;
};
} // namespace graph

View File

@ -46,7 +46,6 @@ SingleServerEdgeCursor::SingleServerEdgeCursor(BaseOptions* opts, size_t nrCurso
std::vector<size_t> const* mapping)
: _opts(opts),
_trx(opts->trx()),
_cursors(),
_currentCursor(0),
_currentSubCursor(0),
_cachePos(0),
@ -79,8 +78,11 @@ static bool CheckInaccesible(transaction::Methods* trx, VPackSlice const& edge)
}
#endif
void SingleServerEdgeCursor::getDocAndRunCallback(OperationCursor* cursor, Callback callback) {
void SingleServerEdgeCursor::getDocAndRunCallback(OperationCursor* cursor, EdgeCursor::Callback const& callback) {
auto collection = cursor->collection();
if (collection == nullptr) {
return;
}
EdgeDocumentToken etkn(collection->id(), _cache[_cachePos++]);
collection->readDocumentWithCallback(
_trx, etkn.localDocumentId(), [&](LocalDocumentId const&, VPackSlice edgeDoc) {
@ -123,7 +125,7 @@ bool SingleServerEdgeCursor::advanceCursor(OperationCursor*& cursor,
return true;
}
bool SingleServerEdgeCursor::next(std::function<void(EdgeDocumentToken&&, VPackSlice, size_t)> callback) {
bool SingleServerEdgeCursor::next(EdgeCursor::Callback const& callback) {
// fills callback with next EdgeDocumentToken and Slice that contains the
// ohter side of the edge (we are standing on a node and want to iterate all
// connected edges
@ -156,7 +158,7 @@ bool SingleServerEdgeCursor::next(std::function<void(EdgeDocumentToken&&, VPackS
}
} else {
if (cursor->hasExtra()) {
bool operationSuccessfull = false;
bool operationSuccessful = false;
auto extraCB = [&](LocalDocumentId const& token, VPackSlice edge) {
if (token.isSet()) {
#ifdef USE_ENTERPRISE
@ -165,7 +167,10 @@ bool SingleServerEdgeCursor::next(std::function<void(EdgeDocumentToken&&, VPackS
return;
}
#endif
operationSuccessfull = true;
if (cursor->collection() == nullptr) {
return;
}
operationSuccessful = true;
auto etkn = EdgeDocumentToken(cursor->collection()->id(), token);
if (_internalCursorMapping != nullptr) {
TRI_ASSERT(_currentCursor < _internalCursorMapping->size());
@ -176,7 +181,7 @@ bool SingleServerEdgeCursor::next(std::function<void(EdgeDocumentToken&&, VPackS
}
};
cursor->nextWithExtra(extraCB, 1);
if (operationSuccessfull) {
if (operationSuccessful) {
return true;
}
} else {
@ -198,7 +203,7 @@ bool SingleServerEdgeCursor::next(std::function<void(EdgeDocumentToken&&, VPackS
return true;
}
void SingleServerEdgeCursor::readAll(std::function<void(EdgeDocumentToken&&, VPackSlice, size_t)> callback) {
void SingleServerEdgeCursor::readAll(EdgeCursor::Callback const& callback) {
size_t cursorId = 0;
for (_currentCursor = 0; _currentCursor < _cursors.size(); ++_currentCursor) {
if (_internalCursorMapping != nullptr) {
@ -210,6 +215,9 @@ void SingleServerEdgeCursor::readAll(std::function<void(EdgeDocumentToken&&, VPa
auto& cursorSet = _cursors[_currentCursor];
for (auto& cursor : cursorSet) {
LogicalCollection* collection = cursor->collection();
if (collection == nullptr) {
continue;
}
auto cid = collection->id();
if (cursor->hasExtra()) {
auto cb = [&](LocalDocumentId const& token, VPackSlice edge) {

View File

@ -56,8 +56,6 @@ class SingleServerEdgeCursor final : public EdgeCursor {
std::vector<LocalDocumentId> _cache;
size_t _cachePos;
std::vector<size_t> const* _internalCursorMapping;
using Callback =
std::function<void(EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)>;
public:
SingleServerEdgeCursor(BaseOptions* options, size_t,
@ -65,9 +63,9 @@ class SingleServerEdgeCursor final : public EdgeCursor {
~SingleServerEdgeCursor();
bool next(std::function<void(EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)> callback) override;
bool next(EdgeCursor::Callback const& callback) override;
void readAll(std::function<void(EdgeDocumentToken&&, arangodb::velocypack::Slice, size_t)>) override;
void readAll(EdgeCursor::Callback const& callback) override;
std::vector<std::vector<OperationCursor*>>& getCursors() { return _cursors; }
@ -75,7 +73,7 @@ class SingleServerEdgeCursor final : public EdgeCursor {
// returns false if cursor can not be further advanced
bool advanceCursor(OperationCursor*& cursor, std::vector<OperationCursor*>& cursorSet);
void getDocAndRunCallback(OperationCursor*, Callback callback);
void getDocAndRunCallback(OperationCursor*, EdgeCursor::Callback const& callback);
};
} // namespace graph
} // namespace arangodb

View File

@ -31,11 +31,12 @@ using namespace arangodb;
IndexIterator::IndexIterator(LogicalCollection* collection, transaction::Methods* trx)
: _collection(collection), _trx(trx) {
TRI_ASSERT(_collection != nullptr);
// note: collection may be a nullptr here, if we are dealing with the EmptyIndexIterator
TRI_ASSERT(_trx != nullptr);
}
bool IndexIterator::nextDocument(DocumentCallback const& cb, size_t limit) {
TRI_ASSERT(_collection != nullptr);
return next(
[this, &cb](LocalDocumentId const& token) {
_collection->readDocumentWithCallback(_trx, token, cb);

View File

@ -83,7 +83,10 @@ class IndexIterator {
virtual char const* typeName() const = 0;
/// @brief return the underlying collection
/// note: this may return a nullptr in case we are dealing with the EmptyIndexIterator!
LogicalCollection* collection() const { return _collection; }
transaction::Methods* transaction() const { return _trx; }
/// @brief whether or not the index iterator supports rearming
@ -122,7 +125,7 @@ class IndexIterator {
virtual void reset();
virtual void skip(uint64_t count, uint64_t& skipped);
protected:
LogicalCollection* _collection;
transaction::Methods* _trx;

View File

@ -384,7 +384,10 @@ void GraphStore<V, E>::_loadVertices(transaction::Methods& trx, ShardID const& v
// tell the formatter the number of docs we are about to load
LogicalCollection* collection = cursor.collection();
uint64_t number = collection->numberDocuments(&trx, transaction::CountType::Normal);
uint64_t number = 0;
if (collection != nullptr) {
number = collection->numberDocuments(&trx, transaction::CountType::Normal);
}
_graphFormat->willLoadVertices(number);
auto cb = [&](LocalDocumentId const& token, VPackSlice slice) {

View File

@ -3435,14 +3435,3 @@ Result Methods::replicateOperations(LogicalCollection const& collection,
return Result{};
}
/// @brief returns an empty index iterator for the collection
std::unique_ptr<IndexIterator> Methods::createEmptyIndexIterator(std::string const& collectionName) {
TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName);
TransactionCollection* trxColl = trxCollection(cid);
if (trxColl == nullptr) {
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL, "unable to determine transaction collection");
}
return std::make_unique<EmptyIndexIterator>(documentCollection(trxColl), this);
}

View File

@ -522,9 +522,6 @@ class Methods {
/// @brief read- or write-unlock a collection
ENTERPRISE_VIRT Result unlockRecursive(TRI_voc_cid_t, AccessMode::Type);
/// @brief returns an empty index iterator for the collection
std::unique_ptr<IndexIterator> createEmptyIndexIterator(std::string const& collectionName);
private:
/// @brief replicates operations from leader to follower(s)
Result replicateOperations(LogicalCollection* collection,

View File

@ -58,6 +58,9 @@ struct OperationCursor {
_hasMore = true;
}
/// @brief return the logical collection used by the iterator.
/// note that the collection may be a nullptr in case we are dealing with
/// an EmptyIndexIterator!
LogicalCollection* collection() const;
inline bool hasMore() const { return _hasMore; }