HBASE-11983 HRegion constructors should not create HLog

This commit is contained in:
Nick Dimiduk 2015-01-13 12:35:19 -08:00
parent 4ac457a7bc
commit 9b7f36b8cf
46 changed files with 422 additions and 513 deletions

View File

@ -513,9 +513,9 @@ public class MasterFileSystem {
HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO); HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO);
HTableDescriptor metaDescriptor = new FSTableDescriptors(c).get(TableName.META_TABLE_NAME); HTableDescriptor metaDescriptor = new FSTableDescriptors(c).get(TableName.META_TABLE_NAME);
setInfoFamilyCachingForMeta(metaDescriptor, false); setInfoFamilyCachingForMeta(metaDescriptor, false);
HRegion meta = HRegion.createHRegion(metaHRI, rd, c, metaDescriptor); HRegion meta = HRegion.createHRegion(metaHRI, rd, c, metaDescriptor, null);
setInfoFamilyCachingForMeta(metaDescriptor, true); setInfoFamilyCachingForMeta(metaDescriptor, true);
HRegion.closeHRegion(meta); meta.close();
} catch (IOException e) { } catch (IOException e) {
e = e instanceof RemoteException ? e = e instanceof RemoteException ?
((RemoteException)e).unwrapRemoteException() : e; ((RemoteException)e).unwrapRemoteException() : e;

View File

@ -61,7 +61,6 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -135,8 +134,6 @@ import org.apache.hadoop.hbase.protobuf.generated.WALProtos.RegionEventDescripto
import org.apache.hadoop.hbase.regionserver.MultiVersionConsistencyControl.WriteEntry; import org.apache.hadoop.hbase.regionserver.MultiVersionConsistencyControl.WriteEntry;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext; import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;
import org.apache.hadoop.hbase.regionserver.wal.HLogKey; import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
import org.apache.hadoop.hbase.regionserver.wal.MetricsWAL;
import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
import org.apache.hadoop.hbase.regionserver.wal.WALEdit; import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
import org.apache.hadoop.hbase.regionserver.wal.WALUtil; import org.apache.hadoop.hbase.regionserver.wal.WALUtil;
import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils; import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils;
@ -3383,13 +3380,10 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver { //
* <b>not</b> check the families for validity. * <b>not</b> check the families for validity.
* *
* @param familyMap Map of kvs per family * @param familyMap Map of kvs per family
* @param localizedWriteEntry The WriteEntry of the MVCC for this transaction. * @param mvccNum The MVCC for this transaction.
* If null, then this method internally creates a mvcc transaction.
* @param output newly added KVs into memstore
* @param isInReplay true when adding replayed KVs into memstore * @param isInReplay true when adding replayed KVs into memstore
* @return the additional memory usage of the memstore caused by the * @return the additional memory usage of the memstore caused by the
* new entries. * new entries.
* @throws IOException
*/ */
private long applyFamilyMapToMemstore(Map<byte[], List<Cell>> familyMap, private long applyFamilyMapToMemstore(Map<byte[], List<Cell>> familyMap,
long mvccNum, List<Cell> memstoreCells, boolean isInReplay) throws IOException { long mvccNum, List<Cell> memstoreCells, boolean isInReplay) throws IOException {
@ -4672,56 +4666,14 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver { //
} }
} }
/**
* Convenience method creating new HRegions. Used by createTable and by the
* bootstrap code in the HMaster constructor.
* Note, this method creates an {@link WAL} for the created region. It
* needs to be closed explicitly. Use {@link HRegion#getWAL()} to get
* access. <b>When done with a region created using this method, you will
* need to explicitly close the {@link WAL} it created too; it will not be
* done for you. Not closing the wal will leave at least a daemon thread
* running.</b> Call {@link #closeHRegion(HRegion)} and it will do
* necessary cleanup for you.
* @param info Info for region to create.
* @param rootDir Root directory for HBase instance
* @return new HRegion
*
* @throws IOException
*/
public static HRegion createHRegion(final HRegionInfo info, final Path rootDir,
final Configuration conf, final HTableDescriptor hTableDescriptor)
throws IOException {
return createHRegion(info, rootDir, conf, hTableDescriptor, null);
}
/**
* This will do the necessary cleanup a call to
* {@link #createHRegion(HRegionInfo, Path, Configuration, HTableDescriptor)}
* requires. This method will close the region and then close its
* associated {@link WAL} file. You can still use it if you call the other createHRegion,
* the one that takes an {@link WAL} instance but don't be surprised by the
* call to the {@link WAL#close()} on the {@link WAL} the
* HRegion was carrying.
* @throws IOException
*/
public static void closeHRegion(final HRegion r) throws IOException {
if (r == null) return;
r.close();
if (r.getWAL() == null) return;
r.getWAL().close();
}
/** /**
* Convenience method creating new HRegions. Used by createTable. * Convenience method creating new HRegions. Used by createTable.
* The {@link WAL} for the created region needs to be closed explicitly.
* Use {@link HRegion#getWAL()} to get access.
* *
* @param info Info for region to create. * @param info Info for region to create.
* @param rootDir Root directory for HBase instance * @param rootDir Root directory for HBase instance
* @param wal shared WAL * @param wal shared WAL
* @param initialize - true to initialize the region * @param initialize - true to initialize the region
* @return new HRegion * @return new HRegion
*
* @throws IOException * @throws IOException
*/ */
public static HRegion createHRegion(final HRegionInfo info, final Path rootDir, public static HRegion createHRegion(final HRegionInfo info, final Path rootDir,
@ -4730,75 +4682,14 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver { //
final WAL wal, final WAL wal,
final boolean initialize) final boolean initialize)
throws IOException { throws IOException {
return createHRegion(info, rootDir, conf, hTableDescriptor,
wal, initialize, false);
}
/**
* Convenience method creating new HRegions. Used by createTable.
* The {@link WAL} for the created region needs to be closed
* explicitly, if it is not null.
* Use {@link HRegion#getWAL()} to get access.
*
* @param info Info for region to create.
* @param rootDir Root directory for HBase instance
* @param wal shared WAL
* @param initialize - true to initialize the region
* @param ignoreWAL - true to skip generate new wal 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 WAL wal,
final boolean initialize, final boolean ignoreWAL)
throws IOException {
Path tableDir = FSUtils.getTableDir(rootDir, info.getTable());
return createHRegion(info, rootDir, tableDir, conf, hTableDescriptor, wal, initialize,
ignoreWAL);
}
/**
* Convenience method creating new HRegions. Used by createTable.
* The {@link WAL} for the created region needs to be closed
* explicitly, if it is not null.
* Use {@link HRegion#getWAL()} to get access.
*
* @param info Info for region to create.
* @param rootDir Root directory for HBase instance
* @param tableDir table directory
* @param wal shared WAL
* @param initialize - true to initialize the region
* @param ignoreWAL - true to skip generate new wal if it is null, mostly for createTable
* @return new HRegion
* @throws IOException
*/
public static HRegion createHRegion(final HRegionInfo info, final Path rootDir, final Path tableDir,
final Configuration conf,
final HTableDescriptor hTableDescriptor,
final WAL wal,
final boolean initialize, final boolean ignoreWAL)
throws IOException {
LOG.info("creating HRegion " + info.getTable().getNameAsString() LOG.info("creating HRegion " + info.getTable().getNameAsString()
+ " HTD == " + hTableDescriptor + " RootDir = " + rootDir + + " HTD == " + hTableDescriptor + " RootDir = " + rootDir +
" Table name == " + info.getTable().getNameAsString()); " Table name == " + info.getTable().getNameAsString());
FileSystem fs = FileSystem.get(conf); FileSystem fs = FileSystem.get(conf);
Path tableDir = FSUtils.getTableDir(rootDir, info.getTable());
HRegionFileSystem.createRegionOnFileSystem(conf, fs, tableDir, info); HRegionFileSystem.createRegionOnFileSystem(conf, fs, tableDir, info);
WAL effectiveWAL = wal;
if (wal == null && !ignoreWAL) {
// TODO HBASE-11983 There'll be no roller for this wal?
// The WAL subsystem will use the default rootDir rather than the passed in rootDir
// unless I pass along via the conf.
Configuration confForWAL = new Configuration(conf);
confForWAL.set(HConstants.HBASE_DIR, rootDir.toString());
effectiveWAL = (new WALFactory(confForWAL,
Collections.<WALActionsListener>singletonList(new MetricsWAL()),
"hregion-" + RandomStringUtils.randomNumeric(8))).
getWAL(info.getEncodedNameAsBytes());
}
HRegion region = HRegion.newHRegion(tableDir, HRegion region = HRegion.newHRegion(tableDir,
effectiveWAL, fs, conf, info, hTableDescriptor, null); wal, fs, conf, info, hTableDescriptor, null);
if (initialize) { if (initialize) {
// If initializing, set the sequenceId. It is also required by WALPerformanceEvaluation when // If initializing, set the sequenceId. It is also required by WALPerformanceEvaluation when
// verifying the WALEdits. // verifying the WALEdits.

View File

@ -506,7 +506,7 @@ public class RestoreSnapshotHelper {
} }
// create the regions on disk // create the regions on disk
ModifyRegionUtils.createRegions(exec, conf, rootDir, tableDir, ModifyRegionUtils.createRegions(exec, conf, rootDir,
tableDesc, clonedRegionsInfo, new ModifyRegionUtils.RegionFillTask() { tableDesc, clonedRegionsInfo, new ModifyRegionUtils.RegionFillTask() {
@Override @Override
public void fillRegion(final HRegion region) throws IOException { public void fillRegion(final HRegion region) throws IOException {
@ -552,7 +552,7 @@ public class RestoreSnapshotHelper {
* </ul> * </ul>
* @param familyDir destination directory for the store file * @param familyDir destination directory for the store file
* @param regionInfo destination region info for the table * @param regionInfo destination region info for the table
* @param hfileName store file name (can be a Reference, HFileLink or simple HFile) * @param storeFile store file name (can be a Reference, HFileLink or simple HFile)
*/ */
private void restoreStoreFile(final Path familyDir, final HRegionInfo regionInfo, private void restoreStoreFile(final Path familyDir, final HRegionInfo regionInfo,
final SnapshotRegionManifest.StoreFile storeFile) throws IOException { final SnapshotRegionManifest.StoreFile storeFile) throws IOException {
@ -582,7 +582,7 @@ public class RestoreSnapshotHelper {
* </pre></blockquote> * </pre></blockquote>
* @param familyDir destination directory for the store file * @param familyDir destination directory for the store file
* @param regionInfo destination region info for the table * @param regionInfo destination region info for the table
* @param hfileName reference file name * @param storeFile reference file name
*/ */
private void restoreReferenceFile(final Path familyDir, final HRegionInfo regionInfo, private void restoreReferenceFile(final Path familyDir, final HRegionInfo regionInfo,
final SnapshotRegionManifest.StoreFile storeFile) throws IOException { final SnapshotRegionManifest.StoreFile storeFile) throws IOException {

View File

@ -53,6 +53,7 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -111,6 +112,8 @@ import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService.Block
import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.HRegionFileSystem; import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
import org.apache.hadoop.hbase.regionserver.StoreFileInfo; import org.apache.hadoop.hbase.regionserver.StoreFileInfo;
import org.apache.hadoop.hbase.regionserver.wal.MetricsWAL;
import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
import org.apache.hadoop.hbase.security.AccessDeniedException; import org.apache.hadoop.hbase.security.AccessDeniedException;
import org.apache.hadoop.hbase.security.UserProvider; import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.util.Bytes.ByteArrayComparator; import org.apache.hadoop.hbase.util.Bytes.ByteArrayComparator;
@ -119,6 +122,8 @@ import org.apache.hadoop.hbase.util.hbck.HFileCorruptionChecker;
import org.apache.hadoop.hbase.util.hbck.TableIntegrityErrorHandler; import org.apache.hadoop.hbase.util.hbck.TableIntegrityErrorHandler;
import org.apache.hadoop.hbase.util.hbck.TableIntegrityErrorHandlerImpl; import org.apache.hadoop.hbase.util.hbck.TableIntegrityErrorHandlerImpl;
import org.apache.hadoop.hbase.util.hbck.TableLockChecker; import org.apache.hadoop.hbase.util.hbck.TableLockChecker;
import org.apache.hadoop.hbase.wal.WAL;
import org.apache.hadoop.hbase.wal.WALFactory;
import org.apache.hadoop.hbase.wal.WALSplitter; import org.apache.hadoop.hbase.wal.WALSplitter;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
@ -1214,17 +1219,26 @@ public class HBaseFsck extends Configured implements Closeable {
} }
/** /**
* This borrows code from MasterFileSystem.bootstrap() * This borrows code from MasterFileSystem.bootstrap(). Explicitly creates it's own WAL, so be
* sure to close it as well as the region when you're finished.
* *
* @return an open hbase:meta HRegion * @return an open hbase:meta HRegion
*/ */
private HRegion createNewMeta() throws IOException { private HRegion createNewMeta() throws IOException {
Path rootdir = FSUtils.getRootDir(getConf()); Path rootdir = FSUtils.getRootDir(getConf());
Configuration c = getConf(); Configuration c = getConf();
HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO); HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO);
HTableDescriptor metaDescriptor = new FSTableDescriptors(c).get(TableName.META_TABLE_NAME); HTableDescriptor metaDescriptor = new FSTableDescriptors(c).get(TableName.META_TABLE_NAME);
MasterFileSystem.setInfoFamilyCachingForMeta(metaDescriptor, false); MasterFileSystem.setInfoFamilyCachingForMeta(metaDescriptor, false);
HRegion meta = HRegion.createHRegion(metaHRI, rootdir, c, metaDescriptor); // The WAL subsystem will use the default rootDir rather than the passed in rootDir
// unless I pass along via the conf.
Configuration confForWAL = new Configuration(c);
confForWAL.set(HConstants.HBASE_DIR, rootdir.toString());
WAL wal = (new WALFactory(confForWAL,
Collections.<WALActionsListener>singletonList(new MetricsWAL()),
"hbck-meta-recovery-" + RandomStringUtils.randomNumeric(8))).
getWAL(metaHRI.getEncodedNameAsBytes());
HRegion meta = HRegion.createHRegion(metaHRI, rootdir, c, metaDescriptor, wal);
MasterFileSystem.setInfoFamilyCachingForMeta(metaDescriptor, true); MasterFileSystem.setInfoFamilyCachingForMeta(metaDescriptor, true);
return meta; return meta;
} }
@ -1282,8 +1296,8 @@ public class HBaseFsck extends Configured implements Closeable {
} }
/** /**
* Rebuilds meta from information in hdfs/fs. Depends on configuration * Rebuilds meta from information in hdfs/fs. Depends on configuration settings passed into
* settings passed into hbck constructor to point to a particular fs/dir. * hbck constructor to point to a particular fs/dir. Assumes HBase is OFFLINE.
* *
* @param fix flag that determines if method should attempt to fix holes * @param fix flag that determines if method should attempt to fix holes
* @return true if successful, false if attempt failed. * @return true if successful, false if attempt failed.
@ -1339,7 +1353,10 @@ public class HBaseFsck extends Configured implements Closeable {
return false; return false;
} }
meta.batchMutate(puts.toArray(new Put[puts.size()])); meta.batchMutate(puts.toArray(new Put[puts.size()]));
HRegion.closeHRegion(meta); meta.close();
if (meta.getWAL() != null) {
meta.getWAL().close();
}
LOG.info("Success! hbase:meta table rebuilt."); LOG.info("Success! hbase:meta table rebuilt.");
LOG.info("Old hbase:meta is moved into " + backupDir); LOG.info("Old hbase:meta is moved into " + backupDir);
return true; return true;

View File

@ -213,7 +213,7 @@ public class HBaseFsckRepair {
HRegion region = HRegion.createHRegion(hri, root, conf, htd, null); HRegion region = HRegion.createHRegion(hri, root, conf, htd, null);
// Close the new region to flush to disk. Close log file too. // Close the new region to flush to disk. Close log file too.
HRegion.closeHRegion(region); region.close();
return region; return region;
} }
} }

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService; import java.util.concurrent.CompletionService;
@ -32,8 +33,10 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
@ -41,6 +44,10 @@ import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.master.AssignmentManager; import org.apache.hadoop.hbase.master.AssignmentManager;
import org.apache.hadoop.hbase.regionserver.wal.MetricsWAL;
import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
import org.apache.hadoop.hbase.wal.WAL;
import org.apache.hadoop.hbase.wal.WALFactory;
/** /**
* Utility methods for interacting with the regions. * Utility methods for interacting with the regions.
@ -60,21 +67,6 @@ public abstract class ModifyRegionUtils {
void editRegion(final HRegionInfo region) throws IOException; void editRegion(final HRegionInfo region) throws IOException;
} }
/**
* Create new set of regions on the specified file-system.
* NOTE: that you should add the regions to hbase:meta after this operation.
*
* @param conf {@link Configuration}
* @param rootDir Root directory for HBase instance
* @param hTableDescriptor description of the table
* @param newRegions {@link HRegionInfo} that describes the regions to create
* @throws IOException
*/
public static List<HRegionInfo> createRegions(final Configuration conf, final Path rootDir,
final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions) throws IOException {
return createRegions(conf, rootDir, hTableDescriptor, newRegions, null);
}
/** /**
* Create new set of regions on the specified file-system. * Create new set of regions on the specified file-system.
* NOTE: that you should add the regions to hbase:meta after this operation. * NOTE: that you should add the regions to hbase:meta after this operation.
@ -89,32 +81,12 @@ public abstract class ModifyRegionUtils {
public static List<HRegionInfo> createRegions(final Configuration conf, final Path rootDir, public static List<HRegionInfo> createRegions(final Configuration conf, final Path rootDir,
final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions, final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions,
final RegionFillTask task) throws IOException { final RegionFillTask task) throws IOException {
Path tableDir = FSUtils.getTableDir(rootDir, hTableDescriptor.getTableName());
return createRegions(conf, rootDir, tableDir, hTableDescriptor, newRegions, task);
}
/**
* Create new set of regions on the specified file-system.
* NOTE: that you should add the regions to hbase:meta after this operation.
*
* @param conf {@link Configuration}
* @param rootDir Root directory for HBase instance
* @param tableDir table directory
* @param hTableDescriptor description of the table
* @param newRegions {@link HRegionInfo} that describes the regions to create
* @param task {@link RegionFillTask} custom code to populate region after creation
* @throws IOException
*/
public static List<HRegionInfo> createRegions(final Configuration conf, final Path rootDir,
final Path tableDir, final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions,
final RegionFillTask task) throws IOException {
if (newRegions == null) return null; if (newRegions == null) return null;
int regionNumber = newRegions.length; int regionNumber = newRegions.length;
ThreadPoolExecutor exec = getRegionOpenAndInitThreadPool(conf, ThreadPoolExecutor exec = getRegionOpenAndInitThreadPool(conf,
"RegionOpenAndInitThread-" + hTableDescriptor.getTableName(), regionNumber); "RegionOpenAndInitThread-" + hTableDescriptor.getTableName(), regionNumber);
try { try {
return createRegions(exec, conf, rootDir, tableDir, hTableDescriptor, newRegions, task); return createRegions(exec, conf, rootDir, hTableDescriptor, newRegions, task);
} finally { } finally {
exec.shutdownNow(); exec.shutdownNow();
} }
@ -127,14 +99,13 @@ public abstract class ModifyRegionUtils {
* @param exec Thread Pool Executor * @param exec Thread Pool Executor
* @param conf {@link Configuration} * @param conf {@link Configuration}
* @param rootDir Root directory for HBase instance * @param rootDir Root directory for HBase instance
* @param tableDir table directory
* @param hTableDescriptor description of the table * @param hTableDescriptor description of the table
* @param newRegions {@link HRegionInfo} that describes the regions to create * @param newRegions {@link HRegionInfo} that describes the regions to create
* @param task {@link RegionFillTask} custom code to populate region after creation * @param task {@link RegionFillTask} custom code to populate region after creation
* @throws IOException * @throws IOException
*/ */
public static List<HRegionInfo> createRegions(final ThreadPoolExecutor exec, public static List<HRegionInfo> createRegions(final ThreadPoolExecutor exec,
final Configuration conf, final Path rootDir, final Path tableDir, final Configuration conf, final Path rootDir,
final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions, final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions,
final RegionFillTask task) throws IOException { final RegionFillTask task) throws IOException {
if (newRegions == null) return null; if (newRegions == null) return null;
@ -146,7 +117,7 @@ public abstract class ModifyRegionUtils {
completionService.submit(new Callable<HRegionInfo>() { completionService.submit(new Callable<HRegionInfo>() {
@Override @Override
public HRegionInfo call() throws IOException { public HRegionInfo call() throws IOException {
return createRegion(conf, rootDir, tableDir, hTableDescriptor, newRegion, task); return createRegion(conf, rootDir, hTableDescriptor, newRegion, task);
} }
}); });
} }
@ -168,19 +139,24 @@ public abstract class ModifyRegionUtils {
* Create new set of regions on the specified file-system. * Create new set of regions on the specified file-system.
* @param conf {@link Configuration} * @param conf {@link Configuration}
* @param rootDir Root directory for HBase instance * @param rootDir Root directory for HBase instance
* @param tableDir table directory
* @param hTableDescriptor description of the table * @param hTableDescriptor description of the table
* @param newRegion {@link HRegionInfo} that describes the region to create * @param newRegion {@link HRegionInfo} that describes the region to create
* @param task {@link RegionFillTask} custom code to populate region after creation * @param task {@link RegionFillTask} custom code to populate region after creation
* @throws IOException * @throws IOException
*/ */
public static HRegionInfo createRegion(final Configuration conf, final Path rootDir, public static HRegionInfo createRegion(final Configuration conf, final Path rootDir,
final Path tableDir, final HTableDescriptor hTableDescriptor, final HRegionInfo newRegion, final HTableDescriptor hTableDescriptor, final HRegionInfo newRegion,
final RegionFillTask task) throws IOException { final RegionFillTask task) throws IOException {
// 1. Create HRegion // 1. Create HRegion
HRegion region = HRegion.createHRegion(newRegion, // The WAL subsystem will use the default rootDir rather than the passed in rootDir
rootDir, tableDir, conf, hTableDescriptor, null, // unless I pass along via the conf.
false, true); Configuration confForWAL = new Configuration(conf);
confForWAL.set(HConstants.HBASE_DIR, rootDir.toString());
WAL wal = (new WALFactory(confForWAL,
Collections.<WALActionsListener>singletonList(new MetricsWAL()),
"hregion-" + RandomStringUtils.randomNumeric(8))).
getWAL(newRegion.getEncodedNameAsBytes());
HRegion region = HRegion.createHRegion(newRegion, rootDir, conf, hTableDescriptor, wal, false);
try { try {
// 2. Custom user code to interact with the created region // 2. Custom user code to interact with the created region
if (task != null) { if (task != null) {
@ -189,6 +165,7 @@ public abstract class ModifyRegionUtils {
} finally { } finally {
// 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();
wal.close();
} }
return region.getRegionInfo(); return region.getRegionInfo();
} }

View File

@ -62,7 +62,7 @@ import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
* server.</li> * server.</li>
* </ul> * </ul>
* *
* Alternatively, you may provide a custome implementation of {@link WALProvider} by class name. * Alternatively, you may provide a custom implementation of {@link WALProvider} by class name.
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public class WALFactory { public class WALFactory {

View File

@ -149,9 +149,8 @@ public abstract class HBaseTestCase extends TestCase {
} }
/** /**
* You must call close on the returned region and then close on the log file * You must call close on the returned region and then close on the log file it created. Do
* it created. Do {@link HRegion#close()} followed by {@link HRegion#getWAL()} * {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} to close both the region and the WAL.
* and on it call close.
* @param desc * @param desc
* @param startKey * @param startKey
* @param endKey * @param endKey
@ -168,7 +167,7 @@ public abstract class HBaseTestCase extends TestCase {
byte [] endKey, Configuration conf) byte [] endKey, Configuration conf)
throws IOException { throws IOException {
HRegionInfo hri = new HRegionInfo(desc.getTableName(), startKey, endKey); HRegionInfo hri = new HRegionInfo(desc.getTableName(), startKey, endKey);
return HRegion.createHRegion(hri, testDir, conf, desc); return HBaseTestingUtility.createRegionAndWAL(hri, testDir, conf, desc);
} }
protected HRegion openClosedRegion(final HRegion closedRegion) protected HRegion openClosedRegion(final HRegion closedRegion)
@ -641,12 +640,12 @@ public abstract class HBaseTestCase extends TestCase {
*/ */
protected void createMetaRegion() throws IOException { protected void createMetaRegion() throws IOException {
FSTableDescriptors fsTableDescriptors = new FSTableDescriptors(conf); FSTableDescriptors fsTableDescriptors = new FSTableDescriptors(conf);
meta = HRegion.createHRegion(HRegionInfo.FIRST_META_REGIONINFO, testDir, meta = HBaseTestingUtility.createRegionAndWAL(HRegionInfo.FIRST_META_REGIONINFO, testDir,
conf, fsTableDescriptors.get(TableName.META_TABLE_NAME) ); conf, fsTableDescriptors.get(TableName.META_TABLE_NAME));
} }
protected void closeRootAndMeta() throws IOException { protected void closeRootAndMeta() throws IOException {
HRegion.closeHRegion(meta); HBaseTestingUtility.closeRegionAndWAL(meta);
} }
public static void assertByteEquals(byte[] expected, public static void assertByteEquals(byte[] expected,

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.hbase; package org.apache.hadoop.hbase;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Jdk14Logger; import org.apache.commons.logging.impl.Jdk14Logger;
@ -62,6 +63,8 @@ import org.apache.hadoop.hbase.regionserver.HStore;
import org.apache.hadoop.hbase.regionserver.InternalScanner; import org.apache.hadoop.hbase.regionserver.InternalScanner;
import org.apache.hadoop.hbase.regionserver.RegionServerServices; import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException; import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException;
import org.apache.hadoop.hbase.regionserver.wal.MetricsWAL;
import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.tool.Canary; import org.apache.hadoop.hbase.tool.Canary;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
@ -75,6 +78,7 @@ import org.apache.hadoop.hbase.util.RegionSplitter;
import org.apache.hadoop.hbase.util.RetryCounter; import org.apache.hadoop.hbase.util.RetryCounter;
import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.WAL; import org.apache.hadoop.hbase.wal.WAL;
import org.apache.hadoop.hbase.wal.WALFactory;
import org.apache.hadoop.hbase.zookeeper.EmptyWatcher; import org.apache.hadoop.hbase.zookeeper.EmptyWatcher;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster; import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
import org.apache.hadoop.hbase.zookeeper.ZKConfig; import org.apache.hadoop.hbase.zookeeper.ZKConfig;
@ -124,7 +128,7 @@ import static org.junit.Assert.fail;
* Create an instance and keep it around testing HBase. This class is * Create an instance and keep it around testing HBase. This class is
* meant to be your one-stop shop for anything you might need testing. Manages * meant to be your one-stop shop for anything you might need testing. Manages
* one cluster at a time only. Managed cluster can be an in-process * one cluster at a time only. Managed cluster can be an in-process
* {@link MiniHBaseCluster}, or a deployed cluster of type {@link DistributedHBaseCluster}. * {@link MiniHBaseCluster}, or a deployed cluster of type {@code DistributedHBaseCluster}.
* Not all methods work with the real cluster. * Not all methods work with the real cluster.
* Depends on log4j being on classpath and * Depends on log4j being on classpath and
* hbase-site.xml for logging and test-run configuration. It does not set * hbase-site.xml for logging and test-run configuration. It does not set
@ -276,6 +280,16 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
return htu; return htu;
} }
/**
* Close both the HRegion {@code r} and it's underlying WAL. For use in tests.
*/
public static void closeRegionAndWAL(final HRegion r) throws IOException {
if (r == null) return;
r.close();
if (r.getWAL() == null) return;
r.getWAL().close();
}
/** /**
* Returns this classes's instance of {@link Configuration}. Be careful how * Returns this classes's instance of {@link Configuration}. Be careful how
* you use the returned Configuration since {@link HConnection} instances * you use the returned Configuration since {@link HConnection} instances
@ -1692,13 +1706,6 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
public static final byte [] START_KEY_BYTES = {FIRST_CHAR, FIRST_CHAR, FIRST_CHAR}; public static final byte [] START_KEY_BYTES = {FIRST_CHAR, FIRST_CHAR, FIRST_CHAR};
public static final String START_KEY = new String(START_KEY_BYTES, HConstants.UTF8_CHARSET); public static final String START_KEY = new String(START_KEY_BYTES, HConstants.UTF8_CHARSET);
/**
* Create a table of name <code>name</code> with {@link COLUMNS} for
* families.
* @param name Name to give table.
* @param versions How many versions to allow per column.
* @return Column descriptor.
*/
public HTableDescriptor createTableDescriptor(final String name, public HTableDescriptor createTableDescriptor(final String name,
final int minVersions, final int versions, final int ttl, KeepDeletedCells keepDeleted) { final int minVersions, final int versions, final int ttl, KeepDeletedCells keepDeleted) {
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name)); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name));
@ -1715,8 +1722,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
} }
/** /**
* Create a table of name <code>name</code> with {@link COLUMNS} for * Create a table of name <code>name</code>.
* families.
* @param name Name to give table. * @param name Name to give table.
* @return Column descriptor. * @return Column descriptor.
*/ */
@ -1741,14 +1747,11 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
} }
/** /**
* Create an HRegion that writes to the local tmp dirs * Create an HRegion that writes to the local tmp dirs. Creates the WAL for you. Be sure to call
* @param info * {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} when you're finished with it.
* @param desc
* @return
* @throws IOException
*/ */
public HRegion createLocalHRegion(HRegionInfo info, HTableDescriptor desc) throws IOException { public HRegion createLocalHRegion(HRegionInfo info, HTableDescriptor desc) throws IOException {
return HRegion.createHRegion(info, getDataTestDir(), getConfiguration(), desc); return createRegionAndWAL(info, getDataTestDir(), getConfiguration(), desc);
} }
/** /**
@ -1774,7 +1777,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
* @param families * @param families
* @throws IOException * @throws IOException
* @return A region on which you must call * @return A region on which you must call
* {@link HRegion#closeHRegion(HRegion)} when done. {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} when done.
*/ */
public HRegion createLocalHRegion(byte[] tableName, byte[] startKey, byte[] stopKey, public HRegion createLocalHRegion(byte[] tableName, byte[] startKey, byte[] stopKey,
String callingMethod, Configuration conf, boolean isReadOnly, Durability durability, String callingMethod, Configuration conf, boolean isReadOnly, Durability durability,
@ -2108,6 +2111,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
* Return an md5 digest of the entire contents of a table. * Return an md5 digest of the entire contents of a table.
*/ */
public String checksumRows(final Table table) throws Exception { public String checksumRows(final Table table) throws Exception {
Scan scan = new Scan(); Scan scan = new Scan();
ResultScanner results = table.getScanner(scan); ResultScanner results = table.getScanner(scan);
MessageDigest digest = MessageDigest.getInstance("MD5"); MessageDigest digest = MessageDigest.getInstance("MD5");
@ -2291,6 +2295,41 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
return newRegions; return newRegions;
} }
/**
* Create an unmanaged WAL. Be sure to close it when you're through.
*/
public static WAL createWal(final Configuration conf, final Path rootDir, final HRegionInfo hri)
throws IOException {
// The WAL subsystem will use the default rootDir rather than the passed in rootDir
// unless I pass along via the conf.
Configuration confForWAL = new Configuration(conf);
confForWAL.set(HConstants.HBASE_DIR, rootDir.toString());
return (new WALFactory(confForWAL,
Collections.<WALActionsListener>singletonList(new MetricsWAL()),
"hregion-" + RandomStringUtils.randomNumeric(8))).
getWAL(hri.getEncodedNameAsBytes());
}
/**
* Create a region with it's own WAL. Be sure to call
* {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} to clean up all resources.
*/
public static HRegion createRegionAndWAL(final HRegionInfo info, final Path rootDir,
final Configuration conf, final HTableDescriptor htd) throws IOException {
return createRegionAndWAL(info, rootDir, conf, htd, true);
}
/**
* Create a region with it's own WAL. Be sure to call
* {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} to clean up all resources.
*/
public static HRegion createRegionAndWAL(final HRegionInfo info, final Path rootDir,
final Configuration conf, final HTableDescriptor htd, boolean initialize)
throws IOException {
WAL wal = createWal(conf, rootDir, info);
return HRegion.createHRegion(info, rootDir, conf, htd, wal, initialize);
}
/** /**
* Returns all rows from the hbase:meta table. * Returns all rows from the hbase:meta table.
* *
@ -2888,7 +2927,6 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
/** /**
* Waits for a table to be 'enabled'. Enabled means that table is set as 'enabled' and the * Waits for a table to be 'enabled'. Enabled means that table is set as 'enabled' and the
* regions have been all assigned. Will timeout after default period (30 seconds) * regions have been all assigned. Will timeout after default period (30 seconds)
* @see #waitTableAvailable(byte[])
* @param table Table to wait on. * @param table Table to wait on.
* @param table * @param table
* @throws InterruptedException * @throws InterruptedException
@ -2907,7 +2945,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
/** /**
* Waits for a table to be 'enabled'. Enabled means that table is set as 'enabled' and the * Waits for a table to be 'enabled'. Enabled means that table is set as 'enabled' and the
* regions have been all assigned. * regions have been all assigned.
* @see #waitTableAvailable(byte[]) * @see #waitTableEnabled(Admin, byte[], long)
* @param table Table to wait on. * @param table Table to wait on.
* @param timeoutMillis Time to wait on it being marked enabled. * @param timeoutMillis Time to wait on it being marked enabled.
* @throws InterruptedException * @throws InterruptedException
@ -2960,7 +2998,6 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
/** /**
* Waits for a table to be 'disabled'. Disabled means that table is set as 'disabled' * Waits for a table to be 'disabled'. Disabled means that table is set as 'disabled'
* @see #waitTableAvailable(byte[])
* @param table Table to wait on. * @param table Table to wait on.
* @param timeoutMillis Time to wait on it being marked disabled. * @param timeoutMillis Time to wait on it being marked disabled.
* @throws InterruptedException * @throws InterruptedException
@ -3619,9 +3656,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
htd.addFamily(hcd); htd.addFamily(hcd);
HRegionInfo info = HRegionInfo info =
new HRegionInfo(TableName.valueOf(tableName), null, null, false); new HRegionInfo(TableName.valueOf(tableName), null, null, false);
HRegion region = return createRegionAndWAL(info, getDataTestDir(), getConfiguration(), htd);
HRegion.createHRegion(info, getDataTestDir(), getConfiguration(), htd);
return region;
} }
public void setFileSystemURI(String fsURI) { public void setFileSystemURI(String fsURI) {

View File

@ -60,8 +60,8 @@ public class TestIntraRowPagination {
HColumnDescriptor hcd = new HColumnDescriptor(family); HColumnDescriptor hcd = new HColumnDescriptor(family);
htd.addFamily(hcd); htd.addFamily(hcd);
} }
HRegion region = HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(), TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
try { try {
Put put; Put put;
Scan scan; Scan scan;
@ -101,7 +101,7 @@ public class TestIntraRowPagination {
TestScannersFromClientSide.verifyResult(result, kvListExp, toLog, TestScannersFromClientSide.verifyResult(result, kvListExp, toLog,
"Testing scan with storeOffset and storeLimit"); "Testing scan with storeOffset and storeLimit");
} finally { } finally {
region.close(); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }

View File

@ -350,6 +350,7 @@ public class TestCoprocessorInterface {
// hence the old entry was indeed removed by the GC and new one has been created // hence the old entry was indeed removed by the GC and new one has been created
Object o3 = ((CoprocessorII)c2).getSharedData().get("test2"); Object o3 = ((CoprocessorII)c2).getSharedData().get("test2");
assertFalse(o3 == o2); assertFalse(o3 == o2);
HBaseTestingUtility.closeRegionAndWAL(region);
} }
@Test @Test
@ -374,7 +375,7 @@ public class TestCoprocessorInterface {
for (int i = 0; i < regions.length; i++) { for (int i = 0; i < regions.length; i++) {
regions[i] = reopenRegion(regions[i], CoprocessorImpl.class); regions[i] = reopenRegion(regions[i], CoprocessorImpl.class);
} }
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
Coprocessor c = region.getCoprocessorHost(). Coprocessor c = region.getCoprocessorHost().
findCoprocessor(CoprocessorImpl.class.getName()); findCoprocessor(CoprocessorImpl.class.getName());
@ -394,7 +395,7 @@ public class TestCoprocessorInterface {
assertTrue(((CoprocessorImpl)c).wasSplit()); assertTrue(((CoprocessorImpl)c).wasSplit());
for (int i = 0; i < regions.length; i++) { for (int i = 0; i < regions.length; i++) {
HRegion.closeHRegion(regions[i]); HBaseTestingUtility.closeRegionAndWAL(regions[i]);
c = region.getCoprocessorHost() c = region.getCoprocessorHost()
.findCoprocessor(CoprocessorImpl.class.getName()); .findCoprocessor(CoprocessorImpl.class.getName());
assertTrue("Coprocessor not started", ((CoprocessorImpl)c).wasStarted()); assertTrue("Coprocessor not started", ((CoprocessorImpl)c).wasStarted());
@ -441,7 +442,7 @@ public class TestCoprocessorInterface {
} }
HRegionInfo info = new HRegionInfo(tableName, null, null, false); HRegionInfo info = new HRegionInfo(tableName, null, null, false);
Path path = new Path(DIR + callingMethod); Path path = new Path(DIR + callingMethod);
HRegion r = HRegion.createHRegion(info, path, conf, htd); HRegion r = HBaseTestingUtility.createRegionAndWAL(info, path, conf, htd);
// this following piece is a hack. // this following piece is a hack.
RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf); RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf);

View File

@ -42,7 +42,6 @@ import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.IsolationLevel; import org.apache.hadoop.hbase.client.IsolationLevel;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
@ -151,7 +150,8 @@ public class TestRegionObserverScannerOpenHook {
} }
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
Path path = new Path(DIR + callingMethod); Path path = new Path(DIR + callingMethod);
HRegion r = HRegion.createHRegion(info, path, conf, htd); WAL wal = HBaseTestingUtility.createWal(conf, path, info);
HRegion r = HRegion.createHRegion(info, path, conf, htd, wal);
// this following piece is a hack. currently a coprocessorHost // this following piece is a hack. currently a coprocessorHost
// is secretly loaded at OpenRegionHandler. we don't really // is secretly loaded at OpenRegionHandler. we don't really
// start a region server here, so just manually create cphost // start a region server here, so just manually create cphost
@ -183,6 +183,7 @@ public class TestRegionObserverScannerOpenHook {
assertNull( assertNull(
"Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: " "Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: "
+ r, r.listCells()); + r, r.listCells());
HBaseTestingUtility.closeRegionAndWAL(region);
} }
@Test @Test
@ -208,6 +209,7 @@ public class TestRegionObserverScannerOpenHook {
assertNull( assertNull(
"Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: " "Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: "
+ r, r.listCells()); + r, r.listCells());
HBaseTestingUtility.closeRegionAndWAL(region);
} }
/* /*

View File

@ -102,7 +102,7 @@ public class TestRegionObserverStacking extends TestCase {
} }
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
Path path = new Path(DIR + callingMethod); Path path = new Path(DIR + callingMethod);
HRegion r = HRegion.createHRegion(info, path, conf, htd); HRegion r = HBaseTestingUtility.createRegionAndWAL(info, path, conf, htd);
// this following piece is a hack. currently a coprocessorHost // this following piece is a hack. currently a coprocessorHost
// is secretly loaded at OpenRegionHandler. we don't really // is secretly loaded at OpenRegionHandler. we don't really
// start a region server here, so just manually create cphost // start a region server here, so just manually create cphost
@ -139,6 +139,7 @@ public class TestRegionObserverStacking extends TestCase {
assertTrue(idA < idB); assertTrue(idA < idB);
assertTrue(idB < idC); assertTrue(idB < idC);
HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }

View File

@ -51,8 +51,8 @@ public class TestColumnPrefixFilter {
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TestColumnPrefixFilter")); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TestColumnPrefixFilter"));
htd.addFamily((new HColumnDescriptor(family)).setMaxVersions(3)); htd.addFamily((new HColumnDescriptor(family)).setMaxVersions(3));
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
HRegion region = HRegion.createHRegion(info, TEST_UTIL. HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
getDataTestDir(), TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
try { try {
List<String> rows = generateRandomWords(100, "row"); List<String> rows = generateRandomWords(100, "row");
List<String> columns = generateRandomWords(10000, "column"); List<String> columns = generateRandomWords(10000, "column");
@ -101,10 +101,10 @@ public class TestColumnPrefixFilter {
assertEquals(prefixMap.get(s).size(), results.size()); assertEquals(prefixMap.get(s).size(), results.size());
} }
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
@Test @Test
@ -113,8 +113,8 @@ public class TestColumnPrefixFilter {
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TestColumnPrefixFilter")); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TestColumnPrefixFilter"));
htd.addFamily((new HColumnDescriptor(family)).setMaxVersions(3)); htd.addFamily((new HColumnDescriptor(family)).setMaxVersions(3));
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
HRegion region = HRegion.createHRegion(info, TEST_UTIL. HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
getDataTestDir(), TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
try { try {
List<String> rows = generateRandomWords(100, "row"); List<String> rows = generateRandomWords(100, "row");
List<String> columns = generateRandomWords(10000, "column"); List<String> columns = generateRandomWords(10000, "column");
@ -166,10 +166,10 @@ public class TestColumnPrefixFilter {
assertEquals(prefixMap.get(s).size(), results.size()); assertEquals(prefixMap.get(s).size(), results.size());
} }
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
List<String> generateRandomWords(int numberOfWords, String suffix) { List<String> generateRandomWords(int numberOfWords, String suffix) {

View File

@ -81,14 +81,14 @@ public class TestDependentColumnFilter {
hcd1.setMaxVersions(3); hcd1.setMaxVersions(3);
htd.addFamily(hcd1); htd.addFamily(hcd1);
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
this.region = HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(), this.region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
addData(); addData();
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
} }
private void addData() throws IOException { private void addData() throws IOException {

View File

@ -142,8 +142,8 @@ public class TestFilter {
htd.addFamily(new HColumnDescriptor(NEW_FAMILIES[0])); htd.addFamily(new HColumnDescriptor(NEW_FAMILIES[0]));
htd.addFamily(new HColumnDescriptor(NEW_FAMILIES[1])); htd.addFamily(new HColumnDescriptor(NEW_FAMILIES[1]));
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
this.region = HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(), this.region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
// Insert first half // Insert first half
for(byte [] ROW : ROWS_ONE) { for(byte [] ROW : ROWS_ONE) {
@ -217,9 +217,7 @@ public class TestFilter {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
WAL wal = region.getWAL(); HBaseTestingUtility.closeRegionAndWAL(region);
region.close();
wal.close();
} }
@Test @Test
@ -656,8 +654,7 @@ public class TestFilter {
/** /**
* Tests the the {@link WhileMatchFilter} works in combination with a * Tests the the {@link WhileMatchFilter} works in combination with a
* {@link Filter} that uses the * {@link Filter} that uses the {@link Filter#filterKeyValue(Cell)} method.
* {@link Filter#filterKeyValue(org.apache.hadoop.hbase.KeyValue)} method.
* *
* See HBASE-2258. * See HBASE-2258.
* *
@ -1453,7 +1450,7 @@ public class TestFilter {
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TestFilter")); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TestFilter"));
htd.addFamily(new HColumnDescriptor(family)); htd.addFamily(new HColumnDescriptor(family));
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
HRegion testRegion = HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(), HRegion testRegion = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
for(int i=0; i<5; i++) { for(int i=0; i<5; i++) {
@ -2007,13 +2004,14 @@ public class TestFilter {
} }
} }
// TODO: intentionally disabled?
public void testNestedFilterListWithSCVF() throws IOException { public void testNestedFilterListWithSCVF() throws IOException {
byte[] columnStatus = Bytes.toBytes("S"); byte[] columnStatus = Bytes.toBytes("S");
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("testNestedFilterListWithSCVF")); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("testNestedFilterListWithSCVF"));
htd.addFamily(new HColumnDescriptor(FAMILIES[0])); htd.addFamily(new HColumnDescriptor(FAMILIES[0]));
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
HRegion testRegion = HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(), HRegion testRegion = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
for(int i=0; i<10; i++) { for(int i=0; i<10; i++) {
Put p = new Put(Bytes.toBytes("row" + i)); Put p = new Put(Bytes.toBytes("row" + i));
p.setDurability(Durability.SKIP_WAL); p.setDurability(Durability.SKIP_WAL);

View File

@ -68,7 +68,7 @@ public class TestInvocationRecordFilter {
TableName.valueOf(TABLE_NAME_BYTES)); TableName.valueOf(TABLE_NAME_BYTES));
htd.addFamily(new HColumnDescriptor(FAMILY_NAME_BYTES)); htd.addFamily(new HColumnDescriptor(FAMILY_NAME_BYTES));
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
this.region = HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(), this.region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
Put put = new Put(ROW_BYTES); Put put = new Put(ROW_BYTES);

View File

@ -54,8 +54,8 @@ public class TestMultipleColumnPrefixFilter {
htd.addFamily(hcd); htd.addFamily(hcd);
// HRegionInfo info = new HRegionInfo(htd, null, null, false); // HRegionInfo info = new HRegionInfo(htd, null, null, false);
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
HRegion region = HRegion.createHRegion(info, TEST_UTIL. HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.
getDataTestDir(), TEST_UTIL.getConfiguration(), htd); getDataTestDir(), TEST_UTIL.getConfiguration(), htd);
List<String> rows = generateRandomWords(100, "row"); List<String> rows = generateRandomWords(100, "row");
List<String> columns = generateRandomWords(10000, "column"); List<String> columns = generateRandomWords(10000, "column");
@ -105,7 +105,7 @@ public class TestMultipleColumnPrefixFilter {
while(scanner.next(results)); while(scanner.next(results));
assertEquals(prefixMap.get("p").size() + prefixMap.get("q").size(), results.size()); assertEquals(prefixMap.get("p").size() + prefixMap.get("q").size(), results.size());
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
@Test @Test
@ -120,8 +120,8 @@ public class TestMultipleColumnPrefixFilter {
hcd2.setMaxVersions(3); hcd2.setMaxVersions(3);
htd.addFamily(hcd2); htd.addFamily(hcd2);
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
HRegion region = HRegion.createHRegion(info, TEST_UTIL. HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.
getDataTestDir(), TEST_UTIL.getConfiguration(), htd); getDataTestDir(), TEST_UTIL.getConfiguration(), htd);
List<String> rows = generateRandomWords(100, "row"); List<String> rows = generateRandomWords(100, "row");
List<String> columns = generateRandomWords(10000, "column"); List<String> columns = generateRandomWords(10000, "column");
@ -177,7 +177,7 @@ public class TestMultipleColumnPrefixFilter {
while(scanner.next(results)); while(scanner.next(results));
assertEquals(prefixMap.get("p").size() + prefixMap.get("q").size(), results.size()); assertEquals(prefixMap.get("p").size() + prefixMap.get("q").size(), results.size());
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
@Test @Test
@ -186,8 +186,8 @@ public class TestMultipleColumnPrefixFilter {
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TestMultipleColumnPrefixFilter")); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TestMultipleColumnPrefixFilter"));
htd.addFamily(new HColumnDescriptor(family)); htd.addFamily(new HColumnDescriptor(family));
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
HRegion region = HRegion.createHRegion(info, TEST_UTIL. HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.
getDataTestDir(), TEST_UTIL.getConfiguration(),htd); getDataTestDir(), TEST_UTIL.getConfiguration(), htd);
List<String> rows = generateRandomWords(100, "row"); List<String> rows = generateRandomWords(100, "row");
List<String> columns = generateRandomWords(10000, "column"); List<String> columns = generateRandomWords(10000, "column");
@ -232,7 +232,7 @@ public class TestMultipleColumnPrefixFilter {
assertEquals(results1.size(), results2.size()); assertEquals(results1.size(), results2.size());
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
List<String> generateRandomWords(int numberOfWords, String suffix) { List<String> generateRandomWords(int numberOfWords, String suffix) {

View File

@ -74,12 +74,12 @@ public class TestPrefixTree {
htd.addFamily(new HColumnDescriptor(fam).setDataBlockEncoding(DataBlockEncoding.PREFIX_TREE)); htd.addFamily(new HColumnDescriptor(fam).setDataBlockEncoding(DataBlockEncoding.PREFIX_TREE));
HRegionInfo info = new HRegionInfo(tableName, null, null, false); HRegionInfo info = new HRegionInfo(tableName, null, null, false);
Path path = testUtil.getDataTestDir(getClass().getSimpleName()); Path path = testUtil.getDataTestDir(getClass().getSimpleName());
region = HRegion.createHRegion(info, path, testUtil.getConfiguration(), htd); region = HBaseTestingUtility.createRegionAndWAL(info, path, testUtil.getConfiguration(), htd);
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
region.close(true); HBaseTestingUtility.closeRegionAndWAL(region);
testUtil.cleanupTestDir(); testUtil.cleanupTestDir();
} }

View File

@ -99,7 +99,8 @@ public class TestScannerSelectionUsingKeyRange {
HTableDescriptor htd = new HTableDescriptor(TABLE); HTableDescriptor htd = new HTableDescriptor(TABLE);
htd.addFamily(hcd); htd.addFamily(hcd);
HRegionInfo info = new HRegionInfo(TABLE); HRegionInfo info = new HRegionInfo(TABLE);
HRegion region = HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(), conf, htd); HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(), conf,
htd);
for (int iFile = 0; iFile < NUM_FILES; ++iFile) { for (int iFile = 0; iFile < NUM_FILES; ++iFile) {
for (int iRow = 0; iRow < NUM_ROWS; ++iRow) { for (int iRow = 0; iRow < NUM_ROWS; ++iRow) {
@ -126,6 +127,6 @@ public class TestScannerSelectionUsingKeyRange {
assertEquals(0, results.size()); assertEquals(0, results.size());
Set<String> accessedFiles = cache.getCachedFileNamesForTest(); Set<String> accessedFiles = cache.getCachedFileNamesForTest();
assertEquals(expectedCount, accessedFiles.size()); assertEquals(expectedCount, accessedFiles.size());
region.close(); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }

View File

@ -107,7 +107,8 @@ public class TestScannerSelectionUsingTTL {
htd.addFamily(hcd); htd.addFamily(hcd);
HRegionInfo info = new HRegionInfo(TABLE); HRegionInfo info = new HRegionInfo(TABLE);
HRegion region = HRegion region =
HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(info.getEncodedName()), HBaseTestingUtility.createRegionAndWAL(info,
TEST_UTIL.getDataTestDir(info.getEncodedName()),
conf, htd); conf, htd);
long ts = EnvironmentEdgeManager.currentTime(); long ts = EnvironmentEdgeManager.currentTime();
@ -157,6 +158,6 @@ public class TestScannerSelectionUsingTTL {
region.compactStores(); region.compactStores();
} }
region.close(); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }

View File

@ -64,13 +64,13 @@ public class TestMasterFailover {
HRegion createRegion(final HRegionInfo hri, final Path rootdir, final Configuration c, HRegion createRegion(final HRegionInfo hri, final Path rootdir, final Configuration c,
final HTableDescriptor htd) final HTableDescriptor htd)
throws IOException { throws IOException {
HRegion r = HRegion.createHRegion(hri, rootdir, c, htd); HRegion r = HBaseTestingUtility.createRegionAndWAL(hri, rootdir, c, htd);
// The above call to create a region will create an wal file. Each // The above call to create a region will create an wal file. Each
// log file create will also create a running thread to do syncing. We need // log file create will also create a running thread to do syncing. We need
// to close out this log else we will have a running thread trying to sync // to close out this log else we will have a running thread trying to sync
// the file system continuously which is ugly when dfs is taken away at the // the file system continuously which is ugly when dfs is taken away at the
// end of the test. // end of the test.
HRegion.closeHRegion(r); HBaseTestingUtility.closeRegionAndWAL(r);
return r; return r;
} }

View File

@ -538,8 +538,9 @@ public class TestAtomicOperation {
final String tableName = "testPutAndCheckAndPut"; final String tableName = "testPutAndCheckAndPut";
Configuration conf = TEST_UTIL.getConfiguration(); Configuration conf = TEST_UTIL.getConfiguration();
conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class); conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class);
final MockHRegion region = (MockHRegion) TEST_UTIL.createLocalHRegion(Bytes.toBytes(tableName), HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName))
null, null, tableName, conf, false, Durability.SYNC_WAL, null, Bytes.toBytes(family)); .addFamily(new HColumnDescriptor(family));
final MockHRegion region = (MockHRegion) TEST_UTIL.createLocalHRegion(htd, null, null);
Put[] puts = new Put[1]; Put[] puts = new Put[1];
Put put = new Put(Bytes.toBytes("r1")); Put put = new Put(Bytes.toBytes("r1"));

View File

@ -90,7 +90,7 @@ public class TestBlocksRead extends HBaseTestCase {
} }
/** /**
* Callers must afterward call {@link HRegion#closeHRegion(HRegion)} * Callers must afterward call {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)}
* @param tableName * @param tableName
* @param callingMethod * @param callingMethod
* @param conf * @param conf
@ -112,7 +112,7 @@ public class TestBlocksRead extends HBaseTestCase {
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
Path path = new Path(DIR + callingMethod); Path path = new Path(DIR + callingMethod);
HRegion r = HRegion.createHRegion(info, path, conf, htd); HRegion r = HBaseTestingUtility.createRegionAndWAL(info, path, conf, htd);
blockCache = new CacheConfig(conf).getBlockCache(); blockCache = new CacheConfig(conf).getBlockCache();
return r; return r;
} }
@ -265,7 +265,7 @@ public class TestBlocksRead extends HBaseTestCase {
assertEquals(1, kvs.length); assertEquals(1, kvs.length);
verifyData(kvs[0], "row", "col5", 5); verifyData(kvs[0], "row", "col5", 5);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -374,7 +374,7 @@ public class TestBlocksRead extends HBaseTestCase {
verifyData(kvs[1], "row", "col2", 12); verifyData(kvs[1], "row", "col2", 12);
verifyData(kvs[2], "row", "col3", 13); verifyData(kvs[2], "row", "col3", 13);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -423,7 +423,7 @@ public class TestBlocksRead extends HBaseTestCase {
assertEquals(2 * BLOOM_TYPE.length, blocksEnd - blocksStart); assertEquals(2 * BLOOM_TYPE.length, blocksEnd - blocksStart);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -450,7 +450,7 @@ public class TestBlocksRead extends HBaseTestCase {
assertEquals(1, kvs.length); assertEquals(1, kvs.length);
verifyData(kvs[0], "row", "col99", 201); verifyData(kvs[0], "row", "col99", 201);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }

View File

@ -158,10 +158,10 @@ public class TestColumnSeeking {
assertTrue(KeyValueTestUtil.containsIgnoreMvccVersion(results, kvSet)); assertTrue(KeyValueTestUtil.containsIgnoreMvccVersion(results, kvSet));
} }
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -270,7 +270,7 @@ public class TestColumnSeeking {
assertTrue(KeyValueTestUtil.containsIgnoreMvccVersion(results, kvSet)); assertTrue(KeyValueTestUtil.containsIgnoreMvccVersion(results, kvSet));
} }
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
List<String> generateRandomWords(int numberOfWords, String suffix) { List<String> generateRandomWords(int numberOfWords, String suffix) {

View File

@ -97,8 +97,8 @@ public class TestDefaultCompactSelection extends TestCase {
final Configuration walConf = new Configuration(conf); final Configuration walConf = new Configuration(conf);
FSUtils.setRootDir(walConf, basedir); FSUtils.setRootDir(walConf, basedir);
wals = new WALFactory(walConf, null, id); wals = new WALFactory(walConf, null, id);
region = HRegion.createHRegion(info, basedir, conf, htd); region = HBaseTestingUtility.createRegionAndWAL(info, basedir, conf, htd);
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
Path tableDir = FSUtils.getTableDir(basedir, htd.getTableName()); Path tableDir = FSUtils.getTableDir(basedir, htd.getTableName());
region = new HRegion(tableDir, wals.getWAL(info.getEncodedNameAsBytes()), fs, conf, info, htd, region = new HRegion(tableDir, wals.getWAL(info.getEncodedNameAsBytes()), fs, conf, info, htd,
null); null);

View File

@ -29,6 +29,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseTestCase; import org.apache.hadoop.hbase.HBaseTestCase;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
@ -73,8 +74,8 @@ public class TestGetClosestAtOrBefore extends HBaseTestCase {
// Up flush size else we bind up when we use default catalog flush of 16k. // Up flush size else we bind up when we use default catalog flush of 16k.
fsTableDescriptors.get(TableName.META_TABLE_NAME).setMemStoreFlushSize(64 * 1024 * 1024); fsTableDescriptors.get(TableName.META_TABLE_NAME).setMemStoreFlushSize(64 * 1024 * 1024);
HRegion mr = HRegion.createHRegion(HRegionInfo.FIRST_META_REGIONINFO, HRegion mr = HBaseTestingUtility.createRegionAndWAL(HRegionInfo.FIRST_META_REGIONINFO,
rootdir, this.conf, fsTableDescriptors.get(TableName.META_TABLE_NAME)); rootdir, this.conf, fsTableDescriptors.get(TableName.META_TABLE_NAME));
try { try {
// Write rows for three tables 'A', 'B', and 'C'. // Write rows for three tables 'A', 'B', and 'C'.
for (char c = 'A'; c < 'D'; c++) { for (char c = 'A'; c < 'D'; c++) {
@ -136,14 +137,7 @@ public class TestGetClosestAtOrBefore extends HBaseTestCase {
findRow(mr, 'C', 46, -1); findRow(mr, 'C', 46, -1);
findRow(mr, 'C', 43, -1); findRow(mr, 'C', 43, -1);
} finally { } finally {
if (mr != null) { HBaseTestingUtility.closeRegionAndWAL(mr);
try {
mr.close();
} catch (Exception e) {
e.printStackTrace();
}
mr.getWAL().close();
}
} }
} }

View File

@ -50,6 +50,7 @@ import java.security.PrivilegedExceptionAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NavigableMap; import java.util.NavigableMap;
@ -127,8 +128,10 @@ import org.apache.hadoop.hbase.protobuf.generated.WALProtos.RegionEventDescripto
import org.apache.hadoop.hbase.regionserver.HRegion.RegionScannerImpl; import org.apache.hadoop.hbase.regionserver.HRegion.RegionScannerImpl;
import org.apache.hadoop.hbase.regionserver.HRegion.RowLock; import org.apache.hadoop.hbase.regionserver.HRegion.RowLock;
import org.apache.hadoop.hbase.regionserver.TestStore.FaultyFileSystem; import org.apache.hadoop.hbase.regionserver.TestStore.FaultyFileSystem;
import org.apache.hadoop.hbase.regionserver.wal.MetricsWAL;
import org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource; import org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource;
import org.apache.hadoop.hbase.regionserver.wal.HLogKey; import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
import org.apache.hadoop.hbase.regionserver.wal.WALUtil; import org.apache.hadoop.hbase.regionserver.wal.WALUtil;
import org.apache.hadoop.hbase.regionserver.wal.WALEdit; import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
import org.apache.hadoop.hbase.wal.DefaultWALProvider; import org.apache.hadoop.hbase.wal.DefaultWALProvider;
@ -253,7 +256,7 @@ public class TestHRegion {
// Close with something in memstore and something in the snapshot. Make sure all is cleared. // Close with something in memstore and something in the snapshot. Make sure all is cleared.
region.close(); region.close();
assertEquals(0, region.getMemstoreSize().get()); assertEquals(0, region.getMemstoreSize().get());
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/* /*
@ -305,7 +308,24 @@ public class TestHRegion {
} }
long sz = store.getFlushableSize(); long sz = store.getFlushableSize();
assertTrue("flushable size should be zero, but it is " + sz, sz == 0); assertTrue("flushable size should be zero, but it is " + sz, sz == 0);
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
}
/**
* Create a WAL outside of the usual helper in
* {@link HBaseTestingUtility#createWal(Configuration, Path, HRegionInfo)} because that method
* doesn't play nicely with FaultyFileSystem. Call this method before overriding
* {@code fs.file.impl}.
* @param callingMethod a unique component for the path, probably the name of the test method.
*/
private static WAL createWALCompatibleWithFaultyFileSystem(String callingMethod,
Configuration conf, byte[] tableName) throws IOException {
final Path logDir = TEST_UTIL.getDataTestDirOnTestFS(callingMethod + ".log");
final Configuration walConf = new Configuration(conf);
FSUtils.setRootDir(walConf, logDir);
return (new WALFactory(walConf,
Collections.<WALActionsListener>singletonList(new MetricsWAL()), callingMethod))
.getWAL(tableName);
} }
/** /**
@ -326,6 +346,8 @@ public class TestHRegion {
@Test (timeout=60000) @Test (timeout=60000)
public void testFlushSizeAccounting() throws Exception { public void testFlushSizeAccounting() throws Exception {
final Configuration conf = HBaseConfiguration.create(CONF); final Configuration conf = HBaseConfiguration.create(CONF);
final String callingMethod = name.getMethodName();
final WAL wal = createWALCompatibleWithFaultyFileSystem(callingMethod, conf, tableName);
// Only retry once. // Only retry once.
conf.setInt("hbase.hstore.flush.retries.number", 1); conf.setInt("hbase.hstore.flush.retries.number", 1);
final User user = final User user =
@ -342,7 +364,8 @@ public class TestHRegion {
HRegion region = null; HRegion region = null;
try { try {
// Initialize region // Initialize region
region = initHRegion(tableName, name.getMethodName(), conf, COLUMN_FAMILY_BYTES); region = initHRegion(tableName, null, null, callingMethod, conf, false,
Durability.SYNC_WAL, wal, COLUMN_FAMILY_BYTES);
long size = region.getMemstoreSize().get(); long size = region.getMemstoreSize().get();
Assert.assertEquals(0, size); Assert.assertEquals(0, size);
// Put one item into memstore. Measure the size of one item in memstore. // Put one item into memstore. Measure the size of one item in memstore.
@ -376,7 +399,7 @@ public class TestHRegion {
// Make sure our memory accounting is right. // Make sure our memory accounting is right.
Assert.assertEquals(sizeOfOnePut * 2, region.getMemstoreSize().get()); Assert.assertEquals(sizeOfOnePut * 2, region.getMemstoreSize().get());
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
return null; return null;
} }
@ -387,6 +410,8 @@ public class TestHRegion {
@Test (timeout=60000) @Test (timeout=60000)
public void testCloseWithFailingFlush() throws Exception { public void testCloseWithFailingFlush() throws Exception {
final Configuration conf = HBaseConfiguration.create(CONF); final Configuration conf = HBaseConfiguration.create(CONF);
final String callingMethod = name.getMethodName();
final WAL wal = createWALCompatibleWithFaultyFileSystem(callingMethod, conf, tableName);
// Only retry once. // Only retry once.
conf.setInt("hbase.hstore.flush.retries.number", 1); conf.setInt("hbase.hstore.flush.retries.number", 1);
final User user = final User user =
@ -403,7 +428,8 @@ public class TestHRegion {
HRegion region = null; HRegion region = null;
try { try {
// Initialize region // Initialize region
region = initHRegion(tableName, name.getMethodName(), conf, COLUMN_FAMILY_BYTES); region = initHRegion(tableName, null, null, callingMethod, conf, false,
Durability.SYNC_WAL, wal, COLUMN_FAMILY_BYTES);
long size = region.getMemstoreSize().get(); long size = region.getMemstoreSize().get();
Assert.assertEquals(0, size); Assert.assertEquals(0, size);
// Put one item into memstore. Measure the size of one item in memstore. // Put one item into memstore. Measure the size of one item in memstore.
@ -428,7 +454,7 @@ public class TestHRegion {
} finally { } finally {
// Make it so all writes succeed from here on out so can close clean // Make it so all writes succeed from here on out so can close clean
ffs.fault.set(false); ffs.fault.set(false);
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
return null; return null;
} }
@ -561,7 +587,7 @@ public class TestHRegion {
assertArrayEquals(Bytes.toBytes(i), CellUtil.cloneValue(kvs.get(0))); assertArrayEquals(Bytes.toBytes(i), CellUtil.cloneValue(kvs.get(0)));
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
wals.close(); wals.close();
} }
@ -619,7 +645,7 @@ public class TestHRegion {
} }
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
wals.close(); wals.close();
} }
@ -652,7 +678,7 @@ public class TestHRegion {
long seqId = region.replayRecoveredEditsIfAny(regiondir, maxSeqIdInStores, null, null); long seqId = region.replayRecoveredEditsIfAny(regiondir, maxSeqIdInStores, null, null);
assertEquals(minSeqId, seqId); assertEquals(minSeqId, seqId);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -717,7 +743,7 @@ public class TestHRegion {
region.getStores().keySet().toArray(new byte[0][])).size()); region.getStores().keySet().toArray(new byte[0][])).size());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
wals.close(); wals.close();
} }
@ -812,7 +838,7 @@ public class TestHRegion {
assertArrayEquals(Bytes.toBytes(i), value); assertArrayEquals(Bytes.toBytes(i), value);
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
wals.close(); wals.close();
} }
@ -931,7 +957,7 @@ public class TestHRegion {
assertArrayEquals(Bytes.toBytes(i), value); assertArrayEquals(Bytes.toBytes(i), value);
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
wals.close(); wals.close();
} }
@ -1051,7 +1077,7 @@ public class TestHRegion {
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1092,7 +1118,7 @@ public class TestHRegion {
} }
} finally { } finally {
if (this.region != null) { if (this.region != null) {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
} }
} }
done.set(true); done.set(true);
@ -1108,7 +1134,7 @@ public class TestHRegion {
} }
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1185,7 +1211,7 @@ public class TestHRegion {
assertEquals("Got back incorrect number of rows from scan: " + keyPrefix3, 0, assertEquals("Got back incorrect number of rows from scan: " + keyPrefix3, 0,
getNumberOfRows(keyPrefix3, value2, this.region)); getNumberOfRows(keyPrefix3, value2, this.region));
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1204,7 +1230,7 @@ public class TestHRegion {
} catch (IOException e) { } catch (IOException e) {
exceptionCaught = true; exceptionCaught = true;
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
assertTrue(exceptionCaught == true); assertTrue(exceptionCaught == true);
@ -1223,7 +1249,7 @@ public class TestHRegion {
} catch (IOException e) { } catch (IOException e) {
exceptionCaught = true; exceptionCaught = true;
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
assertTrue(exceptionCaught == true); assertTrue(exceptionCaught == true);
@ -1319,7 +1345,7 @@ public class TestHRegion {
} }
assertTrue(exception); assertTrue(exception);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1360,7 +1386,7 @@ public class TestHRegion {
metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 2, source); metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 2, source);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1412,7 +1438,7 @@ public class TestHRegion {
@Override @Override
public void run() { public void run() {
try { try {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -1448,7 +1474,7 @@ public class TestHRegion {
codes[i].getOperationStatusCode()); codes[i].getOperationStatusCode());
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1496,7 +1522,7 @@ public class TestHRegion {
metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source); metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
@ -1575,7 +1601,7 @@ public class TestHRegion {
.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new NullComparator(), put, true); .checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new NullComparator(), put, true);
assertTrue(res); assertTrue(res);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1609,7 +1635,7 @@ public class TestHRegion {
put, true); put, true);
assertEquals(false, res); assertEquals(false, res);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1642,7 +1668,7 @@ public class TestHRegion {
delete, true); delete, true);
assertEquals(true, res); assertEquals(true, res);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1737,7 +1763,7 @@ public class TestHRegion {
new BinaryComparator(val3), put, true); new BinaryComparator(val3), put, true);
assertEquals(true, res); assertEquals(true, res);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1784,7 +1810,7 @@ public class TestHRegion {
assertEquals(expected[i], actual[i]); assertEquals(expected[i], actual[i]);
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1804,7 +1830,7 @@ public class TestHRegion {
// expected exception. // expected exception.
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1881,7 +1907,7 @@ public class TestHRegion {
r = region.get(get); r = region.get(get);
assertEquals(0, r.size()); assertEquals(0, r.size());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1916,7 +1942,7 @@ public class TestHRegion {
Result r = region.get(get); Result r = region.get(get);
assertEquals(0, r.size()); assertEquals(0, r.size());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -1960,7 +1986,7 @@ public class TestHRegion {
} }
assertEquals("Family " + new String(family) + " does exist", true, ok); assertEquals("Family " + new String(family) + " does exist", true, ok);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2028,7 +2054,7 @@ public class TestHRegion {
result = region.get(get); result = region.get(get);
assertEquals(1, result.size()); assertEquals(1, result.size());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2067,7 +2093,7 @@ public class TestHRegion {
result = region.get(get); result = region.get(get);
assertEquals(0, result.size()); assertEquals(0, result.size());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2117,7 +2143,7 @@ public class TestHRegion {
assertTrue("LATEST_TIMESTAMP was not replaced with real timestamp", assertTrue("LATEST_TIMESTAMP was not replaced with real timestamp",
kv.getTimestamp() != HConstants.LATEST_TIMESTAMP); kv.getTimestamp() != HConstants.LATEST_TIMESTAMP);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
@ -2152,7 +2178,7 @@ public class TestHRegion {
} }
assertTrue("Should catch FailedSanityCheckException", caughtExcep); assertTrue("Should catch FailedSanityCheckException", caughtExcep);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2194,7 +2220,7 @@ public class TestHRegion {
s.next(results); s.next(results);
assertTrue(CellUtil.matchingRow(results.get(0), rowB)); assertTrue(CellUtil.matchingRow(results.get(0), rowB));
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2253,7 +2279,7 @@ public class TestHRegion {
assertArrayEquals(qual1, CellUtil.cloneQualifier(kv)); assertArrayEquals(qual1, CellUtil.cloneQualifier(kv));
assertArrayEquals(row, CellUtil.cloneRow(kv)); assertArrayEquals(row, CellUtil.cloneRow(kv));
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2293,7 +2319,7 @@ public class TestHRegion {
now = cell.getTimestamp(); now = cell.getTimestamp();
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2324,7 +2350,7 @@ public class TestHRegion {
} }
assertFalse(true); assertFalse(true);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2376,7 +2402,7 @@ public class TestHRegion {
res = region.get(g); res = region.get(g);
assertEquals(count, res.size()); assertEquals(count, res.size());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2395,7 +2421,7 @@ public class TestHRegion {
assertTrue(r.isEmpty()); assertTrue(r.isEmpty());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2438,14 +2464,14 @@ public class TestHRegion {
} finally { } finally {
for (int i = 0; i < subregions.length; i++) { for (int i = 0; i < subregions.length; i++) {
try { try {
HRegion.closeHRegion(subregions[i]); HBaseTestingUtility.closeRegionAndWAL(subregions[i]);
} catch (IOException e) { } catch (IOException e) {
// Ignore. // Ignore.
} }
} }
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2511,7 +2537,7 @@ public class TestHRegion {
assertTrue("Families could not be found in Region", false); assertTrue("Families could not be found in Region", false);
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2537,7 +2563,7 @@ public class TestHRegion {
} }
assertTrue("Families could not be found in Region", ok); assertTrue("Families could not be found in Region", ok);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2581,7 +2607,7 @@ public class TestHRegion {
is = (RegionScannerImpl) region.getScanner(scan); is = (RegionScannerImpl) region.getScanner(scan);
assertEquals(families.length - 1, ((RegionScannerImpl) is).storeHeap.getHeap().size()); assertEquals(families.length - 1, ((RegionScannerImpl) is).storeHeap.getHeap().size());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2618,7 +2644,7 @@ public class TestHRegion {
+ e.getMessage()); + e.getMessage());
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2684,7 +2710,7 @@ public class TestHRegion {
assertTrue(CellComparator.equalsIgnoreMvccVersion(expected2.get(i), res.get(i))); assertTrue(CellComparator.equalsIgnoreMvccVersion(expected2.get(i), res.get(i)));
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2743,7 +2769,7 @@ public class TestHRegion {
assertEquals(expected.get(i), actual.get(i)); assertEquals(expected.get(i), actual.get(i));
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2806,7 +2832,7 @@ public class TestHRegion {
assertTrue(CellComparator.equalsIgnoreMvccVersion(expected.get(i), actual.get(i))); assertTrue(CellComparator.equalsIgnoreMvccVersion(expected.get(i), actual.get(i)));
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2888,7 +2914,7 @@ public class TestHRegion {
assertTrue(CellComparator.equalsIgnoreMvccVersion(expected.get(i), actual.get(i))); assertTrue(CellComparator.equalsIgnoreMvccVersion(expected.get(i), actual.get(i)));
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -2949,7 +2975,7 @@ public class TestHRegion {
assertEquals(expected.get(i), actual.get(i)); assertEquals(expected.get(i), actual.get(i));
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3010,7 +3036,7 @@ public class TestHRegion {
assertTrue(CellComparator.equalsIgnoreMvccVersion(expected.get(i), actual.get(i))); assertTrue(CellComparator.equalsIgnoreMvccVersion(expected.get(i), actual.get(i)));
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3058,7 +3084,7 @@ public class TestHRegion {
assertEquals(false, s.next(results)); assertEquals(false, s.next(results));
assertEquals(0, results.size()); assertEquals(0, results.size());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3137,7 +3163,7 @@ public class TestHRegion {
assertTrue(CellComparator.equalsIgnoreMvccVersion(expected.get(i), actual.get(i))); assertTrue(CellComparator.equalsIgnoreMvccVersion(expected.get(i), actual.get(i)));
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3206,7 +3232,7 @@ public class TestHRegion {
assertFalse(s.next(results)); assertFalse(s.next(results));
assertEquals(results.size(), 0); assertEquals(results.size(), 0);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3301,7 +3327,7 @@ public class TestHRegion {
break; break;
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3395,7 +3421,7 @@ public class TestHRegion {
} }
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3434,7 +3460,7 @@ public class TestHRegion {
verifyData(regions[1], splitRow, numRows, qualifier, families); verifyData(regions[1], splitRow, numRows, qualifier, families);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3502,7 +3528,7 @@ public class TestHRegion {
verifyData(regions[1], splitRow, numRows, qualifier, families); verifyData(regions[1], splitRow, numRows, qualifier, families);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3574,7 +3600,7 @@ public class TestHRegion {
flushThread.join(); flushThread.join();
flushThread.checkNoError(); flushThread.checkNoError();
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3708,7 +3734,7 @@ public class TestHRegion {
flushThread.checkNoError(); flushThread.checkNoError();
} finally { } finally {
try { try {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
} catch (DroppedSnapshotException dse) { } catch (DroppedSnapshotException dse) {
// We could get this on way out because we interrupt the background flusher and it could // We could get this on way out because we interrupt the background flusher and it could
// fail anywhere causing a DSE over in the background flusher... only it is not properly // fail anywhere causing a DSE over in the background flusher... only it is not properly
@ -3735,11 +3761,11 @@ public class TestHRegion {
} }
/** /**
* Block until this thread has put at least one row. * Block calling thread until this instance of PutThread has put at least one row.
*/ */
public void waitForFirstPut() throws InterruptedException { public void waitForFirstPut() throws InterruptedException {
// wait until put thread actually puts some data // wait until put thread actually puts some data
while (numPutsFinished == 0) { while (isAlive() && numPutsFinished == 0) {
checkNoError(); checkNoError();
Thread.sleep(50); Thread.sleep(50);
} }
@ -3909,7 +3935,7 @@ public class TestHRegion {
} }
ctx.stop(); ctx.stop();
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3932,7 +3958,7 @@ public class TestHRegion {
g = new Get(row); g = new Get(row);
region.get(g); region.get(g);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -3971,7 +3997,7 @@ public class TestHRegion {
; ;
assertEquals(1L, res.size()); assertEquals(1L, res.size());
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -4032,7 +4058,7 @@ public class TestHRegion {
assertEquals(num_unique_rows, reader.getFilterEntries()); assertEquals(num_unique_rows, reader.getFilterEntries());
} }
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -4075,7 +4101,7 @@ public class TestHRegion {
checkOneCell(kvs[2], FAMILY, 0, 0, 2); checkOneCell(kvs[2], FAMILY, 0, 0, 2);
checkOneCell(kvs[3], FAMILY, 0, 0, 1); checkOneCell(kvs[3], FAMILY, 0, 0, 1);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -4118,7 +4144,7 @@ public class TestHRegion {
Cell[] keyValues = region.get(get).rawCells(); Cell[] keyValues = region.get(get).rawCells();
assertTrue(keyValues.length == 0); assertTrue(keyValues.length == 0);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -4228,7 +4254,7 @@ public class TestHRegion {
} }
} }
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }
@ -4246,11 +4272,10 @@ public class TestHRegion {
HRegionInfo hri = new HRegionInfo(htd.getTableName()); HRegionInfo hri = new HRegionInfo(htd.getTableName());
// Create a region and skip the initialization (like CreateTableHandler) // Create a region and skip the initialization (like CreateTableHandler)
HRegion region = HRegion.createHRegion(hri, rootDir, CONF, htd, null, false, true); HRegion region = HBaseTestingUtility.createRegionAndWAL(hri, rootDir, CONF, htd, false);
// HRegion region = TEST_UTIL.createLocalHRegion(hri, htd);
Path regionDir = region.getRegionFileSystem().getRegionDir(); Path regionDir = region.getRegionFileSystem().getRegionDir();
FileSystem fs = region.getRegionFileSystem().getFileSystem(); FileSystem fs = region.getRegionFileSystem().getFileSystem();
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
Path regionInfoFile = new Path(regionDir, HRegionFileSystem.REGION_INFO_FILE); Path regionInfoFile = new Path(regionDir, HRegionFileSystem.REGION_INFO_FILE);
@ -4261,7 +4286,7 @@ public class TestHRegion {
// Try to open the region // Try to open the region
region = HRegion.openHRegion(rootDir, hri, htd, null, CONF); region = HRegion.openHRegion(rootDir, hri, htd, null, CONF);
assertEquals(regionDir, region.getRegionFileSystem().getRegionDir()); assertEquals(regionDir, region.getRegionFileSystem().getRegionDir());
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
// Verify that the .regioninfo file is still there // Verify that the .regioninfo file is still there
assertTrue(HRegionFileSystem.REGION_INFO_FILE + " should be present in the region dir", assertTrue(HRegionFileSystem.REGION_INFO_FILE + " should be present in the region dir",
@ -4275,7 +4300,7 @@ public class TestHRegion {
region = HRegion.openHRegion(rootDir, hri, htd, null, CONF); region = HRegion.openHRegion(rootDir, hri, htd, null, CONF);
// region = TEST_UTIL.openHRegion(hri, htd); // region = TEST_UTIL.openHRegion(hri, htd);
assertEquals(regionDir, region.getRegionFileSystem().getRegionDir()); assertEquals(regionDir, region.getRegionFileSystem().getRegionDir());
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
// Verify that the .regioninfo file is still there // Verify that the .regioninfo file is still there
assertTrue(HRegionFileSystem.REGION_INFO_FILE + " should be present in the region dir", assertTrue(HRegionFileSystem.REGION_INFO_FILE + " should be present in the region dir",
@ -4621,7 +4646,7 @@ public class TestHRegion {
verify(wal, never()).sync(); verify(wal, never()).sync();
} }
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
@ -4652,8 +4677,8 @@ public class TestHRegion {
HRegion primaryRegion = null, secondaryRegion = null; HRegion primaryRegion = null, secondaryRegion = null;
try { try {
primaryRegion = HRegion.createHRegion(primaryHri, primaryRegion = HBaseTestingUtility.createRegionAndWAL(primaryHri,
rootDir, TEST_UTIL.getConfiguration(), htd); rootDir, TEST_UTIL.getConfiguration(), htd);
// load some data // load some data
putData(primaryRegion, 0, 1000, cq, families); putData(primaryRegion, 0, 1000, cq, families);
@ -4667,10 +4692,10 @@ public class TestHRegion {
verifyData(secondaryRegion, 0, 1000, cq, families); verifyData(secondaryRegion, 0, 1000, cq, families);
} finally { } finally {
if (primaryRegion != null) { if (primaryRegion != null) {
HRegion.closeHRegion(primaryRegion); HBaseTestingUtility.closeRegionAndWAL(primaryRegion);
} }
if (secondaryRegion != null) { if (secondaryRegion != null) {
HRegion.closeHRegion(secondaryRegion); HBaseTestingUtility.closeRegionAndWAL(secondaryRegion);
} }
} }
} }
@ -4702,8 +4727,8 @@ public class TestHRegion {
HRegion primaryRegion = null, secondaryRegion = null; HRegion primaryRegion = null, secondaryRegion = null;
try { try {
primaryRegion = HRegion.createHRegion(primaryHri, primaryRegion = HBaseTestingUtility.createRegionAndWAL(primaryHri,
rootDir, TEST_UTIL.getConfiguration(), htd); rootDir, TEST_UTIL.getConfiguration(), htd);
// load some data // load some data
putData(primaryRegion, 0, 1000, cq, families); putData(primaryRegion, 0, 1000, cq, families);
@ -4722,10 +4747,10 @@ public class TestHRegion {
} }
} finally { } finally {
if (primaryRegion != null) { if (primaryRegion != null) {
HRegion.closeHRegion(primaryRegion); HBaseTestingUtility.closeRegionAndWAL(primaryRegion);
} }
if (secondaryRegion != null) { if (secondaryRegion != null) {
HRegion.closeHRegion(secondaryRegion); HBaseTestingUtility.closeRegionAndWAL(secondaryRegion);
} }
} }
} }
@ -4755,8 +4780,8 @@ public class TestHRegion {
HRegion primaryRegion = null, secondaryRegion = null; HRegion primaryRegion = null, secondaryRegion = null;
try { try {
primaryRegion = HRegion.createHRegion(primaryHri, primaryRegion = HBaseTestingUtility.createRegionAndWAL(primaryHri,
rootDir, TEST_UTIL.getConfiguration(), htd); rootDir, TEST_UTIL.getConfiguration(), htd);
// load some data // load some data
putData(primaryRegion, 0, 1000, cq, families); putData(primaryRegion, 0, 1000, cq, families);
@ -4776,10 +4801,10 @@ public class TestHRegion {
verifyData(secondaryRegion, 0, 1000, cq, families); verifyData(secondaryRegion, 0, 1000, cq, families);
} finally { } finally {
if (primaryRegion != null) { if (primaryRegion != null) {
HRegion.closeHRegion(primaryRegion); HBaseTestingUtility.closeRegionAndWAL(primaryRegion);
} }
if (secondaryRegion != null) { if (secondaryRegion != null) {
HRegion.closeHRegion(secondaryRegion); HBaseTestingUtility.closeRegionAndWAL(secondaryRegion);
} }
} }
} }
@ -4930,9 +4955,9 @@ public class TestHRegion {
* @param families * @param families
* @throws IOException * @throws IOException
* @return A region on which you must call * @return A region on which you must call
* {@link HRegion#closeHRegion(HRegion)} when done. * {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} when done.
*/ */
public static HRegion initHRegion(TableName tableName, String callingMethod, Configuration conf, private static HRegion initHRegion(TableName tableName, String callingMethod, Configuration conf,
byte[]... families) throws IOException { byte[]... families) throws IOException {
return initHRegion(tableName.getName(), null, null, callingMethod, conf, false, families); return initHRegion(tableName.getName(), null, null, callingMethod, conf, false, families);
} }
@ -4944,9 +4969,9 @@ public class TestHRegion {
* @param families * @param families
* @throws IOException * @throws IOException
* @return A region on which you must call * @return A region on which you must call
* {@link HRegion#closeHRegion(HRegion)} when done. * {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} when done.
*/ */
public static HRegion initHRegion(byte[] tableName, String callingMethod, Configuration conf, private static HRegion initHRegion(byte[] tableName, String callingMethod, Configuration conf,
byte[]... families) throws IOException { byte[]... families) throws IOException {
return initHRegion(tableName, null, null, callingMethod, conf, false, families); return initHRegion(tableName, null, null, callingMethod, conf, false, families);
} }
@ -4959,9 +4984,9 @@ public class TestHRegion {
* @param families * @param families
* @throws IOException * @throws IOException
* @return A region on which you must call * @return A region on which you must call
* {@link HRegion#closeHRegion(HRegion)} when done. * {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} when done.
*/ */
public static HRegion initHRegion(byte[] tableName, String callingMethod, Configuration conf, private static HRegion initHRegion(byte[] tableName, String callingMethod, Configuration conf,
boolean isReadOnly, byte[]... families) throws IOException { boolean isReadOnly, byte[]... families) throws IOException {
return initHRegion(tableName, null, null, callingMethod, conf, isReadOnly, families); return initHRegion(tableName, null, null, callingMethod, conf, isReadOnly, families);
} }
@ -4969,8 +4994,11 @@ public class TestHRegion {
private static HRegion initHRegion(byte[] tableName, byte[] startKey, byte[] stopKey, private static HRegion initHRegion(byte[] tableName, byte[] startKey, byte[] stopKey,
String callingMethod, Configuration conf, boolean isReadOnly, byte[]... families) String callingMethod, Configuration conf, boolean isReadOnly, byte[]... families)
throws IOException { throws IOException {
Path logDir = TEST_UTIL.getDataTestDirOnTestFS(callingMethod + ".log");
HRegionInfo hri = new HRegionInfo(TableName.valueOf(tableName), startKey, stopKey);
final WAL wal = HBaseTestingUtility.createWal(conf, logDir, hri);
return initHRegion(tableName, startKey, stopKey, callingMethod, conf, isReadOnly, return initHRegion(tableName, startKey, stopKey, callingMethod, conf, isReadOnly,
Durability.SYNC_WAL, null, families); Durability.SYNC_WAL, wal, families);
} }
/** /**
@ -4983,7 +5011,7 @@ public class TestHRegion {
* @param families * @param families
* @throws IOException * @throws IOException
* @return A region on which you must call * @return A region on which you must call
* {@link HRegion#closeHRegion(HRegion)} when done. * {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} when done.
*/ */
private static HRegion initHRegion(byte[] tableName, byte[] startKey, byte[] stopKey, private static HRegion initHRegion(byte[] tableName, byte[] startKey, byte[] stopKey,
String callingMethod, Configuration conf, boolean isReadOnly, Durability durability, String callingMethod, Configuration conf, boolean isReadOnly, Durability durability,
@ -5060,7 +5088,7 @@ public class TestHRegion {
assertFalse(hasNext); assertFalse(hasNext);
scanner.close(); scanner.close();
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -5117,7 +5145,7 @@ public class TestHRegion {
assertFalse(hasNext); assertFalse(hasNext);
scanner.close(); scanner.close();
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -5171,7 +5199,7 @@ public class TestHRegion {
assertFalse(hasNext); assertFalse(hasNext);
scanner.close(); scanner.close();
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -5249,7 +5277,7 @@ public class TestHRegion {
assertTrue(Bytes.equals(currRow.get(0).getRow(), rowD)); assertTrue(Bytes.equals(currRow.get(0).getRow(), rowD));
scanner.close(); scanner.close();
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -5329,7 +5357,7 @@ public class TestHRegion {
assertTrue(Bytes.equals(currRow.get(0).getRow(), rowD)); assertTrue(Bytes.equals(currRow.get(0).getRow(), rowD));
scanner.close(); scanner.close();
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -5490,7 +5518,7 @@ public class TestHRegion {
scanner.close(); scanner.close();
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -5564,7 +5592,7 @@ public class TestHRegion {
assertTrue(Bytes.equals(currRow.get(0).getRow(), row1)); assertTrue(Bytes.equals(currRow.get(0).getRow(), row1));
assertFalse(hasNext); assertFalse(hasNext);
} finally { } finally {
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
} }
@ -5659,7 +5687,7 @@ public class TestHRegion {
assertEquals(verify, startRow - 1); assertEquals(verify, startRow - 1);
scanner.close(); scanner.close();
} finally { } finally {
HRegion.closeHRegion(this.region); this.region.close();
this.region = null; this.region = null;
} }
} }
@ -5686,7 +5714,7 @@ public class TestHRegion {
region.delete(new Delete(row)); region.delete(new Delete(row));
Assert.assertEquals(4L, region.getWriteRequestsCount()); Assert.assertEquals(4L, region.getWriteRequestsCount());
HRegion.closeHRegion(this.region); HBaseTestingUtility.closeRegionAndWAL(this.region);
this.region = null; this.region = null;
} }
@ -5706,14 +5734,14 @@ public class TestHRegion {
// open the region w/o rss and wal and flush some files // open the region w/o rss and wal and flush some files
HRegion region = HRegion region =
HRegion.createHRegion(hri, TEST_UTIL.getDataTestDir(), TEST_UTIL HBaseTestingUtility.createRegionAndWAL(hri, TEST_UTIL.getDataTestDir(), TEST_UTIL
.getConfiguration(), htd); .getConfiguration(), htd);
assertNotNull(region); assertNotNull(region);
// create a file in fam1 for the region before opening in OpenRegionHandler // create a file in fam1 for the region before opening in OpenRegionHandler
region.put(new Put(Bytes.toBytes("a")).add(fam1, fam1, fam1)); region.put(new Put(Bytes.toBytes("a")).add(fam1, fam1, fam1));
region.flushcache(); region.flushcache();
region.close(); HBaseTestingUtility.closeRegionAndWAL(region);
ArgumentCaptor<WALEdit> editCaptor = ArgumentCaptor.forClass(WALEdit.class); ArgumentCaptor<WALEdit> editCaptor = ArgumentCaptor.forClass(WALEdit.class);
@ -5757,7 +5785,7 @@ public class TestHRegion {
assertEquals(0, store.getStoreFileCount()); // no store files assertEquals(0, store.getStoreFileCount()); // no store files
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }
@ -5867,7 +5895,7 @@ public class TestHRegion {
} catch (Throwable e) { } catch (Throwable e) {
} }
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
region = null; region = null;
CONF.setLong("hbase.busy.wait.duration", defaultBusyWaitDuration); CONF.setLong("hbase.busy.wait.duration", defaultBusyWaitDuration);
} }
@ -5892,9 +5920,9 @@ public class TestHRegion {
Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
conf.setInt(HFile.FORMAT_VERSION_KEY, HFile.MIN_FORMAT_VERSION_WITH_TAGS); conf.setInt(HFile.FORMAT_VERSION_KEY, HFile.MIN_FORMAT_VERSION_WITH_TAGS);
HRegion region = HRegion.createHRegion(new HRegionInfo(htd.getTableName(), HRegion region = HBaseTestingUtility.createRegionAndWAL(new HRegionInfo(htd.getTableName(),
HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY), HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY),
TEST_UTIL.getDataTestDir(), conf, htd); TEST_UTIL.getDataTestDir(), conf, htd);
assertNotNull(region); assertNotNull(region);
try { try {
long now = EnvironmentEdgeManager.currentTime(); long now = EnvironmentEdgeManager.currentTime();
@ -5996,7 +6024,7 @@ public class TestHRegion {
assertNull(r.getValue(fam1, q1)); assertNull(r.getValue(fam1, q1));
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }

View File

@ -65,11 +65,11 @@ public class TestHRegionInfo {
Path basedir = htu.getDataTestDir(); Path basedir = htu.getDataTestDir();
// Create a region. That'll write the .regioninfo file. // Create a region. That'll write the .regioninfo file.
FSTableDescriptors fsTableDescriptors = new FSTableDescriptors(htu.getConfiguration()); FSTableDescriptors fsTableDescriptors = new FSTableDescriptors(htu.getConfiguration());
HRegion r = HRegion.createHRegion(hri, basedir, htu.getConfiguration(), HRegion r = HBaseTestingUtility.createRegionAndWAL(hri, basedir, htu.getConfiguration(),
fsTableDescriptors.get(TableName.META_TABLE_NAME)); fsTableDescriptors.get(TableName.META_TABLE_NAME));
// Get modtime on the file. // Get modtime on the file.
long modtime = getModTime(r); long modtime = getModTime(r);
HRegion.closeHRegion(r); HBaseTestingUtility.closeRegionAndWAL(r);
Thread.sleep(1001); Thread.sleep(1001);
r = HRegion.openHRegion(basedir, hri, fsTableDescriptors.get(TableName.META_TABLE_NAME), r = HRegion.openHRegion(basedir, hri, fsTableDescriptors.get(TableName.META_TABLE_NAME),
null, htu.getConfiguration()); null, htu.getConfiguration());
@ -80,6 +80,7 @@ public class TestHRegionInfo {
HRegionInfo deserializedHri = HRegionFileSystem.loadRegionInfoFileContent( HRegionInfo deserializedHri = HRegionFileSystem.loadRegionInfoFileContent(
r.getRegionFileSystem().getFileSystem(), r.getRegionFileSystem().getRegionDir()); r.getRegionFileSystem().getFileSystem(), r.getRegionFileSystem().getRegionDir());
assertTrue(hri.equals(deserializedHri)); assertTrue(hri.equals(deserializedHri));
HBaseTestingUtility.closeRegionAndWAL(r);
} }
long getModTime(final HRegion r) throws IOException { long getModTime(final HRegion r) throws IOException {

View File

@ -31,12 +31,8 @@ import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.MiniHBaseCluster;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
@ -176,26 +172,6 @@ public class TestJoinedScanners {
+ " seconds, got " + Long.toString(rows_count/2) + " rows"); + " seconds, got " + Long.toString(rows_count/2) + " rows");
} }
private static HRegion initHRegion(byte[] tableName, byte[] startKey, byte[] stopKey,
String callingMethod, Configuration conf, byte[]... families)
throws IOException {
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
for(byte [] family : families) {
HColumnDescriptor hcd = new HColumnDescriptor(family);
hcd.setDataBlockEncoding(DataBlockEncoding.FAST_DIFF);
htd.addFamily(hcd);
}
HRegionInfo info = new HRegionInfo(htd.getTableName(), startKey, stopKey, false);
Path path = new Path(DIR + callingMethod);
FileSystem fs = FileSystem.get(conf);
if (fs.exists(path)) {
if (!fs.delete(path, true)) {
throw new IOException("Failed delete of " + path);
}
}
return HRegion.createHRegion(info, path, conf, htd);
}
private static Options options = new Options(); private static Options options = new Options();
/** /**

View File

@ -179,7 +179,7 @@ public class TestKeepDeletes {
checkResult(r, c0, c0, T1); checkResult(r, c0, c0, T1);
assertEquals(0, countDeleteMarkers(region)); assertEquals(0, countDeleteMarkers(region));
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -229,7 +229,7 @@ public class TestKeepDeletes {
scan.next(kvs); scan.next(kvs);
assertTrue(kvs.isEmpty()); assertTrue(kvs.isEmpty());
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -274,7 +274,7 @@ public class TestKeepDeletes {
// major compaction deleted it // major compaction deleted it
assertEquals(0, countDeleteMarkers(region)); assertEquals(0, countDeleteMarkers(region));
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -298,7 +298,7 @@ public class TestKeepDeletes {
// ok! // ok!
} }
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -388,7 +388,7 @@ public class TestKeepDeletes {
assertTrue(CellUtil.isDelete(kvs.get(1))); assertTrue(CellUtil.isDelete(kvs.get(1)));
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -431,7 +431,7 @@ public class TestKeepDeletes {
region.compactStores(true); region.compactStores(true);
assertEquals(0, countDeleteMarkers(region)); assertEquals(0, countDeleteMarkers(region));
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -494,7 +494,7 @@ public class TestKeepDeletes {
region.compactStores(true); region.compactStores(true);
assertEquals(0, countDeleteMarkers(region)); assertEquals(0, countDeleteMarkers(region));
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -572,7 +572,7 @@ public class TestKeepDeletes {
region.compactStores(true); region.compactStores(true);
assertEquals(1, countDeleteMarkers(region)); assertEquals(1, countDeleteMarkers(region));
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -652,7 +652,7 @@ public class TestKeepDeletes {
checkGet(region, T2, c1, c0, ts+3, T2, T1); checkGet(region, T2, c1, c0, ts+3, T2, T1);
checkGet(region, T2, c1, c1, ts+3, T2, T1); checkGet(region, T2, c1, c1, ts+3, T2, T1);
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -747,7 +747,7 @@ public class TestKeepDeletes {
region.compactStores(true); region.compactStores(true);
assertEquals(1, countDeleteMarkers(region)); assertEquals(1, countDeleteMarkers(region));
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -797,7 +797,7 @@ public class TestKeepDeletes {
assertEquals(4, kvs.size()); assertEquals(4, kvs.size());
scanner.close(); scanner.close();
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -876,7 +876,7 @@ public class TestKeepDeletes {
region.compactStores(true); region.compactStores(true);
assertEquals(0, countDeleteMarkers(region)); assertEquals(0, countDeleteMarkers(region));
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
/** /**
@ -921,7 +921,7 @@ public class TestKeepDeletes {
// all delete marker gone // all delete marker gone
assertEquals(0, countDeleteMarkers(region)); assertEquals(0, countDeleteMarkers(region));
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
private void checkGet(HRegion region, byte[] row, byte[] fam, byte[] col, private void checkGet(HRegion region, byte[] row, byte[] fam, byte[] col,

View File

@ -105,7 +105,7 @@ public class TestMinVersions {
r = region.getClosestRowBefore(T2, c0); r = region.getClosestRowBefore(T2, c0);
checkResult(r, c0, T4); checkResult(r, c0, T4);
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }
@ -162,7 +162,7 @@ public class TestMinVersions {
r = region.get(g); // this'll use ExplicitColumnTracker r = region.get(g); // this'll use ExplicitColumnTracker
checkResult(r, c0, T3,T2,T1); checkResult(r, c0, T3,T2,T1);
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }
@ -221,7 +221,7 @@ public class TestMinVersions {
r = region.get(g); // this'll use ExplicitColumnTracker r = region.get(g); // this'll use ExplicitColumnTracker
checkResult(r, c0, T3); checkResult(r, c0, T3);
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }
@ -296,7 +296,7 @@ public class TestMinVersions {
r = region.get(g); // this'll use ExplicitColumnTracker r = region.get(g); // this'll use ExplicitColumnTracker
checkResult(r, c0, T5,T4); checkResult(r, c0, T5,T4);
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }
@ -388,7 +388,7 @@ public class TestMinVersions {
r = region.get(g); r = region.get(g);
assertTrue(r.isEmpty()); assertTrue(r.isEmpty());
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }
@ -463,7 +463,7 @@ public class TestMinVersions {
r = region.get(g); r = region.get(g);
checkResult(r, c0, T2); checkResult(r, c0, T2);
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }

View File

@ -285,7 +285,7 @@ public class TestMultiColumnScanner {
"pairs", lastDelTimeMap.size() > 0); "pairs", lastDelTimeMap.size() > 0);
LOG.info("Number of row/col pairs deleted at least once: " + LOG.info("Number of row/col pairs deleted at least once: " +
lastDelTimeMap.size()); lastDelTimeMap.size());
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
private static String getRowQualStr(Cell kv) { private static String getRowQualStr(Cell kv) {

View File

@ -65,8 +65,6 @@ import com.google.common.hash.Hashing;
public class TestPerColumnFamilyFlush { public class TestPerColumnFamilyFlush {
private static final Log LOG = LogFactory.getLog(TestPerColumnFamilyFlush.class); private static final Log LOG = LogFactory.getLog(TestPerColumnFamilyFlush.class);
HRegion region = null;
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Path DIR = TEST_UTIL.getDataTestDir("TestHRegion"); private static final Path DIR = TEST_UTIL.getDataTestDir("TestHRegion");
@ -82,14 +80,14 @@ public class TestPerColumnFamilyFlush {
public static final byte[] FAMILY3 = families[2]; public static final byte[] FAMILY3 = families[2];
private void initHRegion(String callingMethod, Configuration conf) throws IOException { private HRegion initHRegion(String callingMethod, Configuration conf) throws IOException {
HTableDescriptor htd = new HTableDescriptor(TABLENAME); HTableDescriptor htd = new HTableDescriptor(TABLENAME);
for (byte[] family : families) { for (byte[] family : families) {
htd.addFamily(new HColumnDescriptor(family)); htd.addFamily(new HColumnDescriptor(family));
} }
HRegionInfo info = new HRegionInfo(TABLENAME, null, null, false); HRegionInfo info = new HRegionInfo(TABLENAME, null, null, false);
Path path = new Path(DIR, callingMethod); Path path = new Path(DIR, callingMethod);
region = HRegion.createHRegion(info, path, conf, htd); return HBaseTestingUtility.createRegionAndWAL(info, path, conf, htd);
} }
// A helper function to create puts. // A helper function to create puts.
@ -129,7 +127,7 @@ public class TestPerColumnFamilyFlush {
conf.set(FlushPolicyFactory.HBASE_FLUSH_POLICY_KEY, FlushLargeStoresPolicy.class.getName()); conf.set(FlushPolicyFactory.HBASE_FLUSH_POLICY_KEY, FlushLargeStoresPolicy.class.getName());
conf.setLong(FlushLargeStoresPolicy.HREGION_COLUMNFAMILY_FLUSH_SIZE_LOWER_BOUND, 100 * 1024); conf.setLong(FlushLargeStoresPolicy.HREGION_COLUMNFAMILY_FLUSH_SIZE_LOWER_BOUND, 100 * 1024);
// Intialize the HRegion // Intialize the HRegion
initHRegion("testSelectiveFlushWhenEnabled", conf); HRegion region = initHRegion("testSelectiveFlushWhenEnabled", conf);
// Add 1200 entries for CF1, 100 for CF2 and 50 for CF3 // Add 1200 entries for CF1, 100 for CF2 and 50 for CF3
for (int i = 1; i <= 1200; i++) { for (int i = 1; i <= 1200; i++) {
region.put(createPut(1, i)); region.put(createPut(1, i));
@ -257,6 +255,7 @@ public class TestPerColumnFamilyFlush {
// Since we won't find any CF above the threshold, and hence no specific // Since we won't find any CF above the threshold, and hence no specific
// store to flush, we should flush all the memstores. // store to flush, we should flush all the memstores.
assertEquals(0, region.getMemstoreSize().get()); assertEquals(0, region.getMemstoreSize().get());
HBaseTestingUtility.closeRegionAndWAL(region);
} }
@Test (timeout=180000) @Test (timeout=180000)
@ -267,7 +266,7 @@ public class TestPerColumnFamilyFlush {
conf.set(FlushPolicyFactory.HBASE_FLUSH_POLICY_KEY, FlushAllStoresPolicy.class.getName()); conf.set(FlushPolicyFactory.HBASE_FLUSH_POLICY_KEY, FlushAllStoresPolicy.class.getName());
// Intialize the HRegion // Intialize the HRegion
initHRegion("testSelectiveFlushWhenNotEnabled", conf); HRegion region = initHRegion("testSelectiveFlushWhenNotEnabled", conf);
// Add 1200 entries for CF1, 100 for CF2 and 50 for CF3 // Add 1200 entries for CF1, 100 for CF2 and 50 for CF3
for (int i = 1; i <= 1200; i++) { for (int i = 1; i <= 1200; i++) {
region.put(createPut(1, i)); region.put(createPut(1, i));
@ -312,6 +311,7 @@ public class TestPerColumnFamilyFlush {
assertEquals(DefaultMemStore.DEEP_OVERHEAD, cf3MemstoreSize); assertEquals(DefaultMemStore.DEEP_OVERHEAD, cf3MemstoreSize);
assertEquals(0, totalMemstoreSize); assertEquals(0, totalMemstoreSize);
assertEquals(HConstants.NO_SEQNUM, smallestSeqInRegionCurrentMemstore); assertEquals(HConstants.NO_SEQNUM, smallestSeqInRegionCurrentMemstore);
HBaseTestingUtility.closeRegionAndWAL(region);
} }
// Find the (first) region which has the specified name. // Find the (first) region which has the specified name.
@ -585,7 +585,7 @@ public class TestPerColumnFamilyFlush {
table.close(); table.close();
conn.close(); conn.close();
region = getRegionWithName(TABLENAME).getFirst(); HRegion region = getRegionWithName(TABLENAME).getFirst();
cf1StoreFileCount1 = region.getStore(FAMILY1).getStorefilesCount(); cf1StoreFileCount1 = region.getStore(FAMILY1).getStorefilesCount();
cf2StoreFileCount1 = region.getStore(FAMILY2).getStorefilesCount(); cf2StoreFileCount1 = region.getStore(FAMILY2).getStorefilesCount();
cf3StoreFileCount1 = region.getStore(FAMILY3).getStorefilesCount(); cf3StoreFileCount1 = region.getStore(FAMILY3).getStorefilesCount();

View File

@ -248,7 +248,7 @@ public class TestRegionMergeTransaction {
assertEquals((rowCountOfRegionA + rowCountOfRegionB), assertEquals((rowCountOfRegionA + rowCountOfRegionB),
mergedRegionRowCount); mergedRegionRowCount);
} finally { } finally {
HRegion.closeHRegion(mergedRegion); HBaseTestingUtility.closeRegionAndWAL(mergedRegion);
} }
// Assert the write lock is no longer held on region_a and region_b // Assert the write lock is no longer held on region_a and region_b
assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread()); assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
@ -308,7 +308,7 @@ public class TestRegionMergeTransaction {
assertEquals((rowCountOfRegionA + rowCountOfRegionB), assertEquals((rowCountOfRegionA + rowCountOfRegionB),
mergedRegionRowCount); mergedRegionRowCount);
} finally { } finally {
HRegion.closeHRegion(mergedRegion); HBaseTestingUtility.closeRegionAndWAL(mergedRegion);
} }
// Assert the write lock is no longer held on region_a and region_b // Assert the write lock is no longer held on region_a and region_b
assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread()); assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
@ -412,9 +412,9 @@ public class TestRegionMergeTransaction {
HColumnDescriptor hcd = new HColumnDescriptor(CF); HColumnDescriptor hcd = new HColumnDescriptor(CF);
htd.addFamily(hcd); htd.addFamily(hcd);
HRegionInfo hri = new HRegionInfo(htd.getTableName(), startrow, endrow); HRegionInfo hri = new HRegionInfo(htd.getTableName(), startrow, endrow);
HRegion a = HRegion.createHRegion(hri, testdir, HRegion a = HBaseTestingUtility.createRegionAndWAL(hri, testdir,
TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
HRegion.closeHRegion(a); HBaseTestingUtility.closeRegionAndWAL(a);
return HRegion.openHRegion(testdir, hri, htd, wals.getWAL(hri.getEncodedNameAsBytes()), return HRegion.openHRegion(testdir, hri, htd, wals.getWAL(hri.getEncodedNameAsBytes()),
TEST_UTIL.getConfiguration()); TEST_UTIL.getConfiguration());
} }

View File

@ -69,7 +69,7 @@ public class TestResettingCounters {
throw new IOException("Failed delete of " + path); throw new IOException("Failed delete of " + path);
} }
} }
HRegion region = HRegion.createHRegion(hri, path, conf, htd); HRegion region = HBaseTestingUtility.createRegionAndWAL(hri, path, conf, htd);
try { try {
Increment odd = new Increment(rows[0]); Increment odd = new Increment(rows[0]);
odd.setDurability(Durability.SKIP_WAL); odd.setDurability(Durability.SKIP_WAL);
@ -100,9 +100,9 @@ public class TestResettingCounters {
assertEquals(6, Bytes.toLong(CellUtil.cloneValue(kvs[i]))); assertEquals(6, Bytes.toLong(CellUtil.cloneValue(kvs[i])));
} }
} finally { } finally {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
} }

View File

@ -31,19 +31,19 @@ import java.util.NavigableSet;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeepDeletedCells; import org.apache.hadoop.hbase.KeepDeletedCells;
import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil; import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Scan;
@ -308,12 +308,11 @@ public class TestReversibleScanners {
@Test @Test
public void testReversibleRegionScanner() throws IOException { public void testReversibleRegionScanner() throws IOException {
byte[] tableName = Bytes.toBytes("testtable");
byte[] FAMILYNAME2 = Bytes.toBytes("testCf2"); byte[] FAMILYNAME2 = Bytes.toBytes("testCf2");
Configuration conf = HBaseConfiguration.create(); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("testtable"))
HRegion region = TEST_UTIL.createLocalHRegion(tableName, null, null, .addFamily(new HColumnDescriptor(FAMILYNAME))
"testReversibleRegionScanner", conf, false, Durability.SYNC_WAL, null, .addFamily(new HColumnDescriptor(FAMILYNAME2));
FAMILYNAME, FAMILYNAME2); HRegion region = TEST_UTIL.createLocalHRegion(htd, null, null);
loadDataToRegion(region, FAMILYNAME2); loadDataToRegion(region, FAMILYNAME2);
// verify row count with forward scan // verify row count with forward scan

View File

@ -113,7 +113,7 @@ public class TestScanWithBloomError {
createStoreFile(new int[] {1, 9}); createStoreFile(new int[] {1, 9});
scanColSet(new int[]{1, 4, 6, 7}, new int[]{1, 6, 7}); scanColSet(new int[]{1, 4, 6, 7}, new int[]{1, 6, 7});
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
private void scanColSet(int[] colSet, int[] expectedResultCols) private void scanColSet(int[] colSet, int[] expectedResultCols)

View File

@ -162,7 +162,7 @@ public class TestScanner {
assertTrue(count > 10); assertTrue(count > 10);
s.close(); s.close();
} finally { } finally {
HRegion.closeHRegion(this.r); HBaseTestingUtility.closeRegionAndWAL(this.r);
} }
} }
@ -215,7 +215,7 @@ public class TestScanner {
rowInclusiveStopFilter(scan, stopRow); rowInclusiveStopFilter(scan, stopRow);
} finally { } finally {
HRegion.closeHRegion(this.r); HBaseTestingUtility.closeRegionAndWAL(this.r);
} }
} }
@ -242,7 +242,7 @@ public class TestScanner {
return; return;
} }
} finally { } finally {
HRegion.closeHRegion(this.r); HBaseTestingUtility.closeRegionAndWAL(this.r);
} }
} }
@ -355,7 +355,7 @@ public class TestScanner {
} finally { } finally {
// clean up // clean up
HRegion.closeHRegion(r); HBaseTestingUtility.closeRegionAndWAL(r);
} }
} }
@ -475,7 +475,7 @@ public class TestScanner {
LOG.error("Failed", e); LOG.error("Failed", e);
throw e; throw e;
} finally { } finally {
HRegion.closeHRegion(this.r); HBaseTestingUtility.closeRegionAndWAL(this.r);
} }
} }
@ -498,7 +498,7 @@ public class TestScanner {
LOG.error("Failed", e); LOG.error("Failed", e);
throw e; throw e;
} finally { } finally {
HRegion.closeHRegion(this.r); HBaseTestingUtility.closeRegionAndWAL(this.r);
} }
} }
@ -555,7 +555,7 @@ public class TestScanner {
assertTrue(CellUtil.matchingFamily(results.get(0), fam1)); assertTrue(CellUtil.matchingFamily(results.get(0), fam1));
assertTrue(CellUtil.matchingFamily(results.get(1), fam2)); assertTrue(CellUtil.matchingFamily(results.get(1), fam2));
} finally { } finally {
HRegion.closeHRegion(this.r); HBaseTestingUtility.closeRegionAndWAL(this.r);
} }
} }

View File

@ -439,7 +439,7 @@ public class TestSeekOptimizations {
@After @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
if (region != null) { if (region != null) {
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
} }
// We have to re-set the lazy seek flag back to the default so that other // We have to re-set the lazy seek flag back to the default so that other

View File

@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@ -248,7 +247,7 @@ public class TestSplitTransaction {
assertTrue(count > 0 && count != rowcount); assertTrue(count > 0 && count != rowcount);
daughtersRowCount += count; daughtersRowCount += count;
} finally { } finally {
HRegion.closeHRegion(openRegion); HBaseTestingUtility.closeRegionAndWAL(openRegion);
} }
} }
assertEquals(rowcount, daughtersRowCount); assertEquals(rowcount, daughtersRowCount);
@ -332,7 +331,7 @@ public class TestSplitTransaction {
assertTrue(count > 0 && count != rowcount); assertTrue(count > 0 && count != rowcount);
daughtersRowCount += count; daughtersRowCount += count;
} finally { } finally {
HRegion.closeHRegion(openRegion); HBaseTestingUtility.closeRegionAndWAL(openRegion);
} }
} }
assertEquals(rowcount, daughtersRowCount); assertEquals(rowcount, daughtersRowCount);
@ -376,8 +375,9 @@ public class TestSplitTransaction {
HColumnDescriptor hcd = new HColumnDescriptor(CF); HColumnDescriptor hcd = new HColumnDescriptor(CF);
htd.addFamily(hcd); htd.addFamily(hcd);
HRegionInfo hri = new HRegionInfo(htd.getTableName(), STARTROW, ENDROW); HRegionInfo hri = new HRegionInfo(htd.getTableName(), STARTROW, ENDROW);
HRegion r = HRegion.createHRegion(hri, testdir, TEST_UTIL.getConfiguration(), htd); HRegion r = HBaseTestingUtility.createRegionAndWAL(hri, testdir, TEST_UTIL.getConfiguration(),
HRegion.closeHRegion(r); htd);
HBaseTestingUtility.closeRegionAndWAL(r);
return HRegion.openHRegion(testdir, hri, htd, wals.getWAL(hri.getEncodedNameAsBytes()), return HRegion.openHRegion(testdir, hri, htd, wals.getWAL(hri.getEncodedNameAsBytes()),
TEST_UTIL.getConfiguration()); TEST_UTIL.getConfiguration());
} }

View File

@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseTestCase; import org.apache.hadoop.hbase.HBaseTestCase;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests;
@ -138,7 +139,7 @@ public class TestWideScanner extends HBaseTestCase {
s.close(); s.close();
} finally { } finally {
HRegion.closeHRegion(this.r); HBaseTestingUtility.closeRegionAndWAL(this.r);
} }
} }

View File

@ -37,7 +37,6 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.lang.mutable.MutableBoolean; import org.apache.commons.lang.mutable.MutableBoolean;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -68,10 +67,6 @@ import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.DefaultWALProvider; import org.apache.hadoop.hbase.wal.DefaultWALProvider;
import org.apache.hadoop.hbase.wal.WAL; import org.apache.hadoop.hbase.wal.WAL;
import org.apache.hadoop.hbase.wal.WALKey; import org.apache.hadoop.hbase.wal.WALKey;
import org.apache.hadoop.hdfs.DFSClient;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.namenode.LeaseManager;
import org.apache.log4j.Level;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
@ -395,7 +390,7 @@ public class TestFSHLog {
* flush. The addition of the sync over HRegion in flush should fix an issue where flush was * flush. The addition of the sync over HRegion in flush should fix an issue where flush was
* returning before all of its appends had made it out to the WAL (HBASE-11109). * returning before all of its appends had made it out to the WAL (HBASE-11109).
* @throws IOException * @throws IOException
* @see HBASE-11109 * @see <a href="https://issues.apache.org/jira/browse/HBASE-11109">HBASE-11109</a>
*/ */
@Test @Test
public void testFlushSequenceIdIsGreaterThanAllEditsInHFile() throws IOException { public void testFlushSequenceIdIsGreaterThanAllEditsInHFile() throws IOException {
@ -405,9 +400,9 @@ public class TestFSHLog {
final byte[] rowName = tableName.getName(); final byte[] rowName = tableName.getName();
final HTableDescriptor htd = new HTableDescriptor(tableName); final HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor("f")); htd.addFamily(new HColumnDescriptor("f"));
HRegion r = HRegion.createHRegion(hri, TEST_UTIL.getDefaultRootDirPath(), HRegion r = HBaseTestingUtility.createRegionAndWAL(hri, TEST_UTIL.getDefaultRootDirPath(),
TEST_UTIL.getConfiguration(), htd); TEST_UTIL.getConfiguration(), htd);
HRegion.closeHRegion(r); HBaseTestingUtility.closeRegionAndWAL(r);
final int countPerFamily = 10; final int countPerFamily = 10;
final MutableBoolean goslow = new MutableBoolean(false); final MutableBoolean goslow = new MutableBoolean(false);
// subclass and doctor a method. // subclass and doctor a method.

View File

@ -57,7 +57,6 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.ResultScanner;
@ -273,7 +272,7 @@ public class TestWALReplay {
/** /**
* Tests for hbase-2727. * Tests for hbase-2727.
* @throws Exception * @throws Exception
* @see https://issues.apache.org/jira/browse/HBASE-2727 * @see <a href="https://issues.apache.org/jira/browse/HBASE-2727">HBASE-2727</a>
*/ */
@Test @Test
public void test2727() throws Exception { public void test2727() throws Exception {
@ -286,9 +285,8 @@ public class TestWALReplay {
deleteDir(basedir); deleteDir(basedir);
HTableDescriptor htd = createBasic3FamilyHTD(tableName); HTableDescriptor htd = createBasic3FamilyHTD(tableName);
HRegion region2 = HRegion.createHRegion(hri, HRegion region2 = HBaseTestingUtility.createRegionAndWAL(hri, hbaseRootDir, this.conf, htd);
hbaseRootDir, this.conf, htd); HBaseTestingUtility.closeRegionAndWAL(region2);
HRegion.closeHRegion(region2);
final byte [] rowName = tableName.getName(); final byte [] rowName = tableName.getName();
WAL wal1 = createWAL(this.conf); WAL wal1 = createWAL(this.conf);
@ -348,9 +346,8 @@ public class TestWALReplay {
final Path basedir = new Path(this.hbaseRootDir, tableName.getNameAsString()); final Path basedir = new Path(this.hbaseRootDir, tableName.getNameAsString());
deleteDir(basedir); deleteDir(basedir);
final HTableDescriptor htd = createBasic3FamilyHTD(tableName); final HTableDescriptor htd = createBasic3FamilyHTD(tableName);
HRegion region2 = HRegion.createHRegion(hri, HRegion region2 = HBaseTestingUtility.createRegionAndWAL(hri, hbaseRootDir, this.conf, htd);
hbaseRootDir, this.conf, htd); HBaseTestingUtility.closeRegionAndWAL(region2);
HRegion.closeHRegion(region2);
WAL wal = createWAL(this.conf); WAL wal = createWAL(this.conf);
HRegion region = HRegion.openHRegion(hri, htd, wal, this.conf); HRegion region = HRegion.openHRegion(hri, htd, wal, this.conf);
@ -415,9 +412,8 @@ public class TestWALReplay {
final Path basedir = new Path(this.hbaseRootDir, tableName.getNameAsString()); final Path basedir = new Path(this.hbaseRootDir, tableName.getNameAsString());
deleteDir(basedir); deleteDir(basedir);
final HTableDescriptor htd = createBasic3FamilyHTD(tableName); final HTableDescriptor htd = createBasic3FamilyHTD(tableName);
HRegion region2 = HRegion.createHRegion(hri, HRegion region2 = HBaseTestingUtility.createRegionAndWAL(hri, hbaseRootDir, this.conf, htd);
hbaseRootDir, this.conf, htd); HBaseTestingUtility.closeRegionAndWAL(region2);
HRegion.closeHRegion(region2);
WAL wal = createWAL(this.conf); WAL wal = createWAL(this.conf);
HRegion region = HRegion.openHRegion(hri, htd, wal, this.conf); HRegion region = HRegion.openHRegion(hri, htd, wal, this.conf);
@ -488,9 +484,8 @@ public class TestWALReplay {
final byte[] rowName = tableName.getName(); final byte[] rowName = tableName.getName();
final int countPerFamily = 10; final int countPerFamily = 10;
final HTableDescriptor htd = createBasic3FamilyHTD(tableName); final HTableDescriptor htd = createBasic3FamilyHTD(tableName);
HRegion region3 = HRegion.createHRegion(hri, HRegion region3 = HBaseTestingUtility.createRegionAndWAL(hri, hbaseRootDir, this.conf, htd);
hbaseRootDir, this.conf, htd); HBaseTestingUtility.closeRegionAndWAL(region3);
HRegion.closeHRegion(region3);
// Write countPerFamily edits into the three families. Do a flush on one // Write countPerFamily edits into the three families. Do a flush on one
// of the families during the load of edits so its seqid is not same as // of the families during the load of edits so its seqid is not same as
// others to test we do right thing when different seqids. // others to test we do right thing when different seqids.
@ -598,9 +593,8 @@ public class TestWALReplay {
final byte[] rowName = tableName.getName(); final byte[] rowName = tableName.getName();
final int countPerFamily = 10; final int countPerFamily = 10;
final HTableDescriptor htd = createBasic3FamilyHTD(tableName); final HTableDescriptor htd = createBasic3FamilyHTD(tableName);
HRegion region3 = HRegion.createHRegion(hri, HRegion region3 = HBaseTestingUtility.createRegionAndWAL(hri, hbaseRootDir, this.conf, htd);
hbaseRootDir, this.conf, htd); HBaseTestingUtility.closeRegionAndWAL(region3);
HRegion.closeHRegion(region3);
// Write countPerFamily edits into the three families. Do a flush on one // Write countPerFamily edits into the three families. Do a flush on one
// of the families during the load of edits so its seqid is not same as // of the families during the load of edits so its seqid is not same as
// others to test we do right thing when different seqids. // others to test we do right thing when different seqids.
@ -681,9 +675,8 @@ public class TestWALReplay {
final Path basedir = FSUtils.getTableDir(this.hbaseRootDir, tableName); final Path basedir = FSUtils.getTableDir(this.hbaseRootDir, tableName);
deleteDir(basedir); deleteDir(basedir);
final HTableDescriptor htd = createBasic3FamilyHTD(tableName); final HTableDescriptor htd = createBasic3FamilyHTD(tableName);
HRegion region3 = HRegion.createHRegion(hri, hbaseRootDir, this.conf, htd); HRegion region3 = HBaseTestingUtility.createRegionAndWAL(hri, hbaseRootDir, this.conf, htd);
region3.close(); HBaseTestingUtility.closeRegionAndWAL(region3);
region3.getWAL().close();
// Write countPerFamily edits into the three families. Do a flush on one // Write countPerFamily edits into the three families. Do a flush on one
// of the families during the load of edits so its seqid is not same as // of the families during the load of edits so its seqid is not same as
// others to test we do right thing when different seqids. // others to test we do right thing when different seqids.
@ -780,9 +773,8 @@ public class TestWALReplay {
deleteDir(basedir); deleteDir(basedir);
final HTableDescriptor htd = createBasic3FamilyHTD(tableName); final HTableDescriptor htd = createBasic3FamilyHTD(tableName);
HRegion region2 = HRegion.createHRegion(hri, HRegion region2 = HBaseTestingUtility.createRegionAndWAL(hri, hbaseRootDir, this.conf, htd);
hbaseRootDir, this.conf, htd); HBaseTestingUtility.closeRegionAndWAL(region2);
HRegion.closeHRegion(region2);
final WAL wal = createWAL(this.conf); final WAL wal = createWAL(this.conf);
final byte[] rowName = tableName.getName(); final byte[] rowName = tableName.getName();
final byte[] regionName = hri.getEncodedNameAsBytes(); final byte[] regionName = hri.getEncodedNameAsBytes();

View File

@ -31,9 +31,6 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.*; import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Durability; import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegion;
@ -143,7 +140,8 @@ public class TestMergeTable {
byte [] startKey, byte [] endKey, int firstRow, int nrows, Path rootdir) byte [] startKey, byte [] endKey, int firstRow, int nrows, Path rootdir)
throws IOException { throws IOException {
HRegionInfo hri = new HRegionInfo(desc.getTableName(), startKey, endKey); HRegionInfo hri = new HRegionInfo(desc.getTableName(), startKey, endKey);
HRegion region = HRegion.createHRegion(hri, rootdir, UTIL.getConfiguration(), desc); HRegion region = HBaseTestingUtility.createRegionAndWAL(hri, rootdir, UTIL.getConfiguration(),
desc);
LOG.info("Created region " + region.getRegionNameAsString()); LOG.info("Created region " + region.getRegionNameAsString());
for(int i = firstRow; i < firstRow + nrows; i++) { for(int i = firstRow; i < firstRow + nrows; i++) {
Put put = new Put(Bytes.toBytes("row_" + String.format("%1$05d", i))); Put put = new Put(Bytes.toBytes("row_" + String.format("%1$05d", i)));
@ -155,19 +153,19 @@ public class TestMergeTable {
region.flushcache(); region.flushcache();
} }
} }
HRegion.closeHRegion(region); HBaseTestingUtility.closeRegionAndWAL(region);
return region; return region;
} }
protected void setupMeta(Path rootdir, final HRegion [] regions) protected void setupMeta(Path rootdir, final HRegion [] regions)
throws IOException { throws IOException {
HRegion meta = HRegion meta =
HRegion.createHRegion(HRegionInfo.FIRST_META_REGIONINFO, rootdir, HBaseTestingUtility.createRegionAndWAL(HRegionInfo.FIRST_META_REGIONINFO, rootdir,
UTIL.getConfiguration(), UTIL.getMetaTableDescriptor()); UTIL.getConfiguration(), UTIL.getMetaTableDescriptor());
for (HRegion r: regions) { for (HRegion r: regions) {
HRegion.addRegionToMETA(meta, r); HRegion.addRegionToMETA(meta, r);
} }
HRegion.closeHRegion(meta); HBaseTestingUtility.closeRegionAndWAL(meta);
} }
} }

View File

@ -156,7 +156,8 @@ public class TestMergeTool extends HBaseTestCase {
*/ */
for (int i = 0; i < sourceRegions.length; i++) { for (int i = 0; i < sourceRegions.length; i++) {
regions[i] = regions[i] =
HRegion.createHRegion(this.sourceRegions[i], testDir, this.conf, this.desc); HBaseTestingUtility.createRegionAndWAL(this.sourceRegions[i], testDir, this.conf,
this.desc);
/* /*
* Insert data * Insert data
*/ */
@ -183,7 +184,7 @@ public class TestMergeTool extends HBaseTestCase {
for (int i = 0; i < sourceRegions.length; i++) { for (int i = 0; i < sourceRegions.length; i++) {
HRegion r = regions[i]; HRegion r = regions[i];
if (r != null) { if (r != null) {
HRegion.closeHRegion(r); HBaseTestingUtility.closeRegionAndWAL(r);
} }
} }
wals.close(); wals.close();
@ -272,7 +273,7 @@ public class TestMergeTool extends HBaseTestCase {
assertTrue(Bytes.equals(bytes, rows[i][j])); assertTrue(Bytes.equals(bytes, rows[i][j]));
} }
// Close the region and delete the log // Close the region and delete the log
HRegion.closeHRegion(regions[i]); HBaseTestingUtility.closeRegionAndWAL(regions[i]);
} }
WAL log = wals.getWAL(new byte[]{}); WAL log = wals.getWAL(new byte[]{});
// Merge Region 0 and Region 1 // Merge Region 0 and Region 1