|
43 | 43 | import java.util.concurrent.atomic.AtomicReference; |
44 | 44 | import org.apache.commons.lang3.ArrayUtils; |
45 | 45 | import org.apache.hadoop.conf.Configuration; |
| 46 | +import org.apache.hadoop.fs.Path; |
46 | 47 | import org.apache.hadoop.hbase.Cell; |
47 | 48 | import org.apache.hadoop.hbase.CellScanner; |
48 | 49 | import org.apache.hadoop.hbase.CellUtil; |
|
100 | 101 | import org.apache.hadoop.hbase.testclassification.LargeTests; |
101 | 102 | import org.apache.hadoop.hbase.util.Bytes; |
102 | 103 | import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; |
| 104 | +import org.apache.hadoop.hbase.util.FSUtils; |
103 | 105 | import org.apache.hadoop.hbase.util.NonRepeatedEnvironmentEdge; |
104 | 106 | import org.apache.hadoop.hbase.util.Pair; |
105 | 107 | import org.apache.hadoop.hbase.util.TableDescriptorChecker; |
@@ -6864,4 +6866,59 @@ public void testModifyTableWithZeroRegionReplicas() throws Exception { |
6864 | 6866 |
|
6865 | 6867 | TEST_UTIL.getAdmin().modifyTable(newDesc); |
6866 | 6868 | } |
| 6869 | + |
| 6870 | + @Test(timeout = 60000) |
| 6871 | + public void testModifyTableWithMemstoreData() throws Exception { |
| 6872 | + TableName tableName = TableName.valueOf(name.getMethodName()); |
| 6873 | + createTableAndValidateTableSchemaModification(tableName, true); |
| 6874 | + } |
| 6875 | + |
| 6876 | + @Test(timeout = 60000) |
| 6877 | + public void testDeleteCFWithMemstoreData() throws Exception { |
| 6878 | + TableName tableName = TableName.valueOf(name.getMethodName()); |
| 6879 | + createTableAndValidateTableSchemaModification(tableName, false); |
| 6880 | + } |
| 6881 | + |
| 6882 | + /** |
| 6883 | + * Create table and validate online schema modification |
| 6884 | + * @param tableName Table name |
| 6885 | + * @param modifyTable Modify table if true otherwise delete column family |
| 6886 | + * @throws IOException in case of failures |
| 6887 | + */ |
| 6888 | + private void createTableAndValidateTableSchemaModification(TableName tableName, |
| 6889 | + boolean modifyTable) throws Exception { |
| 6890 | + Admin admin = TEST_UTIL.getAdmin(); |
| 6891 | + // Create table with two Cfs |
| 6892 | + byte[] cf1 = Bytes.toBytes("cf1"); |
| 6893 | + byte[] cf2 = Bytes.toBytes("cf2"); |
| 6894 | + TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName) |
| 6895 | + .setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf1)) |
| 6896 | + .setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf2)).build(); |
| 6897 | + admin.createTable(tableDesc); |
| 6898 | + |
| 6899 | + Table t = TEST_UTIL.getConnection().getTable(tableName); |
| 6900 | + // Insert few records and flush the table |
| 6901 | + t.put(new Put(ROW).addColumn(cf1, QUALIFIER, Bytes.toBytes("val1"))); |
| 6902 | + t.put(new Put(ROW).addColumn(cf2, QUALIFIER, Bytes.toBytes("val2"))); |
| 6903 | + admin.flush(tableName); |
| 6904 | + Path tableDir = FSUtils.getTableDir(TEST_UTIL.getDefaultRootDirPath(), tableName); |
| 6905 | + List<Path> regionDirs = FSUtils.getRegionDirs(TEST_UTIL.getTestFileSystem(), tableDir); |
| 6906 | + assertTrue(regionDirs.size() == 1); |
| 6907 | + List<Path> familyDirs = FSUtils.getFamilyDirs(TEST_UTIL.getTestFileSystem(), regionDirs.get(0)); |
| 6908 | + assertTrue(familyDirs.size() == 2); |
| 6909 | + |
| 6910 | + // Insert record but dont flush the table |
| 6911 | + t.put(new Put(ROW).addColumn(cf1, QUALIFIER, Bytes.toBytes("val2"))); |
| 6912 | + t.put(new Put(ROW).addColumn(cf2, QUALIFIER, Bytes.toBytes("val2"))); |
| 6913 | + |
| 6914 | + if (modifyTable) { |
| 6915 | + tableDesc = TableDescriptorBuilder.newBuilder(tableDesc).removeColumnFamily(cf2).build(); |
| 6916 | + admin.modifyTable(tableDesc); |
| 6917 | + } else { |
| 6918 | + admin.deleteColumnFamily(tableName, cf2); |
| 6919 | + } |
| 6920 | + // After table modification or delete family there should be only one CF in FS |
| 6921 | + familyDirs = FSUtils.getFamilyDirs(TEST_UTIL.getTestFileSystem(), regionDirs.get(0)); |
| 6922 | + assertTrue("CF dir count should be 1, but was " + familyDirs.size(), familyDirs.size() == 1); |
| 6923 | + } |
6867 | 6924 | } |
0 commit comments