Skip to content

Commit d06c3af

Browse files
committed
HBASE-22459 Expose store reader reference count (#248)
1 parent 89260f4 commit d06c3af

12 files changed

Lines changed: 79 additions & 1 deletion

File tree

hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLoad.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@ public long getLastMajorCompactionTs() {
358358
return metrics.getLastMajorCompactionTimestamp();
359359
}
360360

361+
/**
362+
* @return the reference count for the stores of this region
363+
*/
364+
public int getStoreRefCount() {
365+
return metrics.getStoreRefCount();
366+
}
367+
361368
/**
362369
* @see java.lang.Object#toString()
363370
*/
@@ -366,6 +373,7 @@ public String toString() {
366373
StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "numberOfStores",
367374
this.getStores());
368375
Strings.appendKeyValue(sb, "numberOfStorefiles", this.getStorefiles());
376+
Strings.appendKeyValue(sb, "storeRefCount", this.getStoreRefCount());
369377
Strings.appendKeyValue(sb, "storefileUncompressedSizeMB",
370378
this.getStoreUncompressedSizeMB());
371379
Strings.appendKeyValue(sb, "lastMajorCompactionTimestamp",

hbase-client/src/main/java/org/apache/hadoop/hbase/RegionMetrics.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,8 @@ default String getNameAsString() {
144144
*/
145145
long getLastMajorCompactionTimestamp();
146146

147+
/**
148+
* @return the reference count for the stores of this region
149+
*/
150+
int getStoreRefCount();
147151
}

hbase-client/src/main/java/org/apache/hadoop/hbase/RegionMetricsBuilder.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static RegionMetrics toRegionMetrics(ClusterStatusProtos.RegionLoad regio
6464
Size.Unit.KILOBYTE))
6565
.setStoreCount(regionLoadPB.getStores())
6666
.setStoreFileCount(regionLoadPB.getStorefiles())
67+
.setStoreRefCount(regionLoadPB.getStoreRefCount())
6768
.setStoreFileSize(new Size(regionLoadPB.getStorefileSizeMB(), Size.Unit.MEGABYTE))
6869
.setStoreSequenceIds(regionLoadPB.getStoreCompleteSequenceIdList().stream()
6970
.collect(Collectors.toMap(
@@ -109,6 +110,7 @@ public static ClusterStatusProtos.RegionLoad toRegionLoad(RegionMetrics regionMe
109110
.get(Size.Unit.KILOBYTE))
110111
.setStores(regionMetrics.getStoreCount())
111112
.setStorefiles(regionMetrics.getStoreCount())
113+
.setStoreRefCount(regionMetrics.getStoreRefCount())
112114
.setStorefileSizeMB((int) regionMetrics.getStoreFileSize().get(Size.Unit.MEGABYTE))
113115
.addAllStoreCompleteSequenceId(toStoreSequenceId(regionMetrics.getStoreSequenceId()))
114116
.setStoreUncompressedSizeMB(
@@ -123,6 +125,7 @@ public static RegionMetricsBuilder newBuilder(byte[] name) {
123125
private final byte[] name;
124126
private int storeCount;
125127
private int storeFileCount;
128+
private int storeRefCount;
126129
private long compactingCellCount;
127130
private long compactedCellCount;
128131
private Size storeFileSize = Size.ZERO;
@@ -151,6 +154,10 @@ public RegionMetricsBuilder setStoreFileCount(int value) {
151154
this.storeFileCount = value;
152155
return this;
153156
}
157+
public RegionMetricsBuilder setStoreRefCount(int value) {
158+
this.storeRefCount = value;
159+
return this;
160+
}
154161
public RegionMetricsBuilder setCompactingCellCount(long value) {
155162
this.compactingCellCount = value;
156163
return this;
@@ -220,6 +227,7 @@ public RegionMetrics build() {
220227
return new RegionMetricsImpl(name,
221228
storeCount,
222229
storeFileCount,
230+
storeRefCount,
223231
compactingCellCount,
224232
compactedCellCount,
225233
storeFileSize,
@@ -242,6 +250,7 @@ private static class RegionMetricsImpl implements RegionMetrics {
242250
private final byte[] name;
243251
private final int storeCount;
244252
private final int storeFileCount;
253+
private final int storeRefCount;
245254
private final long compactingCellCount;
246255
private final long compactedCellCount;
247256
private final Size storeFileSize;
@@ -261,6 +270,7 @@ private static class RegionMetricsImpl implements RegionMetrics {
261270
RegionMetricsImpl(byte[] name,
262271
int storeCount,
263272
int storeFileCount,
273+
int storeRefCount,
264274
final long compactingCellCount,
265275
long compactedCellCount,
266276
Size storeFileSize,
@@ -280,6 +290,7 @@ private static class RegionMetricsImpl implements RegionMetrics {
280290
this.name = Preconditions.checkNotNull(name);
281291
this.storeCount = storeCount;
282292
this.storeFileCount = storeFileCount;
293+
this.storeRefCount = storeRefCount;
283294
this.compactingCellCount = compactingCellCount;
284295
this.compactedCellCount = compactedCellCount;
285296
this.storeFileSize = Preconditions.checkNotNull(storeFileSize);
@@ -313,6 +324,11 @@ public int getStoreFileCount() {
313324
return storeFileCount;
314325
}
315326

327+
@Override
328+
public int getStoreRefCount() {
329+
return storeRefCount;
330+
}
331+
316332
@Override
317333
public Size getStoreFileSize() {
318334
return storeFileSize;
@@ -399,6 +415,8 @@ public String toString() {
399415
this.getStoreCount());
400416
Strings.appendKeyValue(sb, "storeFileCount",
401417
this.getStoreFileCount());
418+
Strings.appendKeyValue(sb, "storeRefCount",
419+
this.getStoreRefCount());
402420
Strings.appendKeyValue(sb, "uncompressedStoreFileSize",
403421
this.getUncompressedStoreFileSize());
404422
Strings.appendKeyValue(sb, "lastMajorCompactionTimestamp",

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
231231
String WALFILE_SIZE_DESC = "Size of all WAL Files";
232232
String STOREFILE_COUNT = "storeFileCount";
233233
String STOREFILE_COUNT_DESC = "Number of Store Files";
234+
String STORE_REF_COUNT = "storeRefCount";
235+
String STORE_REF_COUNT_DESC = "Store reference count";
234236
String MEMSTORE_SIZE = "memStoreSize";
235237
String MEMSTORE_SIZE_DESC = "Size of the memstore";
236238
String STOREFILE_SIZE = "storeFileSize";

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,9 @@ public interface MetricsRegionWrapper {
152152
* Get the replica id of this region.
153153
*/
154154
int getReplicaId();
155+
156+
/**
157+
* @return the number of references active on the store
158+
*/
159+
long getStoreRefCount();
155160
}

hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ void snapshot(MetricsRecordBuilder mrb, boolean ignored) {
213213
regionNamePrefix + MetricsRegionServerSource.STOREFILE_COUNT,
214214
MetricsRegionServerSource.STOREFILE_COUNT_DESC),
215215
this.regionWrapper.getNumStoreFiles());
216+
mrb.addGauge(Interns.info(
217+
regionNamePrefix + MetricsRegionServerSource.STORE_REF_COUNT,
218+
MetricsRegionServerSource.STORE_REF_COUNT),
219+
this.regionWrapper.getStoreRefCount());
216220
mrb.addGauge(Interns.info(
217221
regionNamePrefix + MetricsRegionServerSource.MEMSTORE_SIZE,
218222
MetricsRegionServerSource.MEMSTORE_SIZE_DESC),

hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public long getNumStoreFiles() {
9494
return 0;
9595
}
9696

97+
@Override
98+
public long getStoreRefCount() {
99+
return 0;
100+
}
101+
97102
@Override
98103
public long getMemStoreSize() {
99104
return 0;

hbase-protocol-shaded/src/main/protobuf/ClusterStatus.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ message RegionLoad {
143143

144144
/** the current total filtered read requests made to region */
145145
optional uint64 filtered_read_requests_count = 19;
146+
147+
/** master defines cp_requests_count = 20, the current total coprocessor
148+
requests made to region */
149+
150+
/** the number of references active on the store */
151+
optional int32 store_ref_count = 21 [default = 0];
146152
}
147153

148154
/* Server-level protobufs */

hbase-protocol/src/main/protobuf/ClusterStatus.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ message RegionLoad {
139139

140140
/** the current total filtered read requests made to region */
141141
optional uint64 filtered_read_requests_count = 19;
142+
143+
/** master defines cp_requests_count = 20, the current total coprocessor
144+
requests made to region */
145+
146+
/** the number of references active on the store */
147+
optional int32 store_ref_count = 21 [default = 0];
142148
}
143149

144150
/* Server-level protobufs */

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,4 +2668,10 @@ private void clearCompactedfiles(List<HStoreFile> filesToRemove) throws IOExcept
26682668
public int getCurrentParallelPutCount() {
26692669
return currentParallelPutCount.get();
26702670
}
2671+
2672+
public int getStoreRefCount() {
2673+
return this.storeEngine.getStoreFileManager().getStorefiles().stream()
2674+
.filter(sf -> sf.getReader() != null).filter(HStoreFile::isHFile)
2675+
.mapToInt(HStoreFile::getRefCount).sum();
2676+
}
26712677
}

0 commit comments

Comments
 (0)