org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil Java Examples

The following examples show how to use org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StoreFileWriter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Used when write {@link HStoreFile#COMPACTION_EVENT_KEY} to new file's file info. The compacted
 * store files's name is needed. But if the compacted store file is a result of compaction, it's
 * compacted files which still not archived is needed, too. And don't need to add compacted files
 * recursively. If file A, B, C compacted to new file D, and file D compacted to new file E, will
 * write A, B, C, D to file E's compacted files. So if file E compacted to new file F, will add E
 * to F's compacted files first, then add E's compacted files: A, B, C, D to it. And no need to
 * add D's compacted file, as D's compacted files has been in E's compacted files, too.
 * See HBASE-20724 for more details.
 *
 * @param storeFiles The compacted store files to generate this new file
 * @return bytes of CompactionEventTracker
 */
private byte[] toCompactionEventTrackerBytes(Collection<HStoreFile> storeFiles) {
  Set<String> notArchivedCompactedStoreFiles =
      this.compactedFilesSupplier.get().stream().map(sf -> sf.getPath().getName())
          .collect(Collectors.toSet());
  Set<String> compactedStoreFiles = new HashSet<>();
  for (HStoreFile storeFile : storeFiles) {
    compactedStoreFiles.add(storeFile.getFileInfo().getPath().getName());
    for (String csf : storeFile.getCompactedStoreFiles()) {
      if (notArchivedCompactedStoreFiles.contains(csf)) {
        compactedStoreFiles.add(csf);
      }
    }
  }
  return ProtobufUtil.toCompactionEventTrackerBytes(compactedStoreFiles);
}
 
Example #2
Source File: IntegrationTestMetaReplicas.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  // Set up the integration test util
  if (util == null) {
    util = new IntegrationTestingUtility();
  }
  util.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 3);
  util.getConfiguration().setInt(
      StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, 1000);
  // Make sure there are three servers.
  util.initializeCluster(3);
  ZKWatcher zkw = util.getZooKeeperWatcher();
  Configuration conf = util.getConfiguration();
  String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
      HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
  String primaryMetaZnode = ZNodePaths.joinZNode(baseZNode,
      conf.get("zookeeper.znode.metaserver", "meta-region-server"));
  // check that the data in the znode is parseable (this would also mean the znode exists)
  byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
  ProtobufUtil.toServerName(data);
  waitUntilZnodeAvailable(1);
  waitUntilZnodeAvailable(2);
}
 
Example #3
Source File: TestHRegionReplayEvents.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplayingRegionOpenEventWithFileAlreadyDeleted() throws IOException {
  // tests replaying region open event marker, but the region files have already been compacted
  // from primary and also deleted from the archive directory
  secondaryRegion.replayWALRegionEventMarker(RegionEventDescriptor.newBuilder()
    .setTableName(UnsafeByteOperations.unsafeWrap(
        primaryRegion.getTableDescriptor().getTableName().getName()))
    .setEncodedRegionName(
        UnsafeByteOperations.unsafeWrap(primaryRegion.getRegionInfo().getEncodedNameAsBytes()))
    .setRegionName(UnsafeByteOperations.unsafeWrap(primaryRegion.getRegionInfo().getRegionName()))
    .setEventType(EventType.REGION_OPEN)
    .setServer(ProtobufUtil.toServerName(ServerName.valueOf("foo", 1, 1)))
    .setLogSequenceNumber(Long.MAX_VALUE)
    .addStores(StoreDescriptor.newBuilder()
      .setFamilyName(UnsafeByteOperations.unsafeWrap(families[0]))
      .setStoreHomeDir("/store_home_dir")
      .addStoreFile("/123")
      .build())
    .build());
}
 
Example #4
Source File: TestClientMetaServiceRPCs.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies the active master ServerName as seen by all masters.
 */
@Test public void TestActiveMaster() throws Exception {
  HBaseRpcController rpcController = getRpcController();
  ServerName activeMaster = TEST_UTIL.getMiniHBaseCluster().getMaster().getServerName();
  int rpcCount = 0;
  for (JVMClusterUtil.MasterThread masterThread:
      TEST_UTIL.getMiniHBaseCluster().getMasterThreads()) {
    ClientMetaService.BlockingInterface stub =
        getMasterStub(masterThread.getMaster().getServerName());
    GetActiveMasterResponse resp =
        stub.getActiveMaster(rpcController, GetActiveMasterRequest.getDefaultInstance());
    assertEquals(activeMaster, ProtobufUtil.toServerName(resp.getServerName()));
    rpcCount++;
  }
  assertEquals(MASTER_COUNT, rpcCount);
}
 
