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:
parent
c001f73c37
commit
115a8fd439
|
@ -1557,20 +1557,23 @@ Server {
|
||||||
Bytes.equals(tableName, HConstants.META_TABLE_NAME);
|
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
|
@Override
|
||||||
public DeleteTableResponse deleteTable(RpcController controller, DeleteTableRequest request)
|
public DeleteTableResponse deleteTable(RpcController controller, DeleteTableRequest request)
|
||||||
throws ServiceException {
|
throws ServiceException {
|
||||||
byte [] tableName = request.getTableName().toByteArray();
|
|
||||||
try {
|
try {
|
||||||
checkInitialized();
|
deleteTable(request.getTableName().toByteArray());
|
||||||
if (cpHost != null) {
|
|
||||||
cpHost.preDeleteTable(tableName);
|
|
||||||
}
|
|
||||||
this.executorService.submit(new DeleteTableHandler(tableName, this, this));
|
|
||||||
|
|
||||||
if (cpHost != null) {
|
|
||||||
cpHost.postDeleteTable(tableName);
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ServiceException(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)
|
public AddColumnResponse addColumn(RpcController controller, AddColumnRequest req)
|
||||||
throws ServiceException {
|
throws ServiceException {
|
||||||
byte [] tableName = req.getTableName().toByteArray();
|
|
||||||
HColumnDescriptor column = HColumnDescriptor.convert(req.getColumnFamilies());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checkInitialized();
|
addColumn(req.getTableName().toByteArray(),
|
||||||
if (cpHost != null) {
|
HColumnDescriptor.convert(req.getColumnFamilies()));
|
||||||
if (cpHost.preAddColumn(tableName, column)) {
|
|
||||||
return AddColumnResponse.newBuilder().build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new TableAddFamilyHandler(tableName, column, this, this).process();
|
|
||||||
if (cpHost != null) {
|
|
||||||
cpHost.postAddColumn(tableName, column);
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ServiceException(ioe);
|
throw new ServiceException(ioe);
|
||||||
}
|
}
|
||||||
return AddColumnResponse.newBuilder().build();
|
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)
|
public ModifyColumnResponse modifyColumn(RpcController controller, ModifyColumnRequest req)
|
||||||
throws ServiceException {
|
throws ServiceException {
|
||||||
byte [] tableName = req.getTableName().toByteArray();
|
|
||||||
HColumnDescriptor descriptor = HColumnDescriptor.convert(req.getColumnFamilies());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checkInitialized();
|
modifyColumn(req.getTableName().toByteArray(),
|
||||||
checkCompression(descriptor);
|
HColumnDescriptor.convert(req.getColumnFamilies()));
|
||||||
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);
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ServiceException(ioe);
|
throw new ServiceException(ioe);
|
||||||
}
|
}
|
||||||
return ModifyColumnResponse.newBuilder().build();
|
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
|
@Override
|
||||||
public DeleteColumnResponse deleteColumn(RpcController controller, DeleteColumnRequest req)
|
public DeleteColumnResponse deleteColumn(RpcController controller, DeleteColumnRequest req)
|
||||||
throws ServiceException {
|
throws ServiceException {
|
||||||
final byte [] tableName = req.getTableName().toByteArray();
|
|
||||||
final byte [] columnName = req.getColumnName().toByteArray();
|
|
||||||
try {
|
try {
|
||||||
checkInitialized();
|
deleteColumn(req.getTableName().toByteArray(), req.getColumnName().toByteArray());
|
||||||
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);
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ServiceException(ioe);
|
throw new ServiceException(ioe);
|
||||||
}
|
}
|
||||||
return DeleteColumnResponse.newBuilder().build();
|
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
|
@Override
|
||||||
public EnableTableResponse enableTable(RpcController controller, EnableTableRequest request)
|
public EnableTableResponse enableTable(RpcController controller, EnableTableRequest request)
|
||||||
throws ServiceException {
|
throws ServiceException {
|
||||||
byte [] tableName = request.getTableName().toByteArray();
|
|
||||||
try {
|
try {
|
||||||
checkInitialized();
|
enableTable(request.getTableName().toByteArray());
|
||||||
if (cpHost != null) {
|
|
||||||
cpHost.preEnableTable(tableName);
|
|
||||||
}
|
|
||||||
this.executorService.submit(new EnableTableHandler(this, tableName,
|
|
||||||
catalogTracker, assignmentManager, false));
|
|
||||||
|
|
||||||
if (cpHost != null) {
|
|
||||||
cpHost.postEnableTable(tableName);
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ServiceException(ioe);
|
throw new ServiceException(ioe);
|
||||||
}
|
}
|
||||||
return EnableTableResponse.newBuilder().build();
|
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
|
@Override
|
||||||
public DisableTableResponse disableTable(RpcController controller, DisableTableRequest request)
|
public DisableTableResponse disableTable(RpcController controller, DisableTableRequest request)
|
||||||
throws ServiceException {
|
throws ServiceException {
|
||||||
byte [] tableName = request.getTableName().toByteArray();
|
|
||||||
try {
|
try {
|
||||||
checkInitialized();
|
disableTable(request.getTableName().toByteArray());
|
||||||
if (cpHost != null) {
|
|
||||||
cpHost.preDisableTable(tableName);
|
|
||||||
}
|
|
||||||
this.executorService.submit(new DisableTableHandler(this, tableName,
|
|
||||||
catalogTracker, assignmentManager, false));
|
|
||||||
|
|
||||||
if (cpHost != null) {
|
|
||||||
cpHost.postDisableTable(tableName);
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ServiceException(ioe);
|
throw new ServiceException(ioe);
|
||||||
}
|
}
|
||||||
|
@ -1749,26 +1772,30 @@ Server {
|
||||||
return result.get();
|
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
|
@Override
|
||||||
public ModifyTableResponse modifyTable(RpcController controller, ModifyTableRequest req)
|
public ModifyTableResponse modifyTable(RpcController controller, ModifyTableRequest req)
|
||||||
throws ServiceException {
|
throws ServiceException {
|
||||||
final byte [] tableName = req.getTableName().toByteArray();
|
|
||||||
HTableDescriptor htd = HTableDescriptor.convert(req.getTableSchema());
|
|
||||||
try {
|
try {
|
||||||
checkInitialized();
|
modifyTable(req.getTableName().toByteArray(),
|
||||||
checkCompression(htd);
|
HTableDescriptor.convert(req.getTableSchema()));
|
||||||
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);
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ServiceException(ioe);
|
throw new ServiceException(ioe);
|
||||||
}
|
}
|
||||||
return ModifyTableResponse.newBuilder().build();
|
return ModifyTableResponse.newBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue