aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/common/threaded_compactable_lid_space.cpp
blob: 305b4f1d36bde72a08fce90e2e6c122b1f4ab89d (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "threaded_compactable_lid_space.h"
#include <future>

namespace search::common {

ThreadedCompactableLidSpace::ThreadedCompactableLidSpace(std::shared_ptr<ICompactableLidSpace> target,
                                                         ISequencedTaskExecutor &executor,
                                                         ISequencedTaskExecutor::ExecutorId id)
    : _target(std::move(target)),
      _executor(executor),
      _executorId(id)
{
}

ThreadedCompactableLidSpace::~ThreadedCompactableLidSpace() = default;

void
ThreadedCompactableLidSpace::compactLidSpace(uint32_t wantedDocLidLimit)
{
    std::promise<void> promise;
    auto future = promise.get_future();
    _executor.executeLambda(_executorId, [this, wantedDocLidLimit, &promise]() { _target->compactLidSpace(wantedDocLidLimit); promise.set_value(); });
    future.wait();
}

bool
ThreadedCompactableLidSpace::canShrinkLidSpace() const
{
    return _target->canShrinkLidSpace();
}

size_t
ThreadedCompactableLidSpace::getEstimatedShrinkLidSpaceGain() const
{
    return _target->getEstimatedShrinkLidSpaceGain();
}

void
ThreadedCompactableLidSpace::shrinkLidSpace()
{
    std::promise<void> promise;
    auto future = promise.get_future();
    _executor.executeLambda(_executorId, [this, &promise]() { _target->shrinkLidSpace(); promise.set_value(); });
    future.wait();
}

}