summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2022-10-13 17:17:12 +0200
committerGitHub <noreply@github.com>2022-10-13 17:17:12 +0200
commit92014fad54908e405ceaa254631b5af2d07806cf (patch)
tree84e4beabd59ca6a1440607b5ba28468e92a83e48
parent8694e13bdce0338ab6b8e895d22afd235980f05b (diff)
parent47407693b5ee2bdcf2ba93fb7384799a21b31b42 (diff)
Merge pull request #24435 from vespa-engine/geirst/array-store-compaction-context
Use the generic CompactionContext in ArrayStore.
-rw-r--r--vespalib/src/tests/datastore/array_store/array_store_test.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.h6
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.hpp43
3 files changed, 13 insertions, 38 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 afef530b33e..3179b60a4a1 100644
--- a/vespalib/src/tests/datastore/array_store/array_store_test.cpp
+++ b/vespalib/src/tests/datastore/array_store/array_store_test.cpp
@@ -208,7 +208,7 @@ TEST_P(NumberStoreTest, control_static_sizes) {
EXPECT_EQ(464u, sizeof(store));
EXPECT_EQ(304u, sizeof(NumberStoreTest::ArrayStoreType::DataStoreType));
#else
- EXPECT_EQ(496u, sizeof(store));
+ EXPECT_EQ(504u, 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 e7662b9eb73..95d632d9603 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.h
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.h
@@ -10,6 +10,7 @@
#include "entryref.h"
#include "atomic_entry_ref.h"
#include "i_compaction_context.h"
+#include "i_compactable.h"
#include "large_array_buffer_type.h"
#include "small_array_buffer_type.h"
#include <vespa/vespalib/util/array.h>
@@ -28,7 +29,7 @@ namespace vespalib::datastore {
* The max value of maxSmallArrayTypeId is (2^bufferBits - 1).
*/
template <typename EntryT, typename RefT = EntryRefT<19>, typename TypeMapperT = ArrayStoreTypeMapper<EntryT> >
-class ArrayStore
+class ArrayStore : public ICompactable
{
public:
using AllocSpec = ArrayStoreConfig::AllocSpec;
@@ -66,7 +67,7 @@ private:
public:
ArrayStore(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator);
ArrayStore(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator, TypeMapper&& mapper);
- ~ArrayStore();
+ ~ArrayStore() override;
EntryRef add(const ConstArrayRef &array);
ConstArrayRef get(EntryRef ref) const {
if (!ref.valid()) {
@@ -104,6 +105,7 @@ public:
}
void remove(EntryRef ref);
+ EntryRef move_on_compact(EntryRef ref) override;
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 b31d47fe4fe..95f4a3c4155 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.hpp
@@ -4,13 +4,14 @@
#include "array_store.h"
#include "compacting_buffers.h"
+#include "compaction_context.h"
#include "compaction_spec.h"
-#include "entry_ref_filter.h"
#include "datastore.hpp"
+#include "entry_ref_filter.h"
#include "large_array_buffer_type.hpp"
#include "small_array_buffer_type.hpp"
-#include <atomic>
#include <algorithm>
+#include <atomic>
namespace vespalib::datastore {
@@ -145,38 +146,11 @@ ArrayStore<EntryT, RefT, TypeMapperT>::remove(EntryRef ref)
}
}
-namespace arraystore {
-
template <typename EntryT, typename RefT, typename TypeMapperT>
-class CompactionContext : public ICompactionContext {
-private:
- using ArrayStoreType = ArrayStore<EntryT, RefT, TypeMapperT>;
- ArrayStoreType &_store;
- std::unique_ptr<vespalib::datastore::CompactingBuffers> _compacting_buffers;
- EntryRefFilter _filter;
-
-public:
- CompactionContext(ArrayStoreType &store,
- std::unique_ptr<vespalib::datastore::CompactingBuffers> compacting_buffers)
- : _store(store),
- _compacting_buffers(std::move(compacting_buffers)),
- _filter(_compacting_buffers->make_entry_ref_filter())
- {
- }
- ~CompactionContext() override {
- _compacting_buffers->finish();
- }
- void compact(vespalib::ArrayRef<AtomicEntryRef> refs) override {
- for (auto &atomic_entry_ref : refs) {
- auto ref = atomic_entry_ref.load_relaxed();
- if (ref.valid() && _filter.has(ref)) {
- EntryRef newRef = _store.add(_store.get(ref));
- atomic_entry_ref.store_release(newRef);
- }
- }
- }
-};
-
+EntryRef
+ArrayStore<EntryT, RefT, TypeMapperT>::move_on_compact(EntryRef ref)
+{
+ return add(get(ref));
}
template <typename EntryT, typename RefT, typename TypeMapperT>
@@ -184,8 +158,7 @@ ICompactionContext::UP
ArrayStore<EntryT, RefT, TypeMapperT>::compactWorst(CompactionSpec compaction_spec, const CompactionStrategy &compaction_strategy)
{
auto compacting_buffers = _store.start_compact_worst_buffers(compaction_spec, compaction_strategy);
- return std::make_unique<arraystore::CompactionContext<EntryT, RefT, TypeMapperT>>
- (*this, std::move(compacting_buffers));
+ return std::make_unique<CompactionContext>(*this, std::move(compacting_buffers));
}
template <typename EntryT, typename RefT, typename TypeMapperT>