aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2021-12-08 16:30:28 +0100
committerTor Egge <Tor.Egge@online.no>2021-12-08 16:30:28 +0100
commit6903c931a2448583a258786ba9fe5dec99948ecd (patch)
tree38c1690a7e2be8667f3b4cace5159ce8c040f4f7 /vespalib
parentd6462d26bef1ed26970327fb70c2b9a099dd0fb9 (diff)
Add CompactionSpec.
Pass CompactionStrategy to DataStoreBase::startCompactWorstBuffers in preparation for compacting more buffers in the same compaction round.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/btree/btree_store/btree_store_test.cpp10
-rw-r--r--vespalib/src/tests/btree/btree_test.cpp5
-rw-r--r--vespalib/src/tests/datastore/array_store/array_store_test.cpp6
-rw-r--r--vespalib/src/tests/datastore/unique_store/unique_store_test.cpp6
-rw-r--r--vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/btree/btree.h4
-rw-r--r--vespalib/src/vespa/vespalib/btree/btree.hpp4
-rw-r--r--vespalib/src/vespa/vespalib/btree/btreenodeallocator.h3
-rw-r--r--vespalib/src/vespa/vespalib/btree/btreenodestore.h3
-rw-r--r--vespalib/src/vespa/vespalib/btree/btreenodestore.hpp5
-rw-r--r--vespalib/src/vespa/vespalib/btree/btreestore.h6
-rw-r--r--vespalib/src/vespa/vespalib/btree/btreestore.hpp9
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.h2
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.hpp5
-rw-r--r--vespalib/src/vespa/vespalib/datastore/compaction_spec.h28
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastorebase.cpp8
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastorebase.h5
-rw-r--r--vespalib/src/vespa/vespalib/datastore/i_unique_store_dictionary.h3
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store.h2
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store.hpp4
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h2
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp4
22 files changed, 95 insertions, 33 deletions
diff --git a/vespalib/src/tests/btree/btree_store/btree_store_test.cpp b/vespalib/src/tests/btree/btree_store/btree_store_test.cpp
index 77cb8e519e4..974aafb392a 100644
--- a/vespalib/src/tests/btree/btree_store/btree_store_test.cpp
+++ b/vespalib/src/tests/btree/btree_store/btree_store_test.cpp
@@ -5,9 +5,12 @@
#include <vespa/vespalib/btree/btreeroot.hpp>
#include <vespa/vespalib/btree/btreestore.hpp>
#include <vespa/vespalib/datastore/buffer_type.hpp>
+#include <vespa/vespalib/datastore/compaction_strategy.h>
#include <vespa/vespalib/gtest/gtest.h>
using vespalib::GenerationHandler;
+using vespalib::datastore::CompactionSpec;
+using vespalib::datastore::CompactionStrategy;
using vespalib::datastore::EntryRef;
namespace vespalib::btree {
@@ -131,7 +134,9 @@ BTreeStoreTest::test_compact_sequence(uint32_t sequence_length)
move_refs.reserve(refs.size());
auto usage_before = store.getMemoryUsage();
for (uint32_t pass = 0; pass < 15; ++pass) {
- auto to_hold = store.start_compact_worst_buffers();
+ CompactionSpec compaction_spec(true, false);
+ CompactionStrategy compaction_strategy;
+ auto to_hold = store.start_compact_worst_buffers(compaction_spec, compaction_strategy);
std::vector<bool> filter(TreeStore::RefType::numBuffers());
for (auto buffer_id : to_hold) {
filter[buffer_id] = true;
@@ -168,7 +173,8 @@ TEST_F(BTreeStoreTest, require_that_nodes_for_multiple_btrees_are_compacted)
inc_generation();
auto usage_before = store.getMemoryUsage();
for (uint32_t pass = 0; pass < 15; ++pass) {
- auto to_hold = store.start_compact_worst_btree_nodes();
+ CompactionStrategy compaction_strategy;
+ auto to_hold = store.start_compact_worst_btree_nodes(compaction_strategy);
store.move_btree_nodes(refs);
store.finish_compact_worst_btree_nodes(to_hold);
inc_generation();
diff --git a/vespalib/src/tests/btree/btree_test.cpp b/vespalib/src/tests/btree/btree_test.cpp
index 4af0b9672f2..bd4f4f8ee08 100644
--- a/vespalib/src/tests/btree/btree_test.cpp
+++ b/vespalib/src/tests/btree/btree_test.cpp
@@ -17,6 +17,7 @@
#include <vespa/vespalib/btree/btree.hpp>
#include <vespa/vespalib/btree/btreestore.hpp>
#include <vespa/vespalib/datastore/buffer_type.hpp>
+#include <vespa/vespalib/datastore/compaction_strategy.h>
#include <vespa/vespalib/test/btree/btree_printer.h>
#include <vespa/vespalib/gtest/gtest.h>
@@ -24,6 +25,7 @@
LOG_SETUP("btree_test");
using vespalib::GenerationHandler;
+using vespalib::datastore::CompactionStrategy;
using vespalib::datastore::EntryRef;
namespace vespalib::btree {
@@ -1599,8 +1601,9 @@ TEST_F(BTreeTest, require_that_compaction_works)
auto memory_usage_before = t.getAllocator().getMemoryUsage();
t.foreach_key([&before_list](int key) { before_list.emplace_back(key); });
make_iterators(t, before_list, before_iterators);
+ CompactionStrategy compaction_strategy;
for (int i = 0; i < 15; ++i) {
- t.compact_worst();
+ t.compact_worst(compaction_strategy);
}
inc_generation(g, t);
auto memory_usage_after = t.getAllocator().getMemoryUsage();
diff --git a/vespalib/src/tests/datastore/array_store/array_store_test.cpp b/vespalib/src/tests/datastore/array_store/array_store_test.cpp
index dbd6d41f5e6..c58e357a9a1 100644
--- a/vespalib/src/tests/datastore/array_store/array_store_test.cpp
+++ b/vespalib/src/tests/datastore/array_store/array_store_test.cpp
@@ -3,6 +3,8 @@
#include <vespa/vespalib/test/datastore/buffer_stats.h>
#include <vespa/vespalib/test/datastore/memstats.h>
#include <vespa/vespalib/datastore/array_store.hpp>
+#include <vespa/vespalib/datastore/compaction_spec.h>
+#include <vespa/vespalib/datastore/compaction_strategy.h>
#include <vespa/vespalib/stllike/hash_map.hpp>
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/test/insertion_operators.h>
@@ -124,7 +126,9 @@ struct Fixture
}
template <typename TestedRefType>
void compactWorst(bool compactMemory, bool compactAddressSpace) {
- ICompactionContext::UP ctx = store.compactWorst(compactMemory, compactAddressSpace);
+ CompactionSpec compaction_spec(compactMemory, compactAddressSpace);
+ CompactionStrategy compaction_strategy;
+ ICompactionContext::UP ctx = store.compactWorst(compaction_spec, compaction_strategy);
std::vector<TestedRefType> refs;
for (auto itr = refStore.begin(); itr != refStore.end(); ++itr) {
refs.emplace_back(itr->first);
diff --git a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp
index ccb18f13871..917c91f2dff 100644
--- a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp
+++ b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp
@@ -1,4 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/datastore/compaction_spec.h>
+#include <vespa/vespalib/datastore/compaction_strategy.h>
#include <vespa/vespalib/datastore/unique_store.hpp>
#include <vespa/vespalib/datastore/unique_store_remapper.h>
#include <vespa/vespalib/datastore/unique_store_string_allocator.hpp>
@@ -111,7 +113,9 @@ struct TestBase : public ::testing::Test {
store.trimHoldLists(generation);
}
void compactWorst() {
- auto remapper = store.compact_worst(true, true);
+ CompactionSpec compaction_spec(true, true);
+ CompactionStrategy compaction_strategy;
+ auto remapper = store.compact_worst(compaction_spec, compaction_strategy);
std::vector<EntryRef> refs;
for (const auto &elem : refStore) {
refs.push_back(elem.first);
diff --git a/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp b/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp
index 8d82c10d340..4a8b7eafe6a 100644
--- a/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp
+++ b/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp
@@ -1,5 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/datastore/compaction_strategy.h>
#include <vespa/vespalib/datastore/unique_store.hpp>
#include <vespa/vespalib/datastore/unique_store_dictionary.hpp>
#include <vespa/vespalib/datastore/sharded_hash_map.h>
@@ -137,8 +138,9 @@ TYPED_TEST(UniqueStoreDictionaryTest, compaction_works)
this->inc_generation();
auto btree_memory_usage_before = this->dict.get_btree_memory_usage();
auto hash_memory_usage_before = this->dict.get_hash_memory_usage();
+ CompactionStrategy compaction_strategy;
for (uint32_t i = 0; i < 15; ++i) {
- this->dict.compact_worst(true, true);
+ this->dict.compact_worst(true, true, compaction_strategy);
}
this->inc_generation();
auto btree_memory_usage_after = this->dict.get_btree_memory_usage();
diff --git a/vespalib/src/vespa/vespalib/btree/btree.h b/vespalib/src/vespa/vespalib/btree/btree.h
index 2b03e70fbdf..f87d5751743 100644
--- a/vespalib/src/vespa/vespalib/btree/btree.h
+++ b/vespalib/src/vespa/vespalib/btree/btree.h
@@ -6,6 +6,8 @@
#include "noaggrcalc.h"
#include <vespa/vespalib/util/generationhandler.h>
+namespace vespalib::datastore { class CompactionStrategy; }
+
namespace vespalib::btree {
/**
@@ -149,7 +151,7 @@ public:
_tree.thaw(itr);
}
- void compact_worst();
+ void compact_worst(const datastore::CompactionStrategy& compaction_strategy);
template <typename FunctionType>
void
diff --git a/vespalib/src/vespa/vespalib/btree/btree.hpp b/vespalib/src/vespa/vespalib/btree/btree.hpp
index c4a588bc63e..473d1f4735e 100644
--- a/vespalib/src/vespa/vespalib/btree/btree.hpp
+++ b/vespalib/src/vespa/vespalib/btree/btree.hpp
@@ -26,9 +26,9 @@ BTree<KeyT, DataT, AggrT, CompareT, TraitsT, AggrCalcT>::~BTree()
template <typename KeyT, typename DataT, typename AggrT, typename CompareT,
typename TraitsT, class AggrCalcT>
void
-BTree<KeyT, DataT, AggrT, CompareT, TraitsT, AggrCalcT>::compact_worst()
+BTree<KeyT, DataT, AggrT, CompareT, TraitsT, AggrCalcT>::compact_worst(const datastore::CompactionStrategy& compaction_strategy)
{
- auto to_hold = _alloc.start_compact_worst();
+ auto to_hold = _alloc.start_compact_worst(compaction_strategy);
_tree.move_nodes(_alloc);
_alloc.finishCompact(to_hold);
}
diff --git a/vespalib/src/vespa/vespalib/btree/btreenodeallocator.h b/vespalib/src/vespa/vespalib/btree/btreenodeallocator.h
index 93615ddef82..27e73b3a2b6 100644
--- a/vespalib/src/vespa/vespalib/btree/btreenodeallocator.h
+++ b/vespalib/src/vespa/vespalib/btree/btreenodeallocator.h
@@ -29,6 +29,7 @@ public:
using BTreeRootBaseType = BTreeRootBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>;
using generation_t = vespalib::GenerationHandler::generation_t;
using NodeStore = BTreeNodeStore<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>;
+ using CompactionStrategy = datastore::CompactionStrategy;
using EntryRef = datastore::EntryRef;
using DataStoreBase = datastore::DataStoreBase;
@@ -165,7 +166,7 @@ public:
bool getCompacting(EntryRef ref) const { return _nodeStore.getCompacting(ref); }
std::vector<uint32_t> startCompact() { return _nodeStore.startCompact(); }
- std::vector<uint32_t> start_compact_worst() { return _nodeStore.start_compact_worst(); }
+ std::vector<uint32_t> start_compact_worst(const CompactionStrategy& compaction_strategy) { return _nodeStore.start_compact_worst(compaction_strategy); }
void finishCompact(const std::vector<uint32_t> &toHold) {
return _nodeStore.finishCompact(toHold);
diff --git a/vespalib/src/vespa/vespalib/btree/btreenodestore.h b/vespalib/src/vespa/vespalib/btree/btreenodestore.h
index 70a9ba6c73c..444bf641899 100644
--- a/vespalib/src/vespa/vespalib/btree/btreenodestore.h
+++ b/vespalib/src/vespa/vespalib/btree/btreenodestore.h
@@ -56,6 +56,7 @@ public:
typedef typename LeafNodeType::RefPair LeafNodeTypeRefPair;
typedef vespalib::GenerationHandler::generation_t generation_t;
using EntryRef = datastore::EntryRef;
+ using CompactionStrategy = datastore::CompactionStrategy;
enum NodeTypes
{
@@ -159,7 +160,7 @@ public:
std::vector<uint32_t> startCompact();
- std::vector<uint32_t> start_compact_worst();
+ std::vector<uint32_t> start_compact_worst(const CompactionStrategy& compaction_strategy);
void finishCompact(const std::vector<uint32_t> &toHold);
diff --git a/vespalib/src/vespa/vespalib/btree/btreenodestore.hpp b/vespalib/src/vespa/vespalib/btree/btreenodestore.hpp
index ff4fa59cd74..91953507eb0 100644
--- a/vespalib/src/vespa/vespalib/btree/btreenodestore.hpp
+++ b/vespalib/src/vespa/vespalib/btree/btreenodestore.hpp
@@ -3,6 +3,7 @@
#pragma once
#include "btreenodestore.h"
+#include <vespa/vespalib/datastore/compaction_spec.h>
#include <vespa/vespalib/datastore/datastore.hpp>
namespace vespalib::btree {
@@ -71,9 +72,9 @@ template <typename KeyT, typename DataT, typename AggrT,
size_t INTERNAL_SLOTS, size_t LEAF_SLOTS>
std::vector<uint32_t>
BTreeNodeStore<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>::
-start_compact_worst()
+start_compact_worst(const CompactionStrategy &compaction_strategy)
{
- return _store.startCompactWorstBuffers(true, false);
+ return _store.startCompactWorstBuffers(datastore::CompactionSpec(true, false), compaction_strategy);
}
template <typename KeyT, typename DataT, typename AggrT,
diff --git a/vespalib/src/vespa/vespalib/btree/btreestore.h b/vespalib/src/vespa/vespalib/btree/btreestore.h
index b4238757e46..a79259c6e57 100644
--- a/vespalib/src/vespa/vespalib/btree/btreestore.h
+++ b/vespalib/src/vespa/vespalib/btree/btreestore.h
@@ -49,6 +49,8 @@ public:
TraitsT::INTERNAL_SLOTS,
TraitsT::LEAF_SLOTS,
AggrCalcT> Builder;
+ using CompactionSpec = datastore::CompactionSpec;
+ using CompactionStrategy = datastore::CompactionStrategy;
using EntryRef = datastore::EntryRef;
template <typename EntryType>
using BufferType = datastore::BufferType<EntryType>;
@@ -392,11 +394,11 @@ public:
void
foreach_frozen(EntryRef ref, FunctionType func) const;
- std::vector<uint32_t> start_compact_worst_btree_nodes();
+ std::vector<uint32_t> start_compact_worst_btree_nodes(const CompactionStrategy& compaction_strategy);
void finish_compact_worst_btree_nodes(const std::vector<uint32_t>& to_hold);
void move_btree_nodes(const std::vector<EntryRef>& refs);
- std::vector<uint32_t> start_compact_worst_buffers();
+ std::vector<uint32_t> start_compact_worst_buffers(CompactionSpec compaction_spec, const CompactionStrategy& compaction_strategy);
void move(std::vector<EntryRef>& refs);
private:
diff --git a/vespalib/src/vespa/vespalib/btree/btreestore.hpp b/vespalib/src/vespa/vespalib/btree/btreestore.hpp
index 795e526f927..c0985ff8f94 100644
--- a/vespalib/src/vespa/vespalib/btree/btreestore.hpp
+++ b/vespalib/src/vespa/vespalib/btree/btreestore.hpp
@@ -5,6 +5,7 @@
#include "btreestore.h"
#include "btreebuilder.h"
#include "btreebuilder.hpp"
+#include <vespa/vespalib/datastore/compaction_spec.h>
#include <vespa/vespalib/datastore/datastore.hpp>
#include <vespa/vespalib/util/optimized.h>
@@ -972,10 +973,10 @@ template <typename KeyT, typename DataT, typename AggrT, typename CompareT,
typename TraitsT, typename AggrCalcT>
std::vector<uint32_t>
BTreeStore<KeyT, DataT, AggrT, CompareT, TraitsT, AggrCalcT>::
-start_compact_worst_btree_nodes()
+start_compact_worst_btree_nodes(const CompactionStrategy& compaction_strategy)
{
_builder.clear();
- return _allocator.start_compact_worst();
+ return _allocator.start_compact_worst(compaction_strategy);
}
template <typename KeyT, typename DataT, typename AggrT, typename CompareT,
@@ -1007,10 +1008,10 @@ template <typename KeyT, typename DataT, typename AggrT, typename CompareT,
typename TraitsT, typename AggrCalcT>
std::vector<uint32_t>
BTreeStore<KeyT, DataT, AggrT, CompareT, TraitsT, AggrCalcT>::
-start_compact_worst_buffers()
+start_compact_worst_buffers(CompactionSpec compaction_spec, const CompactionStrategy& compaction_strategy)
{
freeze();
- return _store.startCompactWorstBuffers(true, false);
+ return _store.startCompactWorstBuffers(compaction_spec, compaction_strategy);
}
template <typename KeyT, typename DataT, typename AggrT, typename CompareT,
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.h b/vespalib/src/vespa/vespalib/datastore/array_store.h
index 3ba0caae5b9..d9b62c310b5 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.h
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.h
@@ -96,7 +96,7 @@ public:
}
void remove(EntryRef ref);
- ICompactionContext::UP compactWorst(bool compactMemory, bool compactAddressSpace);
+ ICompactionContext::UP compactWorst(CompactionSpec compaction_spec, const CompactionStrategy& compaction_strategy);
vespalib::MemoryUsage getMemoryUsage() const { return _store.getMemoryUsage(); }
/**
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.hpp b/vespalib/src/vespa/vespalib/datastore/array_store.hpp
index 9317fa557c0..bbbd52c354d 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.hpp
@@ -3,6 +3,7 @@
#pragma once
#include "array_store.h"
+#include "compaction_spec.h"
#include "entry_ref_filter.h"
#include "datastore.hpp"
#include <atomic>
@@ -169,9 +170,9 @@ public:
template <typename EntryT, typename RefT>
ICompactionContext::UP
-ArrayStore<EntryT, RefT>::compactWorst(bool compactMemory, bool compactAddressSpace)
+ArrayStore<EntryT, RefT>::compactWorst(CompactionSpec compaction_spec, const CompactionStrategy &compaction_strategy)
{
- std::vector<uint32_t> bufferIdsToCompact = _store.startCompactWorstBuffers(compactMemory, compactAddressSpace);
+ std::vector<uint32_t> bufferIdsToCompact = _store.startCompactWorstBuffers(compaction_spec, compaction_strategy);
return std::make_unique<arraystore::CompactionContext<EntryT, RefT>>
(_store, *this, std::move(bufferIdsToCompact));
}
diff --git a/vespalib/src/vespa/vespalib/datastore/compaction_spec.h b/vespalib/src/vespa/vespalib/datastore/compaction_spec.h
new file mode 100644
index 00000000000..49e2f5057cb
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/datastore/compaction_spec.h
@@ -0,0 +1,28 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+namespace vespalib::datastore {
+
+/*
+ * Class describing how to compact a compactable data structure.
+ *
+ * memory - to reduce amount of "dead" memory
+ * address_space - to avoid running out of free buffers in data store
+ * (i.e. move data from small buffers to larger buffers)
+ */
+class CompactionSpec
+{
+ bool _compact_memory;
+ bool _compact_address_space;
+public:
+ CompactionSpec(bool compact_memory, bool compact_address_space)
+ : _compact_memory(compact_memory),
+ _compact_address_space(compact_address_space)
+ {
+ }
+ bool get_compact_memory() const noexcept { return _compact_memory; }
+ bool get_compact_address_space() const noexcept { return _compact_address_space; }
+};
+
+}
diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
index b5cab50bc33..367eb328ab2 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
+++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "datastore.h"
+#include "compaction_spec.h"
#include <vespa/vespalib/util/array.hpp>
#include <vespa/vespalib/util/stringfmt.h>
#include <limits>
@@ -526,8 +527,9 @@ DataStoreBase::markCompacting(uint32_t bufferId)
}
std::vector<uint32_t>
-DataStoreBase::startCompactWorstBuffers(bool compactMemory, bool compactAddressSpace)
+DataStoreBase::startCompactWorstBuffers(CompactionSpec compaction_spec, const CompactionStrategy& compaction_strategy)
{
+ (void) compaction_strategy;
constexpr uint32_t noBufferId = std::numeric_limits<uint32_t>::max();
uint32_t worstMemoryBufferId = noBufferId;
uint32_t worstAddressSpaceBufferId = noBufferId;
@@ -540,11 +542,11 @@ DataStoreBase::startCompactWorstBuffers(bool compactMemory, bool compactAddressS
uint32_t arraySize = typeHandler->getArraySize();
uint32_t reservedElements = typeHandler->getReservedElements(bufferId);
size_t deadElems = state.getDeadElems() - reservedElements;
- if (compactMemory && deadElems > worstDeadElems) {
+ if (compaction_spec.get_compact_memory() && deadElems > worstDeadElems) {
worstMemoryBufferId = bufferId;
worstDeadElems = deadElems;
}
- if (compactAddressSpace) {
+ if (compaction_spec.get_compact_address_space()) {
size_t deadArrays = deadElems / arraySize;
if (deadArrays > worstDeadArrays) {
worstAddressSpaceBufferId = bufferId;
diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.h b/vespalib/src/vespa/vespalib/datastore/datastorebase.h
index 6903ae12c9c..e98d9531806 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastorebase.h
+++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.h
@@ -12,6 +12,9 @@
namespace vespalib::datastore {
+class CompactionSpec;
+class CompactionStrategy;
+
/**
* Abstract class used to store data of potential different types in underlying memory buffers.
*
@@ -368,7 +371,7 @@ public:
}
uint32_t startCompactWorstBuffer(uint32_t typeId);
- std::vector<uint32_t> startCompactWorstBuffers(bool compactMemory, bool compactAddressSpace);
+ std::vector<uint32_t> startCompactWorstBuffers(CompactionSpec compaction_spec, const CompactionStrategy &compaction_strategy);
uint64_t get_compaction_count() const { return _compaction_count.load(std::memory_order_relaxed); }
void inc_compaction_count() const { ++_compaction_count; }
bool has_held_buffers() const noexcept { return _hold_buffer_count != 0u; }
diff --git a/vespalib/src/vespa/vespalib/datastore/i_unique_store_dictionary.h b/vespalib/src/vespa/vespalib/datastore/i_unique_store_dictionary.h
index cf848167070..4fd3bcad5e5 100644
--- a/vespalib/src/vespa/vespalib/datastore/i_unique_store_dictionary.h
+++ b/vespalib/src/vespa/vespalib/datastore/i_unique_store_dictionary.h
@@ -10,6 +10,7 @@
namespace vespalib::datastore {
+class CompactionStrategy;
class EntryComparator;
class EntryRefFilter;
struct ICompactable;
@@ -41,7 +42,7 @@ public:
virtual vespalib::MemoryUsage get_btree_memory_usage() const = 0;
virtual vespalib::MemoryUsage get_hash_memory_usage() const = 0;
virtual bool has_held_buffers() const = 0;
- virtual void compact_worst(bool compact_btree_dictionary, bool compact_hash_dictionary) = 0;
+ virtual void compact_worst(bool compact_btree_dictionary, bool compact_hash_dictionary, const CompactionStrategy& compaction_strategy) = 0;
};
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store.h b/vespalib/src/vespa/vespalib/datastore/unique_store.h
index 38643d84be0..b50f753ed03 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store.h
@@ -55,7 +55,7 @@ public:
EntryRef find(EntryConstRefType value);
EntryConstRefType get(EntryRef ref) const { return _allocator.get(ref); }
void remove(EntryRef ref);
- std::unique_ptr<Remapper> compact_worst(bool compact_memory, bool compact_address_space);
+ std::unique_ptr<Remapper> compact_worst(CompactionSpec compaction_spec, const CompactionStrategy& compaction_strategy);
vespalib::MemoryUsage getMemoryUsage() const;
vespalib::MemoryUsage get_values_memory_usage() const { return _store.getMemoryUsage(); }
vespalib::MemoryUsage get_dictionary_memory_usage() const { return _dict->get_memory_usage(); }
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp
index b02a2e52185..2c06788ded8 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp
@@ -157,9 +157,9 @@ public:
template <typename EntryT, typename RefT, typename Compare, typename Allocator>
std::unique_ptr<typename UniqueStore<EntryT, RefT, Compare, Allocator>::Remapper>
-UniqueStore<EntryT, RefT, Compare, Allocator>::compact_worst(bool compact_memory, bool compact_address_space)
+UniqueStore<EntryT, RefT, Compare, Allocator>::compact_worst(CompactionSpec compaction_spec, const CompactionStrategy& compaction_strategy)
{
- std::vector<uint32_t> bufferIdsToCompact = _store.startCompactWorstBuffers(compact_memory, compact_address_space);
+ std::vector<uint32_t> bufferIdsToCompact = _store.startCompactWorstBuffers(compaction_spec, compaction_strategy);
if (bufferIdsToCompact.empty()) {
return std::unique_ptr<Remapper>();
} else {
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h
index 54d541853c7..d64588e3242 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h
@@ -91,7 +91,7 @@ public:
vespalib::MemoryUsage get_btree_memory_usage() const override;
vespalib::MemoryUsage get_hash_memory_usage() const override;
bool has_held_buffers() const override;
- void compact_worst(bool compact_btree_dictionary, bool compact_hash_dictionary) override;
+ void compact_worst(bool compact_btree_dictionary, bool compact_hash_dictionary, const CompactionStrategy& compaction_strategy) override;
};
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp
index 13ae0a317e0..4375b38cf7c 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp
@@ -339,11 +339,11 @@ UniqueStoreDictionary<BTreeDictionaryT, ParentT, HashDictionaryT>::has_held_buff
template <typename BTreeDictionaryT, typename ParentT, typename HashDictionaryT>
void
-UniqueStoreDictionary<BTreeDictionaryT, ParentT, HashDictionaryT>::compact_worst(bool compact_btree_dictionary, bool compact_hash_dictionary)
+UniqueStoreDictionary<BTreeDictionaryT, ParentT, HashDictionaryT>::compact_worst(bool compact_btree_dictionary, bool compact_hash_dictionary, const CompactionStrategy& compaction_strategy)
{
if constexpr (has_btree_dictionary) {
if (compact_btree_dictionary) {
- this->_btree_dict.compact_worst();
+ this->_btree_dict.compact_worst(compaction_strategy);
}
} else {
(void) compact_btree_dictionary;