[ONOS-6297] Use Raft log indexes as versions in ConsistentTreeMap to ensure consistency across leaders.
Change-Id: I816c34b522b7d2a78bad310708436ece01a94aaa
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/Transaction.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/Transaction.java
index fdfe996..3ea2066 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/Transaction.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/Transaction.java
@@ -29,7 +29,6 @@
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkState;
-// CHECKSTYLE:ON
/**
* Manages a transaction within the context of a single primitive.
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapState.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapState.java
index 486cb5f..433b3b3 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapState.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapState.java
@@ -403,7 +403,7 @@
PrepareResult prepareResult = prepare(commit);
if (prepareResult == PrepareResult.OK) {
- commitInternal(commit.operation().transactionLog().transactionId());
+ commitInternal(commit.operation().transactionLog().transactionId()/*, commit.index()*/);
}
return prepareResult;
}
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentTreeMapState.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentTreeMapState.java
index e7c9118..576bfea 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentTreeMapState.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentTreeMapState.java
@@ -20,12 +20,9 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import io.atomix.copycat.server.Commit;
-import io.atomix.copycat.server.Snapshottable;
import io.atomix.copycat.server.StateMachineExecutor;
import io.atomix.copycat.server.session.ServerSession;
import io.atomix.copycat.server.session.SessionListener;
-import io.atomix.copycat.server.storage.snapshot.SnapshotReader;
-import io.atomix.copycat.server.storage.snapshot.SnapshotWriter;
import io.atomix.resource.ResourceStateMachine;
import org.onlab.util.Match;
import org.onosproject.store.service.MapEvent;
@@ -40,7 +37,6 @@
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
-import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -78,13 +74,12 @@
* State machine corresponding to {@link AtomixConsistentTreeMap} backed by a
* {@link TreeMap}.
*/
-public class AtomixConsistentTreeMapState extends ResourceStateMachine implements SessionListener, Snapshottable {
+public class AtomixConsistentTreeMapState extends ResourceStateMachine implements SessionListener {
private final Map<Long, Commit<? extends Listen>> listeners =
Maps.newHashMap();
private TreeMap<String, TreeMapEntryValue> tree = Maps.newTreeMap();
private final Set<String> preparedKeys = Sets.newHashSet();
- private AtomicLong versionCounter = new AtomicLong(0);
private Function<Commit<SubMap>, NavigableMap<String, TreeMapEntryValue>> subMapFunction = this::subMap;
private Function<Commit<FirstKey>, String> firstKeyFunction = this::firstKey;
@@ -115,16 +110,6 @@
}
@Override
- public void snapshot(SnapshotWriter writer) {
- writer.writeLong(versionCounter.get());
- }
-
- @Override
- public void install(SnapshotReader reader) {
- versionCounter = new AtomicLong(reader.readLong());
- }
-
- @Override
public void configure(StateMachineExecutor executor) {
// Listeners
executor.register(Listen.class, this::listen);
@@ -266,7 +251,7 @@
}
byte[] newValue = commit.operation().value();
- long newVersion = versionCounter.incrementAndGet();
+ long newVersion = commit.index();
Versioned<byte[]> newTreeValue = newValue == null ? null
: new Versioned<byte[]>(newValue, newVersion);