List of usage examples for org.apache.zookeeper Op delete
public static Op delete(String path, int version)
From source file:com.navercorp.nbasearc.confmaster.repository.dao.zookeeper.ZkClusterDao.java
License:Apache License
@Override public void deleteCluster(String name) throws MgmtZNodeDoesNotExistException, MgmtZooKeeperException { String path = PathUtil.clusterPath(name); List<Op> ops = new ArrayList<Op>(); ops.add(Op.delete(PathUtil.pgRootPath(name), -1)); ops.add(Op.delete(PathUtil.pgsRootPath(name), -1)); ops.add(Op.delete(PathUtil.gwRootPath(name), -1)); ops.add(Op.delete(PathUtil.rsRootPath(name), -1)); if (zookeeper.isExists(PathUtil.clusterBackupSchedulePath(name))) { ops.add(Op.delete(PathUtil.clusterBackupSchedulePath(name), -1)); }//www . ja v a 2s . c o m ops.add(Op.delete(path, -1)); notificationDao.addDeleteClusterOp(ops, name); List<OpResult> results = zookeeper.multi(ops); zookeeper.handleResultsOfMulti(results); }
From source file:com.navercorp.nbasearc.confmaster.repository.dao.zookeeper.ZkGatewayDao.java
License:Apache License
@Override public void deleteGw(final String name, final String clusterName, PhysicalMachineCluster pmCluster) throws MgmtZooKeeperException, MgmtZNodeDoesNotExistException { String path = PathUtil.gwPath(name, clusterName); List<Op> ops = new ArrayList<Op>(); List<String> children = zookeeper.getChildren(path); for (String childName : children) { StringBuilder builder = new StringBuilder(path); builder.append("/").append(childName); String childPath = builder.toString(); ops.add(Op.delete(childPath, -1)); }// ww w . j a va2 s .c o m ops.add(Op.delete(path, -1)); PmClusterData pmClusterDataClone = (PmClusterData) pmCluster.getData().clone(); pmClusterDataClone.deleteGwId(Integer.valueOf(name)); byte cimDataOfBytes[] = mapper.writeValueAsBytes(pmClusterDataClone); ops.add(Op.setData(pmCluster.getPath(), cimDataOfBytes, -1)); if (pmClusterDataClone.getPgsIdList().isEmpty() && pmClusterDataClone.getGwIdList().isEmpty()) { ops.add(Op.delete(pmCluster.getPath(), -1)); } if (notificationDao.isGatewayExist(clusterName, name)) { notificationDao.addDeleteGatewayOp(ops, clusterName, name); } List<OpResult> results = zookeeper.multi(ops); zookeeper.handleResultsOfMulti(results); }
From source file:com.navercorp.nbasearc.confmaster.repository.dao.zookeeper.ZkNotificationDao.java
License:Apache License
@Override public void addDeleteClusterOp(List<Op> ops, String clusterName) throws MgmtZNodeDoesNotExistException, MgmtZooKeeperException { String path = pathOfCluster(clusterName); boolean exist = zookeeper.isExists(path); if (!exist) { throw new MgmtZNodeDoesNotExistException(path, String .format("-ERR the cluster znode for notification does not exist. cluster:%s.", clusterName)); }/* ww w . ja va 2 s.c om*/ ops.add(Op.delete(pathOfGWAffinity(clusterName), -1)); ops.add(Op.delete(rootPathOfGateway(clusterName), -1)); ops.add(Op.delete(path, -1)); }
From source file:com.navercorp.nbasearc.confmaster.repository.dao.zookeeper.ZkNotificationDao.java
License:Apache License
@Override public void addDeleteGatewayOp(List<Op> ops, String clusterName, String gatewayName) throws MgmtZNodeDoesNotExistException, MgmtZooKeeperException { String clusterPath = pathOfCluster(clusterName); boolean exist = zookeeper.isExists(clusterPath); if (!exist) { throw new MgmtZNodeDoesNotExistException(clusterPath, String.format("-ERR the cluster znode for notification does not exist. cluster:%s, gateway:%s", clusterName, gatewayName)); }//from w ww . j a v a 2s .c o m String gatewayPath = pathOfGateway(clusterName, gatewayName); exist = zookeeper.isExists(gatewayPath); if (!exist) { throw new MgmtZNodeDoesNotExistException(gatewayPath, String.format("-ERR the gateway znode for notification does not exist. cluster:%s, gateway:%s", clusterName, gatewayName)); } ops.add(Op.delete(gatewayPath, -1)); }
From source file:com.navercorp.nbasearc.confmaster.repository.dao.zookeeper.ZkPartitionGroupServerDao.java
License:Apache License
/** * //from w w w.j a v a 2 s .c om * SUBJECT * Q. Why deletePgs() method uses for-loop statement? * A. Due to the synchronization problem for creating or deleting opinions * with pgs_leave and pgs_del * * SCENARIO (remove an opinion) * * PGS * / \ OP1 : Leader's * / \ OP2 : Follower's * OP1 OP2 * * LEADER FOLLOWER * 1. pgs_leave * 2. pgs_del get a watch event of pgs_leave * 2.1. get children of PGS z-node. * 2.2. delete an opinion, OP2 * F 2.3. (fail) delete the children. * * SCENARIO (put an opinion) * * PGS * / OP1 : Leader's * / * OP1 * * LEADER FOLLOWER * 1. pgs_leave * 2. pgs_del * 2.1. get children of PGS z-node. * 2.2. put an opinion, OP2 * 2.3. delete the children. * PGS * \ * \ OP2 : Follower's * OP2 * F 2.4. (fail) delete the PGS z-node. * 2.5. get a watch event of pgs_leave * * But, eventually good things will happen. * * @Return Returns the number of retries if successful. */ @Override public int deletePgs(String name, String clusterName, PartitionGroup pg, PhysicalMachineCluster pmCluster) throws MgmtZooKeeperException { final String path = PathUtil.pgsPath(name, clusterName); final String pathForRs = PathUtil.rsPath(name, clusterName); final int MAX = config.getServerCommandPgsdelMaxretry(); int retryCnt; for (retryCnt = 1; retryCnt <= MAX; retryCnt++) { // Delete children(opinions) of PGS try { zookeeper.deleteChildren(path); } catch (MgmtZooKeeperException e) { if (e.getCause() instanceof KeeperException.NoNodeException && retryCnt != MAX) { // Retry Logger.info("Delete children of {} fail. retry {}", PartitionGroupServer.fullName(clusterName, name), retryCnt, e); continue; } else { throw e; } } // Delete children(opinions) of RS try { zookeeper.deleteChildren(pathForRs); } catch (MgmtZooKeeperException e) { if (e.getCause() instanceof KeeperException.NoNodeException && retryCnt != MAX) { // Retry Logger.info("Delete children of {} fail. retry {}", RedisServer.fullName(clusterName, name), retryCnt, e); continue; } else { throw e; } } // Delete PGS and RS & Update PG List<Op> ops = new ArrayList<Op>(); ops.add(Op.delete(path, -1)); ops.add(Op.delete(pathForRs, -1)); PmClusterData cimData = (PmClusterData) pmCluster.getData().clone(); cimData.deletePgsId(Integer.valueOf(name)); byte cimDataOfBytes[] = mapper.writeValueAsBytes(cimData); ops.add(Op.setData(pmCluster.getPath(), cimDataOfBytes, -1)); PartitionGroupData pgModified = PartitionGroupData.builder().from(pg.getData()) .deletePgsId(Integer.parseInt(name)).build(); byte pgDataOfBytes[] = mapper.writeValueAsBytes(pgModified); ops.add(Op.setData(pg.getPath(), pgDataOfBytes, -1)); if (cimData.getPgsIdList().isEmpty() && cimData.getGwIdList().isEmpty()) { ops.add(Op.delete(pmCluster.getPath(), -1)); } try { List<OpResult> results = zookeeper.multi(ops); zookeeper.handleResultsOfMulti(results); return retryCnt; } catch (MgmtZooKeeperException e) { if (e.getCause() instanceof KeeperException.NotEmptyException && retryCnt != MAX) { // Retry Logger.info("Delete {} fail. retry {}", PartitionGroupServer.fullName(clusterName, name), retryCnt, e); } else { throw e; } } } return retryCnt; }
From source file:com.navercorp.nbasearc.confmaster.server.cluster.GatewayLookup.java
License:Apache License
public void addDeleteClusterOp(List<Op> ops, String clusterName) throws MgmtZNodeDoesNotExistException, MgmtZooKeeperException { String path = PathUtil.pathOfGwLookupCluster(clusterName); boolean exist = zk.isExists(path); if (!exist) { throw new MgmtZNodeDoesNotExistException(path, String .format("-ERR the cluster znode for notification does not exist. cluster:%s.", clusterName)); }/*w ww.j av a 2 s .c om*/ ops.add(Op.delete(PathUtil.pathOfGwAffinity(clusterName), -1)); ops.add(Op.delete(PathUtil.rootPathOfGwLookup(clusterName), -1)); ops.add(Op.delete(path, -1)); }
From source file:com.navercorp.nbasearc.confmaster.server.cluster.GatewayLookup.java
License:Apache License
public void addDeleteGatewayOp(List<Op> ops, String clusterName, String gatewayName) throws MgmtZNodeDoesNotExistException, MgmtZooKeeperException { String clusterPath = PathUtil.pathOfGwLookupCluster(clusterName); boolean exist = zk.isExists(clusterPath); if (!exist) { throw new MgmtZNodeDoesNotExistException(clusterPath, String.format("-ERR the cluster znode for notification does not exist. cluster:%s, gateway:%s", clusterName, gatewayName)); }/*from ww w.ja v a 2 s . c o m*/ String gatewayPath = PathUtil.pathOfGwLookup(clusterName, gatewayName); exist = zk.isExists(gatewayPath); if (!exist) { throw new MgmtZNodeDoesNotExistException(gatewayPath, String.format("-ERR the gateway znode for notification does not exist. cluster:%s, gateway:%s", clusterName, gatewayName)); } ops.add(Op.delete(gatewayPath, -1)); }
From source file:com.navercorp.nbasearc.confmaster.server.command.ClusterService.java
License:Apache License
protected void deleteClusterobject(String clusterName) throws MgmtZNodeDoesNotExistException, MgmtZooKeeperException { List<PhysicalMachine> pmList = container.getAllPm(); for (PhysicalMachine pm : pmList) { PhysicalMachineCluster clusterInPm = container.getPmc(pm.getName(), clusterName); if (null == clusterInPm) { continue; }/*from w w w .ja va2 s. co m*/ if (!clusterInPm.getGwIdList().isEmpty()) { throw new IllegalArgumentException(EXCEPTIONMSG_CLUSTER_HAS_GW + Cluster.fullName(clusterName)); } if (!clusterInPm.getPgsIdList().isEmpty()) { throw new IllegalArgumentException(EXCEPTIONMSG_CLUSTER_HAS_PGS + Cluster.fullName(clusterName)); } } // DB String path = PathUtil.clusterPath(clusterName); List<Op> ops = new ArrayList<Op>(); ops.add(Op.delete(PathUtil.pgRootPath(clusterName), -1)); ops.add(Op.delete(PathUtil.pgsRootPath(clusterName), -1)); ops.add(Op.delete(PathUtil.gwRootPath(clusterName), -1)); ops.add(Op.delete(PathUtil.rsRootPath(clusterName), -1)); if (zk.isExists(PathUtil.clusterBackupSchedulePath(clusterName))) { ops.add(Op.delete(PathUtil.clusterBackupSchedulePath(clusterName), -1)); } ops.add(Op.delete(path, -1)); gwInfoNoti.addDeleteClusterOp(ops, clusterName); List<OpResult> results = zk.multi(ops); zk.handleResultsOfMulti(results); // In Memory container.delete(PathUtil.clusterPath(clusterName)); }
From source file:com.navercorp.nbasearc.confmaster.server.command.GatewayService.java
License:Apache License
protected void deleteGwObject(String pmName, String clusterName, String gwId) throws MgmtZNodeDoesNotExistException, MgmtZooKeeperException { PhysicalMachineCluster pmCluster = container.getPmc(pmName, clusterName); if (null == pmCluster) { throw new IllegalArgumentException(EXCEPTIONMSG_PHYSICAL_MACHINE_CLUSTER_DOES_NOT_EXIST + PhysicalMachineCluster.fullName(pmName, clusterName)); }/*from www . j a v a2s.c om*/ // DB String path = PathUtil.gwPath(gwId, clusterName); List<Op> ops = new ArrayList<Op>(); List<String> children = zk.getChildren(path); for (String childName : children) { StringBuilder builder = new StringBuilder(path); builder.append("/").append(childName); String childPath = builder.toString(); ops.add(Op.delete(childPath, -1)); } ops.add(Op.delete(path, -1)); PhysicalMachineCluster.PmClusterData pmClusterDataClone = pmCluster.clonePersistentData(); pmClusterDataClone.deleteGwId(Integer.valueOf(gwId)); byte cimDataOfBytes[] = mapper.writeValueAsBytes(pmClusterDataClone); ops.add(Op.setData(pmCluster.getPath(), cimDataOfBytes, -1)); if (pmClusterDataClone.getPgsIdList().isEmpty() && pmClusterDataClone.getGwIdList().isEmpty()) { ops.add(Op.delete(pmCluster.getPath(), -1)); } if (gwInfoNotifier.isGatewayExist(clusterName, gwId)) { gwInfoNotifier.addDeleteGatewayOp(ops, clusterName, gwId); } List<OpResult> results = zk.multi(ops); zk.handleResultsOfMulti(results); // In Memory container.delete(PathUtil.gwPath(gwId, clusterName)); // Delete from pm-cluster pmCluster.deleteGwId(gwId); if (pmCluster.isEmpty()) { container.delete(PathUtil.pmClusterPath(clusterName, pmName)); } }
From source file:com.navercorp.nbasearc.confmaster.server.command.PartitionGroupServerService.java
License:Apache License
/** * /*from ww w. ja va2 s . c om*/ * SUBJECT * Q. Why deletePgs() method uses for-loop statement? * A. Due to the synchronization problem for creating or deleting opinions * with pgs_leave and pgs_del * * SCENARIO (remove an opinion) * * PGS * / \ OP1 : Leader's * / \ OP2 : Follower's * OP1 OP2 * * LEADER FOLLOWER * 1. pgs_leave * 2. pgs_del get a watch event of pgs_leave * 2.1. get children of PGS z-node. * 2.2. delete an opinion, OP2 * F 2.3. (fail) delete the children. * * SCENARIO (put an opinion) * * PGS * / OP1 : Leader's * / * OP1 * * LEADER FOLLOWER * 1. pgs_leave * 2. pgs_del * 2.1. get children of PGS z-node. * 2.2. put an opinion, OP2 * 2.3. delete the children. * PGS * \ * \ OP2 : Follower's * OP2 * F 2.4. (fail) delete the PGS z-node. * 2.5. get a watch event of pgs_leave * * But, eventually good things will happen. * * @Return Returns the number of retries if successful. */ protected int deletePgsZooKeeperNZnodes(String name, String clusterName, PartitionGroup pg, PhysicalMachineCluster pmCluster) throws MgmtZooKeeperException { final String path = PathUtil.pgsPath(name, clusterName); final String pathForRs = PathUtil.rsPath(name, clusterName); final int MAX = config.getServerCommandPgsdelMaxretry(); int retryCnt; for (retryCnt = 1; retryCnt <= MAX; retryCnt++) { // Delete children(opinions) of PGS try { zk.deleteChildren(path); } catch (MgmtZooKeeperException e) { if (e.getCause() instanceof KeeperException.NoNodeException && retryCnt != MAX) { // Retry Logger.info("Delete children of {} fail. retry {}", PartitionGroupServer.fullName(clusterName, name), retryCnt, e); continue; } else { throw e; } } // Delete children(opinions) of RS try { zk.deleteChildren(pathForRs); } catch (MgmtZooKeeperException e) { if (e.getCause() instanceof KeeperException.NoNodeException && retryCnt != MAX) { // Retry Logger.info("Delete children of {} fail. retry {}", RedisServer.fullName(clusterName, name), retryCnt, e); continue; } else { throw e; } } // Delete PGS and RS & Update PG List<Op> ops = new ArrayList<Op>(); ops.add(Op.delete(path, -1)); ops.add(Op.delete(pathForRs, -1)); PhysicalMachineCluster.PmClusterData cimData = pmCluster.clonePersistentData(); cimData.deletePgsId(Integer.valueOf(name)); byte cimDataOfBytes[] = mapper.writeValueAsBytes(cimData); ops.add(Op.setData(pmCluster.getPath(), cimDataOfBytes, -1)); PartitionGroup.PartitionGroupData pgModified = pg.clonePersistentData(); pgModified.deletePgsId(Integer.parseInt(name)); byte pgDataOfBytes[] = mapper.writeValueAsBytes(pgModified); ops.add(Op.setData(pg.getPath(), pgDataOfBytes, -1)); if (cimData.getPgsIdList().isEmpty() && cimData.getGwIdList().isEmpty()) { ops.add(Op.delete(pmCluster.getPath(), -1)); } try { List<OpResult> results = zk.multi(ops); zk.handleResultsOfMulti(results); return retryCnt; } catch (MgmtZooKeeperException e) { if (e.getCause() instanceof KeeperException.NotEmptyException && retryCnt != MAX) { // Retry Logger.info("Delete {} fail. retry {}", PartitionGroupServer.fullName(clusterName, name), retryCnt, e); } else { throw e; } } } return retryCnt; }