diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 1d7ae9086d1..d5f1f636a85 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -1557,20 +1557,23 @@ Server { Bytes.equals(tableName, HConstants.META_TABLE_NAME); } + @Override + public void deleteTable(final byte[] tableName) throws IOException { + checkInitialized(); + if (cpHost != null) { + cpHost.preDeleteTable(tableName); + } + this.executorService.submit(new DeleteTableHandler(tableName, this, this)); + if (cpHost != null) { + cpHost.postDeleteTable(tableName); + } + } + @Override public DeleteTableResponse deleteTable(RpcController controller, DeleteTableRequest request) throws ServiceException { - byte [] tableName = request.getTableName().toByteArray(); try { - checkInitialized(); - if (cpHost != null) { - cpHost.preDeleteTable(tableName); - } - this.executorService.submit(new DeleteTableHandler(tableName, this, this)); - - if (cpHost != null) { - cpHost.postDeleteTable(tableName); - } + deleteTable(request.getTableName().toByteArray()); } catch (IOException ioe) { throw new ServiceException(ioe); } @@ -1605,109 +1608,129 @@ Server { } } + @Override + public void addColumn(final byte[] tableName, final HColumnDescriptor column) + throws IOException { + checkInitialized(); + if (cpHost != null) { + if (cpHost.preAddColumn(tableName, column)) { + return; + } + } + new TableAddFamilyHandler(tableName, column, this, this).process(); + if (cpHost != null) { + cpHost.postAddColumn(tableName, column); + } + } + + @Override public AddColumnResponse addColumn(RpcController controller, AddColumnRequest req) throws ServiceException { - byte [] tableName = req.getTableName().toByteArray(); - HColumnDescriptor column = HColumnDescriptor.convert(req.getColumnFamilies()); - try { - checkInitialized(); - if (cpHost != null) { - if (cpHost.preAddColumn(tableName, column)) { - return AddColumnResponse.newBuilder().build(); - } - } - new TableAddFamilyHandler(tableName, column, this, this).process(); - if (cpHost != null) { - cpHost.postAddColumn(tableName, column); - } + addColumn(req.getTableName().toByteArray(), + HColumnDescriptor.convert(req.getColumnFamilies())); } catch (IOException ioe) { throw new ServiceException(ioe); } return AddColumnResponse.newBuilder().build(); } + @Override + public void modifyColumn(byte[] tableName, HColumnDescriptor descriptor) + throws IOException { + checkInitialized(); + checkCompression(descriptor); + if (cpHost != null) { + if (cpHost.preModifyColumn(tableName, descriptor)) { + return; + } + } + new TableModifyFamilyHandler(tableName, descriptor, this, this).process(); + if (cpHost != null) { + cpHost.postModifyColumn(tableName, descriptor); + } + } + + @Override public ModifyColumnResponse modifyColumn(RpcController controller, ModifyColumnRequest req) throws ServiceException { - byte [] tableName = req.getTableName().toByteArray(); - HColumnDescriptor descriptor = HColumnDescriptor.convert(req.getColumnFamilies()); - try { - checkInitialized(); - checkCompression(descriptor); - if (cpHost != null) { - if (cpHost.preModifyColumn(tableName, descriptor)) { - return ModifyColumnResponse.newBuilder().build(); - } - } - new TableModifyFamilyHandler(tableName, descriptor, this, this).process(); - if (cpHost != null) { - cpHost.postModifyColumn(tableName, descriptor); - } + modifyColumn(req.getTableName().toByteArray(), + HColumnDescriptor.convert(req.getColumnFamilies())); } catch (IOException ioe) { throw new ServiceException(ioe); } return ModifyColumnResponse.newBuilder().build(); } + @Override + public void deleteColumn(final byte[] tableName, final byte[] columnName) + throws IOException { + checkInitialized(); + if (cpHost != null) { + if (cpHost.preDeleteColumn(tableName, columnName)) { + return; + } + } + new TableDeleteFamilyHandler(tableName, columnName, this, this).process(); + if (cpHost != null) { + cpHost.postDeleteColumn(tableName, columnName); + } + } + @Override public DeleteColumnResponse deleteColumn(RpcController controller, DeleteColumnRequest req) throws ServiceException { - final byte [] tableName = req.getTableName().toByteArray(); - final byte [] columnName = req.getColumnName().toByteArray(); try { - checkInitialized(); - if (cpHost != null) { - if (cpHost.preDeleteColumn(tableName, columnName)) { - return DeleteColumnResponse.newBuilder().build(); - } - } - new TableDeleteFamilyHandler(tableName, columnName, this, this).process(); - if (cpHost != null) { - cpHost.postDeleteColumn(tableName, columnName); - } + deleteColumn(req.getTableName().toByteArray(), req.getColumnName().toByteArray()); } catch (IOException ioe) { throw new ServiceException(ioe); } return DeleteColumnResponse.newBuilder().build(); } + @Override + public void enableTable(final byte[] tableName) throws IOException { + checkInitialized(); + if (cpHost != null) { + cpHost.preEnableTable(tableName); + } + this.executorService.submit(new EnableTableHandler(this, tableName, + catalogTracker, assignmentManager, false)); + if (cpHost != null) { + cpHost.postEnableTable(tableName); + } + } + @Override public EnableTableResponse enableTable(RpcController controller, EnableTableRequest request) throws ServiceException { - byte [] tableName = request.getTableName().toByteArray(); try { - checkInitialized(); - if (cpHost != null) { - cpHost.preEnableTable(tableName); - } - this.executorService.submit(new EnableTableHandler(this, tableName, - catalogTracker, assignmentManager, false)); - - if (cpHost != null) { - cpHost.postEnableTable(tableName); - } + enableTable(request.getTableName().toByteArray()); } catch (IOException ioe) { throw new ServiceException(ioe); } return EnableTableResponse.newBuilder().build(); } + @Override + public void disableTable(final byte[] tableName) throws IOException { + checkInitialized(); + if (cpHost != null) { + cpHost.preDisableTable(tableName); + } + this.executorService.submit(new DisableTableHandler(this, tableName, + catalogTracker, assignmentManager, false)); + if (cpHost != null) { + cpHost.postDisableTable(tableName); + } + } + @Override public DisableTableResponse disableTable(RpcController controller, DisableTableRequest request) throws ServiceException { - byte [] tableName = request.getTableName().toByteArray(); try { - checkInitialized(); - if (cpHost != null) { - cpHost.preDisableTable(tableName); - } - this.executorService.submit(new DisableTableHandler(this, tableName, - catalogTracker, assignmentManager, false)); - - if (cpHost != null) { - cpHost.postDisableTable(tableName); - } + disableTable(request.getTableName().toByteArray()); } catch (IOException ioe) { throw new ServiceException(ioe); } @@ -1749,26 +1772,30 @@ Server { return result.get(); } + @Override + public void modifyTable(final byte[] tableName, final HTableDescriptor descriptor) + throws IOException { + checkInitialized(); + checkCompression(descriptor); + if (cpHost != null) { + cpHost.preModifyTable(tableName, descriptor); + } + TableEventHandler tblHandle = new ModifyTableHandler(tableName, descriptor, this, this); + this.executorService.submit(tblHandle); + tblHandle.waitForPersist(); + if (cpHost != null) { + cpHost.postModifyTable(tableName, descriptor); + } + } + @Override public ModifyTableResponse modifyTable(RpcController controller, ModifyTableRequest req) throws ServiceException { - final byte [] tableName = req.getTableName().toByteArray(); - HTableDescriptor htd = HTableDescriptor.convert(req.getTableSchema()); try { - checkInitialized(); - checkCompression(htd); - if (cpHost != null) { - cpHost.preModifyTable(tableName, htd); - } - TableEventHandler tblHandle = new ModifyTableHandler(tableName, htd, this, this); - this.executorService.submit(tblHandle); - tblHandle.waitForPersist(); - - if (cpHost != null) { - cpHost.postModifyTable(tableName, htd); - } + modifyTable(req.getTableName().toByteArray(), + HTableDescriptor.convert(req.getTableSchema())); } catch (IOException ioe) { - throw new ServiceException(ioe); + throw new ServiceException(ioe); } return ModifyTableResponse.newBuilder().build(); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java index 51d9bafff5a..f9aa860dc54 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java @@ -22,6 +22,7 @@ import java.io.IOException; import com.google.protobuf.Service; import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.TableDescriptors; @@ -74,6 +75,63 @@ public interface MasterServices extends Server { public void createTable(HTableDescriptor desc, byte [][] splitKeys) throws IOException; + /** + * Delete a table + * @param tableName The table name + * @throws IOException + */ + public void deleteTable(final byte[] tableName) throws IOException; + + /** + * Modify the descriptor of an existing table + * @param tableName The table name + * @param descriptor The updated table descriptor + * @throws IOException + */ + public void modifyTable(final byte[] tableName, final HTableDescriptor descriptor) + throws IOException; + + /** + * Enable an existing table + * @param tableName The table name + * @throws IOException + */ + public void enableTable(final byte[] tableName) throws IOException; + + /** + * Disable an existing table + * @param tableName The table name + * @throws IOException + */ + public void disableTable(final byte[] tableName) throws IOException; + + /** + * Add a new column to an existing table + * @param tableName The table name + * @param column The column definition + * @throws IOException + */ + public void addColumn(final byte[] tableName, final HColumnDescriptor column) + throws IOException; + + /** + * Modify the column descriptor of an existing column in an existing table + * @param tableName The table name + * @param descriptor The updated column definition + * @throws IOException + */ + public void modifyColumn(byte[] tableName, HColumnDescriptor descriptor) + throws IOException; + + /** + * Delete a column from an existing table + * @param tableName The table name + * @param columnName The column name + * @throws IOException + */ + public void deleteColumn(final byte[] tableName, final byte[] columnName) + throws IOException; + /** * @return Return table descriptors implementation. */ diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java index 2d17820a3b2..3073041bd1d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java @@ -294,6 +294,27 @@ public class TestCatalogJanitor { public boolean registerService(Service instance) { return false; } + + @Override + public void deleteTable(byte[] tableName) throws IOException { } + + @Override + public void modifyTable(byte[] tableName, HTableDescriptor descriptor) throws IOException { } + + @Override + public void enableTable(byte[] tableName) throws IOException { } + + @Override + public void disableTable(byte[] tableName) throws IOException { } + + @Override + public void addColumn(byte[] tableName, HColumnDescriptor column) throws IOException { } + + @Override + public void modifyColumn(byte[] tableName, HColumnDescriptor descriptor) throws IOException { } + + @Override + public void deleteColumn(byte[] tableName, byte[] columnName) throws IOException { } } @Test