aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageapi/message/state.h
blob: 900355b12a2bfbe8e58bd1497e29f90aff4c1c83 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/storageapi/messageapi/storagecommand.h>
#include <vespa/storageapi/messageapi/storagereply.h>
#include <vespa/vdslib/state/nodestate.h>
#include <vespa/vdslib/state/cluster_state_bundle.h>

namespace storage::api {

/**
 * @class GetNodeStateCommand
 * @ingroup message
 *
 * @brief Command for setting node state. No payload
 */
class GetNodeStateCommand : public StorageCommand {
    lib::NodeState::UP _expectedState;

public:
    explicit GetNodeStateCommand(lib::NodeState::UP expectedState);

    const lib::NodeState* getExpectedState() const { return _expectedState.get(); }
    void print(std::ostream& out, bool verbose, const std::string& indent) const override;

    DECLARE_STORAGECOMMAND(GetNodeStateCommand, onGetNodeState)
};

/**
 * @class GetNodeStateReply
 * @ingroup message
 *
 * @brief Reply to GetNodeStateCommand
 */
class GetNodeStateReply : public StorageReply {
    lib::NodeState::UP _state;
    std::string _nodeInfo;

public:
    GetNodeStateReply(const GetNodeStateCommand&); // Only used on makeReply()
    GetNodeStateReply(const GetNodeStateCommand&, const lib::NodeState&);

    bool hasNodeState() const { return (_state.get() != 0); }
    const lib::NodeState& getNodeState() const { return *_state; }

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;

    void setNodeInfo(const std::string& info) { _nodeInfo = info; }
    const std::string& getNodeInfo() const { return _nodeInfo; }

    DECLARE_STORAGEREPLY(GetNodeStateReply, onGetNodeStateReply)
};

/**
 * @class SetSystemStateCommand
 * @ingroup message
 *
 * @brief Command for telling a node about the system state - state of each node
 *  in the system and state of the system (all ok, no merging, block
 *  put/get/remove etx)
 */
class SetSystemStateCommand : public StorageCommand {
    lib::ClusterStateBundle _state;

public:
    explicit SetSystemStateCommand(const lib::ClusterStateBundle &state);
    explicit SetSystemStateCommand(const lib::ClusterState &state);
    const lib::ClusterState& getSystemState() const { return *_state.getBaselineClusterState(); }
    const lib::ClusterStateBundle& getClusterStateBundle() const { return _state; }
    void print(std::ostream& out, bool verbose, const std::string& indent) const override;

    DECLARE_STORAGECOMMAND(SetSystemStateCommand, onSetSystemState)
};

/**
 * @class SetSystemStateReply
 * @ingroup message
 *
 * @brief Reply received after a SetSystemStateCommand.
 */
class SetSystemStateReply : public StorageReply {
    lib::ClusterStateBundle _state;

public:
    explicit SetSystemStateReply(const SetSystemStateCommand& cmd);

    // Not serialized. Available locally
    const lib::ClusterState& getSystemState() const { return *_state.getBaselineClusterState(); }
    const lib::ClusterStateBundle& getClusterStateBundle() const { return _state; }
    void print(std::ostream& out, bool verbose, const std::string& indent) const override;

    DECLARE_STORAGEREPLY(SetSystemStateReply, onSetSystemStateReply)
};

class ActivateClusterStateVersionCommand : public StorageCommand {
    uint32_t _version;
public:
    explicit ActivateClusterStateVersionCommand(uint32_t version);
    uint32_t version() const noexcept { return _version; }
    void print(std::ostream& out, bool verbose, const std::string& indent) const override;

    DECLARE_STORAGECOMMAND(ActivateClusterStateVersionCommand, onActivateClusterStateVersion);
};

class ActivateClusterStateVersionReply : public StorageReply {
    uint32_t _activateVersion;
    uint32_t _actualVersion;
public:
    explicit ActivateClusterStateVersionReply(const ActivateClusterStateVersionCommand&);
    uint32_t activateVersion() const noexcept { return _activateVersion; }
    void setActualVersion(uint32_t version) noexcept { _actualVersion = version; }
    uint32_t actualVersion() const noexcept { return _actualVersion; }
    void print(std::ostream& out, bool verbose, const std::string& indent) const override;

    DECLARE_STORAGEREPLY(ActivateClusterStateVersionReply, onActivateClusterStateVersionReply);
};

}