Skip to content

Commit

Permalink
merge feat(split): register child partition XiaoMi#391
Browse files Browse the repository at this point in the history
  • Loading branch information
hycdong committed Jun 19, 2020
1 parent a9e1f03 commit 8157d69
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 255 deletions.
1 change: 1 addition & 0 deletions src/dist/replication/common/replication_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef std::unordered_map<::dsn::rpc_address, dsn::task_ptr> node_tasks;
typedef rpc_holder<query_split_request, query_split_response> query_split_rpc;
typedef rpc_holder<stop_split_request, stop_split_response> stop_split_rpc;
typedef rpc_holder<control_split_request, control_split_response> control_split_rpc;
typedef rpc_holder<register_child_request, register_child_response> register_child_rpc;

class replication_options
{
Expand Down
18 changes: 10 additions & 8 deletions src/dist/replication/lib/replica.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,16 @@ class replica : public serverlet<replica>, public ref_counter, public replica_ba
rpc_address finish_update_address,
bool is_update_child);

// all replicas update partition count, primary will register children on meta
virtual void register_child_on_meta(ballot b);
virtual void on_register_child_on_meta_reply(dsn::error_code ec,
std::shared_ptr<register_child_request> request,
std::shared_ptr<register_child_response> response);
// primary parent register children on meta_server
void register_child_on_meta(ballot b);
void on_register_child_on_meta_reply(dsn::error_code ec,
const register_child_request &request,
const register_child_response &response);
// primary sends register request to meta_server
void parent_send_register_request(const register_child_request &request);

// child partition has been registered on meta_server, could be active
void child_partition_active(const partition_configuration &config);

// meta <=> replica configuration sync through on_config_sync
// called by primary replica to check if partition count changed and partition flag changed to
Expand Down Expand Up @@ -414,9 +419,6 @@ class replica : public serverlet<replica>, public ref_counter, public replica_ba
// parent replica handle child ack when child copy mutation synchronously
void on_copy_mutation_reply(dsn::error_code ec, ballot b, decree d);

// child partitions have been registered on meta, could be active
void child_partition_active(const partition_configuration &config);

// child copy parent prepare list and call child_learn_states
void child_copy_prepare_list(learn_state lstate,
std::vector<mutation_ptr> mutation_list,
Expand Down
30 changes: 12 additions & 18 deletions src/dist/replication/lib/replica_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ void replica::update_configuration_on_meta_server(config_type::type type,
::dsn::rpc_address node,
partition_configuration &newConfig)
{
// type should never be `CT_REGISTER_CHILD`
// if this happens, it means serious mistake happened during partition split
// assert here to stop split and avoid splitting wrong
if (type == config_type::CT_REGISTER_CHILD) {
dassert_replica(false, "invalid config_type, type = {}", enum_to_string(type));
}

newConfig.last_committed_decree = last_committed_decree();

if (type == config_type::CT_PRIMARY_FORCE_UPDATE_BALLOT) {
Expand All @@ -370,8 +377,6 @@ void replica::update_configuration_on_meta_server(config_type::type type,
"");
dassert(
newConfig.primary == node, "%s VS %s", newConfig.primary.to_string(), node.to_string());
} else if (type == config_type::CT_REGISTER_CHILD) {
dassert(false, "invalid config_type, type = %s", enum_to_string(type));
} else if (type != config_type::CT_ASSIGN_PRIMARY &&
type != config_type::CT_UPGRADE_TO_PRIMARY) {
dassert(status() == partition_status::PS_PRIMARY,
Expand Down Expand Up @@ -720,12 +725,11 @@ bool replica::update_local_configuration(const replica_configuration &config,
break;
case partition_status::PS_PARTITION_SPLIT:
if (config.status == partition_status::PS_INACTIVE) {
dwarn("%s: status change from %s @ %" PRId64 " to %s @ %" PRId64 " is not allowed",
name(),
enum_to_string(old_status),
old_ballot,
enum_to_string(config.status),
config.ballot);
dwarn_replica("status change from {} @ {} to {} @ {} is not allowed",
enum_to_string(old_status),
old_ballot,
enum_to_string(config.status),
config.ballot);
return false;
}
break;
Expand Down Expand Up @@ -1321,15 +1325,5 @@ void replica::on_query_child_state_reply(error_code ec,
}
}

void replica::child_partition_active(const partition_configuration &config)
{
ddebug_f("{} finish partition split and become active", name());
_stub->_counter_replicas_splitting_recent_split_succ_count->increment();
// TODO(hyc): should set is false
_primary_states.sync_send_write_request = false;
_primary_states.last_prepare_decree_on_new_primary = _prepare_list->max_decree();
update_configuration(config);
}

} // namespace replication
} // namespace dsn
3 changes: 2 additions & 1 deletion src/dist/replication/lib/replica_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class primary_context
// otherwise, not during partition split
bool sync_send_write_request{false};

// replica->meta register child on meta server and remote storage
// Used for partition split
// primary parent register child on meta_server task
dsn::task_ptr register_child_task;

// replica-> meta query child partition configuration
Expand Down
Loading

0 comments on commit 8157d69

Please sign in to comment.