HBASE-6327 HLog can be null when create table (ShiXing)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1364629 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2012-07-23 13:39:04 +00:00
parent 2144415141
commit 53ac5a3f8f
2 changed files with 30 additions and 7 deletions

View File

@ -152,16 +152,12 @@ public class CreateTableHandler extends EventHandler {
List<HRegionInfo> regionInfos = new ArrayList<HRegionInfo>(); List<HRegionInfo> regionInfos = new ArrayList<HRegionInfo>();
final int batchSize = final int batchSize =
this.conf.getInt("hbase.master.createtable.batchsize", 100); this.conf.getInt("hbase.master.createtable.batchsize", 100);
HLog hlog = null;
for (int regionIdx = 0; regionIdx < this.newRegions.length; regionIdx++) { for (int regionIdx = 0; regionIdx < this.newRegions.length; regionIdx++) {
HRegionInfo newRegion = this.newRegions[regionIdx]; HRegionInfo newRegion = this.newRegions[regionIdx];
// 1. Create HRegion // 1. Create HRegion
HRegion region = HRegion.createHRegion(newRegion, HRegion region = HRegion.createHRegion(newRegion,
this.fileSystemManager.getRootDir(), this.conf, this.fileSystemManager.getRootDir(), this.conf,
this.hTableDescriptor, hlog, false); this.hTableDescriptor, null, false, true);
if (hlog == null) {
hlog = region.getLog();
}
regionInfos.add(region.getRegionInfo()); regionInfos.add(region.getRegionInfo());
if (regionIdx % batchSize == 0) { if (regionIdx % batchSize == 0) {
@ -173,7 +169,6 @@ public class CreateTableHandler extends EventHandler {
// 3. Close the new region to flush to disk. Close log file too. // 3. Close the new region to flush to disk. Close log file too.
region.close(); region.close();
} }
hlog.closeAndDelete();
if (regionInfos.size() > 0) { if (regionInfos.size() > 0) {
MetaEditor.addRegionsToMeta(this.catalogTracker, regionInfos); MetaEditor.addRegionsToMeta(this.catalogTracker, regionInfos);
} }

View File

@ -3778,6 +3778,34 @@ public class HRegion implements HeapSize { // , Writable{
final HLog hlog, final HLog hlog,
final boolean initialize) final boolean initialize)
throws IOException { throws IOException {
return createHRegion(info, rootDir, conf, hTableDescriptor,
hlog, initialize, false);
}
/**
* Convenience method creating new HRegions. Used by createTable.
* The {@link HLog} for the created region needs to be closed
* explicitly, if it is not null.
* Use {@link HRegion#getLog()} to get access.
*
* @param info Info for region to create.
* @param rootDir Root directory for HBase instance
* @param conf
* @param hTableDescriptor
* @param hlog shared HLog
* @param boolean initialize - true to initialize the region
* @param boolean ignoreHLog
- true to skip generate new hlog if it is null, mostly for createTable
* @return new HRegion
*
* @throws IOException
*/
public static HRegion createHRegion(final HRegionInfo info, final Path rootDir,
final Configuration conf,
final HTableDescriptor hTableDescriptor,
final HLog hlog,
final boolean initialize, final boolean ignoreHLog)
throws IOException {
LOG.info("creating HRegion " + info.getTableNameAsString() LOG.info("creating HRegion " + info.getTableNameAsString()
+ " HTD == " + hTableDescriptor + " RootDir = " + rootDir + + " HTD == " + hTableDescriptor + " RootDir = " + rootDir +
" Table name == " + info.getTableNameAsString()); " Table name == " + info.getTableNameAsString());
@ -3788,7 +3816,7 @@ public class HRegion implements HeapSize { // , Writable{
FileSystem fs = FileSystem.get(conf); FileSystem fs = FileSystem.get(conf);
fs.mkdirs(regionDir); fs.mkdirs(regionDir);
HLog effectiveHLog = hlog; HLog effectiveHLog = hlog;
if (hlog == null) { if (hlog == null && !ignoreHLog) {
effectiveHLog = new HLog(fs, new Path(regionDir, HConstants.HREGION_LOGDIR_NAME), effectiveHLog = new HLog(fs, new Path(regionDir, HConstants.HREGION_LOGDIR_NAME),
new Path(regionDir, HConstants.HREGION_OLDLOGDIR_NAME), conf); new Path(regionDir, HConstants.HREGION_OLDLOGDIR_NAME), conf);
} }