You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ji...@apache.org on 2007/12/03 09:28:34 UTC
svn commit: r600443 - in /lucene/hadoop/trunk/src/contrib/hbase: CHANGES.txt
src/java/org/apache/hadoop/hbase/HTable.java
src/test/org/apache/hadoop/hbase/TestScanner2.java
Author: jimk
Date: Mon Dec 3 00:28:32 2007
New Revision: 600443
URL: http://svn.apache.org/viewvc?rev=600443&view=rev
Log:
HADOOP-2321 TestScanner2 does not release resources which sometimes cause the test to time out
Modified:
lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt
lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HTable.java
lucene/hadoop/trunk/src/contrib/hbase/src/test/org/apache/hadoop/hbase/TestScanner2.java
Modified: lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt?rev=600443&r1=600442&r2=600443&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt (original)
+++ lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt Mon Dec 3 00:28:32 2007
@@ -48,6 +48,8 @@
HADOOP-2320 Committed TestGet2 is managled (breaks build).
HADOOP-2322 getRow(row, TS) client interface not properly connected
HADOOP-2309 ConcurrentModificationException doing get of all region start keys
+ HADOOP-2321 TestScanner2 does not release resources which sometimes cause the
+ test to time out
IMPROVEMENTS
HADOOP-2401 Add convenience put method that takes writable
Modified: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HTable.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HTable.java?rev=600443&r1=600442&r2=600443&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HTable.java (original)
+++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HTable.java Mon Dec 3 00:28:32 2007
@@ -122,10 +122,12 @@
* other methods will throw an IllegalStateException
*/
public synchronized void close() {
- closed = true;
- tableServers = null;
- batch.set(null);
- connection.close(tableName);
+ if (!closed) {
+ closed = true;
+ tableServers = null;
+ batch.set(null);
+ connection.close(tableName);
+ }
}
/**
@@ -361,6 +363,7 @@
* Get all the data for the specified row at a specified timestamp
*
* @param row row key
+ * @param ts timestamp
* @return map of colums to values
* @throws IOException
*/
Modified: lucene/hadoop/trunk/src/contrib/hbase/src/test/org/apache/hadoop/hbase/TestScanner2.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/test/org/apache/hadoop/hbase/TestScanner2.java?rev=600443&r1=600442&r2=600443&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/src/test/org/apache/hadoop/hbase/TestScanner2.java (original)
+++ lucene/hadoop/trunk/src/contrib/hbase/src/test/org/apache/hadoop/hbase/TestScanner2.java Mon Dec 3 00:28:32 2007
@@ -78,14 +78,18 @@
Text tableName = new Text(getName());
createTable(new HBaseAdmin(this.conf), tableName);
HTable table = new HTable(this.conf, tableName);
- final String lastKey = "aac";
- addContent(new HTableIncommon(table), FIRST_COLKEY + ":");
- HScannerInterface scanner =
- table.obtainScanner(new Text [] {new Text(FIRST_COLKEY + ":")},
- HConstants.EMPTY_START_ROW, new Text(lastKey));
- for (Map.Entry<HStoreKey, SortedMap<Text, byte []>> e: scanner) {
- LOG.info(e.getKey());
- assertTrue(e.getKey().getRow().toString().compareTo(lastKey) < 0);
+ try {
+ final String lastKey = "aac";
+ addContent(new HTableIncommon(table), FIRST_COLKEY + ":");
+ HScannerInterface scanner =
+ table.obtainScanner(new Text [] {new Text(FIRST_COLKEY + ":")},
+ HConstants.EMPTY_START_ROW, new Text(lastKey));
+ for (Map.Entry<HStoreKey, SortedMap<Text, byte []>> e: scanner) {
+ LOG.info(e.getKey());
+ assertTrue(e.getKey().getRow().toString().compareTo(lastKey) < 0);
+ }
+ } finally {
+ table.close();
}
}
@@ -94,12 +98,16 @@
*/
public void testIterator() throws Exception {
HTable table = new HTable(this.conf, HConstants.ROOT_TABLE_NAME);
- HScannerInterface scanner =
- table.obtainScanner(HConstants.COLUMN_FAMILY_ARRAY,
- HConstants.EMPTY_START_ROW);
- for (Map.Entry<HStoreKey, SortedMap<Text, byte []>> e: scanner) {
- assertNotNull(e.getKey());
- assertNotNull(e.getValue());
+ try {
+ HScannerInterface scanner =
+ table.obtainScanner(HConstants.COLUMN_FAMILY_ARRAY,
+ HConstants.EMPTY_START_ROW);
+ for (Map.Entry<HStoreKey, SortedMap<Text, byte []>> e: scanner) {
+ assertNotNull(e.getKey());
+ assertNotNull(e.getValue());
+ }
+ } finally {
+ table.close();
}
}
@@ -114,18 +122,22 @@
Text tableName = new Text(getName());
createTable(admin, tableName);
HTable table = new HTable(this.conf, tableName);
- // Add a row to columns without qualifiers and then two with. Make one
- // numbers only so easy to find w/ a regex.
- long id = table.startUpdate(new Text(getName()));
- final String firstColkeyFamily = Character.toString(FIRST_COLKEY) + ":";
- table.put(id, new Text(firstColkeyFamily + getName()), GOOD_BYTES);
- table.put(id, new Text(firstColkeyFamily + "22222"), GOOD_BYTES);
- table.put(id, new Text(firstColkeyFamily), GOOD_BYTES);
- table.commit(id);
- // Now do a scan using a regex for a column name.
- checkRegexingScanner(table, firstColkeyFamily + "\\d+");
- // Do a new scan that only matches on column family.
- checkRegexingScanner(table, firstColkeyFamily + "$");
+ try {
+ // Add a row to columns without qualifiers and then two with. Make one
+ // numbers only so easy to find w/ a regex.
+ long id = table.startUpdate(new Text(getName()));
+ final String firstColkeyFamily = Character.toString(FIRST_COLKEY) + ":";
+ table.put(id, new Text(firstColkeyFamily + getName()), GOOD_BYTES);
+ table.put(id, new Text(firstColkeyFamily + "22222"), GOOD_BYTES);
+ table.put(id, new Text(firstColkeyFamily), GOOD_BYTES);
+ table.commit(id);
+ // Now do a scan using a regex for a column name.
+ checkRegexingScanner(table, firstColkeyFamily + "\\d+");
+ // Do a new scan that only matches on column family.
+ checkRegexingScanner(table, firstColkeyFamily + "$");
+ } finally {
+ table.close();
+ }
}
/*
@@ -170,18 +182,22 @@
// Enter data
HTable table = new HTable(conf, tableName);
- for (char i = FIRST_ROWKEY; i <= LAST_ROWKEY; i++) {
- Text rowKey = new Text(new String(new char[] { i }));
- long lockID = table.startUpdate(rowKey);
- for (char j = 0; j < colKeys.length; j++) {
- table.put(lockID, colKeys[j], (i >= FIRST_BAD_RANGE_ROWKEY &&
- i <= LAST_BAD_RANGE_ROWKEY)? BAD_BYTES : GOOD_BYTES);
+ try {
+ for (char i = FIRST_ROWKEY; i <= LAST_ROWKEY; i++) {
+ Text rowKey = new Text(new String(new char[] { i }));
+ long lockID = table.startUpdate(rowKey);
+ for (char j = 0; j < colKeys.length; j++) {
+ table.put(lockID, colKeys[j], (i >= FIRST_BAD_RANGE_ROWKEY &&
+ i <= LAST_BAD_RANGE_ROWKEY)? BAD_BYTES : GOOD_BYTES);
+ }
+ table.commit(lockID);
}
- table.commit(lockID);
+
+ regExpFilterTest(table, colKeys);
+ rowFilterSetTest(table, colKeys);
+ } finally {
+ table.close();
}
-
- regExpFilterTest(table, colKeys);
- rowFilterSetTest(table, colKeys);
}
/**
@@ -269,40 +285,43 @@
*/
public void testSplitDeleteOneAddTwoRegions() throws IOException {
HTable metaTable = new HTable(conf, HConstants.META_TABLE_NAME);
- // First add a new table. Its intial region will be added to META region.
- HBaseAdmin admin = new HBaseAdmin(conf);
- Text tableName = new Text(getName());
- admin.createTable(new HTableDescriptor(tableName.toString()));
- List<HRegionInfo> regions = scan(metaTable);
- assertEquals("Expected one region", 1, regions.size());
- HRegionInfo region = regions.get(0);
- assertTrue("Expected region named for test",
- region.getRegionName().toString().startsWith(getName()));
- // Now do what happens at split time; remove old region and then add two
- // new ones in its place.
- removeRegionFromMETA(new HTable(conf, HConstants.META_TABLE_NAME),
- region.getRegionName());
- HTableDescriptor desc = region.getTableDesc();
- Path homedir = new Path(getName());
- List<HRegion> newRegions = new ArrayList<HRegion>(2);
- newRegions.add(HRegion.createHRegion(
- new HRegionInfo(desc, null, new Text("midway")),
- homedir, this.conf, null));
- newRegions.add(HRegion.createHRegion(
- new HRegionInfo(desc, new Text("midway"), null),
- homedir, this.conf, null));
try {
- for (HRegion r : newRegions) {
- addRegionToMETA(metaTable, r, this.cluster.getHMasterAddress(),
- -1L);
+ // First add a new table. Its intial region will be added to META region.
+ HBaseAdmin admin = new HBaseAdmin(conf);
+ Text tableName = new Text(getName());
+ admin.createTable(new HTableDescriptor(tableName.toString()));
+ List<HRegionInfo> regions = scan(metaTable);
+ assertEquals("Expected one region", 1, regions.size());
+ HRegionInfo region = regions.get(0);
+ assertTrue("Expected region named for test",
+ region.getRegionName().toString().startsWith(getName()));
+ // Now do what happens at split time; remove old region and then add two
+ // new ones in its place.
+ removeRegionFromMETA(metaTable, region.getRegionName());
+ HTableDescriptor desc = region.getTableDesc();
+ Path homedir = new Path(getName());
+ List<HRegion> newRegions = new ArrayList<HRegion>(2);
+ newRegions.add(HRegion.createHRegion(
+ new HRegionInfo(desc, null, new Text("midway")),
+ homedir, this.conf, null));
+ newRegions.add(HRegion.createHRegion(
+ new HRegionInfo(desc, new Text("midway"), null),
+ homedir, this.conf, null));
+ try {
+ for (HRegion r : newRegions) {
+ addRegionToMETA(metaTable, r, this.cluster.getHMasterAddress(),
+ -1L);
+ }
+ regions = scan(metaTable);
+ assertEquals("Should be two regions only", 2, regions.size());
+ } finally {
+ for (HRegion r : newRegions) {
+ r.close();
+ r.getLog().closeAndDelete();
+ }
}
- regions = scan(metaTable);
- assertEquals("Should be two regions only", 2, regions.size());
} finally {
- for (HRegion r : newRegions) {
- r.close();
- r.getLog().closeAndDelete();
- }
+ metaTable.close();
}
}
@@ -388,17 +407,13 @@
*/
private void removeRegionFromMETA(final HTable t, final Text regionName)
throws IOException {
- try {
- long lockid = t.startUpdate(regionName);
- t.delete(lockid, HConstants.COL_REGIONINFO);
- t.delete(lockid, HConstants.COL_SERVER);
- t.delete(lockid, HConstants.COL_STARTCODE);
- t.commit(lockid);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Removed " + regionName + " from table " + t.getTableName());
- }
- } finally {
- t.close();
+ long lockid = t.startUpdate(regionName);
+ t.delete(lockid, HConstants.COL_REGIONINFO);
+ t.delete(lockid, HConstants.COL_SERVER);
+ t.delete(lockid, HConstants.COL_STARTCODE);
+ t.commit(lockid);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Removed " + regionName + " from table " + t.getTableName());
}
}
}