HBASE-7911 Remove duplicated code from CreateTableHandler

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1449400 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
mbertozzi 2013-02-23 20:02:52 +00:00
parent 78b8109fdc
commit 23ad43710f
2 changed files with 3 additions and 78 deletions

View File

@ -55,6 +55,7 @@ import org.apache.hadoop.hbase.master.TableLockManager;
import org.apache.hadoop.hbase.master.TableLockManager.TableLock;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.util.FSTableDescriptors;
import org.apache.hadoop.hbase.util.ModifyRegionUtils;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.zookeeper.KeeperException;
@ -255,59 +256,7 @@ public class CreateTableHandler extends EventHandler {
protected List<HRegionInfo> handleCreateHdfsRegions(final Path tableRootDir,
final String tableName)
throws IOException {
int regionNumber = newRegions.length;
ThreadPoolExecutor regionOpenAndInitThreadPool = getRegionOpenAndInitThreadPool(
"RegionOpenAndInitThread-" + tableName, regionNumber);
CompletionService<HRegion> completionService = new ExecutorCompletionService<HRegion>(
regionOpenAndInitThreadPool);
List<HRegionInfo> regionInfos = new ArrayList<HRegionInfo>();
for (final HRegionInfo newRegion : newRegions) {
completionService.submit(new Callable<HRegion>() {
public HRegion call() throws IOException {
// 1. Create HRegion
HRegion region = HRegion.createHRegion(newRegion,
tableRootDir, conf, hTableDescriptor, null,
false, true);
// 2. Close the new region to flush to disk. Close log file too.
region.close();
return region;
}
});
}
try {
// 3. wait for all regions to finish creation
for (int i = 0; i < regionNumber; i++) {
Future<HRegion> future = completionService.take();
HRegion region = future.get();
regionInfos.add(region.getRegionInfo());
}
} catch (InterruptedException e) {
throw new InterruptedIOException(e.getMessage());
} catch (ExecutionException e) {
throw new IOException(e.getCause());
} finally {
regionOpenAndInitThreadPool.shutdownNow();
}
return regionInfos;
}
protected ThreadPoolExecutor getRegionOpenAndInitThreadPool(
final String threadNamePrefix, int regionNumber) {
int maxThreads = Math.min(regionNumber, conf.getInt(
"hbase.hregion.open.and.init.threads.max", 10));
ThreadPoolExecutor openAndInitializeThreadPool = Threads
.getBoundedCachedThreadPool(maxThreads, 30L, TimeUnit.SECONDS,
new ThreadFactory() {
private int count = 1;
public Thread newThread(Runnable r) {
Thread t = new Thread(r, threadNamePrefix + "-" + count++);
return t;
}
});
return openAndInitializeThreadPool;
return ModifyRegionUtils.createRegions(conf, tableRootDir,
hTableDescriptor, newRegions, null);
}
}

View File

@ -106,8 +106,6 @@ public abstract class ModifyRegionUtils {
HRegion region = HRegion.createHRegion(newRegion,
rootDir, conf, hTableDescriptor, null,
false, true);
HRegion.writeRegioninfoOnFilesystem(region.getRegionInfo(), region.getRegionDir(),
region.getFilesystem(), conf);
try {
// 2. Custom user code to interact with the created region
if (task != null) {
@ -176,26 +174,4 @@ public abstract class ModifyRegionUtils {
throw new InterruptedIOException(e.getMessage());
}
}
/**
* Remove specified regions by removing them from file-system and .META.
* (The regions must be offline).
*
* @param fs {@link FileSystem} on which to delete the region directory
* @param catalogTracker the catalog tracker
* @param regions list of {@link HRegionInfo} to delete.
*/
public static void deleteRegions(final Configuration conf, final FileSystem fs,
final CatalogTracker catalogTracker, final List<HRegionInfo> regions) throws IOException {
if (regions != null && regions.size() > 0) {
List<Delete> deletes = new ArrayList<Delete>(regions.size());
for (HRegionInfo hri: regions) {
deletes.add(new Delete(hri.getRegionName()));
// "Delete" region from FS
HFileArchiver.archiveRegion(conf, fs, hri);
}
MetaEditor.deleteFromMetaTable(catalogTracker, deletes);
}
}
}