/** * Gets the start key from the specified region name. * @param regionName * @return Start key. * @throws java.io.IOException */ static byte[] getStartKey(final byte[] regionName) throws IOException { return parseRegionName(regionName)[1]; }
/** * Separate elements of a regionName. * @param regionName * @return Array of byte[] containing tableName, startKey and id * @throws IOException * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link RegionInfo#parseRegionName(byte[])}. */ @Deprecated @InterfaceAudience.Private public static byte [][] parseRegionName(final byte [] regionName) throws IOException { return RegionInfo.parseRegionName(regionName); }
@InterfaceAudience.Private static boolean isEncodedRegionName(byte[] regionName) throws IOException { try { parseRegionName(regionName); return false; } catch (IOException e) { if (StringUtils.stringifyException(e) .contains(INVALID_REGION_NAME_FORMAT_MESSAGE)) { return true; } throw e; } }
/** Returns an HRI parsed from this regionName. Not all the fields of the HRI * is stored in the name, so the returned object should only be used for the fields * in the regionName. */ public static RegionInfo parseRegionInfoFromRegionName(byte[] regionName) throws IOException { byte[][] fields = RegionInfo.parseRegionName(regionName); long regionId = Long.parseLong(Bytes.toString(fields[2])); int replicaId = fields.length > 3 ? Integer.parseInt(Bytes.toString(fields[3]), 16) : 0; return RegionInfoBuilder.newBuilder(TableName.valueOf(fields[0])) .setStartKey(fields[1]) .setEndKey(fields[2]) .setSplit(false) .setRegionId(regionId) .setReplicaId(replicaId) .build(); }
/** * Post merge region action * @param env MasterProcedureEnv **/ private void preMergeRegionsCommit(final MasterProcedureEnv env) throws IOException { final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost(); if (cpHost != null) { @MetaMutationAnnotation final List<Mutation> metaEntries = new ArrayList<>(); cpHost.preMergeRegionsCommit(regionsToMerge, metaEntries, getUser()); try { for (Mutation p : metaEntries) { RegionInfo.parseRegionName(p.getRow()); } } catch (IOException e) { LOG.error("Row key of mutation from coprocessor is not parsable as region name. " + "Mutations from coprocessor should only be for hbase:meta table.", e); throw e; } } }
byte[][]regionNameParts = RegionInfo.parseRegionName(ri.getRegionName()); regionNameParts[1] = HIDDEN_START_KEY; //replace the real startkey int len = 0;
/** * Post split region actions before the Point-of-No-Return step * @param env MasterProcedureEnv **/ private void preSplitRegionBeforeMETA(final MasterProcedureEnv env) throws IOException, InterruptedException { final List<Mutation> metaEntries = new ArrayList<Mutation>(); final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost(); if (cpHost != null) { cpHost.preSplitBeforeMETAAction(getSplitRow(), metaEntries, getUser()); try { for (Mutation p : metaEntries) { RegionInfo.parseRegionName(p.getRow()); } } catch (IOException e) { LOG.error("pid=" + getProcId() + " row key of mutation from coprocessor not parsable as " + "region name." + "Mutations from coprocessor should only for hbase:meta table."); throw e; } } }
private void checkEquality(RegionInfo ri, Configuration conf) throws IOException { byte[] modifiedRegionName = RegionInfoDisplay.getRegionNameForDisplay(ri, conf); System.out.println(Bytes.toString(modifiedRegionName) + " " + ri.toString()); byte[][] modifiedRegionNameParts = RegionInfo.parseRegionName(modifiedRegionName); byte[][] regionNameParts = RegionInfo.parseRegionName(ri.getRegionName()); //same number of parts assert(modifiedRegionNameParts.length == regionNameParts.length); for (int i = 0; i < regionNameParts.length; i++) { // all parts should match except for [1] where in the modified one, // we should have "hidden_start_key" if (i != 1) { System.out.println("" + i + " " + Bytes.toString(regionNameParts[i]) + " " + Bytes.toString(modifiedRegionNameParts[i])); Assert.assertArrayEquals(regionNameParts[i], modifiedRegionNameParts[i]); } else { System.out.println("" + i + " " + Bytes.toString(regionNameParts[i]) + " " + Bytes.toString(modifiedRegionNameParts[i])); Assert.assertNotEquals(regionNameParts[i], modifiedRegionNameParts[i]); Assert.assertArrayEquals(modifiedRegionNameParts[1], RegionInfoDisplay.getStartKeyForDisplay(ri, conf)); } } }
@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 = RegionInfo.createRegionName(tableName, startKey, regionId, false); byte[][] fields = RegionInfo.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 = RegionInfo.createRegionName(tableName, startKey, regionId, replicaId, false); fields = RegionInfo.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(RegionInfo.REPLICA_ID_FORMAT, replicaId)), fields[3]); }
/** * Gets the start key from the specified region name. * @param regionName * @return Start key. * @throws java.io.IOException */ static byte[] getStartKey(final byte[] regionName) throws IOException { return parseRegionName(regionName)[1]; }
/** * Separate elements of a regionName. * @param regionName * @return Array of byte[] containing tableName, startKey and id * @throws IOException * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link RegionInfo#parseRegionName(byte[])}. */ @Deprecated @InterfaceAudience.Private public static byte [][] parseRegionName(final byte [] regionName) throws IOException { return RegionInfo.parseRegionName(regionName); }
@InterfaceAudience.Private static boolean isEncodedRegionName(byte[] regionName) throws IOException { try { parseRegionName(regionName); return false; } catch (IOException e) { if (StringUtils.stringifyException(e) .contains(INVALID_REGION_NAME_FORMAT_MESSAGE)) { return true; } throw e; } }
/** Returns an HRI parsed from this regionName. Not all the fields of the HRI * is stored in the name, so the returned object should only be used for the fields * in the regionName. */ public static RegionInfo parseRegionInfoFromRegionName(byte[] regionName) throws IOException { byte[][] fields = RegionInfo.parseRegionName(regionName); long regionId = Long.parseLong(Bytes.toString(fields[2])); int replicaId = fields.length > 3 ? Integer.parseInt(Bytes.toString(fields[3]), 16) : 0; return RegionInfoBuilder.newBuilder(TableName.valueOf(fields[0])) .setStartKey(fields[1]) .setEndKey(fields[2]) .setSplit(false) .setRegionId(regionId) .setReplicaId(replicaId) .build(); }
byte[][]regionNameParts = RegionInfo.parseRegionName(ri.getRegionName()); regionNameParts[1] = HIDDEN_START_KEY; //replace the real startkey int len = 0;
private void checkEquality(RegionInfo ri, Configuration conf) throws IOException { byte[] modifiedRegionName = RegionInfoDisplay.getRegionNameForDisplay(ri, conf); System.out.println(Bytes.toString(modifiedRegionName) + " " + ri.toString()); byte[][] modifiedRegionNameParts = RegionInfo.parseRegionName(modifiedRegionName); byte[][] regionNameParts = RegionInfo.parseRegionName(ri.getRegionName()); //same number of parts assert(modifiedRegionNameParts.length == regionNameParts.length); for (int i = 0; i < regionNameParts.length; i++) { // all parts should match except for [1] where in the modified one, // we should have "hidden_start_key" if (i != 1) { System.out.println("" + i + " " + Bytes.toString(regionNameParts[i]) + " " + Bytes.toString(modifiedRegionNameParts[i])); Assert.assertArrayEquals(regionNameParts[i], modifiedRegionNameParts[i]); } else { System.out.println("" + i + " " + Bytes.toString(regionNameParts[i]) + " " + Bytes.toString(modifiedRegionNameParts[i])); Assert.assertNotEquals(regionNameParts[i], modifiedRegionNameParts[i]); Assert.assertArrayEquals(modifiedRegionNameParts[1], RegionInfoDisplay.getStartKeyForDisplay(ri, conf)); } } }
/** * Gets the start key from the specified region name. * @param regionName * @return Start key. * @throws java.io.IOException */ static byte[] getStartKey(final byte[] regionName) throws IOException { return parseRegionName(regionName)[1]; }
/** * Separate elements of a regionName. * @param regionName * @return Array of byte[] containing tableName, startKey and id * @throws IOException * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link RegionInfo#parseRegionName(byte[])}. */ @Deprecated @InterfaceAudience.Private public static byte [][] parseRegionName(final byte [] regionName) throws IOException { return RegionInfo.parseRegionName(regionName); }
@InterfaceAudience.Private static boolean isEncodedRegionName(byte[] regionName) throws IOException { try { parseRegionName(regionName); return false; } catch (IOException e) { if (StringUtils.stringifyException(e) .contains(INVALID_REGION_NAME_FORMAT_MESSAGE)) { return true; } throw e; } }
/** Returns an HRI parsed from this regionName. Not all the fields of the HRI * is stored in the name, so the returned object should only be used for the fields * in the regionName. */ public static RegionInfo parseRegionInfoFromRegionName(byte[] regionName) throws IOException { byte[][] fields = RegionInfo.parseRegionName(regionName); long regionId = Long.parseLong(Bytes.toString(fields[2])); int replicaId = fields.length > 3 ? Integer.parseInt(Bytes.toString(fields[3]), 16) : 0; return RegionInfoBuilder.newBuilder(TableName.valueOf(fields[0])) .setStartKey(fields[1]) .setEndKey(fields[2]) .setSplit(false) .setRegionId(regionId) .setReplicaId(replicaId) .build(); }
@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 = RegionInfo.createRegionName(tableName, startKey, regionId, false); byte[][] fields = RegionInfo.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 = RegionInfo.createRegionName(tableName, startKey, regionId, replicaId, false); fields = RegionInfo.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(RegionInfo.REPLICA_ID_FORMAT, replicaId)), fields[3]); }