Index: storage-drivers/hbase/src/test/org/apache/hcatalog/hbase/snapshot/TestZNodeSetUp.java =================================================================== --- storage-drivers/hbase/src/test/org/apache/hcatalog/hbase/snapshot/TestZNodeSetUp.java (revision 0) +++ storage-drivers/hbase/src/test/org/apache/hcatalog/hbase/snapshot/TestZNodeSetUp.java (revision 0) @@ -0,0 +1,100 @@ +package org.apache.hcatalog.hbase.snapshot; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URI; +import java.util.Map; + +import org.apache.hadoop.fs.Path; +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.conf.HiveConf.ConfVars; +import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse; +import org.apache.hadoop.hive.ql.session.SessionState; +import org.apache.hcatalog.cli.HCatDriver; +import org.apache.hcatalog.cli.SemanticAnalysis.HCatSemanticAnalyzer; +import org.apache.hcatalog.hbase.SkeletonHBaseTest; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.junit.Test; + + +public class TestZNodeSetUp extends SkeletonHBaseTest{ + + private static HiveConf hcatConf; + private static HCatDriver hcatDriver; + + public void Initialize() throws Exception { + + hcatConf = getHiveConf(); + hcatConf.set(ConfVars.SEMANTIC_ANALYZER_HOOK.varname, + HCatSemanticAnalyzer.class.getName()); + URI fsuri = getFileSystem().getUri(); + Path whPath = new Path(fsuri.getScheme(), fsuri.getAuthority(), + getTestDir()); + hcatConf.set(HiveConf.ConfVars.HADOOPFS.varname, fsuri.toString()); + hcatConf.set(ConfVars.METASTOREWAREHOUSE.varname, whPath.toString()); + + //Add hbase properties + + for (Map.Entry el : getHbaseConf()) { + if (el.getKey().startsWith("hbase.")) { + hcatConf.set(el.getKey(), el.getValue()); + } + } + hcatConf.set("revision.manager.zk.DataDir", "/rm_base"); + SessionState.start(new CliSessionState(hcatConf)); + hcatDriver = new HCatDriver(); + + } + + @Test + public void testBasicZNodeCreation() throws Exception{ + + Initialize(); + int port = getHbaseConf().getInt("hbase.zookeeper.property.clientPort", 2181); + String servers = getHbaseConf().get("hbase.zookeeper.quorum"); + String[] splits = servers.split(","); + StringBuffer sb = new StringBuffer(); + for(String split : splits){ + sb.append(split); + sb.append(':'); + sb.append(port); + } + + hcatDriver.run("drop table test_table"); + CommandProcessorResponse response = hcatDriver + .run("create table test_table(key int, value string) STORED BY " + + "'org.apache.hcatalog.hbase.HBaseHCatStorageHandler'" + + "TBLPROPERTIES ('hbase.columns.mapping'=':key,cf1:val')"); + + assertEquals(0, response.getResponseCode()); + + HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf()); + boolean doesTableExist = hAdmin.tableExists("test_table"); + assertTrue(doesTableExist); + + + ZKUtil zkutil = new ZKUtil(sb.toString(), "/rm_base"); + ZooKeeper zk = zkutil.getSession(); + String tablePath = PathUtil.getTxnDataPath("/rm_base", "test_table"); + Stat tempTwo = zk.exists(tablePath, false); + assertTrue(tempTwo != null); + + String cfPath = PathUtil.getTxnDataPath("/rm_base", "test_table") + "/cf1"; + Stat tempThree = zk.exists(cfPath, false); + assertTrue(tempThree != null); + + hcatDriver.run("drop table test_table"); + + System.out.println("Table path : " + tablePath); + Stat tempFour = zk.exists(tablePath, false); + assertTrue(tempFour == null); + + } + +} Index: storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/HBaseHCatStorageHandler.java =================================================================== --- storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/HBaseHCatStorageHandler.java (revision 1240955) +++ storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/HBaseHCatStorageHandler.java (working copy) @@ -191,14 +191,13 @@ hbaseColumnQualifiers, hbaseColumnQualifiersBytes); HTableDescriptor tableDesc; - + Set uniqueColumnFamilies = new HashSet(); if (!getHBaseAdmin().tableExists(tableName)) { // if it is not an external table then create one if (!isExternal) { // Create the column descriptors tableDesc = new HTableDescriptor(tableName); - Set uniqueColumnFamilies = new HashSet( - hbaseColumnFamilies); + uniqueColumnFamilies.addAll(hbaseColumnFamilies); uniqueColumnFamilies.remove(hbaseColumnFamilies.get(iKey)); for (String columnFamily : uniqueColumnFamilies) { @@ -242,6 +241,15 @@ // ensure the table is online new HTable(hbaseConf, tableDesc.getName()); + + //Set up znodes in revision manager. + RevisionManager rm = getOpenedRevisionManager(hbaseConf); + if (rm instanceof ZKBasedRevisionManager) { + ZKBasedRevisionManager zkRM = (ZKBasedRevisionManager) rm; + zkRM.setUpZNodes(tableName, new ArrayList( + uniqueColumnFamilies)); + } + } catch (MasterNotRunningException mnre) { throw new MetaException(StringUtils.stringifyException(mnre)); } catch (IOException ie) { @@ -395,6 +403,13 @@ getHBaseAdmin().disableTable(tableName); } getHBaseAdmin().deleteTable(tableName); + + //Set up znodes in revision manager. + RevisionManager rm = getOpenedRevisionManager(hbaseConf); + if (rm instanceof ZKBasedRevisionManager) { + ZKBasedRevisionManager zkRM = (ZKBasedRevisionManager) rm; + zkRM.deleteZNodes(tableName); + } } } catch (IOException ie) { throw new MetaException(StringUtils.stringifyException(ie)); Index: storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKUtil.java =================================================================== --- storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKUtil.java (revision 1240955) +++ storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKUtil.java (working copy) @@ -429,6 +429,36 @@ } /** + * Delete table znodes. + * + * @param tableName the hbase table name + * @throws IOException Signals that an I/O exception has occurred. + */ + void deleteZNodes(String tableName) throws IOException { + String transactionDataTablePath = PathUtil.getTxnDataPath(baseDir, + tableName); + deleteRecursively(transactionDataTablePath); + } + + void deleteRecursively(String path) throws IOException { + try { + List children = getSession().getChildren(path, false); + if (children.size() != 0) { + for (String child : children) { + deleteRecursively(path + "/" + child); + } + } + getSession().delete(path, -1); + } catch (KeeperException e) { + throw new IOException( + "Exception while deleting path " + path + ".", e); + } catch (InterruptedException e) { + throw new IOException( + "Exception while deleting path " + path + ".", e); + } + } + + /** * This method serializes a given instance of TBase object. * * @param obj An instance of TBase Index: storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKBasedRevisionManager.java =================================================================== --- storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKBasedRevisionManager.java (revision 1240955) +++ storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKBasedRevisionManager.java (working copy) @@ -419,7 +419,29 @@ return lockPath; } + /** + * Sets up the table, column family znodes in zookeeper. + * + * @param tableName the hbase table name + * @param columnFamilies the column families in hbase + * @throws IOException Signals that an I/O exception has occurred. + */ + public void setUpZNodes(String tableName, List columnFamilies) throws IOException{ + zkUtil.createRootZNodes(); + zkUtil.setUpZnodesForTable(tableName, columnFamilies); + } + /** + * Delete the table znodes from zookeeper. + * + * @param tableName the table name + * @throws IOException Signals that an I/O exception has occurred. + */ + public void deleteZNodes(String tableName) throws IOException { + zkUtil.deleteZNodes(tableName); + } + + /* * This class is a listener class for the locks used in revision management. * TBD: Use the following class to signal that that the lock is actually