summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-10-03 16:14:37 +0200
committerTor Egge <Tor.Egge@online.no>2022-10-03 16:14:37 +0200
commitd2eefff31692a1e5d18461fdde987512be7e58dc (patch)
tree5e385e5c42ac48cc6a13ae19f43551a10f42b44d /searchlib
parent73c11ef2eb40d941593d1616255f44cd66dfefd0 (diff)
Remove AlignedEntryRef.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/memoryindex/datastore/feature_store_test.cpp6
-rw-r--r--searchlib/src/tests/memoryindex/datastore/word_store_test.cpp12
-rw-r--r--searchlib/src/vespa/searchlib/memoryindex/feature_store.cpp34
-rw-r--r--searchlib/src/vespa/searchlib/memoryindex/feature_store.h9
-rw-r--r--searchlib/src/vespa/searchlib/memoryindex/word_store.cpp7
-rw-r--r--searchlib/src/vespa/searchlib/memoryindex/word_store.h7
-rw-r--r--searchlib/src/vespa/searchlib/test/fakedata/fakememtreeocc.cpp11
7 files changed, 44 insertions, 42 deletions
diff --git a/searchlib/src/tests/memoryindex/datastore/feature_store_test.cpp b/searchlib/src/tests/memoryindex/datastore/feature_store_test.cpp
index 34f9f7d27a9..564824031a6 100644
--- a/searchlib/src/tests/memoryindex/datastore/feature_store_test.cpp
+++ b/searchlib/src/tests/memoryindex/datastore/feature_store_test.cpp
@@ -90,8 +90,7 @@ TEST_F(FeatureStoreTest, features_can_be_added_and_retrieved)
r = fs.addFeatures(0, f);
r1 = r.first;
EXPECT_TRUE(r.second > 0);
- EXPECT_EQ(FeatureStore::RefType::align(1u),
- FeatureStore::RefType(r1).offset());
+ EXPECT_EQ(1u, FeatureStore::RefType(r1).offset());
EXPECT_EQ(0u, FeatureStore::RefType(r1).bufferId());
LOG(info,
"bits(%" PRIu64 "), ref.offset(%zu), ref.bufferId(%u)",
@@ -131,8 +130,7 @@ TEST_F(FeatureStoreTest, next_words_are_working)
r = fs.addFeatures(0, f);
r1 = r.first;
EXPECT_TRUE(r.second > 0);
- EXPECT_EQ(FeatureStore::RefType::align(1u),
- FeatureStore::RefType(r1).offset());
+ EXPECT_EQ(1u, FeatureStore::RefType(r1).offset());
EXPECT_EQ(0u, FeatureStore::RefType(r1).bufferId());
LOG(info,
"bits(%" PRIu64 "), ref.offset(%zu), ref.bufferId(%u)",
diff --git a/searchlib/src/tests/memoryindex/datastore/word_store_test.cpp b/searchlib/src/tests/memoryindex/datastore/word_store_test.cpp
index 698780a1dc2..1ca87467fc6 100644
--- a/searchlib/src/tests/memoryindex/datastore/word_store_test.cpp
+++ b/searchlib/src/tests/memoryindex/datastore/word_store_test.cpp
@@ -18,14 +18,14 @@ TEST(WordStoreTest, words_can_be_added_and_retrieved)
EntryRef r1 = ws.addWord(w1);
EntryRef r2 = ws.addWord(w2);
EntryRef r3 = ws.addWord(w3);
- uint32_t invp = WordStore::RefType::align(1); // Reserved as invalid
+ uint32_t invp = WordStore::buffer_array_size; // Reserved as invalid
uint32_t w1s = w1.size() + 1;
- uint32_t w1p = WordStore::RefType::pad(w1s);
+ uint32_t w1p = WordStore::calc_pad(w1s);
uint32_t w2s = w2.size() + 1;
- uint32_t w2p = WordStore::RefType::pad(w2s);
- EXPECT_EQ(invp, WordStore::RefType(r1).offset());
- EXPECT_EQ(invp + w1s + w1p, WordStore::RefType(r2).offset());
- EXPECT_EQ(invp + w1s + w1p + w2s + w2p, WordStore::RefType(r3).offset());
+ uint32_t w2p = WordStore::calc_pad(w2s);
+ EXPECT_EQ(invp, WordStore::RefType(r1).offset() * WordStore::buffer_array_size);
+ EXPECT_EQ(invp + w1s + w1p, WordStore::RefType(r2).offset() * WordStore::buffer_array_size);
+ EXPECT_EQ(invp + w1s + w1p + w2s + w2p, WordStore::RefType(r3).offset() * WordStore::buffer_array_size);
EXPECT_EQ(0u, WordStore::RefType(r1).bufferId());
EXPECT_EQ(0u, WordStore::RefType(r2).bufferId());
EXPECT_EQ(0u, WordStore::RefType(r3).bufferId());
diff --git a/searchlib/src/vespa/searchlib/memoryindex/feature_store.cpp b/searchlib/src/vespa/searchlib/memoryindex/feature_store.cpp
index b37300375a8..b5810d06047 100644
--- a/searchlib/src/vespa/searchlib/memoryindex/feature_store.cpp
+++ b/searchlib/src/vespa/searchlib/memoryindex/feature_store.cpp
@@ -9,6 +9,7 @@ namespace search::memoryindex {
constexpr size_t MIN_BUFFER_ARRAYS = 1024u;
using index::SchemaUtil;
+using vespalib::datastore::EntryRef;
uint64_t
FeatureStore::writeFeatures(uint32_t packedIndex, const DocIdAndFeatures &features)
@@ -26,10 +27,10 @@ FeatureStore::writeFeatures(uint32_t packedIndex, const DocIdAndFeatures &featur
return oldOffset;
}
-vespalib::datastore::EntryRef
+EntryRef
FeatureStore::addFeatures(const uint8_t *src, uint64_t byteLen)
{
- uint32_t pad = RefType::pad(byteLen);
+ uint32_t pad = calc_pad(byteLen);
auto result = _store.rawAllocator<uint8_t>(_typeId).alloc(byteLen + pad, DECODE_SAFETY);
uint8_t *dst = result.data;
memcpy(dst, src, byteLen);
@@ -42,7 +43,7 @@ FeatureStore::addFeatures(const uint8_t *src, uint64_t byteLen)
return result.ref;
}
-std::pair<vespalib::datastore::EntryRef, uint64_t>
+std::pair<EntryRef, uint64_t>
FeatureStore::addFeatures(uint64_t beginOffset, uint64_t endOffset)
{
uint64_t bitLen = (endOffset - beginOffset);
@@ -52,18 +53,18 @@ FeatureStore::addFeatures(uint64_t beginOffset, uint64_t endOffset)
assert(wordLen > 0);
assert(byteLen > 0);
const uint8_t *src = reinterpret_cast<const uint8_t *>(_f._valI - wordLen);
- RefType ref = addFeatures(src, byteLen);
+ EntryRef ref = addFeatures(src, byteLen);
return std::make_pair(ref, bitLen);
}
-vespalib::datastore::EntryRef
-FeatureStore::moveFeatures(vespalib::datastore::EntryRef ref, uint64_t bitLen)
+EntryRef
+FeatureStore::moveFeatures(EntryRef ref, uint64_t bitLen)
{
const uint8_t *src = getBits(ref);
uint64_t byteLen = (bitLen + 7) / 8;
- RefType newRef = addFeatures(src, byteLen);
+ EntryRef newRef = addFeatures(src, byteLen);
// Mark old features as dead
- _store.incDead(ref, byteLen + RefType::pad(byteLen));
+ _store.incDead(ref, byteLen + calc_pad(byteLen));
return newRef;
}
@@ -74,8 +75,7 @@ FeatureStore::FeatureStore(const Schema &schema)
_d(nullptr),
_fieldsParams(),
_schema(schema),
- _type(RefType::align(1u), MIN_BUFFER_ARRAYS,
- RefType::offsetSize() / RefType::align(1u)),
+ _type(buffer_array_size, MIN_BUFFER_ARRAYS, RefType::offsetSize()),
_typeId(0)
{
_f.setWriteContext(&_fctx);
@@ -96,7 +96,7 @@ FeatureStore::~FeatureStore()
_store.dropBuffers();
}
-std::pair<vespalib::datastore::EntryRef, uint64_t>
+std::pair<EntryRef, uint64_t>
FeatureStore::addFeatures(uint32_t packedIndex, const DocIdAndFeatures &features)
{
uint64_t oldOffset = writeFeatures(packedIndex, features);
@@ -109,14 +109,14 @@ void
FeatureStore::add_features_guard_bytes()
{
uint32_t len = DECODE_SAFETY;
- uint32_t pad = RefType::pad(len);
- auto result = _store.rawAllocator<int8_t>(_typeId).alloc(len + pad);
+ uint32_t pad = calc_pad(len);
+ auto result = _store.rawAllocator<uint8_t>(_typeId).alloc(len + pad);
memset(result.data, 0, len + pad);
_store.incDead(result.ref, len + pad);
}
void
-FeatureStore::getFeatures(uint32_t packedIndex, vespalib::datastore::EntryRef ref, DocIdAndFeatures &features)
+FeatureStore::getFeatures(uint32_t packedIndex, EntryRef ref, DocIdAndFeatures &features)
{
setupForField(packedIndex, _d);
setupForReadFeatures(ref, _d);
@@ -124,7 +124,7 @@ FeatureStore::getFeatures(uint32_t packedIndex, vespalib::datastore::EntryRef re
}
size_t
-FeatureStore::bitSize(uint32_t packedIndex, vespalib::datastore::EntryRef ref)
+FeatureStore::bitSize(uint32_t packedIndex, EntryRef ref)
{
setupForField(packedIndex, _d);
setupForUnpackFeatures(ref, _d);
@@ -136,8 +136,8 @@ FeatureStore::bitSize(uint32_t packedIndex, vespalib::datastore::EntryRef ref)
return bitLen;
}
-vespalib::datastore::EntryRef
-FeatureStore::moveFeatures(uint32_t packedIndex, vespalib::datastore::EntryRef ref)
+EntryRef
+FeatureStore::moveFeatures(uint32_t packedIndex, EntryRef ref)
{
uint64_t bitLen = bitSize(packedIndex, ref);
return moveFeatures(ref, bitLen);
diff --git a/searchlib/src/vespa/searchlib/memoryindex/feature_store.h b/searchlib/src/vespa/searchlib/memoryindex/feature_store.h
index a96ae9a8f2d..b1d975d0926 100644
--- a/searchlib/src/vespa/searchlib/memoryindex/feature_store.h
+++ b/searchlib/src/vespa/searchlib/memoryindex/feature_store.h
@@ -14,11 +14,14 @@ namespace search::memoryindex {
*/
class FeatureStore {
public:
- using DataStoreType = vespalib::datastore::DataStoreT<vespalib::datastore::AlignedEntryRefT<22, 2>>;
+ using DataStoreType = vespalib::datastore::DataStoreT<vespalib::datastore::EntryRefT<22>>;
using RefType = DataStoreType::RefType;
using EncodeContext = bitcompression::EG2PosOccEncodeContext<true>;
using DecodeContextCooked = bitcompression::EG2PosOccDecodeContextCooked<true>;
using generation_t = vespalib::GenerationHandler::generation_t;
+ static constexpr uint32_t buffer_array_size = 4u; // Must be a power of 2
+ static constexpr uint32_t pad_constant = buffer_array_size - 1u;
+ static uint32_t calc_pad(uint32_t val) { return (-val & pad_constant); }
private:
using Schema = index::Schema;
@@ -154,7 +157,7 @@ public:
uint32_t bufferId = RefType(ref).bufferId();
const vespalib::datastore::BufferState &state = _store.getBufferState(bufferId);
decoder.setEnd(
- ((_store.getEntry<uint8_t>(RefType(0, bufferId)) + state.size() -
+ ((_store.getEntryArray<uint8_t>(RefType(0, bufferId), buffer_array_size) + state.size() -
bits) + 7) / 8,
false);
}
@@ -188,7 +191,7 @@ public:
*/
const uint8_t *getBits(vespalib::datastore::EntryRef ref) const {
RefType iRef(ref);
- return _store.getEntry<uint8_t>(iRef);
+ return _store.getEntryArray<uint8_t>(iRef, buffer_array_size);
}
/**
diff --git a/searchlib/src/vespa/searchlib/memoryindex/word_store.cpp b/searchlib/src/vespa/searchlib/memoryindex/word_store.cpp
index e5ec4ab7808..441587eb718 100644
--- a/searchlib/src/vespa/searchlib/memoryindex/word_store.cpp
+++ b/searchlib/src/vespa/searchlib/memoryindex/word_store.cpp
@@ -10,16 +10,13 @@ constexpr size_t MIN_BUFFER_ARRAYS = 1024;
WordStore::WordStore()
: _store(),
_numWords(0),
- _type(RefType::align(1),
- MIN_BUFFER_ARRAYS,
- RefType::offsetSize() / RefType::align(1)),
+ _type(buffer_array_size, MIN_BUFFER_ARRAYS, RefType::offsetSize()),
_typeId(0)
{
_store.addType(&_type);
_store.init_primary_buffers();
}
-
WordStore::~WordStore()
{
_store.dropBuffers();
@@ -29,7 +26,7 @@ vespalib::datastore::EntryRef
WordStore::addWord(const vespalib::stringref word)
{
size_t wordSize = word.size() + 1;
- size_t bufferSize = RefType::align(wordSize);
+ size_t bufferSize = wordSize + calc_pad(wordSize);
auto result = _store.rawAllocator<char>(_typeId).alloc(bufferSize);
char *be = result.data;
for (size_t i = 0; i < word.size(); ++i) {
diff --git a/searchlib/src/vespa/searchlib/memoryindex/word_store.h b/searchlib/src/vespa/searchlib/memoryindex/word_store.h
index b27ae65d776..913f6bc3ea5 100644
--- a/searchlib/src/vespa/searchlib/memoryindex/word_store.h
+++ b/searchlib/src/vespa/searchlib/memoryindex/word_store.h
@@ -9,8 +9,11 @@ namespace search::memoryindex {
class WordStore {
public:
- using DataStoreType = vespalib::datastore::DataStoreT<vespalib::datastore::AlignedEntryRefT<22, 2>>;
+ using DataStoreType = vespalib::datastore::DataStoreT<vespalib::datastore::EntryRefT<22>>;
using RefType = DataStoreType::RefType;
+ static constexpr uint32_t buffer_array_size = 4u; // Must be a power of 2
+ static constexpr uint32_t pad_constant = buffer_array_size - 1u;
+ static uint32_t calc_pad(uint32_t val) { return (-val & pad_constant); }
private:
DataStoreType _store;
@@ -24,7 +27,7 @@ public:
vespalib::datastore::EntryRef addWord(const vespalib::stringref word);
const char *getWord(vespalib::datastore::EntryRef ref) const {
RefType internalRef(ref);
- return _store.getEntry<char>(internalRef);
+ return _store.getEntryArray<char>(internalRef, buffer_array_size);
}
vespalib::MemoryUsage getMemoryUsage() const {
diff --git a/searchlib/src/vespa/searchlib/test/fakedata/fakememtreeocc.cpp b/searchlib/src/vespa/searchlib/test/fakedata/fakememtreeocc.cpp
index 433f543ab92..11b6a1e3020 100644
--- a/searchlib/src/vespa/searchlib/test/fakedata/fakememtreeocc.cpp
+++ b/searchlib/src/vespa/searchlib/test/fakedata/fakememtreeocc.cpp
@@ -199,14 +199,14 @@ FakeMemTreeOccMgr::sync()
void
FakeMemTreeOccMgr::add(uint32_t wordIdx, index::DocIdAndFeatures &features)
{
- typedef FeatureStore::RefType RefType;
-
const FakeWord *fw = _fakeWords[wordIdx];
std::pair<EntryRef, uint64_t> r =
_featureStore.addFeatures(fw->getPackedIndex(), features);
+ size_t feature_size = (r.second + 7) / 8;
+ feature_size += FeatureStore::calc_pad(feature_size);
- _featureSizes[wordIdx] += RefType::align((r.second + 7) / 8) * 8;
+ _featureSizes[wordIdx] += feature_size * 8;
_unflushed.push_back(PendingOp(wordIdx, features.doc_id(), r.first));
@@ -240,7 +240,6 @@ FakeMemTreeOccMgr::sortUnflushed()
void
FakeMemTreeOccMgr::flush()
{
- typedef FeatureStore::RefType RefType;
typedef std::vector<PendingOp>::iterator I;
if (_unflushed.empty())
@@ -264,7 +263,9 @@ FakeMemTreeOccMgr::flush()
if (i->getRemove()) {
if (itr.valid() && itr.getKey() == docId) {
uint64_t bits = _featureStore.bitSize(fw->getPackedIndex(), EntryRef(itr.getData().get_features_relaxed()));
- _featureSizes[wordIdx] -= RefType::align((bits + 7) / 8) * 8;
+ size_t feature_size = (bits + 7) / 8;
+ feature_size += FeatureStore::calc_pad(feature_size);
+ _featureSizes[wordIdx] -= feature_size * 8;
tree.remove(itr);
}
} else {