Java 类org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerStatusService 实例源码

项目:ditb    文件:HRegionServer.java   
@Override public RegionStoreSequenceIds getLastSequenceId(byte[] encodedRegionName) {
  try {
    GetLastFlushedSequenceIdRequest req =
        RequestConverter.buildGetLastFlushedSequenceIdRequest(encodedRegionName);
    RegionServerStatusService.BlockingInterface rss = rssStub;
    if (rss == null) { // Try to connect one more time
      createRegionServerStatusStub();
      rss = rssStub;
      if (rss == null) {
        // Still no luck, we tried
        LOG.warn("Unable to connect to the master to check " + "the last flushed sequence id");
        return RegionStoreSequenceIds.newBuilder().setLastFlushedSequenceId(HConstants.NO_SEQNUM)
            .build();
      }
    }
    GetLastFlushedSequenceIdResponse resp = rss.getLastFlushedSequenceId(null, req);
    return RegionStoreSequenceIds.newBuilder()
        .setLastFlushedSequenceId(resp.getLastFlushedSequenceId())
        .addAllStoreSequenceId(resp.getStoreLastFlushedSequenceIdList()).build();
  } catch (ServiceException e) {
    LOG.warn("Unable to connect to the master to check the last flushed sequence id", e);
    return RegionStoreSequenceIds.newBuilder().setLastFlushedSequenceId(HConstants.NO_SEQNUM)
        .build();
  }
}
项目:pbase    文件:HRegionServer.java   
@Override
public long getLastSequenceId(byte[] encodedRegionName) {
    long lastFlushedSequenceId = -1L;
    try {
        GetLastFlushedSequenceIdRequest req = RequestConverter
                .buildGetLastFlushedSequenceIdRequest(encodedRegionName);
        RegionServerStatusService.BlockingInterface rss = rssStub;
        if (rss == null) { // Try to connect one more time
            createRegionServerStatusStub();
            rss = rssStub;
            if (rss == null) {
                // Still no luck, we tried
                LOG.warn("Unable to connect to the master to check "
                        + "the last flushed sequence id");
                return -1L;
            }
        }
        lastFlushedSequenceId = rss.getLastFlushedSequenceId(null, req)
                .getLastFlushedSequenceId();
    } catch (ServiceException e) {
        lastFlushedSequenceId = -1l;
        LOG.warn("Unable to connect to the master to check "
                + "the last flushed sequence id", e);
    }
    return lastFlushedSequenceId;
}
项目:ditb    文件:MasterRpcServices.java   
/**
 * @return list of blocking services and their security info classes that this server supports
 */
protected List<BlockingServiceAndInterface> getServices() {
  List<BlockingServiceAndInterface> bssi = new ArrayList<BlockingServiceAndInterface>(4);
  bssi.add(new BlockingServiceAndInterface(
    MasterService.newReflectiveBlockingService(this),
    MasterService.BlockingInterface.class));
  bssi.add(new BlockingServiceAndInterface(
    RegionServerStatusService.newReflectiveBlockingService(this),
    RegionServerStatusService.BlockingInterface.class));
  bssi.addAll(super.getServices());
  return bssi;
}
项目:ditb    文件:HRegionServer.java   
@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();
    ServerName sn = ServerName.parseVersionedServerName(this.serverName.getVersionedBytes());
    request.setServer(ProtobufUtil.toServerName(sn));
    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();
  }
}
项目:pbase    文件:MasterRpcServices.java   
/**
 * @return list of blocking services and their security info classes that this server supports
 */
