X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardDataTree.java;h=d83dd22fcfe6766047b012f44938876ec9fdedd7;hb=a54716c7a8c9a49a6b7b19eaedfbe522a2556b2b;hp=56c5eb65bf087c3a0d979de2ecaff7b0a65467a2;hpb=9fb1df14f2dc885fee1dce821b753cc99af6e54f;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java index 56c5eb65bf..d83dd22fcf 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java @@ -9,12 +9,16 @@ package org.opendaylight.controller.cluster.datastore; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; +import com.google.common.base.Preconditions; import com.google.common.base.Strings; +import java.net.URI; import java.util.AbstractMap.SimpleEntry; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import javax.annotation.concurrent.NotThreadSafe; +import org.opendaylight.controller.cluster.datastore.node.utils.transformer.NormalizedNodePruner; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; @@ -42,7 +46,6 @@ import org.slf4j.LoggerFactory; * This class is not part of the API contract and is subject to change at any time. */ @NotThreadSafe -@VisibleForTesting public final class ShardDataTree extends ShardDataTreeTransactionParent { private static final Logger LOG = LoggerFactory.getLogger(ShardDataTree.class); private static final ShardDataTreeNotificationManager MANAGER = new ShardDataTreeNotificationManager(); @@ -50,12 +53,13 @@ public final class ShardDataTree extends ShardDataTreeTransactionParent { private final ShardDataTreeChangePublisher treeChangePublisher = new ShardDataTreeChangePublisher(); private final ListenerTree listenerTree = ListenerTree.create(); private final TipProducingDataTree dataTree; + private Set validNamespaces; + private ShardDataTreeTransactionFactory transactionFactory = new RecoveryShardDataTreeTransactionFactory(); ShardDataTree(final SchemaContext schemaContext) { dataTree = InMemoryDataTreeFactory.getInstance().create(); - if (schemaContext != null) { - dataTree.setSchemaContext(schemaContext); - } + updateSchemaContext(schemaContext); + } TipProducingDataTree getDataTree() { @@ -63,7 +67,9 @@ public final class ShardDataTree extends ShardDataTreeTransactionParent { } void updateSchemaContext(final SchemaContext schemaContext) { + Preconditions.checkNotNull(schemaContext); dataTree.setSchemaContext(schemaContext); + validNamespaces = NormalizedNodePruner.namespaces(schemaContext); } private ShardDataTreeTransactionChain ensureTransactionChain(final String chainId) { @@ -78,7 +84,7 @@ public final class ShardDataTree extends ShardDataTreeTransactionParent { ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final String txId, final String chainId) { if (Strings.isNullOrEmpty(chainId)) { - return new ReadOnlyShardDataTreeTransaction(txId, dataTree.takeSnapshot()); + return transactionFactory.newReadOnlyTransaction(txId, chainId); } return ensureTransactionChain(chainId).newReadOnlyTransaction(txId); @@ -86,7 +92,7 @@ public final class ShardDataTree extends ShardDataTreeTransactionParent { ReadWriteShardDataTreeTransaction newReadWriteTransaction(final String txId, final String chainId) { if (Strings.isNullOrEmpty(chainId)) { - return new ReadWriteShardDataTreeTransaction(this, txId, dataTree.takeSnapshot().newModification()); + return transactionFactory.newReadWriteTransaction(txId, chainId); } return ensureTransactionChain(chainId).newReadWriteTransaction(txId); @@ -177,4 +183,51 @@ public final class ShardDataTree extends ShardDataTreeTransactionParent { return new SimpleShardDataTreeCohort(this, snapshot); } + void recoveryDone(){ + transactionFactory = new RegularShardDataTreeTransactionFactory(); + } + + @VisibleForTesting + ShardDataTreeTransactionFactory getTransactionFactory(){ + return transactionFactory; + } + + @VisibleForTesting + static interface ShardDataTreeTransactionFactory { + ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final String txId, final String chainId); + + ReadWriteShardDataTreeTransaction newReadWriteTransaction(final String txId, final String chainId); + } + + @VisibleForTesting + class RecoveryShardDataTreeTransactionFactory implements ShardDataTreeTransactionFactory { + + @Override + public ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(String txId, String chainId) { + return new ReadOnlyShardDataTreeTransaction(txId, + new PruningShardDataTreeSnapshot(dataTree.takeSnapshot(), validNamespaces)); + } + + @Override + public ReadWriteShardDataTreeTransaction newReadWriteTransaction(String txId, String chainId) { + return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId, + new PruningShardDataTreeSnapshot(dataTree.takeSnapshot(), validNamespaces).newModification()); + } + } + + @VisibleForTesting + class RegularShardDataTreeTransactionFactory implements ShardDataTreeTransactionFactory { + + @Override + public ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(String txId, String chainId) { + return new ReadOnlyShardDataTreeTransaction(txId, dataTree.takeSnapshot()); + + } + + @Override + public ReadWriteShardDataTreeTransaction newReadWriteTransaction(String txId, String chainId) { + return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId, dataTree.takeSnapshot() + .newModification()); + } + } }