Skip to content

Commit c894c8e

Browse files
committed
Use LongAdder instead of AtomicLong for numBlocksCached
1 parent fbb20ec commit c894c8e

File tree

1 file changed

+5
-5
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl

1 file changed

+5
-5
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetCache.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public boolean shouldAdvertise() {
121121
private final HashMap<ExtendedBlockId, Value> mappableBlockMap =
122122
new HashMap<ExtendedBlockId, Value>();
123123

124-
private final AtomicLong numBlocksCached = new AtomicLong(0);
124+
private final LongAdder numBlocksCached = new LongAdder();
125125

126126
private final FsDatasetImpl dataset;
127127

@@ -205,7 +205,7 @@ public void initCache(String bpid) throws IOException {
205205
for (Map.Entry<ExtendedBlockId, MappableBlock> entry : entrySet) {
206206
mappableBlockMap.put(entry.getKey(),
207207
new Value(keyToMappableBlock.get(entry.getKey()), State.CACHED));
208-
numBlocksCached.addAndGet(1);
208+
numBlocksCached.increment();
209209
dataset.datanode.getMetrics().incrBlocksCached(1);
210210
}
211211
}
@@ -470,7 +470,7 @@ public void run() {
470470
dataset.datanode.
471471
getShortCircuitRegistry().processBlockMlockEvent(key);
472472
}
473-
numBlocksCached.addAndGet(1);
473+
numBlocksCached.increment();
474474
dataset.datanode.getMetrics().incrBlocksCached(1);
475475
success = true;
476476
} finally {
@@ -562,7 +562,7 @@ public void run() {
562562
}
563563
long newUsedBytes = cacheLoader.
564564
release(key, value.mappableBlock.getLength());
565-
numBlocksCached.addAndGet(-1);
565+
numBlocksCached.decrement();
566566
dataset.datanode.getMetrics().incrBlocksUncached(1);
567567
if (revocationTimeMs != 0) {
568568
LOG.debug("Uncaching of {} completed. usedBytes = {}",
@@ -616,7 +616,7 @@ public long getNumBlocksFailedToUncache() {
616616
}
617617

618618
public long getNumBlocksCached() {
619-
return numBlocksCached.get();
619+
return numBlocksCached.longValue();
620620
}
621621

622622
public synchronized boolean isCached(String bpid, long blockId) {

0 commit comments

Comments
 (0)