protected List<BlockingServiceAndInterface> getServices() {
  List<BlockingServiceAndInterface> bssi = new ArrayList<BlockingServiceAndInterface>(4);
  bssi.add(new BlockingServiceAndInterface(
    MasterService.newReflectiveBlockingService(this),
    MasterService.BlockingInterface.class));
  bssi.add(new BlockingServiceAndInterface(
    RegionServerStatusService.newReflectiveBlockingService(this),
    RegionServerStatusService.BlockingInterface.class));
  bssi.addAll(super.getServices());
  return bssi;
}
项目:pbase    文件:HRegionServer.java   
@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();
        ServerName sn = ServerName.parseVersionedServerName(
                this.serverName.getVersionedBytes());
        request.setServer(ProtobufUtil.toServerName(sn));
        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();
    }
}
项目:pbase    文件:HRegionServer.java   
@Override
public boolean reportRegionStateTransition(
        TransitionCode code, long openSeqNum, HRegionInfo... hris) {
    ReportRegionStateTransitionRequest.Builder builder =
            ReportRegionStateTransitionRequest.newBuilder();
    builder.setServer(ProtobufUtil.toServerName(serverName));
    RegionStateTransition.Builder transition = builder.addTransitionBuilder();
    transition.setTransitionCode(code);
    if (code == TransitionCode.OPENED && openSeqNum >= 0) {
        transition.setOpenSeqNum(openSeqNum);
    }
    for (HRegionInfo hri : hris) {
        transition.addRegionInfo(HRegionInfo.convert(hri));
    }
    ReportRegionStateTransitionRequest request = builder.build();
    while (keepLooping()) {
        RegionServerStatusService.BlockingInterface rss = rssStub;
        try {
            if (rss == null) {
                createRegionServerStatusStub();
                continue;
            }
            ReportRegionStateTransitionResponse response =
                    rss.reportRegionStateTransition(null, request);
            if (response.hasErrorMessage()) {
                LOG.info("Failed to transition " + hris[0]
                        + " to " + code + ": " + response.getErrorMessage());
                return false;
            }
            return true;
        } catch (ServiceException se) {
            IOException ioe = ProtobufUtil.getRemoteException(se);
            LOG.info("Failed to report region transition, will retry", ioe);
            if (rssStub == rss) {
                rssStub = null;
            }
        }
    }
    return false;
}
项目:HIndex    文件:HRegionServer.java   
@VisibleForTesting
protected void tryRegionServerReport(long reportStartTime, long reportEndTime)
throws IOException {
  if (this.rssStub == null) {
    // the current server is stopping.
    return;
  }
  ClusterStatusProtos.ServerLoad sl = buildServerLoad(reportStartTime, reportEndTime);
  try {
    RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();
    ServerName sn = ServerName.parseVersionedServerName(
      this.serverNameFromMasterPOV.getVersionedBytes());
    request.setServer(ProtobufUtil.toServerName(sn));
    request.setLoad(sl);
    this.rssStub.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;
    }
    // Couldn't connect to the master, get location from zk and reconnect
    // Method blocks until new master is found or we are stopped
    Pair<ServerName, RegionServerStatusService.BlockingInterface> p =
      createRegionServerStatusStub();
    this.rssStub = p.getSecond();
  }
}
项目:HIndex    文件:HRegionServer.java   
private RegionServerStartupResponse reportForDuty() throws IOException {
  RegionServerStartupResponse result = null;
  Pair<ServerName, RegionServerStatusService.BlockingInterface> p =
    createRegionServerStatusStub();
  this.rssStub = p.getSecond();
  ServerName masterServerName = p.getFirst();
  if (masterServerName == null) return result;
  try {
    this.requestCount.set(0);
    LOG.info("reportForDuty to master=" + masterServerName + " with port=" + this.isa.getPort() +
      ", startcode=" + this.startcode);
    long now = EnvironmentEdgeManager.currentTimeMillis();
    int port = this.isa.getPort();
    RegionServerStartupRequest.Builder request = RegionServerStartupRequest.newBuilder();
    request.setPort(port);
    request.setServerStartCode(this.startcode);
    request.setServerCurrentTime(now);
    result = this.rssStub.regionServerStartup(null, request.build());
  } catch (ServiceException se) {
    IOException ioe = ProtobufUtil.getRemoteException(se);
    if (ioe instanceof ClockOutOfSyncException) {
      LOG.fatal("Master rejected startup because clock is out of sync", ioe);
      // Re-throw IOE will cause RS to abort
      throw ioe;
    } else if (ioe instanceof ServerNotRunningYetException) {
      LOG.debug("Master is not running yet");
    } else {
      LOG.warn("error telling master we are up", se);
    }
  }
  return result;
}
项目:PyroDB    文件:MasterRpcServices.java   
/**
 * @return list of blocking services and their security info classes that this server supports
 */
