/** * Create a RegionOpenInfo based on given region info and version of offline node */ private static RegionOpenInfo buildRegionOpenInfo( final HRegionInfo region, final int versionOfOfflineNode, final List<ServerName> favoredNodes, Boolean openForReplay) { RegionOpenInfo.Builder builder = RegionOpenInfo.newBuilder(); builder.setRegion(HRegionInfo.convert(region)); if (versionOfOfflineNode >= 0) { builder.setVersionOfOfflineNode(versionOfOfflineNode); } if (favoredNodes != null) { for (ServerName server : favoredNodes) { builder.addFavoredNodes(ProtobufUtil.toServerName(server)); } } if(openForReplay != null) { builder.setOpenForDistributedLogReplay(openForReplay); } return builder.build(); }
/** * @param regionsInMeta * @return List of regions neither in transition nor assigned. * @throws IOException */ private static Map<HRegionInfo, ServerName> regionsToAssignWithServerName( final MasterProcedureEnv env, final List<Pair<HRegionInfo, ServerName>> regionsInMeta) throws IOException { Map<HRegionInfo, ServerName> regionsToAssign = new HashMap<HRegionInfo, ServerName>(regionsInMeta.size()); RegionStates regionStates = env.getMasterServices().getAssignmentManager().getRegionStates(); for (Pair<HRegionInfo, ServerName> regionLocation : regionsInMeta) { HRegionInfo hri = regionLocation.getFirst(); ServerName sn = regionLocation.getSecond(); if (regionStates.isRegionOffline(hri)) { regionsToAssign.put(hri, sn); } else { if (LOG.isDebugEnabled()) { LOG.debug("Skipping assign for the region " + hri + " during enable table " + hri.getTable() + " because its already in tranition or assigned."); } } } return regionsToAssign; }
private Triple<Map<HRegionInfo, ServerName>, FavoredNodeAssignmentHelper, List<HRegionInfo>> secondaryAndTertiaryRSPlacementHelper( int regionCount, Map<String, Integer> rackToServerCount) { Map<HRegionInfo, ServerName> primaryRSMap = new HashMap<HRegionInfo, ServerName>(); List<ServerName> servers = getServersFromRack(rackToServerCount); FavoredNodeAssignmentHelper helper = new FavoredNodeAssignmentHelper(servers, rackManager); Map<ServerName, List<HRegionInfo>> assignmentMap = new HashMap<ServerName, List<HRegionInfo>>(); helper.initialize(); // create regions List<HRegionInfo> regions = new ArrayList<HRegionInfo>(regionCount); for (int i = 0; i < regionCount; i++) { HRegionInfo region = new HRegionInfo(TableName.valueOf("foobar"), Bytes.toBytes(i), Bytes.toBytes(i + 1)); regions.add(region); } // place the regions helper.placePrimaryRSAsRoundRobin(assignmentMap, primaryRSMap, regions); return new Triple<Map<HRegionInfo, ServerName>, FavoredNodeAssignmentHelper, List<HRegionInfo>> (primaryRSMap, helper, regions); }
/** * If the input is a region name, it is returned as is. If it's an * encoded region name, the corresponding region is found from meta * and its region name is returned. If we can't find any region in * meta matching the input as either region name or encoded region * name, the input is returned as is. We don't throw unknown * region exception. */ private byte[] getRegionName( final byte[] regionNameOrEncodedRegionName) throws IOException { if (Bytes.equals(regionNameOrEncodedRegionName, HRegionInfo.FIRST_META_REGIONINFO.getRegionName()) || Bytes.equals(regionNameOrEncodedRegionName, HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes())) { return HRegionInfo.FIRST_META_REGIONINFO.getRegionName(); } byte[] tmp = regionNameOrEncodedRegionName; Pair<HRegionInfo, ServerName> regionServerPair = getRegion(regionNameOrEncodedRegionName); if (regionServerPair != null && regionServerPair.getFirst() != null) { tmp = regionServerPair.getFirst().getRegionName(); } return tmp; }
/** * Unassign the list of regions. Configuration knobs: * hbase.bulk.waitbetween.reopen indicates the number of milliseconds to * wait before unassigning another region from this region server * * @param regions * @throws InterruptedException */ private void unassign( List<HRegionInfo> regions) throws InterruptedException { int waitTime = this.server.getConfiguration().getInt( "hbase.bulk.waitbetween.reopen", 0); RegionStates regionStates = assignmentManager.getRegionStates(); for (HRegionInfo region : regions) { if (server.isStopped()) { return; } if (regionStates.isRegionInTransition(region)) { continue; } assignmentManager.unassign(region, false); while (regionStates.isRegionInTransition(region) && !server.isStopped()) { regionStates.waitForUpdate(100); } if (waitTime > 0 && !server.isStopped()) { Thread.sleep(waitTime); } } }
/** * Get the HRegionInfo from cache, if not there, from the hbase:meta table * @param regionName * @return HRegionInfo for the region */ @SuppressWarnings("deprecation") protected HRegionInfo getRegionInfo(final byte [] regionName) { String encodedName = HRegionInfo.encodeRegionName(regionName); RegionState regionState = getRegionState(encodedName); if (regionState != null) { return regionState.getRegion(); } try { Pair<HRegionInfo, ServerName> p = MetaTableAccessor.getRegion(server.getConnection(), regionName); HRegionInfo hri = p == null ? null : p.getFirst(); if (hri != null) { createRegionState(hri); } return hri; } catch (IOException e) { server.abort("Aborting because error occoured while reading " + Bytes.toStringBinary(regionName) + " from hbase:meta", e); return null; } }
/** * @param regionsInMeta * @return List of regions neither in transition nor assigned. * @throws IOException */ private Map<HRegionInfo, ServerName> regionsToAssignWithServerName( final List<Pair<HRegionInfo, ServerName>> regionsInMeta) throws IOException { Map<HRegionInfo, ServerName> regionsToAssign = new HashMap<HRegionInfo, ServerName>(regionsInMeta.size()); RegionStates regionStates = this.assignmentManager.getRegionStates(); for (Pair<HRegionInfo, ServerName> regionLocation : regionsInMeta) { HRegionInfo hri = regionLocation.getFirst(); ServerName sn = regionLocation.getSecond(); if (regionStates.isRegionOffline(hri)) { regionsToAssign.put(hri, sn); } else { if (LOG.isDebugEnabled()) { LOG.debug("Skipping assign for the region " + hri + " during enable table " + hri.getTable() + " because its already in tranition or assigned."); } } } return regionsToAssign; }
void start() throws IOException { if (!noPersistence) { if (server instanceof RegionServerServices) { metaRegion = ((RegionServerServices)server).getFromOnlineRegions( HRegionInfo.FIRST_META_REGIONINFO.getEncodedName()); } if (metaRegion == null) { Configuration conf = server.getConfiguration(); // Config to determine the no of HConnections to META. // A single HConnection should be sufficient in most cases. Only if // you are doing lot of writes (>1M) to META, // increasing this value might improve the write throughput. multiHConnection = new MultiHConnection(conf, conf.getInt("hbase.regionstatestore.meta.connection", 1)); } } initialized = true; }
@Override public void deserializeStateData(final InputStream stream) throws IOException { super.deserializeStateData(stream); MasterProcedureProtos.TruncateTableStateData state = MasterProcedureProtos.TruncateTableStateData.parseDelimitedFrom(stream); user = MasterProcedureUtil.toUserInfo(state.getUserInfo()); if (state.hasTableSchema()) { hTableDescriptor = HTableDescriptor.convert(state.getTableSchema()); tableName = hTableDescriptor.getTableName(); } else { tableName = ProtobufUtil.toTableName(state.getTableName()); } preserveSplits = state.getPreserveSplits(); if (state.getRegionInfoCount() == 0) { regions = null; } else { regions = new ArrayList<HRegionInfo>(state.getRegionInfoCount()); for (HBaseProtos.RegionInfo hri: state.getRegionInfoList()) { regions.add(HRegionInfo.convert(hri)); } } }
@Test(timeout=60000) public void testCreateTwiceWithSameNonce() throws Exception { final TableName tableName = TableName.valueOf("testCreateTwiceWithSameNonce"); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final HTableDescriptor htd = MasterProcedureTestingUtility.createHTD(tableName, "f"); final HRegionInfo[] regions = ModifyRegionUtils.createHRegionInfos(htd, null); // create the table long procId1 = procExec.submitProcedure( new CreateTableProcedure(procExec.getEnvironment(), htd, regions), nonceGroup, nonce); // create another with the same name long procId2 = procExec.submitProcedure( new CreateTableProcedure(procExec.getEnvironment(), htd, regions), nonceGroup, nonce); ProcedureTestingUtility.waitProcedure(procExec, procId1); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId1)); ProcedureTestingUtility.waitProcedure(procExec, procId2); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId2)); assertTrue(procId1 == procId2); }
/** * If merged region no longer holds reference to the merge regions, archive * merge region on hdfs and perform deleting references in hbase:meta * @param mergedRegion * @param regionA * @param regionB * @return true if we delete references in merged region on hbase:meta and archive * the files on the file system * @throws IOException */ boolean cleanMergeRegion(final HRegionInfo mergedRegion, final HRegionInfo regionA, final HRegionInfo regionB) throws IOException { FileSystem fs = this.services.getMasterFileSystem().getFileSystem(); Path rootdir = this.services.getMasterFileSystem().getRootDir(); Path tabledir = FSUtils.getTableDir(rootdir, mergedRegion.getTable()); HTableDescriptor htd = getTableDescriptor(mergedRegion.getTable()); HRegionFileSystem regionFs = null; try { regionFs = HRegionFileSystem.openRegionFromFileSystem( this.services.getConfiguration(), fs, tabledir, mergedRegion, true); } catch (IOException e) { LOG.warn("Merged region does not exist: " + mergedRegion.getEncodedName()); } if (regionFs == null || !regionFs.hasReferences(htd)) { LOG.debug("Deleting region " + regionA.getRegionNameAsString() + " and " + regionB.getRegionNameAsString() + " from fs because merged region no longer holds references"); HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, regionA); HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, regionB); MetaTableAccessor.deleteMergeQualifiers(server.getConnection(), mergedRegion); return true; } return false; }
public OpenedRegionHandler(Server server, AssignmentManager assignmentManager, HRegionInfo regionInfo, OpenRegionCoordination coordination, OpenRegionCoordination.OpenRegionDetails ord) { super(server, EventType.RS_ZK_REGION_OPENED); this.assignmentManager = assignmentManager; this.regionInfo = regionInfo; this.coordination = coordination; this.ord = ord; if(regionInfo.isMetaRegion()) { priority = OpenedPriority.META; } else if(regionInfo.getTable() .getNamespaceAsString().equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) { priority = OpenedPriority.SYSTEM; } else { priority = OpenedPriority.USER; } }
@Override public WAL getWAL(HRegionInfo regionInfo) throws IOException { WAL wal; LogRoller roller = walRoller; //_ROOT_ and hbase:meta regions have separate WAL. if (regionInfo != null && regionInfo.isMetaTable() && regionInfo.getReplicaId() == HRegionInfo.DEFAULT_REPLICA_ID) { roller = ensureMetaWALRoller(); wal = walFactory.getMetaWAL(regionInfo.getEncodedNameAsBytes()); } else if (regionInfo == null) { wal = walFactory.getWAL(UNSPECIFIED_REGION); } else { wal = walFactory.getWAL(regionInfo.getEncodedNameAsBytes()); } roller.addWAL(wal); return wal; }
private Result getMetaRow() throws IOException { Result currentRow = metaScanner.next(); boolean foundResult = false; while (currentRow != null) { LOG.info("Row: <" + Bytes.toStringBinary(currentRow.getRow()) + ">"); byte[] regionInfoValue = currentRow.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); if (regionInfoValue == null || regionInfoValue.length == 0) { currentRow = metaScanner.next(); continue; } HRegionInfo region = HRegionInfo.getHRegionInfo(currentRow); if (!region.getTable().equals(this.tableName)) { currentRow = metaScanner.next(); continue; } foundResult = true; break; } return foundResult ? currentRow : null; }
@Override public void deserializeStateData(final InputStream stream) throws IOException { super.deserializeStateData(stream); MasterProcedureProtos.CreateTableStateData state = MasterProcedureProtos.CreateTableStateData.parseDelimitedFrom(stream); user = MasterProcedureUtil.toUserInfo(state.getUserInfo()); hTableDescriptor = HTableDescriptor.convert(state.getTableSchema()); if (state.getRegionInfoCount() == 0) { newRegions = null; } else { newRegions = new ArrayList<HRegionInfo>(state.getRegionInfoCount()); for (HBaseProtos.RegionInfo hri: state.getRegionInfoList()) { newRegions.add(HRegionInfo.convert(hri)); } } }
@Test public void testSystemTableWALEntryFilter() { SystemTableWALEntryFilter filter = new SystemTableWALEntryFilter(); // meta WALKey key1 = new WALKey( HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), TableName.META_TABLE_NAME); Entry metaEntry = new Entry(key1, null); assertNull(filter.filter(metaEntry)); // ns table WALKey key2 = new WALKey(new byte[] {}, TableName.NAMESPACE_TABLE_NAME); Entry nsEntry = new Entry(key2, null); assertNull(filter.filter(nsEntry)); // user table WALKey key3 = new WALKey(new byte[] {}, TableName.valueOf("foo")); Entry userEntry = new Entry(key3, null); assertEquals(userEntry, filter.filter(userEntry)); }
@Override public int compare(HRegionInfo left, HRegionInfo right) { // This comparator differs from the one HRegionInfo in that it sorts // parent before daughters. if (left == null) return -1; if (right == null) return 1; // Same table name. int result = left.getTable().compareTo(right.getTable()); if (result != 0) return result; // Compare start keys. result = Bytes.compareTo(left.getStartKey(), right.getStartKey()); if (result != 0) return result; // Compare end keys, but flip the operands so parent comes first result = rowEndKeyComparator.compare(right.getEndKey(), left.getEndKey()); return result; }
@Before public void setUp() throws IOException { // parameterized tests add [#] suffix get rid of [ and ]. table = Bytes.toBytes(name.getMethodName().replaceAll("[\\[\\]]", "_")); conf = TEST_UTIL.getConfiguration(); conf.setInt(HFile.FORMAT_VERSION_KEY, HFile.MAX_FORMAT_VERSION); conf.setBoolean(CacheConfig.CACHE_BLOCKS_ON_WRITE_KEY, false); conf.setBoolean(CacheConfig.CACHE_INDEX_BLOCKS_ON_WRITE_KEY, false); conf.setBoolean(CacheConfig.CACHE_BLOOM_BLOCKS_ON_WRITE_KEY, false); fs = HFileSystem.get(conf); // Create the schema HColumnDescriptor hcd = new HColumnDescriptor(family); hcd.setBloomFilterType(BloomType.ROWCOL); cowType.modifyFamilySchema(hcd); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(table)); htd.addFamily(hcd); // Create a store based on the schema final String id = TestCacheOnWriteInSchema.class.getName(); final Path logdir = new Path(FSUtils.getRootDir(conf), DefaultWALProvider.getWALDirectoryName(id)); fs.delete(logdir, true); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); walFactory = new WALFactory(conf, null, id); region = TEST_UTIL.createLocalHRegion(info, htd, walFactory.getWAL(info.getEncodedNameAsBytes())); store = new HStore(region, hcd, conf); }
public CreateTableHandler(Server server, MasterFileSystem fileSystemManager, HTableDescriptor hTableDescriptor, Configuration conf, HRegionInfo [] newRegions, MasterServices masterServices) { super(server, EventType.C_M_CREATE_TABLE); this.fileSystemManager = fileSystemManager; this.hTableDescriptor = hTableDescriptor; this.conf = conf; this.newRegions = newRegions; this.assignmentManager = masterServices.getAssignmentManager(); this.tableLockManager = masterServices.getTableLockManager(); this.tableLock = this.tableLockManager.writeLock(this.hTableDescriptor.getTableName() , EventType.C_M_CREATE_TABLE.toString()); }
@Test public void testHBaseGroupScanAssignmentNoAfinity() throws Exception { NavigableMap<HRegionInfo,ServerName> regionsToScan = Maps.newTreeMap(); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[0], splits[1]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[1], splits[2]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[2], splits[3]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[3], splits[4]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[4], splits[5]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[5], splits[6]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[6], splits[7]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[7], splits[0]), SERVER_X); final List<DrillbitEndpoint> endpoints = Lists.newArrayList(); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_A).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_B).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_C).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_D).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_E).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_F).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_G).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_H).setControlPort(1234).build()); HBaseGroupScan scan = new HBaseGroupScan(); scan.setRegionsToScan(regionsToScan); scan.setHBaseScanSpec(new HBaseScanSpec(TABLE_NAME_STR, splits[0], splits[0], null)); scan.applyAssignments(endpoints); int i = 0; assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'A' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'B' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'C' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'D' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'E' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'F' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'G' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'H' testParallelizationWidth(scan, i); }
private void assertAllOnLine(final HTable t) throws IOException { NavigableMap<HRegionInfo, ServerName> regions = t.getRegionLocations(); for (Map.Entry<HRegionInfo, ServerName> e: regions.entrySet()) { byte [] startkey = e.getKey().getStartKey(); Scan s = new Scan(startkey); ResultScanner scanner = t.getScanner(s); Result r = scanner.next(); org.junit.Assert.assertTrue(r != null && r.size() > 0); scanner.close(); } }
public void preCreateTable(final HTableDescriptor htd, final HRegionInfo[] regions) throws IOException { execOperation(coprocessors.isEmpty() ? null : new CoprocessorOperation() { @Override public void call(MasterObserver oserver, ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { oserver.preCreateTable(ctx, htd, regions); } }); }
public void offlineDisabledRegion(HRegionInfo regionInfo) { if (useZKForAssignment) { // Disabling so should not be reassigned, just delete the CLOSED node LOG.debug("Table being disabled so deleting ZK node and removing from " + "regions in transition, skipping assignment of region " + regionInfo.getRegionNameAsString()); String encodedName = regionInfo.getEncodedName(); deleteNodeInStates(encodedName, "closed", null, EventType.RS_ZK_REGION_CLOSED, EventType.M_ZK_REGION_OFFLINE); } replicasToClose.remove(regionInfo); regionOffline(regionInfo); }
@Override public void postWALWrite(ObserverContext<? extends WALCoprocessorEnvironment> ctx, HRegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException { // only keep primary region's edits if (logKey.getTablename().equals(tableName) && info.getReplicaId() == 0) { entries.add(new Entry(logKey, logEdit)); } }
/** * Before each test, use a different HRI, so the different tests * don't interfere with each other. This allows us to use just * a single ZK cluster for the whole suite. */ @Before public void setupHRI() { TEST_HRI = new HRegionInfo(TEST_HTD.getTableName(), Bytes.toBytes(testIndex), Bytes.toBytes(testIndex + 1)); testIndex++; }
private synchronized HRegion openMetaRegion() throws IOException { if (this.metaRegion != null) { return this.metaRegion; } this.metaRegion = HRegion.openHRegion(HRegionInfo.FIRST_META_REGIONINFO, descriptors.get(TableName.META_TABLE_NAME), getLog(HRegionInfo.FIRST_META_REGIONINFO), this.conf); this.metaRegion.compactStores(); return this.metaRegion; }
@Override public boolean reportRegionStateTransition(TransitionCode code, long openSeqNum, HRegionInfo... hris) { if (simulateRetry) { // Simulate retry by calling the method twice super.reportRegionStateTransition(code, openSeqNum, hris); return super.reportRegionStateTransition(code, openSeqNum, hris); } return super.reportRegionStateTransition(code, openSeqNum, hris); }
private PairOfSameType<HRegionInfo> requestMergeRegion( HMaster master, TableName tablename, int regionAnum, int regionBnum) throws Exception { List<Pair<HRegionInfo, ServerName>> tableRegions = MetaTableAccessor .getTableRegionsAndLocations(master.getZooKeeper(), master.getConnection(), tablename); HRegionInfo regionA = tableRegions.get(regionAnum).getFirst(); HRegionInfo regionB = tableRegions.get(regionBnum).getFirst(); TEST_UTIL.getHBaseAdmin().mergeRegions( regionA.getEncodedNameAsBytes(), regionB.getEncodedNameAsBytes(), false); return new PairOfSameType<HRegionInfo>(regionA, regionB); }
public static HRegionInfo[] createTable(final ProcedureExecutor<MasterProcedureEnv> procExec, final TableName tableName, final byte[][] splitKeys, String... family) throws IOException { HTableDescriptor htd = createHTD(tableName, family); HRegionInfo[] regions = ModifyRegionUtils.createHRegionInfos(htd, splitKeys); long procId = ProcedureTestingUtility.submitAndWait(procExec, new CreateTableProcedure(procExec.getEnvironment(), htd, regions)); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId)); return regions; }
@Override public Map<ServerName, List<HRegionInfo>> roundRobinAssignment( List<HRegionInfo> regions, List<ServerName> servers) { if (countRegionServers != null && services != null) { int regionServers = services.getServerManager().countOfRegionServers(); if (regionServers < countRegionServers.intValue()) { // Let's wait till more region servers join in. // Before that, fail region assignments. counter.incrementAndGet(); return null; } } return super.roundRobinAssignment(regions, servers); }
public void deleteMetaLocation(ZooKeeperWatcher zookeeper, int replicaId) throws KeeperException { if (replicaId == HRegionInfo.DEFAULT_REPLICA_ID) { LOG.info("Deleting hbase:meta region location in ZooKeeper"); } else { LOG.info("Deleting hbase:meta for " + replicaId + " region location in ZooKeeper"); } try { // Just delete the node. Don't need any watches. ZKUtil.deleteNode(zookeeper, zookeeper.getZNodeForReplica(replicaId)); } catch(KeeperException.NoNodeException nne) { // Has already been deleted } }
private long getRegionSize(HRegionInfo hri) { ServerName sn = masterServices.getAssignmentManager().getRegionStates(). getRegionServerOfRegion(hri); RegionLoad regionLoad = masterServices.getServerManager().getLoad(sn). getRegionsLoad().get(hri.getRegionName()); return regionLoad.getStorefileSizeMB(); }
@Test(timeout=60000) public void testAbortProcedureInterruptedNotAllowed() throws Exception { final TableName tableName = TableName.valueOf("testAbortProcedureInterruptedNotAllowed"); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); HRegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f"); ProcedureTestingUtility.waitNoProcedureRunning(procExec); ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true); // Submit a procedure long procId = procExec.submitProcedure( new DisableTableProcedure(procExec.getEnvironment(), tableName, true), nonceGroup, nonce); // Wait for one step to complete ProcedureTestingUtility.waitProcedure(procExec, procId); // Set the mayInterruptIfRunning flag to false boolean abortResult = procExec.abort(procId, false); assertFalse(abortResult); ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); ProcedureTestingUtility.restart(procExec); ProcedureTestingUtility.waitNoProcedureRunning(procExec); ProcedureTestingUtility.assertProcNotFailed(procExec, procId); // Validate the delete table procedure was not aborted MasterProcedureTestingUtility.validateTableIsDisabled( UTIL.getHBaseCluster().getMaster(), tableName); }
@Override public void preMove(ObserverContext<MasterCoprocessorEnvironment> env, HRegionInfo region, ServerName srcServer, ServerName destServer) throws IOException { if (bypass) { env.bypass(); } preMoveCalled = true; }
/** * A helper to warmup a region given a region name * using admin protocol * * @param admin * @param regionInfo * */ public static void warmupRegion(final RpcController controller, final AdminService.BlockingInterface admin, final HRegionInfo regionInfo) throws IOException { try { WarmupRegionRequest warmupRegionRequest = RequestConverter.buildWarmupRegionRequest(regionInfo); admin.warmupRegion(controller, warmupRegionRequest); } catch (ServiceException e) { throw getRemoteException(e); } }
/** * * @param zkw zk reference * @param region region to be closed * @param expectedVersion expected version of the znode * @return true if the znode exists, has the right version and the right state. False otherwise. * @throws KeeperException */ public static boolean checkClosingState(ZooKeeperWatcher zkw, HRegionInfo region, int expectedVersion) throws KeeperException { final String encoded = getNodeName(zkw, region.getEncodedName()); zkw.sync(encoded); // Read existing data of the node Stat stat = new Stat(); byte[] existingBytes = ZKUtil.getDataNoWatch(zkw, encoded, stat); if (existingBytes == null) { LOG.warn(zkw.prefix("Attempt to check the " + "closing node for " + encoded + ". The node does not exist")); return false; } if (expectedVersion != -1 && stat.getVersion() != expectedVersion) { LOG.warn(zkw.prefix("Attempt to check the " + "closing node for " + encoded + ". The node existed but was version " + stat.getVersion() + " not the expected version " + expectedVersion)); return false; } RegionTransition rt = getRegionTransition(existingBytes); if (!EventType.M_ZK_REGION_CLOSING.equals(rt.getEventType())) { LOG.warn(zkw.prefix("Attempt to check the " + "closing node for " + encoded + ". The node existed but was in an unexpected state: " + rt.getEventType())); return false; } return true; }
public void prepareMutationsForMerge(HRegionInfo mergedRegion, HRegionInfo regionA, HRegionInfo regionB, ServerName serverName, List<Mutation> mutations, int regionReplication) throws IOException { HRegionInfo copyOfMerged = new HRegionInfo(mergedRegion); // use the maximum of what master passed us vs local time. long time = Math.max(EnvironmentEdgeManager.currentTime(), masterSystemTime); // Put for parent Put putOfMerged = MetaTableAccessor.makePutFromRegionInfo(copyOfMerged, time); putOfMerged.add(HConstants.CATALOG_FAMILY, HConstants.MERGEA_QUALIFIER, regionA.toByteArray()); putOfMerged.add(HConstants.CATALOG_FAMILY, HConstants.MERGEB_QUALIFIER, regionB.toByteArray()); mutations.add(putOfMerged); // Deletes for merging regions Delete deleteA = MetaTableAccessor.makeDeleteFromRegionInfo(regionA, time); Delete deleteB = MetaTableAccessor.makeDeleteFromRegionInfo(regionB, time); mutations.add(deleteA); mutations.add(deleteB); // Add empty locations for region replicas of the merged region so that number of replicas // can be cached whenever the primary region is looked up from meta for (int i = 1; i < regionReplication; i++) { addEmptyLocation(putOfMerged, i); } // The merged is a new region, openSeqNum = 1 is fine. addLocation(putOfMerged, serverName, 1); }
/** * This tests region assignment */ @Test (timeout=60000) public void testAssignRegion() throws Exception { String table = "testAssignRegion"; try { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(table)); desc.addFamily(new HColumnDescriptor(FAMILY)); admin.createTable(desc); Table meta = new HTable(conf, TableName.META_TABLE_NAME); HRegionInfo hri = new HRegionInfo( desc.getTableName(), Bytes.toBytes("A"), Bytes.toBytes("Z")); MetaTableAccessor.addRegionToMeta(meta, hri); HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); master.assignRegion(hri); AssignmentManager am = master.getAssignmentManager(); am.waitForAssignment(hri); RegionStates regionStates = am.getRegionStates(); ServerName serverName = regionStates.getRegionServerOfRegion(hri); TEST_UTIL.assertRegionOnServer(hri, serverName, 6000); // Region is assigned now. Let's assign it again. // Master should not abort, and region should be assigned. RegionState oldState = regionStates.getRegionState(hri); TEST_UTIL.getHBaseAdmin().assign(hri.getRegionName()); master.getAssignmentManager().waitForAssignment(hri); RegionState newState = regionStates.getRegionState(hri); assertTrue(newState.isOpened() && newState.getStamp() != oldState.getStamp()); } finally { TEST_UTIL.deleteTable(Bytes.toBytes(table)); } }
public static void verifyReplicasCameOnline(TableName tableName, Admin admin, int regionReplication) throws IOException { List<HRegionInfo> regions = admin.getTableRegions(tableName); HashSet<HRegionInfo> set = new HashSet<HRegionInfo>(); for (HRegionInfo hri : regions) { set.add(RegionReplicaUtil.getRegionInfoForDefaultReplica(hri)); for (int i = 0; i < regionReplication; i++) { HRegionInfo replica = RegionReplicaUtil.getRegionInfoForReplica(hri, i); if (!regions.contains(replica)) { Assert.fail(replica + " is not contained in the list of online regions"); } } } assert(set.size() == getSplitKeys().length + 1); }
@Test public void testQosFunctionForMeta() throws IOException { priority = regionServer.rpcServices.getPriority(); RequestHeader.Builder headerBuilder = RequestHeader.newBuilder(); //create a rpc request that has references to hbase:meta region and also //uses one of the known argument classes (known argument classes are //listed in HRegionServer.QosFunctionImpl.knownArgumentClasses) headerBuilder.setMethodName("foo"); GetRequest.Builder getRequestBuilder = GetRequest.newBuilder(); RegionSpecifier.Builder regionSpecifierBuilder = RegionSpecifier.newBuilder(); regionSpecifierBuilder.setType(RegionSpecifierType.REGION_NAME); ByteString name = ByteStringer.wrap(HRegionInfo.FIRST_META_REGIONINFO.getRegionName()); regionSpecifierBuilder.setValue(name); RegionSpecifier regionSpecifier = regionSpecifierBuilder.build(); getRequestBuilder.setRegion(regionSpecifier); Get.Builder getBuilder = Get.newBuilder(); getBuilder.setRow(ByteStringer.wrap("somerow".getBytes())); getRequestBuilder.setGet(getBuilder.build()); GetRequest getRequest = getRequestBuilder.build(); RequestHeader header = headerBuilder.build(); HRegion mockRegion = Mockito.mock(HRegion.class); HRegionServer mockRS = Mockito.mock(HRegionServer.class); RSRpcServices mockRpc = Mockito.mock(RSRpcServices.class); Mockito.when(mockRS.getRSRpcServices()).thenReturn(mockRpc); HRegionInfo mockRegionInfo = Mockito.mock(HRegionInfo.class); Mockito.when(mockRpc.getRegion((RegionSpecifier) Mockito.any())).thenReturn(mockRegion); Mockito.when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo); Mockito.when(mockRegionInfo.isSystemTable()).thenReturn(true); // Presume type. ((AnnotationReadingPriorityFunction)priority).setRegionServer(mockRS); assertEquals(HConstants.SYSTEMTABLE_QOS, priority.getPriority(header, getRequest, User.createUserForTesting(regionServer.conf, "someuser", new String[]{"somegroup"}))); }