在不停机的情况下,实现集群之间数据迁移代码:
1 private void create(ZooKeeper zk1, ZooKeeper zk2, String path) throws Exception { 2 List<String> list = zk1.getChildren(path, null); 3 for (String str : list) { 4 if (path.endsWith("/")) { 5 } else { 6 path = path + "/"; 7 } 8 System.out.println(path + str); 9 zk2.create("/wapage_back" + path + str, zk1.getData(path+str, false, null), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); 10 create(zk1, zk2, path + str); 11 } 12 if (!path.endsWith("/")) zk2.setData("/wapage_back" + path, zk1.getData(path, false, null), -1); 13 }
时间: 2024-11-06 07:21:00