/** * Checks if a current table info file exists for the given table * * @param tableName name of table * @return true if exists * @throws IOException */ public boolean isTableInfoExists(TableName tableName) throws IOException { return getTableInfoPath(tableName) != null; }
private FileStatus getTableInfoPath(Path tableDir) throws IOException { return getTableInfoPath(fs, tableDir, !fsreadonly); }
/** * Find the most current table info file for the table located in the given table directory. * * Looks within the {@link #TABLEINFO_DIR} subdirectory of the given directory for any table info * files and takes the 'current' one - meaning the one with the highest sequence number if present * or no sequence number at all if none exist (for backward compatibility from before there * were sequence numbers). * * @return The file status of the current table info file or null if it does not exist * @throws IOException */ public static FileStatus getTableInfoPath(FileSystem fs, Path tableDir) throws IOException { return getTableInfoPath(fs, tableDir, false); }
private static boolean isTableDir(final FileSystem fs, final Path path) throws IOException { return FSTableDescriptors.getTableInfoPath(fs, path) != null; }
/** * Find the most current table info file for the given table in the hbase root directory. * @return The file status of the current table info file or null if it does not exist */ private FileStatus getTableInfoPath(final TableName tableName) throws IOException { Path tableDir = getTableDir(tableName); return getTableInfoPath(tableDir); }
/** * 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); }
throw new NotImplementedException("Cannot create a table descriptor - in read only mode"); FileStatus status = getTableInfoPath(fs, tableDir); if (status != null) { LOG.debug("Current path=" + status.getPath());
/** * Update table descriptor on the file system * @throws IOException Thrown if failed update. * @throws NotImplementedException if in read only mode */ @VisibleForTesting Path updateTableDescriptor(TableDescriptor td) throws IOException { if (fsreadonly) { throw new NotImplementedException("Cannot update a table descriptor - in read only mode"); } TableName tableName = td.getTableName(); Path tableDir = getTableDir(tableName); Path p = writeTableDescriptor(fs, td, tableDir, getTableInfoPath(tableDir)); if (p == null) throw new IOException("Failed update"); LOG.info("Updated tableinfo=" + p); if (usecache) { this.cache.put(td.getTableName(), td); } return p; }
@Test public void testReadingOldHTDFromFS() throws IOException, DeserializationException { final String name = this.name.getMethodName(); FileSystem fs = FileSystem.get(UTIL.getConfiguration()); Path rootdir = UTIL.getDataTestDir(name); FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir); TableDescriptor htd = TableDescriptorBuilder.newBuilder(TableName.valueOf(name)).build(); Path descriptorFile = fstd.updateTableDescriptor(htd); try (FSDataOutputStream out = fs.create(descriptorFile, true)) { out.write(TableDescriptorBuilder.toByteArray(htd)); } FSTableDescriptors fstd2 = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir); TableDescriptor td2 = fstd2.get(htd.getTableName()); assertEquals(htd, td2); FileStatus descriptorFile2 = FSTableDescriptors.getTableInfoPath(fs, fstd2.getTableDir(htd.getTableName())); byte[] buffer = TableDescriptorBuilder.toByteArray(htd); try (FSDataInputStream in = fs.open(descriptorFile2.getPath())) { in.readFully(buffer); } TableDescriptor td3 = TableDescriptorBuilder.parseFrom(buffer); assertEquals(htd, td3); }
/** * Checks if a current table info file exists for the given table * * @param tableName name of table * @return true if exists * @throws IOException */ public boolean isTableInfoExists(TableName tableName) throws IOException { return getTableInfoPath(tableName) != null; }
private FileStatus getTableInfoPath(Path tableDir) throws IOException { return getTableInfoPath(fs, tableDir, !fsreadonly); }
private static boolean isTableDir(final FileSystem fs, final Path path) throws IOException { return FSTableDescriptors.getTableInfoPath(fs, path) != null; }
private static boolean isTableDir(final FileSystem fs, final Path path) throws IOException { return FSTableDescriptors.getTableInfoPath(fs, path) != null; }
private static boolean isTableDir(final FileSystem fs, final Path path) throws IOException { return FSTableDescriptors.getTableInfoPath(fs, path) != null; }
/** * Checks if <code>.tableinfo<code> exists for given table * * @param fs file system * @param rootdir root directory of HBase installation * @param tableName name of table * @return true if exists * @throws IOException */ public static boolean isTableInfoExists(FileSystem fs, Path rootdir, String tableName) throws IOException { FileStatus status = getTableInfoPath(fs, rootdir, tableName); return status == null? false: fs.exists(status.getPath()); }
/** * Find the most current table info file for the given table in the hbase root directory. * @return The file status of the current table info file or null if it does not exist */ private FileStatus getTableInfoPath(final TableName tableName) throws IOException { Path tableDir = getTableDir(tableName); return getTableInfoPath(tableDir); }
private static FileStatus getTableInfoPath(final FileSystem fs, final Path rootdir, final String tableName) throws IOException { Path tabledir = FSUtils.getTablePath(rootdir, tableName); return getTableInfoPath(fs, tabledir); }
/** * Determines if migration is required by checking to see whether the hbase:meta table has been * migrated. */ private static boolean needsMigration(FileSystem fs, Path rootDir) throws IOException { Path metaTableDir = FSUtils.getTableDir(rootDir, TableName.META_TABLE_NAME); FileStatus metaTableInfoStatus = FSTableDescriptors.getTableInfoPath(fs, metaTableDir); return metaTableInfoStatus == null; }
private static boolean isTableDir(final FileSystem fs, final Path path) throws IOException { // check for old format, of having /table/.tableinfo; hbase:meta doesn't has .tableinfo, // include it. if (fs.isFile(path)) return false; return (FSTableDescriptors.getTableInfoPath(fs, path) != null || FSTableDescriptors .getCurrentTableInfoStatus(fs, path, false) != null) || path.toString().endsWith(".META."); }
/** * Deletes a table's directory from the file system if exists. Used in unit * tests. */ public static void deleteTableDescriptorIfExists(String tableName, Configuration conf) throws IOException { FileSystem fs = FSUtils.getCurrentFileSystem(conf); FileStatus status = getTableInfoPath(fs, FSUtils.getRootDir(conf), tableName); // The below deleteDirectory works for either file or directory. if (status != null && fs.exists(status.getPath())) { FSUtils.deleteDirectory(fs, status.getPath()); } }