24
24
25
25
using std::string;
26
26
27
- void NVMeofGwMon::init (){
27
+ void NVMeofGwMon::init () {
28
28
dout (10 ) << " called " << dendl;
29
29
}
30
30
31
- void NVMeofGwMon::on_restart (){
31
+ void NVMeofGwMon::on_restart () {
32
32
dout (10 ) << " called " << dendl;
33
33
last_beacon.clear ();
34
34
last_tick = ceph::coarse_mono_clock::now ();
35
35
synchronize_last_beacon ();
36
36
}
37
37
38
38
39
- void NVMeofGwMon::synchronize_last_beacon (){
39
+ void NVMeofGwMon::synchronize_last_beacon () {
40
40
dout (10 ) << " called, is leader : " << mon.is_leader () <<" active " << is_active () << dendl;
41
41
// Initialize last_beacon to identify transitions of available GWs to unavailable state
42
42
for (const auto & created_map_pair: map.created_gws ) {
43
43
const auto & group_key = created_map_pair.first ;
44
44
const NvmeGwMonStates& gw_created_map = created_map_pair.second ;
45
45
for (const auto & gw_created_pair: gw_created_map) {
46
46
const auto & gw_id = gw_created_pair.first ;
47
- if (gw_created_pair.second .availability == gw_availability_t ::GW_AVAILABLE){
47
+ if (gw_created_pair.second .availability == gw_availability_t ::GW_AVAILABLE) {
48
48
dout (10 ) << " synchronize last_beacon for GW :" << gw_id << dendl;
49
49
LastBeacon lb = {gw_id, group_key};
50
50
last_beacon[lb] = last_tick;
@@ -57,8 +57,8 @@ void NVMeofGwMon::on_shutdown() {
57
57
dout (10 ) << " called " << dendl;
58
58
}
59
59
60
- void NVMeofGwMon::tick (){
61
- if (!is_active () || !mon.is_leader ()){
60
+ void NVMeofGwMon::tick () {
61
+ if (!is_active () || !mon.is_leader ()) {
62
62
dout (10 ) << " NVMeofGwMon leader : " << mon.is_leader () << " active : " << is_active () << dendl;
63
63
return ;
64
64
}
@@ -89,10 +89,10 @@ void NVMeofGwMon::tick(){
89
89
_propose_pending |= propose;
90
90
91
91
const auto cutoff = now - nvmegw_beacon_grace;
92
- for (auto &itr : last_beacon){// Pass over all the stored beacons
92
+ for (auto &itr : last_beacon) {// Pass over all the stored beacons
93
93
auto & lb = itr.first ;
94
94
auto last_beacon_time = itr.second ;
95
- if (last_beacon_time < cutoff){
95
+ if (last_beacon_time < cutoff) {
96
96
dout (10 ) << " beacon timeout for GW " << lb.gw_id << dendl;
97
97
pending_map.process_gw_map_gw_down (lb.gw_id , lb.group_key , propose);
98
98
_propose_pending |= propose;
@@ -106,7 +106,7 @@ void NVMeofGwMon::tick(){
106
106
pending_map.handle_abandoned_ana_groups (propose); // Periodic: take care of not handled ANA groups
107
107
_propose_pending |= propose;
108
108
109
- if (_propose_pending){
109
+ if (_propose_pending) {
110
110
dout (10 ) << " propose pending " <<dendl;
111
111
propose_pending ();
112
112
}
@@ -120,14 +120,14 @@ const char **NVMeofGwMon::get_tracked_conf_keys() const
120
120
return KEYS;
121
121
}
122
122
123
- void NVMeofGwMon::create_pending (){
123
+ void NVMeofGwMon::create_pending () {
124
124
125
125
pending_map = map;// deep copy of the object
126
126
pending_map.epoch ++;
127
127
dout (10 ) << " pending " << pending_map << dendl;
128
128
}
129
129
130
- void NVMeofGwMon::encode_pending (MonitorDBStore::TransactionRef t){
130
+ void NVMeofGwMon::encode_pending (MonitorDBStore::TransactionRef t) {
131
131
132
132
dout (10 ) << dendl;
133
133
ceph_assert (get_last_committed () + 1 == pending_map.epoch );
@@ -137,7 +137,7 @@ void NVMeofGwMon::encode_pending(MonitorDBStore::TransactionRef t){
137
137
put_last_committed (t, pending_map.epoch );
138
138
}
139
139
140
- void NVMeofGwMon::update_from_paxos (bool *need_bootstrap){
140
+ void NVMeofGwMon::update_from_paxos (bool *need_bootstrap) {
141
141
version_t version = get_last_committed ();
142
142
143
143
if (version != map.epoch ) {
@@ -177,15 +177,15 @@ void NVMeofGwMon::check_subs(bool t)
177
177
const std::string type = " NVMeofGw" ;
178
178
dout (10 ) << " count " << mon.session_map .subs .count (type) << dendl;
179
179
180
- if (mon.session_map .subs .count (type) == 0 ){
180
+ if (mon.session_map .subs .count (type) == 0 ) {
181
181
return ;
182
182
}
183
- for (auto sub : *(mon.session_map .subs [type])){
183
+ for (auto sub : *(mon.session_map .subs [type])) {
184
184
check_sub (sub);
185
185
}
186
186
}
187
187
188
- bool NVMeofGwMon::preprocess_query (MonOpRequestRef op){
188
+ bool NVMeofGwMon::preprocess_query (MonOpRequestRef op) {
189
189
dout (20 ) << dendl;
190
190
191
191
auto m = op->get_req <PaxosServiceMessage>();
@@ -210,7 +210,7 @@ bool NVMeofGwMon::preprocess_query(MonOpRequestRef op){
210
210
return false ;
211
211
}
212
212
213
- bool NVMeofGwMon::prepare_update (MonOpRequestRef op){
213
+ bool NVMeofGwMon::prepare_update (MonOpRequestRef op) {
214
214
auto m = op->get_req <PaxosServiceMessage>();
215
215
switch (m->get_type ()) {
216
216
case MSG_MNVMEOF_GW_BEACON:
@@ -254,7 +254,7 @@ bool NVMeofGwMon::preprocess_command(MonOpRequestRef op)
254
254
dout (10 ) << " MonCommand : " << prefix << dendl;
255
255
string format = cmd_getval_or<string>(cmdmap, " format" , " plain" );
256
256
boost::scoped_ptr<Formatter> f (Formatter::create (format));
257
- if (prefix == " nvme-gw show" ){
257
+ if (prefix == " nvme-gw show" ) {
258
258
std::string pool, group;
259
259
if (!f) {
260
260
f.reset (Formatter::create (format, " json-pretty" , " json-pretty" ));
@@ -264,19 +264,18 @@ bool NVMeofGwMon::preprocess_command(MonOpRequestRef op)
264
264
auto group_key = std::make_pair (pool, group);
265
265
dout (10 ) <<" nvme-gw show pool " << pool << " group " << group << dendl;
266
266
267
- if (map.created_gws [group_key].size ()){
267
+ if (map.created_gws [group_key].size ()) {
268
268
f->open_object_section (" common" );
269
269
f->dump_unsigned (" epoch" , map.epoch );
270
270
f->dump_string (" pool" , pool);
271
271
f->dump_string (" group" , group);
272
272
f->dump_unsigned (" num gws" , map.created_gws [group_key].size ());
273
273
sstrm <<" [ " ;
274
- NvmeAnaGrpId anas[MAX_SUPPORTED_ANA_GROUPS];
275
- int i = 0 ;
274
+ NvmeGwId gw_id;
276
275
for (auto & gw_created_pair: map.created_gws [group_key]) {
276
+ gw_id = gw_created_pair.first ;
277
277
auto & st = gw_created_pair.second ;
278
278
sstrm << st.ana_grp_id +1 << " " ;
279
- anas[i++] = st.ana_grp_id ;
280
279
}
281
280
sstrm << " ]" ;
282
281
f->dump_string (" Anagrp list" , sstrm.str ());
@@ -293,8 +292,8 @@ bool NVMeofGwMon::preprocess_command(MonOpRequestRef op)
293
292
sstrm1 << state.availability ;
294
293
f->dump_string (" Availability" , sstrm1.str ());
295
294
sstrm1.str (" " );
296
- for (size_t i = 0 ; i < map.created_gws [group_key]. size (); i++ ) {
297
- sstrm1 << " " << anas[i]+ 1 <<" : " << state.sm_state [anas[i] ] << " ," ;
295
+ for (auto &state_itr: map.created_gws [group_key][gw_id]. sm_state ) {
296
+ sstrm1 << " " << state_itr. first + 1 << " : " << state.sm_state [state_itr. first ] << " ," ;
298
297
}
299
298
f->dump_string (" ana states" , sstrm1.str ());
300
299
f->close_section ();
@@ -345,17 +344,17 @@ bool NVMeofGwMon::prepare_command(MonOpRequestRef op)
345
344
cmd_getval (cmdmap, " group" , group);
346
345
auto group_key = std::make_pair (pool, group);
347
346
dout (10 ) << " id " << id <<" pool " << pool << " group " << group << dendl;
348
- if (prefix == " nvme-gw create" ){
347
+ if (prefix == " nvme-gw create" ) {
349
348
rc = pending_map.cfg_add_gw (id, group_key);
350
- if (rc == -EINVAL){
349
+ if (rc == -EINVAL) {
351
350
err = rc;
352
351
dout (4 ) << " Error: GW cannot be created " << id << " " << pool << " " << group << " rc " << rc << dendl;
353
352
sstrm.str (" " );
354
353
}
355
354
}
356
355
else {
357
356
rc = pending_map.cfg_delete_gw (id, group_key);
358
- if (rc == -EINVAL){
357
+ if (rc == -EINVAL) {
359
358
dout (4 ) << " Error: GW not found in the database " << id << " " << pool << " " << group << " rc " << rc << dendl;
360
359
err = 0 ;
361
360
sstrm.str (" " );
@@ -381,7 +380,7 @@ bool NVMeofGwMon::prepare_command(MonOpRequestRef op)
381
380
}
382
381
383
382
384
- bool NVMeofGwMon::preprocess_beacon (MonOpRequestRef op){
383
+ bool NVMeofGwMon::preprocess_beacon (MonOpRequestRef op) {
385
384
auto m = op->get_req <MNVMeofGwBeacon>();
386
385
const BeaconSubsystems& sub = m->get_subsystems ();
387
386
dout (15 ) << " beacon from " << m->get_type () << " GW : " << m->get_gw_id () << " num subsystems " << sub.size () << dendl;
@@ -390,7 +389,7 @@ bool NVMeofGwMon::preprocess_beacon(MonOpRequestRef op){
390
389
}
391
390
392
391
393
- bool NVMeofGwMon::prepare_beacon (MonOpRequestRef op){
392
+ bool NVMeofGwMon::prepare_beacon (MonOpRequestRef op) {
394
393
auto m = op->get_req <MNVMeofGwBeacon>();
395
394
396
395
dout (20 ) << " availability " << m->get_availability () << " GW : " << m->get_gw_id () <<
@@ -408,20 +407,20 @@ bool NVMeofGwMon::prepare_beacon(MonOpRequestRef op){
408
407
auto gw = group_gws.find (gw_id);
409
408
const BeaconSubsystems& sub = m->get_subsystems ();
410
409
411
- if (avail == gw_availability_t ::GW_CREATED){
410
+ if (avail == gw_availability_t ::GW_CREATED) {
412
411
if (gw == group_gws.end ()) {
413
412
gw_created = false ;
414
413
dout (10 ) << " Warning: GW " << gw_id << " group_key " << group_key << " was not found in the map.Created_gws " << map.created_gws <<dendl;
415
414
goto set_propose;
416
415
}
417
416
else {
418
417
dout (10 ) << " GW prepares the full startup " << gw_id << " GW availability: " << pending_map.created_gws [group_key][gw_id].availability << dendl;
419
- if (pending_map.created_gws [group_key][gw_id].availability == gw_availability_t ::GW_AVAILABLE){
418
+ if (pending_map.created_gws [group_key][gw_id].availability == gw_availability_t ::GW_AVAILABLE) {
420
419
dout (4 ) << " Warning :GW marked as Available in the NVmeofGwMon database, performed full startup - Force gw to exit!" << gw_id <<dendl;
421
420
avail = gw_availability_t ::GW_UNAVAILABLE;
422
421
// Monitor performs Force Failover for this GW in process_gw_map_gw_down
423
422
}
424
- else if (pending_map.created_gws [group_key][gw_id].performed_full_startup == false ){
423
+ else if (pending_map.created_gws [group_key][gw_id].performed_full_startup == false ) {
425
424
pending_map.created_gws [group_key][gw_id].performed_full_startup = true ;
426
425
propose = true ;
427
426
goto set_propose;
@@ -444,7 +443,7 @@ bool NVMeofGwMon::prepare_beacon(MonOpRequestRef op){
444
443
}
445
444
446
445
// At this stage the gw has to be in the Created_gws
447
- if (gw == group_gws.end ()){
446
+ if (gw == group_gws.end ()) {
448
447
dout (4 ) << " Administratively deleted GW sends beacon " << gw_id <<dendl;
449
448
goto false_return; // not sending ack to this beacon
450
449
}
@@ -474,7 +473,7 @@ bool NVMeofGwMon::prepare_beacon(MonOpRequestRef op){
474
473
nonce_propose = true ;
475
474
}
476
475
pending_map.created_gws [group_key][gw_id].last_gw_map_epoch_valid = ( map.epoch == m->get_last_gwmap_epoch () );
477
- if (pending_map.created_gws [group_key][gw_id].last_gw_map_epoch_valid == false ){
476
+ if (pending_map.created_gws [group_key][gw_id].last_gw_map_epoch_valid == false ) {
478
477
dout (20 ) << " map epoch of gw is not up-to-date " << gw_id << " epoch " << map.epoch << " beacon_epoch " << m->get_last_gwmap_epoch () << dendl;
479
478
}
480
479
if (avail == gw_availability_t ::GW_AVAILABLE)
@@ -487,11 +486,11 @@ bool NVMeofGwMon::prepare_beacon(MonOpRequestRef op){
487
486
epoch_t last_osd_epoch = m->get_last_osd_epoch ();
488
487
pending_map.process_gw_map_ka (gw_id, group_key, last_osd_epoch, propose);
489
488
}
490
- else if (avail == gw_availability_t ::GW_UNAVAILABLE){ // state set by GW client application
489
+ else if (avail == gw_availability_t ::GW_UNAVAILABLE) { // state set by GW client application
491
490
LastBeacon lb = {gw_id, group_key};
492
491
493
492
auto it = last_beacon.find (lb);
494
- if (it != last_beacon.end ()){
493
+ if (it != last_beacon.end ()) {
495
494
last_beacon.erase (lb);
496
495
pending_map.process_gw_map_gw_down (gw_id, group_key, propose);
497
496
}
@@ -502,7 +501,7 @@ bool NVMeofGwMon::prepare_beacon(MonOpRequestRef op){
502
501
503
502
set_propose:
504
503
if (!propose) {
505
- if (gw_created){
504
+ if (gw_created) {
506
505
ack_map.created_gws [group_key][gw_id] = map.created_gws [group_key][gw_id];// respond with a map slice correspondent to the same GW
507
506
}
508
507
ack_map.epoch = map.epoch ;
@@ -514,7 +513,7 @@ bool NVMeofGwMon::prepare_beacon(MonOpRequestRef op){
514
513
mon.no_reply (op);
515
514
}
516
515
false_return:
517
- if (propose){
516
+ if (propose) {
518
517
dout (10 ) << " decision in prepare_beacon" <<dendl;
519
518
return true ;
520
519
}
0 commit comments