BUG 4202: Writes not correctly writing to current shard 47/39247/2
authorTomas Cere <tcere@cisco.com>
Mon, 23 May 2016 12:38:42 +0000 (14:38 +0200)
committerTomas Cere <tcere@cisco.com>
Mon, 23 May 2016 12:56:46 +0000 (12:56 +0000)
If we had a potential child writes were only writing the children
without actually writing the data that needed to go to the current
cursor location.

Change-Id: I38e7b8374e963fc6b2e3b98c360a6413dd54e886
Signed-off-by: Tomas Cere <tcere@cisco.com>
dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/WriteableNodeOperation.java

index d76c67b2aec5105cb9e20747c97b7797c4604cdb..29087156512c117d27bc64d5dbb0d2bbc33e5f28 100644 (file)
@@ -93,17 +93,23 @@ abstract class WriteableNodeOperation implements WriteCursorStrategy {
     @Override
     @SuppressWarnings("rawtypes")
     public final void writeToCurrent(final NormalizedNodeContainer<?, ?, ?> data) {
+        // write the entire thing into the cursor
+        write(data.getIdentifier(), data);
+        // write the children with subshard check and subshard write if we are going into subshard
+        cursor.enter(data.getIdentifier());
         for (NormalizedNode<?, ?> writtenChild : data.getValue()) {
             write(writtenChild.getIdentifier(), writtenChild);
         }
-        // Delete step
+        // Delete step - remove subshard data that was written into current shard
         for (Entry<PathArgument, WriteableModificationNode> shardChild : node.getChildrenWithSubshards().entrySet()) {
             PathArgument childId = shardChild.getKey();
             @SuppressWarnings("unchecked")
             Optional<NormalizedNode<?, ?>> writtenValue = ((NormalizedNodeContainer) data).getChild(childId);
-            if (!writtenValue.isPresent()) {
-                delete(childId, shardChild.getValue());
+            if (writtenValue.isPresent()) {
+                // delete from current
+                cursor.delete(childId);
             }
         }
+        cursor.exit();
     }
 }