/** * Write out an info file under the region directory. Useful recovering mangled regions. * @param useTempDir indicate whether or not using the region .tmp dir for a safer file creation. */ private void writeRegionInfoOnFilesystem(boolean useTempDir) throws IOException { byte[] content = getRegionInfoFileContent(regionInfoForFs); writeRegionInfoOnFilesystem(content, useTempDir); }
regionFs.writeRegionInfoOnFilesystem(false); } else { if (LOG.isDebugEnabled())
writeRegionInfoOnFilesystem(content, true);
/** * Write out an info file under the region directory. Useful recovering mangled regions. * @param useTempDir indicate whether or not using the region .tmp dir for a safer file creation. */ private void writeRegionInfoOnFilesystem(boolean useTempDir) throws IOException { byte[] content = getRegionInfoFileContent(regionInfoForFs); writeRegionInfoOnFilesystem(content, useTempDir); }
/** * Create a new Region on file-system. * @param conf the {@link Configuration} to use * @param fs {@link FileSystem} from which to add the region * @param tableDir {@link Path} to where the table is being stored * @param regionInfo {@link HRegionInfo} for region to be added * @throws IOException if the region creation fails due to a FileSystem exception. */ public static HRegionFileSystem createRegionOnFileSystem(final Configuration conf, final FileSystem fs, final Path tableDir, final HRegionInfo regionInfo) throws IOException { HRegionFileSystem regionFs = new HRegionFileSystem(conf, fs, tableDir, regionInfo); Path regionDir = regionFs.getRegionDir(); if (fs.exists(regionDir)) { LOG.warn("Trying to create a region that already exists on disk: " + regionDir); throw new IOException("The specified region already exists on disk: " + regionDir); } // Create the region directory if (!createDirOnFileSystem(fs, conf, regionDir)) { LOG.warn("Unable to create the region directory: " + regionDir); throw new IOException("Unable to create region directory: " + regionDir); } // Write HRI to a file in case we need to recover hbase:meta regionFs.writeRegionInfoOnFilesystem(false); return regionFs; }
/** * Write out an info file under the stored region directory. Useful recovering mangled regions. * If the regionInfo already exists on-disk, then we fast exit. */ void checkRegionInfoOnFilesystem() throws IOException { // Compose the content of the file so we can compare to length in filesystem. If not same, // rewrite it (it may have been written in the old format using Writables instead of pb). The // pb version is much shorter -- we write now w/o the toString version -- so checking length // only should be sufficient. I don't want to read the file every time to check if it pb // serialized. byte[] content = getRegionInfoFileContent(regionInfoForFs); try { Path regionInfoFile = new Path(getRegionDir(), REGION_INFO_FILE); FileStatus status = fs.getFileStatus(regionInfoFile); if (status != null && status.getLen() == content.length) { // Then assume the content good and move on. // NOTE: that the length is not sufficient to define the the content matches. return; } LOG.info("Rewriting .regioninfo file at: " + regionInfoFile); if (!fs.delete(regionInfoFile, false)) { throw new IOException("Unable to remove existing " + regionInfoFile); } } catch (FileNotFoundException e) { LOG.warn(REGION_INFO_FILE + " file not found for region: " + regionInfoForFs.getEncodedName() + " on table " + regionInfo.getTable()); } // Write HRI to a file in case we need to recover hbase:meta writeRegionInfoOnFilesystem(content, true); }