/** * @return the region name */ @XmlAttribute public String getName() { byte [] tableNameAsBytes = Bytes.toBytes(this.table); TableName tableName = TableName.valueOf(tableNameAsBytes); byte [] nameAsBytes = HRegionInfo.createRegionName( tableName, this.startKey, this.id, !tableName.isSystemTable()); return Bytes.toString(nameAsBytes); }
public HRegionInfo(long regionId, TableName tableName, int replicaId) { super(); this.regionId = regionId; this.tableName = tableName; this.replicaId = replicaId; // Note: First Meta region replicas names are in old format this.regionName = createRegionName(tableName, null, regionId, replicaId, false); setHashCode(); }
this.regionName = createRegionName(this.tableName, startKey, regionId, replicaId, true);
@Test public void testRegionNameForRegionReplicas() throws Exception { String tableName = name.getMethodName(); final TableName tn = TableName.valueOf(tableName); String startKey = "startkey"; final byte[] sk = Bytes.toBytes(startKey); String id = "id"; // assert with only the region name without encoding // primary, replicaId = 0 byte [] name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0, false); String nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id, nameStr); // replicaId = 1 name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 1, false); nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id + "_" + String.format(HRegionInfo.REPLICA_ID_FORMAT, 1), nameStr); // replicaId = max name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0xFFFF, false); nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id + "_" + String.format(HRegionInfo.REPLICA_ID_FORMAT, 0xFFFF), nameStr); }
private byte [] findRow(final Region mr, final char table, final int rowToFind, final int answer) throws IOException { TableName tableb = TableName.valueOf("" + table); // Find the row. byte [] tofindBytes = Bytes.toBytes((short)rowToFind); byte [] metaKey = HRegionInfo.createRegionName( tableb, tofindBytes, HConstants.NINES, false); LOG.info("find=" + new String(metaKey, StandardCharsets.UTF_8)); Result r = UTIL.getClosestRowBefore(mr, metaKey, HConstants.CATALOG_FAMILY); if (answer == -1) { assertNull(r); return null; } assertTrue(Bytes.compareTo(Bytes.toBytes((short)answer), extractRowFromMetaRow(r.getRow())) == 0); return r.getRow(); }
@Test public void testCreateHRegionInfoName() throws Exception { final String tableName = name.getMethodName(); final TableName tn = TableName.valueOf(tableName); String startKey = "startkey"; final byte[] sk = Bytes.toBytes(startKey); String id = "id"; // old format region name byte [] name = HRegionInfo.createRegionName(tn, sk, id, false); String nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id, nameStr); // new format region name. String md5HashInHex = MD5Hash.getMD5AsHex(name); assertEquals(HRegionInfo.MD5_HEX_LENGTH, md5HashInHex.length()); name = HRegionInfo.createRegionName(tn, sk, id, true); nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id + "." + md5HashInHex + ".", nameStr); }
@Test public void testParseName() throws IOException { final TableName tableName = TableName.valueOf(name.getMethodName()); byte[] startKey = Bytes.toBytes("startKey"); long regionId = System.currentTimeMillis(); int replicaId = 42; // test without replicaId byte[] regionName = HRegionInfo.createRegionName(tableName, startKey, regionId, false); byte[][] fields = HRegionInfo.parseRegionName(regionName); assertArrayEquals(Bytes.toString(fields[0]),tableName.getName(), fields[0]); assertArrayEquals(Bytes.toString(fields[1]),startKey, fields[1]); assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)),fields[2]); assertEquals(3, fields.length); // test with replicaId regionName = HRegionInfo.createRegionName(tableName, startKey, regionId, replicaId, false); fields = HRegionInfo.parseRegionName(regionName); assertArrayEquals(Bytes.toString(fields[0]),tableName.getName(), fields[0]); assertArrayEquals(Bytes.toString(fields[1]),startKey, fields[1]); assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)),fields[2]); assertArrayEquals(Bytes.toString(fields[3]), Bytes.toBytes( String.format(HRegionInfo.REPLICA_ID_FORMAT, replicaId)), fields[3]); }
public static void doTestGetRegionInfo(Hbase.Iface handler) throws Exception { // Create tableA and add two columns to rowA handler.createTable(tableAname, getColumnDescriptors()); try { handler.mutateRow(tableAname, rowAname, getMutations(), null); byte[] searchRow = HRegionInfo.createRegionName( TableName.valueOf(tableAname.array()), rowAname.array(), HConstants.NINES, false); TRegionInfo regionInfo = handler.getRegionInfo(ByteBuffer.wrap(searchRow)); assertTrue(Bytes.toStringBinary(regionInfo.getName()).startsWith( Bytes.toStringBinary(tableAname))); } finally { handler.disableTable(tableAname); handler.deleteTable(tableAname); } }
public HRegionInfo(long regionId, TableName tableName, int replicaId) { super(); this.regionId = regionId; this.tableName = tableName; this.replicaId = replicaId; // Note: First Meta region replicas names are in old format this.regionName = createRegionName(tableName, null, regionId, replicaId, false); setHashCode(); }
findRow(mr, 'C', 43, 42); byte[] firstRowInC = HRegionInfo.createRegionName(TableName.valueOf("" + 'C'), HConstants.EMPTY_BYTE_ARRAY, HConstants.ZEROES, false); Scan scan = new Scan(firstRowInC);
this.regionName = createRegionName(this.tableName, startKey, regionId, replicaId, true);
/** * Make a region name of passed parameters. * @param tableName * @param startKey Can be null * @param regionid Region id (Usually timestamp from when region was created). * @param newFormat should we create the region name in the new format * (such that it contains its encoded name?). * @return Region name made of passed tableName, startKey and id */ public static byte [] createRegionName(final byte [] tableName, final byte [] startKey, final long regionid, boolean newFormat) { return createRegionName(tableName, startKey, Long.toString(regionid), newFormat); }
/** * Make a region name of passed parameters. * @param tableName * @param startKey Can be null * @param id Region id (Usually timestamp from when region was created). * @param newFormat should we create the region name in the new format * (such that it contains its encoded name?). * @return Region name made of passed tableName, startKey and id */ public static byte [] createRegionName(final byte [] tableName, final byte [] startKey, final String id, boolean newFormat) { return createRegionName(tableName, startKey, Bytes.toBytes(id), newFormat); }
/** * @return the region name */ @XmlAttribute public String getName() { byte [] tableNameAsBytes = Bytes.toBytes(this.table); byte [] nameAsBytes = HRegionInfo.createRegionName(tableNameAsBytes, this.startKey, this.id, !HTableDescriptor.isMetaTable(tableNameAsBytes)); return Bytes.toString(nameAsBytes); }
public HRegionInfo(long regionId, TableName tableName, int replicaId) { super(); this.regionId = regionId; this.tableName = tableName; this.replicaId = replicaId; // Note: First Meta region replicas names are in old format this.regionName = createRegionName(tableName, null, regionId, replicaId, false); setHashCode(); }
private HRegionLocation getFirstMetaServerForTable(final byte [] tableName) throws IOException { return connection.locateRegion(HConstants.META_TABLE_NAME, HRegionInfo.createRegionName(tableName, null, HConstants.NINES, false)); }
/** * @return the region name */ @XmlAttribute public String getName() { byte [] tableNameAsBytes = Bytes.toBytes(this.table); TableName tableName = TableName.valueOf(tableNameAsBytes); byte [] nameAsBytes = HRegionInfo.createRegionName( tableName, this.startKey, this.id, !tableName.isSystemTable()); return Bytes.toString(nameAsBytes); }
/** * @return the region name */ @XmlAttribute public String getName() { byte [] tableNameAsBytes = Bytes.toBytes(this.table); TableName tableName = TableName.valueOf(tableNameAsBytes); byte [] nameAsBytes = HRegionInfo.createRegionName( tableName, this.startKey, this.id, !tableName.isSystemTable()); return Bytes.toString(nameAsBytes); }
public HRegionInfo(long regionId, TableName tableName, int replicaId) { super(); this.regionId = regionId; this.tableName = tableName; this.replicaId = replicaId; // Note: First Meta region replicas names are in old format this.regionName = createRegionName(tableName, null, regionId, replicaId, false); setHashCode(); }
/** * Extract the region encoded name from the region manifest */ static String getRegionNameFromManifest(final SnapshotRegionManifest manifest) { byte[] regionName = HRegionInfo.createRegionName( ProtobufUtil.toTableName(manifest.getRegionInfo().getTableName()), manifest.getRegionInfo().getStartKey().toByteArray(), manifest.getRegionInfo().getRegionId(), true); return HRegionInfo.encodeRegionName(regionName); }