下面列出了org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper#exists ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Deletes just the splice-specific paths in zookeeper. Does not delete hbase paths.
*/
public static void cleanZookeeper() throws InterruptedException, KeeperException{
RecoverableZooKeeper rzk=getRecoverableZooKeeper();
String rootPath=HConfiguration.getConfiguration().getSpliceRootPath();
for(String path : HConfiguration.zookeeperPaths){
path=rootPath+path;
if(rzk.exists(path,false)!=null){
for(String child : rzk.getChildren(path,false)){
for(String grandChild : rzk.getChildren(path+"/"+child,false)){
rzk.delete(path+"/"+child+"/"+grandChild,-1);
}
rzk.delete(path+"/"+child,-1);
}
rzk.delete(path,-1);
}
}
}
private void reportDiagnostics(String diagnostics) {
try {
RecoverableZooKeeper rzk = ZkUtils.getRecoverableZooKeeper();
String root = HConfiguration.getConfiguration().getSpliceRootPath();
String diagnosticsPath = root + HBaseConfiguration.OLAP_SERVER_PATH + HBaseConfiguration.OLAP_SERVER_DIAGNOSTICS_PATH + "/" + queueName;
if (rzk.exists(diagnosticsPath, false) != null) {
rzk.setData(diagnosticsPath, Bytes.toBytes(diagnostics), -1);
} else {
rzk.create(diagnosticsPath, Bytes.toBytes(diagnostics), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
} catch (Exception e) {
LOG.error("Exception while trying to report diagnostics", e);
// ignore this exception during error reporting
}
}
private void reportDiagnostics(String diagnostics) {
try {
RecoverableZooKeeper rzk = ZkUtils.getRecoverableZooKeeper();
String root = HConfiguration.getConfiguration().getSpliceRootPath();
String diagnosticsRoot = root + HBaseConfiguration.OLAP_SERVER_PATH + HBaseConfiguration.OLAP_SERVER_DIAGNOSTICS_PATH;
zkSafeCreate(diagnosticsRoot);
String diagnosticsPath = diagnosticsRoot + "/spark-" + queueName;
if (rzk.exists(diagnosticsPath, false) != null) {
rzk.setData(diagnosticsPath, com.splicemachine.primitives.Bytes.toBytes(diagnostics), -1);
} else {
rzk.create(diagnosticsPath, com.splicemachine.primitives.Bytes.toBytes(diagnostics), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
} catch (Exception e) {
LOG.error("Exception while trying to report diagnostics", e);
// ignore this exception during error reporting
}
}
public static boolean validZookeeper() throws InterruptedException, KeeperException{
RecoverableZooKeeper rzk=getRecoverableZooKeeper();
String rootPath=HConfiguration.getConfiguration().getSpliceRootPath();
for(String path : HConfiguration.zookeeperPaths){
if(rzk.exists(rootPath+path,false)==null)
return false;
}
return true;
}
public static boolean shouldCaptureIncrementalChanges(FileSystem fs,Path rootDir) throws StandardException{
boolean shouldRegister = false;
try {
boolean enabled = incrementalBackupEnabled();
if (enabled) {
RecoverableZooKeeper zooKeeper = ZkUtils.getRecoverableZooKeeper();
String spliceBackupPath = BackupUtils.getBackupPath();
if (zooKeeper.exists(spliceBackupPath, false)==null){
return false;
}
boolean isRestoreMode = SIDriver.driver().lifecycleManager().isRestoreMode();
if (!isRestoreMode) {
if (BackupUtils.existsDatabaseBackup(fs, rootDir)) {
if (LOG.isDebugEnabled()) {
SpliceLogUtils.debug(LOG, "There exists a successful full or incremental backup in the system");
}
shouldRegister = true;
} else {
List<String> backupJobs = zooKeeper.getChildren(spliceBackupPath, false);
for (String backupId : backupJobs) {
String path = spliceBackupPath + "/" + backupId;
byte[] data = zooKeeper.getData(path, false, null);
BackupJobStatus status = BackupJobStatus.parseFrom(data);
if (status.getScope() == BackupJobStatus.BackupScope.DATABASE) {
if (LOG.isDebugEnabled()) {
SpliceLogUtils.debug(LOG, "A database backup is running");
}
shouldRegister = true;
}
}
}
}
}
return shouldRegister;
}
catch (Exception e) {
e.printStackTrace();
throw StandardException.plainWrapException(e);
}
}
private String getMasterCluster() throws InterruptedException, KeeperException{
RecoverableZooKeeper rzk = zkWatcher.getRecoverableZooKeeper();
String path = replicationMonitorPath + "/master";
if (rzk.exists(path, false) != null) {
List<String> children = rzk.getChildren(path, false);
return children.size() > 0 ? children.get(0) : null;
}
return null;
}
private boolean involvedInReplication() throws InterruptedException, KeeperException{
RecoverableZooKeeper rzk = zkWatcher.getRecoverableZooKeeper();
String masterPath = replicationMonitorPath + "/master/" + thisCluster;
String peerPath = replicationMonitorPath + "/peers/" + thisCluster;
return rzk.exists(masterPath, false) != null || rzk.exists(peerPath, false) != null;
}
public static boolean isSpliceLoaded() throws InterruptedException, KeeperException{
RecoverableZooKeeper rzk=getRecoverableZooKeeper();
String path=HConfiguration.getConfiguration().getSpliceRootPath()+HConfiguration.STARTUP_PATH;
return rzk.exists(path,false)!=null;
}
public static boolean backupInProgress() throws Exception {
String path = BackupUtils.getBackupPath();
RecoverableZooKeeper zooKeeper = ZkUtils.getRecoverableZooKeeper();
Stat stat = zooKeeper.exists(path, false);
return (stat != null);
}
public static boolean backupCanceled() throws KeeperException, InterruptedException {
RecoverableZooKeeper zooKeeper = ZkUtils.getRecoverableZooKeeper();
String path = BackupUtils.getBackupPath();
return zooKeeper.exists(path, false) == null;
}
private List<String> getReplicationPeers() throws KeeperException, InterruptedException {
RecoverableZooKeeper rzk = zkWatcher.getRecoverableZooKeeper();
String path = replicationMonitorPath + "/peers";
return rzk.exists(path, false) != null ? rzk.getChildren(path, false) : Lists.newArrayList();
}