We pass around the instanceId a lot in Accumulo, and the vast majority of the time, it's just so we can pass it as part of the path to a ZooKeeper object that is already constructed. We can avoid a lot of this, and simplify the code quite a bit if we just construct the ZooKeeper object using the instanceId as part of the connection string, so all absolute paths are then relative to the instanceId directory, similar to one might do with chroot.
Here's an example of what the code change would look like:
// the current way
var directZK = new ZooKeeper(zookeepers, 200, null);
directZK.getChildren(Constants.ZROOT + "/" + instanceId + Constants.ZNAMESPACES, false)
.forEach(System.out::println);
// the better way
var chrootZK = new ZooKeeper(zookeepers + Constants.ZROOT + "/" + instanceId, 200, null);
chrootZK.getChildren(Constants.ZNAMESPACES, false).forEach(System.out::println);
We still need to connect without the instanceId when we look up the instanceId from the instance name (which is needed on the client side), but in all other cases, we don't need it.
This issue was originally described at https://issues.apache.org/jira/browse/ACCUMULO-4407
We pass around the instanceId a lot in Accumulo, and the vast majority of the time, it's just so we can pass it as part of the path to a ZooKeeper object that is already constructed. We can avoid a lot of this, and simplify the code quite a bit if we just construct the ZooKeeper object using the instanceId as part of the connection string, so all absolute paths are then relative to the instanceId directory, similar to one might do with
chroot
.Here's an example of what the code change would look like:
We still need to connect without the instanceId when we look up the instanceId from the instance name (which is needed on the client side), but in all other cases, we don't need it.