hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1215236 - in /hbase/trunk/src: main/java/org/apache/hadoop/hbase/master/ test/java/org/apache/hadoop/hbase/ test/java/org/apache/hadoop/hbase/client/ test/java/org/apache/hadoop/hbase/constraint/ test/java/org/apache/hadoop/hbase/mapreduce...
Date Fri, 16 Dec 2011 18:17:32 GMT
Author: tedyu
Date: Fri Dec 16 18:17:32 2011
New Revision: 1215236

URL: http://svn.apache.org/viewvc?rev=1215236&view=rev
Log:
HBASE-5051 HBaseTestingUtility#getHBaseAdmin() creates a new HBaseAdmin instance at each call
(N Keywal)

Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportExport.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFilesSplitRecovery.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestLogRollAbort.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Fri Dec 16 18:17:32
2011
@@ -1478,10 +1478,12 @@ implements HMasterInterface, HMasterRegi
         LOG.error("Error call master coprocessor preShutdown()", ioe);
       }
     }
-    this.assignmentManager.shutdown();
-    this.serverManager.shutdownCluster();
+    if (this.assignmentManager != null) this.assignmentManager.shutdown();
+    if (this.serverManager != null) this.serverManager.shutdownCluster();
     try {
-      this.clusterStatusTracker.setClusterDown();
+      if (this.clusterStatusTracker != null){
+        this.clusterStatusTracker.setClusterDown();
+      }
     } catch (KeeperException e) {
       LOG.error("ZooKeeper exception trying to set cluster as down in ZK", e);
     }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java Fri Dec 16
18:17:32 2011
@@ -579,8 +579,9 @@ public class HBaseTestingUtility {
     }
     s.close();
     t.close();
+
+    getHBaseAdmin(); // create immediately the hbaseAdmin
     LOG.info("Minicluster is up");
-    //getHBaseAdmin();
     return this.hbaseCluster;
   }
 
@@ -642,6 +643,10 @@ public class HBaseTestingUtility {
    * @throws IOException
    */
   public void shutdownMiniHBaseCluster() throws IOException {
+    if (hbaseAdmin != null) {
+      hbaseAdmin.close();
+      hbaseAdmin = null;
+    }
     if (this.hbaseCluster != null) {
       this.hbaseCluster.shutdown();
       // Wait till hbase is down before going on to shutdown zk.
@@ -723,9 +728,7 @@ public class HBaseTestingUtility {
           HColumnDescriptor.DEFAULT_REPLICATION_SCOPE);
       desc.addFamily(hcd);
     }
-    HBaseAdmin admin = getHBaseAdmin();
-    admin.createTable(desc, startKey, endKey, numRegions);
-    admin.close();
+    getHBaseAdmin().createTable(desc, startKey, endKey, numRegions);
     return new HTable(getConfiguration(), tableName);
   }
 
@@ -744,9 +747,7 @@ public class HBaseTestingUtility {
     for(byte[] family : families) {
       desc.addFamily(new HColumnDescriptor(family));
     }
-    HBaseAdmin admin = getHBaseAdmin();
-    admin.createTable(desc);
-    admin.close();
+    getHBaseAdmin().createTable(desc);
     return new HTable(c, tableName);
   }
 
@@ -773,9 +774,7 @@ public class HBaseTestingUtility {
           HColumnDescriptor.DEFAULT_REPLICATION_SCOPE);
       desc.addFamily(hcd);
     }
-    HBaseAdmin admin = getHBaseAdmin();
-    admin.createTable(desc);
-    admin.close();
+    getHBaseAdmin().createTable(desc);
     return new HTable(c, tableName);
   }
 
@@ -814,9 +813,7 @@ public class HBaseTestingUtility {
           HColumnDescriptor.DEFAULT_REPLICATION_SCOPE);
       desc.addFamily(hcd);
     }
-    HBaseAdmin admin = getHBaseAdmin();
-    admin.createTable(desc);
-    admin.close();
+    getHBaseAdmin().createTable(desc);
     return new HTable(new Configuration(getConfiguration()), tableName);
   }
 
@@ -841,9 +838,7 @@ public class HBaseTestingUtility {
           HColumnDescriptor.DEFAULT_REPLICATION_SCOPE);
       desc.addFamily(hcd);
     }
-    HBaseAdmin admin = getHBaseAdmin();
-    admin.createTable(desc);
-    admin.close();
+    getHBaseAdmin().createTable(desc);
     return new HTable(new Configuration(getConfiguration()), tableName);
   }
 
@@ -871,9 +866,7 @@ public class HBaseTestingUtility {
       desc.addFamily(hcd);
       i++;
     }
