在不停机的情况下,实现集群之间数据迁移代码:

 private void create(ZooKeeper zk1, ZooKeeper zk2, String path) throws Exception {
List<String> list = zk1.getChildren(path, null);
for (String str : list) {
if (path.endsWith("/")) {
} else {
path = path + "/";
}
System.out.println(path + str);
zk2.create("/wapage_back" + path + str, zk1.getData(path+str, false, null), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
create(zk1, zk2, path + str);
}
if (!path.endsWith("/")) zk2.setData("/wapage_back" + path, zk1.getData(path, false, null), -1);
}
04-30 06:20