Search in sources :

Example 1 with RegionServerStartupResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse 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 RegionServerStartupResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse in project hbase by apache.

the class MasterRpcServices method regionServerStartup.

@Override
public RegionServerStartupResponse regionServerStartup(RpcController controller, RegionServerStartupRequest request) throws ServiceException {
    // Register with server manager
    try {
        master.checkServiceStarted();
        InetAddress ia = master.getRemoteInetAddress(request.getPort(), request.getServerStartCode());
        // if regionserver passed hostname to use,
        // then use it instead of doing a reverse DNS lookup
        ServerName rs = master.getServerManager().regionServerStartup(request, ia);
        // Send back some config info
        RegionServerStartupResponse.Builder resp = createConfigurationSubset();
        NameStringPair.Builder entry = NameStringPair.newBuilder().setName(HConstants.KEY_FOR_HOSTNAME_SEEN_BY_MASTER).setValue(rs.getHostname());
        resp.addMapEntries(entry.build());
        return resp.build();
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair) ServerName(org.apache.hadoop.hbase.ServerName) RegionServerStartupResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) InetAddress(java.net.InetAddress)

Example 3 with RegionServerStartupResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse in project hbase by apache.

the class HRegionServer method run.

/**
   * The HRegionServer sticks in this loop until closed.
   */
