You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ga...@apache.org on 2015/04/08 00:41:02 UTC

svn commit: r1671966 - in /hive/branches/hbase-metastore: ./ itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/ metastore/ metastore/src/java/org/apache/hadoop/hive/metastore/hbase/

Author: gates
Date: Tue Apr  7 22:41:01 2015
New Revision: 1671966

URL: http://svn.apache.org/r1671966
Log:
HIVE-10090 Add connection manager for Tephra (Alan Gates)

Added:
    hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/HBaseIntegrationTests.java
    hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/TephraHBaseConnection.java
Removed:
    hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/IMockUtils.java
Modified:
    hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseImport.java
    hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseMetastoreSql.java
    hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java
    hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestStorageDescriptorSharing.java
    hive/branches/hbase-metastore/metastore/pom.xml
    hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseConnection.java
    hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java
    hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java
    hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/VanillaHBaseConnection.java
    hive/branches/hbase-metastore/pom.xml

Added: hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/HBaseIntegrationTests.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/HBaseIntegrationTests.java?rev=1671966&view=auto
==============================================================================
--- hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/HBaseIntegrationTests.java (added)
+++ hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/HBaseIntegrationTests.java Tue Apr  7 22:41:01 2015
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hadoop.hive.metastore.hbase;
+
+import co.cask.tephra.hbase98.coprocessor.TransactionProcessor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hive.cli.CliSessionState;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.Driver;
+import org.apache.hadoop.hive.ql.security.SessionStateConfigUserAuthenticator;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactoryForTest;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Integration tests with HBase Mini-cluster for HBaseStore
+ */
+public class HBaseIntegrationTests {
+
+  private static final Log LOG = LogFactory.getLog(HBaseIntegrationTests.class.getName());
+
+  protected static HBaseTestingUtility utility;
+  protected static HBaseAdmin admin;
+  protected static Map<String, String> emptyParameters = new HashMap<String, String>();
+  protected static HiveConf conf;
+
+  protected HBaseStore store;
+  protected Driver driver;
+
+  protected static void startMiniCluster() throws Exception {
+    String connectionClassName =
+        System.getProperty(HiveConf.ConfVars.METASTORE_HBASE_CONNECTION_CLASS.varname);
+    boolean testingTephra =
+        connectionClassName != null && connectionClassName.equals(TephraHBaseConnection.class.getName());
+    utility = new HBaseTestingUtility();
+    utility.startMiniCluster();
+    conf = new HiveConf(utility.getConfiguration(), HBaseIntegrationTests.class);
+    admin = utility.getHBaseAdmin();
+    for (String tableName : HBaseReadWrite.tableNames) {
+      List<byte[]> families = HBaseReadWrite.columnFamilies.get(tableName);
+      HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
+      for (byte[] family : families) {
+        HColumnDescriptor columnDesc = new HColumnDescriptor(family);
+        if (testingTephra) columnDesc.setMaxVersions(Integer.MAX_VALUE);
+        desc.addFamily(columnDesc);
+      }
+      if (testingTephra) desc.addCoprocessor(TransactionProcessor.class.getName());
+      admin.createTable(desc);
+    }
+    admin.close();
+  }
+
+  protected static void shutdownMiniCluster() throws Exception {
+    utility.shutdownMiniCluster();
+  }
+
+  protected void setupConnection() throws IOException {
+
+  }
+
+  protected void setupDriver() {
+    // This chicanery is necessary to make the driver work.  Hive tests need the pfile file
+    // system, while the hbase one uses something else.  So first make sure we've configured our
+    // hbase connection, then get a new config file and populate it as desired.
+    HBaseReadWrite.getInstance(conf);
+    conf = new HiveConf();
+    conf.setVar(HiveConf.ConfVars.DYNAMICPARTITIONINGMODE, "nonstrict");
+    conf.setVar(HiveConf.ConfVars.METASTORE_RAW_STORE_IMPL,
+        "org.apache.hadoop.hive.metastore.hbase.HBaseStore");
+    conf.setBoolVar(HiveConf.ConfVars.METASTORE_FASTPATH, true);
+    conf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false);
+    // Setup so we can test SQL standard auth
+    conf.setBoolVar(HiveConf.ConfVars.HIVE_TEST_AUTHORIZATION_SQLSTD_HS2_MODE, true);
+    conf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER,
+        SQLStdHiveAuthorizerFactoryForTest.class.getName());
+    conf.setVar(HiveConf.ConfVars.HIVE_AUTHENTICATOR_MANAGER,
+        SessionStateConfigUserAuthenticator.class.getName());
+    conf.setBoolVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_ENABLED, true);
+    conf.setVar(HiveConf.ConfVars.USERS_IN_ADMIN_ROLE, System.getProperty("user.name"));
+    //HBaseReadWrite.setTestConnection(hconn);
+
+    SessionState.start(new CliSessionState(conf));
+    driver = new Driver(conf);
+  }
+
+  protected void setupHBaseStore() {
+    // Turn off caching, as we want to test actual interaction with HBase
+    conf.setBoolean(HBaseReadWrite.NO_CACHE_CONF, true);
+    store = new HBaseStore();
+    store.setConf(conf);
+  }
+
+}
+

Modified: hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseImport.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseImport.java?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseImport.java (original)
+++ hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseImport.java Tue Apr  7 22:41:01 2015
@@ -48,18 +48,18 @@ import java.util.List;
 /**
  * Test that import from an RDBMS based metastore works
  */
