1
0
Fork 0

issue 511.5: remove cid from IResearchPrimaryKey since iresearch data-stores are per-collction, minor code cleanup (#7803)

* issue 511.5: remove cid from IResearchPrimaryKey since iresearch data-stores are per-collction, minr code cleanup

* get rid of CID field in a document

* make ArangoSearch PK encoding/decoding logic explicit
This commit is contained in:
Vasiliy 2018-12-19 16:10:58 +03:00 committed by Andrey Abramov
parent ac3a8a3f0b
commit 00a4c34576
15 changed files with 338 additions and 509 deletions

View File

@ -40,7 +40,6 @@
#include "search/term_filter.hpp"
#include "utils/log.hpp"
#include "utils/numeric_utils.hpp"
NS_LOCAL
@ -301,44 +300,15 @@ NS_BEGIN(iresearch)
// --SECTION-- Field implementation
// ----------------------------------------------------------------------------
/*static*/ void Field::setCidValue(
Field& field,
TRI_voc_cid_t const& cid
) {
TRI_ASSERT(field._analyzer);
irs::bytes_ref const cidRef(
reinterpret_cast<irs::byte_type const*>(&cid),
sizeof(TRI_voc_cid_t)
);
field._name = CID_FIELD;
field._features = &irs::flags::empty_instance();
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
auto& sstream = dynamic_cast<irs::string_token_stream&>(*field._analyzer);
#else
auto& sstream = static_cast<irs::string_token_stream&>(*field._analyzer);
#endif
sstream.reset(cidRef);
}
/*static*/ void Field::setCidValue(
Field& field,
TRI_voc_cid_t const& cid,
Field::init_stream_t
) {
field._analyzer = StringStreamPool.emplace().release(); // FIXME don't use shared_ptr
setCidValue(field, cid);
}
/*static*/ void Field::setPkValue(
Field& field,
DocumentPrimaryKey const& pk
LocalDocumentId::BaseType const& pk
) {
field._name = PK_COLUMN;
field._features = &irs::flags::empty_instance();
field._storeValues = ValueStorage::FULL;
field._value = irs::bytes_ref(reinterpret_cast<irs::byte_type const*>(&pk), sizeof(pk));
field._analyzer = StringStreamPool.emplace().release(); // FIXME don't use shared_ptr
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
auto& sstream = dynamic_cast<irs::string_token_stream&>(*field._analyzer);
#else
@ -347,15 +317,6 @@ NS_BEGIN(iresearch)
sstream.reset(field._value);
}
/*static*/ void Field::setPkValue(
Field& field,
DocumentPrimaryKey const& pk,
Field::init_stream_t
) {
field._analyzer = StringStreamPool.emplace().release(); // FIXME don't use shared_ptr
setPkValue(field, pk);
}
Field::Field(Field&& rhs)
: _features(rhs._features),
_analyzer(std::move(rhs._analyzer)),
@ -689,60 +650,30 @@ void FieldIterator::next() {
return PK_COLUMN;
}
/* static */ irs::string_ref const& DocumentPrimaryKey::CID() noexcept {
return CID_FIELD;
}
/*static*/ irs::filter::ptr DocumentPrimaryKey::filter(TRI_voc_cid_t cid) {
cid = PrimaryKeyEndianness<Endianness>::hostToPk(cid);
irs::bytes_ref const term(
reinterpret_cast<irs::byte_type const*>(&cid),
sizeof(cid)
);
auto filter = irs::by_term::make();
// filter matching on cid
static_cast<irs::by_term&>(*filter)
.field(CID_FIELD) // set field
.term(term); // set value
return filter;
}
/*static*/ irs::filter::ptr DocumentPrimaryKey::filter(
TRI_voc_cid_t cid,
TRI_voc_rid_t rid
) {
return std::make_unique<PrimaryKeyFilter>(cid, rid);
/*static*/ LocalDocumentId::BaseType DocumentPrimaryKey::encode(LocalDocumentId value) noexcept {
return PrimaryKeyEndianness<Endianness>::hostToPk(value.id());
}
// PLEASE NOTE that 'in.c_str()' MUST HAVE alignment >= alignof(uint64_t)
/*static*/ bool DocumentPrimaryKey::read(type& value, irs::bytes_ref const& in) noexcept {
if (sizeof(type) != in.size()) {
// NOTE implementation must match implementation of operator irs::bytes_ref()
/*static*/ bool DocumentPrimaryKey::read(
arangodb::LocalDocumentId& value,
irs::bytes_ref const& in
) noexcept {
if (sizeof(arangodb::LocalDocumentId::BaseType) != in.size()) {
return false;
}
static_assert(
sizeof(TRI_voc_cid_t) == sizeof(TRI_voc_rid_t),
"sizeof(TRI_voc_cid_t) != sizeof(TRI_voc_rid_t)"
// PLEASE NOTE that 'in.c_str()' MUST HAVE alignment >= alignof(uint64_t)
value = arangodb::LocalDocumentId(
PrimaryKeyEndianness<Endianness>::pkToHost(
*reinterpret_cast<arangodb::LocalDocumentId::BaseType const*>(in.c_str())
)
);
// PLEASE NOTE that 'in.c_str()' MUST HAVE alignment >= alignof(uint64_t)
auto* begin = reinterpret_cast<TRI_voc_cid_t const*>(in.c_str());
value.first = PrimaryKeyEndianness<Endianness>::pkToHost(begin[0]);
value.second = PrimaryKeyEndianness<Endianness>::pkToHost(begin[1]);
return true;
}
DocumentPrimaryKey::DocumentPrimaryKey(TRI_voc_cid_t cid, TRI_voc_rid_t rid) noexcept
: type(PrimaryKeyEndianness<Endianness>::hostToPk(cid),
PrimaryKeyEndianness<Endianness>::hostToPk(rid)) {
}
NS_END // iresearch
NS_END // arangodb

View File

@ -31,6 +31,7 @@
#include "search/filter.hpp"
#include "store/data_output.hpp"
#include "VocBase/LocalDocumentId.h"
NS_BEGIN(iresearch)
@ -79,18 +80,12 @@ constexpr char const NESTING_LIST_OFFSET_PREFIX = '[';
constexpr char const NESTING_LIST_OFFSET_SUFFIX = ']';
struct IResearchViewMeta; // forward declaration
struct DocumentPrimaryKey; // forward declaration
////////////////////////////////////////////////////////////////////////////////
/// @brief indexed/stored document field adapter for IResearch
////////////////////////////////////////////////////////////////////////////////
struct Field {
struct init_stream_t{}; // initialize stream
static void setCidValue(Field& field, TRI_voc_cid_t const& cid);
static void setCidValue(Field& field, TRI_voc_cid_t const& cid, init_stream_t);
static void setPkValue(Field& field, DocumentPrimaryKey const& pk);
static void setPkValue(Field& field, DocumentPrimaryKey const& pk, init_stream_t);
static void setPkValue(Field& field, LocalDocumentId::BaseType const& pk);
Field() = default;
Field(Field&& rhs);
@ -255,43 +250,23 @@ class FieldIterator : public std::iterator<std::forward_iterator_tag, Field cons
////////////////////////////////////////////////////////////////////////////////
/// @brief represents stored primary key of the ArangoDB document
////////////////////////////////////////////////////////////////////////////////
struct DocumentPrimaryKey : std::pair<TRI_voc_cid_t, TRI_voc_rid_t> {
typedef std::pair<TRI_voc_cid_t, TRI_voc_rid_t> type; // underlying PK type
struct DocumentPrimaryKey {
static irs::string_ref const& PK() noexcept; // stored primary key column
static irs::string_ref const& CID() noexcept; // stored collection id column
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a filter matching 'cid'
/// @brief encodes a specified PK value
/// @returns encoded value
////////////////////////////////////////////////////////////////////////////////
static irs::filter::ptr filter(TRI_voc_cid_t cid);
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a filter matching 'cid' + 'rid' pair
////////////////////////////////////////////////////////////////////////////////
static irs::filter::ptr filter(TRI_voc_cid_t cid, TRI_voc_rid_t rid);
static LocalDocumentId::BaseType encode(LocalDocumentId value) noexcept;
////////////////////////////////////////////////////////////////////////////////
/// @brief reads and decodes PK from a specified buffer
/// @returns 'true' on success, 'false' otherwise
/// @note PLEASE NOTE that 'in.c_str()' MUST HAVE alignment >= alignof(uint64_t)
////////////////////////////////////////////////////////////////////////////////
static bool read(type& value, irs::bytes_ref const& in) noexcept;
static bool read(LocalDocumentId& value, irs::bytes_ref const& in) noexcept;
////////////////////////////////////////////////////////////////////////////////
/// @brief creates PK with properly encoded cid & rid
////////////////////////////////////////////////////////////////////////////////
DocumentPrimaryKey(TRI_voc_cid_t cid, TRI_voc_rid_t rid) noexcept;
////////////////////////////////////////////////////////////////////////////////
/// @brief coverts a PK to corresponding irs::bytes_ref
////////////////////////////////////////////////////////////////////////////////
explicit operator irs::bytes_ref() const noexcept {
return irs::bytes_ref(
reinterpret_cast<irs::byte_type const*>(this),
sizeof(*this)
);
}
DocumentPrimaryKey() = delete;
}; // DocumentPrimaryKey
NS_END // iresearch

View File

@ -92,8 +92,8 @@ struct LinkTrxState final: public arangodb::TransactionState::Cookie {
return _ctx;
}
void remove(TRI_voc_cid_t cid, TRI_voc_rid_t rid) {
_ctx.remove(_removals.emplace(cid, rid));
void remove(arangodb::LocalDocumentId const& value) {
_ctx.remove(_removals.emplace(value));
}
void reset() noexcept {
@ -170,7 +170,7 @@ inline void insertDocument(
irs::segment_writer::document& doc,
arangodb::iresearch::FieldIterator& body,
TRI_voc_cid_t cid,
TRI_voc_rid_t rid) {
arangodb::LocalDocumentId const& docPk) {
using namespace arangodb::iresearch;
// reuse the 'Field' instance stored
@ -189,15 +189,11 @@ inline void insertDocument(
}
// System fields
DocumentPrimaryKey const primaryKey(cid, rid);
// Indexed and Stored: CID + RID
Field::setPkValue(field, primaryKey, Field::init_stream_t());
// Indexed and Stored: LocalDocumentId
auto const primaryKey = DocumentPrimaryKey::encode(docPk);
Field::setPkValue(field, primaryKey);
doc.insert(irs::action::index_store, field);
// Indexed: CID
Field::setCidValue(field, primaryKey.first);
doc.insert(irs::action::index, field);
}
NS_END
@ -351,7 +347,7 @@ void IResearchLink::batchInsert(
if (_inRecovery) {
for (auto const& doc: batch) {
ctx->remove(_collection.id(), doc.first.id());
ctx->remove(doc.first);
}
}
@ -368,7 +364,7 @@ void IResearchLink::batchInsert(
auto doc = ctx->_ctx.insert();
insertDocument(doc, body, _collection.id(), begin->first.id());
insertDocument(doc, body, _collection.id(), begin->first);
if (!doc) {
LOG_TOPIC(WARN, arangodb::iresearch::TOPIC)
@ -443,7 +439,7 @@ arangodb::Result IResearchLink::commit() {
arangodb::aql::QueryCache::instance()->invalidate(
&(_collection.vocbase()), viewImpl->name()
);
}
}
} catch (arangodb::basics::Exception const& e) {
return arangodb::Result(
e.code(),
@ -637,16 +633,16 @@ arangodb::Result IResearchLink::init(
auto& vocbase = _collection.vocbase();
if (arangodb::ServerState::instance()->isCoordinator()) { // coordinator link
auto* engine = arangodb::ClusterInfo::instance();
auto* ci = arangodb::ClusterInfo::instance();
if (!engine) {
if (!ci) {
return arangodb::Result(
TRI_ERROR_INTERNAL,
std::string("failure to get storage engine while initializing arangosearch link '") + std::to_string(_id) + "'"
);
}
auto logicalView = engine->getView(vocbase.name(), viewId);
auto logicalView = ci->getView(vocbase.name(), viewId);
// if there is no logicalView present yet then skip this step
if (logicalView) {
@ -687,7 +683,7 @@ arangodb::Result IResearchLink::init(
);
}
auto clusterWideLink = _collection.id() == _collection.planId() && _collection.isAStub(); // cluster cluster-wide link
auto clusterWideLink = _collection.id() == _collection.planId() && _collection.isAStub(); // cluster-wide link
if (!clusterWideLink) {
auto res = initDataStore(); // prepare data-store which can then update options via the IResearchView::link(...) call
@ -697,7 +693,7 @@ arangodb::Result IResearchLink::init(
}
}
auto logicalView = engine->getView(vocbase.name(), viewId); // valid to call ClusterInfo (initialized in ClusterFFeature::prepare()) even from Databasefeature::start()
auto logicalView = engine->getView(vocbase.name(), viewId); // valid to call ClusterInfo (initialized in ClusterFeature::prepare()) even from Databasefeature::start()
// if there is no logicalView present yet then skip this step
if (logicalView) {
@ -980,7 +976,7 @@ arangodb::Result IResearchLink::insert(
}
if (_inRecovery) {
ctx->remove(_collection.id(), documentId.id());
ctx->remove(documentId);
}
try {
@ -992,7 +988,7 @@ arangodb::Result IResearchLink::insert(
auto doc = ctx->_ctx.insert();
insertDocument(doc, body, _collection.id(), documentId.id());
insertDocument(doc, body, _collection.id(), documentId);
if (!doc) {
return arangodb::Result(
@ -1161,7 +1157,7 @@ arangodb::Result IResearchLink::remove(
// all of its fid stores, no impact to iResearch View data integrity
// ...........................................................................
try {
ctx->remove(_collection.id(), documentId.id());
ctx->remove(documentId);
return TRI_ERROR_NO_ERROR;
} catch (arangodb::basics::Exception const& e) {

View File

@ -150,12 +150,12 @@ void IResearchLinkCoordinator::toVelocyPack(
}
if (arangodb::Index::hasFlag(flags, arangodb::Index::Serialize::Figures)) {
VPackBuilder figuresBuilder;
figuresBuilder.openObject();
toVelocyPackFigures(figuresBuilder);
figuresBuilder.close();
builder.add("figures", figuresBuilder.slice());
builder.add(
"figures",
arangodb::velocypack::Value(arangodb::velocypack::ValueType::Object)
);
toVelocyPackFigures(builder);
builder.close();
}
builder.close();

View File

@ -27,6 +27,7 @@
#include "index/index_reader.hpp"
#include "utils/hash_utils.hpp"
#include "utils/numeric_utils.hpp"
namespace {
@ -47,7 +48,7 @@ irs::doc_iterator::ptr PrimaryKeyFilter::execute(
irs::order::prepared const& /*order*/,
irs::attribute_view const& /*ctx*/
) const {
TRI_ASSERT(_pk.first); // re-execution of a fiter is not expected to ever occur without a call to prepare(...)
TRI_ASSERT(!_pkSeen); // re-execution of a fiter is not expected to ever occur without a call to prepare(...)
auto* pkField = segment.field(arangodb::iresearch::DocumentPrimaryKey::PK());
if (!pkField) {
@ -57,7 +58,9 @@ irs::doc_iterator::ptr PrimaryKeyFilter::execute(
auto term = pkField->iterator();
if (!term->seek(static_cast<irs::bytes_ref>(_pk))) {
auto const pkRef = irs::numeric_utils::numeric_traits<LocalDocumentId::BaseType>::raw_ref(_pk);
if (!term->seek(pkRef)) {
// no such term
return irs::doc_iterator::empty();
}
@ -75,7 +78,7 @@ irs::doc_iterator::ptr PrimaryKeyFilter::execute(
// * recovery should have at most 2 identical live primary keys in the entire datastore
if (irs::filter::type() == typeDefault) { // explicitly check type of instance
TRI_ASSERT(!docs->next()); // primary key duplicates should NOT happen in the same segment in regular runtime
_pk.first = 0; // already matched 1 primary key (should be at most 1 at runtime)
_pkSeen = true; // already matched 1 primary key (should be at most 1 at runtime)
}
// aliasing constructor
@ -87,9 +90,10 @@ irs::doc_iterator::ptr PrimaryKeyFilter::execute(
size_t PrimaryKeyFilter::hash() const noexcept {
size_t seed = 0;
irs::hash_combine(seed, filter::hash());
irs::hash_combine(seed, _pk.first);
irs::hash_combine(seed, _pk.second);
irs::hash_combine(seed, _pk);
return seed;
}
@ -102,7 +106,7 @@ irs::filter::prepared::ptr PrimaryKeyFilter::prepare(
// optimization, since during:
// * regular runtime should have at most 1 identical primary key in the entire datastore
// * recovery should have at most 2 identical primary keys in the entire datastore
if (!_pk.first) {
if (_pkSeen) {
return irs::filter::prepared::empty(); // already processed
}
@ -111,18 +115,14 @@ irs::filter::prepared::ptr PrimaryKeyFilter::prepare(
}
bool PrimaryKeyFilter::equals(filter const& rhs) const noexcept {
auto const& trhs = static_cast<PrimaryKeyFilter const&>(rhs);
return filter::equals(rhs)
&& _pk.first == trhs._pk.first
&& _pk.second == trhs._pk.second;
&& _pk == static_cast<PrimaryKeyFilter const&>(rhs)._pk;
}
/*static*/ ::iresearch::type_id const& PrimaryKeyFilter::type() {
return arangodb::EngineSelectorFeature::ENGINE
&& arangodb::EngineSelectorFeature::ENGINE->inRecovery()
? typeRecovery : typeDefault
;
? typeRecovery : typeDefault;
}
} // iresearch

View File

@ -43,9 +43,10 @@ class PrimaryKeyFilter final
public:
DECLARE_FILTER_TYPE();
PrimaryKeyFilter(TRI_voc_cid_t cid, TRI_voc_rid_t id) noexcept
explicit PrimaryKeyFilter(arangodb::LocalDocumentId const& value) noexcept
: irs::filter(PrimaryKeyFilter::type()),
_pk(cid, id) { // ensure proper endianness
_pk(DocumentPrimaryKey::encode(value)),
_pkSeen(false) {
}
// ----------------------------------------------------------------------------
@ -110,8 +111,9 @@ class PrimaryKeyFilter final
mutable irs::doc_id_t _next{ irs::type_limits<irs::type_t::doc_id_t>::eof() };
}; // PrimaryKeyIterator
mutable DocumentPrimaryKey _pk; // !_pk.first -> do not perform further execution (first-match optimization)
mutable LocalDocumentId::BaseType _pk;
mutable PrimaryKeyIterator _pkIterator;
mutable bool _pkSeen; // true == do not perform further execution (first-match optimization)
}; // PrimaryKeyFilter
///////////////////////////////////////////////////////////////////////////////
@ -126,8 +128,8 @@ class PrimaryKeyFilterContainer final : public irs::empty {
PrimaryKeyFilterContainer(PrimaryKeyFilterContainer&&) = default;
PrimaryKeyFilterContainer& operator=(PrimaryKeyFilterContainer&&) = default;
PrimaryKeyFilter& emplace(TRI_voc_cid_t cid, TRI_voc_rid_t rid) {
_filters.emplace_back(cid, rid);
PrimaryKeyFilter& emplace(arangodb::LocalDocumentId const& value) {
_filters.emplace_back(value);
return _filters.back();
}

View File

@ -62,13 +62,14 @@ typedef irs::async_utils::read_write_mutex::write_mutex WriteMutex;
/// lock is not required to be held by the DBServer CompoundReader
////////////////////////////////////////////////////////////////////////////////
class ViewTrxState final
: public arangodb::TransactionState::Cookie, public irs::index_reader {
: public arangodb::TransactionState::Cookie,
public arangodb::iresearch::IResearchView::Snapshot {
public:
irs::sub_reader const& operator[](
size_t subReaderId
) const noexcept override {
TRI_ASSERT(subReaderId < _subReaders.size());
return *(_subReaders[subReaderId]);
return *(_subReaders[subReaderId].second);
}
void add(
@ -76,6 +77,10 @@ class ViewTrxState final
arangodb::iresearch::IResearchLink::Snapshot&& snapshot
);
TRI_voc_cid_t cid(size_t offset) const noexcept override {
return offset < _subReaders.size() ? _subReaders[offset].first : 0;
}
void clear() noexcept {
_collections.clear();
_subReaders.clear();
@ -103,7 +108,7 @@ class ViewTrxState final
private:
std::unordered_set<TRI_voc_cid_t> _collections;
std::vector<arangodb::iresearch::IResearchLink::Snapshot> _snapshots; // prevent data-store deallocation (lock @ AsyncSelf)
std::vector<irs::sub_reader const*> _subReaders;
std::vector<std::pair<TRI_voc_cid_t, irs::sub_reader const*>> _subReaders;
};
void ViewTrxState::add(
@ -111,7 +116,11 @@ void ViewTrxState::add(
arangodb::iresearch::IResearchLink::Snapshot&& snapshot
) {
for(auto& entry: static_cast<irs::index_reader const&>(snapshot)) {
_subReaders.emplace_back(&entry);
_subReaders.emplace_back(
std::piecewise_construct,
std::forward_as_tuple(cid),
std::forward_as_tuple(&entry)
);
}
_collections.emplace(cid);
@ -122,7 +131,8 @@ uint64_t ViewTrxState::docs_count() const {
uint64_t count = 0;
for (auto& entry: _subReaders) {
count += entry->docs_count();
TRI_ASSERT(entry.second); // non-nullptr ensured by add(...)
count += entry.second->docs_count();
}
return count;
@ -132,7 +142,8 @@ uint64_t ViewTrxState::live_docs_count() const {
uint64_t count = 0;
for (auto& entry: _subReaders) {
count += entry->live_docs_count();
TRI_ASSERT(entry.second); // non-nullptr ensured by add(...)
count += entry.second->live_docs_count();
}
return count;
@ -253,7 +264,8 @@ struct IResearchView::ViewFactory: public arangodb::ViewFactory {
if (!impl->_meta.init(definition, error)
|| impl->_meta._version == 0 // version 0 must be upgraded to split data-store on a per-link basis
|| impl->_meta._version > LATEST_VERSION
|| !metaState.init(definition, error)) {
|| (ServerState::instance()->isSingleServer() // init metaState for SingleServer
&& !metaState.init(definition, error))) {
return arangodb::Result(
TRI_ERROR_BAD_PARAMETER,
error.empty()
@ -264,7 +276,6 @@ struct IResearchView::ViewFactory: public arangodb::ViewFactory {
// NOTE: for single-server must have full list of collections to lock
// for cluster the shards to lock come from coordinator and are not in the definition
if (ServerState::instance()->isSingleServer()) {
for (auto cid: metaState._collections) {
auto collection = vocbase.lookupCollection(cid); // always look up in vocbase (single server or cluster per-shard collection)
auto link =
@ -272,7 +283,6 @@ struct IResearchView::ViewFactory: public arangodb::ViewFactory {
impl->_links.emplace(cid, link ? link->self() : nullptr); // add placeholders to links, when the link comes up it'll call link(...)
}
}
view = impl;
@ -413,7 +423,7 @@ IResearchView::IResearchView(
// populate snapshot when view is registred with a transaction on single-server
if (view && arangodb::ServerState::instance()->isSingleServer()) {
view->snapshot(trx, IResearchView::Snapshot::FindOrCreate);
view->snapshot(trx, IResearchView::SnapshotMode::FindOrCreate);
}
};
}
@ -933,9 +943,9 @@ arangodb::Result IResearchView::renameImpl(std::string const& oldName) {
;
}
irs::index_reader const* IResearchView::snapshot(
IResearchView::Snapshot const* IResearchView::snapshot(
transaction::Methods& trx,
IResearchView::Snapshot mode /*= IResearchView::Snapshot::Find*/,
IResearchView::SnapshotMode mode /*= IResearchView::SnapshotMode::Find*/,
std::unordered_set<TRI_voc_cid_t> const* shards /*= nullptr*/
) const {
if (!trx.state()) {
@ -966,15 +976,15 @@ irs::index_reader const* IResearchView::snapshot(
#endif
switch (mode) {
case Snapshot::Find:
case SnapshotMode::Find:
return ctx && ctx->equalCollections(collections.begin(), collections.end())
? ctx : nullptr; // ensure same collections
case Snapshot::FindOrCreate:
case SnapshotMode::FindOrCreate:
if (ctx && ctx->equalCollections(collections.begin(), collections.end())) {
return ctx; // ensure same collections
}
break;
case Snapshot::SyncAndReplace: {
case SnapshotMode::SyncAndReplace: {
if (ctx) {
ctx->clear(); // ignore existing cookie, recreate snapshot
}

View File

@ -78,10 +78,18 @@ class IResearchView final
public arangodb::FlushTransaction {
typedef std::shared_ptr<TypedResourceMutex<IResearchLink>> AsyncLinkPtr;
public:
typedef std::shared_ptr<TypedResourceMutex<IResearchView>> AsyncViewPtr; // FIXME TODO move to private
//////////////////////////////////////////////////////////////////////////////
/// @brief a snapshot representation of the view with ability to query for cid
//////////////////////////////////////////////////////////////////////////////
class Snapshot: public irs::index_reader {
public:
// @return cid of the sub-reader at operator['offset'] or 0 if undefined
virtual TRI_voc_cid_t cid(size_t offset) const noexcept = 0;
};
/// @enum snapshot getting mode
enum class Snapshot {
enum class SnapshotMode {
/// @brief lookup existing snapshot from a transaction
Find,
@ -155,9 +163,9 @@ class IResearchView final
/// (nullptr == no view snapshot associated with the specified state)
/// if force == true && no snapshot -> associate current snapshot
////////////////////////////////////////////////////////////////////////////////
irs::index_reader const* snapshot(
Snapshot const* snapshot(
transaction::Methods& trx,
Snapshot mode = Snapshot::Find,
SnapshotMode mode = SnapshotMode::Find,
std::unordered_set<TRI_voc_cid_t> const* shards = nullptr
) const;
@ -198,6 +206,7 @@ class IResearchView final
arangodb::Result renameImpl(std::string const& oldName) override;
private:
typedef std::shared_ptr<TypedResourceMutex<IResearchView>> AsyncViewPtr;
struct ViewFactory; // forward declaration
struct FlushCallbackUnregisterer {

View File

@ -52,7 +52,7 @@
namespace {
typedef std::vector<arangodb::iresearch::DocumentPrimaryKey::type> pks_t;
typedef std::vector<arangodb::LocalDocumentId> pks_t;
pks_t::iterator readPKs(
irs::doc_iterator& it,
@ -87,6 +87,28 @@ inline irs::columnstore_reader::values_reader_f pkColumn(
: irs::columnstore_reader::values_reader_f{};
}
inline arangodb::LogicalCollection* lookupCollection(
arangodb::transaction::Methods& trx,
TRI_voc_cid_t cid
) {
TRI_ASSERT(trx.state());
// this is necessary for MMFiles
trx.pinData(cid);
// `Methods::documentCollection(TRI_voc_cid_t)` may throw exception
auto* collection = trx.state()->collection(cid, arangodb::AccessMode::Type::READ);
if (!collection) {
LOG_TOPIC(WARN, arangodb::iresearch::TOPIC)
<< "failed to find collection while reading document from arangosearch view, cid '" << cid << "'";
return nullptr; // not a valid collection reference
}
return collection->collection();
}
}
namespace arangodb {
@ -128,7 +150,7 @@ using namespace arangodb::aql;
}
IResearchViewBlockBase::IResearchViewBlockBase(
irs::index_reader const& reader,
IResearchView::Snapshot const& reader,
ExecutionEngine& engine,
IResearchViewNode const& en)
: ExecutionBlock(&engine, &en),
@ -217,40 +239,14 @@ void IResearchViewBlockBase::reset() {
}
bool IResearchViewBlockBase::readDocument(
DocumentPrimaryKey::type const& docPk,
IndexIterator::DocumentCallback const& callback
) {
TRI_ASSERT(_trx->state());
// this is necessary for MMFiles
_trx->pinData(docPk.first);
// `Methods::documentCollection(TRI_voc_cid_t)` may throw exception
auto* collection = _trx->state()->collection(docPk.first, arangodb::AccessMode::Type::READ);
if (!collection) {
LOG_TOPIC(WARN, arangodb::iresearch::TOPIC)
<< "failed to find collection while reading document from arangosearch view, cid '" << docPk.first
<< "', rid '" << docPk.second << "'";
return false; // not a valid collection reference
}
TRI_ASSERT(collection->collection());
return collection->collection()->readDocumentWithCallback(
_trx, arangodb::LocalDocumentId(docPk.second), callback
);
}
bool IResearchViewBlockBase::readDocument(
LogicalCollection const& collection,
irs::doc_id_t const docId,
irs::columnstore_reader::values_reader_f const& pkValues,
IndexIterator::DocumentCallback const& callback
) {
TRI_ASSERT(pkValues);
arangodb::iresearch::DocumentPrimaryKey::type docPk;
arangodb::LocalDocumentId docPk;
irs::bytes_ref tmpRef;
if (!pkValues(docId, tmpRef) || !arangodb::iresearch::DocumentPrimaryKey::read(docPk, tmpRef)) {
@ -260,27 +256,7 @@ bool IResearchViewBlockBase::readDocument(
return false; // not a valid document reference
}
TRI_ASSERT(_trx->state());
// this is necessary for MMFiles
_trx->pinData(docPk.first);
// `Methods::documentCollection(TRI_voc_cid_t)` may throw exception
auto* collection = _trx->state()->collection(docPk.first, arangodb::AccessMode::Type::READ);
if (!collection) {
LOG_TOPIC(WARN, arangodb::iresearch::TOPIC)
<< "failed to find collection while reading document from arangosearch view, cid '" << docPk.first
<< "', rid '" << docPk.second << "'";
return false; // not a valid collection reference
}
TRI_ASSERT(collection->collection());
return collection->collection()->readDocumentWithCallback(
_trx, arangodb::LocalDocumentId(docPk.second), callback
);
return collection.readDocumentWithCallback(_trx, docPk, callback);
}
std::pair<ExecutionState, std::unique_ptr<AqlItemBlock>>
@ -439,7 +415,7 @@ std::pair<ExecutionState, size_t> IResearchViewBlockBase::skipSome(size_t atMost
// -----------------------------------------------------------------------------
IResearchViewBlock::IResearchViewBlock(
irs::index_reader const& reader,
IResearchView::Snapshot const& reader,
aql::ExecutionEngine& engine,
IResearchViewNode const& node
): IResearchViewUnorderedBlock(reader, engine, node),
@ -484,10 +460,20 @@ bool IResearchViewBlock::next(
continue;
}
auto const cid = _reader.cid(_readerOffset); // CID is constant until resetIterator()
auto* collection = lookupCollection(*_trx, cid);
if (!collection) {
LOG_TOPIC(WARN, arangodb::iresearch::TOPIC)
<< "failed to find collection while reading document from arangosearch view, cid '" << cid << "'";
continue;
}
TRI_ASSERT(_pkReader);
while (limit && _itr->next()) {
if (!readDocument(_itr->value(), _pkReader, ctx.callback)) {
if (!readDocument(*collection, _itr->value(), _pkReader, ctx.callback)) {
continue;
}
@ -561,7 +547,7 @@ size_t IResearchViewBlock::skip(size_t limit) {
// -----------------------------------------------------------------------------
IResearchViewUnorderedBlock::IResearchViewUnorderedBlock(
irs::index_reader const& reader,
IResearchView::Snapshot const& reader,
aql::ExecutionEngine& engine,
IResearchViewNode const& node
): IResearchViewBlockBase(reader, engine, node), _readerOffset(0) {
@ -599,6 +585,16 @@ bool IResearchViewUnorderedBlock::next(
continue;
}
auto const cid = _reader.cid(_readerOffset); // CID is constant until resetIterator()
auto* collection = lookupCollection(*_trx, cid);
if (!collection) {
LOG_TOPIC(WARN, arangodb::iresearch::TOPIC)
<< "failed to find collection while reading document from arangosearch view, cid '" << cid << "'";
continue;
}
TRI_ASSERT(_pkReader);
// read document PKs from iresearch
@ -606,7 +602,7 @@ bool IResearchViewUnorderedBlock::next(
// read documents from underlying storage engine
for (auto begin = _keys.begin(); begin != end; ++begin) {
if (!readDocument(*begin, ctx.callback)) {
if (!collection->readDocumentWithCallback(_trx, *begin, ctx.callback)) {
continue;
}

View File

@ -52,7 +52,7 @@ class IResearchViewNode;
class IResearchViewBlockBase : public aql::ExecutionBlock {
public:
IResearchViewBlockBase(
irs::index_reader const& reader,
IResearchView::Snapshot const& reader,
aql::ExecutionEngine&,
IResearchViewNode const&
);
@ -83,16 +83,12 @@ class IResearchViewBlockBase : public aql::ExecutionBlock {
}; // ReadContext
bool readDocument(
LogicalCollection const& collection,
irs::doc_id_t docId,
irs::columnstore_reader::values_reader_f const& pkValues,
IndexIterator::DocumentCallback const& callback
);
bool readDocument(
DocumentPrimaryKey::type const& key,
IndexIterator::DocumentCallback const& callback
);
virtual void reset();
virtual bool next(
@ -102,10 +98,10 @@ class IResearchViewBlockBase : public aql::ExecutionBlock {
virtual size_t skip(size_t count) = 0;
std::vector<DocumentPrimaryKey::type> _keys; // buffer for primary keys
std::vector<arangodb::LocalDocumentId> _keys; // buffer for primary keys
irs::attribute_view _filterCtx; // filter context
ViewExpressionContext _ctx;
irs::index_reader const& _reader;
IResearchView::Snapshot const& _reader;
irs::filter::prepared::ptr _filter;
irs::order::prepared _order;
iresearch::ExpressionExecutionContext _execCtx; // expression execution context
@ -121,7 +117,7 @@ class IResearchViewBlockBase : public aql::ExecutionBlock {
class IResearchViewUnorderedBlock : public IResearchViewBlockBase {
public:
IResearchViewUnorderedBlock(
irs::index_reader const& reader,
IResearchView::Snapshot const& reader,
aql::ExecutionEngine& engine,
IResearchViewNode const& node
);
@ -156,7 +152,7 @@ class IResearchViewUnorderedBlock : public IResearchViewBlockBase {
class IResearchViewBlock final : public IResearchViewUnorderedBlock {
public:
IResearchViewBlock(
irs::index_reader const& reader,
IResearchView::Snapshot const& reader,
aql::ExecutionEngine& engine,
IResearchViewNode const& node
);

View File

@ -663,7 +663,7 @@ std::unique_ptr<aql::ExecutionBlock> IResearchViewNode::createBlock(
}
auto& view = *this->view();
irs::index_reader const* reader;
IResearchView::Snapshot const* reader;
LOG_TOPIC(TRACE, arangodb::iresearch::TOPIC)
<< "Start getting snapshot for view '" << view.name() << "'";
@ -671,9 +671,9 @@ std::unique_ptr<aql::ExecutionBlock> IResearchViewNode::createBlock(
if (ServerState::instance()->isDBServer()) {
// there are no cluster-wide transactions,
// no place to store snapshot
static IResearchView::Snapshot const SNAPSHOT[] {
IResearchView::Snapshot::FindOrCreate,
IResearchView::Snapshot::SyncAndReplace
static IResearchView::SnapshotMode const SNAPSHOT[] {
IResearchView::SnapshotMode::FindOrCreate,
IResearchView::SnapshotMode::SyncAndReplace
};
std::unordered_set<TRI_voc_cid_t> collections;
auto& resolver = engine.getQuery()->resolver();
@ -695,9 +695,9 @@ std::unique_ptr<aql::ExecutionBlock> IResearchViewNode::createBlock(
*trx, SNAPSHOT[size_t(_options.forceSync)], &collections
);
} else {
static IResearchView::Snapshot const SNAPSHOT[] {
IResearchView::Snapshot::Find,
IResearchView::Snapshot::SyncAndReplace
static IResearchView::SnapshotMode const SNAPSHOT[] {
IResearchView::SnapshotMode::Find,
IResearchView::SnapshotMode::SyncAndReplace
};
reader = LogicalView::cast<IResearchView>(view).snapshot(

View File

@ -217,37 +217,6 @@ TEST_CASE("IResearchDocumentTest", "[iresearch][iresearch-document]") {
IResearchDocumentSetup s;
UNUSED(s);
SECTION("Field_setCid") {
irs::flags features;
features.add<TestAttribute>();
arangodb::iresearch::Field field;
// reset field
field._features = &features;
field._analyzer = nullptr;
// check CID value
{
TRI_voc_cid_t cid = 10;
arangodb::iresearch::Field::setCidValue(field, cid, arangodb::iresearch::Field::init_stream_t());
CHECK(arangodb::iresearch::DocumentPrimaryKey::CID() == field._name);
CHECK(&irs::flags::empty_instance() == field._features);
auto* stream = dynamic_cast<irs::string_token_stream*>(field._analyzer.get());
REQUIRE(nullptr != stream);
CHECK(stream->next());
CHECK(!stream->next());
arangodb::iresearch::Field::setCidValue(field, cid);
CHECK(arangodb::iresearch::DocumentPrimaryKey::CID() == field._name);
CHECK(&irs::flags::empty_instance() == field._features);
CHECK(stream == field._analyzer.get());
CHECK(stream->next());
CHECK(!stream->next());
}
}
SECTION("FieldIterator_static_checks") {
static_assert(
std::is_same<
@ -1512,45 +1481,45 @@ SECTION("FieldIterator_nullptr_analyzer") {
}
}
SECTION("test_cid_rid_encoding") {
SECTION("test_rid_encoding") {
auto data = arangodb::velocypack::Parser::fromJson(
"[{ \"cid\": 62, \"rid\": 1605879230128717824},"
"{ \"cid\": 62, \"rid\": 1605879230128717826},"
"{ \"cid\": 62, \"rid\": 1605879230129766400},"
"{ \"cid\": 62, \"rid\": 1605879230130814976},"
"{ \"cid\": 62, \"rid\": 1605879230130814978},"
"{ \"cid\": 62, \"rid\": 1605879230131863552},"
"{ \"cid\": 62, \"rid\": 1605879230131863554},"
"{ \"cid\": 62, \"rid\": 1605879230132912128},"
"{ \"cid\": 62, \"rid\": 1605879230133960704},"
"{ \"cid\": 62, \"rid\": 1605879230133960706},"
"{ \"cid\": 62, \"rid\": 1605879230135009280},"
"{ \"cid\": 62, \"rid\": 1605879230136057856},"
"{ \"cid\": 62, \"rid\": 1605879230136057858},"
"{ \"cid\": 62, \"rid\": 1605879230137106432},"
"{ \"cid\": 62, \"rid\": 1605879230137106434},"
"{ \"cid\": 62, \"rid\": 1605879230138155008},"
"{ \"cid\": 62, \"rid\": 1605879230138155010},"
"{ \"cid\": 62, \"rid\": 1605879230139203584},"
"{ \"cid\": 62, \"rid\": 1605879230139203586},"
"{ \"cid\": 62, \"rid\": 1605879230140252160},"
"{ \"cid\": 62, \"rid\": 1605879230140252162},"
"{ \"cid\": 62, \"rid\": 1605879230141300736},"
"{ \"cid\": 62, \"rid\": 1605879230142349312},"
"{ \"cid\": 62, \"rid\": 1605879230142349314},"
"{ \"cid\": 62, \"rid\": 1605879230142349316},"
"{ \"cid\": 62, \"rid\": 1605879230143397888},"
"{ \"cid\": 62, \"rid\": 1605879230143397890},"
"{ \"cid\": 62, \"rid\": 1605879230144446464},"
"{ \"cid\": 62, \"rid\": 1605879230144446466},"
"{ \"cid\": 62, \"rid\": 1605879230144446468},"
"{ \"cid\": 62, \"rid\": 1605879230145495040},"
"{ \"cid\": 62, \"rid\": 1605879230145495042},"
"{ \"cid\": 62, \"rid\": 1605879230145495044},"
"{ \"cid\": 62, \"rid\": 1605879230146543616},"
"{ \"cid\": 62, \"rid\": 1605879230146543618},"
"{ \"cid\": 62, \"rid\": 1605879230146543620},"
"{ \"cid\": 62, \"rid\": 1605879230147592192}]"
"[{ \"rid\": 1605879230128717824},"
"{ \"rid\": 1605879230128717826},"
"{ \"rid\": 1605879230129766400},"
"{ \"rid\": 1605879230130814976},"
"{ \"rid\": 1605879230130814978},"
"{ \"rid\": 1605879230131863552},"
"{ \"rid\": 1605879230131863554},"
"{ \"rid\": 1605879230132912128},"
"{ \"rid\": 1605879230133960704},"
"{ \"rid\": 1605879230133960706},"
"{ \"rid\": 1605879230135009280},"
"{ \"rid\": 1605879230136057856},"
"{ \"rid\": 1605879230136057858},"
"{ \"rid\": 1605879230137106432},"
"{ \"rid\": 1605879230137106434},"
"{ \"rid\": 1605879230138155008},"
"{ \"rid\": 1605879230138155010},"
"{ \"rid\": 1605879230139203584},"
"{ \"rid\": 1605879230139203586},"
"{ \"rid\": 1605879230140252160},"
"{ \"rid\": 1605879230140252162},"
"{ \"rid\": 1605879230141300736},"
"{ \"rid\": 1605879230142349312},"
"{ \"rid\": 1605879230142349314},"
"{ \"rid\": 1605879230142349316},"
"{ \"rid\": 1605879230143397888},"
"{ \"rid\": 1605879230143397890},"
"{ \"rid\": 1605879230144446464},"
"{ \"rid\": 1605879230144446466},"
"{ \"rid\": 1605879230144446468},"
"{ \"rid\": 1605879230145495040},"
"{ \"rid\": 1605879230145495042},"
"{ \"rid\": 1605879230145495044},"
"{ \"rid\": 1605879230146543616},"
"{ \"rid\": 1605879230146543618},"
"{ \"rid\": 1605879230146543620},"
"{ \"rid\": 1605879230147592192}]"
);
struct DataStore {
@ -1572,28 +1541,21 @@ SECTION("test_cid_rid_encoding") {
auto const dataSlice = data->slice();
arangodb::iresearch::Field field;
TRI_voc_cid_t cid;
uint64_t rid;
size_t size = 0;
for (auto const docSlice : arangodb::velocypack::ArrayIterator(dataSlice)) {
auto const cidSlice = docSlice.get("cid");
CHECK(cidSlice.isNumber());
auto const ridSlice = docSlice.get("rid");
CHECK(ridSlice.isNumber());
cid = cidSlice.getNumber<TRI_voc_cid_t>();
rid = ridSlice.getNumber<uint64_t>();
arangodb::iresearch::DocumentPrimaryKey const pk(cid, rid);
auto pk = arangodb::iresearch::DocumentPrimaryKey::encode(arangodb::LocalDocumentId(rid));
auto& writer = store0.writer;
// insert document
{
auto doc = writer->documents().insert();
arangodb::iresearch::Field::setCidValue(field, pk.first, arangodb::iresearch::Field::init_stream_t());
CHECK((doc.insert(irs::action::index, field)));
arangodb::iresearch::Field::setPkValue(field, pk);
CHECK(doc.insert(irs::action::index_store, field));
CHECK(doc);
@ -1617,18 +1579,12 @@ SECTION("test_cid_rid_encoding") {
size_t found = 0;
for (auto const docSlice : arangodb::velocypack::ArrayIterator(dataSlice)) {
auto const cidSlice = docSlice.get("cid");
CHECK(cidSlice.isNumber());
auto const ridSlice = docSlice.get("rid");
CHECK(ridSlice.isNumber());
cid = cidSlice.getNumber<TRI_voc_cid_t>();
rid = ridSlice.getNumber<uint64_t>();
auto& segment = (*reader)[0];
auto* cidField = segment.field(arangodb::iresearch::DocumentPrimaryKey::CID());
CHECK(cidField);
CHECK(size == cidField->docs_count());
auto* pkField = segment.field(arangodb::iresearch::DocumentPrimaryKey::PK());
CHECK(pkField);
@ -1636,7 +1592,7 @@ SECTION("test_cid_rid_encoding") {
arangodb::iresearch::PrimaryKeyFilterContainer filters;
CHECK(filters.empty());
auto& filter = filters.emplace(cid, rid);
auto& filter = filters.emplace(arangodb::LocalDocumentId(rid));
REQUIRE(filter.type() == arangodb::iresearch::PrimaryKeyFilter::type());
CHECK(!filters.empty());
@ -1670,10 +1626,9 @@ SECTION("test_cid_rid_encoding") {
irs::bytes_ref pkValue;
CHECK(values(id, pkValue));
arangodb::iresearch::DocumentPrimaryKey::type pk;
arangodb::LocalDocumentId pk;
CHECK(arangodb::iresearch::DocumentPrimaryKey::read(pk, pkValue));
CHECK(cid == pk.first);
CHECK(rid == pk.second);
CHECK(rid == pk.id());
}
}
@ -1697,47 +1652,47 @@ SECTION("test_cid_rid_encoding") {
CHECK(found == size);
}
SECTION("test_cid_rid_filter") {
SECTION("test_rid_filter") {
auto data = arangodb::velocypack::Parser::fromJson(
"[{ \"cid\": 62, \"rid\": 1605879230128717824},"
"{ \"cid\": 62, \"rid\": 1605879230128717826},"
"{ \"cid\": 62, \"rid\": 1605879230129766400},"
"{ \"cid\": 62, \"rid\": 1605879230130814976},"
"{ \"cid\": 62, \"rid\": 1605879230130814978},"
"{ \"cid\": 62, \"rid\": 1605879230131863552},"
"{ \"cid\": 62, \"rid\": 1605879230131863554},"
"{ \"cid\": 62, \"rid\": 1605879230132912128},"
"{ \"cid\": 62, \"rid\": 1605879230133960704},"
"{ \"cid\": 62, \"rid\": 1605879230133960706},"
"{ \"cid\": 62, \"rid\": 1605879230135009280},"
"{ \"cid\": 62, \"rid\": 1605879230136057856},"
"{ \"cid\": 62, \"rid\": 1605879230136057858},"
"{ \"cid\": 62, \"rid\": 1605879230137106432},"
"{ \"cid\": 62, \"rid\": 1605879230137106434},"
"{ \"cid\": 62, \"rid\": 1605879230138155008},"
"{ \"cid\": 62, \"rid\": 1605879230138155010},"
"{ \"cid\": 62, \"rid\": 1605879230139203584},"
"{ \"cid\": 62, \"rid\": 1605879230139203586},"
"{ \"cid\": 62, \"rid\": 1605879230140252160},"
"{ \"cid\": 62, \"rid\": 1605879230140252162},"
"{ \"cid\": 62, \"rid\": 1605879230141300736},"
"{ \"cid\": 62, \"rid\": 1605879230142349312},"
"{ \"cid\": 62, \"rid\": 1605879230142349314},"
"{ \"cid\": 62, \"rid\": 1605879230142349316},"
"{ \"cid\": 62, \"rid\": 1605879230143397888},"
"{ \"cid\": 62, \"rid\": 1605879230143397890},"
"{ \"cid\": 62, \"rid\": 1605879230144446464},"
"{ \"cid\": 62, \"rid\": 1605879230144446466},"
"{ \"cid\": 62, \"rid\": 1605879230144446468},"
"{ \"cid\": 62, \"rid\": 1605879230145495040},"
"{ \"cid\": 62, \"rid\": 1605879230145495042},"
"{ \"cid\": 62, \"rid\": 1605879230145495044},"
"{ \"cid\": 62, \"rid\": 1605879230146543616},"
"{ \"cid\": 62, \"rid\": 1605879230146543618},"
"{ \"cid\": 62, \"rid\": 1605879230146543620},"
"{ \"cid\": 62, \"rid\": 1605879230147592192}]"
"[{ \"rid\": 1605879230128717824},"
"{ \"rid\": 1605879230128717826},"
"{ \"rid\": 1605879230129766400},"
"{ \"rid\": 1605879230130814976},"
"{ \"rid\": 1605879230130814978},"
"{ \"rid\": 1605879230131863552},"
"{ \"rid\": 1605879230131863554},"
"{ \"rid\": 1605879230132912128},"
"{ \"rid\": 1605879230133960704},"
"{ \"rid\": 1605879230133960706},"
"{ \"rid\": 1605879230135009280},"
"{ \"rid\": 1605879230136057856},"
"{ \"rid\": 1605879230136057858},"
"{ \"rid\": 1605879230137106432},"
"{ \"rid\": 1605879230137106434},"
"{ \"rid\": 1605879230138155008},"
"{ \"rid\": 1605879230138155010},"
"{ \"rid\": 1605879230139203584},"
"{ \"rid\": 1605879230139203586},"
"{ \"rid\": 1605879230140252160},"
"{ \"rid\": 1605879230140252162},"
"{ \"rid\": 1605879230141300736},"
"{ \"rid\": 1605879230142349312},"
"{ \"rid\": 1605879230142349314},"
"{ \"rid\": 1605879230142349316},"
"{ \"rid\": 1605879230143397888},"
"{ \"rid\": 1605879230143397890},"
"{ \"rid\": 1605879230144446464},"
"{ \"rid\": 1605879230144446466},"
"{ \"rid\": 1605879230144446468},"
"{ \"rid\": 1605879230145495040},"
"{ \"rid\": 1605879230145495042},"
"{ \"rid\": 1605879230145495044},"
"{ \"rid\": 1605879230146543616},"
"{ \"rid\": 1605879230146543618},"
"{ \"rid\": 1605879230146543620},"
"{ \"rid\": 1605879230147592192}]"
);
auto data1 = arangodb::velocypack::Parser::fromJson("{ \"cid\": 62, \"rid\": 2605879230128717824}");
auto data1 = arangodb::velocypack::Parser::fromJson("{ \"rid\": 2605879230128717824}");
struct DataStore {
irs::memory_directory dir;
@ -1760,22 +1715,17 @@ SECTION("test_cid_rid_filter") {
// initial population
for (auto const docSlice: arangodb::velocypack::ArrayIterator(dataSlice)) {
auto const cidSlice = docSlice.get("cid");
CHECK((cidSlice.isNumber<TRI_voc_cid_t>()));
auto const ridSlice = docSlice.get("rid");
CHECK((ridSlice.isNumber<uint64_t>()));
auto cid = cidSlice.getNumber<TRI_voc_cid_t>();
auto rid = ridSlice.getNumber<uint64_t>();
arangodb::iresearch::Field field;
arangodb::iresearch::DocumentPrimaryKey const pk(cid, rid);
auto pk = arangodb::iresearch::DocumentPrimaryKey::encode(arangodb::LocalDocumentId(rid));
// insert document
{
auto ctx = store.writer->documents();
auto doc = ctx.insert();
arangodb::iresearch::Field::setCidValue(field, pk.first, arangodb::iresearch::Field::init_stream_t());
CHECK((doc.insert(irs::action::index, field)));
arangodb::iresearch::Field::setPkValue(field, pk);
CHECK((doc.insert(irs::action::index_store, field)));
CHECK((doc));
@ -1787,11 +1737,9 @@ SECTION("test_cid_rid_filter") {
// add extra doc to hold segment after others are removed
{
arangodb::iresearch::Field field;
arangodb::iresearch::DocumentPrimaryKey const pk(42, 12345);
auto pk = arangodb::iresearch::DocumentPrimaryKey::encode(arangodb::LocalDocumentId(12345));
auto ctx = store.writer->documents();
auto doc = ctx.insert();
arangodb::iresearch::Field::setCidValue(field, pk.first, arangodb::iresearch::Field::init_stream_t());
CHECK((doc.insert(irs::action::index, field)));
arangodb::iresearch::Field::setPkValue(field, pk);
CHECK((doc.insert(irs::action::index_store, field)));
CHECK((doc));
@ -1803,21 +1751,18 @@ SECTION("test_cid_rid_filter") {
CHECK((expectedDocs + 1 == store.reader->docs_count())); // +1 for keep-alive doc
CHECK((expectedLiveDocs + 1 == store.reader->live_docs_count())); // +1 for keep-alive doc
// check regular filter case (unique cid+rid)
// check regular filter case (unique rid)
{
size_t actualDocs = 0;
for (auto const docSlice: arangodb::velocypack::ArrayIterator(dataSlice)) {
auto const cidSlice = docSlice.get("cid");
CHECK((cidSlice.isNumber<TRI_voc_cid_t>()));
auto const ridSlice = docSlice.get("rid");
CHECK(ridSlice.isNumber<uint64_t>());
auto cid = cidSlice.getNumber<TRI_voc_cid_t>();
auto rid = ridSlice.getNumber<uint64_t>();
arangodb::iresearch::PrimaryKeyFilterContainer filters;
CHECK((filters.empty()));
auto& filter = filters.emplace(cid, rid);
auto& filter = filters.emplace(arangodb::LocalDocumentId(rid));
REQUIRE((filter.type() == arangodb::iresearch::PrimaryKeyFilter::type()));
CHECK((!filters.empty()));
@ -1849,10 +1794,9 @@ SECTION("test_cid_rid_filter") {
irs::bytes_ref pkValue;
CHECK((values(id, pkValue)));
arangodb::iresearch::DocumentPrimaryKey::type pk;
arangodb::LocalDocumentId pk;
CHECK((arangodb::iresearch::DocumentPrimaryKey::read(pk, pkValue)));
CHECK((cid == pk.first));
CHECK((rid == pk.second));
CHECK((rid == pk.id()));
}
}
@ -1861,23 +1805,18 @@ SECTION("test_cid_rid_filter") {
// remove + insert (simulate recovery)
for (auto const docSlice: arangodb::velocypack::ArrayIterator(dataSlice)) {
auto const cidSlice = docSlice.get("cid");
CHECK((cidSlice.isNumber<TRI_voc_cid_t>()));
auto const ridSlice = docSlice.get("rid");
CHECK((ridSlice.isNumber<uint64_t>()));
auto cid = cidSlice.getNumber<TRI_voc_cid_t>();
auto rid = ridSlice.getNumber<uint64_t>();
arangodb::iresearch::Field field;
arangodb::iresearch::DocumentPrimaryKey const pk(cid, rid);
auto pk = arangodb::iresearch::DocumentPrimaryKey::encode(arangodb::LocalDocumentId(rid));
// remove + insert document
{
auto ctx = store.writer->documents();
ctx.remove(std::make_shared<arangodb::iresearch::PrimaryKeyFilter>(cid, rid));
ctx.remove(std::make_shared<arangodb::iresearch::PrimaryKeyFilter>(arangodb::LocalDocumentId(rid)));
auto doc = ctx.insert();
arangodb::iresearch::Field::setCidValue(field, pk.first, arangodb::iresearch::Field::init_stream_t());
CHECK((doc.insert(irs::action::index, field)));
arangodb::iresearch::Field::setPkValue(field, pk);
CHECK((doc.insert(irs::action::index_store, field)));
CHECK((doc));
@ -1888,11 +1827,9 @@ SECTION("test_cid_rid_filter") {
// add extra doc to hold segment after others are removed
{
arangodb::iresearch::Field field;
arangodb::iresearch::DocumentPrimaryKey const pk(43, 123456);
auto pk = arangodb::iresearch::DocumentPrimaryKey::encode(arangodb::LocalDocumentId(123456));
auto ctx = store.writer->documents();
auto doc = ctx.insert();
arangodb::iresearch::Field::setCidValue(field, pk.first, arangodb::iresearch::Field::init_stream_t());
CHECK((doc.insert(irs::action::index, field)));
arangodb::iresearch::Field::setPkValue(field, pk);
CHECK((doc.insert(irs::action::index_store, field)));
CHECK((doc));
@ -1913,16 +1850,13 @@ SECTION("test_cid_rid_filter") {
auto restoreRecovery = irs::make_finally([&beforeRecovery]()->void { StorageEngineMock::inRecoveryResult = beforeRecovery; });
for (auto const docSlice: arangodb::velocypack::ArrayIterator(dataSlice)) {
auto const cidSlice = docSlice.get("cid");
CHECK((cidSlice.isNumber<TRI_voc_cid_t>()));
auto const ridSlice = docSlice.get("rid");
CHECK(ridSlice.isNumber<uint64_t>());
auto cid = cidSlice.getNumber<TRI_voc_cid_t>();
auto rid = ridSlice.getNumber<uint64_t>();
arangodb::iresearch::PrimaryKeyFilterContainer filters;
CHECK((filters.empty()));
auto& filter = filters.emplace(cid, rid);
auto& filter = filters.emplace(arangodb::LocalDocumentId(rid));
REQUIRE((filter.type() == arangodb::iresearch::PrimaryKeyFilter::type()));
CHECK((!filters.empty()));
@ -1954,10 +1888,9 @@ SECTION("test_cid_rid_filter") {
irs::bytes_ref pkValue;
CHECK((values(id, pkValue)));
arangodb::iresearch::DocumentPrimaryKey::type pk;
arangodb::LocalDocumentId pk;
CHECK((arangodb::iresearch::DocumentPrimaryKey::read(pk, pkValue)));
CHECK((cid == pk.first));
CHECK((rid == pk.second));
CHECK((rid == pk.id()));
}
}
}
@ -1967,23 +1900,18 @@ SECTION("test_cid_rid_filter") {
// remove + insert (simulate recovery) 2nd time
for (auto const docSlice: arangodb::velocypack::ArrayIterator(dataSlice)) {
auto const cidSlice = docSlice.get("cid");
CHECK((cidSlice.isNumber<TRI_voc_cid_t>()));
auto const ridSlice = docSlice.get("rid");
CHECK((ridSlice.isNumber<uint64_t>()));
auto cid = cidSlice.getNumber<TRI_voc_cid_t>();
auto rid = ridSlice.getNumber<uint64_t>();
arangodb::iresearch::Field field;
arangodb::iresearch::DocumentPrimaryKey const pk(cid, rid);
auto pk = arangodb::iresearch::DocumentPrimaryKey::encode(arangodb::LocalDocumentId(rid));
// remove + insert document
{
auto ctx = store.writer->documents();
ctx.remove(std::make_shared<arangodb::iresearch::PrimaryKeyFilter>(cid, rid));
ctx.remove(std::make_shared<arangodb::iresearch::PrimaryKeyFilter>(arangodb::LocalDocumentId(rid)));
auto doc = ctx.insert();
arangodb::iresearch::Field::setCidValue(field, pk.first, arangodb::iresearch::Field::init_stream_t());
CHECK((doc.insert(irs::action::index, field)));
arangodb::iresearch::Field::setPkValue(field, pk);
CHECK((doc.insert(irs::action::index_store, field)));
CHECK((doc));
@ -1994,11 +1922,9 @@ SECTION("test_cid_rid_filter") {
// add extra doc to hold segment after others are removed
{
arangodb::iresearch::Field field;
arangodb::iresearch::DocumentPrimaryKey const pk(44, 1234567);
auto pk = arangodb::iresearch::DocumentPrimaryKey::encode(arangodb::LocalDocumentId(1234567));
auto ctx = store.writer->documents();
auto doc = ctx.insert();
arangodb::iresearch::Field::setCidValue(field, pk.first, arangodb::iresearch::Field::init_stream_t());
CHECK((doc.insert(irs::action::index, field)));
arangodb::iresearch::Field::setPkValue(field, pk);
CHECK((doc.insert(irs::action::index_store, field)));
CHECK((doc));
@ -2019,16 +1945,13 @@ SECTION("test_cid_rid_filter") {
auto restoreRecovery = irs::make_finally([&beforeRecovery]()->void { StorageEngineMock::inRecoveryResult = beforeRecovery; });
for (auto const docSlice: arangodb::velocypack::ArrayIterator(dataSlice)) {
auto const cidSlice = docSlice.get("cid");
CHECK((cidSlice.isNumber<TRI_voc_cid_t>()));
auto const ridSlice = docSlice.get("rid");
CHECK(ridSlice.isNumber<uint64_t>());
auto cid = cidSlice.getNumber<TRI_voc_cid_t>();
auto rid = ridSlice.getNumber<uint64_t>();
arangodb::iresearch::PrimaryKeyFilterContainer filters;
CHECK((filters.empty()));
auto& filter = filters.emplace(cid, rid);
auto& filter = filters.emplace(arangodb::LocalDocumentId(rid));
REQUIRE((filter.type() == arangodb::iresearch::PrimaryKeyFilter::type()));
CHECK((!filters.empty()));
@ -2060,10 +1983,9 @@ SECTION("test_cid_rid_filter") {
irs::bytes_ref pkValue;
CHECK((values(id, pkValue)));
arangodb::iresearch::DocumentPrimaryKey::type pk;
arangodb::LocalDocumentId pk;
CHECK((arangodb::iresearch::DocumentPrimaryKey::read(pk, pkValue)));
CHECK((cid == pk.first));
CHECK((rid == pk.second));
CHECK((rid == pk.id()));
}
}
}

View File

@ -682,7 +682,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(1 == snapshot->live_docs_count());
}
@ -707,7 +707,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(0 == snapshot->live_docs_count());
}
}
@ -757,7 +757,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(1 == snapshot->live_docs_count());
}
@ -782,7 +782,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(0 == snapshot->live_docs_count());
}
}
@ -832,7 +832,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(1 == snapshot->live_docs_count());
}
@ -860,7 +860,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(0 == snapshot->live_docs_count());
}
@ -924,7 +924,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(1 == snapshot->live_docs_count());
}
@ -947,7 +947,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(1 == snapshot->live_docs_count());
}
@ -1011,7 +1011,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(1 == snapshot->live_docs_count());
}
@ -1039,7 +1039,7 @@ SECTION("test_drop_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(0 == snapshot->live_docs_count());
}
@ -1172,7 +1172,7 @@ SECTION("test_truncate_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(1 == snapshot->live_docs_count());
}
@ -1197,7 +1197,7 @@ SECTION("test_truncate_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(0 == snapshot->live_docs_count());
}
}
@ -1247,7 +1247,7 @@ SECTION("test_truncate_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(1 == snapshot->live_docs_count());
}
@ -1272,7 +1272,7 @@ SECTION("test_truncate_cid") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(0 == snapshot->live_docs_count());
}
}
@ -1634,7 +1634,7 @@ SECTION("test_insert") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(2 == snapshot->live_docs_count());
}
@ -1689,7 +1689,7 @@ SECTION("test_insert") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((2 == snapshot->live_docs_count()));
}
@ -1737,7 +1737,7 @@ SECTION("test_insert") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((4 == snapshot->docs_count()));
}
@ -1786,7 +1786,7 @@ SECTION("test_insert") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace);
CHECK((4 == snapshot->docs_count()));
}
@ -1833,7 +1833,7 @@ SECTION("test_insert") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace);
CHECK((1 == snapshot->docs_count()));
}
@ -1886,7 +1886,7 @@ SECTION("test_insert") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((4 == snapshot->docs_count()));
}
@ -1939,7 +1939,7 @@ SECTION("test_insert") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace);
CHECK((4 == snapshot->docs_count()));
}
}
@ -1987,7 +1987,7 @@ SECTION("test_query") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(0 == snapshot->docs_count());
}
@ -2037,7 +2037,7 @@ SECTION("test_query") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(12 == snapshot->docs_count());
}
@ -2089,7 +2089,7 @@ SECTION("test_query") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot0 = view->snapshot(trx0, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot0 = view->snapshot(trx0, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(12 == snapshot0->docs_count());
// add more data
@ -2125,7 +2125,7 @@ SECTION("test_query") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot1 = view->snapshot(trx1, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot1 = view->snapshot(trx1, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(24 == snapshot1->docs_count());
}
@ -2191,7 +2191,7 @@ SECTION("test_query") {
EMPTY,
options
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace);
CHECK(i == snapshot->docs_count());
}
}
@ -2305,7 +2305,7 @@ SECTION("test_register_link") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((0 == snapshot->docs_count()));
}
@ -2329,7 +2329,7 @@ SECTION("test_register_link") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((0 == snapshot->docs_count())); // link addition does trigger collection load
// link addition does modify view meta
@ -2367,7 +2367,7 @@ SECTION("test_register_link") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((nullptr == snapshot));
}
@ -2399,7 +2399,7 @@ SECTION("test_register_link") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((0 == snapshot->docs_count())); // link addition does trigger collection load
}
@ -2431,7 +2431,7 @@ SECTION("test_register_link") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((0 == snapshot->docs_count())); // link addition does trigger collection load
{
@ -2513,7 +2513,7 @@ SECTION("test_unregister_link") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((1 == snapshot->docs_count()));
}
@ -2549,7 +2549,7 @@ SECTION("test_unregister_link") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((0 == snapshot->docs_count()));
}
@ -2618,7 +2618,7 @@ SECTION("test_unregister_link") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((1 == snapshot->docs_count()));
}
@ -2650,7 +2650,7 @@ SECTION("test_unregister_link") {
EMPTY,
arangodb::transaction::Options()
);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
auto* snapshot = view->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK((0 == snapshot->docs_count()));
}
@ -2738,14 +2738,6 @@ SECTION("test_unregister_link") {
}
}
SECTION("test_self_token") {
// test empty token
{
arangodb::iresearch::IResearchView::AsyncViewPtr::element_type empty(nullptr);
CHECK((nullptr == empty.get()));
}
}
SECTION("test_tracked_cids") {
auto collectionJson = arangodb::velocypack::Parser::fromJson("{ \"name\": \"testCollection\", \"id\": 100 }");
auto viewJson = arangodb::velocypack::Parser::fromJson("{ \"name\": \"testView\", \"type\": \"arangosearch\", \"id\": 101 }");
@ -3297,10 +3289,10 @@ SECTION("test_transaction_snapshot") {
EMPTY,
arangodb::transaction::Options()
);
CHECK(nullptr == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find));
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find));
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate));
CHECK(nullptr == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find));
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find));
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate));
CHECK(nullptr != snapshot);
CHECK((0 == snapshot->live_docs_count()));
}
@ -3330,10 +3322,10 @@ SECTION("test_transaction_snapshot") {
EMPTY,
opts
);
CHECK(nullptr == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find));
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find));
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate));
CHECK(nullptr == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find));
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find));
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate));
CHECK((nullptr != snapshot));
CHECK((1 == snapshot->live_docs_count()));
}
@ -3383,9 +3375,9 @@ SECTION("test_transaction_snapshot") {
);
CHECK((true == viewImpl->apply(trx)));
CHECK((true == trx.begin().ok()));
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find));
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate));
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find));
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate));
CHECK((nullptr != snapshot));
CHECK((1 == snapshot->live_docs_count()));
CHECK(true == trx.abort().ok()); // prevent assertion in destructor
@ -3405,8 +3397,8 @@ SECTION("test_transaction_snapshot") {
CHECK((true == viewImpl->apply(trx)));
CHECK((true == trx.begin().ok()));
state->waitForSync(true);
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find));
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find));
CHECK((nullptr != snapshot));
CHECK((1 == snapshot->live_docs_count()));
CHECK(true == trx.abort().ok()); // prevent assertion in destructor
@ -3426,8 +3418,8 @@ SECTION("test_transaction_snapshot") {
REQUIRE(state);
CHECK((true == viewImpl->apply(trx)));
CHECK((true == trx.begin().ok()));
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find));
auto* snapshot = viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace);
CHECK(snapshot == viewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find));
CHECK((nullptr != snapshot));
CHECK((2 == snapshot->live_docs_count()));
CHECK(true == trx.abort().ok()); // prevent assertion in destructor

View File

@ -560,7 +560,7 @@ SECTION("test_query") {
);
CHECK((trx.begin().ok()));
std::unordered_set<TRI_voc_cid_t> collections = { logicalCollection->id() };
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate, &collections);
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate, &collections);
CHECK(0 == snapshot->docs_count());
CHECK((trx.commit().ok()));
}
@ -617,7 +617,7 @@ SECTION("test_query") {
);
CHECK((trx.begin().ok()));
std::unordered_set<TRI_voc_cid_t> collections = { logicalCollection->id() };
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate, &collections);
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate, &collections);
CHECK(12 == snapshot->docs_count());
CHECK((trx.commit().ok()));
}
@ -677,9 +677,9 @@ SECTION("test_query") {
);
CHECK((trx0.begin().ok()));
std::unordered_set<TRI_voc_cid_t> collectionIds = { logicalCollection->id() };
CHECK((nullptr == wiewImpl->snapshot(trx0, arangodb::iresearch::IResearchView::Snapshot::Find, &collectionIds)));
auto* snapshot0 = wiewImpl->snapshot(trx0, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace, &collectionIds);
CHECK((snapshot0 == wiewImpl->snapshot(trx0, arangodb::iresearch::IResearchView::Snapshot::Find, &collectionIds)));
CHECK((nullptr == wiewImpl->snapshot(trx0, arangodb::iresearch::IResearchView::SnapshotMode::Find, &collectionIds)));
auto* snapshot0 = wiewImpl->snapshot(trx0, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace, &collectionIds);
CHECK((snapshot0 == wiewImpl->snapshot(trx0, arangodb::iresearch::IResearchView::SnapshotMode::Find, &collectionIds)));
CHECK(12 == snapshot0->docs_count());
CHECK((trx0.commit().ok()));
@ -717,7 +717,7 @@ SECTION("test_query") {
trxOptions
);
CHECK((trx1.begin().ok()));
auto* snapshot1 = wiewImpl->snapshot(trx1, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace, &collectionIds);
auto* snapshot1 = wiewImpl->snapshot(trx1, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace, &collectionIds);
CHECK(24 == snapshot1->docs_count());
CHECK((trx1.commit().ok()));
}
@ -790,7 +790,7 @@ SECTION("test_query") {
);
CHECK((trx.begin().ok()));
std::unordered_set<TRI_voc_cid_t> collections = { logicalCollection->id() };
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace, &collections);
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace, &collections);
CHECK(i == snapshot->docs_count());
CHECK((trx.commit().ok()));
}
@ -1037,7 +1037,7 @@ SECTION("test_transaction_snapshot") {
);
CHECK((trx.begin().ok()));
std::unordered_set<TRI_voc_cid_t> collections = { logicalCollection->id() };
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find, &collections);
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find, &collections);
CHECK((nullptr == snapshot));
CHECK((trx.commit().ok()));
}
@ -1053,9 +1053,9 @@ SECTION("test_transaction_snapshot") {
);
CHECK((trx.begin().ok()));
std::unordered_set<TRI_voc_cid_t> collections = { logicalCollection->id() };
CHECK((nullptr == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find, &collections)));
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate, &collections);
CHECK((snapshot == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate, &collections)));
CHECK((nullptr == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find, &collections)));
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate, &collections);
CHECK((snapshot == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate, &collections)));
CHECK((0 == snapshot->live_docs_count()));
CHECK((trx.commit().ok()));
}
@ -1073,7 +1073,7 @@ SECTION("test_transaction_snapshot") {
);
CHECK((trx.begin().ok()));
std::unordered_set<TRI_voc_cid_t> collections = { logicalCollection->id() };
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find, &collections);
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find, &collections);
CHECK((nullptr == snapshot));
CHECK((trx.commit().ok()));
}
@ -1090,10 +1090,10 @@ SECTION("test_transaction_snapshot") {
);
CHECK((trx.begin().ok()));
std::unordered_set<TRI_voc_cid_t> collections = { logicalCollection->id() };
CHECK((nullptr == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find, &collections)));
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace, &collections);
CHECK((snapshot == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::Find, &collections)));
CHECK((snapshot == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::Snapshot::FindOrCreate, &collections)));
CHECK((nullptr == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find, &collections)));
auto* snapshot = wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace, &collections);
CHECK((snapshot == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::Find, &collections)));
CHECK((snapshot == wiewImpl->snapshot(trx, arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate, &collections)));
CHECK((nullptr != snapshot));
CHECK((1 == snapshot->live_docs_count()));
CHECK((trx.commit().ok()));

View File

@ -1148,19 +1148,19 @@ SECTION("createBlockSingleServer") {
// start transaction (put snapshot into)
REQUIRE(query.trx()->state());
CHECK(nullptr == arangodb::LogicalView::cast<arangodb::iresearch::IResearchView>(*logicalView).snapshot(
*query.trx(), arangodb::iresearch::IResearchView::Snapshot::Find
*query.trx(), arangodb::iresearch::IResearchView::SnapshotMode::Find
));
auto* snapshot = arangodb::LogicalView::cast<arangodb::iresearch::IResearchView>(*logicalView).snapshot(
*query.trx(), arangodb::iresearch::IResearchView::Snapshot::FindOrCreate
*query.trx(), arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate
);
CHECK(snapshot == arangodb::LogicalView::cast<arangodb::iresearch::IResearchView>(*logicalView).snapshot(
*query.trx(), arangodb::iresearch::IResearchView::Snapshot::Find
*query.trx(), arangodb::iresearch::IResearchView::SnapshotMode::Find
));
CHECK(snapshot == arangodb::LogicalView::cast<arangodb::iresearch::IResearchView>(*logicalView).snapshot(
*query.trx(), arangodb::iresearch::IResearchView::Snapshot::FindOrCreate
*query.trx(), arangodb::iresearch::IResearchView::SnapshotMode::FindOrCreate
));
CHECK(snapshot == arangodb::LogicalView::cast<arangodb::iresearch::IResearchView>(*logicalView).snapshot(
*query.trx(), arangodb::iresearch::IResearchView::Snapshot::SyncAndReplace
*query.trx(), arangodb::iresearch::IResearchView::SnapshotMode::SyncAndReplace
));
// after transaction has started
@ -1220,4 +1220,4 @@ SECTION("createBlockCoordinator") {
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------