mirror of https://github.com/apache/lucene.git
SOLR-13037: Harden TestSimGenericDistributedQueue
This commit is contained in:
parent
81dbad54e0
commit
d7ad2f46c3
|
@ -311,17 +311,7 @@ public class SimDistribStateManager implements DistribStateManager {
|
||||||
n = parentNode.children != null ? parentNode.children.get(currentName) : null;
|
n = parentNode.children != null ? parentNode.children.get(currentName) : null;
|
||||||
if (n == null) {
|
if (n == null) {
|
||||||
if (create) {
|
if (create) {
|
||||||
if ((parentNode.mode == CreateMode.EPHEMERAL || parentNode.mode == CreateMode.EPHEMERAL_SEQUENTIAL) &&
|
n = createNode(parentNode, mode, currentPath, currentName,true);
|
||||||
(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);
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -333,6 +323,26 @@ public class SimDistribStateManager implements DistribStateManager {
|
||||||
return n;
|
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
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
multiLock.lock();
|
multiLock.lock();
|
||||||
|
@ -444,33 +454,39 @@ public class SimDistribStateManager implements DistribStateManager {
|
||||||
if ((CreateMode.EPHEMERAL == mode || CreateMode.PERSISTENT == mode) && hasData(path)) {
|
if ((CreateMode.EPHEMERAL == mode || CreateMode.PERSISTENT == mode) && hasData(path)) {
|
||||||
throw new AlreadyExistsException(path);
|
throw new AlreadyExistsException(path);
|
||||||
}
|
}
|
||||||
// check if parent exists
|
|
||||||
String relPath = path.charAt(0) == '/' ? path.substring(1) : path;
|
String relPath = path.charAt(0) == '/' ? path.substring(1) : path;
|
||||||
if (relPath.length() > 0) { // non-root path - check if parent exists
|
if (relPath.length() == 0) {
|
||||||
String[] elements = relPath.split("/");
|
// TODO should trying to create a root node throw an exception since its always init'd in the ctor?
|
||||||
StringBuilder sb = new StringBuilder();
|
return null;
|
||||||
for (int i = 0; i < elements.length - 1; i++) {
|
|
||||||
sb.append('/');
|
|
||||||
sb.append(elements[i]);
|
|
||||||
}
|
|
||||||
if (!hasData(sb.toString())) {
|
|
||||||
throw new NoSuchElementException(sb.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Node n = null;
|
|
||||||
|
// 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();
|
multiLock.lock();
|
||||||
try {
|
try {
|
||||||
n = traverse(path, true, mode);
|
String nodeName = elements[elements.length-1];
|
||||||
} finally {
|
Node parentNode = traverse(parentStringBuilder.toString(), false, mode);
|
||||||
multiLock.unlock();
|
Node childNode = createNode(parentNode, mode, parentStringBuilder.append("/"), nodeName, false);
|
||||||
}
|
childNode.setData(data, -1);
|
||||||
try {
|
parentNode.setChild(childNode.name, childNode);
|
||||||
n.setData(data, -1);
|
return childNode.path;
|
||||||
return n.path;
|
|
||||||
} catch (BadVersionException e) {
|
} catch (BadVersionException e) {
|
||||||
// not happening
|
// not happening
|
||||||
return null;
|
return null;
|
||||||
|
} finally {
|
||||||
|
multiLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,15 +16,12 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.cloud.autoscaling.sim;
|
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.DistributedQueue;
|
||||||
import org.apache.solr.client.solrj.cloud.DistribStateManager;
|
import org.apache.solr.client.solrj.cloud.DistribStateManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-13037")
|
|
||||||
public class TestSimGenericDistributedQueue extends TestSimDistributedQueue {
|
public class TestSimGenericDistributedQueue extends TestSimDistributedQueue {
|
||||||
DistribStateManager stateManager = new SimDistribStateManager();
|
DistribStateManager stateManager = new SimDistribStateManager();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue