HBASE-17245 Replace HTableDescriptor#htd.getColumnFamilies().length with a low-cost implementation. (huaxiang sun)

This commit is contained in:
anoopsamjohn 2016-12-05 13:28:57 +05:30
parent 004f0abb46
commit e10baacd3e
11 changed files with 21 additions and 12 deletions

View File

@ -1197,6 +1197,15 @@ public class HTableDescriptor implements Comparable<HTableDescriptor> {
return Collections.unmodifiableSet(this.families.keySet());
}
/**
* Returns the count of the column families of the table.
*
* @return Count of column families of the table
*/
public int getColumnFamilyCount() {
return families.size();
}
/**
* Returns an array all the {@link HColumnDescriptor} of the column families
* of the table.

View File

@ -733,7 +733,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase {
Admin admin = connection.getAdmin();
try {
if (selected.getColumnFamilies().length < 2) {
if (selected.getColumnFamilyCount() < 2) {
LOG.info("No enough column families to delete in table " + selected.getTableName());
return;
}

View File

@ -1694,7 +1694,7 @@ public class HMaster extends HRegionServer implements MasterServices {
warnOrThrowExceptionForFailure(false, CONF_KEY, e.getMessage(), e);
}
// check that we have at least 1 CF
if (htd.getColumnFamilies().length == 0) {
if (htd.getColumnFamilyCount() == 0) {
String message = "Table should have at least one column family.";
warnOrThrowExceptionForFailure(logWarn, CONF_KEY, message, null);
}

View File

@ -231,7 +231,7 @@ public class CreateTableProcedure
}
// check that we have at least 1 CF
if (hTableDescriptor.getColumnFamilies().length == 0) {
if (hTableDescriptor.getColumnFamilyCount() == 0) {
setFailure("master-create-table", new DoNotRetryIOException("Table " +
getTableName().toString() + " should have at least one column family."));
return false;

View File

@ -242,7 +242,7 @@ public class DeleteColumnFamilyProcedure
+ "' does not exist, so it cannot be deleted");
}
if (unmodifiedHTableDescriptor.getColumnFamilies().length == 1) {
if (unmodifiedHTableDescriptor.getColumnFamilyCount() == 1) {
throw new InvalidFamilyOperationException("Family '" + getColumnFamilyName()
+ "' is the only column family in the table, so it cannot be deleted");
}

View File

@ -237,7 +237,7 @@ public class ModifyTableProcedure
}
// check that we have at least 1 CF
if (modifiedHTableDescriptor.getColumnFamilies().length == 0) {
if (modifiedHTableDescriptor.getColumnFamilyCount() == 0) {
throw new DoNotRetryIOException("Table " + getTableName().toString() +
" should have at least one column family.");
}

View File

@ -326,7 +326,7 @@ public class RestoreSnapshotProcedure
env.getMasterServices().checkTableModifiable(tableName);
// Check that we have at least 1 CF
if (modifiedHTableDescriptor.getColumnFamilies().length == 0) {
if (modifiedHTableDescriptor.getColumnFamilyCount() == 0) {
throw new DoNotRetryIOException("Table " + getTableName().toString() +
" should have at least one column family.");
}

View File

@ -802,7 +802,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
private long initialize(final CancelableProgressable reporter) throws IOException {
//Refuse to open the region if there is no column family in the table
if (htableDescriptor.getColumnFamilies().length == 0) {
if (htableDescriptor.getColumnFamilyCount() == 0) {
throw new DoNotRetryIOException("Table " + htableDescriptor.getNameAsString() +
" should have at least one column family.");
}

View File

@ -246,7 +246,7 @@ public class TestReplicaWithCluster {
HTU.getHBaseAdmin().enableTable(hdt.getTableName());
HTableDescriptor nHdt = HTU.getHBaseAdmin().getTableDescriptor(hdt.getTableName());
Assert.assertEquals("fams=" + Arrays.toString(nHdt.getColumnFamilies()),
bHdt.getColumnFamilies().length + 1, nHdt.getColumnFamilies().length);
bHdt.getColumnFamilyCount() + 1, nHdt.getColumnFamilyCount());
p = new Put(row);
p.addColumn(row, row, row);
@ -270,7 +270,7 @@ public class TestReplicaWithCluster {
Admin admin = HTU.getHBaseAdmin();
nHdt =admin.getTableDescriptor(hdt.getTableName());
Assert.assertEquals("fams=" + Arrays.toString(nHdt.getColumnFamilies()),
bHdt.getColumnFamilies().length + 1, nHdt.getColumnFamilies().length);
bHdt.getColumnFamilyCount() + 1, nHdt.getColumnFamilyCount());
admin.disableTable(hdt.getTableName());
admin.deleteTable(hdt.getTableName());

View File

@ -107,7 +107,7 @@ public class TestDeleteColumnFamilyProcedureFromClient {
assertTrue(admin.isTableAvailable(TABLENAME));
// 2 - Check if all three families exist in descriptor
assertEquals(3, beforehtd.getColumnFamilies().length);
assertEquals(3, beforehtd.getColumnFamilyCount());
HColumnDescriptor[] families = beforehtd.getColumnFamilies();
for (int i = 0; i < families.length; i++) {
assertTrue(families[i].getNameAsString().equals("cf" + (i + 1)));
@ -147,7 +147,7 @@ public class TestDeleteColumnFamilyProcedureFromClient {
// 5 - Check if only 2 column families exist in the descriptor
HTableDescriptor afterhtd = admin.getTableDescriptor(TABLENAME);
assertEquals(2, afterhtd.getColumnFamilies().length);
assertEquals(2, afterhtd.getColumnFamilyCount());
HColumnDescriptor[] newFamilies = afterhtd.getColumnFamilies();
assertTrue(newFamilies[0].getNameAsString().equals("cf1"));
assertTrue(newFamilies[1].getNameAsString().equals("cf3"));

View File

@ -138,7 +138,7 @@ public final class WALPerformanceEvaluation extends Configured implements Tool {
this.numIterations = numIterations;
this.noSync = noSync;
this.syncInterval = syncInterval;
this.numFamilies = htd.getColumnFamilies().length;
this.numFamilies = htd.getColumnFamilyCount();
this.region = region;
this.htd = htd;
scopes = new TreeMap<byte[], Integer>(