protected List<BlockingServiceAndInterface> getServices() {
  List<BlockingServiceAndInterface> bssi = new ArrayList<BlockingServiceAndInterface>(4);
  bssi.add(new BlockingServiceAndInterface(
    MasterService.newReflectiveBlockingService(this),
    MasterService.BlockingInterface.class));
  bssi.add(new BlockingServiceAndInterface(
    RegionServerStatusService.newReflectiveBlockingService(this),
    RegionServerStatusService.BlockingInterface.class));
  bssi.addAll(super.getServices());
  return bssi;
}
项目:PyroDB    文件:HRegionServer.java   
@VisibleForTesting
protected void tryRegionServerReport(long reportStartTime, long reportEndTime)
throws IOException {
  if (this.rssStub == null) {
    // the current server is stopping.
    return;
  }
  ClusterStatusProtos.ServerLoad sl = buildServerLoad(reportStartTime, reportEndTime);
  try {
    RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();
    ServerName sn = ServerName.parseVersionedServerName(
      this.serverName.getVersionedBytes());
    request.setServer(ProtobufUtil.toServerName(sn));
    request.setLoad(sl);
    this.rssStub.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;
    }
    // Couldn't connect to the master, get location from zk and reconnect
    // Method blocks until new master is found or we are stopped
    Pair<ServerName, RegionServerStatusService.BlockingInterface> p =
      createRegionServerStatusStub();
    this.rssStub = p.getSecond();
  }
}
项目:PyroDB    文件:HRegionServer.java   
private RegionServerStartupResponse reportForDuty() throws IOException {
  RegionServerStartupResponse result = null;
  Pair<ServerName, RegionServerStatusService.BlockingInterface> p =
    createRegionServerStatusStub();
  this.rssStub = p.getSecond();
  ServerName masterServerName = p.getFirst();
  if (masterServerName == null) return result;
  try {
    rpcServices.requestCount.set(0);
    LOG.info("reportForDuty to master=" + masterServerName + " with port="
      + rpcServices.isa.getPort() + ", startcode=" + this.startcode);
    long now = EnvironmentEdgeManager.currentTimeMillis();
    int port = rpcServices.isa.getPort();
    RegionServerStartupRequest.Builder request = RegionServerStartupRequest.newBuilder();
    request.setPort(port);
    request.setServerStartCode(this.startcode);
    request.setServerCurrentTime(now);
    result = this.rssStub.regionServerStartup(null, request.build());
  } catch (ServiceException se) {
    IOException ioe = ProtobufUtil.getRemoteException(se);
    if (ioe instanceof ClockOutOfSyncException) {
      LOG.fatal("Master rejected startup because clock is out of sync", ioe);
      // Re-throw IOE will cause RS to abort
      throw ioe;
    } else if (ioe instanceof ServerNotRunningYetException) {
      LOG.debug("Master is not running yet");
    } else {
      LOG.warn("error telling master we are up", se);
    }
  }
  return result;
}
项目:c5    文件:HRegionServer.java   
void tryRegionServerReport(long reportStartTime, long reportEndTime)
throws IOException {
  if (this.rssStub == null) {
    // the current server is stopping.
    return;
  }
  ClusterStatusProtos.ServerLoad sl = buildServerLoad(reportStartTime, reportEndTime);
  try {
    RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();
    ServerName sn = ServerName.parseVersionedServerName(
      this.serverNameFromMasterPOV.getVersionedBytes());
    request.setServer(ProtobufUtil.toServerName(sn));
    request.setLoad(sl);
    this.rssStub.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;
    }
    // Couldn't connect to the master, get location from zk and reconnect
    // Method blocks until new master is found or we are stopped
    Pair<ServerName, RegionServerStatusService.BlockingInterface> p =
      createRegionServerStatusStub();
    this.rssStub = p.getSecond();
  }
}
项目:c5    文件:HRegionServer.java   
private RegionServerStartupResponse reportForDuty() throws IOException {
  RegionServerStartupResponse result = null;
  Pair<ServerName, RegionServerStatusService.BlockingInterface> p =
    createRegionServerStatusStub();
  this.rssStub = p.getSecond();
  ServerName masterServerName = p.getFirst();
  if (masterServerName == null) return result;
  try {
    this.requestCount.set(0);
    LOG.info("reportForDuty to master=" + masterServerName + " with port=" + this.isa.getPort() +
      ", startcode=" + this.startcode);
    long now = EnvironmentEdgeManager.currentTimeMillis();
    int port = this.isa.getPort();
    RegionServerStartupRequest.Builder request = RegionServerStartupRequest.newBuilder();
    request.setPort(port);
    request.setServerStartCode(this.startcode);
    request.setServerCurrentTime(now);
    result = this.rssStub.regionServerStartup(null, request.build());
  } catch (ServiceException se) {
    IOException ioe = ProtobufUtil.getRemoteException(se);
    if (ioe instanceof ClockOutOfSyncException) {
      LOG.fatal("Master rejected startup because clock is out of sync", ioe);
      // Re-throw IOE will cause RS to abort
      throw ioe;
    } else if (ioe instanceof ServerNotRunningYetException) {
      LOG.debug("Master is not running yet");
    } else {
      LOG.warn("error telling master we are up", se);
    }
  }
  return result;
}
项目:ditb    文件:HRegionServer.java   
@Override public boolean reportRegionStateTransition(final RegionStateTransitionContext context) {
  TransitionCode code = context.getCode();
  long openSeqNum = context.getOpenSeqNum();
  HRegionInfo[] hris = context.getHris();

  ReportRegionStateTransitionRequest.Builder builder =
      ReportRegionStateTransitionRequest.newBuilder();
  builder.setServer(ProtobufUtil.toServerName(serverName));
  RegionStateTransition.Builder transition = builder.addTransitionBuilder();
  transition.setTransitionCode(code);
  if (code == TransitionCode.OPENED && openSeqNum >= 0) {
    transition.setOpenSeqNum(openSeqNum);
  }
  for (HRegionInfo hri : hris) {
    transition.addRegionInfo(HRegionInfo.convert(hri));
  }
  ReportRegionStateTransitionRequest request = builder.build();
  while (keepLooping()) {
    RegionServerStatusService.BlockingInterface rss = rssStub;
    try {
      if (rss == null) {
        createRegionServerStatusStub();
        continue;
      }
      ReportRegionStateTransitionResponse response =
          rss.reportRegionStateTransition(null, request);
      if (response.hasErrorMessage()) {
        LOG.info("Failed to transition " + hris[0] + " to " + code + ": " + response
            .getErrorMessage());
        return false;
      }
      return true;
    } catch (ServiceException se) {
      IOException ioe = ProtobufUtil.getRemoteException(se);
      LOG.info("Failed to report region transition, will retry", ioe);
      if (rssStub == rss) {
        rssStub = null;
      }
    }
  }
  return false;
}
项目:ditb    文件:HRegionServer.java   
/**
 * Get the current master from ZooKeeper and open the RPC connection to it.
 * To get a fresh connection, the current rssStub must be null.
 * Method will block until a master is available. You can break from this
 * block by requesting the server stop.
 *
 * @return master + port, or null if server has been stopped
 */
