Review Board 1.7.22


HBase revision manager should configure/drop znodes in the create/drop table meta hooks in the storage handler.

Review Request #3774 - Created Feb. 7, 2012 and updated

Vandana Ayyalasomayajula
hcatalog-253
Reviewers
hcatalog
dcapwell, francisliu
hcatalog
The current revision manager implementation relies on the transactions to set up znodes related to a hbase table. It would be a better way to use the meta hooks in the hbase storage handler to create/delete the znodes related to hbase table. 
A new unit test has been added to cover the new code path. All the unit tests pass. 
/trunk/storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/HBaseHCatStorageHandler.java
Revision 1240955 New Change
[20] 188 lines
[+20] [+] public void preCreateTable(Table tbl) throws MetaException {
189
            int iKey = HBaseSerDe.parseColumnMapping(hbaseColumnsMapping,
189
            int iKey = HBaseSerDe.parseColumnMapping(hbaseColumnsMapping,
190
                    hbaseColumnFamilies, hbaseColumnFamiliesBytes,
190
                    hbaseColumnFamilies, hbaseColumnFamiliesBytes,
191
                    hbaseColumnQualifiers, hbaseColumnQualifiersBytes);
191
                    hbaseColumnQualifiers, hbaseColumnQualifiersBytes);
192

    
   
192

   
193
            HTableDescriptor tableDesc;
193
            HTableDescriptor tableDesc;
194

    
   
194
            Set<String> uniqueColumnFamilies = new HashSet<String>();
195
            if (!getHBaseAdmin().tableExists(tableName)) {
195
            if (!getHBaseAdmin().tableExists(tableName)) {
196
                // if it is not an external table then create one
196
                // if it is not an external table then create one
197
                if (!isExternal) {
197
                if (!isExternal) {
198
                    // Create the column descriptors
198
                    // Create the column descriptors
199
                    tableDesc = new HTableDescriptor(tableName);
199
                    tableDesc = new HTableDescriptor(tableName);
200
                    Set<String> uniqueColumnFamilies = new HashSet<String>(
200
                    uniqueColumnFamilies.addAll(hbaseColumnFamilies);
201
                            hbaseColumnFamilies);

   
202
                    uniqueColumnFamilies.remove(hbaseColumnFamilies.get(iKey));
201
                    uniqueColumnFamilies.remove(hbaseColumnFamilies.get(iKey));
203

    
   
202

   
204
                    for (String columnFamily : uniqueColumnFamilies) {
203
                    for (String columnFamily : uniqueColumnFamilies) {
205
                        HColumnDescriptor familyDesc = new HColumnDescriptor(Bytes
204
                        HColumnDescriptor familyDesc = new HColumnDescriptor(Bytes
206
                                .toBytes(columnFamily));
205
                                .toBytes(columnFamily));
[+20] [20] 33 lines
[+20] public void preCreateTable(Table tbl) throws MetaException {
240
                }
239
                }
241
            }
240
            }
242

    
   
241

   
243
            // ensure the table is online
242
            // ensure the table is online
244
            new HTable(hbaseConf, tableDesc.getName());
243
            new HTable(hbaseConf, tableDesc.getName());

    
   
244

   

    
   
245
            //Set up znodes in revision manager.

    
   
246
            RevisionManager rm = getOpenedRevisionManager(hbaseConf);

    
   
247
            if (rm instanceof ZKBasedRevisionManager) {

    
   
248
                ZKBasedRevisionManager zkRM = (ZKBasedRevisionManager) rm;

    
   
249
                zkRM.setUpZNodes(tableName, new ArrayList<String>(

    
   
250
                        uniqueColumnFamilies));

    
   
251
            }

    
   
252

   
245
        } catch (MasterNotRunningException mnre) {
253
        } catch (MasterNotRunningException mnre) {
246
            throw new MetaException(StringUtils.stringifyException(mnre));
254
            throw new MetaException(StringUtils.stringifyException(mnre));
247
        } catch (IOException ie) {
255
        } catch (IOException ie) {
248
            throw new MetaException(StringUtils.stringifyException(ie));
256
            throw new MetaException(StringUtils.stringifyException(ie));
249
        } catch (SerDeException se) {
257
        } catch (SerDeException se) {
[+20] [20] 143 lines
[+20] [+] private void checkDeleteTable(Table table) throws MetaException {
393
                // we have created an HBase table, so we delete it to roll back;
401
                // we have created an HBase table, so we delete it to roll back;
394
                if (getHBaseAdmin().isTableEnabled(tableName)) {
402
                if (getHBaseAdmin().isTableEnabled(tableName)) {
395
                    getHBaseAdmin().disableTable(tableName);
403
                    getHBaseAdmin().disableTable(tableName);
396
                }
404
                }
397
                getHBaseAdmin().deleteTable(tableName);
405
                getHBaseAdmin().deleteTable(tableName);

    
   
406

   

    
   
407
              //Set up znodes in revision manager.

    
   
408
                RevisionManager rm = getOpenedRevisionManager(hbaseConf);

    
   
409
                if (rm instanceof ZKBasedRevisionManager) {

    
   
410
                    ZKBasedRevisionManager zkRM = (ZKBasedRevisionManager) rm;

    
   
411
                    zkRM.deleteZNodes(tableName);

    
   
412
                }
398
            }
413
            }
399
        } catch (IOException ie) {
414
        } catch (IOException ie) {
400
            throw new MetaException(StringUtils.stringifyException(ie));
415
            throw new MetaException(StringUtils.stringifyException(ie));
401
        }
416
        }
402
    }
417
    }
[+20] [20] 197 lines
/trunk/storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKBasedRevisionManager.java
Revision 1240955 New Change
 
/trunk/storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKUtil.java
Revision 1240955 New Change
 
/trunk/storage-drivers/hbase/src/test/org/apache/hcatalog/hbase/snapshot/TestZNodeSetUp.java
New File
 
  1. /trunk/storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/HBaseHCatStorageHandler.java: Loading...
  2. /trunk/storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKBasedRevisionManager.java: Loading...
  3. /trunk/storage-drivers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKUtil.java: Loading...
  4. /trunk/storage-drivers/hbase/src/test/org/apache/hcatalog/hbase/snapshot/TestZNodeSetUp.java: Loading...