8000 Feature/remove shared ptrs from analyzers by Dronplane · Pull Request #14694 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Feature/remove shared ptrs from analyzers #14694

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 12 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
get rid of shared ptrs
  • Loading branch information
Dronplane committed Aug 25, 2021
commit f01b1eda84fc5ca16dda75057a86bf1c1c5deedd
8 changes: 4 additions & 4 deletions arangod/IResearch/GeoFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ irs::doc_iterator::ptr make_iterator(
/// @brief cached per reader state
//////////////////////////////////////////////////////////////////////////////
struct GeoState {
using TermState = irs::seek_term_iterator::seek_cookie::ptr;
using TermState = irs::seek_term_iterator::cookie_ptr;

//////////////////////////////////////////////////////////////////////////////
/// @brief corresponding stored field
Expand All @@ -224,7 +224,7 @@ struct GeoState {
//////////////////////////////////////////////////////////////////////////////
/// @brief geo term states
//////////////////////////////////////////////////////////////////////////////
std::vector<irs::seek_term_iterator::seek_cookie::ptr> states;
std::vector<irs::seek_term_iterator::cookie_ptr> states;
}; // GeoState

using GeoStates = irs::states_cache<GeoState>;
Expand Down Expand Up @@ -261,7 +261,7 @@ class GeoQuery final : public irs::filter::prepared {

// get terms iterator
TRI_ASSERT(state->reader);
auto terms = state->reader->iterator();
auto terms = state->reader->iterator(irs::SeekMode::NORMAL);

if (IRS_UNLIKELY(!terms)) {
return irs::doc_iterator::empty();
Expand Down Expand Up @@ -365,7 +365,7 @@ std::pair<GeoStates, irs::bstring> prepareStates(
continue;
}

auto terms = reader->iterator();
auto terms = reader->iterator(irs::SeekMode::NORMAL);

if (IRS_UNLIKELY(!terms)) {
continue;
Expand Down
7 changes: 3 additions & 4 deletions arangod/IResearch/IResearchAnalyzerFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,9 @@ void AnalyzerPool::setKey(irs::string_ref const& key) {
_key = irs::string_ref(_config.c_str() + keyOffset, key.size());
}

irs::analysis::analyzer::ptr AnalyzerPool::get() const noexcept {
AnalyzerPool::CacheType AnalyzerPool::get() const noexcept {
try {
// FIXME do not use shared_ptr
return _cache.emplace(_type, _properties).release();
return _cache.emplace(_type, _properties);
} catch (basics::Exception const& e) {
LOG_TOPIC("c9256", WARN, iresearch::TOPIC)
<< "caught exception while instantiating an arangosearch analizer type "
Expand All @@ -1079,7 +1078,7 @@ irs::analysis::analyzer::ptr AnalyzerPool::get() const noexcept {
<< _type << "' properties '" << _properties << "'";
}

return nullptr;
return {};
}

IResearchAnalyzerFeature::IResearchAnalyzerFeature(application_features::ApplicationServer& server)
Expand Down
41 changes: 33 additions & 8 deletions arangod/IResearch/IResearchAnalyzerFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <analysis/analyzer.hpp>
#include <analysis/analyzers.hpp>
#include "analysis/token_streams.hpp"
#include <index/index_features.hpp>
#include <index/field_meta.hpp>
#include <utils/async_utils.hpp>
Expand Down Expand Up @@ -177,10 +178,40 @@ class AnalyzerPool : private irs::util::noncopyable {
VPackSlice slice,
VPackBuffer<uint8_t>& buf);

// type tags for primitive token streams
struct null_stream_tag {};
struct boolean_stream_tag {};
struct numeric_stream_tag {};
struct string_stream_tag {};

// 'make(...)' method wrapper for irs::analysis::analyzer types
struct Builder {
using ptr = irs::analysis::analyzer::ptr;
DECLARE_FACTORY(irs::string_ref const& type, VPackSlice properties);

static ptr make(null_stream_tag&) {
return std::make_shared<irs::null_token_stream>();
}

static ptr make(boolean_stream_tag&) {
return std::make_shared<irs::boolean_token_stream>();
}

static ptr make(numeric_stream_tag&) {
return std::make_shared<irs::numeric_token_stream>();
}

static ptr make(string_stream_tag&) {
return std::make_shared<irs::string_token_stream>();
}
};

using CacheType = irs::unbounded_object_pool<Builder>;

explicit AnalyzerPool(irs::string_ref const& name);

// nullptr == error creating analyzer
irs::analysis::analyzer::ptr get() const noexcept;
CacheType::ptr get() const noexcept;

Features features() const noexcept { return _features; }
irs::features_t fieldFeatures() const noexcept {
Expand Down Expand Up @@ -220,12 +251,6 @@ class AnalyzerPool : private irs::util::noncopyable {
// required for calling AnalyzerPool::init(...) and AnalyzerPool::setKey(...)
friend class IResearchAnalyzerFeature;

// 'make(...)' method wrapper for irs::analysis::analyzer types
struct Builder {
using ptr = irs::analysis::analyzer::ptr;
DECLARE_FACTORY(irs::string_ref const& type, VPackSlice properties);
};

void toVelocyPack(velocypack::Builder& builder,
irs::string_ref const& name);

Expand All @@ -236,7 +261,7 @@ class AnalyzerPool : private irs::util::noncopyable {
LinkVersion version);
void setKey(irs::string_ref const& type);

mutable irs::unbounded_object_pool<Builder> _cache; // cache of irs::analysis::analyzer
mutable CacheType _cache; // cache of irs::analysis::analyzer
std::vector<irs::type_info::type_id> _fieldFeatures; // cached iresearch field features
std::string _config; // non-null type + non-null properties + key
irs::string_ref _key; // the key of the persisted configuration for this pool,
Expand Down
37 changes: 18 additions & 19 deletions arangod/IResearch/IResearchDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "Misc.h"
#include "Transaction/Helpers.h"
#include "Transaction/Methods.h"
#include "analysis/token_streams.hpp"

#include "search/term_filter.hpp"

Expand Down Expand Up @@ -104,11 +103,11 @@ struct AnyFactory {
}
}; // AnyFactory

size_t const DEFAULT_POOL_SIZE = 8; // arbitrary value
irs::unbounded_object_pool<AnyFactory<irs::string_token_stream>> StringStreamPool(DEFAULT_POOL_SIZE);
irs::unbounded_object_pool<AnyFactory<irs::null_token_stream>> NullStreamPool(DEFAULT_POOL_SIZE);
irs::unbounded_object_pool<AnyFactory<irs::boolean_token_stream>> BoolStreamPool(DEFAULT_POOL_SIZE);
irs::unbounded_object_pool<AnyFactory<irs::numeric_token_stream>> NumericStreamPool(DEFAULT_POOL_SIZE);
size_t constexpr DEFAULT_POOL_SIZE = 8; // arbitrary value
irs::unbounded_object_pool<arangodb::iresearch::AnalyzerPool::Builder> StringStreamPool(DEFAULT_POOL_SIZE);
irs::unbounded_object_pool<arangodb::iresearch::AnalyzerPool::Builder> NullStreamPool(DEFAULT_POOL_SIZE);
irs::unbounded_object_pool<arangodb::iresearch::AnalyzerPool::Builder> BoolStreamPool(DEFAULT_POOL_SIZE);
irs::unbounded_object_pool<arangodb::iresearch::AnalyzerPool::Builder> NumericStreamPool(DEFAULT_POOL_SIZE);
std::initializer_list<irs::type_info::type_id> NumericStreamFeatures { irs::type<irs::granularity_prefix>::id() };

// appends the specified 'value' to 'out'
Expand Down Expand Up @@ -308,11 +307,11 @@ namespace iresearch {
field._storeValues = ValueStorage::VALUE;
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
field._analyzer = StringStreamPool.emplace(AnalyzerPool::string_stream_tag());
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
auto& sstream = dynamic_cast<irs::string_token_stream&>(*field._analyzer);
auto& sstream = dynamic_cast<irs::string_token_stream&>(*field._analyzer.get());
#else
auto& sstream = static_cast<irs::string_token_stream&>(*field._analyzer);
auto& sstream = static_cast<irs::string_token_stream&>(*field._analyzer.get());
#endif
sstream.reset(field._value);
}
Expand Down Expand Up @@ -351,12 +350,12 @@ void FieldIterator::setBoolValue(VPackSlice const value) {
arangodb::iresearch::kludge::mangleBool(_nameBuffer);

// init stream
auto stream = BoolStreamPool.emplace();
stream->reset(value.getBool());
auto stream = BoolStreamPool.emplace(AnalyzerPool::boolean_stream_tag());
static_cast<irs::boolean_token_stream*>(stream.get())->reset(value.getBool());

// set field properties
_value._name = _nameBuffer;
_value._analyzer = stream.release(); // FIXME don't use shared_ptr
_value._analyzer = std::move(stream);
_value._indexFeatures = irs::IndexFeatures::NONE;
_value._fieldFeatures = {};
}
Expand All @@ -367,12 +366,12 @@ void FieldIterator::setNumericValue(VPackSlice const value) {
arangodb::iresearch::kludge::mangleNumeric(_nameBuffer);

// init stream
auto stream = NumericStreamPool.emplace();
stream->reset(value.getNumber<double>());
auto stream = NumericStreamPool.emplace(AnalyzerPool::numeric_stream_tag());
static_cast<irs::numeric_token_stream*>(stream.get())->reset(value.getNumber<double>());

// set field properties
_value._name = _nameBuffer;
_value._analyzer = stream.release(); // FIXME don't use shared_ptr
_value._analyzer = std::move(stream);
_value._indexFeatures = irs::IndexFeatures::NONE;
_value._fieldFeatures = { NumericStreamFeatures.begin(),
NumericStreamFeatures.size() };
Expand All @@ -384,12 +383,12 @@ void FieldIterator::setNullValue(VPackSlice const value) {
arangodb::iresearch::kludge::mangleNull(_nameBuffer);

// init stream
auto stream = NullStreamPool.emplace();
stream->reset();
auto stream = NullStreamPool.emplace(AnalyzerPool::null_stream_tag());
static_cast<irs::null_token_stream*>(stream.get())->reset();

// set field properties
_value._name = _nameBuffer;
_value._analyzer = stream.release(); // FIXME don't use shared_ptr
_value._analyzer = std::move(stream);
_value._indexFeatures = irs::IndexFeatures::NONE;
_value._fieldFeatures = {};
}
Expand Down Expand Up @@ -512,7 +511,7 @@ bool FieldIterator::setValue(VPackSlice const value,
break;
default: {
iresearch::kludge::mangleField(_nameBuffer, valueAnalyzer);
_value._analyzer = analyzer;
_value._analyzer = std::move(analyzer);
_value._fieldFeatures = pool->fieldFeatures();
_value._indexFeatures = pool->indexFeatures();
_value._name = _nameBuffer;
Expand Down
5 changes: 4 additions & 1 deletion arangod/IResearch/IResearchDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class token_stream;
class numeric_token_stream;
class boolean_token_stream;

namespace analysis {
class analyzer;
} // namespace analysis
} // namespace iresearch

namespace arangodb {
Expand Down Expand Up @@ -122,7 +125,7 @@ struct Field {
return true;
}

std::shared_ptr<irs::token_stream> _analyzer;
irs::unbounded_object_pool<AnalyzerPool::Builder>::ptr _analyzer;
irs::string_ref _name;
irs::bytes_ref _value;
ValueStorage _storeValues;
Expand Down
2 changes: 1 addition & 1 deletion arangod/IResearch/IResearchFilterFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3268,7 +3268,7 @@ Result fromFuncPhrase(
size_t valueArgsEnd = argc;

irs::by_phrase* phrase = nullptr;
irs::analysis::analyzer::ptr analyzer;
AnalyzerPool::CacheType::ptr analyzer;
// prepare filter if execution phase
if (filter) {
std::string name;
Expand Down
2 changes: 1 addition & 1 deletion arangod/IResearch/IResearchPrimaryKeyFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ irs::doc_iterator::ptr PrimaryKeyFilter::execute(
return irs::doc_iterator::empty();
}

auto term = pkField->iterator();
auto term = pkField->iterator(irs::SeekMode::RANDOM_ONLY);

auto const pkRef =
irs::numeric_utils::numeric_traits<LocalDocumentId::BaseType>::raw_ref(_pk);
Expand Down
0