Bug 2948: Recovered log entries not applied after prior snapshot 13/18113/5
authorTom Pantelis <tpanteli@brocade.com>
Sat, 4 Apr 2015 03:39:52 +0000 (23:39 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 14 Apr 2015 00:51:14 +0000 (20:51 -0400)
commitc190bfc14468c9ad954201a53326df941161c470
treebbe588f1dbbd2d39dda2d243cc1c12301586df94
parent254cfb302af490110740ebef111ae28783018a02
Bug 2948: Recovered log entries not applied after prior snapshot

Modified SnapshotManager#capture to obtain and cache the last journal sequence
number. On commit, the cached sequence number is used to delete
messages. This preserves any ApplyJournalEntries and ReplicatedLogEntry
messages that occur after the capture is initiated.

As a result of his change, we also have to obtain the unapplied entries
at the time the snapahot is initiated and not when we persist.
Otherwise, log entries persisted after the capture is initiated and
before it's persisted would be included in the snapshot's unapplied
list. On recovery, both entries would be recovered and added to the in-memory
journal resulting in duplicate entries.

These changes may result in a subsequent modification that is applied
after the snapshot is initiated to be included in the snapshot and also
persisted in the journal or included as unapplied in the snapshot. On
recovery, the modification entry would be redundantly applied. This could
result in data tree errors, eg if the modification was a delete, the
redundant apply would cause an exception due to the non-existent node.
We'll have to live with that - I think the only way to prevent it is if
we create the snapshot synchronously. Note this could also have occurred
before these changes.

Change-Id: I745d94f5417e17627c1c4d53be8d6fdf01587d35
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
12 files changed:
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorRecoverySupport.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/SnapshotManager.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/base/messages/CaptureSnapshot.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/AbstractRaftActorIntegrationTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupportTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RecoveryIntegrationTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/ReplicationAndSnapshotsIntegrationTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/ReplicationAndSnapshotsWithLaggingFollowerIntegrationTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/SnapshotManagerTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/InMemoryJournal.java