Example #5
Source File: NettyRpcFrameDecoder.java    From hbase with Apache License 2.0 6 votes vote down vote up
private RPCProtos.RequestHeader getHeader(ByteBuf in, int headerSize) throws IOException {
  ByteBuf msg = in.readRetainedSlice(headerSize);
  try {
    byte[] array;
    int offset;
    int length = msg.readableBytes();
    if (msg.hasArray()) {
      array = msg.array();
      offset = msg.arrayOffset() + msg.readerIndex();
    } else {
      array = new byte[length];
      msg.getBytes(msg.readerIndex(), array, 0, length);
      offset = 0;
    }

    RPCProtos.RequestHeader.Builder builder = RPCProtos.RequestHeader.newBuilder();
    ProtobufUtil.mergeFrom(builder, array, offset, length);
    return builder.build();
  } finally {
    msg.release();
  }
}
 
Example #6
Source File: BackupManifest.java    From hbase with Apache License 2.0 6 votes vote down vote up
static BackupImage fromProto(BackupProtos.BackupImage im) {
  String backupId = im.getBackupId();
  String rootDir = im.getBackupRootDir();
  long startTs = im.getStartTs();
  long completeTs = im.getCompleteTs();
  List<HBaseProtos.TableName> tableListList = im.getTableListList();
  List<TableName> tableList = new ArrayList<>();
  for (HBaseProtos.TableName tn : tableListList) {
    tableList.add(ProtobufUtil.toTableName(tn));
  }

  List<BackupProtos.BackupImage> ancestorList = im.getAncestorsList();

  BackupType type =
      im.getBackupType() == BackupProtos.BackupType.FULL ? BackupType.FULL
          : BackupType.INCREMENTAL;

  BackupImage image = new BackupImage(backupId, type, rootDir, tableList, startTs, completeTs);
  for (BackupProtos.BackupImage img : ancestorList) {
    image.addAncestor(fromProto(img));
  }
  image.setIncrTimeRanges(loadIncrementalTimestampMap(im));
  return image;
}
 
Example #7
Source File: ClientTokenUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Obtain and return an authentication token for the current user.
 * @param conn The async HBase cluster connection
 * @return the authentication token instance, wrapped by a {@link CompletableFuture}.
 */
@InterfaceAudience.Private
public static CompletableFuture<Token<AuthenticationTokenIdentifier>> obtainToken(
    AsyncConnection conn) {
  CompletableFuture<Token<AuthenticationTokenIdentifier>> future = new CompletableFuture<>();
  if (injectedException != null) {
    future.completeExceptionally(ProtobufUtil.handleRemoteException(injectedException));
    return future;
  }
  AsyncTable<?> table = conn.getTable(TableName.META_TABLE_NAME);
  table.<AuthenticationProtos.AuthenticationService.Interface,
      AuthenticationProtos.GetAuthenticationTokenResponse> coprocessorService(
    AuthenticationProtos.AuthenticationService::newStub,
        (s, c, r) -> s.getAuthenticationToken(c,
            AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance(), r),
    HConstants.EMPTY_START_ROW).whenComplete((resp, error) -> {
      if (error != null) {
        future.completeExceptionally(ProtobufUtil.handleRemoteException(error));
      } else {
        future.complete(toToken(resp.getToken()));
      }
    });
  return future;
}
 
Example #8
Source File: TestScan.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testAttributesSerialization() throws IOException {
  Scan scan = new Scan();
  scan.setAttribute("attribute1", Bytes.toBytes("value1"));
  scan.setAttribute("attribute2", Bytes.toBytes("value2"));
  scan.setAttribute("attribute3", Bytes.toBytes("value3"));

  ClientProtos.Scan scanProto = ProtobufUtil.toScan(scan);

  Scan scan2 = ProtobufUtil.toScan(scanProto);

  Assert.assertNull(scan2.getAttribute("absent"));
  Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), scan2.getAttribute("attribute1")));
  Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), scan2.getAttribute("attribute2")));
  Assert.assertTrue(Arrays.equals(Bytes.toBytes("value3"), scan2.getAttribute("attribute3")));
  Assert.assertEquals(3, scan2.getAttributesMap().size());
}
 
