-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
pika_cluster.h
146 lines (126 loc) · 4.96 KB
/
pika_cluster.h
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (c) 2015-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_CLUSTER_H_
#define PIKA_CLUSTER_H_
#include "include/pika_command.h"
Status ParseSlotGroup(const std::string& slot_group, std::set<uint32_t>* slots);
class PkClusterInfoCmd : public Cmd {
public:
enum InfoSection { kInfoErr = 0x0, kInfoSlot, kInfoTable };
enum InfoRange { kSingle = 0x0, kAll, kRange };
PkClusterInfoCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag), info_section_(kInfoErr), info_range_(kAll) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new PkClusterInfoCmd(*this); }
private:
InfoSection info_section_;
InfoRange info_range_;
std::string table_name_;
std::set<uint32_t> slots_;
virtual void DoInitial() override;
virtual void Clear() {
info_section_ = kInfoErr;
info_range_ = kAll;
table_name_.clear();
slots_.clear();
}
const static std::string kSlotSection;
const static std::string kTableSection;
void ClusterInfoTableAll(std::string* info);
void ClusterInfoTable(std::string* info);
void ClusterInfoSlotRange(const std::string& table_name, const std::set<uint32_t> slots, std::string* info);
void ClusterInfoSlotAll(std::string* info);
Status GetSlotInfo(const std::string table_name, uint32_t partition_id, std::string* info);
bool ParseInfoSlotSubCmd();
bool ParseInfoTableSubCmd();
};
class SlotParentCmd : public Cmd {
public:
SlotParentCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
protected:
std::set<uint32_t> slots_;
std::set<PartitionInfo> p_infos_;
virtual void DoInitial();
virtual void Clear() {
slots_.clear();
p_infos_.clear();
table_name_.clear();
}
};
class PkClusterAddSlotsCmd : public SlotParentCmd {
public:
PkClusterAddSlotsCmd(const std::string& name, int arity, uint16_t flag) : SlotParentCmd(name, arity, flag) {}
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new PkClusterAddSlotsCmd(*this); }
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
virtual void DoInitial() override;
Status AddSlotsSanityCheck();
};
class PkClusterDelSlotsCmd : public SlotParentCmd {
public:
PkClusterDelSlotsCmd(const std::string& name, int32_t arity, uint16_t flag) : SlotParentCmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new PkClusterDelSlotsCmd(*this); }
private:
virtual void DoInitial() override;
Status RemoveSlotsSanityCheck();
};
class PkClusterSlotsSlaveofCmd : public Cmd {
public:
PkClusterSlotsSlaveofCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new PkClusterSlotsSlaveofCmd(*this); }
private:
std::string ip_;
int64_t port_ = -1;
std::set<uint32_t> slots_;
bool force_sync_;
bool is_none_;
virtual void DoInitial() override;
virtual void Clear() {
ip_.clear();
port_ = 0;
slots_.clear();
force_sync_ = false;
is_none_ = false;
table_name_.clear();
}
};
class PkClusterAddTableCmd : public Cmd {
public:
PkClusterAddTableCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), slot_num_(0) {}
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
Cmd* Clone() override { return new PkClusterAddTableCmd(*this); }
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
int64_t slot_num_ = 0;
void DoInitial() override;
Status AddTableSanityCheck();
void Clear() override {
slot_num_ = 0;
table_name_.clear();
}
};
class PkClusterDelTableCmd : public PkClusterDelSlotsCmd {
public:
PkClusterDelTableCmd(const std::string& name, int arity, uint16_t flag) : PkClusterDelSlotsCmd(name, arity, flag) {}
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
Cmd* Clone() override { return new PkClusterDelTableCmd(*this); }
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
void DoInitial() override;
Status DelTableSanityCheck(const std::string& table_name);
};
#endif // PIKA_CLUSTER_H_