void replica::init_checkpoint() { check_hashed_access(); // only applicable to primary and secondary replicas if (status() != PS_PRIMARY && status() != PS_SECONDARY) return; // no need to checkpoint if (_app->is_delta_state_learning_supported()) return; // already running if (_secondary_states.checkpoint_task != nullptr) return; // private log must be enabled to make sure commits // are not lost during checkpinting dassert(nullptr != _private_log, "log_enable_private_prepare must be true for checkpointing"); // TODO: when NOT to checkpoint, but use private log replay to build the state if (last_committed_decree() - last_durable_decree() < 10000) return; // primary is downgraded to secondary for checkpointing as no write can be seen // during checkpointing (i.e., state is freezed) if (PS_PRIMARY == status()) { configuration_update_request proposal; proposal.config = _primary_states.membership; proposal.type = CT_DOWNGRADE_TO_SECONDARY; proposal.node = proposal.config.primary; downgrade_to_secondary_on_primary(proposal); } // secondary can start checkpint in the long running thread pool else { dassert(PS_SECONDARY == status(), ""); _secondary_states.checkpoint_task = tasking::enqueue( LPC_CHECKPOINT_REPLICA, this, &replica::checkpoint, gpid_to_hash(get_gpid()) ); } }
void replica::on_config_proposal(configuration_update_request& proposal) { check_hashed_access(); ddebug( "%s: on_config_proposal %s for %s", name(), enum_to_string(proposal.type), proposal.node.to_string() ); if (proposal.config.ballot < get_ballot()) { dwarn( "%s: on_config_proposal is out-dated, %lld vs %lld", name(), proposal.config.ballot, get_ballot() ); return; } if (_primary_states.reconfiguration_task != nullptr) { dinfo( "%s: reconfiguration on the way, skip the incoming proposal", name() ); return; } if (proposal.config.ballot > get_ballot()) { if (!update_configuration(proposal.config)) { // is closing or update failed return; } } switch (proposal.type) { case CT_ASSIGN_PRIMARY: case CT_UPGRADE_TO_PRIMARY: assign_primary(proposal); break; case CT_ADD_SECONDARY: add_potential_secondary(proposal); break; case CT_DOWNGRADE_TO_SECONDARY: downgrade_to_secondary_on_primary(proposal); break; case CT_DOWNGRADE_TO_INACTIVE: downgrade_to_inactive_on_primary(proposal); break; case CT_REMOVE: remove(proposal); break; default: dassert (false, ""); } }