Skip to content

Commit

Permalink
my additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonid Chernin committed Dec 31, 2023
1 parent 753e6d3 commit b2e2dd0
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/mon/NVMeofGwMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int NVMeofGwMap::cfg_add_gw(const GW_ID_T &gw_id, const GROUP_KEY& group_key) {
GW_CREATED_T gw_created(i);
Created_gws[group_key][gw_id] = gw_created;

dout(4) << __func__ << "Created GW: " << gw_id << " pool " << group_key.first << "group" << group_key.second
dout(4) << __func__ << "Created GW: " << gw_id << " pool " << group_key.first << " group " << group_key.second
<< " grpid " << gw_created.ana_grp_id << dendl;
return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions src/mon/NVMeofGwMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class NVMeofGwMap
void cancel_timer(const GW_ID_T &gw_id, const GROUP_KEY& group_key, const NQN_ID_T& nqn, ANA_GRP_ID_T anagrpid);

public:
void debug_encode_decode(){
ceph::buffer::list bl;
encode(bl);
auto p = bl.cbegin();
decode(p);
}

void encode(ceph::buffer::list &bl, bool full_encode = true) const {
using ceph::encode;
__u8 struct_v = 0;
Expand Down
108 changes: 105 additions & 3 deletions src/mon/NVMeofGwMon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,108 @@ void NVMeofGwMon::on_restart(){

void NVMeofGwMon::on_shutdown() {}

static int cnt ;
#define start_cnt 6
void NVMeofGwMon::inject1(){
//bool propose = false;
if( ++cnt == 4 ){// simulation that new configuration was added
std::string pool = "pool1";
std::string group = "grp1";
auto group_key = std::make_pair(pool, group);
pending_map.cfg_add_gw("GW1" ,group_key);
pending_map.cfg_add_gw("GW2" ,group_key);
pending_map.cfg_add_gw("GW3" ,group_key);
NONCE_VECTOR_T new_nonces = {"abc", "def","hij"};
//ANA_GRP_ID_T grp = 1;
//pending_map.update_gw_nonce("GW1.g1.p1", grp, new_nonces);
pending_map.Created_gws[group_key]["GW1"].nonce_map[1] = new_nonces;

// pending_map.update_gw_nonce("GW1.g1.p1", grp, new_nonces);
pending_map.Created_gws[group_key]["GW2"].nonce_map[2] = new_nonces;
GW_STATE_T gst1(1);
std::string nqn1 = "nqn2008.node1";
pending_map.Gmap[group_key][nqn1]["GW2"] = gst1;

GW_STATE_T gst2(2);
pending_map.Gmap[group_key][nqn1]["GW3"] = gst2;
dout(4) << pending_map << dendl;


pending_map.debug_encode_decode();
dout(4) << "Dump map after decode encode:" <<dendl;
dout(4) << pending_map << dendl;


//std::stringstream ss;
//pending_map._dump_created_gws(ss);
//dout(4) << ss.str() << dendl;

//pending_map._dump_gwmap(pending_map.Gmap);
//pending_map.debug_encode_decode();
//dout(4) << "Dump map after decode encode:" <<dendl;
//std::stringstream ss1;
//pending_map._dump_created_gws(ss1);
//dout(4) << ss1.str() << dendl;



// pending_map._dump_gwmap(pending_map.Gmap);
}
/* else if( cnt == start_cnt ){ // simulate - add another GW - to check that new map would be synchronized with peons
pending_map.cfg_add_gw("gw2" );
pending_map._dump_gwmap(pending_map.Gmap);
//Simulate KA beacon from the gws
pending_map.process_gw_map_ka( "gw1", "nqn2008.node1", propose);
if(propose)
propose_pending();
pending_map._dump_gwmap(pending_map.Gmap);
}
else if( cnt == start_cnt+2 ){ // simulate - add another GW - to check that new map would be synchronized with peons
pending_map.process_gw_map_ka( "gw2", "nqn2008.node1", propose);
if(propose)
propose_pending();
}
else if( cnt == start_cnt+3 ){ // simulate - gw1 down
pending_map.process_gw_map_gw_down( "gw1", "nqn2008.node1", propose);
if(propose)
propose_pending();
}
else if( cnt == start_cnt+5 ){ // simulate - gw1 is back
pending_map.process_gw_map_ka( "gw1", "nqn2008.node1", propose);
if(propose)
propose_pending();
}
else if( cnt == start_cnt+6 ){ // simulate - gw1 is down Simulate gw election by polling function handle_homeless_ana_groups
pending_map.process_gw_map_gw_down( "gw1", "nqn2008.node1", propose);
if(propose)
propose_pending();
}
else if( cnt == start_cnt+7 ){ // simulate - gw1 is UP
pending_map.process_gw_map_ka( "gw1", "nqn2008.node1", propose);
if(propose)
propose_pending();
}
else if( cnt == start_cnt+9 ){ // simulate - gw2 still OK - checks the persistency timer in the state
pending_map.process_gw_map_ka( "gw2", "nqn2008.node1", propose);
if(propose)
propose_pending();
}
*/
}



void NVMeofGwMon::tick(){
// static int cnt=0;
if(map.delay_propose){
Expand All @@ -49,7 +151,7 @@ void NVMeofGwMon::tick(){
}
bool _propose_pending = false;

//inject1();
inject1();
const auto now = ceph::coarse_mono_clock::now();
const auto nvmegw_beacon_grace = g_conf().get_val<std::chrono::seconds>("mon_nvmeofgw_beacon_grace");
dout(4) << MY_MON_PREFFIX << __func__ << "NVMeofGwMon leader got a real tick, pending epoch "<< pending_map.epoch << dendl;
Expand Down Expand Up @@ -371,7 +473,7 @@ bool NVMeofGwMon::preprocess_beacon(MonOpRequestRef op){
}


//#define BYPASS_GW_CREATE_CLI
#define BYPASS_GW_CREATE_CLI

bool NVMeofGwMon::prepare_beacon(MonOpRequestRef op){
dout(4) << MY_MON_PREFFIX <<__func__ << dendl;
Expand All @@ -397,7 +499,7 @@ bool NVMeofGwMon::prepare_beacon(MonOpRequestRef op){
else{
dout(4) << "GW " << gw_id << " sent beacon being in state GW_WAIT_INITIAL_MAP but it is not created yet!!! "<< dendl;
#ifdef BYPASS_GW_CREATE_CLI
pending_map.cfg_add_gw(gw_id);
pending_map.cfg_add_gw(gw_id ,group_key);
dout(4) << "GW " << gw_id << " created since mode is bypass-create-cli "<< dendl;
propose= true;
#endif
Expand Down
20 changes: 15 additions & 5 deletions src/mon/NVMeofGwSerialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ inline std::ostream& operator<<(std::ostream& os, const GROUP_KEY value) {
};

inline std::ostream& operator<<(std::ostream& os, const GW_STATE_T value) {
os << "GW_STATE_T [ sm_state ";
os << "GW_STATE_T [ \n (gw-mon) sm_state ";
for (int i = 0; i < MAX_SUPPORTED_ANA_GROUPS; i++) {
os << value.sm_state[i] << ",";
}
os << "] failover peers ";
os << "] \n (gw-mon) failover peers ";
for (int i = 0; i < MAX_SUPPORTED_ANA_GROUPS; i++) {
os << value.failover_peer[i] << ",";
}
Expand All @@ -285,7 +285,7 @@ inline std::ostream& operator<<(std::ostream& os, const GWMAP value) {
for (auto& nqn_state: value) {
os << " { nqn: " << nqn_state.first << " -> ";
for (auto& gw_state: nqn_state.second) {
os << " { gw_id: " << gw_state.first << " -> " << gw_state.second << "}";
os << "\n (gw-mon) { gw_id: " << gw_state.first << " -> " << gw_state.second << "}";
}
os << "}";
}
Expand All @@ -297,11 +297,21 @@ inline std::ostream& operator<<(std::ostream& os, const NVMeofGwMap value) {
for (auto& group_state: value.Gmap) {
os << " { " << group_state.first << " } -> { " << group_state.second << " }";
}
os << " ] [ Created_gws: ";
os << " ] \n (gw-mon)[ Created_gws: ";
for (auto& group_gws: value.Created_gws) {
os << " { " << group_gws.first << " } -> { ";
for (auto& gw: group_gws.second) {
os << " { gw_id " << gw.first << " } -> { " << gw.second.ana_grp_id << " }";
os << " \n (gw-mon) { gw_id " << gw.first << " } -> { ana-grp-id:" << gw.second.ana_grp_id << " nonces : " ; // << " }";
// dump nonces map
if(gw.second.nonce_map.size())
for( auto &nonce_map : gw.second.nonce_map){
os << "ana_grp: " << nonce_map.first << " [ " ;
for (auto & nonces : nonce_map.second){
os << nonces << " ";
}
os << "]" ;
}

}
os << " }";
}
Expand Down

0 comments on commit b2e2dd0

Please sign in to comment.