"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/rde/rded/role.cc" between
opensaf-5.21.06.tar.gz and opensaf-5.21.09.tar.gz

About: OpenSAF is a project focused on Service Availability (SA) that develops middleware based on open and industry standard interfaces for applications requiring uninterrupted 24x7 service.

role.cc  (opensaf-5.21.06):role.cc  (opensaf-5.21.09)
skipping to change at line 199 skipping to change at line 199
Role::Role(NODE_ID own_node_id) Role::Role(NODE_ID own_node_id)
: known_nodes_{}, : known_nodes_{},
role_{PCS_RDA_QUIESCED}, role_{PCS_RDA_QUIESCED},
own_node_id_{own_node_id}, own_node_id_{own_node_id},
proc_{new base::Process()}, proc_{new base::Process()},
election_end_time_{}, election_end_time_{},
discover_peer_timeout_{base::GetEnv("RDE_DISCOVER_PEER_TIMEOUT", discover_peer_timeout_{base::GetEnv("RDE_DISCOVER_PEER_TIMEOUT",
kDefaultDiscoverPeerTimeout)}, kDefaultDiscoverPeerTimeout)},
pre_active_script_timeout_{base::GetEnv( pre_active_script_timeout_{base::GetEnv(
"RDE_PRE_ACTIVE_SCRIPT_TIMEOUT", kDefaultPreActiveScriptTimeout)} {} "RDE_PRE_ACTIVE_SCRIPT_TIMEOUT", kDefaultPreActiveScriptTimeout)},
received_peer_info_{true},
peer_info_wait_time_{},
peer_info_wait_timeout_ {kDefaultWaitPeerInfoTimeout} {}
timespec* Role::Poll(timespec* ts) { timespec* Role::Poll(timespec* ts) {
TRACE_ENTER();
timespec* timeout = nullptr; timespec* timeout = nullptr;
if (role_ == PCS_RDA_UNDEFINED) { if (role_ == PCS_RDA_UNDEFINED) {
timespec now = base::ReadMonotonicClock(); timespec now = base::ReadMonotonicClock();
if (election_end_time_ >= now) { if (election_end_time_ >= now) {
*ts = election_end_time_ - now; *ts = election_end_time_ - now;
timeout = ts; timeout = ts;
} else { } else {
election_end_time_ = base::kTimespecMax; election_end_time_ = base::kTimespecMax;
RDE_CONTROL_BLOCK* cb = rde_get_control_block(); RDE_CONTROL_BLOCK* cb = rde_get_control_block();
skipping to change at line 241 skipping to change at line 245
RDE_CONTROL_BLOCK* cb = rde_get_control_block(); RDE_CONTROL_BLOCK* cb = rde_get_control_block();
if (cb->consensus_service_state == ConsensusState::kUnknown || if (cb->consensus_service_state == ConsensusState::kUnknown ||
cb->consensus_service_state == ConsensusState::kDisconnected) { cb->consensus_service_state == ConsensusState::kDisconnected) {
// consensus service was previously disconnected, refresh state // consensus service was previously disconnected, refresh state
Consensus consensus_service; Consensus consensus_service;
if (consensus_service.IsEnabled() == true && if (consensus_service.IsEnabled() == true &&
cb->state_refresh_thread_started == false) { cb->state_refresh_thread_started == false) {
cb->state_refresh_thread_started = true; cb->state_refresh_thread_started = true;
std::thread(&Role::RefreshConsensusState, this, cb).detach(); std::thread(&Role::RefreshConsensusState, this, cb).detach();
} }
if (consensus_service.IsEnabled() == false) {
// We are already ACTIVE, and has just discovered a new node
// which makes the election_end_time_ reset
if (received_peer_info_ == false) {
timespec now = base::ReadMonotonicClock();
if (peer_info_wait_time_ >= now) {
*ts = peer_info_wait_time_ - now;
timeout = ts;
} else {
// Timeout but haven't received peer info
// The peer RDE could be in ACTIVE
// thus self-fence to avoid split-brain risk
LOG_ER("Discovery peer up without peer info. Risk in split-brain,"
"rebooting this node");
opensaf_quick_reboot("Probable split-brain due to "
"unknown RDE peer info");
}
}
}
} }
} }
return timeout; return timeout;
} }
void Role::ExecutePreActiveScript() { void Role::ExecutePreActiveScript() {
int argc = 1; int argc = 1;
char* argv[] = {const_cast<char*>(pre_active_script_), nullptr}; char* argv[] = {const_cast<char*>(pre_active_script_), nullptr};
proc_->Execute(argc, argv, proc_->Execute(argc, argv,
std::chrono::milliseconds(pre_active_script_timeout_)); std::chrono::milliseconds(pre_active_script_timeout_));
} }
void Role::AddPeer(NODE_ID node_id) { void Role::AddPeer(NODE_ID node_id) {
TRACE_ENTER();
auto result = known_nodes_.insert(node_id); auto result = known_nodes_.insert(node_id);
if (result.second) { if (result.second) {
ResetElectionTimer(); ResetElectionTimer();
if (role_ == PCS_RDA_ACTIVE) {
ResetPeerInfoWaitTimer();
received_peer_info_ = false;
}
} }
} }
void Role::RemovePeer(NODE_ID node_id) {
TRACE_ENTER();
if (received_peer_info_ == false && role_ != PCS_RDA_ACTIVE) {
StopPeerInfoWaitTimer();
}
known_nodes_.erase(node_id);
}
// call from main thread only // call from main thread only
bool Role::IsCandidate() { bool Role::IsCandidate() {
TRACE_ENTER(); TRACE_ENTER();
bool result = false; bool result = false;
Consensus consensus_service; Consensus consensus_service;
RDE_CONTROL_BLOCK* cb = rde_get_control_block(); RDE_CONTROL_BLOCK* cb = rde_get_control_block();
// if relaxed node promotion is enabled, allow this node to be promoted // if relaxed node promotion is enabled, allow this node to be promoted
// active if it can see a peer SC and this node has the lowest node ID // active if it can see a peer SC and this node has the lowest node ID
if (consensus_service.IsRelaxedNodePromotionEnabled() == true && if (consensus_service.IsRelaxedNodePromotionEnabled() == true &&
skipping to change at line 333 skipping to change at line 369
known_nodes_.clear(); known_nodes_.clear();
ResetElectionTimer(); ResetElectionTimer();
} else { } else {
rde_rda_send_role(new_role); rde_rda_send_role(new_role);
} }
} }
return UpdateMdsRegistration(new_role, old_role); return UpdateMdsRegistration(new_role, old_role);
} }
void Role::ResetElectionTimer() { void Role::ResetElectionTimer() {
TRACE_ENTER();
election_end_time_ = base::ReadMonotonicClock() + election_end_time_ = base::ReadMonotonicClock() +
base::MillisToTimespec(discover_peer_timeout_); base::MillisToTimespec(discover_peer_timeout_);
} }
void Role::ResetPeerInfoWaitTimer() {
TRACE_ENTER();
LOG_NO("Start/restart waiting peer info timer");
peer_info_wait_time_ = base::ReadMonotonicClock() +
base::MillisToTimespec(peer_info_wait_timeout_);
}
void Role::StopPeerInfoWaitTimer() {
TRACE_ENTER();
// Turn off peer_info_timer
received_peer_info_ = true;
}
uint32_t Role::UpdateMdsRegistration(PCS_RDA_ROLE new_role, uint32_t Role::UpdateMdsRegistration(PCS_RDA_ROLE new_role,
PCS_RDA_ROLE old_role) { PCS_RDA_ROLE old_role) {
uint32_t rc = NCSCC_RC_SUCCESS; uint32_t rc = NCSCC_RC_SUCCESS;
bool mds_registered_before = old_role != PCS_RDA_QUIESCED; bool mds_registered_before = old_role != PCS_RDA_QUIESCED;
bool mds_registered_after = new_role != PCS_RDA_QUIESCED; bool mds_registered_after = new_role != PCS_RDA_QUIESCED;
if (mds_registered_after != mds_registered_before) { if (mds_registered_after != mds_registered_before) {
if (mds_registered_after) { if (mds_registered_after) {
if (rde_mds_register() != NCSCC_RC_SUCCESS) { if (rde_mds_register() != NCSCC_RC_SUCCESS) {
LOG_ER("rde_mds_register() failed"); LOG_ER("rde_mds_register() failed");
rc = NCSCC_RC_FAILURE; rc = NCSCC_RC_FAILURE;
skipping to change at line 360 skipping to change at line 410
LOG_ER("rde_mds_unregister() failed"); LOG_ER("rde_mds_unregister() failed");
rc = NCSCC_RC_FAILURE; rc = NCSCC_RC_FAILURE;
} }
} }
} }
return rc; return rc;
} }
void Role::SetPeerState(PCS_RDA_ROLE node_role, NODE_ID node_id, void Role::SetPeerState(PCS_RDA_ROLE node_role, NODE_ID node_id,
uint64_t peer_promote_pending) { uint64_t peer_promote_pending) {
TRACE_ENTER();
if (role() == PCS_RDA_UNDEFINED) { if (role() == PCS_RDA_UNDEFINED) {
bool give_up = false; bool give_up = false;
RDE_CONTROL_BLOCK *cb = rde_get_control_block(); RDE_CONTROL_BLOCK *cb = rde_get_control_block();
if (node_role == PCS_RDA_UNDEFINED) { if (node_role == PCS_RDA_UNDEFINED) {
if (cb->promote_pending == 0) { if (cb->promote_pending == 0) {
struct timespec now = base::ReadMonotonicClock(); struct timespec now = base::ReadMonotonicClock();
cb->promote_pending = base::TimespecToMillis(now - cb->promote_start); cb->promote_pending = base::TimespecToMillis(now - cb->promote_start);
} }
if ((cb->promote_pending < peer_promote_pending) || if ((cb->promote_pending < peer_promote_pending) ||
(cb->promote_pending == peer_promote_pending && (cb->promote_pending == peer_promote_pending &&
node_id < own_node_id_)) node_id < own_node_id_))
give_up = true; give_up = true;
} }
if (node_role == PCS_RDA_ACTIVE || node_role == PCS_RDA_STANDBY || if (node_role == PCS_RDA_ACTIVE || node_role == PCS_RDA_STANDBY ||
give_up) { give_up) {
// broadcast QUIESCED role to all peers to stop their waiting peer
// info timer
rde_msg peer_info_req;
peer_info_req.type = RDE_MSG_PEER_INFO_RESP;
peer_info_req.info.peer_info.ha_role = PCS_RDA_QUIESCED;
peer_info_req.info.peer_info.promote_pending = 0;
rde_mds_broadcast(&peer_info_req);
SetRole(PCS_RDA_QUIESCED); SetRole(PCS_RDA_QUIESCED);
LOG_NO("Giving up election against 0x%" PRIx32 LOG_NO("Giving up election against 0x%" PRIx32
" with role %s. " " with role %s. "
"My role is now %s", "My role is now %s",
node_id, to_string(node_role), to_string(role())); node_id, to_string(node_role), to_string(role()));
} }
} }
known_nodes_.insert(node_id);
StopPeerInfoWaitTimer();
} }
void Role::PromoteNodeLate() { void Role::PromoteNodeLate() {
TRACE_ENTER(); TRACE_ENTER();
// we are already active and split brain prevention has been // we are already active and split brain prevention has been
// enabled during runtime, we need to obtain lock // enabled during runtime, we need to obtain lock
RDE_CONTROL_BLOCK* cb = rde_get_control_block(); RDE_CONTROL_BLOCK* cb = rde_get_control_block();
std::thread(&Role::PromoteNode, std::thread(&Role::PromoteNode,
this, cb->cluster_members.size(), this, cb->cluster_members.size(),
 End of changes. 11 change blocks. 
1 lines changed or deleted 62 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)