Skip to content

Commit

Permalink
Add metric for cached block location
Browse files Browse the repository at this point in the history
Finish the todo task after Alluxio#16953

pr-link: Alluxio#17056
change-id: cid-e6ddc03b08e7a8a18cd53d77fa9a2f0edf4e1f57
  • Loading branch information
maobaolong authored Mar 17, 2023
1 parent 71521f6 commit 73b4d67
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/common/src/main/java/alluxio/metrics/MetricKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ public static String getSyncMetricName(long mountId) {
.setDescription("Total number of unique blocks in Alluxio")
.setMetricType(MetricType.GAUGE)
.build();
public static final MetricKey MASTER_CACHED_BLOCK_LOCATIONS =
new Builder("Master.CachedBlockLocations")
.setDescription("Total number of cached block locations")
.setMetricType(MetricType.GAUGE)
.build();
public static final MetricKey MASTER_TOTAL_RPCS =
new Builder("Master.TotalRpcs")
.setDescription("Throughput of master RPC calls. This metrics indicates how busy the"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class BlockLocationUtils {
private static final IndexDefinition<BlockLocation, Long> WORKER_ID_INDEX =
IndexDefinition.ofNonUnique(BlockLocation::getWorkerId);

// TODO(maobaolong): Add a metric to monitor the size of mLocationCacheMap
private static final IndexedSet<BlockLocation> BLOCK_LOCATION_CACHE =
new IndexedSet<>(OBJECT_INDEX, WORKER_ID_INDEX);

Expand Down Expand Up @@ -84,4 +83,12 @@ public static BlockLocation getCached(BlockLocation blockLocation) {
public static void evictByWorkerId(long workerId) {
BLOCK_LOCATION_CACHE.removeByField(WORKER_ID_INDEX, workerId);
}

/**
* Gets the cached block location size.
* @return the cached block location size
*/
public static int getCachedBlockLocationSize() {
return BLOCK_LOCATION_CACHE.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,9 @@ public static void registerGauges(final DefaultBlockMaster master) {
master::getWorkerCount);
MetricsSystem.registerGaugeIfAbsent(MetricKey.CLUSTER_LOST_WORKERS.getName(),
master::getLostWorkerCount);

MetricsSystem.registerGaugeIfAbsent(MetricKey.MASTER_CACHED_BLOCK_LOCATIONS.getName(),
BlockLocationUtils::getCachedBlockLocationSize);
}

private Metrics() {} // prevent instantiation
Expand Down

0 comments on commit 73b4d67

Please sign in to comment.