Example #9
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public AddColumnResponse addColumn(RpcController controller,
    AddColumnRequest req) throws ServiceException {
  try {
    long procId = master.addColumn(
        ProtobufUtil.toTableName(req.getTableName()),
        ProtobufUtil.toColumnFamilyDescriptor(req.getColumnFamilies()),
        req.getNonceGroup(),
        req.getNonce());
    if (procId == -1) {
      // This mean operation was not performed in server, so do not set any procId
      return AddColumnResponse.newBuilder().build();
    } else {
      return AddColumnResponse.newBuilder().setProcId(procId).build();
    }
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
 
Example #10
Source File: ZKProcedureCoordinator.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * This is the abort message being sent by the coordinator to member
 *
 * TODO this code isn't actually used but can be used to issue a cancellation from the
 * coordinator.
 */
@Override
final public void sendAbortToMembers(Procedure proc, ForeignException ee) {
  String procName = proc.getName();
  LOG.debug("Aborting procedure '" + procName + "' in zk");
  String procAbortNode = zkProc.getAbortZNode(procName);
  try {
    LOG.debug("Creating abort znode:" + procAbortNode);
    String source = (ee.getSource() == null) ? coordName : ee.getSource();
    byte[] errorInfo = ProtobufUtil.prependPBMagic(ForeignException.serialize(source, ee));
    // first create the znode for the procedure
    ZKUtil.createAndFailSilent(zkProc.getWatcher(), procAbortNode, errorInfo);
    LOG.debug("Finished creating abort node:" + procAbortNode);
  } catch (KeeperException e) {
    // possible that we get this error for the procedure if we already reset the zk state, but in
    // that case we should still get an error for that procedure anyways
    zkProc.logZKTree(zkProc.baseZNode);
    coordinator.rpcConnectionFailure("Failed to post zk node:" + procAbortNode
        + " to abort procedure '" + procName + "'", new IOException(e));
  }
}
 
Example #11
Source File: TruncateTableProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
protected void deserializeStateData(ProcedureStateSerializer serializer)
    throws IOException {
  super.deserializeStateData(serializer);

  MasterProcedureProtos.TruncateTableStateData state =
      serializer.deserialize(MasterProcedureProtos.TruncateTableStateData.class);
  setUser(MasterProcedureUtil.toUserInfo(state.getUserInfo()));
  if (state.hasTableSchema()) {
    tableDescriptor = ProtobufUtil.toTableDescriptor(state.getTableSchema());
    tableName = tableDescriptor.getTableName();
  } else {
    tableName = ProtobufUtil.toTableName(state.getTableName());
  }
  preserveSplits = state.getPreserveSplits();
  if (state.getRegionInfoCount() == 0) {
    regions = null;
  } else {
    regions = new ArrayList<>(state.getRegionInfoCount());
    for (HBaseProtos.RegionInfo hri: state.getRegionInfoList()) {
      regions.add(ProtobufUtil.toRegionInfo(hri));
    }
  }
}
 
Example #12
Source File: ServerMetricsBuilder.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static ClusterStatusProtos.ServerLoad toServerLoad(ServerMetrics metrics) {
  ClusterStatusProtos.ServerLoad.Builder builder = ClusterStatusProtos.ServerLoad.newBuilder()
      .setNumberOfRequests(metrics.getRequestCountPerSecond())
      .setTotalNumberOfRequests(metrics.getRequestCount())
      .setInfoServerPort(metrics.getInfoServerPort())
      .setMaxHeapMB((int) metrics.getMaxHeapSize().get(Size.Unit.MEGABYTE))
      .setUsedHeapMB((int) metrics.getUsedHeapSize().get(Size.Unit.MEGABYTE))
      .addAllCoprocessors(toCoprocessor(metrics.getCoprocessorNames())).addAllRegionLoads(
          metrics.getRegionMetrics().values().stream().map(RegionMetricsBuilder::toRegionLoad)
              .collect(Collectors.toList())).addAllUserLoads(
          metrics.getUserMetrics().values().stream().map(UserMetricsBuilder::toUserMetrics)
              .collect(Collectors.toList())).addAllReplLoadSource(
          metrics.getReplicationLoadSourceList().stream()
              .map(ProtobufUtil::toReplicationLoadSource).collect(Collectors.toList()))
      .setReportStartTime(metrics.getLastReportTimestamp())
      .setReportEndTime(metrics.getReportTimestamp());
  if (metrics.getReplicationLoadSink() != null) {
    builder.setReplLoadSink(ProtobufUtil.toReplicationLoadSink(metrics.getReplicationLoadSink()));
  }

  return builder.build();
}
 
Example #13
Source File: HRegionServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
void reportProcedureDone(ReportProcedureDoneRequest request) throws IOException {
  RegionServerStatusService.BlockingInterface rss;
  // TODO: juggling class state with an instance variable, outside of a synchronized block :'(
  for (;;) {
    rss = rssStub;
    if (rss != null) {
      break;
    }
    createRegionServerStatusStub();
  }
  try {
    rss.reportProcedureDone(null, request);
  } catch (ServiceException se) {
    if (rssStub == rss) {
      rssStub = null;
    }
    throw ProtobufUtil.getRemoteException(se);
  }
}
 
Example #14
Source File: TestRogueRSAssignment.java    From hbase with Apache License 2.0 6 votes vote down vote up
private RegionServerStatusProtos.RegionServerReportRequest.Builder
    makeRSReportRequestWithRegions(final ServerName sn, RegionInfo... regions) {
  ClusterStatusProtos.ServerLoad.Builder sl = ClusterStatusProtos.ServerLoad.newBuilder();
  for (int i = 0; i < regions.length; i++) {
    HBaseProtos.RegionSpecifier.Builder rs = HBaseProtos.RegionSpecifier.newBuilder();
    rs.setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME);
    rs.setValue(UnsafeByteOperations.unsafeWrap(regions[i].getRegionName()));

    ClusterStatusProtos.RegionLoad.Builder rl = ClusterStatusProtos.RegionLoad.newBuilder()
        .setRegionSpecifier(rs.build());

    sl.addRegionLoads(i, rl.build());
  }

  return RegionServerStatusProtos.RegionServerReportRequest.newBuilder()
            .setServer(ProtobufUtil.toServerName(sn))
            .setLoad(sl);
}
 
Example #15
Source File: TableSnapshotInputFormatImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
  TableSnapshotRegionSplit.Builder builder = TableSnapshotRegionSplit.newBuilder()
      .setTable(ProtobufUtil.toTableSchema(htd))
      .setRegion(ProtobufUtil.toRegionInfo(regionInfo));

  for (String location : locations) {
    builder.addLocations(location);
  }

  TableSnapshotRegionSplit split = builder.build();

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  split.writeTo(baos);
  baos.close();
  byte[] buf = baos.toByteArray();
  out.writeInt(buf.length);
  out.write(buf);

  Bytes.writeByteArray(out, Bytes.toBytes(scan));
  Bytes.writeByteArray(out, Bytes.toBytes(restoreDir));

}
 
