Skip to content

Instantly share code, notes, and snippets.

@soenkeliebau
Created January 3, 2022 16:30
Show Gist options
  • Save soenkeliebau/f6816461488983de2cbe2c974c674cef to your computer and use it in GitHub Desktop.
Save soenkeliebau/f6816461488983de2cbe2c974c674cef to your computer and use it in GitHub Desktop.
package tech.stackable;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
public class App {
public static void main(String[] args) throws IOException, InterruptedException {
String queuesznode = "/hbase/queue";
String queueId = "1";
String filename = "testfile";
long position = 10090;
Configuration conf = new Configuration();
conf.set("zookeeper.recovery.retry","10");
ZooKeeperWatcher zookeeper = new ZooKeeperWatcher(conf, "test", new TestAbortable(),true);
while (true) {
try {
String znode = ZKUtil.joinZNode(queuesznode, queueId);
znode = ZKUtil.joinZNode(znode, filename);
// Why serialize String of Long and not Long as bytes?
ZKUtil.setData(zookeeper, znode, ZKUtil.positionToByteArray(position));
System.out.println("successfully set data");
Thread.sleep(1000);
} catch (KeeperException e) {
System.out.println("got exception - aborting!");
e.printStackTrace();
System.exit(-1);
}
}
}
}
@soenkeliebau
Copy link
Author

This has been copied from https://github.com/apache/hbase/blob/7abb12be26115eda7341b82b9860990a14bc6040/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationQueuesZKImpl.java#L125 in order to enable running that code in isolation to facilitate testing of a production issue with HBase and ZooKeeper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment