Bug 2948: Recovered log entries not applied after prior snapshot
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / base / messages / CaptureSnapshot.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.raft.base.messages;
10
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
14
15 public class CaptureSnapshot {
16     private final long lastAppliedIndex;
17     private final long lastAppliedTerm;
18     private final long lastIndex;
19     private final long lastTerm;
20     private final boolean installSnapshotInitiated;
21     private final long replicatedToAllIndex;
22     private final long replicatedToAllTerm;
23     private final List<ReplicatedLogEntry> unAppliedEntries;
24
25     public CaptureSnapshot(long lastIndex, long lastTerm, long lastAppliedIndex, long lastAppliedTerm,
26             long replicatedToAllIndex, long replicatedToAllTerm, List<ReplicatedLogEntry> unAppliedEntries) {
27         this(lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm, replicatedToAllIndex, replicatedToAllTerm,
28                 unAppliedEntries, false);
29     }
30
31     public CaptureSnapshot(long lastIndex, long lastTerm, long lastAppliedIndex,
32             long lastAppliedTerm, long replicatedToAllIndex, long replicatedToAllTerm,
33             List<ReplicatedLogEntry> unAppliedEntries, boolean installSnapshotInitiated) {
34         this.lastIndex = lastIndex;
35         this.lastTerm = lastTerm;
36         this.lastAppliedIndex = lastAppliedIndex;
37         this.lastAppliedTerm = lastAppliedTerm;
38         this.installSnapshotInitiated = installSnapshotInitiated;
39         this.replicatedToAllIndex = replicatedToAllIndex;
40         this.replicatedToAllTerm = replicatedToAllTerm;
41         this.unAppliedEntries = unAppliedEntries != null ? unAppliedEntries : Collections.<ReplicatedLogEntry>emptyList();
42     }
43
44     public long getLastAppliedIndex() {
45         return lastAppliedIndex;
46     }
47
48     public long getLastAppliedTerm() {
49         return lastAppliedTerm;
50     }
51
52     public long getLastIndex() {
53         return lastIndex;
54     }
55
56     public long getLastTerm() {
57         return lastTerm;
58     }
59
60     public boolean isInstallSnapshotInitiated() {
61         return installSnapshotInitiated;
62     }
63
64     public long getReplicatedToAllIndex() {
65         return replicatedToAllIndex;
66     }
67
68     public long getReplicatedToAllTerm() {
69         return replicatedToAllTerm;
70     }
71
72     public List<ReplicatedLogEntry> getUnAppliedEntries() {
73         return unAppliedEntries;
74     }
75
76     @Override
77     public String toString() {
78         StringBuilder builder = new StringBuilder();
79         builder.append("CaptureSnapshot [lastAppliedIndex=").append(lastAppliedIndex).append(", lastAppliedTerm=")
80                 .append(lastAppliedTerm).append(", lastIndex=").append(lastIndex).append(", lastTerm=")
81                 .append(lastTerm).append(", installSnapshotInitiated=").append(installSnapshotInitiated)
82                 .append(", replicatedToAllIndex=").append(replicatedToAllIndex).append(", replicatedToAllTerm=")
83                 .append(replicatedToAllTerm).append(", unAppliedEntries size=").append(unAppliedEntries.size()).append("]");
84         return builder.toString();
85     }
86
87
88 }