ivandika3 commented on code in PR #921:
URL: https://github.com/apache/ratis/pull/921#discussion_r1329447963
##########
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:
Sure, reverted to the original code.
##########
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:
Updated according to the suggested patch diff.
--
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]