-public class TestHBaseImport extends IMockUtils {
+public class TestHBaseImport extends HBaseIntegrationTests {
 
   private static final Log LOG = LogFactory.getLog(TestHBaseStoreIntegration.class.getName());
 
   @BeforeClass
   public static void startup() throws Exception {
-    IMockUtils.startMiniCluster();
+    HBaseIntegrationTests.startMiniCluster();
   }
 
   @AfterClass
   public static void shutdown() throws Exception {
-    IMockUtils.shutdownMiniCluster();
+    HBaseIntegrationTests.shutdownMiniCluster();
   }
 
   @Before

Modified: hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseMetastoreSql.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseMetastoreSql.java?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseMetastoreSql.java (original)
+++ hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseMetastoreSql.java Tue Apr  7 22:41:01 2015
@@ -25,26 +25,27 @@ import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
+
+import java.io.File;
 import java.io.IOException;
 
 /**
  * Integration tests with HBase Mini-cluster using actual SQL
  */
-public class TestHBaseMetastoreSql extends IMockUtils {
+public class TestHBaseMetastoreSql extends HBaseIntegrationTests {
 
   private static final Log LOG = LogFactory.getLog(TestHBaseStoreIntegration.class.getName());
 
   @BeforeClass
   public static void startup() throws Exception {
-    IMockUtils.startMiniCluster();
+    HBaseIntegrationTests.startMiniCluster();
 
   }
 
   @AfterClass
   public static void shutdown() throws Exception {
-    IMockUtils.shutdownMiniCluster();
+    HBaseIntegrationTests.shutdownMiniCluster();
   }
 
   @Before

Modified: hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java (original)
+++ hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java Tue Apr  7 22:41:01 2015
@@ -72,7 +72,7 @@ import java.util.TreeSet;
 /**
  * Integration tests with HBase Mini-cluster for HBaseStore
  */
-public class TestHBaseStoreIntegration extends IMockUtils {
+public class TestHBaseStoreIntegration extends HBaseIntegrationTests {
 
   private static final Log LOG = LogFactory.getLog(TestHBaseStoreIntegration.class.getName());
 
@@ -80,12 +80,12 @@ public class TestHBaseStoreIntegration e
 
   @BeforeClass
   public static void startup() throws Exception {
-    IMockUtils.startMiniCluster();
+    HBaseIntegrationTests.startMiniCluster();
   }
 
   @AfterClass
   public static void shutdown() throws Exception {
-    IMockUtils.shutdownMiniCluster();
+    HBaseIntegrationTests.shutdownMiniCluster();
   }
 
   @Before
@@ -828,7 +828,7 @@ public class TestHBaseStoreIntegration e
     store.grantRole(role1, user1, PrincipalType.USER, "bob", PrincipalType.USER, false);
     store.grantRole(role1, roleName2, PrincipalType.ROLE, "admin", PrincipalType.ROLE, true);
 
-    List<String> roles = HBaseReadWrite.getInstance(conf).getUserRoles(user1);
+    List<String> roles = HBaseReadWrite.getInstance().getUserRoles(user1);
     Assert.assertEquals(2, roles.size());
     String[] roleNames = roles.toArray(new String[roles.size()]);
     Arrays.sort(roleNames);
@@ -874,7 +874,7 @@ public class TestHBaseStoreIntegration e
     store.grantRole(role1, roleName2, PrincipalType.ROLE, "admin", PrincipalType.ROLE, true);
     store.grantRole(role1, user2, PrincipalType.USER, "bob", PrincipalType.USER, false);
 
-    List<String> roles = HBaseReadWrite.getInstance(conf).getUserRoles(user2);
+    List<String> roles = HBaseReadWrite.getInstance().getUserRoles(user2);
     Assert.assertEquals(2, roles.size());
     String[] roleNames = roles.toArray(new String[roles.size()]);
     Arrays.sort(roleNames);
@@ -1112,7 +1112,7 @@ public class TestHBaseStoreIntegration e
     List<PrivilegeGrantInfo> pgi = null;
     switch (objectType) {
       case GLOBAL:
-        pgi = HBaseReadWrite.getInstance(conf).getGlobalPrivs().getRolePrivileges().get(roleName);
+        pgi = HBaseReadWrite.getInstance().getGlobalPrivs().getRolePrivileges().get(roleName);
         break;
 
       case DATABASE:

Modified: hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestStorageDescriptorSharing.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestStorageDescriptorSharing.java?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestStorageDescriptorSharing.java (original)
+++ hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestStorageDescriptorSharing.java Tue Apr  7 22:41:01 2015
@@ -40,7 +40,7 @@ import java.util.List;
 /**
  * Integration tests with HBase Mini-cluster for HBaseStore
  */
-public class TestStorageDescriptorSharing extends IMockUtils {
+public class TestStorageDescriptorSharing extends HBaseIntegrationTests {
 
   private static final Log LOG = LogFactory.getLog(TestHBaseStoreIntegration.class.getName());
 
@@ -48,12 +48,12 @@ public class TestStorageDescriptorSharin
 
   @BeforeClass
   public static void startup() throws Exception {
-    IMockUtils.startMiniCluster();
+    HBaseIntegrationTests.startMiniCluster();
   }
 
   @AfterClass
   public static void shutdown() throws Exception {
-    IMockUtils.shutdownMiniCluster();
+    HBaseIntegrationTests.shutdownMiniCluster();
   }
 
   @Before

Modified: hive/branches/hbase-metastore/metastore/pom.xml
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/pom.xml?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/pom.xml (original)
+++ hive/branches/hbase-metastore/metastore/pom.xml Tue Apr  7 22:41:01 2015
@@ -126,6 +126,21 @@
       <artifactId>libthrift</artifactId>
       <version>${libthrift.version}</version>
     </dependency>
+    <dependency>
+      <groupId>co.cask.tephra</groupId>
+      <artifactId>tephra-api</artifactId>
+      <version>${tephra.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>co.cask.tephra</groupId>
+      <artifactId>tephra-core</artifactId>
+      <version>${tephra.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>co.cask.tephra</groupId>
+      <artifactId>tephra-hbase-compat-0.98</artifactId>
+      <version>${tephra.version}</version>
+    </dependency>
     <!-- test inter-project -->
     <dependency>
       <groupId>junit</groupId>

Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseConnection.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseConnection.java?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseConnection.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseConnection.java Tue Apr  7 22:41:01 2015
@@ -61,6 +61,13 @@ public interface HBaseConnection extends
   void rollbackTransaction() throws IOException;
 
   /**
+   * Flush commits.  A no-op for transaction implementations since they will write at commit time.
+   * @param htab Table to flush
+   * @throws IOException
+   */
+  void flush(HTableInterface htab) throws IOException;
+
+  /**
    * Create a new table
    * @param tableName name of the table
    * @param columnFamilies name of the column families in the table

Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java Tue Apr  7 22:41:01 2015
@@ -87,6 +87,25 @@ class HBaseReadWrite {
   @VisibleForTesting final static byte[] CATALOG_CF = "c".getBytes(HBaseUtils.ENCODING);
   @VisibleForTesting final static byte[] STATS_CF = "s".getBytes(HBaseUtils.ENCODING);
   @VisibleForTesting final static String NO_CACHE_CONF = "no.use.cache";
+  /**
+   * List of tables in HBase
+   */
+  final static String[] tableNames = { DB_TABLE, FUNC_TABLE, GLOBAL_PRIVS_TABLE, PART_TABLE,
+                                       USER_TO_ROLE_TABLE, ROLE_TABLE, SD_TABLE, TABLE_TABLE  };
+  final static Map<String, List<byte[]>> columnFamilies =
+      new HashMap<String, List<byte[]>> (tableNames.length);
+
+  static {
+    columnFamilies.put(DB_TABLE, Arrays.asList(CATALOG_CF));
+    columnFamilies.put(FUNC_TABLE, Arrays.asList(CATALOG_CF));
+    columnFamilies.put(GLOBAL_PRIVS_TABLE, Arrays.asList(CATALOG_CF));
+    columnFamilies.put(PART_TABLE, Arrays.asList(CATALOG_CF, STATS_CF));
+    columnFamilies.put(USER_TO_ROLE_TABLE, Arrays.asList(CATALOG_CF));
+    columnFamilies.put(ROLE_TABLE, Arrays.asList(CATALOG_CF));
+    columnFamilies.put(SD_TABLE, Arrays.asList(CATALOG_CF));
+    columnFamilies.put(TABLE_TABLE, Arrays.asList(CATALOG_CF, STATS_CF));
+  }
+
   private final static byte[] CATALOG_COL = "cat".getBytes(HBaseUtils.ENCODING);
   private final static byte[] ROLES_COL = "roles".getBytes(HBaseUtils.ENCODING);
   private final static byte[] REF_COUNT_COL = "ref".getBytes(HBaseUtils.ENCODING);
@@ -96,8 +115,6 @@ class HBaseReadWrite {
   @VisibleForTesting final static String TEST_CONN = "test_connection";
   private static HBaseConnection testConn;
 
-  private final static String[] tableNames = { DB_TABLE, FUNC_TABLE, GLOBAL_PRIVS_TABLE, PART_TABLE,
-      USER_TO_ROLE_TABLE, ROLE_TABLE, SD_TABLE, TABLE_TABLE  };
   static final private Log LOG = LogFactory.getLog(HBaseReadWrite.class.getName());
 
   private static ThreadLocal<HBaseReadWrite> self = new ThreadLocal<HBaseReadWrite>() {
@@ -234,12 +251,16 @@ class HBaseReadWrite {
     if (!tablesCreated) {
       for (String name : tableNames) {
         if (self.get().conn.getHBaseTable(name, true) == null) {
+          List<byte[]> families = columnFamilies.get(name);
+          self.get().conn.createHBaseTable(name, families);
+          /*
           List<byte[]> columnFamilies = new ArrayList<byte[]>();
           columnFamilies.add(CATALOG_CF);
           if (TABLE_TABLE.equals(name) || PART_TABLE.equals(name)) {
             columnFamilies.add(STATS_CF);
           }
           self.get().conn.createHBaseTable(name, columnFamilies);
+          */
         }
       }
       tablesCreated = true;
@@ -541,7 +562,7 @@ class HBaseReadWrite {
     }
     HTableInterface htab = conn.getHBaseTable(PART_TABLE);
     htab.put(puts);
-    htab.flushCommits();
+    conn.flush(htab);
   }
 
   void replacePartitions(List<Partition> oldParts, List<Partition> newParts) throws IOException {
@@ -567,7 +588,7 @@ class HBaseReadWrite {
     }
     HTableInterface htab = conn.getHBaseTable(PART_TABLE);
     htab.put(puts);
-    htab.flushCommits();
+    conn.flush(htab);
   }
 
   /**
@@ -1014,7 +1035,7 @@ class HBaseReadWrite {
     if (puts.size() > 0) {
       HTableInterface htab = conn.getHBaseTable(ROLE_TABLE);
       htab.put(puts);
-      htab.flushCommits();
+      conn.flush(htab);
     }
 
     // Remove any global privileges held by this role
@@ -1043,7 +1064,7 @@ class HBaseReadWrite {
     if (puts.size() > 0) {
       HTableInterface htab = conn.getHBaseTable(DB_TABLE);
       htab.put(puts);
-      htab.flushCommits();
+      conn.flush(htab);
     }
 
     // Finally, walk the table table
@@ -1068,7 +1089,7 @@ class HBaseReadWrite {
     if (puts.size() > 0) {
       HTableInterface htab = conn.getHBaseTable(TABLE_TABLE);
       htab.put(puts);
-      htab.flushCommits();
+      conn.flush(htab);
     }
   }
 
@@ -1354,7 +1375,7 @@ class HBaseReadWrite {
       Put p = new Put(key);
       p.add(CATALOG_CF, REF_COUNT_COL, Integer.toString(refCnt).getBytes(HBaseUtils.ENCODING));
       htab.put(p);
-      htab.flushCommits();
+      conn.flush(htab);
     }
   }
 
@@ -1386,7 +1407,7 @@ class HBaseReadWrite {
       p.add(CATALOG_CF, REF_COUNT_COL, Integer.toString(refCnt).getBytes(HBaseUtils.ENCODING));
       htab.put(p);
     }
-    htab.flushCommits();
+    conn.flush(htab);
     return key;
   }
 
@@ -1699,7 +1720,7 @@ class HBaseReadWrite {
     Put p = new Put(key);
     p.add(colFam, colName, obj);
     htab.put(p);
-    htab.flushCommits();
+    conn.flush(htab);
   }
 
   private void store(String table, byte[] key, byte[] colFam, byte[][] colName, byte[][] obj)
@@ -1710,7 +1731,7 @@ class HBaseReadWrite {
       p.add(colFam, colName[i], obj[i]);
     }
     htab.put(p);
-    htab.flushCommits();
+    conn.flush(htab);
   }
 
   private byte[] read(String table, byte[] key, byte[] colFam, byte[] colName) throws IOException {

Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java Tue Apr  7 22:41:01 2015
@@ -102,56 +102,80 @@ public class HBaseStore implements RawSt
 
   @Override
   public boolean openTransaction() {
-    if (txnNestLevel++ == 0) getHBase().begin();
+    if (txnNestLevel++ <= 0) {
+      LOG.debug("Opening HBase transaction");
+      getHBase().begin();
+      txnNestLevel = 1;
+    }
     return true;
   }
 
   @Override
   public boolean commitTransaction() {
-    if (txnNestLevel-- < 1) getHBase().commit();
+    if (--txnNestLevel == 0) {
+      LOG.debug("Committing HBase transaction");
+      getHBase().commit();
+    }
     return true;
   }
 
   @Override
   public void rollbackTransaction() {
     txnNestLevel = 0;
+    LOG.debug("Rolling back HBase transaction");
     getHBase().rollback();
   }
 
   @Override
   public void createDatabase(Database db) throws InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
+
       // HiveMetaStore already checks for existence of the database, don't recheck
       getHBase().putDb(db);
+      commit = true;
     } catch (IOException e) {
       LOG.error("Unable to create database ", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
 
   }
 
   @Override
   public Database getDatabase(String name) throws NoSuchObjectException {
+    boolean commit = false;
+    openTransaction();
     try {
       Database db = getHBase().getDb(name);
       if (db == null) {
         throw new NoSuchObjectException("Unable to find db " + name);
       }
+      commit = true;
       return db;
     } catch (IOException e) {
       LOG.error("Unable to get db", e);
       throw new NoSuchObjectException("Error reading db " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public boolean dropDatabase(String dbname) throws NoSuchObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().deleteDb(dbname);
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to delete db" + e);
       throw new MetaException("Unable to drop database " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -160,25 +184,35 @@ public class HBaseStore implements RawSt
       MetaException {
     // ObjectStore fetches the old db before updating it, but I can't see the possible value of
     // that since the caller will have needed to call getDatabase to have the db object.
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().putDb(db);
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to alter database ", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public List<String> getDatabases(String pattern) throws MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       List<Database> dbs = getHBase().scanDatabases(likeToRegex(pattern));
       List<String> dbNames = new ArrayList<String>(dbs.size());
       for (Database db : dbs) dbNames.add(db.getName());
+      commit = true;
       return dbNames;
     } catch (IOException e) {
       LOG.error("Unable to get databases ", e);
       throw new MetaException("Unable to get databases, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -204,61 +238,86 @@ public class HBaseStore implements RawSt
 
   @Override
   public void createTable(Table tbl) throws InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     // HiveMetaStore above us checks if the table already exists, so we can blindly store it here.
     try {
       getHBase().putTable(tbl);
+      commit = true;
     } catch (IOException e) {
       LOG.error("Unable to create table ", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public boolean dropTable(String dbName, String tableName) throws MetaException,
       NoSuchObjectException, InvalidObjectException, InvalidInputException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().deleteTable(dbName, tableName);
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to delete db" + e);
       throw new MetaException("Unable to drop table " + tableNameForErrorMsg(dbName, tableName));
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public Table getTable(String dbName, String tableName) throws MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       Table table = getHBase().getTable(dbName, tableName);
       if (table == null) {
         LOG.debug("Unable to find table " + tableNameForErrorMsg(dbName, tableName));
       }
+      commit = true;
       return table;
     } catch (IOException e) {
       LOG.error("Unable to get table", e);
       throw new MetaException("Error reading table " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public boolean addPartition(Partition part) throws InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().putPartition(part);
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to add partition", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public boolean addPartitions(String dbName, String tblName, List<Partition> parts)
       throws InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().putPartitions(parts);
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to add partitions", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -271,87 +330,125 @@ public class HBaseStore implements RawSt
   @Override
   public Partition getPartition(String dbName, String tableName, List<String> part_vals) throws
       MetaException, NoSuchObjectException {
+    boolean commit = false;
+    openTransaction();
     try {
       Partition part = getHBase().getPartition(dbName, tableName, part_vals);
       if (part == null) {
         throw new NoSuchObjectException("Unable to find partition " +
             partNameForErrorMsg(dbName, tableName, part_vals));
       }
+      commit = true;
       return part;
     } catch (IOException e) {
       LOG.error("Unable to get partition", e);
       throw new MetaException("Error reading partition " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public boolean doesPartitionExist(String dbName, String tableName, List<String> part_vals) throws
       MetaException, NoSuchObjectException {
+    boolean commit = false;
+    openTransaction();
     try {
-      return getHBase().getPartition(dbName, tableName, part_vals) != null;
+      boolean exists = getHBase().getPartition(dbName, tableName, part_vals) != null;
+      commit = true;
+      return exists;
     } catch (IOException e) {
       LOG.error("Unable to get partition", e);
       throw new MetaException("Error reading partition " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public boolean dropPartition(String dbName, String tableName, List<String> part_vals) throws
       MetaException, NoSuchObjectException, InvalidObjectException, InvalidInputException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().deletePartition(dbName, tableName, part_vals);
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to delete db" + e);
       throw new MetaException("Unable to drop partition " + partNameForErrorMsg(dbName, tableName,
           part_vals));
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public List<Partition> getPartitions(String dbName, String tableName, int max) throws
       MetaException, NoSuchObjectException {
+    boolean commit = false;
+    openTransaction();
     try {
-      return getHBase().scanPartitionsInTable(dbName, tableName, max);
+      List<Partition> parts = getHBase().scanPartitionsInTable(dbName, tableName, max);
+      commit = true;
+      return parts;
     } catch (IOException e) {
       LOG.error("Unable to get partitions", e);
       throw new MetaException("Error scanning partitions");
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public void alterTable(String dbname, String name, Table newTable) throws InvalidObjectException,
       MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       Table oldTable = getHBase().getTable(dbname, name);
       getHBase().replaceTable(oldTable, newTable);
+      commit = true;
     } catch (IOException e) {
       LOG.error("Unable to alter table " + tableNameForErrorMsg(dbname, name), e);
       throw new MetaException("Unable to alter table " + tableNameForErrorMsg(dbname, name));
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public List<String> getTables(String dbName, String pattern) throws MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       List<Table> tables = getHBase().scanTables(dbName, likeToRegex(pattern));
       List<String> tableNames = new ArrayList<String>(tables.size());
       for (Table table : tables) tableNames.add(table.getTableName());
+      commit = true;
       return tableNames;
     } catch (IOException e) {
       LOG.error("Unable to get tables ", e);
       throw new MetaException("Unable to get tables, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public List<Table> getTableObjectsByName(String dbname, List<String> tableNames) throws
       MetaException, UnknownDBException {
+    boolean commit = false;
+    openTransaction();
     try {
-      return getHBase().getTables(dbname, tableNames);
+      List<Table> tables = getHBase().getTables(dbname, tableNames);
+      commit = true;
+      return tables;
     } catch (IOException e) {
       LOG.error("Unable to get tables ", e);
       throw new MetaException("Unable to get tables, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -370,6 +467,8 @@ public class HBaseStore implements RawSt
   @Override
   public List<String> listPartitionNames(String db_name, String tbl_name, short max_parts) throws
       MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       List<Partition> parts = getHBase().scanPartitionsInTable(db_name, tbl_name, max_parts);
       if (parts == null) return null;
@@ -378,10 +477,13 @@ public class HBaseStore implements RawSt
       for (Partition p : parts) {
         names.add(buildExternalPartName(table, p));
       }
+      commit = true;
       return names;
     } catch (IOException e) {
       LOG.error("Unable to get partitions", e);
       throw new MetaException("Error scanning partitions");
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -395,12 +497,17 @@ public class HBaseStore implements RawSt
   @Override
   public void alterPartition(String db_name, String tbl_name, List<String> part_vals,
                              Partition new_part) throws InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       Partition oldPart = getHBase().getPartition(db_name, tbl_name, part_vals);
       getHBase().replacePartition(oldPart, new_part);
+      commit = true;
     } catch (IOException e) {
       LOG.error("Unable to add partition", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -408,12 +515,17 @@ public class HBaseStore implements RawSt
   public void alterPartitions(String db_name, String tbl_name, List<List<String>> part_vals_list,
                               List<Partition> new_parts) throws InvalidObjectException,
       MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       List<Partition> oldParts = getHBase().getPartitions(db_name, tbl_name, part_vals_list);
       getHBase().replacePartitions(oldParts, new_parts);
+      commit = true;
     } catch (IOException e) {
       LOG.error("Unable to add partition", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -460,8 +572,14 @@ public class HBaseStore implements RawSt
     final ExpressionTree exprTree = (filter != null && !filter.isEmpty()) ? PartFilterExprUtil
         .getFilterParser(filter).tree : ExpressionTree.EMPTY_TREE;
     List<Partition> result = new ArrayList<Partition>();
-    getPartitionsByExprInternal(dbName, tblName, exprTree, maxParts, result);
-    return result;
+    boolean commit = false;
+    openTransaction();
+    try {
+      getPartitionsByExprInternal(dbName, tblName, exprTree, maxParts, result);
+      return result;
+    } finally {
+      commitOrRoleBack(commit);
+    }
   }
 
   @Override
@@ -472,7 +590,13 @@ public class HBaseStore implements RawSt
     // TODO: investigate if there should be any role for defaultPartitionName in this
     // implementation. direct sql code path in ObjectStore does not use it.
 
-    return getPartitionsByExprInternal(dbName, tblName, exprTree, maxParts, result);
+    boolean commit = false;
+    openTransaction();
+    try {
+      return getPartitionsByExprInternal(dbName, tblName, exprTree, maxParts, result);
+    } finally {
+      commitOrRoleBack(commit);
+    }
   }
 
   private boolean getPartitionsByExprInternal(String dbName, String tblName,
@@ -592,20 +716,27 @@ public class HBaseStore implements RawSt
       MetaException, NoSuchObjectException {
     int now = (int)(System.currentTimeMillis()/1000);
     Role role = new Role(roleName, now, ownerName);
+    boolean commit = false;
+    openTransaction();
     try {
       if (getHBase().getRole(roleName) != null) {
         throw new InvalidObjectException("Role " + roleName + " already exists");
       }
       getHBase().putRole(role);
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to create role ", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public boolean removeRole(String roleName) throws MetaException, NoSuchObjectException {
+    boolean commit = false;
+    openTransaction();
     try {
       Set<String> usersInRole = getHBase().findAllUsersInRole(roleName);
       getHBase().deleteRole(roleName);
@@ -613,10 +744,13 @@ public class HBaseStore implements RawSt
       for (String user : usersInRole) {
         getHBase().buildRoleMapForUser(user);
       }
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to delete role" + e);
       throw new MetaException("Unable to drop role " + roleName);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -624,6 +758,8 @@ public class HBaseStore implements RawSt
   public boolean grantRole(Role role, String userName, PrincipalType principalType, String grantor,
                            PrincipalType grantorType, boolean grantOption)
       throws MetaException, NoSuchObjectException, InvalidObjectException {
+    boolean commit = false;
+    openTransaction();
     try {
       Set<String> usersToRemap = findUsersToRemapRolesFor(role, userName, principalType);
       HbaseMetastoreProto.RoleGrantInfo.Builder builder =
@@ -643,16 +779,21 @@ public class HBaseStore implements RawSt
       for (String user : usersToRemap) {
         getHBase().buildRoleMapForUser(user);
       }
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to grant role", e);
       throw new MetaException("Unable to grant role " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public boolean revokeRole(Role role, String userName, PrincipalType principalType,
                             boolean grantOption) throws MetaException, NoSuchObjectException {
+    boolean commit = false;
+    openTransaction();
     // This can have a couple of different meanings.  If grantOption is true, then this is only
     // revoking the grant option, the role itself doesn't need to be removed.  If it is false
     // then we need to remove the userName from the role altogether.
@@ -667,16 +808,21 @@ public class HBaseStore implements RawSt
           getHBase().buildRoleMapForUser(user);
         }
       }
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to revoke role " + role.getRoleName() + " from " + userName, e);
       throw new MetaException("Unable to revoke role " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public PrincipalPrivilegeSet getUserPrivilegeSet(String userName, List<String> groupNames)
       throws InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       PrincipalPrivilegeSet pps = new PrincipalPrivilegeSet();
       PrincipalPrivilegeSet global = getHBase().getGlobalPrivs();
@@ -700,10 +846,13 @@ public class HBaseStore implements RawSt
           }
         }
       }
+      commit = true;
       return pps;
     } catch (IOException e) {
       LOG.error("Unable to get db privileges for user", e);
       throw new MetaException("Unable to get db privileges for user, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -711,6 +860,8 @@ public class HBaseStore implements RawSt
   public PrincipalPrivilegeSet getDBPrivilegeSet(String dbName, String userName,
                                                  List<String> groupNames)
       throws InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       PrincipalPrivilegeSet pps = new PrincipalPrivilegeSet();
       Database db = getHBase().getDb(dbName);
@@ -736,10 +887,13 @@ public class HBaseStore implements RawSt
           }
         }
       }
+      commit = true;
       return pps;
     } catch (IOException e) {
       LOG.error("Unable to get db privileges for user", e);
       throw new MetaException("Unable to get db privileges for user, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -747,6 +901,8 @@ public class HBaseStore implements RawSt
   public PrincipalPrivilegeSet getTablePrivilegeSet(String dbName, String tableName,
                                                     String userName, List<String> groupNames)
       throws InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       PrincipalPrivilegeSet pps = new PrincipalPrivilegeSet();
       Table table = getHBase().getTable(dbName, tableName);
@@ -771,10 +927,13 @@ public class HBaseStore implements RawSt
           }
         }
       }
+      commit = true;
       return pps;
     } catch (IOException e) {
       LOG.error("Unable to get db privileges for user", e);
       throw new MetaException("Unable to get db privileges for user, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -802,6 +961,8 @@ public class HBaseStore implements RawSt
                                                              PrincipalType principalType) {
     List<PrivilegeGrantInfo> grants;
     List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+    boolean commit = false;
+    openTransaction();
     try {
       PrincipalPrivilegeSet pps = getHBase().getGlobalPrivs();
       if (pps == null) return privileges;
@@ -827,9 +988,12 @@ public class HBaseStore implements RawSt
         privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.GLOBAL, null,
             null, null, null), principalName, principalType, pgi));
       }
+      commit = true;
       return privileges;
     } catch (IOException e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -839,6 +1003,8 @@ public class HBaseStore implements RawSt
                                                          String dbName) {
     List<PrivilegeGrantInfo> grants;
     List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+    boolean commit = false;
+    openTransaction();
     try {
       Database db = getHBase().getDb(dbName);
       if (db == null) return privileges;
@@ -866,9 +1032,12 @@ public class HBaseStore implements RawSt
         privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.DATABASE, dbName,
          null, null, null), principalName, principalType, pgi));
       }
+      commit = true;
       return privileges;
     } catch (IOException e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -879,6 +1048,8 @@ public class HBaseStore implements RawSt
                                                       String tableName) {
     List<PrivilegeGrantInfo> grants;
     List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+    boolean commit = false;
+    openTransaction();
     try {
       Table table = getHBase().getTable(dbName, tableName);
       if (table == null) return privileges;
@@ -906,9 +1077,12 @@ public class HBaseStore implements RawSt
         privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.TABLE, dbName,
             tableName, null, null), principalName, principalType, pgi));
       }
+      commit = true;
       return privileges;
     } catch (IOException e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -947,40 +1121,55 @@ public class HBaseStore implements RawSt
   @Override
   public boolean grantPrivileges(PrivilegeBag privileges)
       throws InvalidObjectException, MetaException, NoSuchObjectException {
-    for (HiveObjectPrivilege priv : privileges.getPrivileges()) {
-      // Locate the right object to deal with
-     PrivilegeInfo privilegeInfo = findPrivilegeToGrantOrRevoke(priv);
-
-      // Now, let's see if we've already got this privilege
-      for (PrivilegeGrantInfo info : privilegeInfo.grants) {
-        if (info.getPrivilege().equals(priv.getGrantInfo().getPrivilege())) {
-          throw new InvalidObjectException(priv.getPrincipalName() + " already has " +
-              priv.getGrantInfo().getPrivilege() + " on " + privilegeInfo.typeErrMsg);
+    boolean commit = false;
+    openTransaction();
+    try {
+      for (HiveObjectPrivilege priv : privileges.getPrivileges()) {
+        // Locate the right object to deal with
+        PrivilegeInfo privilegeInfo = findPrivilegeToGrantOrRevoke(priv);
+
+        // Now, let's see if we've already got this privilege
+        for (PrivilegeGrantInfo info : privilegeInfo.grants) {
+          if (info.getPrivilege().equals(priv.getGrantInfo().getPrivilege())) {
+            throw new InvalidObjectException(priv.getPrincipalName() + " already has " +
+                priv.getGrantInfo().getPrivilege() + " on " + privilegeInfo.typeErrMsg);
+          }
         }
-      }
-      privilegeInfo.grants.add(priv.getGrantInfo());
+        privilegeInfo.grants.add(priv.getGrantInfo());
 
-      writeBackGrantOrRevoke(priv, privilegeInfo);
+        writeBackGrantOrRevoke(priv, privilegeInfo);
+      }
+      commit = true;
+      return true;
+    } finally {
+      commitOrRoleBack(commit);
     }
-    return true;
   }
 
   @Override
   public boolean revokePrivileges(PrivilegeBag privileges, boolean grantOption) throws
       InvalidObjectException, MetaException, NoSuchObjectException {
-    for (HiveObjectPrivilege priv : privileges.getPrivileges()) {
-      PrivilegeInfo privilegeInfo = findPrivilegeToGrantOrRevoke(priv);
+    boolean commit = false;
+    openTransaction();
+    try {
+      for (HiveObjectPrivilege priv : privileges.getPrivileges()) {
+        PrivilegeInfo privilegeInfo = findPrivilegeToGrantOrRevoke(priv);
 
-      for (int i = 0; i < privilegeInfo.grants.size(); i++) {
-        if (privilegeInfo.grants.get(i).getPrivilege().equals(priv.getGrantInfo().getPrivilege())) {
-          if (grantOption) privilegeInfo.grants.get(i).setGrantOption(false);
-          else privilegeInfo.grants.remove(i);
-          break;
+        for (int i = 0; i < privilegeInfo.grants.size(); i++) {
+          if (privilegeInfo.grants.get(i).getPrivilege().equals(
+              priv.getGrantInfo().getPrivilege())) {
+            if (grantOption) privilegeInfo.grants.get(i).setGrantOption(false);
+            else privilegeInfo.grants.remove(i);
+            break;
+          }
         }
+        writeBackGrantOrRevoke(priv, privilegeInfo);
       }
-      writeBackGrantOrRevoke(priv, privilegeInfo);
+      commit = true;
+      return true;
+    } finally {
+      commitOrRoleBack(commit);
     }
-    return true;
   }
 
   private static class PrivilegeInfo {
@@ -1103,48 +1292,67 @@ public class HBaseStore implements RawSt
 
   @Override
   public Role getRole(String roleName) throws NoSuchObjectException {
+    boolean commit = false;
+    openTransaction();
     try {
       Role role = getHBase().getRole(roleName);
       if (role == null) {
         throw new NoSuchObjectException("Unable to find role " + roleName);
       }
+      commit = true;
       return role;
     } catch (IOException e) {
       LOG.error("Unable to get role", e);
       throw new NoSuchObjectException("Error reading table " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public List<String> listRoleNames() {
+    boolean commit = false;
+    openTransaction();
     try {
       List<Role> roles = getHBase().scanRoles();
       List<String> roleNames = new ArrayList<String>(roles.size());
       for (Role role : roles) roleNames.add(role.getRoleName());
+      commit = true;
       return roleNames;
     } catch (IOException e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public List<Role> listRoles(String principalName, PrincipalType principalType) {
     List<Role> roles = new ArrayList<Role>();
+    boolean commit = false;
+    openTransaction();
     try {
-      roles.addAll(getHBase().getPrincipalDirectRoles(principalName, principalType));
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-    // Add the public role if this is a user
-    if (principalType == PrincipalType.USER) {
-      roles.add(new Role(HiveMetaStore.PUBLIC, 0, null));
+      try {
+        roles.addAll(getHBase().getPrincipalDirectRoles(principalName, principalType));
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+      // Add the public role if this is a user
+      if (principalType == PrincipalType.USER) {
+        roles.add(new Role(HiveMetaStore.PUBLIC, 0, null));
+      }
+      commit = true;
+      return roles;
+    } finally {
+      commitOrRoleBack(commit);
     }
-    return roles;
   }
 
   @Override
   public List<RolePrincipalGrant> listRolesWithGrants(String principalName,
                                                       PrincipalType principalType) {
+    boolean commit = false;
+    openTransaction();
     try {
       List<Role> roles = listRoles(principalName, principalType);
       List<RolePrincipalGrant> rpgs = new ArrayList<RolePrincipalGrant>(roles.size());
@@ -1161,14 +1369,19 @@ public class HBaseStore implements RawSt
           }
         }
       }
+      commit = true;
       return rpgs;
     } catch (Exception e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public List<RolePrincipalGrant> listRoleMembers(String roleName) {
+    boolean commit = false;
+    openTransaction();
     try {
       HbaseMetastoreProto.RoleGrantInfoList gil = getHBase().getRolePrincipals(roleName);
       List<RolePrincipalGrant> roleMaps = new ArrayList<RolePrincipalGrant>(gil.getGrantInfoList().size());
@@ -1178,9 +1391,12 @@ public class HBaseStore implements RawSt
             giw.getGrantOption(), (int)giw.getAddTime(), giw.getGrantor(),
             HBaseUtils.convertPrincipalTypes(giw.getGrantorType())));
       }
+      commit = true;
       return roleMaps;
     } catch (Exception e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1220,49 +1436,73 @@ public class HBaseStore implements RawSt
                                                   String userName, List<String> groupNames)
       throws MetaException, NoSuchObjectException {
     // We don't handle auth info with partitions
+    boolean commit = false;
+    openTransaction();
     try {
-      return getHBase().scanPartitions(db_name, tbl_name, part_vals, max_parts);
+      List<Partition> parts = getHBase().scanPartitions(db_name, tbl_name, part_vals, max_parts);
+      commit = true;
+      return parts;
     } catch (IOException e) {
       LOG.error("Unable to list partition names", e);
       throw new MetaException("Failed to list part names, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
-  public boolean updateTableColumnStatistics(ColumnStatistics colStats)
-      throws NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException {
+  public boolean updateTableColumnStatistics(ColumnStatistics colStats) throws
+      NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().updateStatistics(colStats.getStatsDesc().getDbName(),
           colStats.getStatsDesc().getTableName(), null, null, colStats);
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to update column statistics", e);
       throw new MetaException("Failed to update column statistics, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
-  public boolean updatePartitionColumnStatistics(ColumnStatistics statsObj, List<String> partVals)
-      throws NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException {
+  public boolean updatePartitionColumnStatistics(ColumnStatistics statsObj,
+                                                 List<String> partVals) throws
+      NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().updateStatistics(statsObj.getStatsDesc().getDbName(),
-          statsObj.getStatsDesc().getTableName(), statsObj.getStatsDesc().getPartName(), partVals,
-          statsObj);
+          statsObj.getStatsDesc().getTableName(), statsObj.getStatsDesc().getPartName(),
+          partVals, statsObj);
+      commit = true;
       return true;
     } catch (IOException e) {
       LOG.error("Unable to update column statistics", e);
       throw new MetaException("Failed to update column statistics, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public ColumnStatistics getTableColumnStatistics(String dbName, String tableName,
-      List<String> colName) throws MetaException, NoSuchObjectException {
+                                                   List<String> colName) throws MetaException,
+      NoSuchObjectException {
+    boolean commit = false;
+    openTransaction();
     try {
-      return getHBase().getTableStatistics(dbName, tableName, colName);
+      ColumnStatistics cs = getHBase().getTableStatistics(dbName, tableName, colName);
+      commit = true;
+      return cs;
     } catch (IOException e) {
       LOG.error("Unable to fetch column statistics", e);
       throw new MetaException("Failed to fetch column statistics, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1273,11 +1513,19 @@ public class HBaseStore implements RawSt
     for (String partName : partNames) {
       partVals.add(partNameToVals(partName));
     }
-    try {
-      return getHBase().getPartitionStatistics(dbName, tblName, partNames, partVals, colNames);
+    for (String partName : partNames) partVals.add(partNameToVals(partName));
+    boolean commit = false;
+    openTransaction();
+    try {
+      List<ColumnStatistics> cs =
+          getHBase().getPartitionStatistics(dbName, tblName, partNames,  partVals, colNames);
+      commit = true;
+      return cs;
     } catch (IOException e) {
       LOG.error("Unable to fetch column statistics", e);
       throw new MetaException("Failed fetching column statistics, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1308,11 +1556,17 @@ public class HBaseStore implements RawSt
     for (String partName : partNames) {
       partVals.add(partNameToVals(partName));
     }
+    boolean commit = false;
+    openTransaction();
     try {
-      return getHBase().getAggrStats(dbName, tblName, partNames, partVals, colNames);
+      AggrStats stats = getHBase().getAggrStats(dbName, tblName, partNames, partVals, colNames);
+      commit = true;
+      return stats;
     } catch (IOException e) {
       LOG.error("Unable to fetch aggregate column statistics", e);
       throw new MetaException("Failed fetching aggregate column statistics, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1364,14 +1618,7 @@ public class HBaseStore implements RawSt
 
   @Override
   public void verifySchema() throws MetaException {
-    try {
-      if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST)) {
-        getHBase().createTablesIfNotExist();
-      }
-    } catch (IOException e) {
-      LOG.fatal("Unable to verify schema ", e);
-      throw new MetaException("Unable to verify schema");
-    }
+
   }
 
   @Override
@@ -1387,13 +1634,18 @@ public class HBaseStore implements RawSt
   @Override
   public void dropPartitions(String dbName, String tblName, List<String> partNames) throws
       MetaException, NoSuchObjectException {
+    boolean commit = false;
+    openTransaction();
     try {
       for (String partName : partNames) {
         dropPartition(dbName, tblName, partNameToVals(partName));
       }
+      commit = true;
     } catch (Exception e) {
       LOG.error("Unable to drop partitions", e);
       throw new NoSuchObjectException("Failure dropping partitions, " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1401,6 +1653,8 @@ public class HBaseStore implements RawSt
   public List<HiveObjectPrivilege> listPrincipalDBGrantsAll(String principalName,
                                                             PrincipalType principalType) {
     List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+    boolean commit = false;
+    openTransaction();
     try {
       List<Database> dbs = getHBase().scanDatabases(null);
       for (Database db : dbs) {
@@ -1431,9 +1685,12 @@ public class HBaseStore implements RawSt
               db.getName(), null, null, null), principalName, principalType, pgi));
         }
       }
+      commit = true;
       return privileges;
     } catch (IOException e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1441,6 +1698,8 @@ public class HBaseStore implements RawSt
   public List<HiveObjectPrivilege> listPrincipalTableGrantsAll(String principalName,
                                                                PrincipalType principalType) {
     List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+    boolean commit = false;
+    openTransaction();
     try {
       List<Table> tables = getHBase().scanTables(null, null);
       for (Table table : tables) {
@@ -1472,9 +1731,12 @@ public class HBaseStore implements RawSt
               pgi));
         }
       }
+      commit = true;
       return privileges;
     } catch (IOException e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1499,6 +1761,8 @@ public class HBaseStore implements RawSt
   @Override
   public List<HiveObjectPrivilege> listGlobalGrantsAll() {
     List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+    boolean commit = false;
+    openTransaction();
     try {
       PrincipalPrivilegeSet pps = getHBase().getGlobalPrivs();
       if (pps != null) {
@@ -1515,15 +1779,20 @@ public class HBaseStore implements RawSt
           }
         }
       }
+      commit = true;
       return privileges;
     } catch (IOException e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public List<HiveObjectPrivilege> listDBGrantsAll(String dbName) {
     List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+    boolean commit = false;
+    openTransaction();
     try {
       Database db = getHBase().getDb(dbName);
       PrincipalPrivilegeSet pps = db.getPrivileges();
@@ -1541,9 +1810,12 @@ public class HBaseStore implements RawSt
           }
         }
       }
+      commit = true;
       return privileges;
     } catch (IOException e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1557,6 +1829,8 @@ public class HBaseStore implements RawSt
   @Override
   public List<HiveObjectPrivilege> listTableGrantsAll(String dbName, String tableName) {
     List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+    boolean commit = false;
+    openTransaction();
     try {
       Table table = getHBase().getTable(dbName, tableName);
       PrincipalPrivilegeSet pps = table.getPrivileges();
@@ -1574,9 +1848,12 @@ public class HBaseStore implements RawSt
           }
         }
       }
+      commit = true;
       return privileges;
     } catch (IOException e) {
       throw new RuntimeException(e);
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1594,56 +1871,82 @@ public class HBaseStore implements RawSt
 
   @Override
   public void createFunction(Function func) throws InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().putFunction(func);
+      commit = true;
     } catch (IOException e) {
       LOG.error("Unable to create function", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public void alterFunction(String dbName, String funcName, Function newFunction) throws
       InvalidObjectException, MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().putFunction(newFunction);
+      commit = true;
     } catch (IOException e) {
       LOG.error("Unable to alter function ", e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public void dropFunction(String dbName, String funcName) throws MetaException,
       NoSuchObjectException, InvalidObjectException, InvalidInputException {
+    boolean commit = false;
+    openTransaction();
     try {
       getHBase().deleteFunction(dbName, funcName);
+      commit = true;
     } catch (IOException e) {
       LOG.error("Unable to delete function" + e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public Function getFunction(String dbName, String funcName) throws MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
-      return getHBase().getFunction(dbName, funcName);
+      Function func = getHBase().getFunction(dbName, funcName);
+      commit = true;
+      return func;
     } catch (IOException e) {
       LOG.error("Unable to get function" + e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
   @Override
   public List<String> getFunctions(String dbName, String pattern) throws MetaException {
+    boolean commit = false;
+    openTransaction();
     try {
       List<Function> funcs = getHBase().scanFunctions(dbName, likeToRegex(pattern));
       List<String> funcNames = new ArrayList<String>(funcs.size());
       for (Function func : funcs) funcNames.add(func.getFunctionName());
+      commit = true;
       return funcNames;
     } catch (IOException e) {
       LOG.error("Unable to get functions" + e);
       throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
+    } finally {
+      commitOrRoleBack(commit);
     }
   }
 
@@ -1769,4 +2072,14 @@ public class HBaseStore implements RawSt
     // use it, even though it wouldn't work on RDBMS backed metastores.
     return like.replace("*", ".*");
   }
+
+  private void commitOrRoleBack(boolean commit) {
+    if (commit) {
+      LOG.debug("Committing transaction");
+      commitTransaction();
+    } else {
+      LOG.debug("Rolling back transaction");
+      rollbackTransaction();
+    }
+  }
 }

Added: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/TephraHBaseConnection.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/TephraHBaseConnection.java?rev=1671966&view=auto
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/TephraHBaseConnection.java (added)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/TephraHBaseConnection.java Tue Apr  7 22:41:01 2015
@@ -0,0 +1,127 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hadoop.hive.metastore.hbase;
+
+import co.cask.tephra.TransactionAware;
+import co.cask.tephra.TransactionContext;
+import co.cask.tephra.TransactionFailureException;
+import co.cask.tephra.TransactionManager;
+import co.cask.tephra.TransactionSystemClient;
+import co.cask.tephra.distributed.ThreadLocalClientProvider;
+import co.cask.tephra.distributed.TransactionServiceClient;
+import co.cask.tephra.hbase98.TransactionAwareHTable;
+import co.cask.tephra.hbase98.coprocessor.TransactionProcessor;
+import co.cask.tephra.inmemory.InMemoryTxSystemClient;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.twill.discovery.InMemoryDiscoveryService;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A class that uses Tephra for transaction management.
+ */
+public class TephraHBaseConnection extends VanillaHBaseConnection {
+  static final private Log LOG = LogFactory.getLog(TephraHBaseConnection.class.getName());
+
+  private Map<String, TransactionAware> txnTables;
+  private TransactionContext txn;
+  private TransactionSystemClient txnClient;
+
+  TephraHBaseConnection() {
+    super();
+    txnTables = new HashMap<String, TransactionAware>();
+  }
+
+  @Override
+  public void connect() throws IOException {
+    super.connect();
+    if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST)) {
+      LOG.debug("Using an in memory client transaction system for testing");
+      TransactionManager txnMgr = new TransactionManager(conf);
+      txnMgr.startAndWait();
+      txnClient = new InMemoryTxSystemClient(txnMgr);
+    } else {
+      // TODO should enable use of ZKDiscoveryService if users want it
+      LOG.debug("Using real client transaction system for production");
+      txnClient = new TransactionServiceClient(conf,
+          new ThreadLocalClientProvider(conf, new InMemoryDiscoveryService()));
+    }
+    for (String tableName : HBaseReadWrite.tableNames) {
+      txnTables.put(tableName, new TransactionAwareHTable(super.getHBaseTable(tableName, true)));
+    }
+    txn = new TransactionContext(txnClient, txnTables.values());
+  }
+
+  @Override
+  public void beginTransaction() throws IOException {
+    try {
+      txn.start();
+      LOG.debug("Started txn in tephra");
+    } catch (TransactionFailureException e) {
+      throw new IOException(e);
+    }
+  }
+
+  @Override
+  public void commitTransaction() throws IOException {
+    try {
+      txn.finish();
+      LOG.debug("Finished txn in tephra");
+    } catch (TransactionFailureException e) {
+      throw new IOException(e);
+    }
+  }
+
+  @Override
+  public void rollbackTransaction() throws IOException {
+    try {
+      txn.abort();
+      LOG.debug("Aborted txn in tephra");
+    } catch (TransactionFailureException e) {
+      throw new IOException(e);
+    }
+  }
+
+  @Override
+  public void flush(HTableInterface htab) throws IOException {
+    // NO-OP as we want to flush at commit time
+  }
+
+  @Override
+  protected HTableDescriptor buildDescriptor(String tableName, List<byte[]> columnFamilies)
+      throws IOException {
+    HTableDescriptor tableDesc = super.buildDescriptor(tableName, columnFamilies);
+    tableDesc.addCoprocessor(TransactionProcessor.class.getName());
+    return tableDesc;
+  }
+
+  @Override
+  public HTableInterface getHBaseTable(String tableName, boolean force) throws IOException {
+    // Ignore force, it will mess up our previous creation of the tables.
+    return (TransactionAwareHTable)txnTables.get(tableName);
+  }
+
+}

Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/VanillaHBaseConnection.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/VanillaHBaseConnection.java?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/VanillaHBaseConnection.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/VanillaHBaseConnection.java Tue Apr  7 22:41:01 2015
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.hadoop.hive.metastore.hbase;
 
 import org.apache.commons.logging.Log;
@@ -24,17 +42,16 @@ import java.util.Map;
 public class VanillaHBaseConnection implements HBaseConnection {
   static final private Log LOG = LogFactory.getLog(VanillaHBaseConnection.class.getName());
 
-
-  private HConnection conn;
-  private Map<String, HTableInterface> tables;
-  Configuration conf;
+  protected HConnection conn;
+  protected Map<String, HTableInterface> tables;
+  protected Configuration conf;
 
   VanillaHBaseConnection() {
+    tables = new HashMap<String, HTableInterface>();
   }
 
   @Override
   public void connect() throws IOException {
-    tables = new HashMap<String, HTableInterface>();
     if (conf == null) throw new RuntimeException("Must call getConf before connect");
     conn = HConnectionManager.createConnection(conf);
   }
@@ -60,16 +77,26 @@ public class VanillaHBaseConnection impl
   }
 
   @Override
-  public void createHBaseTable(String tableName, List<byte[]> columnFamilies) throws
-      IOException {
+  public void flush(HTableInterface htab) throws IOException {
+    htab.flushCommits();
+  }
+
+  @Override
+  public void createHBaseTable(String tableName, List<byte[]> columnFamilies)
+      throws IOException {
     HBaseAdmin admin = new HBaseAdmin(conn);
     LOG.info("Creating HBase table " + tableName);
+    admin.createTable(buildDescriptor(tableName, columnFamilies));
+    admin.close();
+  }
+
+  protected HTableDescriptor buildDescriptor(String tableName, List<byte[]> columnFamilies)
+      throws IOException {
     HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(tableName));
     for (byte[] cf : columnFamilies) {
       tableDesc.addFamily(new HColumnDescriptor(cf));
     }
-    admin.createTable(tableDesc);
-    admin.close();
+    return tableDesc;
   }
 
   @Override

Modified: hive/branches/hbase-metastore/pom.xml
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/pom.xml?rev=1671966&r1=1671965&r2=1671966&view=diff
==============================================================================
--- hive/branches/hbase-metastore/pom.xml (original)
+++ hive/branches/hbase-metastore/pom.xml Tue Apr  7 22:41:01 2015
@@ -167,6 +167,7 @@
     <felix.version>2.4.0</felix.version>
     <curator.version>2.6.0</curator.version>
     <jsr305.version>3.0.0</jsr305.version>
+    <tephra.version>0.4.0</tephra.version>
   </properties>
 
   <repositories>