aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/datastore/compaction_context.cpp
blob: 7f70d5de3af82b578a61b48dfdeb555732358cf5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright Vespa.ai. 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_on_compact(ref);
            atomic_entry_ref.store_release(newRef);
        }
    }
}

}