/** * @return This instance serialized as protobuf w/ a magic pb prefix. * @see #parseFrom(byte[]) * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link org.apache.hadoop.hbase.client.RegionInfo#toByteArray(RegionInfo)}. */ @Deprecated public byte [] toByteArray() { return RegionInfo.toByteArray(this); }
/** * Write the number of regions moved in the first line followed by regions moved in subsequent * lines */ private void writeFile(String filename, List<RegionInfo> movedRegions) throws IOException { try (DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(filename)))) { dos.writeInt(movedRegions.size()); for (RegionInfo region : movedRegions) { Bytes.writeByteArray(dos, RegionInfo.toByteArray(region)); } } catch (IOException e) { LOG.error( "ERROR: Was Not able to write regions moved to output file but moved " + movedRegions .size() + " regions", e); throw e; } }
@Test public void testPb() throws DeserializationException { RegionInfo ri = RegionInfoBuilder.FIRST_META_REGIONINFO; byte [] bytes = RegionInfo.toByteArray(ri); RegionInfo pbri = RegionInfo.parseFrom(bytes); assertTrue(RegionInfo.COMPARATOR.compare(ri, pbri) == 0); }
public static Put addRegionInfo(final Put p, final RegionInfo hri) throws IOException { p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(p.getRow()) .setFamily(getCatalogFamily()) .setQualifier(HConstants.REGIONINFO_QUALIFIER) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(hri)) .build()); return p; }
.setTimestamp(putOfMerged.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(regionA)) .build()) .add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setTimestamp(putOfMerged.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(regionB)) .build());
/** * Adds split daughters to the Put */ public static Put addDaughtersToPut(Put put, RegionInfo splitA, RegionInfo splitB) throws IOException { if (splitA != null) { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(HConstants.SPLITA_QUALIFIER) .setTimestamp(put.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(splitA)) .build()); } if (splitB != null) { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(HConstants.SPLITB_QUALIFIER) .setTimestamp(put.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(splitB)) .build()); } return put; }
/** * Inserts a new region's meta information into the passed * <code>meta</code> region. Used by the HMaster bootstrap code adding * new table to hbase:meta table. * * @param meta hbase:meta HRegion to be updated * @param r HRegion to add to <code>meta</code> * * @throws IOException */ public static void addRegionToMETA(final HRegion meta, final HRegion r) throws IOException { meta.checkResources(); // The row key is the region name byte[] row = r.getRegionInfo().getRegionName(); final long now = EnvironmentEdgeManager.currentTime(); final List<Cell> cells = new ArrayList<>(2); cells.add(new KeyValue(row, HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, now, RegionInfo.toByteArray(r.getRegionInfo()))); // Set into the root table the version of the meta table. cells.add(new KeyValue(row, HConstants.CATALOG_FAMILY, HConstants.META_VERSION_QUALIFIER, now, Bytes.toBytes(HConstants.META_VERSION))); meta.put(row, HConstants.CATALOG_FAMILY, cells); }
public static byte[] toByteArray(RegionInfo regionInfo) { return RegionInfo.toByteArray(regionInfo); } }
kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, RegionInfo.toByteArray(RegionInfoBuilder.FIRST_META_REGIONINFO))); kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
/** * @return This instance serialized as protobuf w/ a magic pb prefix. * @see #parseFrom(byte[]) * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link org.apache.hadoop.hbase.client.RegionInfo#toByteArray(RegionInfo)}. */ @Deprecated public byte [] toByteArray() { return RegionInfo.toByteArray(this); }
@Test public void testGetHRegionInfo() throws IOException { assertNull(MetaTableAccessor.getRegionInfo(new Result())); List<Cell> kvs = new ArrayList<>(); Result r = Result.create(kvs); assertNull(MetaTableAccessor.getRegionInfo(r)); byte [] f = HConstants.CATALOG_FAMILY; // Make a key value that doesn't have the expected qualifier. kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.SERVER_QUALIFIER, f)); r = Result.create(kvs); assertNull(MetaTableAccessor.getRegionInfo(r)); // Make a key that does not have a regioninfo value. kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER, f)); RegionInfo hri = MetaTableAccessor.getRegionInfo(Result.create(kvs)); assertTrue(hri == null); // OK, give it what it expects kvs.clear(); kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER, RegionInfo.toByteArray(RegionInfoBuilder.FIRST_META_REGIONINFO))); hri = MetaTableAccessor.getRegionInfo(Result.create(kvs)); assertNotNull(hri); assertTrue(RegionInfo.COMPARATOR.compare(hri, RegionInfoBuilder.FIRST_META_REGIONINFO) == 0); }
public static Put addRegionInfo(final Put p, final RegionInfo hri) throws IOException { p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(p.getRow()) .setFamily(getCatalogFamily()) .setQualifier(HConstants.REGIONINFO_QUALIFIER) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(hri)) .build()); return p; }
.setTimestamp(putOfMerged.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(regionA)) .build()) .add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setTimestamp(putOfMerged.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(regionB)) .build());
public static byte[] toByteArray(RegionInfo regionInfo) { return RegionInfo.toByteArray(regionInfo); } }
public static byte[] toByteArray(RegionInfo regionInfo) { return RegionInfo.toByteArray(regionInfo); } }
/** * Adds split daughters to the Put */ public static Put addDaughtersToPut(Put put, RegionInfo splitA, RegionInfo splitB) throws IOException { if (splitA != null) { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(HConstants.SPLITA_QUALIFIER) .setTimestamp(put.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(splitA)) .build()); } if (splitB != null) { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(HConstants.SPLITB_QUALIFIER) .setTimestamp(put.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(splitB)) .build()); } return put; }
/** * @return This instance serialized as protobuf w/ a magic pb prefix. * @see #parseFrom(byte[]) * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link org.apache.hadoop.hbase.client.RegionInfo#toByteArray(RegionInfo)}. */ @Deprecated public byte [] toByteArray() { return RegionInfo.toByteArray(this); }
@Test public void testPb() throws DeserializationException { RegionInfo ri = RegionInfoBuilder.FIRST_META_REGIONINFO; byte [] bytes = RegionInfo.toByteArray(ri); RegionInfo pbri = RegionInfo.parseFrom(bytes); assertTrue(RegionInfo.COMPARATOR.compare(ri, pbri) == 0); }
public static Put addRegionInfo(final Put p, final RegionInfo hri) throws IOException { p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(p.getRow()) .setFamily(getCatalogFamily()) .setQualifier(HConstants.REGIONINFO_QUALIFIER) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(hri)) .build()); return p; }
@Test public void testGetHRegionInfo() throws IOException { assertNull(MetaTableAccessor.getRegionInfo(new Result())); List<Cell> kvs = new ArrayList<>(); Result r = Result.create(kvs); assertNull(MetaTableAccessor.getRegionInfo(r)); byte [] f = HConstants.CATALOG_FAMILY; // Make a key value that doesn't have the expected qualifier. kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.SERVER_QUALIFIER, f)); r = Result.create(kvs); assertNull(MetaTableAccessor.getRegionInfo(r)); // Make a key that does not have a regioninfo value. kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER, f)); RegionInfo hri = MetaTableAccessor.getRegionInfo(Result.create(kvs)); assertTrue(hri == null); // OK, give it what it expects kvs.clear(); kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER, RegionInfo.toByteArray(RegionInfoBuilder.FIRST_META_REGIONINFO))); hri = MetaTableAccessor.getRegionInfo(Result.create(kvs)); assertNotNull(hri); assertTrue(RegionInfo.COMPARATOR.compare(hri, RegionInfoBuilder.FIRST_META_REGIONINFO) == 0); }