Example #16
Source File: SnapshotManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Clone the specified snapshot.
 * The clone will fail if the destination table has a snapshot or restore in progress.
 *
 * @param reqSnapshot Snapshot Descriptor from request
 * @param tableName table to clone
 * @param snapshot Snapshot Descriptor
 * @param snapshotTableDesc Table Descriptor
 * @param nonceKey unique identifier to prevent duplicated RPC
 * @return procId the ID of the clone snapshot procedure
 * @throws IOException
 */
private long cloneSnapshot(final SnapshotDescription reqSnapshot, final TableName tableName,
    final SnapshotDescription snapshot, final TableDescriptor snapshotTableDesc,
    final NonceKey nonceKey, final boolean restoreAcl) throws IOException {
  MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
  TableDescriptor htd = TableDescriptorBuilder.copy(tableName, snapshotTableDesc);
  org.apache.hadoop.hbase.client.SnapshotDescription snapshotPOJO = null;
  if (cpHost != null) {
    snapshotPOJO = ProtobufUtil.createSnapshotDesc(snapshot);
    cpHost.preCloneSnapshot(snapshotPOJO, htd);
  }
  long procId;
  try {
    procId = cloneSnapshot(snapshot, htd, nonceKey, restoreAcl);
  } catch (IOException e) {
    LOG.error("Exception occurred while cloning the snapshot " + snapshot.getName()
      + " as table " + tableName.getNameAsString(), e);
    throw e;
  }
  LOG.info("Clone snapshot=" + snapshot.getName() + " as table=" + tableName);

  if (cpHost != null) {
    cpHost.postCloneSnapshot(snapshotPOJO, htd);
  }
  return procId;
}
 