@VisibleForTesting protected synchronized ServerName createRegionServerStatusStub() {
  if (rssStub != null) {
    return masterAddressTracker.getMasterAddress();
  }
  ServerName sn = null;
  long previousLogTime = 0;
  boolean refresh = false; // for the first time, use cached data
  RegionServerStatusService.BlockingInterface intf = null;
  boolean interrupted = false;
  try {
    while (keepLooping()) {
      sn = this.masterAddressTracker.getMasterAddress(refresh);
      if (sn == null) {
        if (!keepLooping()) {
          // give up with no connection.
          LOG.debug("No master found and cluster is stopped; bailing out");
          return null;
        }
        if (System.currentTimeMillis() > (previousLogTime + 1000)) {
          LOG.debug("No master found; retry");
          previousLogTime = System.currentTimeMillis();
        }
        refresh = true; // let's try pull it from ZK directly
        if (sleep(200)) {
          interrupted = true;
        }
        continue;
      }

      // If we are on the active master, use the shortcut
      if (this instanceof HMaster && sn.equals(getServerName())) {
        intf = ((HMaster) this).getMasterRpcServices();
        break;
      }
      try {
        BlockingRpcChannel channel = this.rpcClient
            .createBlockingRpcChannel(sn, userProvider.getCurrent(), shortOperationTimeout);
        intf = RegionServerStatusService.newBlockingStub(channel);
        break;
      } catch (IOException e) {
        if (System.currentTimeMillis() > (previousLogTime + 1000)) {
          e = e instanceof RemoteException ? ((RemoteException) e).unwrapRemoteException() : e;
          if (e instanceof ServerNotRunningYetException) {
            LOG.info("Master isn't available yet, retrying");
          } else {
            LOG.warn("Unable to connect to master. Retrying. Error was:", e);
          }
          previousLogTime = System.currentTimeMillis();
        }
        if (sleep(200)) {
          interrupted = true;
        }
      }
    }
  } finally {
    if (interrupted) {
      Thread.currentThread().interrupt();
    }
  }
  rssStub = intf;
  return sn;
}
项目:pbase    文件:HRegionServer.java   
/**
 * Get the current master from ZooKeeper and open the RPC connection to it.
 * <p/>
 * Method will block until a master is available. You can break from this
 * block by requesting the server stop.
 *
 * @return master + port, or null if server has been stopped
 */
