X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fpersistence%2FLocalSnapshotStore.java;h=42c90b80d4df0ca70e6fbb95ba8f5be9b8cadb6b;hb=78aefba8c580123d0763b483fab81d2a993e32eb;hp=62b0cf5bfd061867da72cd4084eb8eec86d72821;hpb=d8ef44c67accea4006489e4cbb6c8f0d4d428b6a;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStore.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStore.java index 62b0cf5bfd..42c90b80d4 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStore.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStore.java @@ -7,6 +7,8 @@ */ package org.opendaylight.controller.cluster.persistence; +import static com.google.common.base.Preconditions.checkArgument; + import akka.actor.ExtendedActorSystem; import akka.dispatch.Futures; import akka.persistence.SelectedSnapshot; @@ -20,6 +22,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.io.ByteStreams; import com.typesafe.config.Config; import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -137,7 +140,7 @@ public class LocalSnapshotStore extends SnapshotStore { private Object deserialize(final File file) throws IOException { return JavaSerializer.currentSystem().withValue((ExtendedActorSystem) context().system(), (Callable) () -> { - try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(file))) { + try (ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)))) { return in.readObject(); } catch (ClassNotFoundException e) { throw new IOException("Error loading snapshot file " + file, e); @@ -175,7 +178,7 @@ public class LocalSnapshotStore extends SnapshotStore { LOG.debug("Saving to temp file: {}", temp); - try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(temp))) { + try (ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(temp)))) { out.writeObject(snapshot); } catch (IOException e) { LOG.error("Error saving snapshot file {}. Deleting file..", temp, e); @@ -341,9 +344,9 @@ public class LocalSnapshotStore extends SnapshotStore { @VisibleForTesting static int compare(final SnapshotMetadata m1, final SnapshotMetadata m2) { - return (int) (!m1.persistenceId().equals(m2.persistenceId()) - ? m1.persistenceId().compareTo(m2.persistenceId()) : - m1.sequenceNr() != m2.sequenceNr() ? m1.sequenceNr() - m2.sequenceNr() : - m1.timestamp() != m2.timestamp() ? m1.timestamp() - m2.timestamp() : 0); + checkArgument(m1.persistenceId().equals(m2.persistenceId()), + "Persistence id does not match. id1: %s, id2: %s", m1.persistenceId(), m2.persistenceId()); + final int cmp = Long.compare(m1.timestamp(), m2.timestamp()); + return cmp != 0 ? cmp : Long.compare(m1.sequenceNr(), m2.sequenceNr()); } }