public JVMClusterUtil.MasterThread addMaster(Configuration c, final int index) throws IOException { // Create each master with its own Configuration instance so each has // its HConnection instance rather than share (see HBASE_INSTANCES down in // the guts of HConnectionManager. // Also, create separate CoordinatedStateManager instance per Server. // This is special case when we have to have more than 1 CoordinatedStateManager // within 1 process. CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf); JVMClusterUtil.MasterThread mt = JVMClusterUtil.createMasterThread(c, cp, (Class<? extends HMaster>) conf.getClass(HConstants.MASTER_IMPL, this.masterClass), index); this.masterThreads.add(mt); return mt; }
/** * Creates a {@link MasterThread}. * Call 'start' on the returned thread to make it run. * @param c Configuration to use. * @param cp consensus provider to use * @param hmc Class to create. * @param index Used distinguishing the object returned. * @throws IOException * @return Master added. */ public static JVMClusterUtil.MasterThread createMasterThread( final Configuration c, CoordinatedStateManager cp, final Class<? extends HMaster> hmc, final int index) throws IOException { HMaster server; try { server = hmc.getConstructor(Configuration.class, CoordinatedStateManager.class). newInstance(c, cp); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException(); throw new RuntimeException("Failed construction of Master: " + hmc.toString() + ((target.getCause() != null)? target.getCause().getMessage(): ""), target); } catch (Exception e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } return new JVMClusterUtil.MasterThread(server, index); }
@Override public ServerName getServerHoldingRegion(final TableName tn, byte[] regionName) throws IOException { // Assume there is only one master thread which is the active master. // If there are multiple master threads, the backup master threads // should hold some regions. Please refer to #countServedRegions // to see how we find out all regions. HMaster master = getMaster(); Region region = master.getOnlineRegion(regionName); if (region != null) { return master.getServerName(); } int index = getServerWith(regionName); if (index < 0) { return null; } return getRegionServer(index).getServerName(); }
@Test public void testFlushedSequenceIdsSentToHMaster() throws IOException, InterruptedException, ServiceException { SortedMap<byte[], Long> allFlushedSequenceIds = new TreeMap<byte[], Long>(Bytes.BYTES_COMPARATOR); for (int i = 0; i < NUM_RS; ++i) { flushAllRegions(i); } Thread.sleep(10000); HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); for (int i = 0; i < NUM_RS; ++i) { for (byte[] regionName : getRegionsByServer(i)) { if (allFlushedSequenceIds.containsKey(regionName)) { GetLastFlushedSequenceIdRequest req = RequestConverter.buildGetLastFlushedSequenceIdRequest(regionName); assertEquals((long)allFlushedSequenceIds.get(regionName), master.getMasterRpcServices().getLastFlushedSequenceId( null, req).getLastFlushedSequenceId()); } } } }
private void moveRegionAndWait(HRegionInfo destRegion, ServerName destServer) throws InterruptedException, MasterNotRunningException, ZooKeeperConnectionException, IOException { HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); TEST_UTIL.getHBaseAdmin().move( destRegion.getEncodedNameAsBytes(), Bytes.toBytes(destServer.getServerName())); while (true) { ServerName serverName = master.getAssignmentManager() .getRegionStates().getRegionServerOfRegion(destRegion); if (serverName != null && serverName.equals(destServer)) { TEST_UTIL.assertRegionOnServer( destRegion, serverName, 200); break; } Thread.sleep(10); } }
@Test (timeout=300000) public void testMoveToPreviouslyAssignedRS() throws IOException, InterruptedException { byte[] tableName = Bytes.toBytes("testMoveToPreviouslyAssignedRS"); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); HBaseAdmin localAdmin = createTable(tableName); List<HRegionInfo> tableRegions = localAdmin.getTableRegions(tableName); HRegionInfo hri = tableRegions.get(0); AssignmentManager am = master.getAssignmentManager(); assertTrue("Region " + hri.getRegionNameAsString() + " should be assigned properly", am.waitForAssignment(hri)); ServerName server = am.getRegionStates().getRegionServerOfRegion(hri); localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName())); assertEquals("Current region server and region server before move should be same.", server, am.getRegionStates().getRegionServerOfRegion(hri)); }
@Test (timeout=300000) public void testCreateTableCalledTwiceAndFirstOneInProgress() throws Exception { final TableName tableName = TableName.valueOf("testCreateTableCalledTwiceAndFirstOneInProgress"); final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); final HMaster m = cluster.getMaster(); final HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(FAMILYNAME)); final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getTableName(), null, null) }; CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(), desc, cluster.getConfiguration(), hRegionInfos, m); handler.prepare(); throwException = true; handler.process(); throwException = false; CustomCreateTableHandler handler1 = new CustomCreateTableHandler(m, m.getMasterFileSystem(), desc, cluster.getConfiguration(), hRegionInfos, m); handler1.prepare(); handler1.process(); for (int i = 0; i < 100; i++) { if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) { Thread.sleep(200); } } assertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(tableName)); }
@Test (timeout=60000) public void testMasterRestartAfterEnablingNodeIsCreated() throws Exception { byte[] tableName = Bytes.toBytes("testMasterRestartAfterEnablingNodeIsCreated"); final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); final HMaster m = cluster.getMaster(); final HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); desc.addFamily(new HColumnDescriptor(FAMILYNAME)); final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getTableName(), null, null) }; CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(), desc, cluster.getConfiguration(), hRegionInfos, m); handler.prepare(); throwException = true; handler.process(); abortAndStartNewMaster(cluster); assertTrue(cluster.getLiveMasterThreads().size() == 1); }
@Test (timeout=180000) public void testStarted() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); assertTrue("Master should be active", master.isActiveMaster()); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); assertNotNull("CoprocessorHost should not be null", host); CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( CPMasterObserver.class.getName()); assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp); // check basic lifecycle assertTrue("MasterObserver should have been started", cp.wasStarted()); assertTrue("preMasterInitialization() hook should have been called", cp.wasMasterInitializationCalled()); assertTrue("postStartMaster() hook should have been called", cp.wasStartMasterCalled()); }
@Test (timeout=180000) public void testTableDescriptorsEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( CPMasterObserver.class.getName()); cp.resetStates(); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); master.getMasterRpcServices().getTableDescriptors(null, req); assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled()); }
/** * Helper method for testing async snapshot operations. Just waits for the * given snapshot to complete on the server by repeatedly checking the master. * * @param master: the master running the snapshot * @param snapshot: the snapshot to check * @param sleep: amount to sleep between checks to see if the snapshot is done * @throws ServiceException if the snapshot fails */ public static void waitForSnapshotToComplete(HMaster master, SnapshotDescription snapshot, long sleep) throws ServiceException { final IsSnapshotDoneRequest request = IsSnapshotDoneRequest.newBuilder() .setSnapshot(snapshot).build(); IsSnapshotDoneResponse done = IsSnapshotDoneResponse.newBuilder() .buildPartial(); while (!done.getDone()) { done = master.getMasterRpcServices().isSnapshotDone(null, request); try { Thread.sleep(sleep); } catch (InterruptedException e) { throw new ServiceException(e); } } }
/** * Expect the snapshot to throw an error when checking if the snapshot is * complete * * @param master master to check * @param snapshot the {@link SnapshotDescription} request to pass to the master * @param clazz expected exception from the master */ public static void expectSnapshotDoneException(HMaster master, IsSnapshotDoneRequest snapshot, Class<? extends HBaseSnapshotException> clazz) { try { master.getMasterRpcServices().isSnapshotDone(null, snapshot); Assert.fail("didn't fail to lookup a snapshot"); } catch (ServiceException se) { try { throw ProtobufUtil.getRemoteException(se); } catch (HBaseSnapshotException e) { assertEquals("Threw wrong snapshot exception!", clazz, e.getClass()); } catch (Throwable t) { Assert.fail("Threw an unexpected exception:" + t); } } }
@Test(timeout = 300000) public void testAsyncFlushSnapshot() throws Exception { Admin admin = UTIL.getHBaseAdmin(); SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("asyncSnapshot") .setTable(TABLE_NAME.getNameAsString()) .setType(SnapshotDescription.Type.FLUSH) .build(); // take the snapshot async admin.takeSnapshotAsync(snapshot); // constantly loop, looking for the snapshot to complete HMaster master = UTIL.getMiniHBaseCluster().getMaster(); SnapshotTestingUtils.waitForSnapshotToComplete(master, snapshot, 200); LOG.info(" === Async Snapshot Completed ==="); UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG); // make sure we get the snapshot SnapshotTestingUtils.assertOneSnapshotThatMatches(admin, snapshot); }
@Test public void testRewritingClusterIdToPB() throws Exception { TEST_UTIL.startMiniZKCluster(); TEST_UTIL.startMiniDFSCluster(1); TEST_UTIL.createRootDir(); TEST_UTIL.getConfiguration().setBoolean("hbase.replication", true); Path rootDir = FSUtils.getRootDir(TEST_UTIL.getConfiguration()); FileSystem fs = rootDir.getFileSystem(TEST_UTIL.getConfiguration()); Path filePath = new Path(rootDir, HConstants.CLUSTER_ID_FILE_NAME); FSDataOutputStream s = null; try { s = fs.create(filePath); s.writeUTF(UUID.randomUUID().toString()); } finally { if (s != null) { s.close(); } } TEST_UTIL.startMiniHBaseCluster(1, 1); HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); assertEquals(1, master.getServerManager().getOnlineServersList().size()); }
private void moveRegionAndWait(Region destRegion, HRegionServer destServer) throws InterruptedException, MasterNotRunningException, ZooKeeperConnectionException, IOException { HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); TEST_UTIL.getHBaseAdmin().move( destRegion.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(destServer.getServerName().getServerName())); while (true) { ServerName serverName = master.getAssignmentManager() .getRegionStates().getRegionServerOfRegion(destRegion.getRegionInfo()); if (serverName != null && serverName.equals(destServer.getServerName())) { TEST_UTIL.assertRegionOnServer( destRegion.getRegionInfo(), serverName, 200); break; } Thread.sleep(10); } }
private void waitAndVerifyRegionNum(HMaster master, TableName tablename, int expectedRegionNum) throws Exception { List<Pair<HRegionInfo, ServerName>> tableRegionsInMeta; List<HRegionInfo> tableRegionsInMaster; long timeout = System.currentTimeMillis() + waitTime; while (System.currentTimeMillis() < timeout) { tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(master.getZooKeeper(), master.getConnection(), tablename); tableRegionsInMaster = master.getAssignmentManager().getRegionStates() .getRegionsOfTable(tablename); if (tableRegionsInMeta.size() == expectedRegionNum && tableRegionsInMaster.size() == expectedRegionNum) { break; } Thread.sleep(250); } tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(master.getZooKeeper(), master.getConnection(), tablename); LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta)); assertEquals(expectedRegionNum, tableRegionsInMeta.size()); }
/** * Helper method for testing async snapshot operations. Just waits for the * given snapshot to complete on the server by repeatedly checking the master. * * @param master: the master running the snapshot * @param snapshot: the snapshot to check * @param sleep: amount to sleep between checks to see if the snapshot is done * @throws ServiceException if the snapshot fails */ public static void waitForSnapshotToComplete(HMaster master, SnapshotDescription snapshot, long sleep) throws ServiceException { final IsSnapshotDoneRequest request = IsSnapshotDoneRequest.newBuilder() .setSnapshot(snapshot).build(); IsSnapshotDoneResponse done = IsSnapshotDoneResponse.newBuilder() .buildPartial(); while (!done.getDone()) { done = master.isSnapshotDone(null, request); try { Thread.sleep(sleep); } catch (InterruptedException e) { throw new ServiceException(e); } } }
@Test(timeout = 180000) public void testRoundRobinAssignmentDuringIndexTableCreation() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); String tableName = "testRoundRobinAssignmentDuringIndexTableCreation"; String indexTableName = IndexUtils.getIndexTableName(tableName); HTableDescriptor iHtd = TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq"); char c = 'A'; byte[][] split = new byte[20][]; for (int i = 0; i < 20; i++) { byte[] b = { (byte) c }; split[i] = b; c++; } admin.createTable(iHtd, split); boolean isRegionColocated = TestUtils.checkForColocation(master, tableName, indexTableName); assertTrue("User regions and index regions should colocate.", isRegionColocated); }
@Test(timeout = 180000) public void testEnabledIndexTableShouldBeDisabledIfUserTableInDisablingAndMasterRestarted() throws Exception { String tableName = "testEnabledIndexTableDisabledIfUserTableInDisablingAndMasterRestarted"; String indexTableName = IndexUtils.getIndexTableName(tableName); HTableDescriptor iHtd = TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq"); admin.createTable(iHtd); MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); master.getAssignmentManager().getZKTable().setDisablingTable(TableName.valueOf(tableName)); cluster.abortMaster(0); cluster.startMaster(); cluster.waitOnMaster(0); cluster.waitForActiveAndReadyMaster(); Thread.sleep(1000); assertTrue("User table should be disabled.", admin.isTableDisabled(tableName)); assertTrue("Index table should be disabled.", admin.isTableDisabled(indexTableName)); }
@Override public void process() { TableName tableName = this.hTableDescriptor.getTableName(); LOG.info("Create table " + tableName); try { MasterCoprocessorHost cpHost = ((HMaster) this.server).getCoprocessorHost(); if (cpHost != null) { cpHost.preCreateTableHandler(this.hTableDescriptor, this.newRegions); } handleCreateTable(tableName); completed(null); if (cpHost != null) { cpHost.postCreateTableHandler(this.hTableDescriptor, this.newRegions); } } catch (Throwable e) { LOG.error("Error trying to create the table " + tableName, e); completed(e); } }
/** * Creates a {@link MasterThread}. * Call 'start' on the returned thread to make it run. * @param c Configuration to use. * @param hmc Class to create. * @param index Used distinguishing the object returned. * @throws IOException * @return Master added. */ public static JVMClusterUtil.MasterThread createMasterThread( final Configuration c, final Class<? extends HMaster> hmc, final int index) throws IOException { HMaster server; try { server = hmc.getConstructor(Configuration.class).newInstance(c); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException(); throw new RuntimeException("Failed construction of Master: " + hmc.toString() + ((target.getCause() != null)? target.getCause().getMessage(): ""), target); } catch (Exception e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } return new JVMClusterUtil.MasterThread(server, index); }
@Override protected void handleTableOperation(List<HRegionInfo> hris) throws IOException { MasterCoprocessorHost cpHost = ((HMaster) this.server).getMasterCoprocessorHost(); if (cpHost != null) { cpHost.preModifyTableHandler(this.tableName, this.htd); } // Update descriptor HTableDescriptor oldHtd = getTableDescriptor(); this.masterServices.getTableDescriptors().add(this.htd); deleteFamilyFromFS(hris, oldHtd.getFamiliesKeys()); removeReplicaColumnsIfNeeded(this.htd.getRegionReplication(), oldHtd.getRegionReplication(), htd.getTableName()); if (cpHost != null) { cpHost.postModifyTableHandler(this.tableName, this.htd); } }
public static List<Pair<byte[], ServerName>> getStartKeysAndLocations(HMaster master, String tableName) throws IOException, InterruptedException { List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations = MetaReader.getTableRegionsAndLocations(master.getCatalogTracker(), TableName.valueOf(tableName)); List<Pair<byte[], ServerName>> startKeyAndLocationPairs = new ArrayList<Pair<byte[], ServerName>>(tableRegionsAndLocations.size()); Pair<byte[], ServerName> startKeyAndLocation = null; for (Pair<HRegionInfo, ServerName> regionAndLocation : tableRegionsAndLocations) { startKeyAndLocation = new Pair<byte[], ServerName>(regionAndLocation.getFirst().getStartKey(), regionAndLocation.getSecond()); startKeyAndLocationPairs.add(startKeyAndLocation); } return startKeyAndLocationPairs; }
@Override protected void handleTableOperation(List<HRegionInfo> regions) throws IOException, CoordinatedStateException { MasterCoprocessorHost cpHost = ((HMaster) this.server).getMasterCoprocessorHost(); if (cpHost != null) { cpHost.preTruncateTableHandler(this.tableName); } // 1. Wait because of region in transition waitRegionInTransition(regions); // 2. Remove table from hbase:meta and HDFS removeTableData(regions); // ----------------------------------------------------------------------- // PONR: At this point the table is deleted. // If the recreate fails, the user can only re-create the table. // ----------------------------------------------------------------------- // 3. Recreate the regions recreateTable(regions); if (cpHost != null) { cpHost.postTruncateTableHandler(this.tableName); } }
@Override public void process() { TableName tableName = this.hTableDescriptor.getTableName(); LOG.info("Create table " + tableName); try { final MasterCoprocessorHost cpHost = ((HMaster) this.server).getMasterCoprocessorHost(); if (cpHost != null) { cpHost.preCreateTableHandler(this.hTableDescriptor, this.newRegions); } handleCreateTable(tableName); completed(null); if (cpHost != null) { this.activeUser.runAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { cpHost.postCreateTableHandler(hTableDescriptor, newRegions); return null; } }); } } catch (Throwable e) { LOG.error("Error trying to create the table " + tableName, e); completed(e); } }
@Test(timeout = 300000) public void testAsyncFlushSnapshot() throws Exception { HBaseAdmin admin = UTIL.getHBaseAdmin(); SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("asyncSnapshot") .setTable(TABLE_NAME.getNameAsString()) .setType(SnapshotDescription.Type.FLUSH) .build(); // take the snapshot async admin.takeSnapshotAsync(snapshot); // constantly loop, looking for the snapshot to complete HMaster master = UTIL.getMiniHBaseCluster().getMaster(); SnapshotTestingUtils.waitForSnapshotToComplete(master, snapshot, 200); LOG.info(" === Async Snapshot Completed ==="); FSUtils.logFileSystemState(UTIL.getTestFileSystem(), FSUtils.getRootDir(UTIL.getConfiguration()), LOG); // make sure we get the snapshot SnapshotTestingUtils.assertOneSnapshotThatMatches(admin, snapshot); }
@Test public void testTableDescriptorsEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getCoprocessorHost(); CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( CPMasterObserver.class.getName()); cp.resetStates(); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); master.getTableDescriptors(null, req); assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled()); }
@Test public void testStarted() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); assertTrue("Master should be active", master.isActiveMaster()); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); assertNotNull("CoprocessorHost should not be null", host); CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( CPMasterObserver.class.getName()); assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp); // check basic lifecycle assertTrue("MasterObserver should have been started", cp.wasStarted()); assertTrue("preMasterInitialization() hook should have been called", cp.wasMasterInitializationCalled()); assertTrue("postStartMaster() hook should have been called", cp.wasStartMasterCalled()); }
@Test public void testTableDescriptorsEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( CPMasterObserver.class.getName()); cp.resetStates(); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); master.getMasterRpcServices().getTableDescriptors(null, req); assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled()); }
@Test(timeout = 300000) public void testAsyncFlushSnapshot() throws Exception { Admin admin = UTIL.getHBaseAdmin(); SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("asyncSnapshot") .setTable(TABLE_NAME.getNameAsString()) .setType(SnapshotDescription.Type.FLUSH) .build(); // take the snapshot async admin.takeSnapshotAsync(snapshot); // constantly loop, looking for the snapshot to complete HMaster master = UTIL.getMiniHBaseCluster().getMaster(); SnapshotTestingUtils.waitForSnapshotToComplete(master, snapshot, 200); LOG.info(" === Async Snapshot Completed ==="); FSUtils.logFileSystemState(UTIL.getTestFileSystem(), FSUtils.getRootDir(UTIL.getConfiguration()), LOG); // make sure we get the snapshot SnapshotTestingUtils.assertOneSnapshotThatMatches(admin, snapshot); }
@Test(timeout = 180000) public void testRandomAssignmentDuringIndexTableEnable() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); master.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", false); HTableDescriptor iHtd = TestUtils.createIndexedHTableDescriptor("testRandomAssignmentDuringIndexTableEnable", "cf", "index_name", "cf", "cq"); char c = 'A'; byte[][] split = new byte[3][]; for (int i = 0; i < 3; i++) { byte[] b = { (byte) c }; split[i] = b; c++; } admin.createTable(iHtd, split); String tableName = "testRandomAssignmentDuringIndexTableEnable"; String indexTableName = "testRandomAssignmentDuringIndexTableEnable" + Constants.INDEX_TABLE_SUFFIX; admin.disableTable(tableName); admin.enableTable(tableName); boolean isRegionColocated = TestUtils.checkForColocation(master, tableName, indexTableName); assertTrue("User regions and index regions should colocate.", isRegionColocated); }
private void moveRegionAndWait(HRegion destRegion, HRegionServer destServer) throws InterruptedException, MasterNotRunningException, ZooKeeperConnectionException, IOException { HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); TEST_UTIL.getHBaseAdmin().move( destRegion.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(destServer.getServerName().getServerName())); while (true) { ServerName serverName = master.getAssignmentManager() .getRegionStates().getRegionServerOfRegion(destRegion.getRegionInfo()); if (serverName != null && serverName.equals(destServer.getServerName())) { TEST_UTIL.assertRegionOnServer( destRegion.getRegionInfo(), serverName, 200); break; } Thread.sleep(10); } }
public static boolean checkForColocation(HMaster master, String tableName, String indexTableName) throws IOException, InterruptedException { List<Pair<byte[], ServerName>> uTableStartKeysAndLocations = getStartKeysAndLocations(master, tableName); List<Pair<byte[], ServerName>> iTableStartKeysAndLocations = getStartKeysAndLocations(master, indexTableName); boolean regionsColocated = true; if (uTableStartKeysAndLocations.size() != iTableStartKeysAndLocations.size()) { regionsColocated = false; } else { for (int i = 0; i < uTableStartKeysAndLocations.size(); i++) { Pair<byte[], ServerName> uStartKeyAndLocation = uTableStartKeysAndLocations.get(i); Pair<byte[], ServerName> iStartKeyAndLocation = iTableStartKeysAndLocations.get(i); if (Bytes.compareTo(uStartKeyAndLocation.getFirst(), iStartKeyAndLocation.getFirst()) == 0) { if (uStartKeyAndLocation.getSecond().equals(iStartKeyAndLocation.getSecond())) { continue; } } regionsColocated = false; } } return regionsColocated; }
/** * Constructor. * @param conf Configuration to use. Post construction has the master's * address. * @param noMasters Count of masters to start. * @param noRegionServers Count of regionservers to start. * @param masterClass * @param regionServerClass * @throws IOException */ @SuppressWarnings("unchecked") public LocalHBaseCluster(final Configuration conf, final int noMasters, final int noRegionServers, final Class<? extends HMaster> masterClass, final Class<? extends HRegionServer> regionServerClass) throws IOException { this.conf = conf; // Always have masters and regionservers come up on port '0' so we don't // clash over default ports. conf.set(HConstants.MASTER_PORT, "0"); conf.set(HConstants.REGIONSERVER_PORT, "0"); if (conf.getInt(HConstants.REGIONSERVER_INFO_PORT, 0) != -1) { conf.set(HConstants.REGIONSERVER_INFO_PORT, "0"); } this.masterClass = (Class<? extends HMaster>) conf.getClass(HConstants.MASTER_IMPL, masterClass); // Start the HMasters. for (int i = 0; i < noMasters; i++) { addMaster(new Configuration(conf), i); } // Start the HRegionServers. this.regionServerClass = (Class<? extends HRegionServer>)conf.getClass(HConstants.REGION_SERVER_IMPL, regionServerClass); for (int i = 0; i < noRegionServers; i++) { addRegionServer(new Configuration(conf), i); } }