• Ozan Tezcan's avatar
    Handle unnecessary snapshots better (#143) · 85ae16e0
    Ozan Tezcan authored
    If a node receives a snapshot with snapshot_last_idx, it checks if 
    it already has the snapshot and informs leader accordingly.
    
    The problem is the receiver node may not have a snapshot but log 
    entries more than snapshot_last_idx:
    
    e.g
    Leader: snapshot_last_idx : 50
    Follower: snapshot_last_idx:0, last log entry index: 100
    
    If the leader tries to send snapshot to the follower 
    (with snapshot last index:50), currently, follower accepts 
    the snapshot. As follower already has entries upto index 100, snapshot
    is unnecessary. After delivery is complete, to load the snapshot, 
    follower will call raft_begin_load_snapshot(). This function realizes
    the snapshot was unnecessary and it fails. It is harmless but snapshot
    delivery was unnecessary.
    
    This PR prevents this issue earlier by checking last log index instead
     of snapshot last index.
    
    Also, added more virtraft tests with auto-flush on. 
    (This is a different pattern, it might help with detecting these issues)
    85ae16e0
test_snapshotting.c 31.9 KB