Skip to content

Commit 16f6d75

Browse files
PankajGuanghao Zhang
authored andcommitted
HBASE-22806 Recreating a deleted column family brings back the deleted cells (apache#530)
Signed-off-by: stack <stack@apache.org>
1 parent 8a7b4a3 commit 16f6d75

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ protected Flow executeFromState(final MasterProcedureEnv env, final ModifyTableS
120120
break;
121121
case MODIFY_TABLE_REMOVE_REPLICA_COLUMN:
122122
updateReplicaColumnsIfNeeded(env, unmodifiedTableDescriptor, modifiedTableDescriptor);
123-
if (deleteColumnFamilyInModify) {
124-
setNextState(ModifyTableState.MODIFY_TABLE_DELETE_FS_LAYOUT);
125-
} else {
126-
setNextState(ModifyTableState.MODIFY_TABLE_POST_OPERATION);
127-
}
128-
break;
129-
case MODIFY_TABLE_DELETE_FS_LAYOUT:
130-
deleteFromFs(env, unmodifiedTableDescriptor, modifiedTableDescriptor);
131123
setNextState(ModifyTableState.MODIFY_TABLE_POST_OPERATION);
132124
break;
133125
case MODIFY_TABLE_POST_OPERATION:
@@ -138,6 +130,14 @@ protected Flow executeFromState(final MasterProcedureEnv env, final ModifyTableS
138130
if (env.getAssignmentManager().isTableEnabled(getTableName())) {
139131
addChildProcedure(new ReopenTableRegionsProcedure(getTableName()));
140132
}
133+
if (deleteColumnFamilyInModify) {
134+
setNextState(ModifyTableState.MODIFY_TABLE_DELETE_FS_LAYOUT);
135+
} else {
136+
setNextState(ModifyTableState.MODIFY_TABLE_SYNC_SCHEMA_TO_PEER);
137+
}
138+
break;
139+
case MODIFY_TABLE_DELETE_FS_LAYOUT:
140+
deleteFromFs(env, unmodifiedTableDescriptor, modifiedTableDescriptor);
141141
setNextState(ModifyTableState.MODIFY_TABLE_SYNC_SCHEMA_TO_PEER);
142142
break;
143143
case MODIFY_TABLE_SYNC_SCHEMA_TO_PEER:

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.concurrent.atomic.AtomicReference;
4646
import org.apache.commons.lang3.ArrayUtils;
4747
import org.apache.hadoop.conf.Configuration;
48+
import org.apache.hadoop.fs.Path;
4849
import org.apache.hadoop.hbase.Cell;
4950
import org.apache.hadoop.hbase.CellScanner;
5051
import org.apache.hadoop.hbase.CellUtil;
@@ -103,6 +104,7 @@
103104
import org.apache.hadoop.hbase.testclassification.LargeTests;
104105
import org.apache.hadoop.hbase.util.Bytes;
105106
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
107+
import org.apache.hadoop.hbase.util.FSUtils;
106108
import org.apache.hadoop.hbase.util.NonRepeatedEnvironmentEdge;
107109
import org.apache.hadoop.hbase.util.Pair;
108110
import org.apache.hadoop.hbase.util.TableDescriptorChecker;
@@ -6911,4 +6913,59 @@ public void testModifyTableWithZeroRegionReplicas() throws Exception {
69116913

69126914
TEST_UTIL.getAdmin().modifyTable(newDesc);
69136915
}
6916+
6917+
@Test(timeout = 60000)
6918+
public void testModifyTableWithMemstoreData() throws Exception {
6919+
TableName tableName = TableName.valueOf(name.getMethodName());
6920+
createTableAndValidateTableSchemaModification(tableName, true);
6921+
}
6922+
6923+
@Test(timeout = 60000)
6924+
public void testDeleteCFWithMemstoreData() throws Exception {
6925+
TableName tableName = TableName.valueOf(name.getMethodName());
6926+
createTableAndValidateTableSchemaModification(tableName, false);
6927+
}
6928+
6929+
/**
6930+
* Create table and validate online schema modification
6931+
* @param tableName Table name
6932+
* @param modifyTable Modify table if true otherwise delete column family
6933+
* @throws IOException in case of failures
6934+
*/
6935+
private void createTableAndValidateTableSchemaModification(TableName tableName,
6936+
boolean modifyTable) throws Exception {
6937+
Admin admin = TEST_UTIL.getAdmin();
6938+
// Create table with two Cfs
6939+
byte[] cf1 = Bytes.toBytes("cf1");
6940+
byte[] cf2 = Bytes.toBytes("cf2");
6941+
TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName)
6942+
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf1))
6943+
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf2)).build();
6944+
admin.createTable(tableDesc);
6945+
6946+
Table t = TEST_UTIL.getConnection().getTable(tableName);
6947+
// Insert few records and flush the table
6948+
t.put(new Put(ROW).addColumn(cf1, QUALIFIER, Bytes.toBytes("val1")));
6949+
t.put(new Put(ROW).addColumn(cf2, QUALIFIER, Bytes.toBytes("val2")));
6950+
admin.flush(tableName);
6951+
Path tableDir = FSUtils.getTableDir(TEST_UTIL.getDefaultRootDirPath(), tableName);
6952+
List<Path> regionDirs = FSUtils.getRegionDirs(TEST_UTIL.getTestFileSystem(), tableDir);
6953+
assertTrue(regionDirs.size() == 1);
6954+
List<Path> familyDirs = FSUtils.getFamilyDirs(TEST_UTIL.getTestFileSystem(), regionDirs.get(0));
6955+
assertTrue(familyDirs.size() == 2);
6956+
6957+
// Insert record but dont flush the table
6958+
t.put(new Put(ROW).addColumn(cf1, QUALIFIER, Bytes.toBytes("val2")));
6959+
t.put(new Put(ROW).addColumn(cf2, QUALIFIER, Bytes.toBytes("val2")));
6960+
6961+
if (modifyTable) {
6962+
tableDesc = TableDescriptorBuilder.newBuilder(tableDesc).removeColumnFamily(cf2).build();
6963+
admin.modifyTable(tableDesc);
6964+
} else {
6965+
admin.deleteColumnFamily(tableName, cf2);
6966+
}
6967+
// After table modification or delete family there should be only one CF in FS
6968+
familyDirs = FSUtils.getFamilyDirs(TEST_UTIL.getTestFileSystem(), regionDirs.get(0));
6969+
assertTrue("CF dir count should be 1, but was " + familyDirs.size(), familyDirs.size() == 1);
6970+
}
69146971
}

0 commit comments

Comments
 (0)