本文整理汇总了Java中org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos类的典型用法代码示例。如果您正苦于以下问题:Java ZooKeeperProtos类的具体用法?Java ZooKeeperProtos怎么用?Java ZooKeeperProtos使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZooKeeperProtos类属于org.apache.hadoop.hbase.protobuf.generated包,在下文中一共展示了ZooKeeperProtos类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTableStateIfInStates
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
/**
* Checks and sets table state in ZK. Sets no watches.
* {@inheritDoc}
*/
@Override
public boolean setTableStateIfInStates(TableName tableName,
ZooKeeperProtos.Table.State newState,
ZooKeeperProtos.Table.State... states)
throws CoordinatedStateException {
synchronized (this.cache) {
// Transition ENABLED->DISABLING has to be performed with a hack, because
// we treat empty state as enabled in this case because 0.92- clusters.
if (
(newState == ZooKeeperProtos.Table.State.DISABLING) &&
this.cache.get(tableName) != null && !isTableState(tableName, states) ||
(newState != ZooKeeperProtos.Table.State.DISABLING &&
!isTableState(tableName, states) )) {
return false;
}
try {
setTableStateInZK(tableName, newState);
} catch (KeeperException e) {
throw new CoordinatedStateException(e);
}
return true;
}
}
示例2: checkAndRemoveTableState
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void checkAndRemoveTableState(TableName tableName, ZooKeeperProtos.Table.State states,
boolean deletePermanentState)
throws CoordinatedStateException {
synchronized (this.cache) {
if (isTableState(tableName, states)) {
this.cache.remove(tableName);
if (deletePermanentState) {
try {
ZKUtil.deleteNodeFailSilent(this.watcher,
ZKUtil.joinZNode(this.watcher.tableZNode, tableName.getNameAsString()));
} catch (KeeperException e) {
throw new CoordinatedStateException(e);
}
}
}
}
}
示例3: getAllTables
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
/**
* Gets a list of all the tables of specified states in zookeeper.
* @return Set of tables of specified states, empty Set if none
* @throws KeeperException
*/
Set<TableName> getAllTables(final ZooKeeperProtos.Table.State... states)
throws KeeperException, InterruptedIOException {
Set<TableName> allTables = new HashSet<TableName>();
List<String> children =
ZKUtil.listChildrenNoWatch(watcher, watcher.tableZNode);
if(children == null) return allTables;
for (String child: children) {
TableName tableName = TableName.valueOf(child);
ZooKeeperProtos.Table.State state;
try {
state = getTableState(watcher, tableName);
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
for (ZooKeeperProtos.Table.State expectedState: states) {
if (state == expectedState) {
allTables.add(tableName);
break;
}
}
}
return allTables;
}
示例4: handleMetadata
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
@Override
public void handleMetadata(byte[] ownerMetadata) {
if (!LOG.isDebugEnabled()) {
return;
}
ZooKeeperProtos.TableLock data = fromBytes(ownerMetadata);
if (data == null) {
return;
}
LOG.debug("Table is locked by " +
String.format("[tableName=%s:%s, lockOwner=%s, threadId=%s, " +
"purpose=%s, isShared=%s, createTime=%s]",
data.getTableName().getNamespace().toStringUtf8(),
data.getTableName().getQualifier().toStringUtf8(),
ProtobufUtil.toServerName(data.getLockOwner()), data.getThreadId(),
data.getPurpose(), data.getIsShared(), data.getCreateTime()));
}
示例5: createTableLock
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
private InterProcessLock createTableLock() {
String tableLockZNode = ZKUtil.joinZNode(zkWatcher.tableLockZNode,
tableName.getNameAsString());
ZooKeeperProtos.TableLock data = ZooKeeperProtos.TableLock.newBuilder()
.setTableName(ProtobufUtil.toProtoTableName(tableName))
.setLockOwner(ProtobufUtil.toServerName(serverName))
.setThreadId(Thread.currentThread().getId())
.setPurpose(purpose)
.setIsShared(isShared)
.setCreateTime(EnvironmentEdgeManager.currentTime()).build();
byte[] lockMetadata = toBytes(data);
InterProcessReadWriteLock lock = new ZKInterProcessReadWriteLock(zkWatcher, tableLockZNode,
METADATA_HANDLER);
return isShared ? lock.readLock(lockMetadata) : lock.writeLock(lockMetadata);
}
示例6: process
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
@Override
public void process() {
LOG.debug("Handling CLOSED event for " + regionInfo.getEncodedName());
// Check if this table is being disabled or not
if (this.assignmentManager.getTableStateManager().isTableState(this.regionInfo.getTable(),
ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING) ||
assignmentManager.getReplicasToClose().contains(regionInfo)) {
assignmentManager.offlineDisabledRegion(regionInfo);
return;
}
// ZK Node is in CLOSED state, assign it.
assignmentManager.getRegionStates().updateRegionState(
regionInfo, RegionState.State.CLOSED);
// This below has to do w/ online enable/disable of a table
assignmentManager.removeClosedRegion(regionInfo);
assignmentManager.assign(regionInfo, true);
}
示例7: prepareCreate
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
private boolean prepareCreate(final MasterProcedureEnv env) throws IOException {
final TableName tableName = getTableName();
if (MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) {
setFailure("master-create-table", new TableExistsException(getTableName()));
return false;
}
// During master initialization, the ZK state could be inconsistent from failed DDL
// in the past. If we fail here, it would prevent master to start. We should force
// setting the system table state regardless the table state.
boolean skipTableStateCheck =
!(env.getMasterServices().isInitialized()) && tableName.isSystemTable();
if (!skipTableStateCheck) {
TableStateManager tsm = env.getMasterServices().getAssignmentManager().getTableStateManager();
if (tsm.isTableState(tableName, true, ZooKeeperProtos.Table.State.ENABLING,
ZooKeeperProtos.Table.State.ENABLED)) {
LOG.warn("The table " + tableName + " does not exist in meta but has a znode. " +
"run hbck to fix inconsistencies.");
setFailure("master-create-table", new TableExistsException(getTableName()));
return false;
}
}
return true;
}
示例8: assignRegions
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
protected static void assignRegions(final MasterProcedureEnv env,
final TableName tableName, final List<HRegionInfo> regions)
throws HBaseException, IOException {
ProcedureSyncWait.waitRegionServers(env);
final AssignmentManager assignmentManager = env.getMasterServices().getAssignmentManager();
// Mark the table as Enabling
assignmentManager.getTableStateManager().setTableState(tableName,
ZooKeeperProtos.Table.State.ENABLING);
// Trigger immediate assignment of the regions in round-robin fashion
ModifyRegionUtils.assignRegions(assignmentManager, regions);
// Enable table
assignmentManager.getTableStateManager()
.setTableState(tableName, ZooKeeperProtos.Table.State.ENABLED);
}
示例9: undoTableStateChange
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
/**
* Rollback of table state change in prepareDisable()
* @param env MasterProcedureEnv
*/
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION",
justification="Intended")
private void undoTableStateChange(final MasterProcedureEnv env) {
if (!skipTableStateCheck) {
try {
// If the state was changed, undo it.
if (env.getMasterServices().getAssignmentManager().getTableStateManager().isTableState(
tableName, ZooKeeperProtos.Table.State.DISABLING)) {
EnableTableProcedure.setTableStateToEnabled(env, tableName);
}
} catch (Exception e) {
// Ignore exception.
LOG.trace(e.getMessage());
}
}
}
示例10: parsePeerFrom
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
/**
* @param bytes Content of a peer znode.
* @return ClusterKey parsed from the passed bytes.
* @throws DeserializationException
*/
private static ReplicationPeerConfig parsePeerFrom(final byte[] bytes)
throws DeserializationException {
if (ProtobufUtil.isPBMagicPrefix(bytes)) {
int pblen = ProtobufUtil.lengthOfPBMagic();
ZooKeeperProtos.ReplicationPeer.Builder builder =
ZooKeeperProtos.ReplicationPeer.newBuilder();
ZooKeeperProtos.ReplicationPeer peer;
try {
ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen);
peer = builder.build();
} catch (IOException e) {
throw new DeserializationException(e);
}
return convert(peer);
} else {
if (bytes.length > 0) {
return new ReplicationPeerConfig().setClusterKey(Bytes.toString(bytes));
}
return new ReplicationPeerConfig().setClusterKey("");
}
}
示例11: recoverTableInDisablingState
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
/**
* Recover the tables that were not fully moved to DISABLED state. These
* tables are in DISABLING state when the master restarted/switched.
*
* @throws KeeperException
* @throws TableNotFoundException
* @throws IOException
*/
private void recoverTableInDisablingState()
throws KeeperException, IOException, CoordinatedStateException {
Set<TableName> disablingTables =
tableStateManager.getTablesInStates(ZooKeeperProtos.Table.State.DISABLING);
if (disablingTables.size() != 0) {
for (TableName tableName : disablingTables) {
// Recover by calling DisableTableHandler
LOG.info("The table " + tableName
+ " is in DISABLING state. Hence recovering by moving the table"
+ " to DISABLED state.");
new DisableTableHandler(this.server, tableName,
this, tableLockManager, true).prepare().process();
}
}
}
示例12: recoverTableInEnablingState
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
/**
* Recover the tables that are not fully moved to ENABLED state. These tables
* are in ENABLING state when the master restarted/switched
*
* @throws KeeperException
* @throws org.apache.hadoop.hbase.TableNotFoundException
* @throws IOException
*/
private void recoverTableInEnablingState()
throws KeeperException, IOException, CoordinatedStateException {
Set<TableName> enablingTables = tableStateManager.
getTablesInStates(ZooKeeperProtos.Table.State.ENABLING);
if (enablingTables.size() != 0) {
for (TableName tableName : enablingTables) {
// Recover by calling EnableTableHandler
LOG.info("The table " + tableName
+ " is in ENABLING state. Hence recovering by moving the table"
+ " to ENABLED state.");
// enableTable in sync way during master startup,
// no need to invoke coprocessor
EnableTableHandler eth = new EnableTableHandler(this.server, tableName,
this, tableLockManager, true);
try {
eth.prepare();
} catch (TableNotFoundException e) {
LOG.warn("Table " + tableName + " not found in hbase:meta to recover.");
continue;
}
eth.process();
}
}
}
示例13: parseWALPositionFrom
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
/**
* @param bytes - Content of a WAL position znode.
* @return long - The current WAL position.
* @throws DeserializationException
*/
public static long parseWALPositionFrom(final byte[] bytes) throws DeserializationException {
if (bytes == null) {
throw new DeserializationException("Unable to parse null WAL position.");
}
if (ProtobufUtil.isPBMagicPrefix(bytes)) {
int pblen = ProtobufUtil.lengthOfPBMagic();
ZooKeeperProtos.ReplicationHLogPosition.Builder builder =
ZooKeeperProtos.ReplicationHLogPosition.newBuilder();
ZooKeeperProtos.ReplicationHLogPosition position;
try {
ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen);
position = builder.build();
} catch (IOException e) {
throw new DeserializationException(e);
}
return position.getPosition();
} else {
if (bytes.length > 0) {
return Bytes.toLong(bytes);
}
return 0;
}
}
示例14: onRegionOpen
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
private void onRegionOpen(final HRegionInfo hri, final ServerName sn, long openSeqNum) {
regionOnline(hri, sn, openSeqNum);
if (useZKForAssignment) {
try {
// Delete the ZNode if exists
ZKAssign.deleteNodeFailSilent(watcher, hri);
} catch (KeeperException ke) {
server.abort("Unexpected ZK exception deleting node " + hri, ke);
}
}
// reset the count, if any
failedOpenTracker.remove(hri.getEncodedName());
if (getTableStateManager().isTableState(hri.getTable(),
ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) {
invokeUnAssign(hri);
}
}
示例15: appendPeerState
import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; //导入依赖的package包/类
private static void appendPeerState(ZooKeeperWatcher zkw, String znodeToProcess,
StringBuilder sb) throws KeeperException, InvalidProtocolBufferException {
String peerState = zkw.getConfiguration().get("zookeeper.znode.replication.peers.state",
"peer-state");
int pblen = ProtobufUtil.lengthOfPBMagic();
for (String child : ZKUtil.listChildrenNoWatch(zkw, znodeToProcess)) {
if (!child.equals(peerState)) continue;
String peerStateZnode = ZKUtil.joinZNode(znodeToProcess, child);
sb.append("\n").append(peerStateZnode).append(": ");
byte[] peerStateData;
try {
peerStateData = ZKUtil.getData(zkw, peerStateZnode);
ZooKeeperProtos.ReplicationState.Builder builder =
ZooKeeperProtos.ReplicationState.newBuilder();
ProtobufUtil.mergeFrom(builder, peerStateData, pblen, peerStateData.length - pblen);
sb.append(builder.getState().name());
} catch (IOException ipbe) {
LOG.warn("Got Exception while parsing peer: " + znodeToProcess, ipbe);
} catch (InterruptedException e) {
zkw.interruptedException(e);
return;
}
}
}