/** * Returns the latest table descriptor for the table located at the given directory * directly from the file system if it exists. * @throws TableInfoMissingException if there is no descriptor */ public static HTableDescriptor getTableDescriptorFromFs(FileSystem fs, Path tableDir) throws IOException { FileStatus status = getTableInfoPath(fs, tableDir); if (status == null) { throw new TableInfoMissingException("No table descriptor file under " + tableDir); } FSDataInputStream fsDataInputStream = fs.open(status.getPath()); HTableDescriptor hTableDescriptor = null; try { hTableDescriptor = new HTableDescriptor(); hTableDescriptor.readFields(fsDataInputStream); } finally { fsDataInputStream.close(); } return hTableDescriptor; }
static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs, Path tableDir) throws NullPointerException, IOException { if (tableDir == null) throw new NullPointerException(); FileStatus status = getTableInfoPath(fs, tableDir); if (status == null) { throw new TableInfoMissingException("No .tableinfo file under " + tableDir.toUri()); } FSDataInputStream fsDataInputStream = fs.open(status.getPath()); HTableDescriptor hTableDescriptor = null; try { hTableDescriptor = new HTableDescriptor(); hTableDescriptor.readFields(fsDataInputStream); } finally { fsDataInputStream.close(); } return new TableDescriptorModtime(status.getModificationTime(), hTableDescriptor); }
/** * Returns the latest table descriptor for the table located at the given directory * directly from the file system if it exists. * @throws TableInfoMissingException if there is no descriptor */ public static HTableDescriptor getTableDescriptorFromFs(FileSystem fs, Path tableDir, boolean rewritePb) throws IOException { FileStatus status = getTableInfoPath(fs, tableDir, false); if (status == null) { throw new TableInfoMissingException("No table descriptor file under " + tableDir); } return readTableDescriptor(fs, status, rewritePb); }
/** * Returns the latest table descriptor for the table located at the given directory * directly from the file system if it exists. * @throws TableInfoMissingException if there is no descriptor */ public static HTableDescriptor getTableDescriptorFromFs(FileSystem fs, Path tableDir) throws IOException { FileStatus status = getTableInfoPath(fs, tableDir, false); if (status == null) { throw new TableInfoMissingException("No table descriptor file under " + tableDir); } return readTableDescriptor(fs, status, false); }
/** * Returns the latest table descriptor for the table located at the given directory * directly from the file system if it exists. * @throws TableInfoMissingException if there is no descriptor */ public static TableDescriptor getTableDescriptorFromFs(FileSystem fs, Path tableDir) throws IOException { FileStatus status = getTableInfoPath(fs, tableDir, false); if (status == null) { throw new TableInfoMissingException("No table descriptor file under " + tableDir); } return readTableDescriptor(fs, status); }
static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs, Path tableDir) throws NullPointerException, IOException { if (tableDir == null) throw new NullPointerException(); FileStatus status = getTableInfoPath(fs, tableDir); if (status == null) { throw new TableInfoMissingException("No .tableinfo file under " + tableDir.toUri()); } int len = Ints.checkedCast(status.getLen()); byte [] content = new byte[len]; FSDataInputStream fsDataInputStream = fs.open(status.getPath()); try { fsDataInputStream.readFully(content); } finally { fsDataInputStream.close(); } HTableDescriptor htd = null; try { htd = HTableDescriptor.parseFrom(content); } catch (DeserializationException e) { throw new IOException("content=" + Bytes.toShort(content), e); } if (!ProtobufUtil.isPBMagicPrefix(content)) { // Convert the file over to be pb before leaving here. createTableDescriptor(fs, tableDir.getParent(), htd, true); } return new TableDescriptorModtime(status.getModificationTime(), htd); }