-    HBaseAdmin admin = getHBaseAdmin();
-    admin.createTable(desc);
-    admin.close();
+    getHBaseAdmin().createTable(desc);
     return new HTable(new Configuration(getConfiguration()), tableName);
   }
 
@@ -882,10 +875,8 @@ public class HBaseTestingUtility {
    * @param tableName existing table
    */
   public void deleteTable(byte[] tableName) throws IOException {
-    HBaseAdmin admin = new HBaseAdmin(getConfiguration());
-    admin.disableTable(tableName);
-    admin.deleteTable(tableName);
-    admin.close();
+    getHBaseAdmin().disableTable(tableName);
+    getHBaseAdmin().deleteTable(tableName);
   }
 
   /**
@@ -1093,14 +1084,12 @@ public class HBaseTestingUtility {
     HConnection conn = table.getConnection();
     conn.clearRegionCache();
     // assign all the new regions IF table is enabled.
-    HBaseAdmin admin = getHBaseAdmin();
-    if (admin.isTableEnabled(table.getTableName())) {
+    if (getHBaseAdmin().isTableEnabled(table.getTableName())) {
       for(HRegionInfo hri : newRegions) {
         hbaseCluster.getMaster().assignRegion(hri);
       }
     }
 
-    admin.close();
     meta.close();
 
     return count;
@@ -1323,14 +1312,21 @@ public class HBaseTestingUtility {
 
   /**
    * Returns a HBaseAdmin instance.
+   * This instance is shared between HBaseTestingUtility intance users.
+   * Don't close it, it will be closed automatically when the
+   * cluster shutdowns
    *
    * @return The HBaseAdmin instance.
    * @throws IOException
    */
-  public HBaseAdmin getHBaseAdmin()
+  public synchronized HBaseAdmin getHBaseAdmin()
   throws IOException {
-    return new HBaseAdmin(new Configuration(getConfiguration()));
+    if (hbaseAdmin == null){
+      hbaseAdmin = new HBaseAdmin(new Configuration(getConfiguration()));
+    }
+    return hbaseAdmin;
   }
+  private HBaseAdmin hbaseAdmin = null;
 
   /**
    * Closes the named region.
@@ -1349,9 +1345,7 @@ public class HBaseTestingUtility {
    * @throws IOException
    */
   public void closeRegion(byte[] regionName) throws IOException {
-    HBaseAdmin admin = getHBaseAdmin();
-    admin.closeRegion(regionName, null);
-    admin.close();
+    getHBaseAdmin().closeRegion(regionName, null);
   }
 
   /**
@@ -1443,14 +1437,12 @@ public class HBaseTestingUtility {
 
   public void waitTableAvailable(byte[] table, long timeoutMillis)
   throws InterruptedException, IOException {
-    HBaseAdmin admin = getHBaseAdmin();
     long startWait = System.currentTimeMillis();
-    while (!admin.isTableAvailable(table)) {
+    while (!getHBaseAdmin().isTableAvailable(table)) {
       assertTrue("Timed out waiting for table " + Bytes.toStringBinary(table),
           System.currentTimeMillis() - startWait < timeoutMillis);
       Thread.sleep(200);
     }
-    admin.close();
   }
 
   /**
@@ -1860,6 +1852,7 @@ public class HBaseTestingUtility {
           totalNumberOfRegions);
 
       admin.createTable(desc, splits);
+      admin.close();
     } catch (MasterNotRunningException e) {
       LOG.error("Master not running", e);
       throw new IOException(e);
@@ -1873,6 +1866,7 @@ public class HBaseTestingUtility {
   public static int getMetaRSPort(Configuration conf) throws IOException {
     HTable table = new HTable(conf, HConstants.META_TABLE_NAME);
     HRegionLocation hloc = table.getRegionLocation(Bytes.toBytes(""));
+    table.close();
     return hloc.getPort();
   }
 

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Fri Dec 16 18:17:32
2011
@@ -82,12 +82,11 @@ public class TestAdmin {
 
   @Before
   public void setUp() throws Exception {
-    this.admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
+    this.admin = TEST_UTIL.getHBaseAdmin();
   }
 
   @After
   public void tearDown() throws Exception {
-    this.admin.close();
   }
 
   @Test

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java Fri Dec
16 18:17:32 2011
@@ -197,6 +197,7 @@ public class TestFromClientSide {
      assertArrayEquals(T2, kvs[3].getValue());
      assertArrayEquals(T1, kvs[4].getValue());
      scanner.close();
+     h.close();
    }
 
    /**

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java Fri Dec
16 18:17:32 2011
@@ -126,6 +126,7 @@ public class TestConstraint {
       Throwable t = causes.get(0);
       assertEquals(ConstraintException.class, t.getClass());
     }
+    table.close();
   }
 
   /**
@@ -230,6 +231,7 @@ public class TestConstraint {
     table.put(put);
     // and we make sure that constraints were not run...
     assertFalse(CheckWasRunConstraint.wasRun);
+    table.close();
   }
 
   @After

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportExport.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportExport.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportExport.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportExport.java Fri
Dec 16 18:17:32 2011
@@ -186,6 +186,7 @@ public class TestImportExport {
         HColumnDescriptor.DEFAULT_BLOOMFILTER,
         HConstants.REPLICATION_SCOPE_LOCAL));
     UTIL.getHBaseAdmin().createTable(desc);
+    t.close();
     t = new HTable(UTIL.getConfiguration(), IMPORT_TABLE);
     args = new String[] {
         IMPORT_TABLE,
@@ -213,5 +214,6 @@ public class TestImportExport {
     assertEquals(now+2, res[4].getTimestamp());
     assertEquals(now+1, res[5].getTimestamp());
     assertEquals(now, res[6].getTimestamp());
+    t.close();
   }
 }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFilesSplitRecovery.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFilesSplitRecovery.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFilesSplitRecovery.java
(original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFilesSplitRecovery.java
Fri Dec 16 18:17:32 2011
@@ -111,8 +111,7 @@ public class TestLoadIncrementalHFilesSp
         htd.addFamily(new HColumnDescriptor(family(i)));
       }
 
-      HBaseAdmin admin = util.getHBaseAdmin();
-      admin.createTable(htd);
+      util.getHBaseAdmin().createTable(htd);
     } catch (TableExistsException tee) {
       LOG.info("Table " + table + " already exists");
     }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java Fri Dec 16 18:17:32
2011
@@ -67,7 +67,6 @@ public class TestMaster {
   public void testMasterOpsWhileSplitting() throws Exception {
     MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
     HMaster m = cluster.getMaster();
-    HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
 
     HTable ht = TEST_UTIL.createTable(TABLENAME, FAMILYNAME);
     TEST_UTIL.loadTable(ht, FAMILYNAME);
@@ -91,7 +90,7 @@ public class TestMaster {
       registerListener(EventType.RS_ZK_REGION_SPLIT, list);
 
     LOG.info("Splitting table");
-    admin.split(TABLENAME);
+    TEST_UTIL.getHBaseAdmin().split(TABLENAME);
     LOG.info("Waiting for split result to be about to open");
     split.await(60, TimeUnit.SECONDS);
     try {
@@ -113,7 +112,6 @@ public class TestMaster {
     } finally {
       proceed.countDown();
     }
-    admin.close();
   }
 
   static class RegionSplitListener implements EventHandlerListener {

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java
(original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java
Fri Dec 16 18:17:32 2011
@@ -236,8 +236,7 @@ public class TestHRegionServerBulkLoad {
         htd.addFamily(new HColumnDescriptor(family(i)));
       }
 
-      HBaseAdmin admin = UTIL.getHBaseAdmin();
-      admin.createTable(htd);
+      UTIL.getHBaseAdmin().createTable(htd);
     } catch (TableExistsException tee) {
       LOG.info("Table " + table + " already exists");
     }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestLogRollAbort.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestLogRollAbort.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestLogRollAbort.java
(original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestLogRollAbort.java
Fri Dec 16 18:17:32 2011
@@ -123,7 +123,8 @@ public class TestLogRollAbort {
     LOG.info("Starting testRSAbortWithUnflushedEdits()");
 
     // When the META table can be opened, the region servers are running
-    new HTable(TEST_UTIL.getConfiguration(), HConstants.META_TABLE_NAME);
+    new HTable(TEST_UTIL.getConfiguration(),
+      HConstants.META_TABLE_NAME).close();
 
     // Create the test table and open it
     String tableName = this.getClass().getSimpleName();

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java Fri
Dec 16 18:17:32 2011
@@ -201,7 +201,6 @@ public class TestScannersWithFilters {
       numRows -= 2;
       table.close();
     }
-    admin.close();
   }
 
   @AfterClass

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java Fri Dec
16 18:17:32 2011
@@ -123,6 +123,7 @@ public class TestTableResource {
     assertEquals(m.size(), 2);
     regionMap = m;
     LOG.info("regions: " + regionMap);
+    table.close();
   }
 
   @AfterClass

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java?rev=1215236&r1=1215235&r2=1215236&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java
(original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java
Fri Dec 16 18:17:32 2011
@@ -233,6 +233,8 @@ public class OfflineMetaRebuildTestCore 
     }
     meta.delete(dels);
     meta.flushCommits();
+    scanner.close();
+    meta.close();
   }
 
   /**



Mime
View raw message