aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/prepare_restart_handler.h
blob: dc81374c958f207facb7ad455b09a2480f5608a7 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/config-proton.h>
#include <condition_variable>
#include <memory>
#include <mutex>

namespace proton {

class FlushEngine;

/**
 * Class ensuring that only a single prepare restart happens at the same time.
 *
 * If another thread tries to start a new prepare restart while one is running, this thread waits
 * until the ongoing operation is done and returns successfully. No extra work is done.
 */
class PrepareRestartHandler {
public:
    using ProtonConfig = vespa::config::search::core::internal::InternalProtonType;

private:
    FlushEngine &_flushEngine;
    std::mutex _mutex;
    std::condition_variable _cond;
    bool _running;

    void performPrepareRestart(const ProtonConfig &protonCfg, std::unique_lock<std::mutex> &lock);

public:
    PrepareRestartHandler(FlushEngine &flushEngine);
    bool prepareRestart(const ProtonConfig &protonCfg);
};

}