|
45 | 45 | import java.util.concurrent.atomic.AtomicReference; |
46 | 46 | import org.apache.commons.lang3.ArrayUtils; |
47 | 47 | import org.apache.hadoop.conf.Configuration; |
| 48 | +import org.apache.hadoop.fs.Path; |
48 | 49 | import org.apache.hadoop.hbase.Cell; |
49 | 50 | import org.apache.hadoop.hbase.CellScanner; |
50 | 51 | import org.apache.hadoop.hbase.CellUtil; |
|
103 | 104 | import org.apache.hadoop.hbase.testclassification.LargeTests; |
104 | 105 | import org.apache.hadoop.hbase.util.Bytes; |
105 | 106 | import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; |
| 107 | +import org.apache.hadoop.hbase.util.FSUtils; |
106 | 108 | import org.apache.hadoop.hbase.util.NonRepeatedEnvironmentEdge; |
107 | 109 | import org.apache.hadoop.hbase.util.Pair; |
108 | 110 | import org.apache.hadoop.hbase.util.TableDescriptorChecker; |
@@ -6911,4 +6913,59 @@ public void testModifyTableWithZeroRegionReplicas() throws Exception { |
6911 | 6913 |
|
6912 | 6914 | TEST_UTIL.getAdmin().modifyTable(newDesc); |
6913 | 6915 | } |
| 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 | + } |
6914 | 6971 | } |
0 commit comments