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
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2023 IBM, Inc.
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*/
#ifndef MON_NVMEGWMONITOR_H_
#define MON_NVMEGWMONITOR_H_
#include "PaxosService.h"
#include "NVMeofGwMap.h"
struct LastBeacon {
NvmeGwId gw_id;
NvmeGroupKey group_key;
// Comparison operators to allow usage as a map key
bool operator<(const LastBeacon& other) const {
if (gw_id != other.gw_id) return gw_id < other.gw_id;
return group_key < other.group_key;
}
bool operator==(const LastBeacon& other) const {
return gw_id == other.gw_id &&
group_key == other.group_key;
}
};
class NVMeofGwMon: public PaxosService,
public md_config_obs_t
{
NVMeofGwMap map; //NVMeGWMap
NVMeofGwMap pending_map;
std::map<LastBeacon, ceph::coarse_mono_clock::time_point> last_beacon;
ceph::coarse_mono_clock::time_point last_tick;
public:
NVMeofGwMon(Monitor &mn, Paxos &p, const std::string& service_name)
: PaxosService(mn, p, service_name) {
map.mon = &mn;
}
~NVMeofGwMon() override {}
// config observer
const char** get_tracked_conf_keys() const override;
void handle_conf_change(
const ConfigProxy& conf, const std::set<std::string> &changed) override {};
// 3 pure virtual methods of the paxosService
void create_initial() override {};
void create_pending() override;
void encode_pending(MonitorDBStore::TransactionRef t) override;
void init() override;
void on_shutdown() override;
void on_restart() override;
void update_from_paxos(bool *need_bootstrap) override;
version_t get_trim_to() const override;
bool preprocess_query(MonOpRequestRef op) override;
bool prepare_update(MonOpRequestRef op) override;
bool preprocess_command(MonOpRequestRef op);
bool prepare_command(MonOpRequestRef op);
void encode_full(MonitorDBStore::TransactionRef t) override {}
bool preprocess_beacon(MonOpRequestRef op);
bool prepare_beacon(MonOpRequestRef op);
void tick() override;
void print_summary(ceph::Formatter *f, std::ostream *ss) const;
void check_subs(bool type);
void check_sub(Subscription *sub);
private:
// used for calculate pool & group GW responsible for rebalance
uint32_t global_rebalance_index = 1;
uint8_t tick_ratio = 0;
void synchronize_last_beacon();
void process_gw_down(const NvmeGwId &gw_id,
const NvmeGroupKey& group_key, bool &propose_pending,
gw_availability_t avail);
};
#endif /* MON_NVMEGWMONITOR_H_ */
|