/** * @param hri * @return Content of the file we write out to the filesystem under a region * @throws IOException */ private static byte[] getRegionInfoFileContent(final RegionInfo hri) throws IOException { return RegionInfo.toDelimitedByteArray(hri); }
/** * Use this instead of {@link #toByteArray()} when writing to a stream and you want to use * the pb mergeDelimitedFrom (w/o the delimiter, pb reads to EOF which may not be what you want). * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException * @see #toByteArray() * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link RegionInfo#toDelimitedByteArray(RegionInfo)}. */ @Deprecated public byte [] toDelimitedByteArray() throws IOException { return RegionInfo.toDelimitedByteArray(this); }
/** * Serializes given RegionInfo's as a byte array. Use this instead of * {@link RegionInfo#toByteArray(RegionInfo)} when * writing to a stream and you want to use the pb mergeDelimitedFrom (w/o the delimiter, pb reads * to EOF which may not be what you want). {@link #parseDelimitedFrom(byte[], int, int)} can * be used to read back the instances. * @param infos RegionInfo objects to serialize * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException */ static byte[] toDelimitedByteArray(RegionInfo... infos) throws IOException { byte[][] bytes = new byte[infos.length][]; int size = 0; for (int i = 0; i < infos.length; i++) { bytes[i] = toDelimitedByteArray(infos[i]); size += bytes[i].length; } byte[] result = new byte[size]; int offset = 0; for (byte[] b : bytes) { System.arraycopy(b, 0, result, offset, b.length); offset += b.length; } return result; }
/** * Serializes given HRegionInfo's as a byte array. Use this instead of {@link #toByteArray()} when * writing to a stream and you want to use the pb mergeDelimitedFrom (w/o the delimiter, pb reads * to EOF which may not be what you want). {@link #parseDelimitedFrom(byte[], int, int)} can * be used to read back the instances. * @param infos HRegionInfo objects to serialize * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException * @see #toByteArray() * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link RegionInfo#toDelimitedByteArray(RegionInfo...)}. */ @Deprecated @InterfaceAudience.Private public static byte[] toDelimitedByteArray(HRegionInfo... infos) throws IOException { return RegionInfo.toDelimitedByteArray(infos); }
/** * Write the .regioninfo file on-disk. */ public static void writeRegioninfoOnFilesystem(final Configuration conf, final FileSystem fs, final Path regionInfoDir, RegionInfo regionInfo) throws IOException { final byte[] content = RegionInfo.toDelimitedByteArray(regionInfo); Path regionInfoFile = new Path(regionInfoDir, "." + HConstants.REGIONINFO_QUALIFIER_STR); // First check to get the permissions FsPermission perms = FSUtils.getFilePermissions(fs, conf, HConstants.DATA_FILE_UMASK_KEY); // Write the RegionInfo file content FSDataOutputStream out = FSUtils.create(conf, fs, regionInfoFile, perms, null); try { out.write(content); } finally { out.close(); } }
protected RegionInfo createRegion(Configuration conf, final Table htbl, byte[] startKey, byte[] endKey) throws IOException { Table meta = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME); HTableDescriptor htd = htbl.getTableDescriptor(); RegionInfo hri = RegionInfoBuilder.newBuilder(htbl.getName()) .setStartKey(startKey) .setEndKey(endKey) .build(); LOG.info("manually adding regioninfo and hdfs data: " + hri.toString()); Path rootDir = FSUtils.getRootDir(conf); FileSystem fs = rootDir.getFileSystem(conf); Path p = new Path(FSUtils.getTableDir(rootDir, htbl.getName()), hri.getEncodedName()); fs.mkdirs(p); Path riPath = new Path(p, HRegionFileSystem.REGION_INFO_FILE); FSDataOutputStream out = fs.create(riPath); out.write(RegionInfo.toDelimitedByteArray(hri)); out.close(); // add to meta. MetaTableAccessor.addRegionToMeta(TEST_UTIL.getConnection(), hri); meta.close(); return hri; }
/** * Use this instead of {@link #toByteArray()} when writing to a stream and you want to use * the pb mergeDelimitedFrom (w/o the delimiter, pb reads to EOF which may not be what you want). * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException * @see #toByteArray() * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link RegionInfo#toDelimitedByteArray(RegionInfo)}. */ @Deprecated public byte [] toDelimitedByteArray() throws IOException { return RegionInfo.toDelimitedByteArray(this); }
/** * Serializes given RegionInfo's as a byte array. Use this instead of * {@link RegionInfo#toByteArray(RegionInfo)} when * writing to a stream and you want to use the pb mergeDelimitedFrom (w/o the delimiter, pb reads * to EOF which may not be what you want). {@link #parseDelimitedFrom(byte[], int, int)} can * be used to read back the instances. * @param infos RegionInfo objects to serialize * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException */ static byte[] toDelimitedByteArray(RegionInfo... infos) throws IOException { byte[][] bytes = new byte[infos.length][]; int size = 0; for (int i = 0; i < infos.length; i++) { bytes[i] = toDelimitedByteArray(infos[i]); size += bytes[i].length; } byte[] result = new byte[size]; int offset = 0; for (byte[] b : bytes) { System.arraycopy(b, 0, result, offset, b.length); offset += b.length; } return result; }
/** * Serializes given HRegionInfo's as a byte array. Use this instead of {@link #toByteArray()} when * writing to a stream and you want to use the pb mergeDelimitedFrom (w/o the delimiter, pb reads * to EOF which may not be what you want). {@link #parseDelimitedFrom(byte[], int, int)} can * be used to read back the instances. * @param infos HRegionInfo objects to serialize * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException * @see #toByteArray() * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link RegionInfo#toDelimitedByteArray(RegionInfo...)}. */ @Deprecated @InterfaceAudience.Private public static byte[] toDelimitedByteArray(HRegionInfo... infos) throws IOException { return RegionInfo.toDelimitedByteArray(infos); }
/** * Use this instead of {@link #toByteArray()} when writing to a stream and you want to use * the pb mergeDelimitedFrom (w/o the delimiter, pb reads to EOF which may not be what you want). * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException * @see #toByteArray() * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link RegionInfo#toDelimitedByteArray(RegionInfo)}. */ @Deprecated public byte [] toDelimitedByteArray() throws IOException { return RegionInfo.toDelimitedByteArray(this); }
/** * Serializes given RegionInfo's as a byte array. Use this instead of * {@link RegionInfo#toByteArray(RegionInfo)} when * writing to a stream and you want to use the pb mergeDelimitedFrom (w/o the delimiter, pb reads * to EOF which may not be what you want). {@link #parseDelimitedFrom(byte[], int, int)} can * be used to read back the instances. * @param infos RegionInfo objects to serialize * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException */ static byte[] toDelimitedByteArray(RegionInfo... infos) throws IOException { byte[][] bytes = new byte[infos.length][]; int size = 0; for (int i = 0; i < infos.length; i++) { bytes[i] = toDelimitedByteArray(infos[i]); size += bytes[i].length; } byte[] result = new byte[size]; int offset = 0; for (byte[] b : bytes) { System.arraycopy(b, 0, result, offset, b.length); offset += b.length; } return result; }
/** * Serializes given HRegionInfo's as a byte array. Use this instead of {@link #toByteArray()} when * writing to a stream and you want to use the pb mergeDelimitedFrom (w/o the delimiter, pb reads * to EOF which may not be what you want). {@link #parseDelimitedFrom(byte[], int, int)} can * be used to read back the instances. * @param infos HRegionInfo objects to serialize * @return This instance serialized as a delimited protobuf w/ a magic pb prefix. * @throws IOException * @see #toByteArray() * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link RegionInfo#toDelimitedByteArray(RegionInfo...)}. */ @Deprecated @InterfaceAudience.Private public static byte[] toDelimitedByteArray(HRegionInfo... infos) throws IOException { return RegionInfo.toDelimitedByteArray(infos); }
protected RegionInfo createRegion(Configuration conf, final Table htbl, byte[] startKey, byte[] endKey) throws IOException { Table meta = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME); HTableDescriptor htd = htbl.getTableDescriptor(); RegionInfo hri = RegionInfoBuilder.newBuilder(htbl.getName()) .setStartKey(startKey) .setEndKey(endKey) .build(); LOG.info("manually adding regioninfo and hdfs data: " + hri.toString()); Path rootDir = FSUtils.getRootDir(conf); FileSystem fs = rootDir.getFileSystem(conf); Path p = new Path(FSUtils.getTableDir(rootDir, htbl.getName()), hri.getEncodedName()); fs.mkdirs(p); Path riPath = new Path(p, HRegionFileSystem.REGION_INFO_FILE); FSDataOutputStream out = fs.create(riPath); out.write(RegionInfo.toDelimitedByteArray(hri)); out.close(); // add to meta. MetaTableAccessor.addRegionToMeta(TEST_UTIL.getConnection(), hri); meta.close(); return hri; }