Source:
<code>public static void updateCatalogToZK(ZooKeeper zk, int version, long genId, SegmentedCatalog catalogAndDeployment, ZKCatalogStatus catalogStatus, long txnId) throws KeeperException, InterruptedException { assert (catalogAndDeployment != null); makeCatalogHeader(catalogAndDeployment, version, genId); String path = VoltZK.catalogbytes + "/" + version; ByteBuffer buffer = ByteBuffer.allocate(13); buffer.put((byte)ZKCatalogStatus.PENDING.ordinal()); buffer.putInt(catalogAndDeployment.m_data.size()); buffer.putLong(txnId); Stat stat = null; try { zk.create(path, buffer.array(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException e) { stat = zk.exists(path, false); stat = zk.setData(path, buffer.array(), stat.getVersion()); List<String> children = zk.getChildren(path, false); for (String child : children) { ZKUtil.deleteRecursively(zk, ZKUtil.joinZKPath(path, child)); <START> } <END> } for (ByteBuffer chunk : catalogAndDeployment.m_data) { zk.create(ZKUtil.joinZKPath(path, "part_"), chunk.array(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); } if (catalogStatus == ZKCatalogStatus.COMPLETE) { buffer.position(0); buffer.put((byte)catalogStatus.ordinal()); zk.setData(path, buffer.array(), stat == null ? -1 : stat.getVersion()); List<String> children = zk.getChildren(VoltZK.catalogbytes, false); for (String child : children) { int priorVersion = Integer.parseInt(child); if (priorVersion < version) { hostLog.info("***deleting " + ZKUtil.joinZKPath(VoltZK.catalogbytes, child)); ZKUtil.deleteRecursively(zk, ZKUtil.joinZKPath(VoltZK.catalogbytes, child)); } } } }</code><technical_language>Is expectedNodeCount needed updated here? If transaction is restarted node failure, expectedNodeCount updated</technical_language>

Target:
public static void updateCatalogToZK(ZooKeeper zk, int version, long genId, SegmentedCatalog catalogAndDeployment, ZKCatalogStatus catalogStatus, long txnId) throws KeeperException, InterruptedException { assert (catalogAndDeployment != null); makeCatalogHeader(catalogAndDeployment, version, genId); String path = VoltZK.catalogbytes + "/" + version; ByteBuffer buffer = ByteBuffer.allocate(13); buffer.put((byte)ZKCatalogStatus.PENDING.ordinal()); buffer.putInt(catalogAndDeployment.m_data.size()); buffer.putLong(txnId); Stat stat = null; try { zk.create(path, buffer.array(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException e) { stat = zk.exists(path, false); stat = zk.setData(path, buffer.array(), stat.getVersion()); List<String> children = zk.getChildren(path, false); for (String child : children) { ZKUtil.deleteRecursively(zk, ZKUtil.joinZKPath(path, child)); } } for (ByteBuffer chunk : catalogAndDeployment.m_data) { zk.create(ZKUtil.joinZKPath(path, "part_"), chunk.array(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); } if (catalogStatus == ZKCatalogStatus.COMPLETE) { buffer.position(0); buffer.put((byte)catalogStatus.ordinal()); zk.setData(path, buffer.array(), stat == null ? -1 : stat.getVersion()); List<String> children = zk.getChildren(VoltZK.catalogbytes, false); for (String child : children) { int priorVersion = Integer.parseInt(child); if (priorVersion < version) { ZKUtil.deleteRecursively(zk, ZKUtil.joinZKPath(VoltZK.catalogbytes, child)); } } } }