Example #17
Source File: VersionModel.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public ProtobufMessageHandler getObjectFromMessage(byte[] message)
    throws IOException {
  Version.Builder builder = Version.newBuilder();
  ProtobufUtil.mergeFrom(builder, message);
  if (builder.hasRestVersion()) {
    restVersion = builder.getRestVersion();
  }
  if (builder.hasJvmVersion()) {
    jvmVersion = builder.getJvmVersion();
  }
  if (builder.hasOsVersion()) {
    osVersion = builder.getOsVersion();
  }
  if (builder.hasServerVersion()) {
    serverVersion = builder.getServerVersion();
  }
  if (builder.hasJerseyVersion()) {
    jerseyVersion = builder.getJerseyVersion();
  }
  return this;
}
 
Example #18
Source File: SingleColumnValueFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
FilterProtos.SingleColumnValueFilter convert() {
  FilterProtos.SingleColumnValueFilter.Builder builder =
    FilterProtos.SingleColumnValueFilter.newBuilder();
  if (this.columnFamily != null) {
    builder.setColumnFamily(UnsafeByteOperations.unsafeWrap(this.columnFamily));
  }
  if (this.columnQualifier != null) {
    builder.setColumnQualifier(UnsafeByteOperations.unsafeWrap(this.columnQualifier));
  }
  HBaseProtos.CompareType compareOp = CompareType.valueOf(this.op.name());
  builder.setCompareOp(compareOp);
  builder.setComparator(ProtobufUtil.toComparator(this.comparator));
  builder.setFilterIfMissing(this.filterIfMissing);
  builder.setLatestVersionOnly(this.latestVersionOnly);

  return builder.build();
}
 
Example #19
Source File: SnapshotManifest.java    From hbase with Apache License 2.0 5 votes vote down vote up
private RegionVisitor createRegionVisitor(final SnapshotDescription desc) throws IOException {
  switch (getSnapshotFormat(desc)) {
    case SnapshotManifestV1.DESCRIPTOR_VERSION:
      return new SnapshotManifestV1.ManifestBuilder(conf, rootFs, workingDir);
    case SnapshotManifestV2.DESCRIPTOR_VERSION:
      return new SnapshotManifestV2.ManifestBuilder(conf, rootFs, workingDir);
    default:
    throw new CorruptedSnapshotException("Invalid Snapshot version: " + desc.getVersion(),
      ProtobufUtil.createSnapshotDesc(desc));
  }
}
 
Example #20
Source File: TestMasterQosFunction.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegionInTransition() throws IOException {
  // Check ReportRegionInTransition
  HBaseProtos.RegionInfo meta_ri =
    ProtobufUtil.toRegionInfo(RegionInfoBuilder.FIRST_META_REGIONINFO);
  HBaseProtos.RegionInfo normal_ri =
    ProtobufUtil.toRegionInfo(RegionInfoBuilder.newBuilder(TableName.valueOf("test:table"))
      .setStartKey(Bytes.toBytes("a")).setEndKey(Bytes.toBytes("b")).build());


  RegionServerStatusProtos.RegionStateTransition metaTransition = RegionServerStatusProtos
      .RegionStateTransition.newBuilder()
      .addRegionInfo(meta_ri)
      .setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED)
      .build();

  RegionServerStatusProtos.RegionStateTransition normalTransition = RegionServerStatusProtos
      .RegionStateTransition.newBuilder()
      .addRegionInfo(normal_ri)
      .setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED)
      .build();

  RegionServerStatusProtos.ReportRegionStateTransitionRequest metaTransitionRequest =
      RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder()
          .setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100)))
          .addTransition(normalTransition)
          .addTransition(metaTransition).build();

  RegionServerStatusProtos.ReportRegionStateTransitionRequest normalTransitionRequest =
      RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder()
          .setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100)))
          .addTransition(normalTransition).build();

  final String reportFuncName = "ReportRegionStateTransition";
  checkMethod(conf, reportFuncName, HConstants.META_QOS, qosFunction,
      metaTransitionRequest);
  checkMethod(conf, reportFuncName, HConstants.HIGH_QOS, qosFunction, normalTransitionRequest);
}
 
