HBASE-7374. Expose table operations for coprocessors by way of MasterServices

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1423578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2012-12-18 19:01:23 +00:00
parent c001f73c37
commit 115a8fd439
3 changed files with 192 additions and 86 deletions

View File

@ -1558,19 +1558,22 @@ Server {
}
@Override
public DeleteTableResponse deleteTable(RpcController controller, DeleteTableRequest request)
throws ServiceException {
byte [] tableName = request.getTableName().toByteArray();
try {
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 {
try {
deleteTable(request.getTableName().toByteArray());
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
@ -1605,45 +1608,55 @@ Server {
}
}
public AddColumnResponse addColumn(RpcController controller, AddColumnRequest req)
throws ServiceException {
byte [] tableName = req.getTableName().toByteArray();
HColumnDescriptor column = HColumnDescriptor.convert(req.getColumnFamilies());
try {
@Override
public void addColumn(final byte[] tableName, final HColumnDescriptor column)
throws IOException {
checkInitialized();
if (cpHost != null) {
if (cpHost.preAddColumn(tableName, column)) {
return AddColumnResponse.newBuilder().build();
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 {
try {
addColumn(req.getTableName().toByteArray(),
HColumnDescriptor.convert(req.getColumnFamilies()));
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
return AddColumnResponse.newBuilder().build();
}
public ModifyColumnResponse modifyColumn(RpcController controller, ModifyColumnRequest req)
throws ServiceException {
byte [] tableName = req.getTableName().toByteArray();
HColumnDescriptor descriptor = HColumnDescriptor.convert(req.getColumnFamilies());
try {
@Override
public void modifyColumn(byte[] tableName, HColumnDescriptor descriptor)
throws IOException {
checkInitialized();
checkCompression(descriptor);
if (cpHost != null) {
if (cpHost.preModifyColumn(tableName, descriptor)) {
return ModifyColumnResponse.newBuilder().build();
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 {
try {
modifyColumn(req.getTableName().toByteArray(),
HColumnDescriptor.convert(req.getColumnFamilies()));
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
@ -1651,21 +1664,25 @@ Server {
}
@Override
public DeleteColumnResponse deleteColumn(RpcController controller, DeleteColumnRequest req)
throws ServiceException {
final byte [] tableName = req.getTableName().toByteArray();
final byte [] columnName = req.getColumnName().toByteArray();
try {
public void deleteColumn(final byte[] tableName, final byte[] columnName)
throws IOException {
checkInitialized();
if (cpHost != null) {
if (cpHost.preDeleteColumn(tableName, columnName)) {
return DeleteColumnResponse.newBuilder().build();
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 {
try {
deleteColumn(req.getTableName().toByteArray(), req.getColumnName().toByteArray());
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
@ -1673,20 +1690,23 @@ Server {
}
@Override
public EnableTableResponse enableTable(RpcController controller, EnableTableRequest request)
throws ServiceException {
byte [] tableName = request.getTableName().toByteArray();
try {
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 {
try {
enableTable(request.getTableName().toByteArray());
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
@ -1694,20 +1714,23 @@ Server {
}
@Override
public DisableTableResponse disableTable(RpcController controller, DisableTableRequest request)
throws ServiceException {
byte [] tableName = request.getTableName().toByteArray();
try {
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 {
try {
disableTable(request.getTableName().toByteArray());
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
@ -1750,23 +1773,27 @@ Server {
}
@Override
public ModifyTableResponse modifyTable(RpcController controller, ModifyTableRequest req)
throws ServiceException {
final byte [] tableName = req.getTableName().toByteArray();
HTableDescriptor htd = HTableDescriptor.convert(req.getTableSchema());
try {
public void modifyTable(final byte[] tableName, final HTableDescriptor descriptor)
throws IOException {
checkInitialized();
checkCompression(htd);
checkCompression(descriptor);
if (cpHost != null) {
cpHost.preModifyTable(tableName, htd);
cpHost.preModifyTable(tableName, descriptor);
}
TableEventHandler tblHandle = new ModifyTableHandler(tableName, htd, this, this);
TableEventHandler tblHandle = new ModifyTableHandler(tableName, descriptor, this, this);
this.executorService.submit(tblHandle);
tblHandle.waitForPersist();
if (cpHost != null) {
cpHost.postModifyTable(tableName, htd);
cpHost.postModifyTable(tableName, descriptor);
}
}
@Override
public ModifyTableResponse modifyTable(RpcController controller, ModifyTableRequest req)
throws ServiceException {
try {
modifyTable(req.getTableName().toByteArray(),
HTableDescriptor.convert(req.getTableSchema()));
} catch (IOException ioe) {
throw new ServiceException(ioe);
}

View File

@ -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.
*/

View File

@ -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