use of org.apache.hadoop.hbase.util.MultiHConnection in project hbase by apache.
the class RegionStateStore method start.
void start() throws IOException {
if (server instanceof RegionServerServices) {
metaRegion = ((RegionServerServices) server).getFromOnlineRegions(HRegionInfo.FIRST_META_REGIONINFO.getEncodedName());
}
// When meta is not colocated on master
if (metaRegion == null) {
Configuration conf = server.getConfiguration();
// Config to determine the no of HConnections to META.
// A single Connection should be sufficient in most cases. Only if
// you are doing lot of writes (>1M) to META,
// increasing this value might improve the write throughput.
multiHConnection = new MultiHConnection(conf, conf.getInt("hbase.regionstatestore.meta.connection", 1));
}
initialized = true;
}
use of org.apache.hadoop.hbase.util.MultiHConnection in project hbase by apache.
the class RegionStateStore method updateRegionState.
void updateRegionState(long openSeqNum, RegionState newState, RegionState oldState) {
try {
HRegionInfo hri = newState.getRegion();
// Update meta before checking for initialization. Meta state stored in zk.
if (hri.isMetaRegion()) {
// persist meta state in MetaTableLocator (which in turn is zk storage currently)
try {
MetaTableLocator.setMetaLocation(server.getZooKeeper(), newState.getServerName(), hri.getReplicaId(), newState.getState());
// Done
return;
} catch (KeeperException e) {
throw new IOException("Failed to update meta ZNode", e);
}
}
if (!initialized || !shouldPersistStateChange(hri, newState, oldState)) {
return;
}
ServerName oldServer = oldState != null ? oldState.getServerName() : null;
ServerName serverName = newState.getServerName();
State state = newState.getState();
int replicaId = hri.getReplicaId();
Put metaPut = new Put(MetaTableAccessor.getMetaKeyForRegion(hri));
StringBuilder info = new StringBuilder("Updating hbase:meta row ");
info.append(hri.getRegionNameAsString()).append(" with state=").append(state);
if (serverName != null && !serverName.equals(oldServer)) {
metaPut.addImmutable(HConstants.CATALOG_FAMILY, getServerNameColumn(replicaId), Bytes.toBytes(serverName.getServerName()));
info.append(", sn=").append(serverName);
}
if (openSeqNum >= 0) {
Preconditions.checkArgument(state == State.OPEN && serverName != null, "Open region should be on a server");
MetaTableAccessor.addLocation(metaPut, serverName, openSeqNum, -1, replicaId);
info.append(", openSeqNum=").append(openSeqNum);
info.append(", server=").append(serverName);
}
metaPut.addImmutable(HConstants.CATALOG_FAMILY, getStateColumn(replicaId), Bytes.toBytes(state.name()));
LOG.info(info);
HTableDescriptor descriptor = server.getTableDescriptors().get(hri.getTable());
boolean serial = false;
if (descriptor != null) {
serial = server.getTableDescriptors().get(hri.getTable()).hasSerialReplicationScope();
}
boolean shouldPutBarrier = serial && state == State.OPEN;
// Persist the state change to meta
if (metaRegion != null) {
try {
// Assume meta is pinned to master.
// At least, that's what we want.
metaRegion.put(metaPut);
if (shouldPutBarrier) {
Put barrierPut = MetaTableAccessor.makeBarrierPut(hri.getEncodedNameAsBytes(), openSeqNum, hri.getTable().getName());
metaRegion.put(barrierPut);
}
// Done here
return;
} catch (Throwable t) {
// to the master
synchronized (this) {
if (metaRegion != null) {
LOG.info("Meta region shortcut failed", t);
if (multiHConnection == null) {
multiHConnection = new MultiHConnection(server.getConfiguration(), 1);
}
metaRegion = null;
}
}
}
}
// Called when meta is not on master
List<Put> list = shouldPutBarrier ? Arrays.asList(metaPut, MetaTableAccessor.makeBarrierPut(hri.getEncodedNameAsBytes(), openSeqNum, hri.getTable().getName())) : Collections.singletonList(metaPut);
multiHConnection.processBatchCallback(list, TableName.META_TABLE_NAME, null, null);
} catch (IOException ioe) {
LOG.error("Failed to persist region state " + newState, ioe);
server.abort("Failed to update region location", ioe);
}
}
Aggregations