Example #21
Source File: ReopenTableRegionsProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
  super.serializeStateData(serializer);
  ReopenTableRegionsStateData.Builder builder = ReopenTableRegionsStateData.newBuilder()
    .setTableName(ProtobufUtil.toProtoTableName(tableName));
  regions.stream().map(ProtobufUtil::toRegionLocation).forEachOrdered(builder::addRegion);
  serializer.serialize(builder.build());
}
 
Example #22
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public UpdateFavoredNodesResponse updateFavoredNodes(RpcController controller,
    UpdateFavoredNodesRequest request) throws ServiceException {
  List<UpdateFavoredNodesRequest.RegionUpdateInfo> openInfoList = request.getUpdateInfoList();
  UpdateFavoredNodesResponse.Builder respBuilder = UpdateFavoredNodesResponse.newBuilder();
  for (UpdateFavoredNodesRequest.RegionUpdateInfo regionUpdateInfo : openInfoList) {
    RegionInfo hri = ProtobufUtil.toRegionInfo(regionUpdateInfo.getRegion());
    if (regionUpdateInfo.getFavoredNodesCount() > 0) {
      regionServer.updateRegionFavoredNodesMapping(hri.getEncodedName(),
        regionUpdateInfo.getFavoredNodesList());
    }
  }
  respBuilder.setResponse(openInfoList.size());
  return respBuilder.build();
}
 
Example #23
Source File: SnapshotInfo.java    From hbase with Apache License 2.0 5 votes vote down vote up
SnapshotStats(final Configuration conf, final FileSystem fs,
    final SnapshotDescription snapshot)
{
  this.snapshot = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshot);
  this.snapshotTable = snapshot.getTableName();
  this.conf = conf;
  this.fs = fs;
}
 
Example #24
Source File: HRegionServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected void tryRegionServerReport(long reportStartTime, long reportEndTime)
    throws IOException {
  RegionServerStatusService.BlockingInterface rss = rssStub;
  if (rss == null) {
    // the current server could be stopping.
    return;
  }
  ClusterStatusProtos.ServerLoad sl = buildServerLoad(reportStartTime, reportEndTime);
  try {
    RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();
    request.setServer(ProtobufUtil.toServerName(this.serverName));
    request.setLoad(sl);
    rss.regionServerReport(null, request.build());
  } catch (ServiceException se) {
    IOException ioe = ProtobufUtil.getRemoteException(se);
    if (ioe instanceof YouAreDeadException) {
      // This will be caught and handled as a fatal error in run()
      throw ioe;
    }
    if (rssStub == rss) {
      rssStub = null;
    }
    // Couldn't connect to the master, get location from zk and reconnect
    // Method blocks until new master is found or we are stopped
    createRegionServerStatusStub(true);
  }
}
 
Example #25
Source File: TestAdmin2.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testCloseRegionThatFetchesTheHRIFromMeta() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  createTableWithDefaultConf(tableName);

  RegionInfo info = null;
  HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(tableName);
  List<RegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
  for (RegionInfo regionInfo : onlineRegions) {
    if (!regionInfo.isMetaRegion()) {
      if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion2")) {
        info = regionInfo;
        ADMIN.unassign(regionInfo.getRegionName(), true);
      }
    }
  }

  boolean isInList = ProtobufUtil.getOnlineRegions(
    rs.getRSRpcServices()).contains(info);
  long timeout = System.currentTimeMillis() + 10000;
  while ((System.currentTimeMillis() < timeout) && (isInList)) {
    Thread.sleep(100);
    isInList = ProtobufUtil.getOnlineRegions(
      rs.getRSRpcServices()).contains(info);
  }

  assertFalse("The region should not be present in online regions list.",
    isInList);
}
 
