blob: 3fe37b39f3f897da4d7cb0c4497d7b925f9f9353 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// 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/util/time.h>
#include <mutex>
#include <condition_variable>
class FNET_Transport;
namespace search::transactionlog::client {
class TransLogClient;
class Session;
class Visitor;
class Callback;
}
namespace proton {
/**
* Base class managing the initialization and replay of a transaction log.
**/
class TransactionLogManagerBase {
protected:
using TransLogClient = search::transactionlog::client::TransLogClient;
using Session = search::transactionlog::client::Session;
using Visitor = search::transactionlog::client::Visitor;
using Callback = search::transactionlog::client::Callback;
private:
std::unique_ptr<TransLogClient> _tlc;
std::unique_ptr<Session> _tlcSession;
vespalib::string _domainName;
mutable std::mutex _replayLock;
mutable std::condition_variable _replayCond;
volatile bool _replayDone;
bool _replayStarted;
vespalib::Timer _replayStopWatch;
protected:
using SerialNum = search::SerialNum;
struct StatusResult {
SerialNum serialBegin;
SerialNum serialEnd;
size_t count;
StatusResult() : serialBegin(0), serialEnd(0), count(0) {}
};
StatusResult init();
void internalStartReplay();
virtual void doLogReplayComplete(const vespalib::string &domainName, vespalib::duration elapsedTime) const = 0;
public:
TransactionLogManagerBase(const TransactionLogManagerBase &) = delete;
TransactionLogManagerBase & operator = (const TransactionLogManagerBase &) = delete;
/**
* Create a new manager.
*
* @param tlsSpec the spec of the transaction log server.
* @param domainName the name of the domain this manager should handle.
**/
TransactionLogManagerBase(FNET_Transport & transport,
const vespalib::string &tlsSpec,
const vespalib::string &domainName);
virtual ~TransactionLogManagerBase();
void changeReplayDone();
void close();
std::unique_ptr<Visitor> createTlcVisitor(Callback &callback);
void waitForReplayDone() const;
TransLogClient &getClient() { return *_tlc; }
Session *getSession() { return _tlcSession.get(); }
const vespalib::string &getDomainName() const { return _domainName; }
bool getReplayDone() const;
bool isDoingReplay() const;
void logReplayComplete() const;
const vespalib::string &getRpcTarget() const;
};
} // namespace proton
|