Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vthacker committed Sep 8, 2023
1 parent 8988fc1 commit 26007d3
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ public DiskOrMessageCountBasedRolloverStrategy(
this.liveBytesDirGauge = this.registry.gauge(LIVE_BYTES_DIR, new AtomicLong(0));

directorySizeExecutorService.scheduleAtFixedRate(
this::calculateDirectorySize,
() -> {
var dirSize = calculateDirectorySize(activeChunkDirectory);
// in case the method fails to calculate we return -1 so don't update the old value
if (dirSize > 0) {
approximateDirectoryBytes.set(dirSize);
}
},
DIRECTORY_SIZE_EXECUTOR_PERIOD_MS,
DIRECTORY_SIZE_EXECUTOR_PERIOD_MS,
TimeUnit.MILLISECONDS);
Expand Down Expand Up @@ -89,10 +95,10 @@ public long getMaxBytesPerChunk() {
@Override
public void setActiveChunkDirectory(FSDirectory directory) {
this.activeChunkDirectory.set(directory);
this.approximateDirectoryBytes.set(0);
approximateDirectoryBytes.set(0);
}

public void calculateDirectorySize() {
public static long calculateDirectorySize(AtomicReference<FSDirectory> activeChunkDirectory) {
try {
FSDirectory activeChunkDir = activeChunkDirectory.get();
if (activeChunkDir != null && activeChunkDir.listAll().length > 0) {
Expand All @@ -111,11 +117,12 @@ public void calculateDirectorySize() {
}
})
.sum();
approximateDirectoryBytes.set(directorySize);
return directorySize;
}
} catch (Exception e) {
LOG.error("Error calculating the directory size", e);
}
return -1;
}

@Override
Expand Down

0 comments on commit 26007d3

Please sign in to comment.