Example #26
Source File: GCMultipleMergedRegionsProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected void serializeStateData(ProcedureStateSerializer serializer)
    throws IOException {
  super.serializeStateData(serializer);
  final GCMultipleMergedRegionsStateData.Builder msg =
      GCMultipleMergedRegionsStateData.newBuilder().
          addAllParents(this.parents.stream().map(ProtobufUtil::toRegionInfo).
              collect(Collectors.toList())).
          setMergedChild(ProtobufUtil.toRegionInfo(this.mergedChild));
  serializer.serialize(msg.build());
}
 
Example #27
Source File: MasterAddressTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Get the address of the current master if one is available.  Returns null
 * if no current master. If refresh is set, try to load the data from ZK again,
 * otherwise, cached data will be used.
 *
 * @param refresh whether to refresh the data by calling ZK directly.
 * @return Server name or null if timed out.
 */
public ServerName getMasterAddress(final boolean refresh) {
  try {
    return ProtobufUtil.parseServerNameFrom(super.getData(refresh));
  } catch (DeserializationException e) {
    LOG.warn("Failed parse", e);
    return null;
  }
}
 
Example #28
Source File: TestRegionServerNoMaster.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Test that if we do a close while opening it stops the opening.
 */
@Test
public void testCancelOpeningWithoutZK() throws Exception {
  // We close
  closeRegionNoZK();
  checkRegionIsClosed(HTU, getRS(), hri);

  // Let do the initial steps, without having a handler
  getRS().getRegionsInTransitionInRS().put(hri.getEncodedNameAsBytes(), Boolean.TRUE);

  // That's a close without ZK.
  AdminProtos.CloseRegionRequest crr =
      ProtobufUtil.buildCloseRegionRequest(getRS().getServerName(), regionName);
  try {
    getRS().rpcServices.closeRegion(null, crr);
    Assert.assertTrue(false);
  } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException expected) {
  }

  // The state in RIT should have changed to close
  Assert.assertEquals(Boolean.FALSE, getRS().getRegionsInTransitionInRS().get(
      hri.getEncodedNameAsBytes()));

  // Let's start the open handler
  TableDescriptor htd = getRS().tableDescriptors.get(hri.getTable());

  getRS().executorService.submit(new OpenRegionHandler(getRS(), getRS(), hri, htd, -1));

  // The open handler should have removed the region from RIT but kept the region closed
  checkRegionIsClosed(HTU, getRS(), hri);

  openRegion(HTU, getRS(), hri);
}
 
Example #29
Source File: SyncReplicationReplayWALRemoteProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
  SyncReplicationReplayWALRemoteStateData.Builder builder =
    SyncReplicationReplayWALRemoteStateData.newBuilder().setPeerId(peerId)
      .setTargetServer(ProtobufUtil.toServerName(targetServer));
  wals.stream().forEach(builder::addWal);
  serializer.serialize(builder.build());
}
 
Example #30
Source File: SnapshotManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Delete the specified snapshot
 * @param snapshot
 * @throws SnapshotDoesNotExistException If the specified snapshot does not exist.
 * @throws IOException For filesystem IOExceptions
 */
public void deleteSnapshot(SnapshotDescription snapshot) throws IOException {
  // check to see if it is completed
  if (!isSnapshotCompleted(snapshot)) {
    throw new SnapshotDoesNotExistException(ProtobufUtil.createSnapshotDesc(snapshot));
  }

  String snapshotName = snapshot.getName();
  // first create the snapshot description and check to see if it exists
  FileSystem fs = master.getMasterFileSystem().getFileSystem();
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
  // Get snapshot info from file system. The one passed as parameter is a "fake" snapshotInfo with
  // just the "name" and it does not contains the "real" snapshot information
  snapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);

  // call coproc pre hook
  MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
  org.apache.hadoop.hbase.client.SnapshotDescription snapshotPOJO = null;
  if (cpHost != null) {
    snapshotPOJO = ProtobufUtil.createSnapshotDesc(snapshot);
    cpHost.preDeleteSnapshot(snapshotPOJO);
  }

  LOG.debug("Deleting snapshot: " + snapshotName);
  // delete the existing snapshot
  if (!fs.delete(snapshotDir, true)) {
    throw new HBaseSnapshotException("Failed to delete snapshot directory: " + snapshotDir);
  }

  // call coproc post hook
  if (cpHost != null) {
    cpHost.postDeleteSnapshot(snapshotPOJO);
  }

}