fabriziofortino commented on a change in pull request #309:
URL: https://github.com/apache/jackrabbit-oak/pull/309#discussion_r662324608
##########
File path:
oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentDiskCache.java
##########
@@ -193,16 +188,27 @@ public void cleanUp() {
private void cleanUpInternal() {
if (isCacheFull()) {
try {
- Stream<Path> segmentsPaths = Files.walk(directory.toPath())
+ Stream<SegmentCacheEntry> segmentCacheEntryStream =
Files.walk(directory.toPath())
+ .map(path -> {
+ try {
+ return new SegmentCacheEntry(path,
Files.readAttributes(path, BasicFileAttributes.class).lastAccessTime());
+ } catch (IOException e) {
+ logger.error("Error while getting the last
access time for {}", path.toFile().getName());
+ }
+ return new SegmentCacheEntry(null,
FileTime.fromMillis(Long.MAX_VALUE));
+ })
.sorted(sortedByAccessTime)
- .filter(filePath -> !filePath.toFile().isDirectory());
+ .filter(segmentCacheEntry ->
!segmentCacheEntry.getPath().toFile().isDirectory());
Review comment:
I think this filter can be moved before the first `map()`: there is no
need to create `SegmentCacheEntry` for folders.
##########
File path:
oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentDiskCache.java
##########
@@ -193,16 +188,27 @@ public void cleanUp() {
private void cleanUpInternal() {
if (isCacheFull()) {
try {
- Stream<Path> segmentsPaths = Files.walk(directory.toPath())
+ Stream<SegmentCacheEntry> segmentCacheEntryStream =
Files.walk(directory.toPath())
+ .map(path -> {
+ try {
+ return new SegmentCacheEntry(path,
Files.readAttributes(path, BasicFileAttributes.class).lastAccessTime());
+ } catch (IOException e) {
+ logger.error("Error while getting the last
access time for {}", path.toFile().getName());
+ }
+ return new SegmentCacheEntry(null,
FileTime.fromMillis(Long.MAX_VALUE));
+ })
.sorted(sortedByAccessTime)
- .filter(filePath -> !filePath.toFile().isDirectory());
+ .filter(segmentCacheEntry ->
!segmentCacheEntry.getPath().toFile().isDirectory());
- StreamConsumer.forEach(segmentsPaths, (path, breaker) -> {
+ StreamConsumer.forEach(segmentCacheEntryStream,
(segmentCacheEntry, breaker) -> {
if (cacheSize.get() > maxCacheSizeBytes * 0.66) {
- cacheSize.addAndGet(-path.toFile().length());
- path.toFile().delete();
- evictionCount.incrementAndGet();
+ if (segmentCacheEntry.getPath() != null) { // it can
be null if error has occurred while processing the stream
Review comment:
this won't be needed if we always return the path
##########
File path:
oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentDiskCache.java
##########
@@ -193,16 +188,27 @@ public void cleanUp() {
private void cleanUpInternal() {
if (isCacheFull()) {
try {
- Stream<Path> segmentsPaths = Files.walk(directory.toPath())
+ Stream<SegmentCacheEntry> segmentCacheEntryStream =
Files.walk(directory.toPath())
+ .map(path -> {
+ try {
+ return new SegmentCacheEntry(path,
Files.readAttributes(path, BasicFileAttributes.class).lastAccessTime());
+ } catch (IOException e) {
+ logger.error("Error while getting the last
access time for {}", path.toFile().getName());
+ }
+ return new SegmentCacheEntry(null,
FileTime.fromMillis(Long.MAX_VALUE));
Review comment:
I think it would be better to return the actual path here. If for some
weird reason we cannot read any lastAccessTime we won't be able to clean up the
cache at all.
```suggestion
return new SegmentCacheEntry(path,
FileTime.fromMillis(Long.MAX_VALUE));
```
##########
File path:
oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentDiskCache.java
##########
@@ -213,6 +219,23 @@ private void cleanUpInternal() {
}
}
+ private class SegmentCacheEntry {
Review comment:
cosmetics: since this class is internal, we could have the members as
`public final` and remove the getters to be more concise.
--
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]