aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Coordination/Keeper4LWInfo.h
blob: 105478457cc12a9e9a8deeec6c4bf1155b601cc8 (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
#pragma once

#include <string>

#include <base/types.h>
#include <Common/Exception.h>

namespace DB
{

namespace ErrorCodes
{
    extern const int LOGICAL_ERROR;
}

/// Keeper server related information for different 4lw commands
struct Keeper4LWInfo
{
    bool is_leader;
    bool is_observer;
    bool is_follower;
    bool is_standalone;

    bool has_leader;

    uint64_t alive_connections_count;
    uint64_t outstanding_requests_count;

    uint64_t follower_count;
    uint64_t synced_follower_count;

    uint64_t total_nodes_count;
    int64_t last_zxid;

    String getRole() const
    {
        if (is_standalone)
            return "standalone";
        if (is_leader)
            return "leader";
        if (is_observer)
            return "observer";
        if (is_follower)
            return "follower";

        throw Exception(ErrorCodes::LOGICAL_ERROR, "RAFT server has undefined state, it's a bug");
    }
};

/// Keeper log information for 4lw commands
struct KeeperLogInfo
{
    /// My first log index in log store.
    uint64_t first_log_idx;

    /// My first log term.
    uint64_t first_log_term;

    /// My last log index in log store.
    uint64_t last_log_idx;

    /// My last log term.
    uint64_t last_log_term;

    /// My last committed log index in state machine.
    uint64_t last_committed_log_idx;

    /// Leader's committed log index from my perspective.
    uint64_t leader_committed_log_idx;

    /// Target log index should be committed to.
    uint64_t target_committed_log_idx;

    /// The largest committed log index in last snapshot.
    uint64_t last_snapshot_idx;
};

}