HBASE-24977 Meta table shouldn't be modified as read only (#2537)

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Pankaj 2020-10-30 05:04:23 +05:30 committed by GitHub
parent eee1cf7ff6
commit e3beccf1fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CompoundConfiguration;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.TableDescriptor;
@ -150,6 +151,11 @@ public final class TableDescriptorChecker {
warnOrThrowExceptionForFailure(logWarn, message, null);
}
// Meta table shouldn't be set as read only, otherwise it will impact region assignments
if (td.isReadOnly() && TableName.isMetaTableName(td.getTableName())) {
warnOrThrowExceptionForFailure(false, "Meta table can't be set as read only.", null);
}
for (ColumnFamilyDescriptor hcd : td.getColumnFamilies()) {
if (hcd.getTimeToLive() <= 0) {
String message = "TTL for column family " + hcd.getNameAsString() + " must be positive.";

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hbase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -28,6 +29,7 @@ import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.regionserver.Region;
import org.apache.hadoop.hbase.testclassification.MediumTests;
@ -133,4 +135,31 @@ public class TestHBaseMetaEdit {
assertTrue(hioe.getMessage().contains("Delete of hbase:meta"));
}
}
/**
* Validate whether meta table can be altered as READ only, shouldn't be allowed otherwise it will
* break assignment functionalities. See HBASE-24977.
*/
@Test
public void testAlterMetaWithReadOnly() throws IOException {
Admin admin = UTIL.getAdmin();
TableDescriptor origMetaTableDesc = admin.getDescriptor(TableName.META_TABLE_NAME);
assertFalse(origMetaTableDesc.isReadOnly());
TableDescriptor newTD =
TableDescriptorBuilder.newBuilder(origMetaTableDesc).setReadOnly(true).build();
try {
admin.modifyTable(newTD);
fail("Meta table can't be set as read only");
} catch (Exception e) {
assertFalse(admin.getDescriptor(TableName.META_TABLE_NAME).isReadOnly());
}
// Create a table to check region assignment & meta operation
TableName tableName = TableName.valueOf("tempTable");
TableDescriptor td = TableDescriptorBuilder.newBuilder(tableName).setReadOnly(true)
.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f1")).build())
.build();
UTIL.getAdmin().createTable(td);
UTIL.deleteTable(tableName);
}
}