You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ge...@apache.org on 2018/12/13 11:28:09 UTC

lucene-solr:branch_7x: SOLR-13037: Harden TestSimGenericDistributedQueue

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 3d6a09e9d -> b072a7d26


SOLR-13037: Harden TestSimGenericDistributedQueue


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b072a7d2
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b072a7d2
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b072a7d2

Branch: refs/heads/branch_7x
Commit: b072a7d264a3cd45ff83ebb97045d05bb758fefd
Parents: 3d6a09e
Author: Jason Gerlowski <ge...@apache.org>
Authored: Wed Dec 12 22:01:07 2018 -0500
Committer: Jason Gerlowski <ge...@apache.org>
Committed: Thu Dec 13 06:28:02 2018 -0500

----------------------------------------------------------------------
 .../autoscaling/sim/SimDistribStateManager.java | 76 ++++++++++++--------
 .../sim/TestSimGenericDistributedQueue.java     |  3 -
 2 files changed, 46 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b072a7d2/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/SimDistribStateManager.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/SimDistribStateManager.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/SimDistribStateManager.java
index 7b73038..afccdaa 100644
--- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/SimDistribStateManager.java
+++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/SimDistribStateManager.java
@@ -311,17 +311,7 @@ public class SimDistribStateManager implements DistribStateManager {
       n = parentNode.children != null ? parentNode.children.get(currentName) : null;
       if (n == null) {
         if (create) {
-          if ((parentNode.mode == CreateMode.EPHEMERAL || parentNode.mode == CreateMode.EPHEMERAL_SEQUENTIAL) &&
-              (mode == CreateMode.EPHEMERAL || mode == CreateMode.EPHEMERAL_SEQUENTIAL)) {
-            throw new IOException("NoChildrenEphemerals for " + parentNode.path);
-          }
-          if (CreateMode.PERSISTENT_SEQUENTIAL == mode || CreateMode.EPHEMERAL_SEQUENTIAL == mode) {
-            currentName = currentName + String.format(Locale.ROOT, "%010d", parentNode.seq);
-            parentNode.seq++;
-          }
-          currentPath.append(currentName);
-          n = new Node(parentNode, currentName, currentPath.toString(), mode, id);
-          parentNode.setChild(currentName, n);
+          n = createNode(parentNode, mode, currentPath, currentName,true);
         } else {
           break;
         }
@@ -333,6 +323,26 @@ public class SimDistribStateManager implements DistribStateManager {
     return n;
   }
 
+  private Node createNode(Node parentNode, CreateMode mode, StringBuilder fullChildPath, String baseChildName, boolean attachToParent) throws IOException {
+    String nodeName = baseChildName;
+    if ((parentNode.mode == CreateMode.EPHEMERAL || parentNode.mode == CreateMode.EPHEMERAL_SEQUENTIAL) &&
+        (mode == CreateMode.EPHEMERAL || mode == CreateMode.EPHEMERAL_SEQUENTIAL)) {
+      throw new IOException("NoChildrenEphemerals for " + parentNode.path);
+    }
+    if (CreateMode.PERSISTENT_SEQUENTIAL == mode || CreateMode.EPHEMERAL_SEQUENTIAL == mode) {
+      nodeName = nodeName + String.format(Locale.ROOT, "%010d", parentNode.seq);
+      parentNode.seq++;
+    }
+
+    fullChildPath.append(nodeName);
+    Node child = new Node(parentNode, nodeName, fullChildPath.toString(), mode, id);
+
+    if (attachToParent) {
+      parentNode.setChild(nodeName, child);
+    }
+    return child;
+  }
+
   @Override
   public void close() throws IOException {
     multiLock.lock();
@@ -444,33 +454,39 @@ public class SimDistribStateManager implements DistribStateManager {
     if ((CreateMode.EPHEMERAL == mode || CreateMode.PERSISTENT == mode) && hasData(path)) {
       throw new AlreadyExistsException(path);
     }
-    // check if parent exists
+
     String relPath = path.charAt(0) == '/' ? path.substring(1) : path;
-    if (relPath.length() > 0) { // non-root path - check if parent exists
-      String[] elements = relPath.split("/");
-      StringBuilder sb = new StringBuilder();
-      for (int i = 0; i < elements.length - 1; i++) {
-        sb.append('/');
-        sb.append(elements[i]);
-      }
-      if (!hasData(sb.toString())) {
-        throw new NoSuchElementException(sb.toString());
-      }
+    if (relPath.length() == 0) {
+      // TODO should trying to create a root node throw an exception since its always init'd in the ctor?
+      return null;
     }
-    Node n = null;
-    multiLock.lock();
-    try {
-      n = traverse(path, true, mode);
-    } finally {
-      multiLock.unlock();
+
+    // non-root-node.  Make sure parent exists.
+    String[] elements = relPath.split("/");
+    StringBuilder parentStringBuilder = new StringBuilder();
+    for (int i = 0; i < elements.length - 1; i++) {
+      parentStringBuilder.append('/');
+      parentStringBuilder.append(elements[i]);
+    }
+    if (!hasData(parentStringBuilder.toString())) {
+      throw new NoSuchElementException(parentStringBuilder.toString());
     }
+
+    multiLock.lock();
     try {
-      n.setData(data, -1);
-      return n.path;
+      String nodeName = elements[elements.length-1];
+      Node parentNode = traverse(parentStringBuilder.toString(), false, mode);
+      Node childNode = createNode(parentNode, mode, parentStringBuilder.append("/"), nodeName, false);
+      childNode.setData(data, -1);
+      parentNode.setChild(childNode.name, childNode);
+      return childNode.path;
     } catch (BadVersionException e) {
       // not happening
       return null;
+    } finally {
+      multiLock.unlock();
     }
+
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b072a7d2/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimGenericDistributedQueue.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimGenericDistributedQueue.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimGenericDistributedQueue.java
index 68c37a4..1ff6d12 100644
--- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimGenericDistributedQueue.java
+++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimGenericDistributedQueue.java
@@ -16,15 +16,12 @@
  */
 package org.apache.solr.cloud.autoscaling.sim;
 
-import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
-
 import org.apache.solr.client.solrj.cloud.DistributedQueue;
 import org.apache.solr.client.solrj.cloud.DistribStateManager;
 
 /**
  *
  */
-@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-13037")
 public class TestSimGenericDistributedQueue extends TestSimDistributedQueue {
   DistribStateManager stateManager = new SimDistribStateManager();