Java Code Examples for org.apache.hadoop.hbase.client.RegionInfo#getEncodedNameAsBytes()
The following examples show how to use
org.apache.hadoop.hbase.client.RegionInfo#getEncodedNameAsBytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegionGroupingProvider.java From hbase with Apache License 2.0 | 6 votes |
@Override public WAL getWAL(RegionInfo region) throws IOException { String group; if (META_WAL_PROVIDER_ID.equals(this.providerId)) { group = META_WAL_GROUP_NAME; } else { byte[] id; byte[] namespace; if (region != null) { id = region.getEncodedNameAsBytes(); namespace = region.getTable().getNamespace(); } else { id = HConstants.EMPTY_BYTE_ARRAY; namespace = null; } group = strategy.group(id, namespace); } return getWAL(group); }
Example 2
Source File: WALUtil.java From hbase with Apache License 2.0 | 6 votes |
/** * A 'full' WAL transaction involves starting an mvcc transaction followed by an append, an * optional sync, and then a call to complete the mvcc transaction. This method does it all. Good * for case of adding a single edit or marker to the WAL. * <p/> * This write is for internal use only. Not for external client consumption. * @return WALKeyImpl that was added to the WAL. */ private static WALKeyImpl doFullMarkerAppendTransaction(final WAL wal, final NavigableMap<byte[], Integer> replicationScope, final RegionInfo hri, final WALEdit edit, final MultiVersionConcurrencyControl mvcc, final Map<String, byte[]> extendedAttributes, final boolean sync) throws IOException { // TODO: Pass in current time to use? WALKeyImpl walKey = new WALKeyImpl(hri.getEncodedNameAsBytes(), hri.getTable(), System.currentTimeMillis(), mvcc, replicationScope, extendedAttributes); long trx = MultiVersionConcurrencyControl.NONE; try { trx = wal.appendMarker(hri, walKey, edit); if (sync) { wal.sync(trx); } // Call complete only here because these are markers only. They are not for clients to read. mvcc.complete(walKey.getWriteEntry()); } catch (IOException ioe) { if (walKey.getWriteEntry() != null) { mvcc.complete(walKey.getWriteEntry()); } throw ioe; } return walKey; }
Example 3
Source File: TestWALSplit.java From hbase with Apache License 2.0 | 6 votes |
private static void appendCompactionEvent(Writer w, RegionInfo hri, String[] inputs, String output) throws IOException { WALProtos.CompactionDescriptor.Builder desc = WALProtos.CompactionDescriptor.newBuilder(); desc.setTableName(ByteString.copyFrom(hri.getTable().toBytes())) .setEncodedRegionName(ByteString.copyFrom(hri.getEncodedNameAsBytes())) .setRegionName(ByteString.copyFrom(hri.getRegionName())) .setFamilyName(ByteString.copyFrom(FAMILY)) .setStoreHomeDir(hri.getEncodedName() + "/" + Bytes.toString(FAMILY)) .addAllCompactionInput(Arrays.asList(inputs)) .addCompactionOutput(output); WALEdit edit = WALEdit.createCompaction(hri, desc.build()); WALKeyImpl key = new WALKeyImpl(hri.getEncodedNameAsBytes(), TABLE_NAME, 1, EnvironmentEdgeManager.currentTime(), HConstants.DEFAULT_CLUSTER_ID); w.append(new Entry(key, edit)); w.sync(false); }
Example 4
Source File: RSRpcServices.java From hbase with Apache License 2.0 | 5 votes |
/** * Wamrmup a region on this server. * * This method should only be called by Master. It synchrnously opens the region and * closes the region bringing the most important pages in cache. * <p> * * @param controller the RPC controller * @param request the request * @throws ServiceException */ @Override public WarmupRegionResponse warmupRegion(final RpcController controller, final WarmupRegionRequest request) throws ServiceException { final RegionInfo region = ProtobufUtil.toRegionInfo(request.getRegionInfo()); TableDescriptor htd; WarmupRegionResponse response = WarmupRegionResponse.getDefaultInstance(); try { checkOpen(); String encodedName = region.getEncodedName(); byte[] encodedNameBytes = region.getEncodedNameAsBytes(); final HRegion onlineRegion = regionServer.getRegion(encodedName); if (onlineRegion != null) { LOG.info("Region already online. Skipping warming up " + region); return response; } htd = regionServer.tableDescriptors.get(region.getTable()); if (regionServer.getRegionsInTransitionInRS().containsKey(encodedNameBytes)) { LOG.info("Region is in transition. Skipping warmup " + region); return response; } LOG.info("Warming up region " + region.getRegionNameAsString()); HRegion.warmupHRegion(region, htd, regionServer.getWAL(region), regionServer.getConfiguration(), regionServer, null); } catch (IOException ie) { LOG.error("Failed warming up region " + region.getRegionNameAsString(), ie); throw new ServiceException(ie); } return response; }
Example 5
Source File: ProtobufLogTestHelper.java From hbase with Apache License 2.0 | 5 votes |
private static WAL.Entry generateEdit(int i, RegionInfo hri, TableName tableName, byte[] row, int columnCount, long timestamp, MultiVersionConcurrencyControl mvcc) { WALKeyImpl key = new WALKeyImpl(hri.getEncodedNameAsBytes(), tableName, i, timestamp, HConstants.DEFAULT_CLUSTER_ID, mvcc); WALEdit edit = new WALEdit(); int prefix = i; IntStream.range(0, columnCount).mapToObj(j -> toValue(prefix, j)) .map(value -> new KeyValue(row, row, row, timestamp, value)).forEachOrdered(edit::add); return new WAL.Entry(key, edit); }
Example 6
Source File: AbstractTestFSWAL.java From hbase with Apache License 2.0 | 5 votes |
protected void addEdits(WAL log, RegionInfo hri, TableDescriptor htd, int times, MultiVersionConcurrencyControl mvcc, NavigableMap<byte[], Integer> scopes, String cf) throws IOException { final byte[] row = Bytes.toBytes(cf); for (int i = 0; i < times; i++) { long timestamp = System.currentTimeMillis(); WALEdit cols = new WALEdit(); cols.add(new KeyValue(row, row, row, timestamp, row)); WALKeyImpl key = new WALKeyImpl(hri.getEncodedNameAsBytes(), htd.getTableName(), SequenceId.NO_SEQUENCE_ID, timestamp, WALKey.EMPTY_UUIDS, HConstants.NO_NONCE, HConstants.NO_NONCE, mvcc, scopes); log.appendData(hri, key, cols); } log.sync(); }
Example 7
Source File: AbstractTestFSWAL.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testWriteEntryCanBeNull() throws IOException { String testName = currentTest.getMethodName(); AbstractFSWAL<?> wal = newWAL(FS, CommonFSUtils.getWALRootDir(CONF), DIR.toString(), testName, CONF, null, true, null, null); wal.close(); TableDescriptor td = TableDescriptorBuilder.newBuilder(TableName.valueOf("table")) .setColumnFamily(ColumnFamilyDescriptorBuilder.of("row")).build(); RegionInfo ri = RegionInfoBuilder.newBuilder(td.getTableName()).build(); MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl(); NavigableMap<byte[], Integer> scopes = new TreeMap<>(Bytes.BYTES_COMPARATOR); for (byte[] fam : td.getColumnFamilyNames()) { scopes.put(fam, 0); } long timestamp = System.currentTimeMillis(); byte[] row = Bytes.toBytes("row"); WALEdit cols = new WALEdit(); cols.add(new KeyValue(row, row, row, timestamp, row)); WALKeyImpl key = new WALKeyImpl(ri.getEncodedNameAsBytes(), td.getTableName(), SequenceId.NO_SEQUENCE_ID, timestamp, WALKey.EMPTY_UUIDS, HConstants.NO_NONCE, HConstants.NO_NONCE, mvcc, scopes); try { wal.append(ri, key, cols, true); fail("Should fail since the wal has already been closed"); } catch (IOException e) { // expected assertThat(e.getMessage(), containsString("log is closed")); // the WriteEntry should be null since we fail before setting it. assertNull(key.getWriteEntry()); } }
Example 8
Source File: ServerManager.java From hbase with Apache License 2.0 | 4 votes |
/** * Called by delete table and similar to notify the ServerManager that a region was removed. */ public void removeRegion(final RegionInfo regionInfo) { final byte[] encodedName = regionInfo.getEncodedNameAsBytes(); storeFlushedSequenceIdsByRegion.remove(encodedName); flushedSequenceIdByRegion.remove(encodedName); }
Example 9
Source File: ServerManager.java From hbase with Apache License 2.0 | 4 votes |
@VisibleForTesting public boolean isRegionInServerManagerStates(final RegionInfo hri) { final byte[] encodedName = hri.getEncodedNameAsBytes(); return (storeFlushedSequenceIdsByRegion.containsKey(encodedName) || flushedSequenceIdByRegion.containsKey(encodedName)); }
Example 10
Source File: OpenRegionHandler.java From hbase with Apache License 2.0 | 4 votes |
private static boolean isRegionStillOpening( RegionInfo regionInfo, RegionServerServices rsServices) { byte[] encodedName = regionInfo.getEncodedNameAsBytes(); Boolean action = rsServices.getRegionsInTransitionInRS().get(encodedName); return Boolean.TRUE.equals(action); // true means opening for RIT }
Example 11
Source File: TestWALRootDir.java From hbase with Apache License 2.0 | 4 votes |
private WALKeyImpl getWalKey(final long time, RegionInfo hri, final long startPoint) { return new WALKeyImpl(hri.getEncodedNameAsBytes(), tableName, time, new MultiVersionConcurrencyControl(startPoint)); }
Example 12
Source File: AbstractTestWALReplay.java From hbase with Apache License 2.0 | 4 votes |
private WALKeyImpl createWALKey(final TableName tableName, final RegionInfo hri, final MultiVersionConcurrencyControl mvcc, NavigableMap<byte[], Integer> scopes) { return new WALKeyImpl(hri.getEncodedNameAsBytes(), tableName, 999, mvcc, scopes); }
Example 13
Source File: PhoenixServerRpcIT.java From phoenix with Apache License 2.0 | 4 votes |
/** * Verifies that the given tables each have a single region and are on * different region servers. If they are on the same server moves tableName2 * to the other region server. */ private void ensureTablesOnDifferentRegionServers(String tableName1, String tableName2) throws Exception { byte[] table1 = Bytes.toBytes(tableName1); byte[] table2 = Bytes.toBytes(tableName2); Admin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin(); HBaseTestingUtility util = getUtility(); MiniHBaseCluster cluster = util.getHBaseCluster(); HMaster master = cluster.getMaster(); AssignmentManager am = master.getAssignmentManager(); // verify there is only a single region for data table List<RegionInfo> tableRegions = admin.getRegions(TableName.valueOf(table1)); assertEquals("Expected single region for " + table1, tableRegions.size(), 1); RegionInfo hri1 = tableRegions.get(0); // verify there is only a single region for index table tableRegions = admin.getRegions(TableName.valueOf(table2)); RegionInfo hri2 = tableRegions.get(0); assertEquals("Expected single region for " + table2, tableRegions.size(), 1); ServerName serverName1 = am.getRegionStates().getRegionServerOfRegion(hri1); ServerName serverName2 = am.getRegionStates().getRegionServerOfRegion(hri2); // if data table and index table are on same region server, move the index table to the other region server if (serverName1.equals(serverName2)) { HRegionServer server1 = util.getHBaseCluster().getRegionServer(0); HRegionServer server2 = util.getHBaseCluster().getRegionServer(1); HRegionServer dstServer = null; HRegionServer srcServer = null; if (server1.getServerName().equals(serverName2)) { dstServer = server2; srcServer = server1; } else { dstServer = server1; srcServer = server2; } byte[] encodedRegionNameInBytes = hri2.getEncodedNameAsBytes(); admin.move(encodedRegionNameInBytes, Bytes.toBytes(dstServer.getServerName().getServerName())); while (dstServer.getOnlineRegion(hri2.getRegionName()) == null || dstServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || srcServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || master.getAssignmentManager().getRegionStates().isRegionInTransition(hri2)) { // wait for the move to be finished Thread.sleep(1); } } hri1 = admin.getRegions(TableName.valueOf(table1)).get(0); serverName1 = am.getRegionStates().getRegionServerOfRegion(hri1); hri2 = admin.getRegions(TableName.valueOf(table2)).get(0); serverName2 = am.getRegionStates().getRegionServerOfRegion(hri2); // verify index and data tables are on different servers assertNotEquals("Tables " + tableName1 + " and " + tableName2 + " should be on different region servers", serverName1, serverName2); }