@@ -1386,6 +1386,7 @@ func TestHandleMsgApp(t *testing.T) {
13861386 }
13871387 }
13881388 for _ , tt := range []struct {
1389+ commit uint64 // the initial commit index
13891390 m pb.Message
13901391 wIndex uint64
13911392 wCommit uint64
@@ -1402,6 +1403,16 @@ func TestHandleMsgApp(t *testing.T) {
14021403 {m : msgApp (2 , entryID {index : 2 , term : 2 }.terms (2 ), 3 ), wIndex : 3 , wCommit : 3 },
14031404 {m : msgApp (2 , entryID {index : 1 , term : 1 }.terms (2 ), 4 ), wIndex : 2 , wCommit : 2 },
14041405
1406+ // Appends overlapping the commit index.
1407+ // TODO(pav-kv): accept these appends.
1408+ {commit : 2 , m : msgApp (2 , entryID {index : 1 , term : 1 }.terms (2 ), 2 ), wIndex : 2 , wCommit : 2 },
1409+ {commit : 2 , m : msgApp (2 , entryID {index : 1 , term : 1 }.terms (2 , 2 , 2 ), 4 ), wIndex : 2 , wCommit : 2 },
1410+ {commit : 2 , m : msgApp (2 , entryID {index : 2 , term : 2 }.terms (2 ), 3 ), wIndex : 3 , wCommit : 3 },
1411+ // Something is wrong with the appended slice. Entry at index 2 is already
1412+ // committed with term = 2, but we are receiving an append which says entry
1413+ // 2 has term 1 and is committed. This must be rejected.
1414+ {commit : 2 , m : msgApp (2 , entryID {index : 1 , term : 1 }.terms (1 , 1 ), 3 ), wIndex : 2 , wCommit : 2 },
1415+
14051416 // Ensure 3
14061417 {m : msgApp (1 , entryID {index : 1 , term : 1 }.terms (), 3 ), wIndex : 2 , wCommit : 1 }, // match entry 1, commit up to last new entry 1
14071418 {m : msgApp (2 , entryID {index : 1 , term : 1 }.terms (2 ), 3 ), wIndex : 2 , wCommit : 2 }, // match entry 1, commit up to last new entry 2
@@ -1411,8 +1422,11 @@ func TestHandleMsgApp(t *testing.T) {
14111422 t .Run ("" , func (t * testing.T ) {
14121423 storage := newTestMemoryStorage (withPeers (1 , 2 ))
14131424 require .NoError (t , storage .Append (init ))
1425+ require .NoError (t , storage .SetHardState (pb.HardState {
1426+ Term : term ,
1427+ Commit : tt .commit ,
1428+ }))
14141429 sm := newTestRaft (1 , 10 , 1 , storage )
1415- sm .becomeFollower (term , None )
14161430
14171431 sm .handleAppendEntries (tt .m )
14181432 assert .Equal (t , tt .wIndex , sm .raftLog .lastIndex ())
0 commit comments