szetszwo commented on code in PR #921:
URL: https://github.com/apache/ratis/pull/921#discussion_r1329228118
##########
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogCache.java:
##########
@@ -178,12 +198,21 @@ long getTotalFileSize() {
return sizeInBytes;
}
- long getTotalCacheSize() {
- return segments.stream().mapToLong(LogSegment::getTotalCacheSize).sum();
+ LogSegmentListCacheInfo getCacheInfo() {
+ long totalCacheSize = 0L;
+ long cachedCount = 0L;
+ for (LogSegment segment: segments) {
+ if (segment.hasCache()) {
+ cachedCount++;
+ }
+ // TODO: Should we only increment when hasCache = true?
+ totalCacheSize += segment.getTotalCacheSize();
+ }
+ return new LogSegmentListCacheInfo(totalCacheSize, cachedCount);
}
long countCached() {
- return segments.stream().filter(LogSegment::hasCache).count();
+ return getCacheInfo().getCachedCount();
Review Comment:
Let's keep the original code for `raftLogMetrics`. It only needs the count.
##########
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogCache.java:
##########
@@ -397,13 +426,17 @@ long getOpenSegmentSizeInBytes() {
return openSegment == null ? 0 : openSegment.getTotalFileSize();
}
- private long getTotalCacheSize() {
- return closedSegments.getTotalCacheSize() +
-
Optional.ofNullable(openSegment).map(LogSegment::getTotalCacheSize).orElse(0L);
+ private long getTotalCacheSize(LogSegmentListCacheInfo
+ closedSegmentsCacheInfo) {
+ return closedSegmentsCacheInfo.getTotalCacheSize() +
+
Optional.ofNullable(openSegment).map(LogSegment::getTotalCacheSize).orElse(0L);
Review Comment:
Let's combine this method with `shouldEvict()`.
##########
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogCache.java:
##########
@@ -178,12 +198,21 @@ long getTotalFileSize() {
return sizeInBytes;
}
- long getTotalCacheSize() {
- return segments.stream().mapToLong(LogSegment::getTotalCacheSize).sum();
+ LogSegmentListCacheInfo getCacheInfo() {
+ long totalCacheSize = 0L;
+ long cachedCount = 0L;
+ for (LogSegment segment: segments) {
+ if (segment.hasCache()) {
+ cachedCount++;
+ }
+ // TODO: Should we only increment when hasCache = true?
Review Comment:
Although the result should the same, it seems better to increment when
hasCache = true.
##########
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogCache.java:
##########
@@ -145,6 +146,25 @@ public String toString() {
}
static class LogSegmentList {
+
+ static class LogSegmentListCacheInfo {
Review Comment:
Let's move it one level up and simply call it `CacheInfo`.
##########
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogCache.java:
##########
@@ -145,6 +146,25 @@ public String toString() {
}
static class LogSegmentList {
+
+ static class LogSegmentListCacheInfo {
+ private final long totalCacheSize;
+ private final long cachedCount;
Review Comment:
Let's simply call it `size` and `count` and add javadoc.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]