diff --git a/src/replica/prepare_list.cpp b/src/replica/prepare_list.cpp index 2a2d3814ef..783d2febb9 100644 --- a/src/replica/prepare_list.cpp +++ b/src/replica/prepare_list.cpp @@ -79,25 +79,14 @@ error_code prepare_list::prepare(mutation_ptr &mu, error_code err; switch (status) { case partition_status::PS_PRIMARY: - // pop committed mutations if buffer is full or pop_all_committed_mutations = true - while ((d - min_decree() >= capacity() || pop_all_committed_mutations) && - last_committed_decree() > min_decree()) { - pop_min(); - } - return mutation_cache::put(mu); - case partition_status::PS_SECONDARY: case partition_status::PS_POTENTIAL_SECONDARY: - // all mutations with lower decree must be ready - commit(mu->data.header.last_committed_decree, COMMIT_TO_DECREE_HARD); // pop committed mutations if buffer is full or pop_all_committed_mutations = true while ((d - min_decree() >= capacity() || pop_all_committed_mutations) && last_committed_decree() > min_decree()) { pop_min(); } - err = mutation_cache::put(mu); - dassert_replica(err == ERR_OK, "mutation_cache::put failed, err = {}", err); - return err; + return mutation_cache::put(mu); //// delayed commit - only when capacity is an issue // case partition_status::PS_POTENTIAL_SECONDARY: diff --git a/src/replica/replica_2pc.cpp b/src/replica/replica_2pc.cpp index 964d3b9474..4eb93cfb35 100644 --- a/src/replica/replica_2pc.cpp +++ b/src/replica/replica_2pc.cpp @@ -490,7 +490,8 @@ void replica::on_prepare(dsn::message_ex *request) error_code err = _prepare_list->prepare(mu, status()); dassert(err == ERR_OK, "prepare mutation failed, err = %s", err.to_string()); - if (partition_status::PS_POTENTIAL_SECONDARY == status()) { + if (partition_status::PS_POTENTIAL_SECONDARY == status() || + partition_status::PS_SECONDARY == status()) { dassert(mu->data.header.decree <= last_committed_decree() + _options->max_mutation_count_in_prepare_list, "%" PRId64 " VS %" PRId64 "(%" PRId64 " + %d)", @@ -498,13 +499,6 @@ void replica::on_prepare(dsn::message_ex *request) last_committed_decree() + _options->max_mutation_count_in_prepare_list, last_committed_decree(), _options->max_mutation_count_in_prepare_list); - } else if (partition_status::PS_SECONDARY == status()) { - dassert(mu->data.header.decree <= last_committed_decree() + _options->staleness_for_commit, - "%" PRId64 " VS %" PRId64 "(%" PRId64 " + %d)", - mu->data.header.decree, - last_committed_decree() + _options->staleness_for_commit, - last_committed_decree(), - _options->staleness_for_commit); } else { derror("%s: mutation %s on_prepare failed as invalid replica state, state = %s", name(), @@ -569,6 +563,8 @@ void replica::on_append_log_completed(mutation_ptr &mu, error_code err, size_t s } // always ack ack_prepare_message(err, mu); + // all mutations with lower decree must be ready + _prepare_list->commit(mu->data.header.last_committed_decree, COMMIT_TO_DECREE_HARD); break; case partition_status::PS_PARTITION_SPLIT: if (err != ERR_OK) { diff --git a/src/replica/storage/simple_kv/test/case-210.ini b/src/replica/storage/simple_kv/test/case-210.ini index c757146252..bd2cdc1589 100644 --- a/src/replica/storage/simple_kv/test/case-210.ini +++ b/src/replica/storage/simple_kv/test/case-210.ini @@ -138,7 +138,7 @@ prepare_timeout_ms_for_potential_secondaries = 3000 batch_write_disabled = true staleness_for_commit = 5 -max_mutation_count_in_prepare_list = 10 +max_mutation_count_in_prepare_list = 11 mutation_2pc_min_replica_count = 2 group_check_disabled = false diff --git a/src/replica/storage/simple_kv/test/case-211.ini b/src/replica/storage/simple_kv/test/case-211.ini index c757146252..bd2cdc1589 100644 --- a/src/replica/storage/simple_kv/test/case-211.ini +++ b/src/replica/storage/simple_kv/test/case-211.ini @@ -138,7 +138,7 @@ prepare_timeout_ms_for_potential_secondaries = 3000 batch_write_disabled = true staleness_for_commit = 5 -max_mutation_count_in_prepare_list = 10 +max_mutation_count_in_prepare_list = 11 mutation_2pc_min_replica_count = 2 group_check_disabled = false diff --git a/src/replica/storage/simple_kv/test/case-213.ini b/src/replica/storage/simple_kv/test/case-213.ini index d6b90e39e4..5d3dcb4b97 100644 --- a/src/replica/storage/simple_kv/test/case-213.ini +++ b/src/replica/storage/simple_kv/test/case-213.ini @@ -138,7 +138,7 @@ prepare_timeout_ms_for_potential_secondaries = 3000 batch_write_disabled = true staleness_for_commit = 5 -max_mutation_count_in_prepare_list = 10 +max_mutation_count_in_prepare_list = 110 mutation_2pc_min_replica_count = 2 group_check_disabled = false