HBASE-19391 Calling HRegion#initializeRegionInternals from a region replica can still re-create a region directory
This commit is contained in:
parent
13223c217c
commit
a0900857c7
|
@ -969,28 +969,29 @@ public class HRegionFileSystem {
|
||||||
public static HRegionFileSystem createRegionOnFileSystem(final Configuration conf,
|
public static HRegionFileSystem createRegionOnFileSystem(final Configuration conf,
|
||||||
final FileSystem fs, final Path tableDir, final RegionInfo regionInfo) throws IOException {
|
final FileSystem fs, final Path tableDir, final RegionInfo regionInfo) throws IOException {
|
||||||
HRegionFileSystem regionFs = new HRegionFileSystem(conf, fs, tableDir, regionInfo);
|
HRegionFileSystem regionFs = new HRegionFileSystem(conf, fs, tableDir, regionInfo);
|
||||||
Path regionDir = regionFs.getRegionDir();
|
|
||||||
|
|
||||||
if (fs.exists(regionDir)) {
|
// We only create a .regioninfo and the region directory if this is the default region replica
|
||||||
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
|
|
||||||
// Only primary replicas should write region info
|
|
||||||
if (regionInfo.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) {
|
if (regionInfo.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) {
|
||||||
|
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);
|
regionFs.writeRegionInfoOnFilesystem(false);
|
||||||
|
return regionFs;
|
||||||
} else {
|
} else {
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("Skipping creation of .regioninfo file for " + regionInfo);
|
LOG.debug("Skipping creation of .regioninfo file for " + regionInfo);
|
||||||
}
|
}
|
||||||
return regionFs;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue