From fd6fce5918121f6c802acdbe67ba9ac006049b94 Mon Sep 17 00:00:00 2001 From: Gary Wu Date: Wed, 18 Nov 2015 11:23:06 -0800 Subject: [PATCH] Prevent partial init in DatastoreSnapshotRestore The config subsystem should only push one config at a time, but in case it doesn't, synchronize DatastoreSnapshotRestore.initialize() to prevent partial initialization in the event of concurrent calls to getAndRemove(). Change-Id: Ie614e8b2045d86ea46b55609bf5cde9e6597b086 Signed-off-by: Gary Wu --- .../cluster/datastore/DatastoreSnapshotRestore.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestore.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestore.java index bed23895d3..7ef05e273f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestore.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestore.java @@ -15,7 +15,6 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot; import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshotList; @@ -35,7 +34,6 @@ public class DatastoreSnapshotRestore { private final String restoreDirectoryPath; private final Map datastoreSnapshots = new ConcurrentHashMap<>(); - private final AtomicBoolean initialized = new AtomicBoolean(); public static void createInstance(String restoreDirectoryPath) { instance.compareAndSet(null, new DatastoreSnapshotRestore(restoreDirectoryPath)); @@ -54,10 +52,9 @@ public class DatastoreSnapshotRestore { this.restoreDirectoryPath = Preconditions.checkNotNull(restoreDirectoryPath); } - private void initialize() { - if(!initialized.compareAndSet(false, true)) { - return; - } + // sychronize this method so that, in case of concurrent access to getAndRemove(), + // no one ends up with partially initialized data + private synchronized void initialize() { File restoreDirectoryFile = new File(restoreDirectoryPath); -- 2.36.6