private synchronized ServerName createRegionServerStatusStub() {
    if (rssStub != null) {
        return masterAddressTracker.getMasterAddress();
    }
    ServerName sn = null;
    long previousLogTime = 0;
    boolean refresh = false; // for the first time, use cached data
    RegionServerStatusService.BlockingInterface intf = null;
    boolean interrupted = false;
    try {
        while (keepLooping()) {
            sn = this.masterAddressTracker.getMasterAddress(refresh);
            if (sn == null) {
                if (!keepLooping()) {
                    // give up with no connection.
                    LOG.debug("No master found and cluster is stopped; bailing out");
                    return null;
                }
                if (System.currentTimeMillis() > (previousLogTime + 1000)) {
                    LOG.debug("No master found; retry");
                    previousLogTime = System.currentTimeMillis();
                }
                refresh = true; // let's try pull it from ZK directly
                if (sleep(200)) {
                    interrupted = true;
                }
                continue;
            }

            // If we are on the active master, use the shortcut
            if (this instanceof HMaster && sn.equals(getServerName())) {
                intf = ((HMaster) this).getMasterRpcServices();
                break;
            }
            try {
                BlockingRpcChannel channel =
                        this.rpcClient.createBlockingRpcChannel(sn, userProvider.getCurrent(), operationTimeout);
                intf = RegionServerStatusService.newBlockingStub(channel);
                break;
            } catch (IOException e) {
                if (System.currentTimeMillis() > (previousLogTime + 1000)) {
                    e = e instanceof RemoteException ?
                            ((RemoteException) e).unwrapRemoteException() : e;
                    if (e instanceof ServerNotRunningYetException) {
                        LOG.info("Master isn't available yet, retrying");
                    } else {
                        LOG.warn("Unable to connect to master. Retrying. Error was:", e);
                    }
                    previousLogTime = System.currentTimeMillis();
                }
                if (sleep(200)) {
                    interrupted = true;
                }
            }
        }
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }
    rssStub = intf;
    return sn;
}
项目:HIndex    文件:HRegionServer.java   
/**
 * Get the current master from ZooKeeper and open the RPC connection to it.
 *
 * Method will block until a master is available. You can break from this
 * block by requesting the server stop.
 *
 * @return master + port, or null if server has been stopped
 */
private Pair<ServerName, RegionServerStatusService.BlockingInterface>
createRegionServerStatusStub() {
  ServerName sn = null;
  long previousLogTime = 0;
  RegionServerStatusService.BlockingInterface master = null;
  boolean refresh = false; // for the first time, use cached data
  RegionServerStatusService.BlockingInterface intf = null;
  while (keepLooping() && master == null) {
    sn = this.masterAddressTracker.getMasterAddress(refresh);
    if (sn == null) {
      if (!keepLooping()) {
        // give up with no connection.
        LOG.debug("No master found and cluster is stopped; bailing out");
        return null;
      }
      LOG.debug("No master found; retry");
      previousLogTime = System.currentTimeMillis();
      refresh = true; // let's try pull it from ZK directly
      sleeper.sleep();
      continue;
    }

    new InetSocketAddress(sn.getHostname(), sn.getPort());
    try {
      BlockingRpcChannel channel =
          this.rpcClient.createBlockingRpcChannel(sn, userProvider.getCurrent(), this.rpcTimeout);
      intf = RegionServerStatusService.newBlockingStub(channel);
      break;
    } catch (IOException e) {
      e = e instanceof RemoteException ?
          ((RemoteException)e).unwrapRemoteException() : e;
      if (e instanceof ServerNotRunningYetException) {
        if (System.currentTimeMillis() > (previousLogTime+1000)){
          LOG.info("Master isn't available yet, retrying");
          previousLogTime = System.currentTimeMillis();
        }
      } else {
        if (System.currentTimeMillis() > (previousLogTime + 1000)) {
          LOG.warn("Unable to connect to master. Retrying. Error was:", e);
          previousLogTime = System.currentTimeMillis();
        }
      }
      try {
        Thread.sleep(200);
      } catch (InterruptedException ignored) {
      }
    }
  }
  return new Pair<ServerName, RegionServerStatusService.BlockingInterface>(sn, intf);
}
项目:PyroDB    文件:HRegionServer.java   
/**
 * Get the current master from ZooKeeper and open the RPC connection to it.
 *
 * Method will block until a master is available. You can break from this
 * block by requesting the server stop.
 *
 * @return master + port, or null if server has been stopped
 */
