Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D9DE91840E for ; Tue, 26 Jan 2016 17:55:57 +0000 (UTC) Received: (qmail 16133 invoked by uid 500); 26 Jan 2016 17:55:57 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 15997 invoked by uid 500); 26 Jan 2016 17:55:56 -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 15637 invoked by uid 99); 26 Jan 2016 17:55:56 -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; Tue, 26 Jan 2016 17:55:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 87B11E0243; Tue, 26 Jan 2016 17:55:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: misty@apache.org To: commits@hbase.apache.org Date: Tue, 26 Jan 2016 17:55:59 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/18] hbase-site git commit: Published site at d6b3d838eba382f6b7734ca1f40fa58eb97a4f89. http://git-wip-us.apache.org/repos/asf/hbase-site/blob/c221e35e/testdevapidocs/src-html/org/apache/hadoop/hbase/MiniHBaseCluster.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/MiniHBaseCluster.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/MiniHBaseCluster.html index 5efca6d..d870bc5 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/MiniHBaseCluster.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/MiniHBaseCluster.html @@ -83,735 +83,734 @@ 075 * @param numRegionServers initial number of region servers to start. 076 * @throws IOException 077 */ -078 public MiniHBaseCluster(Configuration conf, int numMasters, -079 int numRegionServers) -080 throws IOException, InterruptedException { -081 this(conf, numMasters, numRegionServers, null, null); -082 } -083 -084 public MiniHBaseCluster(Configuration conf, int numMasters, int numRegionServers, -085 Class<? extends HMaster> masterClass, -086 Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass) -087 throws IOException, InterruptedException { -088 super(conf); -089 conf.set(HConstants.MASTER_PORT, "0"); -090 -091 // Hadoop 2 -092 CompatibilityFactory.getInstance(MetricsAssertHelper.class).init(); -093 -094 init(numMasters, numRegionServers, masterClass, regionserverClass); -095 this.initialClusterStatus = getClusterStatus(); -096 } -097 -098 public Configuration getConfiguration() { -099 return this.conf; -100 } -101 -102 /** -103 * Subclass so can get at protected methods (none at moment). Also, creates -104 * a FileSystem instance per instantiation. Adds a shutdown own FileSystem -105 * on the way out. Shuts down own Filesystem only, not All filesystems as -106 * the FileSystem system exit hook does. -107 */ -108 public static class MiniHBaseClusterRegionServer extends HRegionServer { -109 private Thread shutdownThread = null; -110 private User user = null; -111 public static boolean TEST_SKIP_CLOSE = false; -112 -113 public MiniHBaseClusterRegionServer(Configuration conf, CoordinatedStateManager cp) -114 throws IOException, InterruptedException { -115 super(conf, cp); -116 this.user = User.getCurrent(); -117 } -118 -119 /* -120 * @param c -121 * @param currentfs We return this if we did not make a new one. -122 * @param uniqueName Same name used to help identify the created fs. -123 * @return A new fs instance if we are up on DistributeFileSystem. -124 * @throws IOException -125 */ -126 -127 @Override -128 protected void handleReportForDutyResponse( -129 final RegionServerStartupResponse c) throws IOException { -130 super.handleReportForDutyResponse(c); -131 // Run this thread to shutdown our filesystem on way out. -132 this.shutdownThread = new SingleFileSystemShutdownThread(getFileSystem()); -133 } -134 -135 @Override -136 public void run() { -137 try { -138 this.user.runAs(new PrivilegedAction<Object>(){ -139 public Object run() { -140 runRegionServer(); -141 return null; -142 } -143 }); -144 } catch (Throwable t) { -145 LOG.error("Exception in run", t); -146 } finally { -147 // Run this on the way out. -148 if (this.shutdownThread != null) { -149 this.shutdownThread.start(); -150 Threads.shutdown(this.shutdownThread, 30000); -151 } -152 } -153 } -154 -155 private void runRegionServer() { -156 super.run(); -157 } -158 -159 @Override -160 public void kill() { -161 super.kill(); -162 } -163 -164 public void abort(final String reason, final Throwable cause) { -165 this.user.runAs(new PrivilegedAction<Object>() { -166 public Object run() { -167 abortRegionServer(reason, cause); -168 return null; -169 } -170 }); -171 } -172 -173 private void abortRegionServer(String reason, Throwable cause) { -174 super.abort(reason, cause); -175 } -176 } -177 -178 /** -179 * Alternate shutdown hook. -180 * Just shuts down the passed fs, not all as default filesystem hook does. -181 */ -182 static class SingleFileSystemShutdownThread extends Thread { -183 private final FileSystem fs; -184 SingleFileSystemShutdownThread(final FileSystem fs) { -185 super("Shutdown of " + fs); -186 this.fs = fs; -187 } -188 @Override -189 public void run() { -190 try { -191 LOG.info("Hook closing fs=" + this.fs); -192 this.fs.close(); -193 } catch (NullPointerException npe) { -194 LOG.debug("Need to fix these: " + npe.toString()); -195 } catch (IOException e) { -196 LOG.warn("Running hook", e); -197 } -198 } -199 } -200 -201 private void init(final int nMasterNodes, final int nRegionNodes, -202 Class<? extends HMaster> masterClass, -203 Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass) -204 throws IOException, InterruptedException { -205 try { -206 if (masterClass == null){ -207 masterClass = HMaster.class; -208 } -209 if (regionserverClass == null){ -210 regionserverClass = MiniHBaseCluster.MiniHBaseClusterRegionServer.class; -211 } -212 -213 // start up a LocalHBaseCluster -214 hbaseCluster = new LocalHBaseCluster(conf, nMasterNodes, 0, -215 masterClass, regionserverClass); -216 -217 // manually add the regionservers as other users -218 for (int i=0; i<nRegionNodes; i++) { -219 Configuration rsConf = HBaseConfiguration.create(conf); -220 User user = HBaseTestingUtility.getDifferentUser(rsConf, -221 ".hfs."+index++); -222 hbaseCluster.addRegionServer(rsConf, i, user); -223 } -224 -225 hbaseCluster.startup(); -226 } catch (IOException e) { -227 shutdown(); -228 throw e; -229 } catch (Throwable t) { -230 LOG.error("Error starting cluster", t); -231 shutdown(); -232 throw new IOException("Shutting down", t); -233 } -234 } -235 -236 @Override -237 public void startRegionServer(String hostname, int port) throws IOException { -238 this.startRegionServer(); -239 } -240 -241 @Override -242 public void killRegionServer(ServerName serverName) throws IOException { -243 HRegionServer server = getRegionServer(getRegionServerIndex(serverName)); -244 if (server instanceof MiniHBaseClusterRegionServer) { -245 LOG.info("Killing " + server.toString()); -246 ((MiniHBaseClusterRegionServer) server).kill(); -247 } else { -248 abortRegionServer(getRegionServerIndex(serverName)); -249 } -250 } -251 -252 @Override -253 public void stopRegionServer(ServerName serverName) throws IOException { -254 stopRegionServer(getRegionServerIndex(serverName)); -255 } -256 -257 @Override -258 public void waitForRegionServerToStop(ServerName serverName, long timeout) throws IOException { -259 //ignore timeout for now -260 waitOnRegionServer(getRegionServerIndex(serverName)); -261 } -262 -263 @Override -264 public void startZkNode(String hostname, int port) throws IOException { -265 LOG.warn("Starting zookeeper nodes on mini cluster is not supported"); -266 } -267 -268 @Override -269 public void killZkNode(ServerName serverName) throws IOException { -270 LOG.warn("Aborting zookeeper nodes on mini cluster is not supported"); -271 } -272 -273 @Override -274 public void stopZkNode(ServerName serverName) throws IOException { -275 LOG.warn("Stopping zookeeper nodes on mini cluster is not supported"); -276 } -277 -278 @Override -279 public void waitForZkNodeToStart(ServerName serverName, long timeout) throws IOException { -280 LOG.warn("Waiting for zookeeper nodes to start on mini cluster is not supported"); -281 } -282 -283 @Override -284 public void waitForZkNodeToStop(ServerName serverName, long timeout) throws IOException { -285 LOG.warn("Waiting for zookeeper nodes to stop on mini cluster is not supported"); -286 } -287 -288 @Override -289 public void startDataNode(ServerName serverName) throws IOException { -290 LOG.warn("Starting datanodes on mini cluster is not supported"); -291 } -292 -293 @Override -294 public void killDataNode(ServerName serverName) throws IOException { -295 LOG.warn("Aborting datanodes on mini cluster is not supported"); -296 } -297 -298 @Override -299 public void stopDataNode(ServerName serverName) throws IOException { -300 LOG.warn("Stopping datanodes on mini cluster is not supported"); -301 } -302 -303 @Override -304 public void waitForDataNodeToStart(ServerName serverName, long timeout) throws IOException { -305 LOG.warn("Waiting for datanodes to start on mini cluster is not supported"); -306 } -307 -308 @Override -309 public void waitForDataNodeToStop(ServerName serverName, long timeout) throws IOException { -310 LOG.warn("Waiting for datanodes to stop on mini cluster is not supported"); -311 } -312 -313 @Override -314 public void startMaster(String hostname, int port) throws IOException { -315 this.startMaster(); -316 } -317 -318 @Override -319 public void killMaster(ServerName serverName) throws IOException { -320 abortMaster(getMasterIndex(serverName)); -321 } -322 -323 @Override -324 public void stopMaster(ServerName serverName) throws IOException { -325 stopMaster(getMasterIndex(serverName)); -326 } -327 -328 @Override -329 public void waitForMasterToStop(ServerName serverName, long timeout) throws IOException { -330 //ignore timeout for now -331 waitOnMaster(getMasterIndex(serverName)); -332 } -333 -334 /** -335 * Starts a region server thread running -336 * -337 * @throws IOException -338 * @return New RegionServerThread -339 */ -340 public JVMClusterUtil.RegionServerThread startRegionServer() -341 throws IOException { -342 final Configuration newConf = HBaseConfiguration.create(conf); -343 User rsUser = -344 HBaseTestingUtility.getDifferentUser(newConf, ".hfs."+index++); -345 JVMClusterUtil.RegionServerThread t = null; -346 try { -347 t = hbaseCluster.addRegionServer( -348 newConf, hbaseCluster.getRegionServers().size(), rsUser); -349 t.start(); -350 t.waitForServerOnline(); -351 } catch (InterruptedException ie) { -352 throw new IOException("Interrupted adding regionserver to cluster", ie); -353 } -354 return t; -355 } -356 -357 /** -358 * Cause a region server to exit doing basic clean up only on its way out. -359 * @param serverNumber Used as index into a list. -360 */ -361 public String abortRegionServer(int serverNumber) { -362 HRegionServer server = getRegionServer(serverNumber); -363 LOG.info("Aborting " + server.toString()); -364 server.abort("Aborting for tests", new Exception("Trace info")); -365 return server.toString(); -366 } -367 -368 /** -369 * Shut down the specified region server cleanly -370 * -371 * @param serverNumber Used as index into a list. -372 * @return the region server that was stopped -373 */ -374 public JVMClusterUtil.RegionServerThread stopRegionServer(int serverNumber) { -375 return stopRegionServer(serverNumber, true); -376 } -377 -378 /** -379 * Shut down the specified region server cleanly -380 * -381 * @param serverNumber Used as index into a list. -382 * @param shutdownFS True is we are to shutdown the filesystem as part of this -383 * regionserver's shutdown. Usually we do but you do not want to do this if -384 * you are running multiple regionservers in a test and you shut down one -385 * before end of the test. -386 * @return the region server that was stopped -387 */ -388 public JVMClusterUtil.RegionServerThread stopRegionServer(int serverNumber, -389 final boolean shutdownFS) { -390 JVMClusterUtil.RegionServerThread server = -391 hbaseCluster.getRegionServers().get(serverNumber); -392 LOG.info("Stopping " + server.toString()); -393 server.getRegionServer().stop("Stopping rs " + serverNumber); -394 return server; -395 } -396 -397 /** -398 * Wait for the specified region server to stop. Removes this thread from list -399 * of running threads. -400 * @param serverNumber -401 * @return Name of region server that just went down. -402 */ -403 public String waitOnRegionServer(final int serverNumber) { -404 return this.hbaseCluster.waitOnRegionServer(serverNumber); -405 } +078 public MiniHBaseCluster(Configuration conf, int numMasters, int numRegionServers) +079 throws IOException, InterruptedException { +080 this(conf, numMasters, numRegionServers, null, null); +081 } +082 +083 public MiniHBaseCluster(Configuration conf, int numMasters, int numRegionServers, +084 Class<? extends HMaster> masterClass, +085 Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass) +086 throws IOException, InterruptedException { +087 super(conf); +088 conf.set(HConstants.MASTER_PORT, "0"); +089 +090 // Hadoop 2 +091 CompatibilityFactory.getInstance(MetricsAssertHelper.class).init(); +092 +093 init(numMasters, numRegionServers, masterClass, regionserverClass); +094 this.initialClusterStatus = getClusterStatus(); +095 } +096 +097 public Configuration getConfiguration() { +098 return this.conf; +099 } +100 +101 /** +102 * Subclass so can get at protected methods (none at moment). Also, creates +103 * a FileSystem instance per instantiation. Adds a shutdown own FileSystem +104 * on the way out. Shuts down own Filesystem only, not All filesystems as +105 * the FileSystem system exit hook does. +106 */ +107 public static class MiniHBaseClusterRegionServer extends HRegionServer { +108 private Thread shutdownThread = null; +109 private User user = null; +110 +111 public MiniHBaseClusterRegionServer(Configuration conf, CoordinatedStateManager cp) +112 throws IOException, InterruptedException { +113 super(conf, cp); +114 this.user = User.getCurrent(); +115 } +116 +117 /* +118 * @param c +119 * @param currentfs We return this if we did not make a new one. +120 * @param uniqueName Same name used to help identify the created fs. +121 * @return A new fs instance if we are up on DistributeFileSystem. +122 * @throws IOException +123 */ +124 +125 @Override +126 protected void handleReportForDutyResponse( +127 final RegionServerStartupResponse c) throws IOException { +128 super.handleReportForDutyResponse(c); +129 // Run this thread to shutdown our filesystem on way out. +130 this.shutdownThread = new SingleFileSystemShutdownThread(getFileSystem()); +131 } +132 +133 @Override +134 public void run() { +135 try { +136 this.user.runAs(new PrivilegedAction<Object>(){ +137 public Object run() { +138 runRegionServer(); +139 return null; +140 } +141 }); +142 } catch (Throwable t) { +143 LOG.error("Exception in run", t); +144 } finally { +145 // Run this on the way out. +146 if (this.shutdownThread != null) { +147 this.shutdownThread.start(); +148 Threads.shutdown(this.shutdownThread, 30000); +149 } +150 } +151 } +152 +153 private void runRegionServer() { +154 super.run(); +155 } +156 +157 @Override +158 public void kill() { +159 super.kill(); +160 } +161 +162 @Override +163 public void abort(final String reason, final Throwable cause) { +164 this.user.runAs(new PrivilegedAction<Object>() { +165 public Object run() { +166 abortRegionServer(reason, cause); +167 return null; +168 } +169 }); +170 } +171 +172 private void abortRegionServer(String reason, Throwable cause) { +173 super.abort(reason, cause); +174 } +175 } +176 +177 /** +178 * Alternate shutdown hook. +179 * Just shuts down the passed fs, not all as default filesystem hook does. +180 */ +181 static class SingleFileSystemShutdownThread extends Thread { +182 private final FileSystem fs; +183 SingleFileSystemShutdownThread(final FileSystem fs) { +184 super("Shutdown of " + fs); +185 this.fs = fs; +186 } +187 @Override +188 public void run() { +189 try { +190 LOG.info("Hook closing fs=" + this.fs); +191 this.fs.close(); +192 } catch (NullPointerException npe) { +193 LOG.debug("Need to fix these: " + npe.toString()); +194 } catch (IOException e) { +195 LOG.warn("Running hook", e); +196 } +197 } +198 } +199 +200 private void init(final int nMasterNodes, final int nRegionNodes, +201 Class<? extends HMaster> masterClass, +202 Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass) +203 throws IOException, InterruptedException { +204 try { +205 if (masterClass == null){ +206 masterClass = HMaster.class; +207 } +208 if (regionserverClass == null){ +209 regionserverClass = MiniHBaseCluster.MiniHBaseClusterRegionServer.class; +210 } +211 +212 // start up a LocalHBaseCluster +213 hbaseCluster = new LocalHBaseCluster(conf, nMasterNodes, 0, +214 masterClass, regionserverClass); +215 +216 // manually add the regionservers as other users +217 for (int i=0; i<nRegionNodes; i++) { +218 Configuration rsConf = HBaseConfiguration.create(conf); +219 User user = HBaseTestingUtility.getDifferentUser(rsConf, +220 ".hfs."+index++); +221 hbaseCluster.addRegionServer(rsConf, i, user); +222 } +223 +224 hbaseCluster.startup(); +225 } catch (IOException e) { +226 shutdown(); +227 throw e; +228 } catch (Throwable t) { +229 LOG.error("Error starting cluster", t); +230 shutdown(); +231 throw new IOException("Shutting down", t); +232 } +233 } +234 +235 @Override +236 public void startRegionServer(String hostname, int port) throws IOException { +237 this.startRegionServer(); +238 } +239 +240 @Override +241 public void killRegionServer(ServerName serverName) throws IOException { +242 HRegionServer server = getRegionServer(getRegionServerIndex(serverName)); +243 if (server instanceof MiniHBaseClusterRegionServer) { +244 LOG.info("Killing " + server.toString()); +245 ((MiniHBaseClusterRegionServer) server).kill(); +246 } else { +247 abortRegionServer(getRegionServerIndex(serverName)); +248 } +249 } +250 +251 @Override +252 public void stopRegionServer(ServerName serverName) throws IOException { +253 stopRegionServer(getRegionServerIndex(serverName)); +254 } +255 +256 @Override +257 public void waitForRegionServerToStop(ServerName serverName, long timeout) throws IOException { +258 //ignore timeout for now +259 waitOnRegionServer(getRegionServerIndex(serverName)); +260 } +261 +262 @Override +263 public void startZkNode(String hostname, int port) throws IOException { +264 LOG.warn("Starting zookeeper nodes on mini cluster is not supported"); +265 } +266 +267 @Override +268 public void killZkNode(ServerName serverName) throws IOException { +269 LOG.warn("Aborting zookeeper nodes on mini cluster is not supported"); +270 } +271 +272 @Override +273 public void stopZkNode(ServerName serverName) throws IOException { +274 LOG.warn("Stopping zookeeper nodes on mini cluster is not supported"); +275 } +276 +277 @Override +278 public void waitForZkNodeToStart(ServerName serverName, long timeout) throws IOException { +279 LOG.warn("Waiting for zookeeper nodes to start on mini cluster is not supported"); +280 } +281 +282 @Override +283 public void waitForZkNodeToStop(ServerName serverName, long timeout) throws IOException { +284 LOG.warn("Waiting for zookeeper nodes to stop on mini cluster is not supported"); +285 } +286 +287 @Override +288 public void startDataNode(ServerName serverName) throws IOException { +289 LOG.warn("Starting datanodes on mini cluster is not supported"); +290 } +291 +292 @Override +293 public void killDataNode(ServerName serverName) throws IOException { +294 LOG.warn("Aborting datanodes on mini cluster is not supported"); +295 } +296 +297 @Override +298 public void stopDataNode(ServerName serverName) throws IOException { +299 LOG.warn("Stopping datanodes on mini cluster is not supported"); +300 } +301 +302 @Override +303 public void waitForDataNodeToStart(ServerName serverName, long timeout) throws IOException { +304 LOG.warn("Waiting for datanodes to start on mini cluster is not supported"); +305 } +306 +307 @Override +308 public void waitForDataNodeToStop(ServerName serverName, long timeout) throws IOException { +309 LOG.warn("Waiting for datanodes to stop on mini cluster is not supported"); +310 } +311 +312 @Override +313 public void startMaster(String hostname, int port) throws IOException { +314 this.startMaster(); +315 } +316 +317 @Override +318 public void killMaster(ServerName serverName) throws IOException { +319 abortMaster(getMasterIndex(serverName)); +320 } +321 +322 @Override +323 public void stopMaster(ServerName serverName) throws IOException { +324 stopMaster(getMasterIndex(serverName)); +325 } +326 +327 @Override +328 public void waitForMasterToStop(ServerName serverName, long timeout) throws IOException { +329 //ignore timeout for now +330 waitOnMaster(getMasterIndex(serverName)); +331 } +332 +333 /** +334 * Starts a region server thread running +335 * +336 * @throws IOException +337 * @return New RegionServerThread +338 */ +339 public JVMClusterUtil.RegionServerThread startRegionServer() +340 throws IOException { +341 final Configuration newConf = HBaseConfiguration.create(conf); +342 User rsUser = +343 HBaseTestingUtility.getDifferentUser(newConf, ".hfs."+index++); +344 JVMClusterUtil.RegionServerThread t = null; +345 try { +346 t = hbaseCluster.addRegionServer( +347 newConf, hbaseCluster.getRegionServers().size(), rsUser); +348 t.start(); +349 t.waitForServerOnline(); +350 } catch (InterruptedException ie) { +351 throw new IOException("Interrupted adding regionserver to cluster", ie); +352 } +353 return t; +354 } +355 +356 /** +357 * Cause a region server to exit doing basic clean up only on its way out. +358 * @param serverNumber Used as index into a list. +359 */ +360 public String abortRegionServer(int serverNumber) { +361 HRegionServer server = getRegionServer(serverNumber); +362 LOG.info("Aborting " + server.toString()); +363 server.abort("Aborting for tests", new Exception("Trace info")); +364 return server.toString(); +365 } +366 +367 /** +368 * Shut down the specified region server cleanly +369 * +370 * @param serverNumber Used as index into a list. +371 * @return the region server that was stopped +372 */ +373 public JVMClusterUtil.RegionServerThread stopRegionServer(int serverNumber) { +374 return stopRegionServer(serverNumber, true); +375 } +376 +377 /** +378 * Shut down the specified region server cleanly +379 * +380 * @param serverNumber Used as index into a list. +381 * @param shutdownFS True is we are to shutdown the filesystem as part of this +382 * regionserver's shutdown. Usually we do but you do not want to do this if +383 * you are running multiple regionservers in a test and you shut down one +384 * before end of the test. +385 * @return the region server that was stopped +386 */ +387 public JVMClusterUtil.RegionServerThread stopRegionServer(int serverNumber, +388 final boolean shutdownFS) { +389 JVMClusterUtil.RegionServerThread server = +390 hbaseCluster.getRegionServers().get(serverNumber); +391 LOG.info("Stopping " + server.toString()); +392 server.getRegionServer().stop("Stopping rs " + serverNumber); +393 return server; +394 } +395 +396 /** +397 * Wait for the specified region server to stop. Removes this thread from list +398 * of running threads. +399 * @param serverNumber +400 * @return Name of region server that just went down. +401 */ +402 public String waitOnRegionServer(final int serverNumber) { +403 return this.hbaseCluster.waitOnRegionServer(serverNumber); +404 } +405 406 -407 -408 /** -409 * Starts a master thread running -410 * -411 * @throws IOException -412 * @return New RegionServerThread -413 */ -414 public JVMClusterUtil.MasterThread startMaster() throws IOException { -415 Configuration c = HBaseConfiguration.create(conf); -416 User user = -417 HBaseTestingUtility.getDifferentUser(c, ".hfs."+index++); -418 -419 JVMClusterUtil.MasterThread t = null; -420 try { -421 t = hbaseCluster.addMaster(c, hbaseCluster.getMasters().size(), user); -422 t.start(); -423 } catch (InterruptedException ie) { -424 throw new IOException("Interrupted adding master to cluster", ie); -425 } -426 return t; -427 } -428 -429 /** -430 * Returns the current active master, if available. -431 * @return the active HMaster, null if none is active. -432 */ -433 public MasterService.BlockingInterface getMasterAdminService() { -434 return this.hbaseCluster.getActiveMaster().getMasterRpcServices(); -435 } -436 -437 /** -438 * Returns the current active master, if available. -439 * @return the active HMaster, null if none is active. -440 */ -441 public HMaster getMaster() { -442 return this.hbaseCluster.getActiveMaster(); -443 } -444 -445 /** -446 * Returns the current active master thread, if available. -447 * @return the active MasterThread, null if none is active. -448 */ -449 public MasterThread getMasterThread() { -450 for (MasterThread mt: hbaseCluster.getLiveMasters()) { -451 if (mt.getMaster().isActiveMaster()) { -452 return mt; -453 } -454 } -455 return null; -456 } -457 -458 /** -459 * Returns the master at the specified index, if available. -460 * @return the active HMaster, null if none is active. -461 */ -462 public HMaster getMaster(final int serverNumber) { -463 return this.hbaseCluster.getMaster(serverNumber); -464 } -465 -466 /** -467 * Cause a master to exit without shutting down entire cluster. -468 * @param serverNumber Used as index into a list. -469 */ -470 public String abortMaster(int serverNumber) { -471 HMaster server = getMaster(serverNumber); -472 LOG.info("Aborting " + server.toString()); -473 server.abort("Aborting for tests", new Exception("Trace info")); -474 return server.toString(); -475 } -476 -477 /** -478 * Shut down the specified master cleanly -479 * -480 * @param serverNumber Used as index into a list. -481 * @return the region server that was stopped -482 */ -483 public JVMClusterUtil.MasterThread stopMaster(int serverNumber) { -484 return stopMaster(serverNumber, true); -485 } -486 -487 /** -488 * Shut down the specified master cleanly -489 * -490 * @param serverNumber Used as index into a list. -491 * @param shutdownFS True is we are to shutdown the filesystem as part of this -492 * master's shutdown. Usually we do but you do not want to do this if -493 * you are running multiple master in a test and you shut down one -494 * before end of the test. -495 * @return the master that was stopped -496 */ -497 public JVMClusterUtil.MasterThread stopMaster(int serverNumber, -498 final boolean shutdownFS) { -499 JVMClusterUtil.MasterThread server = -500 hbaseCluster.getMasters().get(serverNumber); -501 LOG.info("Stopping " + server.toString()); -502 server.getMaster().stop("Stopping master " + serverNumber); -503 return server; -504 } -505 -506 /** -507 * Wait for the specified master to stop. Removes this thread from list -508 * of running threads. -509 * @param serverNumber -510 * @return Name of master that just went down. -511 */ -512 public String waitOnMaster(final int serverNumber) { -513 return this.hbaseCluster.waitOnMaster(serverNumber); -514 } -515 -516 /** -517 * Blocks until there is an active master and that master has completed -518 * initialization. -519 * -520 * @return true if an active master becomes available. false if there are no -521 * masters left. -522 * @throws InterruptedException -523 */ -524 public boolean waitForActiveAndReadyMaster(long timeout) throws IOException { -525 List<JVMClusterUtil.MasterThread> mts; -526 long start = System.currentTimeMillis(); -527 while (!(mts = getMasterThreads()).isEmpty() -528 && (System.currentTimeMillis() - start) < timeout) { -529 for (JVMClusterUtil.MasterThread mt : mts) { -530 if (mt.getMaster().isActiveMaster() && mt.getMaster().isInitialized()) { -531 return true; -532 } -533 } -534 -535 Threads.sleep(100); -536 } -537 return false; -538 } -539 -540 /** -541 * @return List of master threads. -542 */ -543 public List<JVMClusterUtil.MasterThread> getMasterThreads() { -544 return this.hbaseCluster.getMasters(); -545 } -546 -547 /** -548 * @return List of live master threads (skips the aborted and the killed) -549 */ -550 public List<JVMClusterUtil.MasterThread> getLiveMasterThreads() { -551 return this.hbaseCluster.getLiveMasters(); -552 } -553 -554 /** -555 * Wait for Mini HBase Cluster to shut down. -556 */ -557 public void join() { -558 this.hbaseCluster.join(); -559 } -560 -561 /** -562 * Shut down the mini HBase cluster -563 * @throws IOException -564 */ -565 @SuppressWarnings("deprecation") -566 public void shutdown() throws IOException { -567 if (this.hbaseCluster != null) { -568 this.hbaseCluster.shutdown(); -569 } -570 } -571 -572 @Override -573 public void close() throws IOException { -574 } -575 -576 @Override -577 public ClusterStatus getClusterStatus() throws IOException { -578 HMaster master = getMaster(); -579 return master == null ? null : master.getClusterStatus(); -580 } -581 -582 /** -583 * Call flushCache on all regions on all participating regionservers. -584 * @throws IOException -585 */ -586 public void flushcache() throws IOException { -587 for (JVMClusterUtil.RegionServerThread t: -588 this.hbaseCluster.getRegionServers()) { -589 for(Region r: t.getRegionServer().getOnlineRegionsLocalContext()) { -590 r.flush(true); -591 } -592 } -593 } -594 -595 /** -596 * Call flushCache on all regions of the specified table. -597 * @throws IOException -598 */ -599 public void flushcache(TableName tableName) throws IOException { -600 for (JVMClusterUtil.RegionServerThread t: -601 this.hbaseCluster.getRegionServers()) { -602 for(Region r: t.getRegionServer().getOnlineRegionsLocalContext()) { -603 if(r.getTableDesc().getTableName().equals(tableName)) { -604 r.flush(true); -605 } -606 } -607 } -608 } -609 -610 /** -611 * Call flushCache on all regions on all participating regionservers. -612 * @throws IOException -613 */ -614 public void compact(boolean major) throws IOException { -615 for (JVMClusterUtil.RegionServerThread t: -616 this.hbaseCluster.getRegionServers()) { -617 for(Region r: t.getRegionServer().getOnlineRegionsLocalContext()) { -618 r.compact(major); -619 } -620 } -621 } -622 -623 /** -624 * Call flushCache on all regions of the specified table. -625 * @throws IOException -626 */ -627 public void compact(TableName tableName, boolean major) throws IOException { -628 for (JVMClusterUtil.RegionServerThread t: -629 this.hbaseCluster.getRegionServers()) { -630 for(Region r: t.getRegionServer().getOnlineRegionsLocalContext()) { -631 if(r.getTableDesc().getTableName().equals(tableName)) { -632 r.compact(major); -633 } -634 } -635 } -636 } -637 -638 /** -639 * @return List of region server threads. -640 */ -641 public List<JVMClusterUtil.RegionServerThread> getRegionServerThreads() { -642 return this.hbaseCluster.getRegionServers(); -643 } -644 -645 /** -646 * @return List of live region server threads (skips the aborted and the killed) -647 */ -648 public List<JVMClusterUtil.RegionServerThread> getLiveRegionServerThreads() { -649 return this.hbaseCluster.getLiveRegionServers(); -650 } -651 -652 /** -653 * Grab a numbered region server of your choice. -654 * @param serverNumber -655 * @return region server -656 */ -657 public HRegionServer getRegionServer(int serverNumber) { -658 return hbaseCluster.getRegionServer(serverNumber); -659 } -660 -661 public List<HRegion> getRegions(byte[] tableName) { -662 return getRegions(TableName.valueOf(tableName)); -663 } -664 -665 public List<HRegion> getRegions(TableName tableName) { -666 List<HRegion> ret = new ArrayList<HRegion>(); -667 for (JVMClusterUtil.RegionServerThread rst : getRegionServerThreads()) { -668 HRegionServer hrs = rst.getRegionServer(); -669 for (Region region : hrs.getOnlineRegionsLocalContext()) { -670 if (region.getTableDesc().getTableName().equals(tableName)) { -671 ret.add((HRegion)region); -672 } -673 } -674 } -675 return ret; -676 } -677 -678 /** -679 * @return Index into List of {@link MiniHBaseCluster#getRegionServerThreads()} -680 * of HRS carrying regionName. Returns -1 if none found. -681 */ -682 public int getServerWithMeta() { -683 return getServerWith(HRegionInfo.FIRST_META_REGIONINFO.getRegionName()); -684 } -685 -686 /** -687 * Get the location of the specified region -688 * @param regionName Name of the region in bytes -689 * @return Index into List of {@link MiniHBaseCluster#getRegionServerThreads()} -690 * of HRS carrying hbase:meta. Returns -1 if none found. -691 */ -692 public int getServerWith(byte[] regionName) { -693 int index = -1; -694 int count = 0; -695 for (JVMClusterUtil.RegionServerThread rst: getRegionServerThreads()) { -696 HRegionServer hrs = rst.getRegionServer(); -697 Region metaRegion = hrs.getOnlineRegion(regionName); -698 if (metaRegion != null) { -699 index = count; -700 break; -701 } -702 count++; -703 } -704 return index; -705 } -