8000 Bug fix/simplify things by jsteemann · Pull Request #6516 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Bug fix/simplify things #6516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arangod/Cluster/ClusterComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ size_t ClusterComm::performRequests(std::vector<ClusterCommRequest>& requests,
ClusterCommTimeout timeout, size_t& nrDone,
arangodb::LogTopic const& logTopic,
bool retryOnCollNotFound) {
if (requests.size() == 0) {
if (requests.empty()) {
nrDone = 0;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions arangod/ClusterEngine/ClusterCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "Utils/OperationOptions.h"
#include "VocBase/LocalDocumentId.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/ManagedDocumentResult.h"
#include "VocBase/ticks.h"
#include "VocBase/voc-types.h"

Expand Down
1 change: 0 additions & 1 deletion arangod/ClusterEngine/ClusterCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "ClusterEngine/Common.h"
#include "StorageEngine/PhysicalCollection.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/ManagedDocumentResult.h"

namespace rocksdb {
class Transaction;
Expand Down
69 changes: 53 additions & 16 deletions arangod/MMFiles/MMFilesCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,55 @@
#include "VocBase/KeyGenerator.h"
#include "VocBase/LocalDocumentId.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/ManagedDocumentResult.h"
#include "VocBase/ticks.h"

using namespace arangodb;
using Helper = arangodb::basics::VelocyPackHelper;

/// @brief state during opening of a collection
namespace arangodb {
struct OpenIteratorState {
LogicalCollection* _collection;
arangodb::MMFilesPrimaryIndex* _primaryIndex;
TRI_voc_tid_t _tid;
TRI_voc_fid_t _fid;
std::unordered_map<TRI_voc_fid_t, MMFilesDatafileStatisticsContainer*>
_stats;
MMFilesDatafileStatisticsContainer* _dfi;
transaction::Methods* _trx;
ManagedDocumentResult _mdr;
IndexLookupContext _context;
uint64_t _deletions;
uint64_t _documents;
int64_t _initialCount;

OpenIteratorState(LogicalCollection* collection, transaction::Methods* trx)
: _collection(collection),
_primaryIndex(
static_cast<MMFilesCollection*>(collection->getPhysical())
->primaryIndex()),
_tid(0),
_fid(0),
_stats(),
_dfi(nullptr),
_trx(trx),
_context(trx, collection, &_mdr, 1),
_deletions(0),
_documents(0),
_initialCount(-1) {
TRI_ASSERT(collection != nullptr);
TRI_ASSERT(trx != nullptr);
}

~OpenIteratorState() {
for (auto& it : _stats) {
delete it.second;
}
}
};
}

namespace {

/// @brief helper class for filling indexes
Expand Down Expand Up @@ -100,7 +144,7 @@ class MMFilesIndexFillerTask : public basics::LocalTask {

/// @brief find a statistics container for a given file id
static MMFilesDatafileStatisticsContainer* FindDatafileStats(
MMFilesCollection::OpenIteratorState* state, TRI_voc_fid_t fid) {
OpenIteratorState* state, TRI_voc_fid_t fid) {
auto it = state->_stats.find(fid);

if (it != state->_stats.end()) {
Expand Down Expand Up @@ -216,7 +260,7 @@ PhysicalCollection* MMFilesCollection::clone(LogicalCollection& logical) const {
/// @brief process a document (or edge) marker when opening a collection
int MMFilesCollection::OpenIteratorHandleDocumentMarker(
MMFilesMarker const* marker, MMFilesDatafile* datafile,
MMFilesCollection::OpenIteratorState* state) {
OpenIteratorState* state) {
LogicalCollection* collection = state->_collection;
TRI_ASSERT(collection != nullptr);
auto physical = static_cast<MMFilesCollection*>(collection->getPhysical());
Expand Down Expand Up @@ -265,7 +309,7 @@ int MMFilesCollection::OpenIteratorHandleDocumentMarker(
// no primary index lock required here because we are the only ones reading
// from the index ATM
MMFilesSimpleIndexElement* found =
state->_primaryIndex->lookupKeyRef(trx, keySlice, state->_mmdr);
state->_primaryIndex->lookupKeyRef(trx, keySlice, state->_mdr);

// it is a new entry
if (found == nullptr || !found->isSet()) {
Expand All @@ -274,7 +318,7 @@ int MMFilesCollection::OpenIteratorHandleDocumentMarker(
// insert into primary index
Result res = state->_primaryIndex->insertKey(trx, localDocumentId,
VPackSlice(vpack),
state->_mmdr,
state->_mdr,
Index::OperationMode::normal);

if (res.fail()) {
Expand Down Expand Up @@ -336,7 +380,7 @@ int MMFilesCollection::OpenIteratorHandleDocumentMarker(
/// @brief process a deletion marker when opening a collection
int MMFilesCollection::OpenIteratorHandleDeletionMarker(
MMFilesMarker const* marker, MMFilesDatafile* datafile,
MMFilesCollection::OpenIteratorState* state) {
OpenIteratorState* state) {
LogicalCollection* collection = state->_collection;
TRI_ASSERT(collection != nullptr);
auto physical = static_cast<MMFilesCollection*>(collection->getPhysical());
Expand Down Expand Up @@ -371,7 +415,7 @@ int MMFilesCollection::OpenIteratorHandleDeletionMarker(
// no primary index lock required here because we are the only ones reading
// from the index ATM
MMFilesSimpleIndexElement found =
state->_primaryIndex->lookupKey(trx, keySlice, state->_mmdr);
state->_primaryIndex->lookupKey(trx, keySlice, state->_mdr);

// it is a new entry, so we missed the create
if (!found) {
Expand Down Expand Up @@ -407,7 +451,7 @@ int MMFilesCollection::OpenIteratorHandleDeletionMarker(
state->_dfi->numberDeletions++;

state->_primaryIndex->removeKey(trx, oldLocalDocumentId, VPackSlice(vpack),
state->_mmdr, Index::OperationMode::normal);
state->_mdr, Index::OperationMode::normal);

physical->removeLocalDocumentId(oldLocalDocumentId, true);
}
Expand All @@ -417,7 +461,7 @@ int MMFilesCollection::OpenIteratorHandleDeletionMarker(

/// @brief iterator for open
bool MMFilesCollection::OpenIterator(MMFilesMarker const* marker,
MMFilesCollection::OpenIteratorState* data,
OpenIteratorState* data,
MMFilesDatafile* datafile) {
TRI_voc_tick_t const tick = marker->getTick();
MMFilesMarkerType const type = marker->getType();
Expand All @@ -434,15 +478,8 @@ bool MMFilesCollection::OpenIterator(MMFilesMarker const* marker,
if (tick > datafile->_dataMax) {
datafile->_dataMax = tick;
}

if (++data->_operations % 1024 == 0) {
data->_mmdr.reset();
}
} else if (type == TRI_DF_MARKER_VPACK_REMOVE) {
res = OpenIteratorHandleDeletionMarker(marker, datafile, data);
if (++data->_operations % 1024 == 0) {
data->_mmdr.reset();
}
} else {
if (type == TRI_DF_MARKER_HEADER) {
// ensure there is a datafile info entry for each datafile of the
Expand Down Expand Up @@ -3290,7 +3327,7 @@ Result MMFilesCollection::update(

if (newSlice.length() <= 1) {
// no need to do anything
result = std::move(previous);
result = previous;

if (_logicalCollection.waitForSync()) {
options.waitForSync = true;
Expand Down
50 changes: 2 additions & 48 deletions arangod/MMFiles/MMFilesCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,17 @@
#include "VocBase/KeyGenerator.h"
#include "VocBase/LocalDocumentId.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/ManagedDocumentResult.h"

struct MMFilesDatafile;
struct MMFilesMarker;

namespace arangodb {


class LogicalCollection;
class ManagedDocumentResult;
struct MMFilesDocumentOperation;
class MMFilesPrimaryIndex;
class MMFilesWalMarker;
struct OpenIteratorState;
class Result;
class TransactionState;

Expand All @@ -72,51 +70,7 @@ class MMFilesCollection final : public PhysicalCollection {
TRI_ASSERT(phys != nullptr);
return toMMFilesCollection(phys);
}

/// @brief state during opening of a collection
struct OpenIteratorState {
LogicalCollection* _collection;
arangodb::MMFilesPrimaryIndex* _primaryIndex;
TRI_voc_tid_t _tid;
TRI_voc_fid_t _fid;
std::unordered_map<TRI_voc_fid_t, MMFilesDatafileStatisticsContainer*>
_stats;
MMFilesDatafileStatisticsContainer* _dfi;
transaction::Methods* _trx;
ManagedDocumentResult _mmdr;
IndexLookupContext _context;
uint64_t _deletions;
uint64_t _documents;
uint64_t _operations;
int64_t _initialCount;

OpenIteratorState(LogicalCollection* collection, transaction::Methods* trx)
: _collection(collection),
_primaryIndex(
static_cast<MMFilesCollection*>(collection->getPhysical())
->primaryIndex()),
_tid(0),
_fid(0),
_stats(),
_dfi(nullptr),
_trx(trx),
_mmdr(),
_context(trx, collection, &_mmdr, 1),
_deletions(0),
_documents(0),
_operations(0),
_initialCount(-1) {
TRI_ASSERT(collection != nullptr);
TRI_ASSERT(trx != nullptr);
}

~OpenIteratorState() {
for (auto& it : _stats) {
delete it.second;
}
}
};


struct DatafileDescription {
MMFilesDatafile const* _data;
TRI_voc_tick_t _dataMin;
Expand Down
11 changes: 6 additions & 5 deletions arangod/MMFiles/MMFilesCollectionKeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "Utils/SingleCollectionTransaction.h"
#include "Transaction/StandaloneContext.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/ManagedDocumentResult.h"
#include "VocBase/vocbase.h"

#include <velocypack/Builder.h>
Expand Down Expand Up @@ -110,13 +111,13 @@ void MMFilesCollectionKeys::create(TRI_voc_tick_t maxTick) {
THROW_ARANGO_EXCEPTION(res);
}

ManagedDocumentResult mmdr;
MMFilesCollection *mmColl = MMFilesCollection::toMMFilesCollection(_collection);
ManagedDocumentResult mdr;
MMFilesCollection* mmColl = MMFilesCollection::toMMFilesCollection(_collection);

trx.invokeOnAllElements(
_collection->name(), [this, &trx, &maxTick, &mmdr, &mmColl](LocalDocumentId const& token) {
if (mmColl->readDocumentConditional(&trx, token, maxTick, mmdr)) {
_vpack.emplace_back(mmdr.vpack());
_collection->name(), [this, &trx, &maxTick, &mdr, &mmColl](LocalDocumentId const& token) {
if (mmColl->readDocumentConditional(&trx, token, maxTick, mdr)) {
_vpack.emplace_back(mdr.vpack());
}
return true;
});
Expand Down
19 changes: 10 additions & 9 deletions arangod/MMFiles/MMFilesEdgeIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "Transaction/Methods.h"
#include "Utils/CollectionNameResolver.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/ManagedDocumentResult.h"

#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
Expand All @@ -55,12 +56,12 @@ static std::vector<std::vector<arangodb::basics::AttributeName>> const

MMFilesEdgeIndexIterator::MMFilesEdgeIndexIterator(
LogicalCollection* collection, transaction::Methods* trx,
ManagedDocumentResult* mmdr, arangodb::MMFilesEdgeIndex const* index,
ManagedDocumentResult* mdr, arangodb::MMFilesEdgeIndex const* index,
TRI_MMFilesEdgeIndexHash_t const* indexImpl,
std::unique_ptr<VPackBuilder> keys)
: IndexIterator(collection, trx),
_index(indexImpl),
_context(trx, collection, mmdr, index->fields().size()),
_context(trx, collection, mdr, index->fields().size()),
_keys(std::move(keys)),
_iterator(_keys->slice()),
_posInBuffer(0),
Expand Down Expand Up @@ -419,7 +420,7 @@ bool MMFilesEdgeIndex::supportsFilterCondition(

/// @brief creates an IndexIterator for the given Condition
IndexIterator* MMFilesEdgeIndex::iteratorForCondition(
transaction::Methods* trx, ManagedDocumentResult* mmdr,
transaction::Methods* trx, ManagedDocumentResult* mdr,
arangodb::aql::AstNode const* node,
arangodb::aql::Variable const* reference,
IndexIteratorOptions const& opts) {
Expand All @@ -442,7 +443,7 @@ IndexIterator* MMFilesEdgeIndex::iteratorForCondition(

if (comp->type == aql::NODE_TYPE_OPERATOR_BINARY_EQ) {
// a.b == value
return createEqIterator(trx, mmdr, attrNode, valNode);
return createEqIterator(trx, mdr, attrNode, valNode);
}

if (comp->type == aql::NODE_TYPE_OPERATOR_BINARY_IN) {
Expand All @@ -452,7 +453,7 @@ IndexIterator* MMFilesEdgeIndex::iteratorForCondition(
return new EmptyIndexIterator(&_collection, trx);
}

return createInIterator(trx, mmdr, attrNode, valNode);
return createInIterator(trx, mdr, attrNode, valNode);
}

// operator type unsupported
Expand All @@ -469,7 +470,7 @@ arangodb::aql::AstNode* MMFilesEdgeIndex::specializeCondition(

/// @brief create the iterator
IndexIterator* MMFilesEdgeIndex::createEqIterator(
transaction::Methods* trx, ManagedDocumentResult* mmdr,
transaction::Methods* trx, ManagedDocumentResult* mdr,
arangodb::aql::AstNode const* attrNode,
arangodb::aql::AstNode const* valNode) const {
// lease builder, but immediately pass it to the unique_ptr so we don't leak
Expand All @@ -489,7 +490,7 @@ IndexIterator* MMFilesEdgeIndex::createEqIterator(
return new MMFilesEdgeIndexIterator(
&_collection,
trx,
mmdr,
mdr,
this,
isFrom ? _edgesFrom.get() : _edgesTo.get(),
std::move(keys)
Expand All @@ -498,7 +499,7 @@ IndexIterator* MMFilesEdgeIndex::createEqIterator(

/// @brief create the iterator
IndexIterator* MMFilesEdgeIndex::createInIterator(
transaction::Methods* trx, ManagedDocumentResult* mmdr,
transaction::Methods* trx, ManagedDocumentResult* mdr,
arangodb::aql::AstNode const* attrNode,
arangodb::aql::AstNode const* valNode) const {
// lease builder, but immediately pass it to the unique_ptr so we don't leak
Expand All @@ -525,7 +526,7 @@ IndexIterator* MMFilesEdgeIndex::createInIterator(
return new MMFilesEdgeIndexIterator(
&_collection,
trx,
mmdr,
mdr,
this,
isFrom ? _edgesFrom.get() : _edgesTo.get(),
std::move(keys)
Expand Down
1 change: 1 addition & 0 deletions arangod/MMFiles/MMFilesHashIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "Transaction/Context.h"
#include "Transaction/Helpers.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/ManagedDocumentResult.h"

#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
Expand Down
Loading
0