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 D6727200CF6 for ; Mon, 18 Sep 2017 17:13:13 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D53511609DF; Mon, 18 Sep 2017 15:13:13 +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 53FB61609D8 for ; Mon, 18 Sep 2017 17:13:11 +0200 (CEST) Received: (qmail 29688 invoked by uid 500); 18 Sep 2017 15:13:10 -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 29349 invoked by uid 99); 18 Sep 2017 15:13:09 -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; Mon, 18 Sep 2017 15:13:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 87C42F574B; Mon, 18 Sep 2017 15:13:08 +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: Mon, 18 Sep 2017 15:13:13 -0000 Message-Id: <84e62c9a29c8431e85602932d4eb6c45@git.apache.org> In-Reply-To: <3b0cc6126f6543fb9489d5d0f985775d@git.apache.org> References: <3b0cc6126f6543fb9489d5d0f985775d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/30] hbase-site git commit: Published site at . archived-at: Mon, 18 Sep 2017 15:13:14 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/2bb8bd01/testdevapidocs/src-html/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.html index 82eb9fd..8eb952a 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.html @@ -71,668 +71,655 @@ 063import org.apache.hadoop.hbase.coprocessor.ObserverContext; 064import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; 065import org.apache.hadoop.hbase.coprocessor.RegionObserver; -066import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment; -067import org.apache.hadoop.hbase.coprocessor.RegionServerObserver; -068import org.apache.hadoop.hbase.master.HMaster; -069import org.apache.hadoop.hbase.master.MasterCoprocessorHost; -070import org.apache.hadoop.hbase.master.TableNamespaceManager; -071import org.apache.hadoop.hbase.quotas.MasterQuotaManager; -072import org.apache.hadoop.hbase.quotas.QuotaExceededException; -073import org.apache.hadoop.hbase.quotas.QuotaUtil; -074import org.apache.hadoop.hbase.regionserver.Region; -075import org.apache.hadoop.hbase.regionserver.Store; -076import org.apache.hadoop.hbase.regionserver.StoreFile; -077import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker; -078import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest; -079import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException; -080import org.apache.hadoop.hbase.testclassification.MediumTests; -081import org.apache.hadoop.hbase.util.Bytes; -082import org.apache.hadoop.hbase.util.FSUtils; -083import org.apache.hadoop.hbase.util.Threads; -084import org.apache.zookeeper.KeeperException; -085import org.junit.After; -086import org.junit.AfterClass; -087import org.junit.BeforeClass; -088import org.junit.Rule; -089import org.junit.Test; -090import org.junit.experimental.categories.Category; -091import org.junit.rules.TestRule; -092 -093@Category(MediumTests.class) -094public class TestNamespaceAuditor { -095 @Rule public final TestRule timeout = CategoryBasedTimeout.builder(). -096 withTimeout(this.getClass()).withLookingForStuckThread(true).build(); -097 private static final Log LOG = LogFactory.getLog(TestNamespaceAuditor.class); -098 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); -099 private static Admin ADMIN; -100 private String prefix = "TestNamespaceAuditor"; -101 -102 @BeforeClass -103 public static void before() throws Exception { -104 Configuration conf = UTIL.getConfiguration(); -105 conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, CustomObserver.class.getName()); -106 conf.setStrings( -107 CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, -108 MasterSyncObserver.class.getName(), CPMasterObserver.class.getName()); -109 conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 5); -110 conf.setBoolean(QuotaUtil.QUOTA_CONF_KEY, true); -111 conf.setClass("hbase.coprocessor.regionserver.classes", CPRegionServerObserver.class, -112 RegionServerObserver.class); -113 UTIL.startMiniCluster(1, 1); -114 waitForQuotaInitialize(UTIL); -115 ADMIN = UTIL.getAdmin(); -116 } -117 -118 @AfterClass -119 public static void tearDown() throws Exception { -120 UTIL.shutdownMiniCluster(); -121 } -122 -123 @After -124 public void cleanup() throws Exception, KeeperException { -125 for (HTableDescriptor table : ADMIN.listTables()) { -126 ADMIN.disableTable(table.getTableName()); -127 deleteTable(table.getTableName()); -128 } -129 for (NamespaceDescriptor ns : ADMIN.listNamespaceDescriptors()) { -130 if (ns.getName().startsWith(prefix)) { -131 ADMIN.deleteNamespace(ns.getName()); -132 } -133 } -134 assertTrue("Quota manager not initialized", UTIL.getHBaseCluster().getMaster() -135 .getMasterQuotaManager().isQuotaInitialized()); -136 } -137 -138 @Test -139 public void testTableOperations() throws Exception { -140 String nsp = prefix + "_np2"; -141 NamespaceDescriptor nspDesc = -142 NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "5") -143 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build(); -144 ADMIN.createNamespace(nspDesc); -145 assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp)); -146 assertEquals(ADMIN.listNamespaceDescriptors().length, 3); -147 HColumnDescriptor fam1 = new HColumnDescriptor("fam1"); -148 -149 HTableDescriptor tableDescOne = -150 new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1")); -151 tableDescOne.addFamily(fam1); -152 HTableDescriptor tableDescTwo = -153 new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2")); -154 tableDescTwo.addFamily(fam1); -155 HTableDescriptor tableDescThree = -156 new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table3")); -157 tableDescThree.addFamily(fam1); -158 ADMIN.createTable(tableDescOne); -159 boolean constraintViolated = false; -160 try { -161 ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 5); -162 } catch (Exception exp) { -163 assertTrue(exp instanceof IOException); -164 constraintViolated = true; -165 } finally { -166 assertTrue("Constraint not violated for table " + tableDescTwo.getTableName(), -167 constraintViolated); -168 } -169 ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4); -170 NamespaceTableAndRegionInfo nspState = getQuotaManager().getState(nsp); -171 assertNotNull(nspState); -172 assertTrue(nspState.getTables().size() == 2); -173 assertTrue(nspState.getRegionCount() == 5); -174 constraintViolated = false; -175 try { -176 ADMIN.createTable(tableDescThree); -177 } catch (Exception exp) { -178 assertTrue(exp instanceof IOException); -179 constraintViolated = true; -180 } finally { -181 assertTrue("Constraint not violated for table " + tableDescThree.getTableName(), -182 constraintViolated); -183 } -184 } -185 -186 @Test -187 public void testValidQuotas() throws Exception { -188 boolean exceptionCaught = false; -189 FileSystem fs = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getFileSystem(); -190 Path rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); -191 NamespaceDescriptor nspDesc = -192 NamespaceDescriptor.create(prefix + "vq1") -193 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "hihdufh") -194 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build(); -195 try { -196 ADMIN.createNamespace(nspDesc); -197 } catch (Exception exp) { -198 LOG.warn(exp); -199 exceptionCaught = true; -200 } finally { -201 assertTrue(exceptionCaught); -202 assertFalse(fs.exists(FSUtils.getNamespaceDir(rootDir, nspDesc.getName()))); -203 } -204 nspDesc = -205 NamespaceDescriptor.create(prefix + "vq2") -206 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "-456") -207 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build(); -208 try { -209 ADMIN.createNamespace(nspDesc); -210 } catch (Exception exp) { -211 LOG.warn(exp); -212 exceptionCaught = true; -213 } finally { -214 assertTrue(exceptionCaught); -215 assertFalse(fs.exists(FSUtils.getNamespaceDir(rootDir, nspDesc.getName()))); -216 } -217 nspDesc = -218 NamespaceDescriptor.create(prefix + "vq3") -219 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10") -220 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "sciigd").build(); -221 try { -222 ADMIN.createNamespace(nspDesc); -223 } catch (Exception exp) { -224 LOG.warn(exp); -225 exceptionCaught = true; -226 } finally { -227 assertTrue(exceptionCaught); -228 assertFalse(fs.exists(FSUtils.getNamespaceDir(rootDir, nspDesc.getName()))); -229 } -230 nspDesc = -231 NamespaceDescriptor.create(prefix + "vq4") -232 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10") -233 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "-1500").build(); -234 try { -235 ADMIN.createNamespace(nspDesc); -236 } catch (Exception exp) { -237 LOG.warn(exp); -238 exceptionCaught = true; -239 } finally { -240 assertTrue(exceptionCaught); -241 assertFalse(fs.exists(FSUtils.getNamespaceDir(rootDir, nspDesc.getName()))); -242 } -243 } -244 -245 @Test -246 public void testDeleteTable() throws Exception { -247 String namespace = prefix + "_dummy"; -248 NamespaceDescriptor nspDesc = -249 NamespaceDescriptor.create(namespace) -250 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "100") -251 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "3").build(); -252 ADMIN.createNamespace(nspDesc); -253 assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(namespace)); -254 NamespaceTableAndRegionInfo stateInfo = getNamespaceState(nspDesc.getName()); -255 assertNotNull("Namespace state found null for " + namespace, stateInfo); -256 HColumnDescriptor fam1 = new HColumnDescriptor("fam1"); -257 HTableDescriptor tableDescOne = -258 new HTableDescriptor(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table1")); -259 tableDescOne.addFamily(fam1); -260 HTableDescriptor tableDescTwo = -261 new HTableDescriptor(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table2")); -262 tableDescTwo.addFamily(fam1); -263 ADMIN.createTable(tableDescOne); -264 ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 5); -265 stateInfo = getNamespaceState(nspDesc.getName()); -266 assertNotNull("Namespace state found to be null.", stateInfo); -267 assertEquals(2, stateInfo.getTables().size()); -268 assertEquals(5, stateInfo.getRegionCountOfTable(tableDescTwo.getTableName())); -269 assertEquals(6, stateInfo.getRegionCount()); -270 ADMIN.disableTable(tableDescOne.getTableName()); -271 deleteTable(tableDescOne.getTableName()); -272 stateInfo = getNamespaceState(nspDesc.getName()); -273 assertNotNull("Namespace state found to be null.", stateInfo); -274 assertEquals(5, stateInfo.getRegionCount()); -275 assertEquals(1, stateInfo.getTables().size()); -276 ADMIN.disableTable(tableDescTwo.getTableName()); -277 deleteTable(tableDescTwo.getTableName()); -278 ADMIN.deleteNamespace(namespace); -279 stateInfo = getNamespaceState(namespace); -280 assertNull("Namespace state not found to be null.", stateInfo); -281 } +066import org.apache.hadoop.hbase.coprocessor.RegionServerObserver; +067import org.apache.hadoop.hbase.master.HMaster; +068import org.apache.hadoop.hbase.master.MasterCoprocessorHost; +069import org.apache.hadoop.hbase.master.TableNamespaceManager; +070import org.apache.hadoop.hbase.quotas.MasterQuotaManager; +071import org.apache.hadoop.hbase.quotas.QuotaExceededException; +072import org.apache.hadoop.hbase.quotas.QuotaUtil; +073import org.apache.hadoop.hbase.regionserver.Store; +074import org.apache.hadoop.hbase.regionserver.StoreFile; +075import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker; +076import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException; +077import org.apache.hadoop.hbase.testclassification.MediumTests; +078import org.apache.hadoop.hbase.util.Bytes; +079import org.apache.hadoop.hbase.util.FSUtils; +080import org.apache.hadoop.hbase.util.Threads; +081import org.apache.zookeeper.KeeperException; +082import org.junit.After; +083import org.junit.AfterClass; +084import org.junit.BeforeClass; +085import org.junit.Rule; +086import org.junit.Test; +087import org.junit.experimental.categories.Category; +088import org.junit.rules.TestRule; +089 +090@Category(MediumTests.class) +091public class TestNamespaceAuditor { +092 @Rule public final TestRule timeout = CategoryBasedTimeout.builder(). +093 withTimeout(this.getClass()).withLookingForStuckThread(true).build(); +094 private static final Log LOG = LogFactory.getLog(TestNamespaceAuditor.class); +095 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); +096 private static Admin ADMIN; +097 private String prefix = "TestNamespaceAuditor"; +098 +099 @BeforeClass +100 public static void before() throws Exception { +101 Configuration conf = UTIL.getConfiguration(); +102 conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, CustomObserver.class.getName()); +103 conf.setStrings( +104 CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, +105 MasterSyncObserver.class.getName(), CPMasterObserver.class.getName()); +106 conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 5); +107 conf.setBoolean(QuotaUtil.QUOTA_CONF_KEY, true); +108 conf.setClass("hbase.coprocessor.regionserver.classes", CPRegionServerObserver.class, +109 RegionServerObserver.class); +110 UTIL.startMiniCluster(1, 1); +111 waitForQuotaInitialize(UTIL); +112 ADMIN = UTIL.getAdmin(); +113 } +114 +115 @AfterClass +116 public static void tearDown() throws Exception { +117 UTIL.shutdownMiniCluster(); +118 } +119 +120 @After +121 public void cleanup() throws Exception, KeeperException { +122 for (HTableDescriptor table : ADMIN.listTables()) { +123 ADMIN.disableTable(table.getTableName()); +124 deleteTable(table.getTableName()); +125 } +126 for (NamespaceDescriptor ns : ADMIN.listNamespaceDescriptors()) { +127 if (ns.getName().startsWith(prefix)) { +128 ADMIN.deleteNamespace(ns.getName()); +129 } +130 } +131 assertTrue("Quota manager not initialized", UTIL.getHBaseCluster().getMaster() +132 .getMasterQuotaManager().isQuotaInitialized()); +133 } +134 +135 @Test +136 public void testTableOperations() throws Exception { +137 String nsp = prefix + "_np2"; +138 NamespaceDescriptor nspDesc = +139 NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "5") +140 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build(); +141 ADMIN.createNamespace(nspDesc); +142 assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp)); +143 assertEquals(ADMIN.listNamespaceDescriptors().length, 3); +144 HColumnDescriptor fam1 = new HColumnDescriptor("fam1"); +145 +146 HTableDescriptor tableDescOne = +147 new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1")); +148 tableDescOne.addFamily(fam1); +149 HTableDescriptor tableDescTwo = +150 new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2")); +151 tableDescTwo.addFamily(fam1); +152 HTableDescriptor tableDescThree = +153 new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table3")); +154 tableDescThree.addFamily(fam1); +155 ADMIN.createTable(tableDescOne); +156 boolean constraintViolated = false; +157 try { +158 ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 5); +159 } catch (Exception exp) { +160 assertTrue(exp instanceof IOException); +161 constraintViolated = true; +162 } finally { +163 assertTrue("Constraint not violated for table " + tableDescTwo.getTableName(), +164 constraintViolated); +165 } +166 ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4); +167 NamespaceTableAndRegionInfo nspState = getQuotaManager().getState(nsp); +168 assertNotNull(nspState); +169 assertTrue(nspState.getTables().size() == 2); +170 assertTrue(nspState.getRegionCount() == 5); +171 constraintViolated = false; +172 try { +173 ADMIN.createTable(tableDescThree); +174 } catch (Exception exp) { +175 assertTrue(exp instanceof IOException); +176 constraintViolated = true; +177 } finally { +178 assertTrue("Constraint not violated for table " + tableDescThree.getTableName(), +179 constraintViolated); +180 } +181 } +182 +183 @Test +184 public void testValidQuotas() throws Exception { +185 boolean exceptionCaught = false; +186 FileSystem fs = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getFileSystem(); +187 Path rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); +188 NamespaceDescriptor nspDesc = +189 NamespaceDescriptor.create(prefix + "vq1") +190 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "hihdufh") +191 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build(); +192 try { +193 ADMIN.createNamespace(nspDesc); +194 } catch (Exception exp) { +195 LOG.warn(exp); +196 exceptionCaught = true; +197 } finally { +198 assertTrue(exceptionCaught); +199 assertFalse(fs.exists(FSUtils.getNamespaceDir(rootDir, nspDesc.getName()))); +200 } +201 nspDesc = +202 NamespaceDescriptor.create(prefix + "vq2") +203 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "-456") +204 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build(); +205 try { +206 ADMIN.createNamespace(nspDesc); +207 } catch (Exception exp) { +208 LOG.warn(exp); +209 exceptionCaught = true; +210 } finally { +211 assertTrue(exceptionCaught); +212 assertFalse(fs.exists(FSUtils.getNamespaceDir(rootDir, nspDesc.getName()))); +213 } +214 nspDesc = +215 NamespaceDescriptor.create(prefix + "vq3") +216 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10") +217 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "sciigd").build(); +218 try { +219 ADMIN.createNamespace(nspDesc); +220 } catch (Exception exp) { +221 LOG.warn(exp); +222 exceptionCaught = true; +223 } finally { +224 assertTrue(exceptionCaught); +225 assertFalse(fs.exists(FSUtils.getNamespaceDir(rootDir, nspDesc.getName()))); +226 } +227 nspDesc = +228 NamespaceDescriptor.create(prefix + "vq4") +229 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10") +230 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "-1500").build(); +231 try { +232 ADMIN.createNamespace(nspDesc); +233 } catch (Exception exp) { +234 LOG.warn(exp); +235 exceptionCaught = true; +236 } finally { +237 assertTrue(exceptionCaught); +238 assertFalse(fs.exists(FSUtils.getNamespaceDir(rootDir, nspDesc.getName()))); +239 } +240 } +241 +242 @Test +243 public void testDeleteTable() throws Exception { +244 String namespace = prefix + "_dummy"; +245 NamespaceDescriptor nspDesc = +246 NamespaceDescriptor.create(namespace) +247 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "100") +248 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "3").build(); +249 ADMIN.createNamespace(nspDesc); +250 assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(namespace)); +251 NamespaceTableAndRegionInfo stateInfo = getNamespaceState(nspDesc.getName()); +252 assertNotNull("Namespace state found null for " + namespace, stateInfo); +253 HColumnDescriptor fam1 = new HColumnDescriptor("fam1"); +254 HTableDescriptor tableDescOne = +255 new HTableDescriptor(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table1")); +256 tableDescOne.addFamily(fam1); +257 HTableDescriptor tableDescTwo = +258 new HTableDescriptor(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table2")); +259 tableDescTwo.addFamily(fam1); +260 ADMIN.createTable(tableDescOne); +261 ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 5); +262 stateInfo = getNamespaceState(nspDesc.getName()); +263 assertNotNull("Namespace state found to be null.", stateInfo); +264 assertEquals(2, stateInfo.getTables().size()); +265 assertEquals(5, stateInfo.getRegionCountOfTable(tableDescTwo.getTableName())); +266 assertEquals(6, stateInfo.getRegionCount()); +267 ADMIN.disableTable(tableDescOne.getTableName()); +268 deleteTable(tableDescOne.getTableName()); +269 stateInfo = getNamespaceState(nspDesc.getName()); +270 assertNotNull("Namespace state found to be null.", stateInfo); +271 assertEquals(5, stateInfo.getRegionCount()); +272 assertEquals(1, stateInfo.getTables().size()); +273 ADMIN.disableTable(tableDescTwo.getTableName()); +274 deleteTable(tableDescTwo.getTableName()); +275 ADMIN.deleteNamespace(namespace); +276 stateInfo = getNamespaceState(namespace); +277 assertNull("Namespace state not found to be null.", stateInfo); +278 } +279 +280 public static class CPRegionServerObserver implements RegionServerObserver { +281 private volatile boolean shouldFailMerge = false; 282 -283 public static class CPRegionServerObserver implements RegionServerObserver { -284 private volatile boolean shouldFailMerge = false; -285 -286 public void failMerge(boolean fail) { -287 shouldFailMerge = fail; -288 } -289 -290 private boolean triggered = false; -291 -292 public synchronized void waitUtilTriggered() throws InterruptedException { -293 while (!triggered) { -294 wait(); -295 } -296 } -297 -298 @Override -299 public synchronized void preMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx, -300 Region regionA, Region regionB) throws IOException { -301 triggered = true; -302 notifyAll(); -303 if (shouldFailMerge) { -304 throw new IOException("fail merge"); -305 } -306 } -307 } -308 -309 public static class CPMasterObserver implements MasterObserver { -310 private volatile boolean shouldFailMerge = false; -311 -312 public void failMerge(boolean fail) { -313 shouldFailMerge = fail; -314 } -315 -316 @Override -317 public synchronized void preMergeRegionsAction( -318 final ObserverContext<MasterCoprocessorEnvironment> ctx, -319 final HRegionInfo[] regionsToMerge) throws IOException { -320 notifyAll(); -321 if (shouldFailMerge) { -322 throw new IOException("fail merge"); -323 } -324 } -325 } -326 -327 @Test -328 public void testRegionMerge() throws Exception { -329 String nsp1 = prefix + "_regiontest"; -330 final int initialRegions = 3; -331 NamespaceDescriptor nspDesc = -332 NamespaceDescriptor.create(nsp1) -333 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "" + initialRegions) -334 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build(); -335 ADMIN.createNamespace(nspDesc); -336 final TableName tableTwo = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table2"); -337 byte[] columnFamily = Bytes.toBytes("info"); -338 HTableDescriptor tableDescOne = new HTableDescriptor(tableTwo); -339 tableDescOne.addFamily(new HColumnDescriptor(columnFamily)); -340 ADMIN.createTable(tableDescOne, Bytes.toBytes("0"), Bytes.toBytes("9"), initialRegions); -341 Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); -342 try (Table table = connection.getTable(tableTwo)) { -343 UTIL.loadNumericRows(table, Bytes.toBytes("info"), 1000, 1999); -344 } -345 ADMIN.flush(tableTwo); -346 List<HRegionInfo> hris = ADMIN.getTableRegions(tableTwo); -347 assertEquals(initialRegions, hris.size()); -348 Collections.sort(hris); -349 Future<?> f = ADMIN.mergeRegionsAsync( -350 hris.get(0).getEncodedNameAsBytes(), -351 hris.get(1).getEncodedNameAsBytes(), -352 false); -353 f.get(10, TimeUnit.SECONDS); -354 -355 hris = ADMIN.getTableRegions(tableTwo); -356 assertEquals(initialRegions - 1, hris.size()); -357 Collections.sort(hris); -358 ADMIN.split(tableTwo, Bytes.toBytes("3")); -359 // Not much we can do here until we have split return a Future. -360 Threads.sleep(5000); -361 hris = ADMIN.getTableRegions(tableTwo); -362 assertEquals(initialRegions, hris.size()); -363 Collections.sort(hris); -364 -365 // Fail region merge through Coprocessor hook -366 MiniHBaseCluster cluster = UTIL.getHBaseCluster(); -367 MasterCoprocessorHost cpHost = cluster.getMaster().getMasterCoprocessorHost(); -368 Coprocessor coprocessor = cpHost.findCoprocessor(CPMasterObserver.class.getName()); -369 CPMasterObserver masterObserver = (CPMasterObserver) coprocessor; -370 masterObserver.failMerge(true); -371 -372 f = ADMIN.mergeRegionsAsync( -373 hris.get(1).getEncodedNameAsBytes(), -374 hris.get(2).getEncodedNameAsBytes(), -375 false); -376 try { -377 f.get(10, TimeUnit.SECONDS); -378 fail("Merge was supposed to fail!"); -379 } catch (ExecutionException ee) { -380 // Expected. -381 } -382 hris = ADMIN.getTableRegions(tableTwo); -383 assertEquals(initialRegions, hris.size()); -384 Collections.sort(hris); -385 // verify that we cannot split -386 HRegionInfo hriToSplit2 = hris.get(1); -387 ADMIN.split(tableTwo, Bytes.toBytes("6")); -388 Thread.sleep(2000); -389 assertEquals(initialRegions, ADMIN.getTableRegions(tableTwo).size()); -390 } -391 -392 /* -393 * Create a table and make sure that the table creation fails after adding this table entry into -394 * namespace quota cache. Now correct the failure and recreate the table with same name. -395 * HBASE-13394 -396 */ -397 @Test -398 public void testRecreateTableWithSameNameAfterFirstTimeFailure() throws Exception { -399 String nsp1 = prefix + "_testRecreateTable"; -400 NamespaceDescriptor nspDesc = -401 NamespaceDescriptor.create(nsp1) -402 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "20") -403 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1").build(); -404 ADMIN.createNamespace(nspDesc); -405 final TableName tableOne = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table1"); -406 byte[] columnFamily = Bytes.toBytes("info"); -407 HTableDescriptor tableDescOne = new HTableDescriptor(tableOne); -408 tableDescOne.addFamily(new HColumnDescriptor(columnFamily)); -409 MasterSyncObserver.throwExceptionInPreCreateTableAction = true; -410 try { +283 public void failMerge(boolean fail) { +284 shouldFailMerge = fail; +285 } +286 +287 private boolean triggered = false; +288 +289 public synchronized void waitUtilTriggered() throws InterruptedException { +290 while (!triggered) { +291 wait(); +292 } +293 } +294 } +295 +296 public static class CPMasterObserver implements MasterObserver { +297 private volatile boolean shouldFailMerge = false; +298 +299 public void failMerge(boolean fail) { +300 shouldFailMerge = fail; +301 } +302 +303 @Override +304 public synchronized void preMergeRegionsAction( +305 final ObserverContext<MasterCoprocessorEnvironment> ctx, +306 final HRegionInfo[] regionsToMerge) throws IOException { +307 notifyAll(); +308 if (shouldFailMerge) { +309 throw new IOException("fail merge"); +310 } +311 } +312 } +313 +314 @Test +315 public void testRegionMerge() throws Exception { +316 String nsp1 = prefix + "_regiontest"; +317 final int initialRegions = 3; +318 NamespaceDescriptor nspDesc = +319 NamespaceDescriptor.create(nsp1) +320 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "" + initialRegions) +321 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build(); +322 ADMIN.createNamespace(nspDesc); +323 final TableName tableTwo = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table2"); +324 byte[] columnFamily = Bytes.toBytes("info"); +325 HTableDescriptor tableDescOne = new HTableDescriptor(tableTwo); +326 tableDescOne.addFamily(new HColumnDescriptor(columnFamily)); +327 ADMIN.createTable(tableDescOne, Bytes.toBytes("0"), Bytes.toBytes("9"), initialRegions); +328 Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); +329 try (Table table = connection.getTable(tableTwo)) { +330 UTIL.loadNumericRows(table, Bytes.toBytes("info"), 1000, 1999); +331 } +332 ADMIN.flush(tableTwo); +333 List<HRegionInfo> hris = ADMIN.getTableRegions(tableTwo); +334 assertEquals(initialRegions, hris.size()); +335 Collections.sort(hris); +336 Future<?> f = ADMIN.mergeRegionsAsync( +337 hris.get(0).getEncodedNameAsBytes(), +338 hris.get(1).getEncodedNameAsBytes(), +339 false); +340 f.get(10, TimeUnit.SECONDS); +341 +342 hris = ADMIN.getTableRegions(tableTwo); +343 assertEquals(initialRegions - 1, hris.size()); +344 Collections.sort(hris); +345 ADMIN.split(tableTwo, Bytes.toBytes("3")); +346 // Not much we can do here until we have split return a Future. +347 Threads.sleep(5000); +348 hris = ADMIN.getTableRegions(tableTwo); +349 assertEquals(initialRegions, hris.size()); +350 Collections.sort(hris); +351 +352 // Fail region merge through Coprocessor hook +353 MiniHBaseCluster cluster = UTIL.getHBaseCluster(); +354 MasterCoprocessorHost cpHost = cluster.getMaster().getMasterCoprocessorHost(); +355 Coprocessor coprocessor = cpHost.findCoprocessor(CPMasterObserver.class.getName()); +356 CPMasterObserver masterObserver = (CPMasterObserver) coprocessor; +357 masterObserver.failMerge(true); +358 +359 f = ADMIN.mergeRegionsAsync( +360 hris.get(1).getEncodedNameAsBytes(), +361 hris.get(2).getEncodedNameAsBytes(), +362 false); +363 try { +364 f.get(10, TimeUnit.SECONDS); +365 fail("Merge was supposed to fail!"); +366 } catch (ExecutionException ee) { +367 // Expected. +368 } +369 hris = ADMIN.getTableRegions(tableTwo); +370 assertEquals(initialRegions, hris.size()); +371 Collections.sort(hris); +372 // verify that we cannot split +373 HRegionInfo hriToSplit2 = hris.get(1); +374 ADMIN.split(tableTwo, Bytes.toBytes("6")); +375 Thread.sleep(2000); +376 assertEquals(initialRegions, ADMIN.getTableRegions(tableTwo).size()); +377 } +378 +379 /* +380 * Create a table and make sure that the table creation fails after adding this table entry into +381 * namespace quota cache. Now correct the failure and recreate the table with same name. +382 * HBASE-13394 +383 */ +384 @Test +385 public void testRecreateTableWithSameNameAfterFirstTimeFailure() throws Exception { +386 String nsp1 = prefix + "_testRecreateTable"; +387 NamespaceDescriptor nspDesc = +388 NamespaceDescriptor.create(nsp1) +389 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "20") +390 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1").build(); +391 ADMIN.createNamespace(nspDesc); +392 final TableName tableOne = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table1"); +393 byte[] columnFamily = Bytes.toBytes("info"); +394 HTableDescriptor tableDescOne = new HTableDescriptor(tableOne); +395 tableDescOne.addFamily(new HColumnDescriptor(columnFamily)); +396 MasterSyncObserver.throwExceptionInPreCreateTableAction = true; +397 try { +398 try { +399 ADMIN.createTable(tableDescOne); +400 fail("Table " + tableOne.toString() + "creation should fail."); +401 } catch (Exception exp) { +402 LOG.error(exp); +403 } +404 assertFalse(ADMIN.tableExists(tableOne)); +405 +406 NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp1); +407 assertEquals("First table creation failed in namespace so number of tables in namespace " +408 + "should be 0.", 0, nstate.getTables().size()); +409 +410 MasterSyncObserver.throwExceptionInPreCreateTableAction = false; 411 try { 412 ADMIN.createTable(tableDescOne); -413 fail("Table " + tableOne.toString() + "creation should fail."); -414 } catch (Exception exp) { -415 LOG.error(exp); +413 } catch (Exception e) { +414 fail("Table " + tableOne.toString() + "creation should succeed."); +415 LOG.error(e); 416 } -417 assertFalse(ADMIN.tableExists(tableOne)); -418 -419 NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp1); -420 assertEquals("First table creation failed in namespace so number of tables in namespace " -421 + "should be 0.", 0, nstate.getTables().size()); -422 -423 MasterSyncObserver.throwExceptionInPreCreateTableAction = false; -424 try { -425 ADMIN.createTable(tableDescOne); -426 } catch (Exception e) { -427 fail("Table " + tableOne.toString() + "creation should succeed."); -428 LOG.error(e); -429 } -430 assertTrue(ADMIN.tableExists(tableOne)); -431 nstate = getNamespaceState(nsp1); -432 assertEquals("First table was created successfully so table size in namespace should " -433 + "be one now.", 1, nstate.getTables().size()); -434 } finally { -435 MasterSyncObserver.throwExceptionInPreCreateTableAction = false; -436 if (ADMIN.tableExists(tableOne)) { -437 ADMIN.disableTable(tableOne); -438 deleteTable(tableOne); -439 } -440 ADMIN.deleteNamespace(nsp1); -441 } -442 } -443 -444 private NamespaceTableAndRegionInfo getNamespaceState(String namespace) throws KeeperException, -445 IOException { -446 return getQuotaManager().getState(namespace); -447 } -448 -449 byte[] getSplitKey(byte[] startKey, byte[] endKey) { -450 String skey = Bytes.toString(startKey); -451 int key; -452 if (StringUtils.isBlank(skey)) { -453 key = Integer.parseInt(Bytes.toString(endKey))/2 ; -454 } else { -455 key = (int) (Integer.parseInt(skey) * 1.5); -456 } -457 return Bytes.toBytes("" + key); -458 } -459 -460 public static class CustomObserver implements RegionObserver { -461 volatile CountDownLatch postCompact; -462 -463 @Override -464 public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, Store store, -465 StoreFile resultFile, CompactionLifeCycleTracker tracker) throws IOException { -466 postCompact.countDown(); -467 } -468 -469 @Override -470 public void start(CoprocessorEnvironment e) throws IOException { -471 postCompact = new CountDownLatch(1); -472 } -473 } -474 -475 @Test -476 public void testStatePreserve() throws Exception { -477 final String nsp1 = prefix + "_testStatePreserve"; -478 NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp1) -479 .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "20") -480 .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "10").build(); -481 ADMIN.createNamespace(nspDesc); -482 TableName tableOne = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table1"); -483 TableName tableTwo = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table2"); -484 TableName tableThree = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table3"); -485 HColumnDescriptor fam1 = new HColumnDescriptor("fam1"); -486 HTableDescriptor tableDescOne = new HTableDescriptor(tableOne); -487 tableDescOne.addFamily(fam1); -488 HTableDescriptor tableDescTwo = new HTableDescriptor(tableTwo); -489 tableDescTwo.addFamily(fam1); -490 HTableDescriptor tableDescThree = new HTableDescriptor(tableThree); -491 tableDescThree.addFamily(fam1); -492 ADMIN.createTable(tableDescOne, Bytes.toBytes("1"), Bytes.toBytes("1000"), 3); -493 ADMIN.createTable(tableDescTwo, Bytes.toBytes("1"), Bytes.toBytes("1000"), 3); -494 ADMIN.createTable(tableDescThree, Bytes.toBytes("1"), Bytes.toBytes("1000"), 4); -495 ADMIN.disableTable(tableThree); -496 deleteTable(tableThree); -497 // wait for chore to complete -498 UTIL.waitFor(1000, new Waiter.Predicate<Exception>() { -499 @Override -500 public boolean evaluate() throws Exception { -501 return (getNamespaceState(nsp1).getTables().size() == 2); -502 } -503 }); -504 NamespaceTableAndRegionInfo before = getNamespaceState(nsp1); -505 restartMaster(); -506 NamespaceTableAndRegionInfo after = getNamespaceState(nsp1); -507 assertEquals("Expected: " + before.getTables() + " Found: " + after.getTables(), before -508 .getTables().size(), after.getTables().size()); -509 } -510 -511 public static void waitForQuotaInitialize(final HBaseTestingUtility util) throws Exception { -512 util.waitFor(60000, new Waiter.Predicate<Exception>() { -513 @Override -514 public boolean evaluate() throws Exception { -515 HMaster master = util.getHBaseCluster().getMaster(); -516 if (master == null) { -517 return false; -518 } -519 MasterQuotaManager quotaManager = master.getMasterQuotaManager(); -520 return quotaManager != null && quotaManager.isQuotaInitialized(); -521 } -522 }); -523 } -524 -525 private void restartMaster() throws Exception { -526 UTIL.getHBaseCluster().getMaster(0).stop("Stopping to start again"); -527 UTIL.getHBaseCluster().waitOnMaster(0); -528 UTIL.getHBaseCluster().startMaster(); -529 waitForQuotaInitialize(UTIL); -530 } -531 -532 private NamespaceAuditor getQuotaManager() { -533 return UTIL.getHBaseCluster().getMaster() -534 .getMasterQuotaManager().getNamespaceQuotaManager(); -535 } -536 -537 public static class MasterSyncObserver implements MasterObserver { -538 volatile CountDownLatch tableDeletionLatch; -539 static boolean throwExceptionInPreCreateTableAction; +417 assertTrue(ADMIN.tableExists(tableOne)); +418 nstate = getNamespaceState(nsp1); +419 assertEquals("First table was created successfully so table size in namespace should " +420 + "be one now.", 1, nstate.getTables().size()); +421 } finally { +422 MasterSyncObserver.throwExceptionInPreCreateTableAction = false; +423 if (ADMIN.tableExists(tableOne)) { +424 ADMIN.disableTable(tableOne); +425 deleteTable(tableOne); +426 } +427 ADMIN.deleteNamespace(nsp1); +428 } +429 } +430 +431 private NamespaceTableAndRegionInfo getNamespaceState(String namespace) throws KeeperException, +432 IOException { +433 return getQuotaManager().getState(namespace); +434 } +435 +436 byte[] getSplitKey(byte[] startKey, byte[] endKey) { +437 String skey = Bytes.toString(startKey); +438 int key; +439 if (StringUtils.isBlank(skey)) { +440 key = Integer.parseInt(Bytes.toString(endKey))/2 ; +441 } else { +442 key = (int) (Integer.parseInt(skey) * 1.5); +443 } +444 return Bytes.toBytes("" + key); +445 } +446 +447 public static class CustomObserver implements RegionObserver { +448 volatile CountDownLatch postCompact; +449 +450 @Override +451 public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, Store store, +452 StoreFile resultFile, CompactionLifeCycleTracker tracker) throws IOException { +453 postCompact.countDown(); +454 } +455 +456 @Override +457 public void start(CoprocessorEnvironment e) throws IOException { +458 postCompact = new CountDownLatch(1); +459 } +460 } +461 +