diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-10-06 00:48:45 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-10-06 00:48:45 +0200 |
commit | e3e76af788dd5a0c8cbad64cebbe60656ac4075b (patch) | |
tree | 9c25b7eb1f09a9a3423838e1f5270caa8e42553f /vespalib | |
parent | b61e190f896f217f54a71e14b33b0589b8d87a32 (diff) |
Use vespalib::datastore::CompactionContext when compacting tensor attributes.
Diffstat (limited to 'vespalib')
4 files changed, 66 insertions, 1 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt b/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt index a2b561b6792..9990e3f5764 100644 --- a/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt +++ b/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt @@ -9,6 +9,7 @@ vespa_add_library(vespalib_vespalib_datastore OBJECT bufferstate.cpp compact_buffer_candidates.cpp compacting_buffers.cpp + compaction_context.cpp compaction_strategy.cpp compaction_strategy.cpp datastore.cpp diff --git a/vespalib/src/vespa/vespalib/datastore/compaction_context.cpp b/vespalib/src/vespa/vespalib/datastore/compaction_context.cpp new file mode 100644 index 00000000000..65e028119a2 --- /dev/null +++ b/vespalib/src/vespa/vespalib/datastore/compaction_context.cpp @@ -0,0 +1,34 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "compaction_context.h" +#include "compacting_buffers.h" +#include "i_compactable.h" + +namespace vespalib::datastore { + +CompactionContext::CompactionContext(ICompactable& store, + std::unique_ptr<CompactingBuffers> compacting_buffers) + : _store(store), + _compacting_buffers(std::move(compacting_buffers)), + _filter(_compacting_buffers->make_entry_ref_filter()) +{ +} + +CompactionContext::~CompactionContext() +{ + _compacting_buffers->finish(); +} + +void +CompactionContext::compact(vespalib::ArrayRef<AtomicEntryRef> refs) +{ + for (auto &atomic_entry_ref : refs) { + auto ref = atomic_entry_ref.load_relaxed(); + if (ref.valid() && _filter.has(ref)) { + EntryRef newRef = _store.move(ref); + atomic_entry_ref.store_release(newRef); + } + } +} + +} diff --git a/vespalib/src/vespa/vespalib/datastore/compaction_context.h b/vespalib/src/vespa/vespalib/datastore/compaction_context.h new file mode 100644 index 00000000000..2fb0ed0bcb6 --- /dev/null +++ b/vespalib/src/vespa/vespalib/datastore/compaction_context.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 + +#include "i_compaction_context.h" +#include "entry_ref_filter.h" + +namespace vespalib::datastore { + +class CompactingBuffers; +struct ICompactable; + +/** + * A compaction context is used when performing a compaction of data buffers in a data store. + */ +class CompactionContext : public ICompactionContext { +private: + ICompactable& _store; + std::unique_ptr<vespalib::datastore::CompactingBuffers> _compacting_buffers; + EntryRefFilter _filter; + +public: + CompactionContext(ICompactable& store, std::unique_ptr<CompactingBuffers> compacting_buffers); + ~CompactionContext() override; + void compact(vespalib::ArrayRef<AtomicEntryRef> refs) override; +}; + +} diff --git a/vespalib/src/vespa/vespalib/datastore/i_compaction_context.h b/vespalib/src/vespa/vespalib/datastore/i_compaction_context.h index 684ad826f20..c72cd806798 100644 --- a/vespalib/src/vespa/vespalib/datastore/i_compaction_context.h +++ b/vespalib/src/vespa/vespalib/datastore/i_compaction_context.h @@ -2,7 +2,9 @@ #pragma once -#include <vespa/vespalib/util/array.h> +#include "atomic_entry_ref.h" +#include <vespa/vespalib/util/arrayref.h> +#include <memory> namespace vespalib::datastore { |