aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-01-12 14:23:16 +0100
committerTor Egge <Tor.Egge@online.no>2023-01-12 14:23:16 +0100
commit0ef72239262b0353a6625d638097bf1c57bf051f (patch)
tree433a31639984773ff484ca2184769dccc4bb636d /vespalib
parentca9c0bb23d927af20f4c40cc71679c22c7cb08e5 (diff)
Add compaction spec to array store.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/datastore/array_store/array_store_test.cpp7
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.h11
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.hpp23
3 files changed, 30 insertions, 11 deletions
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 aa35fb24823..69df94f7181 100644
--- a/vespalib/src/tests/datastore/array_store/array_store_test.cpp
+++ b/vespalib/src/tests/datastore/array_store/array_store_test.cpp
@@ -143,7 +143,8 @@ struct ArrayStoreTest : public TestT
void compactWorst(bool compactMemory, bool compactAddressSpace) {
CompactionSpec compaction_spec(compactMemory, compactAddressSpace);
CompactionStrategy compaction_strategy;
- ICompactionContext::UP ctx = store.compactWorst(compaction_spec, compaction_strategy);
+ store.set_compaction_spec(compaction_spec);
+ ICompactionContext::UP ctx = store.compact_worst(compaction_strategy);
std::vector<AtomicEntryRef> refs;
for (auto itr = refStore.begin(); itr != refStore.end(); ++itr) {
refs.emplace_back(itr->first);
@@ -205,10 +206,10 @@ INSTANTIATE_TEST_SUITE_P(NumberStoreFreeListsDisabledMultiTest,
TEST_P(NumberStoreTest, control_static_sizes) {
#ifdef _LIBCPP_VERSION
- EXPECT_EQ(472u, sizeof(store));
+ EXPECT_EQ(480u, sizeof(store));
EXPECT_EQ(304u, sizeof(NumberStoreTest::ArrayStoreType::DataStoreType));
#else
- EXPECT_EQ(504u, sizeof(store));
+ EXPECT_EQ(512u, sizeof(store));
EXPECT_EQ(336u, sizeof(NumberStoreTest::ArrayStoreType::DataStoreType));
#endif
EXPECT_EQ(112u, sizeof(NumberStoreTest::ArrayStoreType::SmallBufferType));
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.h b/vespalib/src/vespa/vespalib/datastore/array_store.h
index 4c7f15d78e4..c76b71ae34e 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.h
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.h
@@ -6,6 +6,7 @@
#include "array_store_config.h"
#include "buffer_type.h"
#include "bufferstate.h"
+#include "compaction_spec.h"
#include "datastore.h"
#include "entryref.h"
#include "atomic_entry_ref.h"
@@ -48,6 +49,7 @@ private:
TypeMapper _mapper;
std::vector<SmallBufferType> _smallArrayTypes;
LargeBufferType _largeArrayType;
+ CompactionSpec _compaction_spec;
using generation_t = vespalib::GenerationHandler::generation_t;
void initArrayTypes(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator);
@@ -106,11 +108,16 @@ public:
void remove(EntryRef ref);
EntryRef move_on_compact(EntryRef ref) override;
- ICompactionContext::UP compactWorst(CompactionSpec compaction_spec, const CompactionStrategy& compaction_strategy);
+ ICompactionContext::UP compact_worst(const CompactionStrategy& compaction_strategy);
// Use this if references to array store is not an array of AtomicEntryRef
- std::unique_ptr<CompactingBuffers> start_compact_worst_buffers(CompactionSpec compaction_spec, const CompactionStrategy &compaction_strategy);
+ std::unique_ptr<CompactingBuffers> start_compact_worst_buffers(const CompactionStrategy &compaction_strategy);
vespalib::MemoryUsage getMemoryUsage() const { return _store.getMemoryUsage(); }
+ vespalib::MemoryUsage update_stat(const CompactionStrategy& compaction_strategy);
+ bool consider_compact() const noexcept { return _compaction_spec.compact() && !_store.has_held_buffers(); }
+
+ // Set compaction spec. Only used by unit tests.
+ void set_compaction_spec(CompactionSpec compaction_spec) noexcept { _compaction_spec = compaction_spec; }
/**
* Returns the address space usage by this store as the ratio between active buffers
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.hpp b/vespalib/src/vespa/vespalib/datastore/array_store.hpp
index cf158686f01..4276318f993 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.hpp
@@ -5,7 +5,7 @@
#include "array_store.h"
#include "compacting_buffers.h"
#include "compaction_context.h"
-#include "compaction_spec.h"
+#include "compaction_strategy.h"
#include "datastore.hpp"
#include "entry_ref_filter.h"
#include "large_array_buffer_type.hpp"
@@ -46,7 +46,8 @@ ArrayStore<EntryT, RefT, TypeMapperT>::ArrayStore(const ArrayStoreConfig &cfg, s
_store(),
_mapper(std::move(mapper)),
_smallArrayTypes(),
- _largeArrayType(cfg.spec_for_type_id(0), memory_allocator, _mapper)
+ _largeArrayType(cfg.spec_for_type_id(0), memory_allocator, _mapper),
+ _compaction_spec()
{
initArrayTypes(cfg, std::move(memory_allocator));
_store.init_primary_buffers();
@@ -155,17 +156,17 @@ ArrayStore<EntryT, RefT, TypeMapperT>::move_on_compact(EntryRef ref)
template <typename EntryT, typename RefT, typename TypeMapperT>
ICompactionContext::UP
-ArrayStore<EntryT, RefT, TypeMapperT>::compactWorst(CompactionSpec compaction_spec, const CompactionStrategy &compaction_strategy)
+ArrayStore<EntryT, RefT, TypeMapperT>::compact_worst(const CompactionStrategy &compaction_strategy)
{
- auto compacting_buffers = _store.start_compact_worst_buffers(compaction_spec, compaction_strategy);
+ auto compacting_buffers = _store.start_compact_worst_buffers(_compaction_spec, compaction_strategy);
return std::make_unique<CompactionContext>(*this, std::move(compacting_buffers));
}
template <typename EntryT, typename RefT, typename TypeMapperT>
std::unique_ptr<CompactingBuffers>
-ArrayStore<EntryT, RefT, TypeMapperT>::start_compact_worst_buffers(CompactionSpec compaction_spec, const CompactionStrategy &compaction_strategy)
+ArrayStore<EntryT, RefT, TypeMapperT>::start_compact_worst_buffers(const CompactionStrategy &compaction_strategy)
{
- return _store.start_compact_worst_buffers(compaction_spec, compaction_strategy);
+ return _store.start_compact_worst_buffers(_compaction_spec, compaction_strategy);
}
template <typename EntryT, typename RefT, typename TypeMapperT>
@@ -176,6 +177,16 @@ ArrayStore<EntryT, RefT, TypeMapperT>::addressSpaceUsage() const
}
template <typename EntryT, typename RefT, typename TypeMapperT>
+vespalib::MemoryUsage
+ArrayStore<EntryT, RefT, TypeMapperT>::update_stat(const CompactionStrategy& compaction_strategy)
+{
+ auto address_space_usage = _store.getAddressSpaceUsage();
+ auto memory_usage = _store.getMemoryUsage();
+ _compaction_spec = compaction_strategy.should_compact(memory_usage, address_space_usage);
+ return memory_usage;
+}
+
+template <typename EntryT, typename RefT, typename TypeMapperT>
const BufferState &
ArrayStore<EntryT, RefT, TypeMapperT>::bufferState(EntryRef ref) const
{