summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-08-28 13:28:23 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-08-28 13:45:34 +0000
commit35f99197a7dde6516c56fb4030d838046358eed1 (patch)
tree315f9d93cc4198631b52db45e7d1cacf8c2031de /searchlib
parent403b9de3b91b9898c0125108694f486841f24e89 (diff)
Collapse EnumStoreBase into EnumStoreT in preparation for replacing underlying data store with unique store.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/address_space_usage.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumattributesaver.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h17
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstore.cpp16
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstore.h162
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstore.hpp206
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstorebase.cpp225
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstorebase.h186
-rw-r--r--searchlib/src/vespa/searchlib/attribute/load_utils.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h3
-rw-r--r--searchlib/src/vespa/searchlib/attribute/loadedvalue.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multi_value_mapping.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multienumattribute.h4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multistringpostattribute.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/numericbase.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postingchange.cpp14
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postingchange.h8
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistattribute.h4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postingstore.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.h10
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/sourceblendersearch.cpp1
33 files changed, 418 insertions, 493 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
index c190f8af023..286d10ef1c7 100644
--- a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
@@ -41,7 +41,6 @@ vespa_add_library(searchlib_attribute OBJECT
enumhintsearchcontext.cpp
enum_store_dictionary.cpp
enumstore.cpp
- enumstorebase.cpp
extendableattributes.cpp
fixedsourceselector.cpp
flagattribute.cpp
diff --git a/searchlib/src/vespa/searchlib/attribute/address_space_usage.cpp b/searchlib/src/vespa/searchlib/attribute/address_space_usage.cpp
index 4ad06fae54c..e03eec2764a 100644
--- a/searchlib/src/vespa/searchlib/attribute/address_space_usage.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/address_space_usage.cpp
@@ -1,7 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "address_space_usage.h"
-#include "enumstorebase.h"
+#include "i_enum_store.h"
namespace search {
@@ -21,7 +21,7 @@ AddressSpaceUsage::AddressSpaceUsage(const AddressSpace &enumStoreUsage_,
AddressSpace
AddressSpaceUsage::defaultEnumStoreUsage()
{
- return AddressSpace(0, 0, EnumStoreBase::DataStoreType::RefType::offsetSize());
+ return AddressSpace(0, 0, IEnumStore::Index::offsetSize());
}
AddressSpace
diff --git a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp
index 689aa102d3a..24c0eeabd2c 100644
--- a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp
@@ -2,7 +2,6 @@
#include "enum_store_dictionary.h"
#include "enumstore.h"
-#include "enumstorebase.h"
#include <vespa/vespalib/btree/btree.hpp>
#include <vespa/vespalib/btree/btreeiterator.hpp>
#include <vespa/vespalib/btree/btreenode.hpp>
diff --git a/searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp b/searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp
index 1c42eaa5835..db235f91798 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "enumattributesaver.h"
+#include "i_enum_store_dictionary.h"
#include "iattributesavetarget.h"
#include <vespa/vespalib/util/bufferwriter.h>
#include <vespa/vespalib/datastore/unique_store_enumerator.hpp>
diff --git a/searchlib/src/vespa/searchlib/attribute/enumattributesaver.h b/searchlib/src/vespa/searchlib/attribute/enumattributesaver.h
index 8d0e69afddc..c399a0a88b1 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumattributesaver.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumattributesaver.h
@@ -2,7 +2,7 @@
#pragma once
-#include "enumstorebase.h"
+#include "i_enum_store.h"
#include <vespa/vespalib/datastore/unique_store_enumerator.h>
namespace search {
diff --git a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.cpp b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.cpp
index f221ac858bd..28a270555d3 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.cpp
@@ -25,15 +25,15 @@ EnumHintSearchContext::~EnumHintSearchContext() = default;
void
-EnumHintSearchContext::lookupTerm(const EnumStoreComparator &comp)
+EnumHintSearchContext::lookupTerm(const datastore::EntryComparator &comp)
{
_uniqueValues = _dict_snapshot->count(comp);
}
void
-EnumHintSearchContext::lookupRange(const EnumStoreComparator &low,
- const EnumStoreComparator &high)
+EnumHintSearchContext::lookupRange(const datastore::EntryComparator &low,
+ const datastore::EntryComparator &high)
{
_uniqueValues = _dict_snapshot->count_in_range(low, high);
}
diff --git a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h
index 6f766bec386..5a20318ae7b 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h
@@ -2,11 +2,15 @@
#pragma once
-#include "enumstore.h"
+#include "i_enum_store_dictionary.h"
#include "ipostinglistsearchcontext.h"
#include <vespa/searchlib/queryeval/searchiterator.h>
-namespace search::attribute {
+namespace search {
+
+namespace datastore { class EntryComparator; }
+
+namespace attribute {
/**
* Search context helper for enumerated attributes, used to eliminate
@@ -19,16 +23,16 @@ class EnumHintSearchContext : public IPostingListSearchContext
uint32_t _uniqueValues;
uint32_t _docIdLimit;
uint64_t _numValues; // attr.getStatus().getNumValues();
-
+
protected:
EnumHintSearchContext(const IEnumStoreDictionary &dictionary,
uint32_t docIdLimit,
uint64_t numValues);
~EnumHintSearchContext();
- void lookupTerm(const EnumStoreComparator &comp);
- void lookupRange(const EnumStoreComparator &low, const EnumStoreComparator &high);
-
+ void lookupTerm(const datastore::EntryComparator &comp);
+ void lookupRange(const datastore::EntryComparator &low, const datastore::EntryComparator &high);
+
queryeval::SearchIterator::UP
createPostingIterator(fef::TermFieldMatchData *matchData, bool strict) override;
@@ -37,3 +41,4 @@ protected:
};
}
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.cpp b/searchlib/src/vespa/searchlib/attribute/enumstore.cpp
index c45486f9513..4cf5ea9c766 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstore.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumstore.cpp
@@ -1,6 +1,8 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "enumstore.hpp"
+#include <vespa/vespalib/stllike/hash_map.hpp>
+#include <vespa/vespalib/util/rcuvector.hpp>
#include <iomanip>
#include <vespa/log/log.h>
@@ -82,6 +84,12 @@ EnumStoreT<StringEntryType>::deserialize(const void *src,
return sz;
}
+vespalib::asciistream & operator << (vespalib::asciistream & os, const IEnumStore::Index & idx) {
+ return os << "offset(" << idx.offset() << "), bufferId(" << idx.bufferId() << "), idx(" << idx.ref() << ")";
+}
+
+template class datastore::DataStoreT<IEnumStore::Index>;
+
template
class btree::BTreeBuilder<IEnumStore::Index, btree::BTreeNoLeafData, btree::NoAggregated,
EnumTreeTraits::INTERNAL_SLOTS, EnumTreeTraits::LEAF_SLOTS>;
@@ -99,3 +107,11 @@ template class EnumStoreT<NumericEntryType<float> >;
template class EnumStoreT<NumericEntryType<double> >;
} // namespace search
+
+namespace vespalib {
+ template class RcuVectorBase<search::IEnumStore::Index>;
+}
+
+VESPALIB_HASH_MAP_INSTANTIATE_H_E_M(search::IEnumStore::Index, search::IEnumStore::Index,
+ vespalib::hash<search::IEnumStore::Index>, std::equal_to<search::IEnumStore::Index>,
+ vespalib::hashtable_base::and_modulator);
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.h b/searchlib/src/vespa/searchlib/attribute/enumstore.h
index be2a8eafd9e..fa5e9611c55 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstore.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumstore.h
@@ -3,7 +3,7 @@
#pragma once
#include "enum_store_dictionary.h"
-#include "enumstorebase.h"
+#include "i_enum_store.h"
#include <vespa/searchlib/util/foldedstringcompare.h>
#include <vespa/vespalib/btree/btreenode.h>
#include <vespa/vespalib/btree/btreenodeallocator.h>
@@ -74,7 +74,7 @@ struct FloatingPointCompareHelper
// EnumStoreT
//-----------------------------------------------------------------------------
template <class EntryType>
-class EnumStoreT : public EnumStoreBase
+class EnumStoreT : public IEnumStore
{
friend class EnumStoreTest;
public:
@@ -82,9 +82,31 @@ public:
using ComparatorType = EnumStoreComparatorT<EntryType>;
using FoldedComparatorType = EnumStoreFoldedComparatorT<EntryType>;
using EnumStoreType = EnumStoreT<EntryType>;
- using EnumStoreBase::deserialize;
- using EnumStoreBase::fixupRefCounts;
- using EnumStoreBase::reset;
+ using DataStoreType = datastore::DataStoreT<Index>;
+ using generation_t = vespalib::GenerationHandler::generation_t;
+
+ class EntryBase {
+ protected:
+ char * _data;
+ public:
+ EntryBase(void * data) : _data(static_cast<char *>(data)) {}
+ uint32_t getRefCount() const {
+ return *(reinterpret_cast<uint32_t *>(_data) + 1);
+ }
+ void incRefCount() {
+ uint32_t *dst = reinterpret_cast<uint32_t *>(_data) + 1;
+ ++(*dst);
+ }
+ void decRefCount() {
+ uint32_t *dst = reinterpret_cast<uint32_t *>(_data) + 1;
+ --(*dst);
+ }
+ void setRefCount(uint32_t refCount) {
+ uint32_t *dst = reinterpret_cast<uint32_t *>(_data) + 1;
+ *dst = refCount;
+ }
+ static uint32_t size() { return 2*sizeof(uint32_t); }
+ };
class Entry : public EntryBase {
public:
@@ -92,9 +114,40 @@ public:
Type getValue() const;
static uint32_t fixedSize() { return EntryBase::size() + EntryType::fixedSize(); }
};
+
+ class EnumBufferType : public datastore::BufferType<char> {
+ private:
+ size_t _minSizeNeeded; // lower cap for sizeNeeded
+ size_t _deadElems; // dead elements in active buffer
+ bool _pendingCompact;
+ bool _wantCompact;
+ public:
+ EnumBufferType();
+ size_t calcArraysToAlloc(uint32_t bufferId, size_t sizeNeeded, bool resizing) const override;
+ void setSizeNeededAndDead(size_t sizeNeeded, size_t deadElems) {
+ _minSizeNeeded = sizeNeeded;
+ _deadElems = deadElems;
+ }
+ void onFree(size_t usedElems) override {
+ datastore::BufferType<char>::onFree(usedElems);
+ _pendingCompact = _wantCompact;
+ _wantCompact = false;
+ }
+ void setWantCompact() { _wantCompact = true; }
+ bool getPendingCompact() const { return _pendingCompact; }
+ void clearPendingCompact() { _pendingCompact = false; }
+ };
+
static void insertEntry(char * dst, uint32_t refCount, Type value);
private:
+ IEnumStoreDictionary *_enumDict;
+ DataStoreType _store;
+ EnumBufferType _type;
+ std::vector<uint32_t> _toHoldBuffers; // used during compaction
+
+ static const uint32_t TYPE_ID = 0;
+
EnumStoreT(const EnumStoreT & rhs) = delete;
EnumStoreT & operator=(const EnumStoreT & rhs) = delete;
@@ -102,10 +155,21 @@ private:
memcpy(dst, &value, sizeof(Type));
}
-protected:
- typedef IEnumStore::IndexSet IndexSet;
- using EnumStoreBase::_store;
- using EnumStoreBase::TYPE_ID;
+ EntryBase getEntryBase(Index idx) const {
+ return EntryBase(const_cast<DataStoreType &>(_store).getEntry<char>(idx));
+ }
+ datastore::BufferState & getBuffer(uint32_t bufferIdx) {
+ return _store.getBufferState(bufferIdx);
+ }
+ const datastore::BufferState & getBuffer(uint32_t bufferIdx) const {
+ return _store.getBufferState(bufferIdx);
+ }
+ bool validIndex(Index idx) const {
+ return (idx.valid() && idx.offset() < _store.getBufferState(idx.bufferId()).size());
+ }
+ uint32_t getBufferIndex(datastore::BufferState::State status);
+ void postCompact();
+ bool preCompact(uint64_t bytesNeeded);
Entry getEntry(Index idx) const {
return Entry(const_cast<DataStoreType &>(_store).getEntry<char>(idx));
@@ -114,18 +178,70 @@ protected:
void freeUnusedEnum(Index idx, IndexSet & unused) override;
public:
- EnumStoreT(uint64_t initBufferSize, bool hasPostings)
- : EnumStoreBase(initBufferSize, hasPostings)
- {
+ EnumStoreT(uint64_t initBufferSize, bool hasPostings);
+ virtual ~EnumStoreT();
+
+ void reset(uint64_t initBufferSize);
+
+ uint32_t getRefCount(Index idx) const { return getEntryBase(idx).getRefCount(); }
+ void incRefCount(Index idx) { getEntryBase(idx).incRefCount(); }
+ void decRefCount(Index idx) { getEntryBase(idx).decRefCount(); }
+
+ // Only use when reading from enumerated attribute save files
+ void fixupRefCount(Index idx, uint32_t refCount) override {
+ getEntryBase(idx).setRefCount(refCount);
+ }
+
+ uint32_t getNumUniques() const override { return _enumDict->getNumUniques(); }
+
+ uint32_t getRemaining() const {
+ return _store.getBufferState(_store.getActiveBufferId(TYPE_ID)).remaining();
+ }
+ uint32_t getCapacity() const {
+ return _store.getBufferState(_store.getActiveBufferId(TYPE_ID)).capacity();
+ }
+ vespalib::MemoryUsage getMemoryUsage() const override { return _store.getMemoryUsage(); }
+ vespalib::MemoryUsage getTreeMemoryUsage() const override { return _enumDict->get_memory_usage(); }
+
+ vespalib::AddressSpace getAddressSpaceUsage() const;
+
+ void transferHoldLists(generation_t generation);
+ void trimHoldLists(generation_t firstUsed);
+
+ static void failNewSize(uint64_t minNewSize, uint64_t maxSize);
+
+ // Align buffers and entries to 4 bytes boundary.
+ static uint64_t alignBufferSize(uint64_t val) { return Index::align(val); }
+ static uint32_t alignEntrySize(uint32_t val) { return Index::align(val); }
+
+ void fallbackResize(uint64_t bytesNeeded);
+ bool getPendingCompact() const { return _type.getPendingCompact(); }
+ void clearPendingCompact() { _type.clearPendingCompact(); }
+
+ ssize_t deserialize0(const void *src, size_t available, IndexVector &idx) override;
+
+ ssize_t deserialize(const void *src, size_t available, IndexVector &idx) {
+ return _enumDict->deserialize(src, available, idx);
+ }
+
+ void fixupRefCounts(const EnumVector &hist) { _enumDict->fixupRefCounts(hist); }
+ void freezeTree() { _enumDict->freeze(); }
+
+ IEnumStoreDictionary &getEnumStoreDict() override { return *_enumDict; }
+ const IEnumStoreDictionary &getEnumStoreDict() const override { return *_enumDict; }
+ EnumPostingTree &getPostingDictionary() { return _enumDict->getPostingDictionary(); }
+
+ const EnumPostingTree &getPostingDictionary() const {
+ return _enumDict->getPostingDictionary();
}
+ const datastore::DataStoreBase &get_data_store_base() const override { return _store; }
+
bool getValue(Index idx, Type & value) const;
Type getValue(uint32_t idx) const { return getValue(Index(datastore::EntryRef(idx))); }
Type getValue(Index idx) const { return getEntry(idx).getValue(); }
- static uint32_t
- getEntrySize(Type value)
- {
+ static uint32_t getEntrySize(Type value) {
return alignEntrySize(EntryBase::size() + EntryType::size(value));
}
@@ -192,17 +308,17 @@ public:
}
void writeValues(BufferWriter &writer, const Index *idxs, size_t count) const override;
- ssize_t deserialize(const void *src, size_t available, size_t &initSpace) override;
- ssize_t deserialize(const void *src, size_t available, Index &idx) override;
+ ssize_t deserialize(const void *src, size_t available, size_t &initSpace);
+ ssize_t deserialize(const void *src, size_t available, Index &idx);
bool foldedChange(const Index &idx1, const Index &idx2) override;
virtual bool findEnum(Type value, IEnumStore::EnumHandle &e) const;
virtual std::vector<IEnumStore::EnumHandle> findFoldedEnums(Type value) const;
void addEnum(Type value, Index &newIdx);
virtual bool findIndex(Type value, Index &idx) const;
void freeUnusedEnums(bool movePostingidx) override;
- void freeUnusedEnums(const IndexSet& toRemove) override;
+ void freeUnusedEnums(const IndexSet& toRemove);
void reset(Builder &builder);
- bool performCompaction(uint64_t bytesNeeded, EnumIndexMap & old2New) override;
+ bool performCompaction(uint64_t bytesNeeded, EnumIndexMap & old2New);
private:
template <typename Dictionary>
@@ -215,12 +331,18 @@ private:
void performCompaction(Dictionary &dict, EnumIndexMap & old2New);
};
+vespalib::asciistream & operator << (vespalib::asciistream & os, const IEnumStore::Index & idx);
+
+extern template
+class datastore::DataStoreT<IEnumStore::Index>;
+
+
template <typename EntryType>
inline typename EntryType::Type
EnumStoreT<EntryType>::Entry::getValue() const // implementation for numeric
{
Type dst;
- const char * src = _data + EntryBase::size();
+ const char * src = this->_data + EntryBase::size();
memcpy(&dst, src, sizeof(Type));
return dst;
}
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp
index 297a5e3f807..428875e00db 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp
@@ -5,6 +5,7 @@
#include "enumstore.h"
#include "enumcomparator.h"
+#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/util/hdr_abort.h>
#include <vespa/vespalib/btree/btreenode.hpp>
#include <vespa/vespalib/btree/btreenodestore.hpp>
@@ -25,15 +26,49 @@ const uint32_t dummy_enum_value = 0;
}
template <typename EntryType>
-void EnumStoreT<EntryType>::freeUnusedEnum(Index idx, IndexSet & unused)
+EnumStoreT<EntryType>::EnumBufferType::EnumBufferType()
+ : datastore::BufferType<char>(Index::align(1),
+ Index::offsetSize() / Index::align(1),
+ Index::offsetSize() / Index::align(1)),
+ _minSizeNeeded(0),
+ _deadElems(0),
+ _pendingCompact(false),
+ _wantCompact(false)
{
- Entry e = getEntry(idx);
- if (e.getRefCount() == 0) {
- Type value = e.getValue();
- if (unused.insert(idx).second) {
- _store.incDead(idx, getEntrySize(value));
- }
+}
+
+template <typename EntryType>
+size_t
+EnumStoreT<EntryType>::EnumBufferType::calcArraysToAlloc(uint32_t bufferId, size_t sizeNeeded, bool resizing) const
+{
+ (void) resizing;
+ size_t reservedElements = getReservedElements(bufferId);
+ sizeNeeded = std::max(sizeNeeded, _minSizeNeeded);
+ size_t usedElems = _activeUsedElems;
+ if (_lastUsedElems != nullptr) {
+ usedElems += *_lastUsedElems;
+ }
+ assert((usedElems % _arraySize) == 0);
+ double growRatio = 1.5f;
+ uint64_t maxSize = static_cast<uint64_t>(_maxArrays) * _arraySize;
+ uint64_t newSize = usedElems - _deadElems + sizeNeeded;
+ if (usedElems != 0) {
+ newSize *= growRatio;
}
+ newSize += reservedElements;
+ newSize = alignBufferSize(newSize);
+ assert((newSize % _arraySize) == 0);
+ if (newSize <= maxSize) {
+ return newSize / _arraySize;
+ }
+ newSize = usedElems - _deadElems + sizeNeeded + reservedElements + 1000000;
+ newSize = alignBufferSize(newSize);
+ assert((newSize % _arraySize) == 0);
+ if (newSize <= maxSize) {
+ return _maxArrays;
+ }
+ failNewSize(newSize, maxSize);
+ return 0;
}
template <typename EntryType>
@@ -54,6 +89,161 @@ EnumStoreT<StringEntryType>::
insertEntryValue(char * dst, Type value);
template <typename EntryType>
+uint32_t
+EnumStoreT<EntryType>::getBufferIndex(datastore::BufferState::State status)
+{
+ for (uint32_t i = 0; i < _store.getNumBuffers(); ++i) {
+ if (_store.getBufferState(i).getState() == status) {
+ return i;
+ }
+ }
+ return Index::numBuffers();
+}
+
+template <typename EntryType>
+void
+EnumStoreT<EntryType>::postCompact()
+{
+ _store.finishCompact(_toHoldBuffers);
+}
+
+template <typename EntryType>
+bool
+EnumStoreT<EntryType>::preCompact(uint64_t bytesNeeded)
+{
+ if (getBufferIndex(datastore::BufferState::FREE) == Index::numBuffers()) {
+ return false;
+ }
+ uint32_t activeBufId = _store.getActiveBufferId(TYPE_ID);
+ datastore::BufferState & activeBuf = _store.getBufferState(activeBufId);
+ _type.setSizeNeededAndDead(bytesNeeded, activeBuf.getDeadElems());
+ _toHoldBuffers = _store.startCompact(TYPE_ID);
+ return true;
+}
+
+template <typename EntryType>
+void EnumStoreT<EntryType>::freeUnusedEnum(Index idx, IndexSet & unused)
+{
+ Entry e = getEntry(idx);
+ if (e.getRefCount() == 0) {
+ Type value = e.getValue();
+ if (unused.insert(idx).second) {
+ _store.incDead(idx, getEntrySize(value));
+ }
+ }
+}
+
+template <typename EntryType>
+EnumStoreT<EntryType>::EnumStoreT(uint64_t initBufferSize, bool hasPostings)
+ : _enumDict(nullptr),
+ _store(),
+ _type(),
+ _toHoldBuffers()
+{
+ if (hasPostings) {
+ _enumDict = new EnumStoreDictionary<EnumPostingTree>(*this);
+ } else {
+ _enumDict = new EnumStoreDictionary<EnumTree>(*this);
+ }
+ _store.addType(&_type);
+ _type.setSizeNeededAndDead(initBufferSize, 0);
+ _store.initActiveBuffers();
+}
+
+template <typename EntryType>
+EnumStoreT<EntryType>::~EnumStoreT()
+{
+ _store.clearHoldLists();
+ _store.dropBuffers();
+ delete _enumDict;
+}
+
+template <typename EntryType>
+void
+EnumStoreT<EntryType>::reset(uint64_t initBufferSize)
+{
+ _store.clearHoldLists();
+ _store.dropBuffers();
+ _type.setSizeNeededAndDead(initBufferSize, 0);
+ _store.initActiveBuffers();
+ _enumDict->onReset();
+}
+
+template <typename EntryType>
+vespalib::AddressSpace
+EnumStoreT<EntryType>::getAddressSpaceUsage() const
+{
+ const datastore::BufferState &activeState = _store.getBufferState(_store.getActiveBufferId(TYPE_ID));
+ return vespalib::AddressSpace(activeState.size(), activeState.getDeadElems(), DataStoreType::RefType::offsetSize());
+}
+
+template <typename EntryType>
+void
+EnumStoreT<EntryType>::transferHoldLists(generation_t generation)
+{
+ _enumDict->transfer_hold_lists(generation);
+ _store.transferHoldLists(generation);
+}
+
+template <typename EntryType>
+void
+EnumStoreT<EntryType>::trimHoldLists(generation_t firstUsed)
+{
+ // remove generations in the range [0, firstUsed>
+ _enumDict->trim_hold_lists(firstUsed);
+ _store.trimHoldLists(firstUsed);
+}
+
+template <typename EntryType>
+void
+EnumStoreT<EntryType>::failNewSize(uint64_t minNewSize, uint64_t maxSize)
+{
+ throw vespalib::IllegalStateException(vespalib::make_string("EnumStoreT::failNewSize: Minimum new size (%" PRIu64 ") exceeds max size (%" PRIu64 ")", minNewSize, maxSize));
+}
+
+template <typename EntryType>
+void
+EnumStoreT<EntryType>::fallbackResize(uint64_t bytesNeeded)
+{
+ uint32_t activeBufId = _store.getActiveBufferId(TYPE_ID);
+ size_t reservedElements = _type.getReservedElements(activeBufId);
+ _type.setSizeNeededAndDead(bytesNeeded, reservedElements);
+ _type.setWantCompact();
+ _store.fallbackResize(activeBufId, bytesNeeded);
+}
+
+template <typename EntryType>
+ssize_t
+EnumStoreT<EntryType>::deserialize0(const void *src,
+ size_t available,
+ IndexVector &idx)
+{
+ size_t left = available;
+ size_t initSpace = Index::align(1);
+ const char * p = static_cast<const char *>(src);
+ while (left > 0) {
+ ssize_t sz = deserialize(p, left, initSpace);
+ if (sz < 0)
+ return sz;
+ p += sz;
+ left -= sz;
+ }
+ reset(initSpace);
+ left = available;
+ p = static_cast<const char *>(src);
+ Index idx1;
+ while (left > 0) {
+ ssize_t sz = deserialize(p, left, idx1);
+ if (sz < 0)
+ return sz;
+ p += sz;
+ left -= sz;
+ idx.push_back(idx1);
+ }
+ return available - left;
+}
+
+template <typename EntryType>
bool
EnumStoreT<EntryType>::getValue(Index idx, Type & value) const
{
@@ -308,7 +498,7 @@ void
EnumStoreT<EntryType>::reset(Builder &builder, Dictionary &dict)
{
typedef typename Dictionary::Builder DictionaryBuilder;
- EnumStoreBase::reset(builder.getBufferSize());
+ reset(builder.getBufferSize());
DictionaryBuilder treeBuilder(dict.getAllocator());
uint32_t activeBufferId = _store.getActiveBufferId(TYPE_ID);
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstorebase.cpp b/searchlib/src/vespa/searchlib/attribute/enumstorebase.cpp
deleted file mode 100644
index 7aba3547339..00000000000
--- a/searchlib/src/vespa/searchlib/attribute/enumstorebase.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "enumstorebase.h"
-#include "enumstore.h"
-#include "enum_store_dictionary.h"
-#include <vespa/vespalib/btree/btree.hpp>
-#include <vespa/vespalib/btree/btreeiterator.hpp>
-#include <vespa/vespalib/btree/btreenode.hpp>
-#include <vespa/vespalib/btree/btreenodeallocator.hpp>
-#include <vespa/vespalib/btree/btreeroot.hpp>
-#include <vespa/vespalib/datastore/datastore.hpp>
-#include <vespa/vespalib/datastore/unique_store_dictionary.hpp>
-#include <vespa/vespalib/stllike/asciistream.h>
-#include <vespa/vespalib/stllike/hash_map.hpp>
-#include <vespa/vespalib/util/bufferwriter.h>
-#include <vespa/vespalib/util/exceptions.h>
-#include <vespa/vespalib/util/rcuvector.hpp>
-
-
-#include <vespa/log/log.h>
-LOG_SETUP(".searchlib.attribute.enumstorebase");
-
-namespace search {
-
-using btree::BTreeNode;
-
-EnumStoreBase::EnumBufferType::EnumBufferType()
- : datastore::BufferType<char>(Index::align(1),
- Index::offsetSize() / Index::align(1),
- Index::offsetSize() / Index::align(1)),
- _minSizeNeeded(0),
- _deadElems(0),
- _pendingCompact(false),
- _wantCompact(false)
-{
-}
-
-size_t
-EnumStoreBase::EnumBufferType::calcArraysToAlloc(uint32_t bufferId, size_t sizeNeeded, bool resizing) const
-{
- (void) resizing;
- size_t reservedElements = getReservedElements(bufferId);
- sizeNeeded = std::max(sizeNeeded, _minSizeNeeded);
- size_t usedElems = _activeUsedElems;
- if (_lastUsedElems != nullptr) {
- usedElems += *_lastUsedElems;
- }
- assert((usedElems % _arraySize) == 0);
- double growRatio = 1.5f;
- uint64_t maxSize = static_cast<uint64_t>(_maxArrays) * _arraySize;
- uint64_t newSize = usedElems - _deadElems + sizeNeeded;
- if (usedElems != 0) {
- newSize *= growRatio;
- }
- newSize += reservedElements;
- newSize = alignBufferSize(newSize);
- assert((newSize % _arraySize) == 0);
- if (newSize <= maxSize) {
- return newSize / _arraySize;
- }
- newSize = usedElems - _deadElems + sizeNeeded + reservedElements + 1000000;
- newSize = alignBufferSize(newSize);
- assert((newSize % _arraySize) == 0);
- if (newSize <= maxSize) {
- return _maxArrays;
- }
- failNewSize(newSize, maxSize);
- return 0;
-}
-
-EnumStoreBase::EnumStoreBase(uint64_t initBufferSize, bool hasPostings)
- : _enumDict(nullptr),
- _store(),
- _type(),
- _toHoldBuffers()
-{
- if (hasPostings)
- _enumDict = new EnumStoreDictionary<EnumPostingTree>(*this);
- else
- _enumDict = new EnumStoreDictionary<EnumTree>(*this);
- _store.addType(&_type);
- _type.setSizeNeededAndDead(initBufferSize, 0);
- _store.initActiveBuffers();
-}
-
-EnumStoreBase::~EnumStoreBase()
-{
- _store.clearHoldLists();
- _store.dropBuffers();
- delete _enumDict;
-}
-
-void
-EnumStoreBase::reset(uint64_t initBufferSize)
-{
- _store.clearHoldLists();
- _store.dropBuffers();
- _type.setSizeNeededAndDead(initBufferSize, 0);
- _store.initActiveBuffers();
- _enumDict->onReset();
-}
-
-uint32_t
-EnumStoreBase::getBufferIndex(datastore::BufferState::State status)
-{
- for (uint32_t i = 0; i < _store.getNumBuffers(); ++i) {
- if (_store.getBufferState(i).getState() == status) {
- return i;
- }
- }
- return Index::numBuffers();
-}
-
-vespalib::MemoryUsage
-EnumStoreBase::getMemoryUsage() const
-{
- return _store.getMemoryUsage();
-}
-
-vespalib::AddressSpace
-EnumStoreBase::getAddressSpaceUsage() const
-{
- const datastore::BufferState &activeState = _store.getBufferState(_store.getActiveBufferId(TYPE_ID));
- return vespalib::AddressSpace(activeState.size(), activeState.getDeadElems(), DataStoreType::RefType::offsetSize());
-}
-
-void
-EnumStoreBase::transferHoldLists(generation_t generation)
-{
- _enumDict->transfer_hold_lists(generation);
- _store.transferHoldLists(generation);
-}
-
-void
-EnumStoreBase::trimHoldLists(generation_t firstUsed)
-{
- // remove generations in the range [0, firstUsed>
- _enumDict->trim_hold_lists(firstUsed);
- _store.trimHoldLists(firstUsed);
-}
-
-bool
-EnumStoreBase::preCompact(uint64_t bytesNeeded)
-{
- if (getBufferIndex(datastore::BufferState::FREE) == Index::numBuffers()) {
- return false;
- }
- uint32_t activeBufId = _store.getActiveBufferId(TYPE_ID);
- datastore::BufferState & activeBuf = _store.getBufferState(activeBufId);
- _type.setSizeNeededAndDead(bytesNeeded, activeBuf.getDeadElems());
- _toHoldBuffers = _store.startCompact(TYPE_ID);
- return true;
-}
-
-
-void
-EnumStoreBase::fallbackResize(uint64_t bytesNeeded)
-{
- uint32_t activeBufId = _store.getActiveBufferId(TYPE_ID);
- size_t reservedElements = _type.getReservedElements(activeBufId);
- _type.setSizeNeededAndDead(bytesNeeded, reservedElements);
- _type.setWantCompact();
- _store.fallbackResize(activeBufId, bytesNeeded);
-}
-
-
-void
-EnumStoreBase::postCompact()
-{
- _store.finishCompact(_toHoldBuffers);
-}
-
-void
-EnumStoreBase::failNewSize(uint64_t minNewSize, uint64_t maxSize)
-{
- throw vespalib::IllegalStateException(vespalib::make_string("EnumStoreBase::failNewSize: Minimum new size (%" PRIu64 ") exceeds max size (%" PRIu64 ")", minNewSize, maxSize));
-}
-
-ssize_t
-EnumStoreBase::deserialize0(const void *src,
- size_t available,
- IndexVector &idx)
-{
- size_t left = available;
- size_t initSpace = Index::align(1);
- const char * p = static_cast<const char *>(src);
- while (left > 0) {
- ssize_t sz = deserialize(p, left, initSpace);
- if (sz < 0)
- return sz;
- p += sz;
- left -= sz;
- }
- reset(initSpace);
- left = available;
- p = static_cast<const char *>(src);
- Index idx1;
- while (left > 0) {
- ssize_t sz = deserialize(p, left, idx1);
- if (sz < 0)
- return sz;
- p += sz;
- left -= sz;
- idx.push_back(idx1);
- }
- return available - left;
-}
-
-
-vespalib::asciistream & operator << (vespalib::asciistream & os, const IEnumStore::Index & idx) {
- return os << "offset(" << idx.offset() << "), bufferId(" << idx.bufferId() << "), idx(" << idx.ref() << ")";
-}
-
-
-template class datastore::DataStoreT<IEnumStore::Index>;
-
-}
-
-namespace vespalib {
-template class RcuVectorBase<search::IEnumStore::Index>;
-}
-
-VESPALIB_HASH_MAP_INSTANTIATE_H_E_M(search::IEnumStore::Index, search::IEnumStore::Index,
- vespalib::hash<search::IEnumStore::Index>, std::equal_to<search::IEnumStore::Index>,
- vespalib::hashtable_base::and_modulator);
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstorebase.h b/searchlib/src/vespa/searchlib/attribute/enumstorebase.h
deleted file mode 100644
index cec6c5e5ac8..00000000000
--- a/searchlib/src/vespa/searchlib/attribute/enumstorebase.h
+++ /dev/null
@@ -1,186 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include "enum_store_dictionary.h"
-#include <vespa/searchcommon/attribute/iattributevector.h>
-#include <vespa/vespalib/datastore/datastore.h>
-#include <vespa/vespalib/datastore/entryref.h>
-#include <vespa/vespalib/util/address_space.h>
-#include <vespa/vespalib/util/array.h>
-#include <vespa/vespalib/util/memoryusage.h>
-#include <atomic>
-#include <set>
-
-namespace vespalib { class asciistream; }
-namespace search {
-
-class BufferWriter;
-
-namespace attribute { class Status; }
-
-using EnumStoreComparator = datastore::EntryComparator;
-
-
-class EnumStoreBase : public IEnumStore {
-public:
- using DataStoreType = datastore::DataStoreT<Index>;
- using generation_t = vespalib::GenerationHandler::generation_t;
-
-
- class EntryBase {
- protected:
- char * _data;
- public:
- EntryBase(void * data) : _data(static_cast<char *>(data)) {}
-
- uint32_t getRefCount() const {
- return *(reinterpret_cast<uint32_t *>(_data) + 1);
- }
-
- void incRefCount() {
- uint32_t *dst = reinterpret_cast<uint32_t *>(_data) + 1;
- ++(*dst);
- }
-
- void decRefCount() {
- uint32_t *dst = reinterpret_cast<uint32_t *>(_data) + 1;
- --(*dst);
- }
-
- void setRefCount(uint32_t refCount) {
- uint32_t *dst = reinterpret_cast<uint32_t *>(_data) + 1;
- *dst = refCount;
- }
-
- static uint32_t size() { return 2*sizeof(uint32_t); }
- };
-
-protected:
-
- class EnumBufferType : public datastore::BufferType<char> {
- private:
- size_t _minSizeNeeded; // lower cap for sizeNeeded
- size_t _deadElems; // dead elements in active buffer
- bool _pendingCompact;
- bool _wantCompact;
- public:
- EnumBufferType();
-
- size_t calcArraysToAlloc(uint32_t bufferId, size_t sizeNeeded, bool resizing) const override;
-
- void setSizeNeededAndDead(size_t sizeNeeded, size_t deadElems) {
- _minSizeNeeded = sizeNeeded;
- _deadElems = deadElems;
- }
-
- void onFree(size_t usedElems) override {
- datastore::BufferType<char>::onFree(usedElems);
- _pendingCompact = _wantCompact;
- _wantCompact = false;
- }
-
- void setWantCompact() { _wantCompact = true; }
- bool getPendingCompact() const { return _pendingCompact; }
- void clearPendingCompact() { _pendingCompact = false; }
- };
-
- IEnumStoreDictionary *_enumDict;
- DataStoreType _store;
- EnumBufferType _type;
- std::vector<uint32_t> _toHoldBuffers; // used during compaction
-
- static const uint32_t TYPE_ID = 0;
-
- EnumStoreBase(uint64_t initBufferSize, bool hasPostings);
-
- virtual ~EnumStoreBase();
-
- EntryBase getEntryBase(Index idx) const {
- return EntryBase(const_cast<DataStoreType &>(_store).getEntry<char>(idx));
- }
- datastore::BufferState & getBuffer(uint32_t bufferIdx) {
- return _store.getBufferState(bufferIdx);
- }
- const datastore::BufferState & getBuffer(uint32_t bufferIdx) const {
- return _store.getBufferState(bufferIdx);
- }
- bool validIndex(Index idx) const {
- return (idx.valid() && idx.offset() < _store.getBufferState(idx.bufferId()).size());
- }
-
- uint32_t getBufferIndex(datastore::BufferState::State status);
- void postCompact();
- bool preCompact(uint64_t bytesNeeded);
-
-public:
- void reset(uint64_t initBufferSize);
-
- uint32_t getRefCount(Index idx) const { return getEntryBase(idx).getRefCount(); }
- void incRefCount(Index idx) { getEntryBase(idx).incRefCount(); }
- void decRefCount(Index idx) { getEntryBase(idx).decRefCount(); }
-
- // Only use when reading from enumerated attribute save files
- void fixupRefCount(Index idx, uint32_t refCount) override {
- getEntryBase(idx).setRefCount(refCount);
- }
-
- uint32_t getNumUniques() const override { return _enumDict->getNumUniques(); }
-
- uint32_t getRemaining() const {
- return _store.getBufferState(_store.getActiveBufferId(TYPE_ID)).remaining();
- }
- uint32_t getCapacity() const {
- return _store.getBufferState(_store.getActiveBufferId(TYPE_ID)).capacity();
- }
- vespalib::MemoryUsage getMemoryUsage() const override;
- vespalib::MemoryUsage getTreeMemoryUsage() const override { return _enumDict->get_memory_usage(); }
-
- vespalib::AddressSpace getAddressSpaceUsage() const;
-
- void transferHoldLists(generation_t generation);
- void trimHoldLists(generation_t firstUsed);
-
- static void failNewSize(uint64_t minNewSize, uint64_t maxSize);
-
- // Align buffers and entries to 4 bytes boundary.
- static uint64_t alignBufferSize(uint64_t val) { return Index::align(val); }
- static uint32_t alignEntrySize(uint32_t val) { return Index::align(val); }
-
- void fallbackResize(uint64_t bytesNeeded);
- bool getPendingCompact() const { return _type.getPendingCompact(); }
- void clearPendingCompact() { _type.clearPendingCompact(); }
-
- virtual ssize_t deserialize(const void *src, size_t available, size_t &initSpace) = 0;
- virtual ssize_t deserialize(const void *src, size_t available, Index &idx) = 0;
-
- ssize_t deserialize0(const void *src, size_t available, IndexVector &idx) override;
-
- ssize_t deserialize(const void *src, size_t available, IndexVector &idx) {
- return _enumDict->deserialize(src, available, idx);
- }
-
- virtual void freeUnusedEnums(const IndexSet& toRemove) = 0;
-
- void fixupRefCounts(const EnumVector &hist) { _enumDict->fixupRefCounts(hist); }
- void freezeTree() { _enumDict->freeze(); }
-
- virtual bool performCompaction(uint64_t bytesNeeded, EnumIndexMap & old2New) = 0;
-
- IEnumStoreDictionary &getEnumStoreDict() override { return *_enumDict; }
- const IEnumStoreDictionary &getEnumStoreDict() const override { return *_enumDict; }
- EnumPostingTree &getPostingDictionary() { return _enumDict->getPostingDictionary(); }
-
- const EnumPostingTree &getPostingDictionary() const {
- return _enumDict->getPostingDictionary();
- }
- const datastore::DataStoreBase &get_data_store_base() const override { return _store; }
-};
-
-vespalib::asciistream & operator << (vespalib::asciistream & os, const IEnumStore::Index & idx);
-
-extern template
-class datastore::DataStoreT<IEnumStore::Index>;
-
-
-}
diff --git a/searchlib/src/vespa/searchlib/attribute/load_utils.cpp b/searchlib/src/vespa/searchlib/attribute/load_utils.cpp
index b33d604c4a8..041daa08cd5 100644
--- a/searchlib/src/vespa/searchlib/attribute/load_utils.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/load_utils.cpp
@@ -1,10 +1,10 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include "i_enum_store.h"
#include "load_utils.hpp"
-#include "multivalue.h"
-#include "enumstorebase.h"
#include "loadedenumvalue.h"
#include "multi_value_mapping.h"
+#include "multivalue.h"
#include <vespa/vespalib/util/array.hpp>
using search::multivalue::Value;
diff --git a/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h b/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h
index a58fa479249..4fa3510fbec 100644
--- a/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h
+++ b/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h
@@ -3,7 +3,8 @@
#pragma once
#include <vespa/vespalib/util/array.h>
-#include <vespa/searchlib/attribute/enumstorebase.h>
+#include <vespa/vespalib/util/arrayref.h>
+#include <vespa/searchlib/attribute/i_enum_store.h>
namespace search
{
diff --git a/searchlib/src/vespa/searchlib/attribute/loadedvalue.h b/searchlib/src/vespa/searchlib/attribute/loadedvalue.h
index f8af21e6fa7..b1d1c178e5f 100644
--- a/searchlib/src/vespa/searchlib/attribute/loadedvalue.h
+++ b/searchlib/src/vespa/searchlib/attribute/loadedvalue.h
@@ -3,7 +3,7 @@
#pragma once
#include <vespa/searchcommon/common/undefinedvalues.h>
-#include <vespa/searchlib/attribute/enumstorebase.h>
+#include <vespa/searchlib/attribute/i_enum_store.h>
#include <vespa/vespalib/datastore/entryref.h>
namespace search
diff --git a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.cpp b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.cpp
index 8cc6d6d6ac6..6a1a5194890 100644
--- a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.cpp
@@ -1,10 +1,10 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include "attributevector.h"
+#include "i_enum_store.h"
#include "multi_value_mapping.h"
#include "multi_value_mapping.hpp"
#include "multivalue.h"
-#include "enumstorebase.h"
-#include "attributevector.h"
#include <vespa/vespalib/util/array.hpp>
using search::multivalue::Value;
diff --git a/searchlib/src/vespa/searchlib/attribute/multienumattribute.h b/searchlib/src/vespa/searchlib/attribute/multienumattribute.h
index 48c3649a9b2..ac271247e70 100644
--- a/searchlib/src/vespa/searchlib/attribute/multienumattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/multienumattribute.h
@@ -2,10 +2,10 @@
#pragma once
-#include "multivalueattribute.h"
-#include "enumstorebase.h"
+#include "i_enum_store.h"
#include "loadedenumvalue.h"
#include "multivalue.h"
+#include "multivalueattribute.h"
#include "no_loaded_vector.h"
namespace search {
diff --git a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.cpp b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.cpp
index 6f0ea37896f..4409bdd5857 100644
--- a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.cpp
@@ -9,7 +9,7 @@ LOG_SETUP(".searchlib.attribute.multi_string_post_attribute");
namespace search {
IEnumStore::Index
-StringEnumIndexMapper::map(IEnumStore::Index original, const EnumStoreComparator & compare) const
+StringEnumIndexMapper::map(IEnumStore::Index original, const datastore::EntryComparator& compare) const
{
return _dictionary.find(original, compare).getKey();
}
diff --git a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp
index 8d956b55733..154bbb91809 100644
--- a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp
@@ -30,7 +30,7 @@ class StringEnumIndexMapper : public EnumIndexMapper
{
public:
StringEnumIndexMapper(const EnumPostingTree & dictionary) : _dictionary(dictionary) { }
- IEnumStore::Index map(IEnumStore::Index original, const EnumStoreComparator & compare) const override;
+ IEnumStore::Index map(IEnumStore::Index original, const datastore::EntryComparator& compare) const override;
virtual bool hasFold() const override { return true; }
private:
const EnumPostingTree & _dictionary;
diff --git a/searchlib/src/vespa/searchlib/attribute/numericbase.h b/searchlib/src/vespa/searchlib/attribute/numericbase.h
index f05f99a622a..687dd0face6 100644
--- a/searchlib/src/vespa/searchlib/attribute/numericbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/numericbase.h
@@ -3,7 +3,7 @@
#pragma once
#include "attributevector.h"
-#include "enumstorebase.h"
+#include "i_enum_store.h"
#include "loadedenumvalue.h"
#include <vespa/searchlib/common/sort.h>
diff --git a/searchlib/src/vespa/searchlib/attribute/postingchange.cpp b/searchlib/src/vespa/searchlib/attribute/postingchange.cpp
index 45bcfb0beac..a98c030bcee 100644
--- a/searchlib/src/vespa/searchlib/attribute/postingchange.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/postingchange.cpp
@@ -102,7 +102,7 @@ removeDupRemovals(std::vector<uint32_t> &removals)
}
IEnumStore::Index
-EnumIndexMapper::map(IEnumStore::Index original, const EnumStoreComparator & compare) const
+EnumIndexMapper::map(IEnumStore::Index original, const datastore::EntryComparator& compare) const
{
(void) compare;
return original;
@@ -170,14 +170,14 @@ public:
const WeightedIndex * entriesOld, size_t szOld,
AlwaysWeightedIndexVector & added, AlwaysWeightedIndexVector & changed, AlwaysWeightedIndexVector & removed);
- ActualChangeComputer(const EnumStoreComparator &compare, const EnumIndexMapper &mapper);
+ ActualChangeComputer(const datastore::EntryComparator& compare, const EnumIndexMapper& mapper);
~ActualChangeComputer();
private:
WeightedIndexVector _oldEntries;
WeightedIndexVector _newEntries;
vespalib::hash_map<uint32_t, uint32_t> _cachedMapping;
- const EnumStoreComparator &_compare;
+ const datastore::EntryComparator &_compare;
const EnumIndexMapper &_mapper;
const bool _hasFold;
@@ -262,7 +262,7 @@ public:
};
template <typename WeightedIndex>
-ActualChangeComputer<WeightedIndex>::ActualChangeComputer(const EnumStoreComparator &compare,
+ActualChangeComputer<WeightedIndex>::ActualChangeComputer(const datastore::EntryComparator &compare,
const EnumIndexMapper &mapper)
: _oldEntries(),
_newEntries(),
@@ -318,7 +318,7 @@ template <typename MultivalueMapping>
PostingMap
PostingChangeComputerT<WeightedIndex, PostingMap>::
compute(const MultivalueMapping & mvm, const DocIndices & docIndices,
- const EnumStoreComparator & compare, const EnumIndexMapper & mapper)
+ const datastore::EntryComparator & compare, const EnumIndexMapper & mapper)
{
typedef ActualChangeComputer<WeightedIndex> AC;
AC actualChange(compare, mapper);
@@ -362,13 +362,13 @@ typedef std::vector<std::pair<uint32_t, std::vector<ValueIndex>>> DocIndicesValu
template WeightedPostingChangeMap PostingChangeComputerT<WeightedIndex, WeightedPostingChangeMap>
::compute<WeightedMultiValueMapping>(const WeightedMultiValueMapping &,
const DocIndicesWeighted &,
- const EnumStoreComparator &,
+ const datastore::EntryComparator &,
const EnumIndexMapper &);
template WeightedPostingChangeMap PostingChangeComputerT<ValueIndex, WeightedPostingChangeMap>
::compute<ValueMultiValueMapping>(const ValueMultiValueMapping &,
const DocIndicesValue &,
- const EnumStoreComparator &,
+ const datastore::EntryComparator &,
const EnumIndexMapper &);
}
diff --git a/searchlib/src/vespa/searchlib/attribute/postingchange.h b/searchlib/src/vespa/searchlib/attribute/postingchange.h
index 3d5cafe098a..569fbfd6517 100644
--- a/searchlib/src/vespa/searchlib/attribute/postingchange.h
+++ b/searchlib/src/vespa/searchlib/attribute/postingchange.h
@@ -2,12 +2,14 @@
#pragma once
+#include "i_enum_store.h"
#include "postingdata.h"
-#include "enumstorebase.h"
#include <vespa/vespalib/util/array.h>
namespace search {
+namespace datastore { class EntryComparator; }
+
class GrowableBitVector;
/**
@@ -48,7 +50,7 @@ class EnumIndexMapper
{
public:
virtual ~EnumIndexMapper() { }
- virtual IEnumStore::Index map(IEnumStore::Index original, const EnumStoreComparator & compare) const;
+ virtual IEnumStore::Index map(IEnumStore::Index original, const datastore::EntryComparator& compare) const;
virtual bool hasFold() const { return false; }
};
@@ -60,7 +62,7 @@ private:
public:
template <typename MultivalueMapping>
static PostingMap compute(const MultivalueMapping & mvm, const DocIndices & docIndices,
- const EnumStoreComparator & compare, const EnumIndexMapper & mapper);
+ const datastore::EntryComparator & compare, const EnumIndexMapper & mapper);
};
template <>
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp
index 800e621045a..c8ee6ab50b2 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp
@@ -114,7 +114,7 @@ PostingListAttributeBase<P>::fillPostingsFixupEnumBase(const LoadedEnumAttribute
template <typename P>
void
PostingListAttributeBase<P>::updatePostings(PostingMap &changePost,
- EnumStoreComparator &cmp)
+ datastore::EntryComparator &cmp)
{
for (auto& elem : changePost) {
auto& change = elem.second;
@@ -159,7 +159,7 @@ PostingListAttributeBase<P>::
clearPostings(attribute::IAttributeVector::EnumHandle eidx,
uint32_t fromLid,
uint32_t toLid,
- EnumStoreComparator &cmp)
+ datastore::EntryComparator &cmp)
{
PostingChange<P> postings;
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h
index 50e97e703c3..69b6cf73fa8 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h
@@ -57,7 +57,7 @@ protected:
virtual void updatePostings(PostingMap & changePost) = 0;
- void updatePostings(PostingMap &changePost, EnumStoreComparator &cmp);
+ void updatePostings(PostingMap &changePost, datastore::EntryComparator &cmp);
void clearAllPostings();
void disableFreeLists() { _postingList.disableFreeLists(); }
void disableElemHoldList() { _postingList.disableElemHoldList(); }
@@ -65,7 +65,7 @@ protected:
bool forwardedOnAddDoc(DocId doc, size_t wantSize, size_t wantCapacity);
void clearPostings(attribute::IAttributeVector::EnumHandle eidx, uint32_t fromLid,
- uint32_t toLid, EnumStoreComparator &cmp);
+ uint32_t toLid, datastore::EntryComparator &cmp);
void forwardedShrinkLidSpace(uint32_t newSize) override;
virtual vespalib::MemoryUsage getMemoryUsage() const override;
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp
index 97d54022cc2..70cf5f00edb 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp
@@ -44,7 +44,7 @@ PostingListSearchContext::~PostingListSearchContext() = default;
void
-PostingListSearchContext::lookupTerm(const EnumStoreComparator &comp)
+PostingListSearchContext::lookupTerm(const datastore::EntryComparator &comp)
{
_lowerDictItr.lower_bound(_frozenDictionary.getRoot(), EnumIndex(), comp);
_upperDictItr = _lowerDictItr;
@@ -56,8 +56,8 @@ PostingListSearchContext::lookupTerm(const EnumStoreComparator &comp)
void
-PostingListSearchContext::lookupRange(const EnumStoreComparator &low,
- const EnumStoreComparator &high)
+PostingListSearchContext::lookupRange(const datastore::EntryComparator &low,
+ const datastore::EntryComparator &high)
{
_lowerDictItr.lower_bound(_frozenDictionary.getRoot(), EnumIndex(), low);
_upperDictItr = _lowerDictItr;
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h
index f31fbd8423d..a274528c92b 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h
@@ -52,8 +52,8 @@ protected:
~PostingListSearchContext();
- void lookupTerm(const EnumStoreComparator &comp);
- void lookupRange(const EnumStoreComparator &low, const EnumStoreComparator &high);
+ void lookupTerm(const datastore::EntryComparator &comp);
+ void lookupRange(const datastore::EntryComparator &low, const datastore::EntryComparator &high);
void lookupSingle();
virtual bool useThis(const DictionaryConstIterator & it) const {
(void) it;
diff --git a/searchlib/src/vespa/searchlib/attribute/postingstore.h b/searchlib/src/vespa/searchlib/attribute/postingstore.h
index 7ca1fa5e641..278b587deda 100644
--- a/searchlib/src/vespa/searchlib/attribute/postingstore.h
+++ b/searchlib/src/vespa/searchlib/attribute/postingstore.h
@@ -2,8 +2,8 @@
#pragma once
+#include "enum_store_dictionary.h"
#include "postinglisttraits.h"
-#include "enumstorebase.h"
#include <set>
namespace search {
diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.h b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.h
index 4895eb2256a..23ec0016abf 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.h
@@ -63,7 +63,7 @@ private:
void mergeMemoryStats(vespalib::MemoryUsage & total) override;
void applyUpdateValueChange(const Change & c, EnumStore & enumStore,
std::map<DocId, EnumIndex> & currEnumIndices);
- void makePostingChange(const EnumStoreComparator *cmp,
+ void makePostingChange(const datastore::EntryComparator *cmp,
const std::map<DocId, EnumIndex> &currEnumIndices,
PostingMap &changePost);
diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp
index 0b80c7cbf4a..8afb0418b68 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp
@@ -53,7 +53,7 @@ SingleValueNumericPostingAttribute<B>::applyUpdateValueChange(const Change & c,
template <typename B>
void
SingleValueNumericPostingAttribute<B>::
-makePostingChange(const EnumStoreComparator *cmpa,
+makePostingChange(const datastore::EntryComparator *cmpa,
const std::map<DocId, EnumIndex> &currEnumIndices,
PostingMap &changePost)
{
diff --git a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h
index 5afbc5aee1b..49d1be93580 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h
@@ -72,7 +72,7 @@ private:
std::map<DocId, EnumIndex> &currEnumIndices);
void
- makePostingChange(const EnumStoreComparator *cmp,
+ makePostingChange(const datastore::EntryComparator *cmp,
Dictionary &dict,
const std::map<DocId, EnumIndex> &currEnumIndices,
PostingMap &changePost);
diff --git a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp
index 8374647311e..ed76a8eca14 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp
@@ -51,7 +51,7 @@ SingleValueStringPostingAttributeT<B>::applyUpdateValueChange(const Change & c,
template <typename B>
void
SingleValueStringPostingAttributeT<B>::
-makePostingChange(const EnumStoreComparator *cmpa,
+makePostingChange(const datastore::EntryComparator *cmpa,
Dictionary &dict,
const std::map<DocId, EnumIndex> &currEnumIndices,
PostingMap &changePost)
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.h b/searchlib/src/vespa/searchlib/attribute/stringbase.h
index 9e441aa2e0c..39f40e0fffe 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.h
@@ -2,15 +2,15 @@
#pragma once
+#include "no_loaded_vector.h"
#include <vespa/searchlib/attribute/attributevector.h>
+#include <vespa/searchlib/attribute/changevector.h>
+#include <vespa/searchlib/attribute/i_enum_store.h>
+#include <vespa/searchlib/attribute/loadedenumvalue.h>
#include <vespa/searchlib/util/foldedstringcompare.h>
+#include <vespa/vespalib/text/lowercase.h>
#include <vespa/vespalib/text/utf8.h>
#include <vespa/vespalib/util/regexp.h>
-#include <vespa/vespalib/text/lowercase.h>
-#include <vespa/searchlib/attribute/enumstorebase.h>
-#include <vespa/searchlib/attribute/loadedenumvalue.h>
-#include "no_loaded_vector.h"
-#include <vespa/searchlib/attribute/changevector.h>
namespace search {
diff --git a/searchlib/src/vespa/searchlib/queryeval/sourceblendersearch.cpp b/searchlib/src/vespa/searchlib/queryeval/sourceblendersearch.cpp
index b372834f3f8..23a0d2d52a6 100644
--- a/searchlib/src/vespa/searchlib/queryeval/sourceblendersearch.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/sourceblendersearch.cpp
@@ -2,6 +2,7 @@
#include "sourceblendersearch.h"
#include "isourceselector.h"
+#include <vespa/fastos/dynamiclibrary.h>
#include <vespa/vespalib/objects/visit.hpp>
#include <vespa/vespalib/util/array.hpp>