Index: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (revision 1357184) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (working copy) @@ -3756,6 +3756,34 @@ final HLog hlog, final boolean initialize) 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() + " HTD == " + hTableDescriptor + " RootDir = " + rootDir + " Table name == " + info.getTableNameAsString()); @@ -3766,7 +3794,7 @@ FileSystem fs = FileSystem.get(conf); fs.mkdirs(regionDir); HLog effectiveHLog = hlog; - if (hlog == null) { + if (hlog == null && !ignoreHLog) { effectiveHLog = new HLog(fs, new Path(regionDir, HConstants.HREGION_LOGDIR_NAME), new Path(regionDir, HConstants.HREGION_OLDLOGDIR_NAME), conf); } Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java (revision 1357309) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java (working copy) @@ -152,16 +152,12 @@ List regionInfos = new ArrayList(); final int batchSize = this.conf.getInt("hbase.master.createtable.batchsize", 100); - HLog hlog = null; for (int regionIdx = 0; regionIdx < this.newRegions.length; regionIdx++) { HRegionInfo newRegion = this.newRegions[regionIdx]; // 1. Create HRegion HRegion region = HRegion.createHRegion(newRegion, this.fileSystemManager.getRootDir(), this.conf, - this.hTableDescriptor, hlog, false); - if (hlog == null) { - hlog = region.getLog(); - } + this.hTableDescriptor, null, false, true); regionInfos.add(region.getRegionInfo()); if (regionIdx % batchSize == 0) { @@ -173,7 +169,6 @@ // 3. Close the new region to flush to disk. Close log file too. region.close(); } - hlog.closeAndDelete(); if (regionInfos.size() > 0) { MetaEditor.addRegionsToMeta(this.catalogTracker, regionInfos); }