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

#pragma once

#include <vespa/searchlib/common/serialnum.h>
#include <vespa/vespalib/stllike/string.h>
#include <atomic>
#include <memory>

namespace proton {

class TlsReplayProgress
{
private:
    const vespalib::string  _domainName;
    const search::SerialNum _first;
    const search::SerialNum _last;
    std::atomic<search::SerialNum> _current;

public:
    using UP = std::unique_ptr<TlsReplayProgress>;

    TlsReplayProgress(const vespalib::string &domainName,
                      search::SerialNum first,
                      search::SerialNum last)
        : _domainName(domainName),
          _first(first),
          _last(last),
          _current(first)
    {
    }
    const vespalib::string &getDomainName() const noexcept { return _domainName; }
    search::SerialNum getFirst() const noexcept { return _first; }
    search::SerialNum getLast() const noexcept { return _last; }
    search::SerialNum getCurrent() const noexcept { return _current.load(std::memory_order_relaxed); }
    float getProgress() const noexcept {
        if (_first == _last) {
            return 1.0;
        } else {
            return ((float)(getCurrent() - _first)/float(_last - _first));
        }
    }
    void updateCurrent(search::SerialNum current) noexcept { _current.store(current, std::memory_order_relaxed); }
};

} // namespace proton