Skip to content

Commit

Permalink
HBASE-25569 Adding region count and average region size in a table at…
Browse files Browse the repository at this point in the history
… regionserver level (#2948)

Signed-off-by: Viraj Jasani <[email protected]>
  • Loading branch information
mnpoonia authored Feb 13, 2021
1 parent 7d80d99 commit e2a00af
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ public interface MetricsTableWrapperAggregate {
* Get the table region size against this table
*/
long getTableSize(String table);

/**
* Get the average region size for this table
*/
long getAvgRegionSize(String table);

/**
* Get the number of regions hosted on for this table
*/
long getNumRegions(String table);
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ void snapshot(MetricsRecordBuilder mrb, boolean ignored) {
mrb.addGauge(Interns.info(tableNamePrefix + MetricsTableSource.TABLE_SIZE,
MetricsTableSource.TABLE_SIZE_DESC),
tableWrapperAgg.getTableSize(tableName.getNameAsString()));
mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.AVERAGE_REGION_SIZE,
MetricsRegionServerSource.AVERAGE_REGION_SIZE_DESC),
tableWrapperAgg.getAvgRegionSize(tableName.getNameAsString()));
mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.REGION_COUNT,
MetricsRegionServerSource.REGION_COUNT_DESC),
tableWrapperAgg.getNumRegions(tableName.getNameAsString()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public long getTableSize(String table) {
return 3000;
}

@Override
public long getNumRegions(String table) {
return 3;
}

@Override
public long getAvgRegionSize(String table) {
return 3000;
}

public String getTableName() {
return tableName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ public void run() {
}
metricsTable.setMemstoresSize(metricsTable.getMemstoresSize() + r.getMemstoreSize());
metricsTable.setStoreFilesSize(metricsTable.getStoreFilesSize() + tempStorefilesSize);
metricsTable.setTableSize(metricsTable.getMemstoresSize() + metricsTable.getStoreFilesSize());
metricsTable.setReadRequestsCount(metricsTable.getReadRequestsCount() + r.getReadRequestsCount());
metricsTable.setWriteRequestsCount(metricsTable.getWriteRequestsCount() + r.getWriteRequestsCount());
metricsTable.setTotalRequestsCount(metricsTable.getReadRequestsCount() + metricsTable.getWriteRequestsCount());
metricsTable
.setTableSize(metricsTable.getMemstoresSize() + metricsTable.getStoreFilesSize());
metricsTable
.setReadRequestsCount(metricsTable.getReadRequestsCount() + r.getReadRequestsCount());
metricsTable.setWriteRequestsCount(
metricsTable.getWriteRequestsCount() + r.getWriteRequestsCount());
metricsTable.setTotalRequestsCount(
metricsTable.getReadRequestsCount() + metricsTable.getWriteRequestsCount());
metricsTable.setRegionCount(metricsTable.getRegionCount() + 1);
}

for(Map.Entry<TableName, MetricsTableValues> entry : localMetricsTableMap.entrySet()) {
Expand Down Expand Up @@ -108,55 +113,75 @@ public void run() {
@Override
public long getReadRequestsCount(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null)
if (metricsTable == null) {
return 0;
else
return metricsTable.getReadRequestsCount();
}
return metricsTable.getReadRequestsCount();
}

@Override
public long getWriteRequestsCount(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null)
if (metricsTable == null) {
return 0;
else
return metricsTable.getWriteRequestsCount();
}
return metricsTable.getWriteRequestsCount();
}

@Override
public long getTotalRequestsCount(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null)
if (metricsTable == null) {
return 0;
else
return metricsTable.getTotalRequestsCount();
}
return metricsTable.getTotalRequestsCount();
}

@Override
public long getMemstoresSize(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null)
if (metricsTable == null) {
return 0;
else
return metricsTable.getMemstoresSize();
}
return metricsTable.getMemstoresSize();
}

@Override
public long getStoreFilesSize(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null)
if (metricsTable == null) {
return 0;
else
return metricsTable.getStoreFilesSize();
}
return metricsTable.getStoreFilesSize();
}

@Override
public long getTableSize(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null)
if (metricsTable == null) {
return 0;
}
return metricsTable.getTableSize();
}

@Override
public long getNumRegions(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null) {
return 0;
else
return metricsTable.getTableSize();
}
return metricsTable.regionCount;
}

@Override
public long getAvgRegionSize(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null) {
return 0;
}
return metricsTable.regionCount == 0 ? 0
: (metricsTable.getMemstoresSize() + metricsTable.getStoreFilesSize())
/ metricsTable.getRegionCount();
}

@Override
Expand All @@ -172,6 +197,7 @@ private static class MetricsTableValues {
private long memstoresSize;
private long storeFilesSize;
private long tableSize;
private long regionCount;

public long getTotalRequestsCount() {
return totalRequestsCount;
Expand Down Expand Up @@ -220,6 +246,14 @@ public long getTableSize() {
public void setTableSize(long tableSize) {
this.tableSize = tableSize;
}

public long getRegionCount() {
return regionCount;
}

public void setRegionCount(long regionCount) {
this.regionCount = regionCount;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,14 @@ public long getTableSize(String table) {
public String getTableName() {
return tableName;
}

@Override
public long getNumRegions(String table) {
return 11;
}

@Override
public long getAvgRegionSize(String table) {
return 22;
}
}

0 comments on commit e2a00af

Please sign in to comment.