if (!needCreate[i])
continue;
String path = paths.get(i);
T record = records == null ? null : records.get(i);
cbList[i] = new CreateCallbackHandler();
_zkClient.asyncCreate(path, record, mode, cbList[i]);
}
List<String> parentPaths =
new ArrayList<String>(Collections.<String> nCopies(paths.size(), null));
boolean failOnNoNode = false;
for (int i = 0; i < paths.size(); i++) {
if (!needCreate[i])
continue;
CreateCallbackHandler cb = cbList[i];
cb.waitForSuccess();
String path = paths.get(i);
if (Code.get(cb.getRc()) == Code.NONODE) {
String parentPath = HelixUtil.getZkParentPath(path);
parentPaths.set(i, parentPath);
failOnNoNode = true;
} else {
// if create succeed or fail on error other than NONODE,
// give up
needCreate[i] = false;
// if succeeds, record what paths we've created
if (Code.get(cb.getRc()) == Code.OK && pathsCreated != null) {
if (pathsCreated.get(i) == null) {
pathsCreated.set(i, new ArrayList<String>());
}
pathsCreated.get(i).add(path);
}
}
}
if (failOnNoNode) {
boolean[] needCreateParent = Arrays.copyOf(needCreate, needCreate.length);
CreateCallbackHandler[] parentCbList =
create(parentPaths, null, needCreateParent, pathsCreated, AccessOption.PERSISTENT);
for (int i = 0; i < parentCbList.length; i++) {
CreateCallbackHandler parentCb = parentCbList[i];
if (parentCb == null)
continue;
Code rc = Code.get(parentCb.getRc());
// if parent is created, retry create child
if (rc == Code.OK || rc == Code.NODEEXISTS) {
retry = true;
break;