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

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import com.google.protobuf.Service; import com.google.protobuf.Service;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.Server;
import org.apache.hadoop.hbase.TableDescriptors; import org.apache.hadoop.hbase.TableDescriptors;
@ -74,6 +75,63 @@ public interface MasterServices extends Server {
public void createTable(HTableDescriptor desc, byte [][] splitKeys) public void createTable(HTableDescriptor desc, byte [][] splitKeys)
throws IOException; 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. * @return Return table descriptors implementation.
*/ */

View File

@ -294,6 +294,27 @@ public class TestCatalogJanitor {
public boolean registerService(Service instance) { public boolean registerService(Service instance) {
return false; 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 @Test