@Override
public void run() {
    try {
        // Do pre-registration initializations; zookeeper, lease threads, etc.
        preRegistrationInitialization();
    } catch (Throwable e) {
        abort("Fatal exception during initialization", e);
    }
    try {
        if (!isStopped() && !isAborted()) {
            ShutdownHook.install(conf, fs, this, Thread.currentThread());
            // Initialize the RegionServerCoprocessorHost now that our ephemeral
            // node was created, in case any coprocessors want to use ZooKeeper
            this.rsHost = new RegionServerCoprocessorHost(this, this.conf);
        }
        // server is stopped or the clusterup flag is down or hdfs went wacky.
        while (keepLooping()) {
            RegionServerStartupResponse w = reportForDuty();
            if (w == null) {
                LOG.warn("reportForDuty failed; sleeping and then retrying.");
                this.sleeper.sleep();
            } else {
                handleReportForDutyResponse(w);
                break;
            }
        }
        if (!isStopped() && isHealthy()) {
            // start the snapshot handler and other procedure handlers,
            // since the server is ready to run
            rspmHost.start();
            // Start the Quota Manager
            rsQuotaManager.start(getRpcServer().getScheduler());
        }
        // We registered with the Master.  Go into run mode.
        long lastMsg = System.currentTimeMillis();
        long oldRequestCount = -1;
        // The main run loop.
        while (!isStopped() && isHealthy()) {
            if (!isClusterUp()) {
                if (isOnlineRegionsEmpty()) {
                    stop("Exiting; cluster shutdown set and not carrying any regions");
                } else if (!this.stopping) {
                    this.stopping = true;
                    LOG.info("Closing user regions");
                    closeUserRegions(this.abortRequested);
                } else if (this.stopping) {
                    boolean allUserRegionsOffline = areAllUserRegionsOffline();
                    if (allUserRegionsOffline) {
                        // meta regions will be closed on our way out.
                        if (oldRequestCount == getWriteRequestCount()) {
                            stop("Stopped; only catalog regions remaining online");
                            break;
                        }
                        oldRequestCount = getWriteRequestCount();
                    } else {
                        // Make sure all regions have been closed -- some regions may
                        // have not got it because we were splitting at the time of
                        // the call to closeUserRegions.
                        closeUserRegions(this.abortRequested);
                    }
                    LOG.debug("Waiting on " + getOnlineRegionsAsPrintableString());
                }
            }
            long now = System.currentTimeMillis();
            if ((now - lastMsg) >= msgInterval) {
                tryRegionServerReport(lastMsg, now);
                lastMsg = System.currentTimeMillis();
            }
            if (!isStopped() && !isAborted()) {
                this.sleeper.sleep();
            }
        }
    // for
    } catch (Throwable t) {
        if (!rpcServices.checkOOME(t)) {
            String prefix = t instanceof YouAreDeadException ? "" : "Unhandled: ";
            abort(prefix + t.getMessage(), t);
        }
    }
    // Run shutdown.
    if (mxBean != null) {
        MBeans.unregister(mxBean);
        mxBean = null;
    }
    if (this.leases != null)
        this.leases.closeAfterLeasesExpire();
    if (this.splitLogWorker != null) {
        splitLogWorker.stop();
    }
    if (this.infoServer != null) {
        LOG.info("Stopping infoServer");
        try {
            this.infoServer.stop();
        } catch (Exception e) {
            LOG.error("Failed to stop infoServer", e);
        }
    }
    // Send cache a shutdown.
    if (cacheConfig != null && cacheConfig.isBlockCacheEnabled()) {
        cacheConfig.getBlockCache().shutdown();
    }
    mobCacheConfig.getMobFileCache().shutdown();
    if (movedRegionsCleaner != null) {
        movedRegionsCleaner.stop("Region Server stopping");
    }
    // TODO: Should we check they are alive? If OOME could have exited already
    if (this.hMemManager != null)
        this.hMemManager.stop();
    if (this.cacheFlusher != null)
        this.cacheFlusher.interruptIfNecessary();
    if (this.compactSplitThread != null)
        this.compactSplitThread.interruptIfNecessary();
    if (this.compactionChecker != null)
        this.compactionChecker.cancel(true);
    if (this.healthCheckChore != null)
        this.healthCheckChore.cancel(true);
    if (this.nonceManagerChore != null)
        this.nonceManagerChore.cancel(true);
    if (this.storefileRefresher != null)
        this.storefileRefresher.cancel(true);
    sendShutdownInterrupt();
    // Stop the quota manager
    if (rsQuotaManager != null) {
        rsQuotaManager.stop();
    }
    // Stop the snapshot and other procedure handlers, forcefully killing all running tasks
    if (rspmHost != null) {
        rspmHost.stop(this.abortRequested || this.killed);
    }
    if (this.killed) {
    // Just skip out w/o closing regions.  Used when testing.
    } else if (abortRequested) {
        if (this.fsOk) {
            // Don't leave any open file handles
            closeUserRegions(abortRequested);
        }
        LOG.info("aborting server " + this.serverName);
    } else {
        closeUserRegions(abortRequested);
        LOG.info("stopping server " + this.serverName);
    }
    // so callers waiting for meta without timeout can stop
    if (this.metaTableLocator != null)
        this.metaTableLocator.stop();
    if (this.clusterConnection != null && !clusterConnection.isClosed()) {
        try {
            this.clusterConnection.close();
        } catch (IOException e) {
            // Although the {@link Closeable} interface throws an {@link
            // IOException}, in reality, the implementation would never do that.
            LOG.warn("Attempt to close server's short circuit ClusterConnection failed.", e);
        }
    }
    // Closing the compactSplit thread before closing meta regions
    if (!this.killed && containsMetaTableRegions()) {
        if (!abortRequested || this.fsOk) {
            if (this.compactSplitThread != null) {
                this.compactSplitThread.join();
                this.compactSplitThread = null;
            }
            closeMetaTableRegions(abortRequested);
        }
    }
    if (!this.killed && this.fsOk) {
        waitOnAllRegionsToClose(abortRequested);
        LOG.info("stopping server " + this.serverName + "; all regions closed.");
    }
    //fsOk flag may be changed when closing regions throws exception.
    if (this.fsOk) {
        shutdownWAL(!abortRequested);
    }
    // Make sure the proxy is down.
    if (this.rssStub != null) {
        this.rssStub = null;
    }
    if (this.lockStub != null) {
        this.lockStub = null;
    }
    if (this.rpcClient != null) {
        this.rpcClient.close();
    }
    if (this.leases != null) {
        this.leases.close();
    }
    if (this.pauseMonitor != null) {
        this.pauseMonitor.stop();
    }
    if (!killed) {
        stopServiceThreads();
    }
    if (this.rpcServices != null) {
        this.rpcServices.stop();
    }
    try {
        deleteMyEphemeralNode();
    } catch (KeeperException.NoNodeException nn) {
    } catch (KeeperException e) {
        LOG.warn("Failed deleting my ephemeral node", e);
    }
    // We may have failed to delete the znode at the previous step, but
    //  we delete the file anyway: a second attempt to delete the znode is likely to fail again.
    ZNodeClearer.deleteMyEphemeralNodeOnDisk();
    if (this.zooKeeper != null) {
        this.zooKeeper.close();
    }
    LOG.info("stopping server " + this.serverName + "; zookeeper connection closed.");
    LOG.info(Thread.currentThread().getName() + " exiting");
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) RegionServerStartupResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse) YouAreDeadException(org.apache.hadoop.hbase.YouAreDeadException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) RegionMovedException(org.apache.hadoop.hbase.exceptions.RegionMovedException) MalformedObjectNameException(javax.management.MalformedObjectNameException) RegionOpeningException(org.apache.hadoop.hbase.exceptions.RegionOpeningException) InterruptedIOException(java.io.InterruptedIOException) ClockOutOfSyncException(org.apache.hadoop.hbase.ClockOutOfSyncException) YouAreDeadException(org.apache.hadoop.hbase.YouAreDeadException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) BindException(java.net.BindException) KeeperException(org.apache.zookeeper.KeeperException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException) RemoteException(org.apache.hadoop.ipc.RemoteException) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

IOException (java.io.IOException)3 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)3 RegionServerStartupResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse)3 InterruptedIOException (java.io.InterruptedIOException)2 ClockOutOfSyncException (org.apache.hadoop.hbase.ClockOutOfSyncException)2 ServerName (org.apache.hadoop.hbase.ServerName)2 ServerNotRunningYetException (org.apache.hadoop.hbase.ipc.ServerNotRunningYetException)2 BindException (java.net.BindException)1 InetAddress (java.net.InetAddress)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)1 YouAreDeadException (org.apache.hadoop.hbase.YouAreDeadException)1 RegionMovedException (org.apache.hadoop.hbase.exceptions.RegionMovedException)1 RegionOpeningException (org.apache.hadoop.hbase.exceptions.RegionOpeningException)1 UnknownProtocolException (org.apache.hadoop.hbase.exceptions.UnknownProtocolException)1 NameStringPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)1 RegionServerStartupRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest)1 RemoteException (org.apache.hadoop.ipc.RemoteException)1 KeeperException (org.apache.zookeeper.KeeperException)1