Search in sources :

Example 1 with ClockOutOfSyncException

use of org.apache.hadoop.hbase.ClockOutOfSyncException in project hbase by apache.

the class HRegionServer method reportForDuty.

/*
   * Let the master know we're here Run initialization using parameters passed
   * us by the master.
   * @return A Map of key/value configurations we got from the Master else
   * null if we failed to register.
   * @throws IOException
   */
private RegionServerStartupResponse reportForDuty() throws IOException {
    ServerName masterServerName = createRegionServerStatusStub(true);
    if (masterServerName == null)
        return null;
    RegionServerStartupResponse result = null;
    try {
        rpcServices.requestCount.reset();
        rpcServices.rpcGetRequestCount.reset();
        rpcServices.rpcScanRequestCount.reset();
        rpcServices.rpcMultiRequestCount.reset();
        rpcServices.rpcMutateRequestCount.reset();
        LOG.info("reportForDuty to master=" + masterServerName + " with port=" + rpcServices.isa.getPort() + ", startcode=" + this.startcode);
        long now = EnvironmentEdgeManager.currentTime();
        int port = rpcServices.isa.getPort();
        RegionServerStartupRequest.Builder request = RegionServerStartupRequest.newBuilder();
        if (shouldUseThisHostnameInstead()) {
            request.setUseThisHostnameInstead(useThisHostnameInstead);
        }
        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);
        }
        rssStub = null;
    }
    return result;
}
Also used : ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) ClockOutOfSyncException(org.apache.hadoop.hbase.ClockOutOfSyncException) ServerName(org.apache.hadoop.hbase.ServerName) RegionServerStartupResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException) RegionServerStartupRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest)

Example 2 with ClockOutOfSyncException

use of org.apache.hadoop.hbase.ClockOutOfSyncException in project hbase by apache.

the class TestClockSkewDetection method testClockSkewDetection.

@Test
public void testClockSkewDetection() throws Exception {
    final Configuration conf = HBaseConfiguration.create();
    ServerManager sm = new ServerManager(new MockNoopMasterServices(conf) {

        @Override
        public ClusterConnection getClusterConnection() {
            ClusterConnection conn = mock(ClusterConnection.class);
            when(conn.getRpcControllerFactory()).thenReturn(mock(RpcControllerFactory.class));
            return conn;
        }
    }, true);
    LOG.debug("regionServerStartup 1");
    InetAddress ia1 = InetAddress.getLocalHost();
    RegionServerStartupRequest.Builder request = RegionServerStartupRequest.newBuilder();
    request.setPort(1234);
    request.setServerStartCode(-1);
    request.setServerCurrentTime(System.currentTimeMillis());
    sm.regionServerStartup(request.build(), ia1);
    final Configuration c = HBaseConfiguration.create();
    long maxSkew = c.getLong("hbase.master.maxclockskew", 30000);
    long warningSkew = c.getLong("hbase.master.warningclockskew", 1000);
    try {
        //Master Time > Region Server Time
        LOG.debug("Test: Master Time > Region Server Time");
        LOG.debug("regionServerStartup 2");
        InetAddress ia2 = InetAddress.getLocalHost();
        request = RegionServerStartupRequest.newBuilder();
        request.setPort(1235);
        request.setServerStartCode(-1);
        request.setServerCurrentTime(System.currentTimeMillis() - maxSkew * 2);
        sm.regionServerStartup(request.build(), ia2);
        fail("HMaster should have thrown a ClockOutOfSyncException but didn't.");
    } catch (ClockOutOfSyncException e) {
        //we want an exception
        LOG.info("Recieved expected exception: " + e);
    }
    try {
        // Master Time < Region Server Time
        LOG.debug("Test: Master Time < Region Server Time");
        LOG.debug("regionServerStartup 3");
        InetAddress ia3 = InetAddress.getLocalHost();
        request = RegionServerStartupRequest.newBuilder();
        request.setPort(1236);
        request.setServerStartCode(-1);
        request.setServerCurrentTime(System.currentTimeMillis() + maxSkew * 2);
        sm.regionServerStartup(request.build(), ia3);
        fail("HMaster should have thrown a ClockOutOfSyncException but didn't.");
    } catch (ClockOutOfSyncException e) {
        // we want an exception
        LOG.info("Recieved expected exception: " + e);
    }
    // make sure values above warning threshold but below max threshold don't kill
    LOG.debug("regionServerStartup 4");
    InetAddress ia4 = InetAddress.getLocalHost();
    request = RegionServerStartupRequest.newBuilder();
    request.setPort(1237);
    request.setServerStartCode(-1);
    request.setServerCurrentTime(System.currentTimeMillis() - warningSkew * 2);
    sm.regionServerStartup(request.build(), ia4);
    // make sure values above warning threshold but below max threshold don't kill
    LOG.debug("regionServerStartup 5");
    InetAddress ia5 = InetAddress.getLocalHost();
    request = RegionServerStartupRequest.newBuilder();
    request.setPort(1238);
    request.setServerStartCode(-1);
    request.setServerCurrentTime(System.currentTimeMillis() + warningSkew * 2);
    sm.regionServerStartup(request.build(), ia5);
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ClockOutOfSyncException(org.apache.hadoop.hbase.ClockOutOfSyncException) InetAddress(java.net.InetAddress) RegionServerStartupRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest) Test(org.junit.Test)

Aggregations

ClockOutOfSyncException (org.apache.hadoop.hbase.ClockOutOfSyncException)2 RegionServerStartupRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 InetAddress (java.net.InetAddress)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 ServerName (org.apache.hadoop.hbase.ServerName)1 ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)1 ServerNotRunningYetException (org.apache.hadoop.hbase.ipc.ServerNotRunningYetException)1 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)1 RegionServerStartupResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse)1 Test (org.junit.Test)1