Skip to content

Commit

Permalink
Merge pull request #21153 from vespa-engine/toregge/add-memory-alloca…
Browse files Browse the repository at this point in the history
…tor-to-enum-store

Add memory allocator to enum store.
  • Loading branch information
baldersheim authored Feb 11, 2022
2 parents ca7f13c + 187b9d0 commit 0f3e655
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions searchlib/src/tests/attribute/enumstore/enumstore_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/searchlib/attribute/enumstore.hpp>
#include <vespa/vespalib/test/memory_allocator_observer.h>
#include <vespa/vespalib/gtest/gtest.h>

#include <vespa/log/log.h>
Expand All @@ -11,6 +12,8 @@ using vespalib::datastore::CompactionStrategy;
using vespalib::datastore::EntryRef;
using vespalib::datastore::EntryRefFilter;
using RefT = vespalib::datastore::EntryRefT<22>;
using vespalib::alloc::test::MemoryAllocatorObserver;
using AllocStats = MemoryAllocatorObserver::Stats;

namespace vespalib::datastore {

Expand Down Expand Up @@ -374,6 +377,13 @@ TEST(EnumStoreTest, address_space_usage_is_reported)
EXPECT_EQ(AddressSpace(3, 3, ADDRESS_LIMIT + 2), store.get_values_address_space_usage());
}

TEST(EnumStoreTest, provided_memory_allocator_is_used)
{
AllocStats stats;
NumericEnumStore ses(false, DictionaryConfig::Type::BTREE, std::make_unique<MemoryAllocatorObserver>(stats));
EXPECT_EQ(AllocStats(1, 0), stats);
}

class BatchUpdaterTest : public ::testing::Test {
public:
NumericEnumStore store;
Expand Down
1 change: 1 addition & 0 deletions searchlib/src/vespa/searchlib/attribute/enumstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class EnumStoreT : public IEnumStore {
std::unique_ptr<EntryComparator> allocate_optionally_folded_comparator(bool folded) const;
ComparatorType make_optionally_folded_comparator(bool folded) const;
public:
EnumStoreT(bool has_postings, const search::DictionaryConfig& dict_cfg, std::shared_ptr<vespalib::alloc::MemoryAllocator> memory_allocator);
EnumStoreT(bool has_postings, const search::DictionaryConfig & dict_cfg);
~EnumStoreT() override;

Expand Down
10 changes: 8 additions & 2 deletions searchlib/src/vespa/searchlib/attribute/enumstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ EnumStoreT<EntryT>::load_unique_value(const void* src, size_t available, Index&
}

template <typename EntryT>
EnumStoreT<EntryT>::EnumStoreT(bool has_postings, const DictionaryConfig & dict_cfg)
: _store({}),
EnumStoreT<EntryT>::EnumStoreT(bool has_postings, const DictionaryConfig& dict_cfg, std::shared_ptr<vespalib::alloc::MemoryAllocator> memory_allocator)
: _store(std::move(memory_allocator)),
_dict(),
_is_folded(dict_cfg.getMatch() == DictionaryConfig::Match::UNCASED),
_comparator(_store.get_data_store()),
Expand All @@ -86,6 +86,12 @@ EnumStoreT<EntryT>::EnumStoreT(bool has_postings, const DictionaryConfig & dict_
_dict = static_cast<IEnumStoreDictionary*>(&_store.get_dictionary());
}

template <typename EntryT>
EnumStoreT<EntryT>::EnumStoreT(bool has_postings, const DictionaryConfig& dict_cfg)
: EnumStoreT<EntryT>(has_postings, dict_cfg, {})
{
}

template <typename EntryT>
EnumStoreT<EntryT>::~EnumStoreT() = default;

Expand Down

0 comments on commit 0f3e655

Please sign in to comment.