本文整理了Java中org.apache.accumulo.server.zookeeper.ZooReaderWriter
类的一些代码示例,展示了ZooReaderWriter
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooReaderWriter
类的具体详情如下:
包路径:org.apache.accumulo.server.zookeeper.ZooReaderWriter
类名称:ZooReaderWriter
暂无
代码示例来源:origin: org.apache.accumulo/accumulo-server
public static boolean setTableProperty(String tableId, String property, String value) throws KeeperException, InterruptedException {
if (!isPropertyValid(property, value))
return false;
// create the zk node for per-table properties for this table if it doesn't already exist
String zkTablePath = getTablePath(tableId);
ZooReaderWriter.getInstance().putPersistentData(zkTablePath, new byte[0], NodeExistsPolicy.SKIP);
// create the zk node for this property and set it's data to the specified value
String zPath = zkTablePath + "/" + property;
ZooReaderWriter.getInstance().putPersistentData(zPath, value.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE);
return true;
}
代码示例来源:origin: org.apache.accumulo/accumulo-tserver
long getCompactionCancelID() {
String zTablePath = Constants.ZROOT + "/" + tabletServer.getInstance().getInstanceID()
+ Constants.ZTABLES + "/" + extent.getTableId() + Constants.ZTABLE_COMPACT_CANCEL_ID;
try {
return Long
.parseLong(new String(ZooReaderWriter.getInstance().getData(zTablePath, null), UTF_8));
} catch (KeeperException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.apache.accumulo/accumulo-server
@Override
public void run() {
try {
// Initially set the logger if the Monitor's log4j advertisement node exists
if (ZooReaderWriter.getInstance().exists(path, this))
updateMonitorLog4jLocation();
log.info("Set watch for Monitor Log4j watcher");
} catch (Exception e) {
log.error("Unable to set watch for Monitor Log4j watcher on " + path);
}
super.run();
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
/**
* Ensure that the full path to ZooKeeper nodes that will be used exist
*/
public static void ensureZooKeeperInitialized(final ZooReaderWriter zooReaderWriter,
final String zRoot) throws KeeperException, InterruptedException {
if (!zooReaderWriter.exists(zRoot + ReplicationConstants.ZOO_TSERVERS, null)) {
zooReaderWriter.mkdirs(zRoot + ReplicationConstants.ZOO_TSERVERS);
}
if (!zooReaderWriter.exists(zRoot + ReplicationConstants.ZOO_WORK_QUEUE, null)) {
zooReaderWriter.mkdirs(zRoot + ReplicationConstants.ZOO_WORK_QUEUE);
}
}
}
代码示例来源:origin: org.apache.accumulo/accumulo-server
public void addWork(String workId, byte[] data) throws KeeperException, InterruptedException {
if (workId.equalsIgnoreCase(LOCKS_NODE))
throw new IllegalArgumentException("locks is reserved work id");
zoo.mkdirs(path);
zoo.putPersistentData(path + "/" + workId, data, NodeExistsPolicy.SKIP);
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
public void removeNamespace(String namespaceId) throws KeeperException, InterruptedException {
ZooReaderWriter.getInstance().recursiveDelete(
ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/" + namespaceId,
NodeMissingPolicy.SKIP);
}
代码示例来源:origin: org.apache.accumulo/accumulo-server
public MergeInfo getMergeInfo(Text tableId) {
synchronized (mergeLock) {
try {
String path = ZooUtil.getRoot(instance.getInstanceID()) + Constants.ZTABLES + "/" + tableId.toString() + "/merge";
if (!ZooReaderWriter.getInstance().exists(path))
return new MergeInfo();
byte[] data = ZooReaderWriter.getInstance().getData(path, new Stat());
DataInputBuffer in = new DataInputBuffer();
in.reset(data, data.length);
MergeInfo info = new MergeInfo();
info.readFields(in);
return info;
} catch (KeeperException.NoNodeException ex) {
log.info("Error reading merge state, it probably just finished");
return new MergeInfo();
} catch (Exception ex) {
log.warn("Unexpected error reading merge state", ex);
return new MergeInfo();
}
}
}
代码示例来源:origin: org.apache.accumulo/accumulo-server
ZooReaderWriter zoo = ZooReaderWriter.getInstance();
if (zoo.exists(monitorPath)) {
byte[] data = zoo.getData(monitorPath, null);
zoo.recursiveDelete(monitorPath, NodeMissingPolicy.SKIP);
zoo.putPersistentData(monitorPath, new byte[0], NodeExistsPolicy.FAIL);
zoo.putPersistentData(monitorLockPath, new byte[0], NodeExistsPolicy.FAIL);
} else if (!zoo.exists(monitorLockPath)) {
zoo.putPersistentData(monitorLockPath, new byte[0], NodeExistsPolicy.FAIL);
zoo.putPersistentData(zRoot + Constants.ZMONITOR, new byte[0], NodeExistsPolicy.FAIL);
if (!zoo.exists(monitorLockPath)) {
zoo.putPersistentData(monitorLockPath, new byte[0], NodeExistsPolicy.FAIL);
代码示例来源:origin: org.apache.accumulo/accumulo-server
private static GCStatus fetchGcStatus() {
GCStatus result = null;
InetSocketAddress address = null;
try {
// Read the gc location from its lock
ZooReaderWriter zk = ZooReaderWriter.getInstance();
String path = ZooUtil.getRoot(instance) + Constants.ZGC_LOCK;
List<String> locks = zk.getChildren(path, null);
if (locks != null && locks.size() > 0) {
Collections.sort(locks);
address = new ServerServices(new String(zk.getData(path + "/" + locks.get(0), null), UTF_8)).getAddress(Service.GC_CLIENT);
GCMonitorService.Client client = ThriftUtil.getClient(new GCMonitorService.Client.Factory(), address, config.getConfiguration());
try {
result = client.getStatus(Tracer.traceInfo(), SecurityConstants.getSystemCredentials());
} finally {
ThriftUtil.returnClient(client);
}
}
} catch (Exception ex) {
log.warn("Unable to contact the garbage collector at " + address, ex);
}
return result;
}
代码示例来源:origin: org.apache.accumulo/accumulo-server
public void setMergeState(MergeInfo info, MergeState state) throws IOException, KeeperException, InterruptedException {
synchronized (mergeLock) {
String path = ZooUtil.getRoot(instance.getInstanceID()) + Constants.ZTABLES + "/" + info.getRange().getTableId().toString() + "/merge";
info.setState(state);
if (state.equals(MergeState.NONE)) {
ZooReaderWriter.getInstance().recursiveDelete(path, NodeMissingPolicy.SKIP);
} else {
DataOutputBuffer out = new DataOutputBuffer();
try {
info.write(out);
} catch (IOException ex) {
throw new RuntimeException("Unlikely", ex);
}
ZooReaderWriter.getInstance().putPersistentData(path, out.getData(),
state.equals(MergeState.STARTED) ? ZooUtil.NodeExistsPolicy.FAIL : ZooUtil.NodeExistsPolicy.OVERWRITE);
}
mergeLock.notifyAll();
}
nextEvent.event("Merge state of %s set to %s", info.getRange(), state);
}
代码示例来源:origin: org.apache.accumulo/accumulo-master
public MasterTime(Master master) throws IOException {
this.zPath = ZooUtil.getRoot(master.getInstance()) + Constants.ZMASTER_TICK;
this.zk = ZooReaderWriter.getInstance();
this.master = master;
try {
zk.putPersistentData(zPath, "0".getBytes(StandardCharsets.UTF_8), NodeExistsPolicy.SKIP);
skewAmount = Long.parseLong(new String(zk.getData(zPath, null), StandardCharsets.UTF_8))
- System.nanoTime();
} catch (Exception ex) {
throw new IOException("Error updating master time", ex);
}
this.timer = new Timer();
timer.schedule(this, 0, MILLISECONDS.convert(10, SECONDS));
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
public DeadServerList(String path) {
this.path = path;
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
try {
zoo.mkdirs(path);
} catch (Exception ex) {
log.error("Unable to make parent directories of " + path, ex);
}
}
代码示例来源:origin: org.apache.accumulo/accumulo-server
@Override
public void process(WatchedEvent event) {
nextEvent.event("Noticed recovery changes", event.getType());
try {
// watcher only fires once, add it back
ZooReaderWriter.getInstance().getChildren(zroot + Constants.ZRECOVERY, this);
} catch (Exception e) {
log.error("Failed to add log recovery watcher back", e);
}
}
});
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
@Override
public boolean hasSystemPermission(String user, SystemPermission permission)
throws AccumuloSecurityException {
byte[] perms;
try {
String path = ZKUserPath + "/" + user + ZKUserSysPerms;
ZooReaderWriter.getInstance().sync(path);
perms = ZooReaderWriter.getInstance().getData(path, null);
} catch (KeeperException e) {
if (e.code() == Code.NONODE) {
return false;
}
log.warn("Unhandled KeeperException, failing closed for table permission check", e);
return false;
} catch (InterruptedException e) {
log.warn("Unhandled InterruptedException, failing closed for table permission check", e);
return false;
}
if (perms == null)
return false;
return ZKSecurityTool.convertSystemPermissions(perms).contains(permission);
}
代码示例来源:origin: org.apache.accumulo/accumulo-server
try {
try {
processor.newProcessor().process(child, zoo.getData(childPath, null));
zoo.recursiveDelete(childPath, NodeMissingPolicy.SKIP);
} catch (Exception e) {
log.error("Error received when trying to delete entry in zookeeper " + childPath, e);
zoo.recursiveDelete(lockPath, NodeMissingPolicy.SKIP);
} catch (Exception e) {
log.error("Error received when trying to delete entry in zookeeper " + childPath, e);
lookForWork(processor, zoo.getChildren(path));
} catch (KeeperException e) {
log.error("Failed to look for work", e);
代码示例来源:origin: org.apache.accumulo/accumulo-test
Instance instance = conn.getInstance();
ZooReaderWriter zk = new ZooReaderWriter(cluster.getZooKeepers(), 30000, OUR_SECRET);
String path = ZooUtil.getRoot(instance) + Constants.ZGC_LOCK;
for (int i = 0; i < 5; i++) {
List<String> locks;
try {
locks = zk.getChildren(path, null);
} catch (NoNodeException e) {
Thread.sleep(5000);
String gcLoc = new String(zk.getData(lockPath, null));
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
public void cloneTable(String srcTable, String tableId, String tableName, String namespaceId,
Map<String,String> propertiesToSet, Set<String> propertiesToExclude,
NodeExistsPolicy existsPolicy) throws KeeperException, InterruptedException {
prepareNewTableState(instance.getInstanceID(), tableId, namespaceId, tableName, TableState.NEW,
existsPolicy);
String srcTablePath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES + "/"
+ srcTable + Constants.ZTABLE_CONF;
String newTablePath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES + "/"
+ tableId + Constants.ZTABLE_CONF;
ZooReaderWriter.getInstance().recursiveCopyPersistent(srcTablePath, newTablePath,
NodeExistsPolicy.OVERWRITE);
for (Entry<String,String> entry : propertiesToSet.entrySet())
TablePropUtil.setTableProperty(tableId, entry.getKey(), entry.getValue());
for (String prop : propertiesToExclude)
ZooReaderWriter.getInstance().recursiveDelete(Constants.ZROOT + "/" + instance.getInstanceID()
+ Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_CONF + "/" + prop,
NodeMissingPolicy.SKIP);
updateTableStateCache(tableId);
}
代码示例来源:origin: org.apache.accumulo/accumulo-server
@Override
public void run() {
try {
lookForWork(processor, zoo.getChildren(path));
} catch (KeeperException e) {
log.error("Failed to look for work", e);
} catch (InterruptedException e) {
log.info("Interrupted looking for work", e);
}
}
}, r.nextInt(60 * 1000), 60 * 1000);
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
public List<Path> getWalsInUse(TServerInstance tsi) throws WalMarkerException {
List<Path> result = new ArrayList<>();
try {
String zpath = root() + "/" + tsi.toString();
zoo.sync(zpath);
for (String child : zoo.getChildren(zpath)) {
Pair<WalState,Path> parts = parse(zoo.getData(zpath + "/" + child, null));
if (parts.getFirst() != WalState.UNREFERENCED) {
result.add(parts.getSecond());
}
}
} catch (KeeperException.NoNodeException e) {
log.debug("{} has no wal entry in zookeeper, assuming no logs", tsi);
} catch (KeeperException | InterruptedException e) {
throw new WalMarkerException(e);
}
return result;
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
private String root() throws WalMarkerException {
String root = ZooUtil.getRoot(instance) + ZWALS;
try {
if (!checkedExistance && !zoo.exists(root)) {
zoo.putPersistentData(root, new byte[0], NodeExistsPolicy.SKIP);
}
checkedExistance = true;
} catch (KeeperException | InterruptedException e) {
throw new WalMarkerException(e);
}
return root;
}
内容来源于网络,如有侵权,请联系作者删除!