diff --git a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheGarbageCollector.java b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheGarbageCollector.java index f09c00f57cc687..60b4146137e57a 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheGarbageCollector.java +++ b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheGarbageCollector.java @@ -33,7 +33,7 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutorService; -import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.LongAdder; /** * A garbage collector for the disk cache. @@ -235,8 +235,8 @@ private void visitDirectory(Path path) { /** Deletes disk cache entries, performing I/O in parallel. */ private final class EntryDeleter extends AbstractQueueVisitor { - private final AtomicLong deletedEntries = new AtomicLong(0); - private final AtomicLong deletedBytes = new AtomicLong(0); + private final LongAdder deletedEntries = new LongAdder(); + private final LongAdder deletedBytes = new LongAdder(); EntryDeleter() { super( @@ -252,8 +252,8 @@ void delete(Path path, long size) { () -> { try { if (path.delete()) { - deletedEntries.incrementAndGet(); - deletedBytes.addAndGet(size); + deletedEntries.increment(); + deletedBytes.add(size); } } catch (IOException e) { throw new IORuntimeException(e); @@ -268,7 +268,7 @@ DeletionStats await() throws IOException, InterruptedException { } catch (IORuntimeException e) { throw e.getCauseIOException(); } - return new DeletionStats(deletedEntries.get(), deletedBytes.get()); + return new DeletionStats(deletedEntries.sum(), deletedBytes.sum()); } } }