HBASE-7726 Family Dir is not removed using modifyTable()
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1483883 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b3c97c3e3e
commit
13483015c9
|
@ -1813,6 +1813,11 @@ public class HBaseAdmin implements Abortable, Closeable {
|
|||
*/
|
||||
public void modifyTable(final byte [] tableName, final HTableDescriptor htd)
|
||||
throws IOException {
|
||||
if (!Bytes.equals(tableName, htd.getName())) {
|
||||
throw new IllegalArgumentException("the specified table name '" + Bytes.toString(tableName) +
|
||||
"' doesn't match with the HTD one: " + htd.getNameAsString());
|
||||
}
|
||||
|
||||
execute(new MasterAdminCallable<Void>() {
|
||||
@Override
|
||||
public Void call() throws ServiceException {
|
||||
|
|
|
@ -20,7 +20,10 @@ package org.apache.hadoop.hbase.master.handler;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.hbase.HRegionInfo;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
|
@ -28,10 +31,14 @@ import org.apache.hadoop.hbase.Server;
|
|||
import org.apache.hadoop.hbase.executor.EventType;
|
||||
import org.apache.hadoop.hbase.master.HMaster;
|
||||
import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
|
||||
import org.apache.hadoop.hbase.master.MasterFileSystem;
|
||||
import org.apache.hadoop.hbase.master.MasterServices;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
@InterfaceAudience.Private
|
||||
public class ModifyTableHandler extends TableEventHandler {
|
||||
private static final Log LOG = LogFactory.getLog(ModifyTableHandler.class);
|
||||
|
||||
private final HTableDescriptor htd;
|
||||
|
||||
public ModifyTableHandler(final byte [] tableName,
|
||||
|
@ -52,18 +59,41 @@ public class ModifyTableHandler extends TableEventHandler {
|
|||
@Override
|
||||
protected void handleTableOperation(List<HRegionInfo> hris)
|
||||
throws IOException {
|
||||
MasterCoprocessorHost cpHost = ((HMaster) this.server)
|
||||
.getCoprocessorHost();
|
||||
MasterCoprocessorHost cpHost = ((HMaster) this.server).getCoprocessorHost();
|
||||
if (cpHost != null) {
|
||||
cpHost.preModifyTableHandler(this.tableName, this.htd);
|
||||
}
|
||||
// Update descriptor
|
||||
HTableDescriptor oldHtd = getTableDescriptor();
|
||||
this.masterServices.getTableDescriptors().add(this.htd);
|
||||
deleteFamilyFromFS(hris, oldHtd.getFamiliesKeys());
|
||||
if (cpHost != null) {
|
||||
cpHost.postModifyTableHandler(this.tableName, this.htd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes from hdfs the families that are not longer present in the new table descriptor.
|
||||
*/
|
||||
private void deleteFamilyFromFS(final List<HRegionInfo> hris, final Set<byte[]> oldFamilies) {
|
||||
try {
|
||||
Set<byte[]> newFamilies = this.htd.getFamiliesKeys();
|
||||
MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
|
||||
for (byte[] familyName: oldFamilies) {
|
||||
if (!newFamilies.contains(familyName)) {
|
||||
LOG.debug("Removing family=" + Bytes.toString(familyName) +
|
||||
" from table=" + this.tableName);
|
||||
for (HRegionInfo hri: hris) {
|
||||
// Delete the family directory in FS for all the regions one by one
|
||||
mfs.deleteFamilyFromFS(hri, familyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Unable to remove on-disk directories for the removed families", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String name = "UnknownServerName";
|
||||
|
|
Loading…
Reference in New Issue