Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 935FA200CF6 for ; Sun, 23 Jul 2017 17:08:46 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 91E6C164753; Sun, 23 Jul 2017 15:08:46 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8739A16441D for ; Sun, 23 Jul 2017 17:08:44 +0200 (CEST) Received: (qmail 68412 invoked by uid 500); 23 Jul 2017 15:08:40 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 66396 invoked by uid 99); 23 Jul 2017 15:08:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Jul 2017 15:08:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 00D8CDFC25; Sun, 23 Jul 2017 15:08:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Sun, 23 Jul 2017 15:09:01 -0000 Message-Id: In-Reply-To: <10dce31be4034f58b712555cb49aa90c@git.apache.org> References: <10dce31be4034f58b712555cb49aa90c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [26/51] [partial] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd. archived-at: Sun, 23 Jul 2017 15:08:46 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/0383a9c2/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html index 5479fb1..49ef112 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/HMaster.InitializationMonitor.html @@ -123,3388 +123,3334 @@ 115import org.apache.hadoop.hbase.master.procedure.DeleteColumnFamilyProcedure; 116import org.apache.hadoop.hbase.master.procedure.DeleteTableProcedure; 117import org.apache.hadoop.hbase.master.procedure.DisableTableProcedure; -118import org.apache.hadoop.hbase.master.procedure.DispatchMergingRegionsProcedure; -119import org.apache.hadoop.hbase.master.procedure.EnableTableProcedure; -120import org.apache.hadoop.hbase.master.procedure.MasterProcedureConstants; -121import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; -122import org.apache.hadoop.hbase.master.procedure.MasterProcedureScheduler; -123import org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil; -124import org.apache.hadoop.hbase.master.procedure.ModifyColumnFamilyProcedure; -125import org.apache.hadoop.hbase.master.procedure.ModifyTableProcedure; -126import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch; -127import org.apache.hadoop.hbase.master.procedure.TruncateTableProcedure; -128import org.apache.hadoop.hbase.master.replication.ReplicationManager; -129import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; -130import org.apache.hadoop.hbase.mob.MobConstants; -131import org.apache.hadoop.hbase.monitoring.MemoryBoundedLogMessageBuffer; -132import org.apache.hadoop.hbase.monitoring.MonitoredTask; -133import org.apache.hadoop.hbase.monitoring.TaskMonitor; -134import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost; -135import org.apache.hadoop.hbase.procedure.flush.MasterFlushTableProcedureManager; -136import org.apache.hadoop.hbase.procedure2.LockInfo; -137import org.apache.hadoop.hbase.procedure2.ProcedureEvent; -138import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; -139import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore; -140import org.apache.hadoop.hbase.quotas.MasterQuotaManager; -141import org.apache.hadoop.hbase.quotas.MasterSpaceQuotaObserver; -142import org.apache.hadoop.hbase.quotas.QuotaObserverChore; -143import org.apache.hadoop.hbase.quotas.QuotaUtil; -144import org.apache.hadoop.hbase.quotas.SnapshotQuotaObserverChore; -145import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshotNotifier; -146import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshotNotifierFactory; -147import org.apache.hadoop.hbase.regionserver.DefaultStoreEngine; -148import org.apache.hadoop.hbase.regionserver.HRegionServer; -149import org.apache.hadoop.hbase.regionserver.HStore; -150import org.apache.hadoop.hbase.regionserver.RSRpcServices; -151import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; -152import org.apache.hadoop.hbase.regionserver.RegionSplitPolicy; -153import org.apache.hadoop.hbase.regionserver.compactions.ExploringCompactionPolicy; -154import org.apache.hadoop.hbase.regionserver.compactions.FIFOCompactionPolicy; -155import org.apache.hadoop.hbase.replication.ReplicationException; -156import org.apache.hadoop.hbase.replication.ReplicationFactory; -157import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; -158import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; -159import org.apache.hadoop.hbase.replication.ReplicationQueuesZKImpl; -160import org.apache.hadoop.hbase.replication.master.TableCFsUpdater; -161import org.apache.hadoop.hbase.replication.regionserver.Replication; -162import org.apache.hadoop.hbase.security.AccessDeniedException; -163import org.apache.hadoop.hbase.security.UserProvider; -164import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; -165import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse.CompactionState; -166import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionServerInfo; -167import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas; -168import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceViolationPolicy; -169import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription; -170import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos; -171import org.apache.hadoop.hbase.util.Addressing; -172import org.apache.hadoop.hbase.util.Bytes; -173import org.apache.hadoop.hbase.util.CompressionTest; -174import org.apache.hadoop.hbase.util.EncryptionTest; -175import org.apache.hadoop.hbase.util.FSUtils; -176import org.apache.hadoop.hbase.util.HFileArchiveUtil; -177import org.apache.hadoop.hbase.util.HasThread; -178import org.apache.hadoop.hbase.util.IdLock; -179import org.apache.hadoop.hbase.util.ModifyRegionUtils; -180import org.apache.hadoop.hbase.util.Pair; -181import org.apache.hadoop.hbase.util.Threads; -182import org.apache.hadoop.hbase.util.VersionInfo; -183import org.apache.hadoop.hbase.util.ZKDataMigrator; -184import org.apache.hadoop.hbase.zookeeper.DrainingServerTracker; -185import org.apache.hadoop.hbase.zookeeper.LoadBalancerTracker; -186import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker; -187import org.apache.hadoop.hbase.zookeeper.MasterMaintenanceModeTracker; -188import org.apache.hadoop.hbase.zookeeper.RegionNormalizerTracker; -189import org.apache.hadoop.hbase.zookeeper.RegionServerTracker; -190import org.apache.hadoop.hbase.zookeeper.SplitOrMergeTracker; -191import org.apache.hadoop.hbase.zookeeper.ZKClusterId; -192import org.apache.hadoop.hbase.zookeeper.ZKUtil; -193import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; -194import org.apache.zookeeper.KeeperException; -195import org.eclipse.jetty.server.Server; -196import org.eclipse.jetty.server.ServerConnector; -197import org.eclipse.jetty.servlet.ServletHolder; -198import org.eclipse.jetty.webapp.WebAppContext; -199 -200import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting; -201import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; -202import org.apache.hadoop.hbase.shaded.com.google.common.collect.Maps; -203import com.google.protobuf.Descriptors; -204import com.google.protobuf.Service; -205 -206/** -207 * HMaster is the "master server" for HBase. An HBase cluster has one active -208 * master. If many masters are started, all compete. Whichever wins goes on to -209 * run the cluster. All others park themselves in their constructor until -210 * master or cluster shutdown or until the active master loses its lease in -211 * zookeeper. Thereafter, all running master jostle to take over master role. -212 * -213 * <p>The Master can be asked shutdown the cluster. See {@link #shutdown()}. In -214 * this case it will tell all regionservers to go down and then wait on them -215 * all reporting in that they are down. This master will then shut itself down. -216 * -217 * <p>You can also shutdown just this master. Call {@link #stopMaster()}. -218 * -219 * @see org.apache.zookeeper.Watcher -220 */ -221@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS) -222@SuppressWarnings("deprecation") -223public class HMaster extends HRegionServer implements MasterServices { -224 private static final Log LOG = LogFactory.getLog(HMaster.class.getName()); -225 -226 /** -227 * Protection against zombie master. Started once Master accepts active responsibility and -228 * starts taking over responsibilities. Allows a finite time window before giving up ownership. -229 */ -230 private static class InitializationMonitor extends HasThread { -231 /** The amount of time in milliseconds to sleep before checking initialization status. */ -232 public static final String TIMEOUT_KEY = "hbase.master.initializationmonitor.timeout"; -233 public static final long TIMEOUT_DEFAULT = TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES); -234 -235 /** -236 * When timeout expired and initialization has not complete, call {@link System#exit(int)} when -237 * true, do nothing otherwise. -238 */ -239 public static final String HALT_KEY = "hbase.master.initializationmonitor.haltontimeout"; -240 public static final boolean HALT_DEFAULT = false; -241 -242 private final HMaster master; -243 private final long timeout; -244 private final boolean haltOnTimeout; -245 -246 /** Creates a Thread that monitors the {@link #isInitialized()} state. */ -247 InitializationMonitor(HMaster master) { -248 super("MasterInitializationMonitor"); -249 this.master = master; -250 this.timeout = master.getConfiguration().getLong(TIMEOUT_KEY, TIMEOUT_DEFAULT); -251 this.haltOnTimeout = master.getConfiguration().getBoolean(HALT_KEY, HALT_DEFAULT); -252 this.setDaemon(true); -253 } -254 -255 @Override -256 public void run() { -257 try { -258 while (!master.isStopped() && master.isActiveMaster()) { -259 Thread.sleep(timeout); -260 if (master.isInitialized()) { -261 LOG.debug("Initialization completed within allotted tolerance. Monitor exiting."); -262 } else { -263 LOG.error("Master failed to complete initialization after " + timeout + "ms. Please" -264 + " consider submitting a bug report including a thread dump of this process."); -265 if (haltOnTimeout) { -266 LOG.error("Zombie Master exiting. Thread dump to stdout"); -267 Threads.printThreadInfo(System.out, "Zombie HMaster"); -268 System.exit(-1); -269 } -270 } -271 } -272 } catch (InterruptedException ie) { -273 LOG.trace("InitMonitor thread interrupted. Existing."); -274 } -275 } -276 } -277 -278 // MASTER is name of the webapp and the attribute name used stuffing this -279 //instance into web context. -280 public static final String MASTER = "master"; -281 -282 // Manager and zk listener for master election -283 private final ActiveMasterManager activeMasterManager; -284 // Region server tracker -285 RegionServerTracker regionServerTracker; -286 // Draining region server tracker -287 private DrainingServerTracker drainingServerTracker; -288 // Tracker for load balancer state -289 LoadBalancerTracker loadBalancerTracker; -290 -291 // Tracker for split and merge state -292 private SplitOrMergeTracker splitOrMergeTracker; -293 -294 // Tracker for region normalizer state -295 private RegionNormalizerTracker regionNormalizerTracker; -296 -297 //Tracker for master maintenance mode setting -298 private MasterMaintenanceModeTracker maintenanceModeTracker; -299 -300 private ClusterSchemaService clusterSchemaService; -301 -302 // Metrics for the HMaster -303 final MetricsMaster metricsMaster; -304 // file system manager for the master FS operations -305 private MasterFileSystem fileSystemManager; -306 private MasterWalManager walManager; -307 -308 // server manager to deal with region server info -309 private volatile ServerManager serverManager; -310 -311 // manager of assignment nodes in zookeeper -312 private AssignmentManager assignmentManager; -313 -314 // manager of replication -315 private ReplicationManager replicationManager; -316 -317 // buffer for "fatal error" notices from region servers -318 // in the cluster. This is only used for assisting -319 // operations/debugging. -320 MemoryBoundedLogMessageBuffer rsFatals; -321 -322 // flag set after we become the active master (used for testing) -323 private volatile boolean activeMaster = false; -324 -325 // flag set after we complete initialization once active, -326 // it is not private since it's used in unit tests -327 private final ProcedureEvent initialized = new ProcedureEvent("master initialized"); -328 -329 // flag set after master services are started, -330 // initialization may have not completed yet. -331 volatile boolean serviceStarted = false; -332 -333 // flag set after we complete assignMeta. -334 private final ProcedureEvent serverCrashProcessingEnabled = -335 new ProcedureEvent("server crash processing"); -336 -337 // Maximum time we should run balancer for -338 private final int maxBlancingTime; -339 // Maximum percent of regions in transition when balancing -340 private final double maxRitPercent; -341 -342 private final LockManager lockManager = new LockManager(this); -343 -344 private LoadBalancer balancer; -345 private RegionNormalizer normalizer; -346 private BalancerChore balancerChore; -347 private RegionNormalizerChore normalizerChore; -348 private ClusterStatusChore clusterStatusChore; -349 private ClusterStatusPublisher clusterStatusPublisherChore = null; -350 -351 CatalogJanitor catalogJanitorChore; -352 private ReplicationMetaCleaner replicationMetaCleaner; -353 private ReplicationZKNodeCleanerChore replicationZKNodeCleanerChore; -354 private LogCleaner logCleaner; -355 private HFileCleaner hfileCleaner; -356 private ExpiredMobFileCleanerChore expiredMobFileCleanerChore; -357 private MobCompactionChore mobCompactChore; -358 private MasterMobCompactionThread mobCompactThread; -359 // used to synchronize the mobCompactionStates -360 private final IdLock mobCompactionLock = new IdLock(); -361 // save the information of mob compactions in tables. -362 // the key is table name, the value is the number of compactions in that table. -363 private Map<TableName, AtomicInteger> mobCompactionStates = Maps.newConcurrentMap(); -364 -365 MasterCoprocessorHost cpHost; -366 -367 private final boolean preLoadTableDescriptors; -368 -369 // Time stamps for when a hmaster became active -370 private long masterActiveTime; -371 -372 //should we check the compression codec type at master side, default true, HBASE-6370 -373 private final boolean masterCheckCompression; -374 -375 //should we check encryption settings at master side, default true -376 private final boolean masterCheckEncryption; -377 -378 Map<String, Service> coprocessorServiceHandlers = Maps.newHashMap(); -379 -380 // monitor for snapshot of hbase tables -381 SnapshotManager snapshotManager; -382 // monitor for distributed procedures -383 private MasterProcedureManagerHost mpmHost; -384 -385 // it is assigned after 'initialized' guard set to true, so should be volatile -386 private volatile MasterQuotaManager quotaManager; -387 private SpaceQuotaSnapshotNotifier spaceQuotaSnapshotNotifier; -388 private QuotaObserverChore quotaObserverChore; -389 private SnapshotQuotaObserverChore snapshotQuotaChore; -390 -391 private ProcedureExecutor<MasterProcedureEnv> procedureExecutor; -392 private WALProcedureStore procedureStore; -393 -394 // handle table states -395 private TableStateManager tableStateManager; -396 -397 private long splitPlanCount; -398 private long mergePlanCount; -399 -400 /** flag used in test cases in order to simulate RS failures during master initialization */ -401 private volatile boolean initializationBeforeMetaAssignment = false; -402 -403 /* Handle favored nodes information */ -404 private FavoredNodesManager favoredNodesManager; -405 -406 /** jetty server for master to redirect requests to regionserver infoServer */ -407 private Server masterJettyServer; -408 -409 public static class RedirectServlet extends HttpServlet { -410 private static final long serialVersionUID = 2894774810058302473L; -411 private final int regionServerInfoPort; -412 private final String regionServerHostname; -413 -414 /** -415 * @param infoServer that we're trying to send all requests to -416 * @param hostname may be null. if given, will be used for redirects instead of host from client. -417 */ -418 public RedirectServlet(InfoServer infoServer, String hostname) { -419 regionServerInfoPort = infoServer.getPort(); -420 regionServerHostname = hostname; -421 } -422 -423 @Override -424 public void doGet(HttpServletRequest request, -425 HttpServletResponse response) throws ServletException, IOException { -426 String redirectHost = regionServerHostname; -427 if(redirectHost == null) { -428 redirectHost = request.getServerName(); -429 if(!Addressing.isLocalAddress(InetAddress.getByName(redirectHost))) { -430 LOG.warn("Couldn't resolve '" + redirectHost + "' as an address local to this node and '" + -431 MASTER_HOSTNAME_KEY + "' is not set; client will get a HTTP 400 response. If " + -432 "your HBase deployment relies on client accessible names that the region server process " + -433 "can't resolve locally, then you should set the previously mentioned configuration variable " + -434 "to an appropriate hostname."); -435 // no sending client provided input back to the client, so the goal host is just in the logs. -436 response.sendError(400, "Request was to a host that I can't resolve for any of the network interfaces on " + -437 "this node. If this is due to an intermediary such as an HTTP load balancer or other proxy, your HBase " + -438 "administrator can set '" + MASTER_HOSTNAME_KEY + "' to point to the correct hostname."); -439 return; -440 } -441 } -442 // TODO this scheme should come from looking at the scheme registered in the infoserver's http server for the -443 // host and port we're using, but it's buried way too deep to do that ATM. -444 String redirectUrl = request.getScheme() + "://" -445 + redirectHost + ":" + regionServerInfoPort -446 + request.getRequestURI(); -447 response.sendRedirect(redirectUrl); -448 } -449 } -450 -451 /** -452 * Initializes the HMaster. The steps are as follows: -453 * <p> -454 * <ol> -455 * <li>Initialize the local HRegionServer -456 * <li>Start the ActiveMasterManager. -457 * </ol> -458 * <p> -459 * Remaining steps of initialization occur in -460 * #finishActiveMasterInitialization(MonitoredTask) after -461 * the master becomes the active one. -462 */ -463 public HMaster(final Configuration conf, CoordinatedStateManager csm) -464 throws IOException, KeeperException { -465 super(conf, csm); -466 this.rsFatals = new MemoryBoundedLogMessageBuffer( -467 conf.getLong("hbase.master.buffer.for.rs.fatals", 1*1024*1024)); -468 -469 LOG.info("hbase.rootdir=" + getRootDir() + -470 ", hbase.cluster.distributed=" + this.conf.getBoolean(HConstants.CLUSTER_DISTRIBUTED, false)); -471 -472 // Disable usage of meta replicas in the master -473 this.conf.setBoolean(HConstants.USE_META_REPLICAS, false); -474 -475 Replication.decorateMasterConfiguration(this.conf); -476 -477 // Hack! Maps DFSClient => Master for logs. HDFS made this -478 // config param for task trackers, but we can piggyback off of it. -479 if (this.conf.get("mapreduce.task.attempt.id") == null) { -480 this.conf.set("mapreduce.task.attempt.id", "hb_m_" + this.serverName.toString()); -481 } -482 -483 // should we check the compression codec type at master side, default true, HBASE-6370 -484 this.masterCheckCompression = conf.getBoolean("hbase.master.check.compression", true); -485 -486 // should we check encryption settings at master side, default true -487 this.masterCheckEncryption = conf.getBoolean("hbase.master.check.encryption", true); -488 -489 this.metricsMaster = new MetricsMaster(new MetricsMasterWrapperImpl(this)); -490 -491 // preload table descriptor at startup -492 this.preLoadTableDescriptors = conf.getBoolean("hbase.master.preload.tabledescriptors", true); -493 -494 this.maxBlancingTime = getMaxBalancingTime(); -495 this.maxRitPercent = conf.getDouble(HConstants.HBASE_MASTER_BALANCER_MAX_RIT_PERCENT, -496 HConstants.DEFAULT_HBASE_MASTER_BALANCER_MAX_RIT_PERCENT); -497 -498 // Do we publish the status? -499 -500 boolean shouldPublish = conf.getBoolean(HConstants.STATUS_PUBLISHED, -501 HConstants.STATUS_PUBLISHED_DEFAULT); -502 Class<? extends ClusterStatusPublisher.Publisher> publisherClass = -503 conf.getClass(ClusterStatusPublisher.STATUS_PUBLISHER_CLASS, -504 ClusterStatusPublisher.DEFAULT_STATUS_PUBLISHER_CLASS, -505 ClusterStatusPublisher.Publisher.class); -506 -507 if (shouldPublish) { -508 if (publisherClass == null) { -509 LOG.warn(HConstants.STATUS_PUBLISHED + " is true, but " + -510 ClusterStatusPublisher.DEFAULT_STATUS_PUBLISHER_CLASS + -511 " is not set - not publishing status"); -512 } else { -513 clusterStatusPublisherChore = new ClusterStatusPublisher(this, conf, publisherClass); -514 getChoreService().scheduleChore(clusterStatusPublisherChore); -515 } -516 } -517 -518 // Some unit tests don't need a cluster, so no zookeeper at all -519 if (!conf.getBoolean("hbase.testing.nocluster", false)) { -520 setInitLatch(new CountDownLatch(1)); -521 activeMasterManager = new ActiveMasterManager(zooKeeper, this.serverName, this); -522 int infoPort = putUpJettyServer(); -523 startActiveMasterManager(infoPort); -524 } else { -525 activeMasterManager = null; -526 } -527 } -528 -529 // return the actual infoPort, -1 means disable info server. -530 private int putUpJettyServer() throws IOException { -531 if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) { -532 return -1; -533 } -534 final int infoPort = conf.getInt("hbase.master.info.port.orig", -535 HConstants.DEFAULT_MASTER_INFOPORT); -536 // -1 is for disabling info server, so no redirecting -537 if (infoPort < 0 || infoServer == null) { -538 return -1; -539 } -540 if(infoPort == infoServer.getPort()) { -541 return infoPort; -542 } -543 final String addr = conf.get("hbase.master.info.bindAddress", "0.0.0.0"); -544 if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) { -545 String msg = -546 "Failed to start redirecting jetty server. Address " + addr -547 + " does not belong to this host. Correct configuration parameter: " -548 + "hbase.master.info.bindAddress"; -549 LOG.error(msg); -550 throw new IOException(msg); -551 } -552 -553 // TODO I'm pretty sure we could just add another binding to the InfoServer run by -554 // the RegionServer and have it run the RedirectServlet instead of standing up -555 // a second entire stack here. -556 masterJettyServer = new Server(); -557 final ServerConnector connector = new ServerConnector(masterJettyServer); -558 connector.setHost(addr); -559 connector.setPort(infoPort); -560 masterJettyServer.addConnector(connector); -561 masterJettyServer.setStopAtShutdown(true); -562 -563 final String redirectHostname = shouldUseThisHostnameInstead() ? useThisHostnameInstead : null; -564 -565 final RedirectServlet redirect = new RedirectServlet(infoServer, redirectHostname); -566 final WebAppContext context = new WebAppContext(null, "/", null, null, null, null, WebAppContext.NO_SESSIONS); -567 context.addServlet(new ServletHolder(redirect), "/*"); -568 context.setServer(masterJettyServer); -569 -570 try { -571 masterJettyServer.start(); -572 } catch (Exception e) { -573 throw new IOException("Failed to start redirecting jetty server", e); -574 } -575 return connector.getLocalPort(); -576 } -577 -578 @Override -579 protected TableDescriptors getFsTableDescriptors() throws IOException { -580 return super.getFsTableDescriptors(); -581 } -582 -583 /** -584 * For compatibility, if failed with regionserver credentials, try the master one -585 */ -586 @Override -587 protected void login(UserProvider user, String host) throws IOException { -588 try { -589 super.login(user, host); -590 } catch (IOException ie) { -591 user.login("hbase.master.keytab.file", -592 "hbase.master.kerberos.principal", host); -593 } -594 } -595 -596 /** -597 * If configured to put regions on active master, -598 * wait till a backup master becomes active. -599 * Otherwise, loop till the server is stopped or aborted. -600 */ -601 @Override -602 protected void waitForMasterActive(){ -603 boolean tablesOnMaster = BaseLoadBalancer.tablesOnMaster(conf); -604 while (!(tablesOnMaster && activeMaster) -605 && !isStopped() && !isAborted()) { -606 sleeper.sleep(); -607 } -608 } -609 -610 @VisibleForTesting -611 public MasterRpcServices getMasterRpcServices() { -612 return (MasterRpcServices)rpcServices; -613 } -614 -615 public boolean balanceSwitch(final boolean b) throws IOException { -616 return getMasterRpcServices().switchBalancer(b, BalanceSwitchMode.ASYNC); -617 } -618 -619 @Override -620 protected String getProcessName() { -621 return MASTER; -622 } -623 -624 @Override -625 protected boolean canCreateBaseZNode() { -626 return true; -627 } -628 -629 @Override -630 protected boolean canUpdateTableDescriptor() { -631 return true; -632 } -633 -634 @Override -635 protected RSRpcServices createRpcServices() throws IOException { -636 return new MasterRpcServices(this); -637 } -638 -639 @Override -640 protected void configureInfoServer() { -641 infoServer.addServlet("master-status", "/master-status", MasterStatusServlet.class); -642 infoServer.setAttribute(MASTER, this); -643 if (BaseLoadBalancer.tablesOnMaster(conf)) { -644 super.configureInfoServer(); -645 } -646 } -647 -648 @Override -649 protected Class<? extends HttpServlet> getDumpServlet() { -650 return MasterDumpServlet.class; -651 } -652 -653 @Override -654 public MetricsMaster getMasterMetrics() { -655 return metricsMaster; -656 } -657 -658 /** -659 * Initialize all ZK based system trackers. -660 */ -661 void initializeZKBasedSystemTrackers() throws IOException, -662 InterruptedException, KeeperException, CoordinatedStateException { -663 this.balancer = LoadBalancerFactory.getLoadBalancer(conf); -664 this.normalizer = RegionNormalizerFactory.getRegionNormalizer(conf); -665 this.normalizer.setMasterServices(this); -666 this.normalizer.setMasterRpcServices((MasterRpcServices)rpcServices); -667 this.loadBalancerTracker = new LoadBalancerTracker(zooKeeper, this); -668 this.loadBalancerTracker.start(); -669 -670 this.regionNormalizerTracker = new RegionNormalizerTracker(zooKeeper, this); -671 this.regionNormalizerTracker.start(); -672 -673 this.splitOrMergeTracker = new SplitOrMergeTracker(zooKeeper, conf, this); -674 this.splitOrMergeTracker.start(); -675 -676 // Create Assignment Manager -677 this.assignmentManager = new AssignmentManager(this); -678 this.assignmentManager.start(); -679 -680 this.replicationManager = new ReplicationManager(conf, zooKeeper, this); -681 -682 this.regionServerTracker = new RegionServerTracker(zooKeeper, this, this.serverManager); -683 this.regionServerTracker.start(); -684 -685 this.drainingServerTracker = new DrainingServerTracker(zooKeeper, this, this.serverManager); -686 this.drainingServerTracker.start(); -687 -688 this.maintenanceModeTracker = new MasterMaintenanceModeTracker(zooKeeper); -689 this.maintenanceModeTracker.start(); -690 -691 // Set the cluster as up. If new RSs, they'll be waiting on this before -692 // going ahead with their startup. -693 boolean wasUp = this.clusterStatusTracker.isClusterUp(); -694 if (!wasUp) this.clusterStatusTracker.setClusterUp(); -695 -696 LOG.info("Server active/primary master=" + this.serverName + -697 ", sessionid=0x" + -698 Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId()) + -699 ", setting cluster-up flag (Was=" + wasUp + ")"); -700 -701 // create/initialize the snapshot manager and other procedure managers -702 this.snapshotManager = new SnapshotManager(); -703 this.mpmHost = new MasterProcedureManagerHost(); -704 this.mpmHost.register(this.snapshotManager); -705 this.mpmHost.register(new MasterFlushTableProcedureManager()); -706 this.mpmHost.loadProcedures(conf); -707 this.mpmHost.initialize(this, this.metricsMaster); -708 } -709 -710 /** -711 * Finish initialization of HMaster after becoming the primary master. -712 * -713 * <ol> -714 * <li>Initialize master components - file system manager, server manager, -715 * assignment manager, region server tracker, etc</li> -716 * <li>Start necessary service threads - balancer, catalog janior, -717 * executor services, etc</li> -718 * <li>Set cluster as UP in ZooKeeper</li> -719 * <li>Wait for RegionServers to check-in</li> -720 * <li>Split logs and perform data recovery, if necessary</li> -721 * <li>Ensure assignment of meta/namespace regions<li> -722 * <li>Handle either fresh cluster start or master failover</li> -723 * </ol> -724 */ -725 private void finishActiveMasterInitialization(MonitoredTask status) -726 throws IOException, InterruptedException, KeeperException, CoordinatedStateException { -727 -728 activeMaster = true; -729 Thread zombieDetector = new Thread(new InitializationMonitor(this), -730 "ActiveMasterInitializationMonitor-" + System.currentTimeMillis()); -731 zombieDetector.start(); -732 -733 /* -734 * We are active master now... go initialize components we need to run. -735 * Note, there may be dross in zk from previous runs; it'll get addressed -736 * below after we determine if cluster startup or failover. -737 */ -738 -739 status.setStatus("Initializing Master file system"); -740 -741 this.masterActiveTime = System.currentTimeMillis(); -742 // TODO: Do this using Dependency Injection, using PicoContainer, Guice or Spring. -743 // Initialize the chunkCreator -744 initializeMemStoreChunkCreator(); -745 this.fileSystemManager = new MasterFileSystem(this); -746 this.walManager = new MasterWalManager(this); -747 -748 // enable table descriptors cache -749 this.tableDescriptors.setCacheOn(); -750 // set the META's descriptor to the correct replication -751 this.tableDescriptors.get(TableName.META_TABLE_NAME).setRegionReplication( -752 conf.getInt(HConstants.META_REPLICAS_NUM, HConstants.DEFAULT_META_REPLICA_NUM)); -753 // warm-up HTDs cache on master initialization -754 if (preLoadTableDescriptors) { -755 status.setStatus("Pre-loading table descriptors"); -756 this.tableDescriptors.getAll(); -757 } -758 -759 // publish cluster ID -760 status.setStatus("Publishing Cluster ID in ZooKeeper"); -761 ZKClusterId.setClusterId(this.zooKeeper, fileSystemManager.getClusterId()); -762 this.initLatch.countDown(); -763 -764 this.serverManager = createServerManager(this); -765 -766 this.tableStateManager = new TableStateManager(this); -767 -768 status.setStatus("Initializing ZK system trackers"); -769 initializeZKBasedSystemTrackers(); -770 -771 // This is for backwards compatibility -772 // See HBASE-11393 -773 status.setStatus("Update TableCFs node in ZNode"); -774 TableCFsUpdater tableCFsUpdater = new TableCFsUpdater(zooKeeper, -775 conf, this.clusterConnection); -776 tableCFsUpdater.update(); -777 -778 // Add the Observer to delete space quotas on table deletion before starting all CPs by -779 // default with quota support, avoiding if user specifically asks to not load this Observer. -780 if (QuotaUtil.isQuotaEnabled(conf)) { -781 updateConfigurationForSpaceQuotaObserver(conf); -782 } -783 // initialize master side coprocessors before we start handling requests -784 status.setStatus("Initializing master coprocessors"); -785 this.cpHost = new MasterCoprocessorHost(this, this.conf); -786 -787 // start up all service threads. -788 status.setStatus("Initializing master service threads"); -789 startServiceThreads(); -790 -791 // Wake up this server to check in -792 sleeper.skipSleepCycle(); -793 -794 // Wait for region servers to report in -795 status.setStatus("Wait for region servers to report in"); -796 waitForRegionServers(status); -797 -798 // get a list for previously failed RS which need log splitting work -799 // we recover hbase:meta region servers inside master initialization and -800 // handle other failed servers in SSH in order to start up master node ASAP -801 MasterMetaBootstrap metaBootstrap = createMetaBootstrap(this, status); -802 metaBootstrap.splitMetaLogsBeforeAssignment(); -803 -804 this.initializationBeforeMetaAssignment = true; -805 -806 if (this.balancer instanceof FavoredNodesPromoter) { -807 favoredNodesManager = new FavoredNodesManager(this); -808 } -809 // Wait for regionserver to finish initialization. -810 if (BaseLoadBalancer.tablesOnMaster(conf)) { -811 waitForServerOnline(); -812 } -813 -814 //initialize load balancer -815 this.balancer.setMasterServices(this); -816 this.balancer.setClusterStatus(getClusterStatus()); -817 this.balancer.initialize(); -818 -819 // Check if master is shutting down because of some issue -820 // in initializing the regionserver or the balancer. -821 if (isStopped()) return; -822 -823 // Make sure meta assigned before proceeding. -824 status.setStatus("Assigning Meta Region"); -825 metaBootstrap.assignMeta(); -826 -827 // check if master is shutting down because above assignMeta could return even hbase:meta isn't -828 // assigned when master is shutting down -829 if (isStopped()) return; -830 -831 //Initialize after meta as it scans meta -832 if (favoredNodesManager != null) { -833 SnapshotOfRegionAssignmentFromMeta snapshotOfRegionAssignment = -834 new SnapshotOfRegionAssignmentFromMeta(getConnection()); -835 snapshotOfRegionAssignment.initialize(); -836 favoredNodesManager.initialize(snapshotOfRegionAssignment); -837 } -838 -839 // migrating existent table state from zk, so splitters -840 // and recovery process treat states properly. -841 for (Map.Entry<TableName, TableState.State> entry : ZKDataMigrator -842 .queryForTableStates(getZooKeeper()).entrySet()) { -843 LOG.info("Converting state from zk to new states:" + entry); -844 tableStateManager.setTableState(entry.getKey(), entry.getValue()); -845 } -846 ZKUtil.deleteChildrenRecursively(getZooKeeper(), getZooKeeper().znodePaths.tableZNode); -847 -848 status.setStatus("Submitting log splitting work for previously failed region servers"); -849 metaBootstrap.processDeadServers(); -850 -851 // Fix up assignment manager status -852 status.setStatus("Starting assignment manager"); -853 this.assignmentManager.joinCluster(); -854 -855 // set cluster status again after user regions are assigned -856 this.balancer.setClusterStatus(getClusterStatus()); -857 -858 // Start balancer and meta catalog janitor after meta and regions have been assigned. -859 status.setStatus("Starting balancer and catalog janitor"); -860 this.clusterStatusChore = new ClusterStatusChore(this, balancer); -861 getChoreService().scheduleChore(clusterStatusChore); -862 this.balancerChore = new BalancerChore(this); -863 getChoreService().scheduleChore(balancerChore); -864 this.normalizerChore = new RegionNormalizerChore(this); -865 getChoreService().scheduleChore(normalizerChore); -866 this.catalogJanitorChore = new CatalogJanitor(this); -867 getChoreService().scheduleChore(catalogJanitorChore); -868 -869 status.setStatus("Starting cluster schema service"); -870 initClusterSchemaService(); -871 -872 if (this.cpHost != null) { -873 try { -874 this.cpHost.preMasterInitialization(); -875 } catch (IOException e) { -876 LOG.error("Coprocessor preMasterInitialization() hook failed", e); -877 } -878 } -879 -880 status.markComplete("Initialization successful"); -881 LOG.info(String.format("Master has completed initialization %.3fsec", -882 (System.currentTimeMillis() - masterActiveTime) / 1000.0f)); -883 configurationManager.registerObserver(this.balancer); -884 configurationManager.registerObserver(this.hfileCleaner); -885 -886 // Set master as 'initialized'. -887 setInitialized(true); -888 -889 assignmentManager.checkIfShouldMoveSystemRegionAsync(); -890 -891 status.setStatus("Assign meta replicas"); -892 metaBootstrap.assignMetaReplicas(); -893 -894 status.setStatus("Starting quota manager"); -895 initQuotaManager(); -896 if (QuotaUtil.isQuotaEnabled(conf)) { -897 // Create the quota snapshot notifier -898 spaceQuotaSnapshotNotifier = createQuotaSnapshotNotifier(); -899 spaceQuotaSnapshotNotifier.initialize(getClusterConnection()); -900 this.quotaObserverChore = new QuotaObserverChore(this, getMasterMetrics()); -901 // Start the chore to read the region FS space reports and act on them -902 getChoreService().scheduleChore(quotaObserverChore); -903 -904 this.snapshotQuotaChore = new SnapshotQuotaObserverChore(this, getMasterMetrics()); -905 // Start the chore to read snapshots and add their usage to table/NS quotas -906 getChoreService().scheduleChore(snapshotQuotaChore); -907 } -908 -909 // clear the dead servers with same host name and port of online server because we are not -910 // removing dead server with same hostname and port of rs which is trying to check in before -911 // master initialization. See HBASE-5916. -912 this.serverManager.clearDeadServersWithSameHostNameAndPortOfOnlineServer(); -913 -914 // Check and set the znode ACLs if needed in case we are overtaking a non-secure configuration -915 status.setStatus("Checking ZNode ACLs"); -916 zooKeeper.checkAndSetZNodeAcls(); -917 -918 status.setStatus("Initializing MOB Cleaner"); -919 initMobCleaner(); -920 -921 status.setStatus("Calling postStartMaster coprocessors"); -922 if (this.cpHost != null) { -923 // don't let cp initialization errors kill the master -924 try { -925 this.cpHost.postStartMaster(); -926 } catch (IOException ioe) { -927 LOG.error("Coprocessor postStartMaster() hook failed", ioe); -928 } -929 } -930 -931 zombieDetector.interrupt(); -932 } -933 -934 /** -935 * Adds the {@code MasterSpaceQuotaObserver} to the list of configured Master observers to -936 * automatically remove space quotas for a table when that table is deleted. -937 */ -938 @VisibleForTesting -939 public void updateConfigurationForSpaceQuotaObserver(Configuration conf) { -940 // We're configured to not delete quotas on table deletion, so we don't need to add the obs. -941 if (!conf.getBoolean( -942 MasterSpaceQuotaObserver.REMOVE_QUOTA_ON_TABLE_DELETE, -943 MasterSpaceQuotaObserver.REMOVE_QUOTA_ON_TABLE_DELETE_DEFAULT)) { -944 return; -945 } -946 String[] masterCoprocs = conf.getStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY); -947 final int length = null == masterCoprocs ? 0 : masterCoprocs.length; -948 String[] updatedCoprocs = new String[length + 1]; -949 if (length > 0) { -950 System.arraycopy(masterCoprocs, 0, updatedCoprocs, 0, masterCoprocs.length); -951 } -952 updatedCoprocs[length] = MasterSpaceQuotaObserver.class.getName(); -953 conf.setStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, updatedCoprocs); -954 } -955 -956 private void initMobCleaner() { -957 this.expiredMobFileCleanerChore = new ExpiredMobFileCleanerChore(this); -958 getChoreService().scheduleChore(expiredMobFileCleanerChore); -959 -960 int mobCompactionPeriod = conf.getInt(MobConstants.MOB_COMPACTION_CHORE_PERIOD, -961 MobConstants.DEFAULT_MOB_COMPACTION_CHORE_PERIOD); -962 if (mobCompactionPeriod > 0) { -963 this.mobCompactChore = new MobCompactionChore(this, mobCompactionPeriod); -964 getChoreService().scheduleChore(mobCompactChore); -965 } else { -966 LOG -967 .info("The period is " + mobCompactionPeriod + " seconds, MobCompactionChore is disabled"); -968<