@@ -1414,13 +1414,6 @@ void RaftReplDev::handle_commit(repl_req_ptr_t rreq, bool recovery) {
14141414 m_listener->on_commit (rreq->lsn (), rreq->header (), rreq->key (), {rreq->local_blkid ()}, rreq);
14151415 }
14161416
1417- if (!recovery) {
1418- auto prev_lsn = m_commit_upto_lsn.exchange (rreq->lsn ());
1419- RD_DBG_ASSERT_GT (rreq->lsn (), prev_lsn,
1420- " Out of order commit of lsns, it is not expected in RaftReplDev. cur_lsns={}, prev_lsns={}" ,
1421- rreq->lsn (), prev_lsn);
1422- }
1423-
14241417 // Remove the request from repl_key map only after the listener operation is completed.
14251418 // This prevents unnecessary block allocation in the following scenario:
14261419 // 1. The follower processes a commit for LSN 100 and remove rreq from rep_key map before listener commit
@@ -1431,6 +1424,13 @@ void RaftReplDev::handle_commit(repl_req_ptr_t rreq, bool recovery) {
14311424 m_repl_key_req_map.erase (rreq->rkey ());
14321425 // Remove the request from lsn map.
14331426 m_state_machine->unlink_lsn_to_req (rreq->lsn (), rreq);
1427+
1428+ if (!recovery) {
1429+ auto prev_lsn = m_commit_upto_lsn.exchange (rreq->lsn ());
1430+ RD_DBG_ASSERT_GT (rreq->lsn (), prev_lsn,
1431+ " Out of order commit of lsns, it is not expected in RaftReplDev. cur_lsns={}, prev_lsns={}" ,
1432+ rreq->lsn (), prev_lsn);
1433+ }
14341434 if (!rreq->is_proposer ()) rreq->clear ();
14351435}
14361436
@@ -1856,18 +1856,21 @@ nuraft::cb_func::ReturnCode RaftReplDev::raft_event(nuraft::cb_func::Type type,
18561856 m_commit_upto_lsn.load (), raft_req->get_commit_idx ());
18571857
18581858 auto reqs = sisl::VectorPool< repl_req_ptr_t >::alloc ();
1859- auto last_commit_lsn = uint64_cast (get_last_commit_lsn ());
1859+ auto last_lsn = uint64_cast (m_data_journal->next_slot () - 1 );
1860+ auto last_term = last_lsn == 0 ? 0
1861+ : m_data_journal->term_at (last_lsn);
18601862 for (unsigned long i = 0 ; i < entries.size (); i++) {
18611863 auto & entry = entries[i];
18621864 auto lsn = start_lsn + i;
18631865 auto term = entry->get_term ();
18641866 if (entry->get_val_type () != nuraft::log_val_type::app_log) { continue ; }
18651867 if (entry->get_buf_ptr ()->size () == 0 ) { continue ; }
1866- // skipping localize for already committed log(dup), they anyway will be discard
1867- // by nuraft before append_log.
1868- if (lsn <= last_commit_lsn) {
1869- RD_LOGT (NO_TRACE_ID , " Raft channel: term {}, lsn {}, skipping dup, last_commit_lsn {}" , term, lsn,
1870- last_commit_lsn);
1868+ // skipping localize for already appended log with the same term(dup), they anyway will be discard
1869+ // or rollback by nuraft before append_log, this way can avoid dup-append for committing logs
1870+ if (lsn <= last_lsn && term == last_term) {
1871+ // This is a duplicate log, we have already applied it, so skip it.
1872+ RD_LOGT (NO_TRACE_ID , " Raft channel: term {}, lsn {}, skipping dup, last_lsn {}, last_term {}" , term, lsn,
1873+ last_lsn, last_term);
18711874 continue ;
18721875 }
18731876 // Those LSNs already in logstore but not yet committed, will be dedup here,
0 commit comments