HBASE-22459 Expose store reader reference count (#248)

This commit is contained in:
Andrew Purtell 2019-05-30 15:04:16 -07:00
parent 89260f4f3e
commit d06c3af980
No known key found for this signature in database
GPG Key ID: 8597754DD5365CCD
12 changed files with 79 additions and 1 deletions

View File

@ -358,6 +358,13 @@ public class RegionLoad implements RegionMetrics {
return metrics.getLastMajorCompactionTimestamp();
}
/**
* @return the reference count for the stores of this region
*/
public int getStoreRefCount() {
return metrics.getStoreRefCount();
}
/**
* @see java.lang.Object#toString()
*/
@ -366,6 +373,7 @@ public class RegionLoad implements RegionMetrics {
StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "numberOfStores",
this.getStores());
Strings.appendKeyValue(sb, "numberOfStorefiles", this.getStorefiles());
Strings.appendKeyValue(sb, "storeRefCount", this.getStoreRefCount());
Strings.appendKeyValue(sb, "storefileUncompressedSizeMB",
this.getStoreUncompressedSizeMB());
Strings.appendKeyValue(sb, "lastMajorCompactionTimestamp",

View File

@ -144,4 +144,8 @@ public interface RegionMetrics {
*/
long getLastMajorCompactionTimestamp();
/**
* @return the reference count for the stores of this region
*/
int getStoreRefCount();
}

View File

@ -64,6 +64,7 @@ public final class RegionMetricsBuilder {
Size.Unit.KILOBYTE))
.setStoreCount(regionLoadPB.getStores())
.setStoreFileCount(regionLoadPB.getStorefiles())
.setStoreRefCount(regionLoadPB.getStoreRefCount())
.setStoreFileSize(new Size(regionLoadPB.getStorefileSizeMB(), Size.Unit.MEGABYTE))
.setStoreSequenceIds(regionLoadPB.getStoreCompleteSequenceIdList().stream()
.collect(Collectors.toMap(
@ -109,6 +110,7 @@ public final class RegionMetricsBuilder {
.get(Size.Unit.KILOBYTE))
.setStores(regionMetrics.getStoreCount())
.setStorefiles(regionMetrics.getStoreCount())
.setStoreRefCount(regionMetrics.getStoreRefCount())
.setStorefileSizeMB((int) regionMetrics.getStoreFileSize().get(Size.Unit.MEGABYTE))
.addAllStoreCompleteSequenceId(toStoreSequenceId(regionMetrics.getStoreSequenceId()))
.setStoreUncompressedSizeMB(
@ -123,6 +125,7 @@ public final class RegionMetricsBuilder {
private final byte[] name;
private int storeCount;
private int storeFileCount;
private int storeRefCount;
private long compactingCellCount;
private long compactedCellCount;
private Size storeFileSize = Size.ZERO;
@ -151,6 +154,10 @@ public final class RegionMetricsBuilder {
this.storeFileCount = value;
return this;
}
public RegionMetricsBuilder setStoreRefCount(int value) {
this.storeRefCount = value;
return this;
}
public RegionMetricsBuilder setCompactingCellCount(long value) {
this.compactingCellCount = value;
return this;
@ -220,6 +227,7 @@ public final class RegionMetricsBuilder {
return new RegionMetricsImpl(name,
storeCount,
storeFileCount,
storeRefCount,
compactingCellCount,
compactedCellCount,
storeFileSize,
@ -242,6 +250,7 @@ public final class RegionMetricsBuilder {
private final byte[] name;
private final int storeCount;
private final int storeFileCount;
private final int storeRefCount;
private final long compactingCellCount;
private final long compactedCellCount;
private final Size storeFileSize;
@ -261,6 +270,7 @@ public final class RegionMetricsBuilder {
RegionMetricsImpl(byte[] name,
int storeCount,
int storeFileCount,
int storeRefCount,
final long compactingCellCount,
long compactedCellCount,
Size storeFileSize,
@ -280,6 +290,7 @@ public final class RegionMetricsBuilder {
this.name = Preconditions.checkNotNull(name);
this.storeCount = storeCount;
this.storeFileCount = storeFileCount;
this.storeRefCount = storeRefCount;
this.compactingCellCount = compactingCellCount;
this.compactedCellCount = compactedCellCount;
this.storeFileSize = Preconditions.checkNotNull(storeFileSize);
@ -313,6 +324,11 @@ public final class RegionMetricsBuilder {
return storeFileCount;
}
@Override
public int getStoreRefCount() {
return storeRefCount;
}
@Override
public Size getStoreFileSize() {
return storeFileSize;
@ -399,6 +415,8 @@ public final class RegionMetricsBuilder {
this.getStoreCount());
Strings.appendKeyValue(sb, "storeFileCount",
this.getStoreFileCount());
Strings.appendKeyValue(sb, "storeRefCount",
this.getStoreRefCount());
Strings.appendKeyValue(sb, "uncompressedStoreFileSize",
this.getUncompressedStoreFileSize());
Strings.appendKeyValue(sb, "lastMajorCompactionTimestamp",

View File

@ -231,6 +231,8 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
String WALFILE_SIZE_DESC = "Size of all WAL Files";
String STOREFILE_COUNT = "storeFileCount";
String STOREFILE_COUNT_DESC = "Number of Store Files";
String STORE_REF_COUNT = "storeRefCount";
String STORE_REF_COUNT_DESC = "Store reference count";
String MEMSTORE_SIZE = "memStoreSize";
String MEMSTORE_SIZE_DESC = "Size of the memstore";
String STOREFILE_SIZE = "storeFileSize";

View File

@ -152,4 +152,9 @@ public interface MetricsRegionWrapper {
* Get the replica id of this region.
*/
int getReplicaId();
/**
* @return the number of references active on the store
*/
long getStoreRefCount();
}

View File

@ -213,6 +213,10 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
regionNamePrefix + MetricsRegionServerSource.STOREFILE_COUNT,
MetricsRegionServerSource.STOREFILE_COUNT_DESC),
this.regionWrapper.getNumStoreFiles());
mrb.addGauge(Interns.info(
regionNamePrefix + MetricsRegionServerSource.STORE_REF_COUNT,
MetricsRegionServerSource.STORE_REF_COUNT),
this.regionWrapper.getStoreRefCount());
mrb.addGauge(Interns.info(
regionNamePrefix + MetricsRegionServerSource.MEMSTORE_SIZE,
MetricsRegionServerSource.MEMSTORE_SIZE_DESC),

View File

@ -94,6 +94,11 @@ public class TestMetricsRegionSourceImpl {
return 0;
}
@Override
public long getStoreRefCount() {
return 0;
}
@Override
public long getMemStoreSize() {
return 0;

View File

@ -143,6 +143,12 @@ message RegionLoad {
/** the current total filtered read requests made to region */
optional uint64 filtered_read_requests_count = 19;
/** master defines cp_requests_count = 20, the current total coprocessor
requests made to region */
/** the number of references active on the store */
optional int32 store_ref_count = 21 [default = 0];
}
/* Server-level protobufs */

View File

@ -139,6 +139,12 @@ message RegionLoad {
/** the current total filtered read requests made to region */
optional uint64 filtered_read_requests_count = 19;
/** master defines cp_requests_count = 20, the current total coprocessor
requests made to region */
/** the number of references active on the store */
optional int32 store_ref_count = 21 [default = 0];
}
/* Server-level protobufs */

View File

@ -2668,4 +2668,10 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat
public int getCurrentParallelPutCount() {
return currentParallelPutCount.get();
}
public int getStoreRefCount() {
return this.storeEngine.getStoreFileManager().getStorefiles().stream()
.filter(sf -> sf.getReader() != null).filter(HStoreFile::isHFile)
.mapToInt(HStoreFile::getRefCount).sum();
}
}

View File

@ -48,6 +48,7 @@ public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable
private ScheduledExecutorService executor;
private Runnable runnable;
private long numStoreFiles;
private long storeRefCount;
private long memstoreSize;
private long storeFileSize;
private long maxStoreFileAge;
@ -119,6 +120,11 @@ public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable
return storeFileSize;
}
@Override
public long getStoreRefCount() {
return storeRefCount;
}
@Override
public long getReadRequestCount() {
return this.region.getReadRequestsCount();
@ -221,6 +227,7 @@ public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable
@Override
public void run() {
long tempNumStoreFiles = 0;
int tempStoreRefCount = 0;
long tempMemstoreSize = 0;
long tempStoreFileSize = 0;
long tempMaxStoreFileAge = 0;
@ -232,8 +239,9 @@ public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable
long avgAgeNumerator = 0;
long numHFiles = 0;
if (region.stores != null) {
for (Store store : region.stores.values()) {
for (HStore store : region.stores.values()) {
tempNumStoreFiles += store.getStorefilesCount();
tempStoreRefCount += store.getStoreRefCount();
tempMemstoreSize += store.getMemStoreSize().getDataSize();
tempStoreFileSize += store.getStorefilesSize();
OptionalLong storeMaxStoreFileAge = store.getMaxStoreFileAge();
@ -260,6 +268,7 @@ public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable
}
numStoreFiles = tempNumStoreFiles;
storeRefCount = tempStoreRefCount;
memstoreSize = tempMemstoreSize;
storeFileSize = tempStoreFileSize;
maxStoreFileAge = tempMaxStoreFileAge;

View File

@ -60,6 +60,11 @@ public class MetricsRegionWrapperStub implements MetricsRegionWrapper {
return 102;
}
@Override
public long getStoreRefCount() {
return 0;
}
@Override
public long getMemStoreSize() {
return 103;