private Pair<ServerName, RegionServerStatusService.BlockingInterface>
    createRegionServerStatusStub() {
  ServerName sn = null;
  long previousLogTime = 0;
  RegionServerStatusService.BlockingInterface master = null;
  boolean refresh = false; // for the first time, use cached data
  RegionServerStatusService.BlockingInterface intf = null;
  boolean interrupted = false;
  try {
    while (keepLooping() && master == null) {
      sn = this.masterAddressTracker.getMasterAddress(refresh);
      if (sn == null) {
        if (!keepLooping()) {
          // give up with no connection.
          LOG.debug("No master found and cluster is stopped; bailing out");
          return null;
        }
        LOG.debug("No master found; retry");
        previousLogTime = System.currentTimeMillis();
        refresh = true; // let's try pull it from ZK directly
        sleeper.sleep();
        continue;
      }

      // If we are on the active master, use the shortcut
      if (this instanceof HMaster && sn.equals(getServerName())) {
        intf = ((HMaster)this).getMasterRpcServices();
        break;
      }
      try {
        BlockingRpcChannel channel =
          this.rpcClient.createBlockingRpcChannel(sn, userProvider.getCurrent(), operationTimeout);
        intf = RegionServerStatusService.newBlockingStub(channel);
        break;
      } catch (IOException e) {
        e = e instanceof RemoteException ?
          ((RemoteException)e).unwrapRemoteException() : e;
        if (e instanceof ServerNotRunningYetException) {
          if (System.currentTimeMillis() > (previousLogTime+1000)){
            LOG.info("Master isn't available yet, retrying");
            previousLogTime = System.currentTimeMillis();
          }
        } else {
          if (System.currentTimeMillis() > (previousLogTime + 1000)) {
            LOG.warn("Unable to connect to master. Retrying. Error was:", e);
            previousLogTime = System.currentTimeMillis();
          }
        }
        try {
          Thread.sleep(200);
        } catch (InterruptedException ex) {
          interrupted = true;
          LOG.warn("Interrupted while sleeping");
        }
      }
    }
  } finally {
    if (interrupted) {
      Thread.currentThread().interrupt();
    }
  }
  return new Pair<ServerName, RegionServerStatusService.BlockingInterface>(sn, intf);
}
项目:c5    文件:HRegionServer.java   
/**
 * Get the current master from ZooKeeper and open the RPC connection to it.
 *
 * Method will block until a master is available. You can break from this
 * block by requesting the server stop.
 *
 * @return master + port, or null if server has been stopped
 */
private Pair<ServerName, RegionServerStatusService.BlockingInterface>
createRegionServerStatusStub() {
  ServerName sn = null;
  long previousLogTime = 0;
  RegionServerStatusService.BlockingInterface master = null;
  boolean refresh = false; // for the first time, use cached data
  RegionServerStatusService.BlockingInterface intf = null;
  while (keepLooping() && master == null) {
    sn = this.masterAddressManager.getMasterAddress(refresh);
    if (sn == null) {
      if (!keepLooping()) {
        // give up with no connection.
        LOG.debug("No master found and cluster is stopped; bailing out");
        return null;
      }
      LOG.debug("No master found; retry");
      previousLogTime = System.currentTimeMillis();
      refresh = true; // let's try pull it from ZK directly
      sleeper.sleep();
      continue;
    }

    new InetSocketAddress(sn.getHostname(), sn.getPort());
    try {
      BlockingRpcChannel channel =
          this.rpcClient.createBlockingRpcChannel(sn, userProvider.getCurrent(), this.rpcTimeout);
      intf = RegionServerStatusService.newBlockingStub(channel);
      break;
    } catch (IOException e) {
      e = e instanceof RemoteException ?
          ((RemoteException)e).unwrapRemoteException() : e;
      if (e instanceof ServerNotRunningYetException) {
        if (System.currentTimeMillis() > (previousLogTime+1000)){
          LOG.info("Master isn't available yet, retrying");
          previousLogTime = System.currentTimeMillis();
        }
      } else {
        if (System.currentTimeMillis() > (previousLogTime + 1000)) {
          LOG.warn("Unable to connect to master. Retrying. Error was:", e);
          previousLogTime = System.currentTimeMillis();
        }
      }
      try {
        Thread.sleep(200);
      } catch (InterruptedException ignored) {
      }
    }
  }
  return new Pair<ServerName, RegionServerStatusService.BlockingInterface>(sn, intf);
}