This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new bebc564d5f [core] Make SimpleCounter thread-safe (#8942)
bebc564d5f is described below
commit bebc564d5ff126b081433e0e2d57b9511d9b6088
Author: sanshi <[email protected]>
AuthorDate: Thu Jul 30 23:02:05 2026 +0800
[core] Make SimpleCounter thread-safe (#8942)
---
.../main/java/org/apache/paimon/metrics/SimpleCounter.java | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git
a/paimon-core/src/main/java/org/apache/paimon/metrics/SimpleCounter.java
b/paimon-core/src/main/java/org/apache/paimon/metrics/SimpleCounter.java
index a5ae861cbb..afa641bb57 100644
--- a/paimon-core/src/main/java/org/apache/paimon/metrics/SimpleCounter.java
+++ b/paimon-core/src/main/java/org/apache/paimon/metrics/SimpleCounter.java
@@ -18,16 +18,18 @@
package org.apache.paimon.metrics;
+import java.util.concurrent.atomic.AtomicLong;
+
/** A simple low-overhead {@link org.apache.paimon.metrics.Counter}. */
public class SimpleCounter implements Counter {
/** the current count. */
- private long count;
+ private final AtomicLong count = new AtomicLong();
/** Increment the current count by 1. */
@Override
public void inc() {
- count++;
+ count.incrementAndGet();
}
/**
@@ -37,13 +39,13 @@ public class SimpleCounter implements Counter {
*/
@Override
public void inc(long n) {
- count += n;
+ count.addAndGet(n);
}
/** Decrement the current count by 1. */
@Override
public void dec() {
- count--;
+ count.decrementAndGet();
}
/**
@@ -53,7 +55,7 @@ public class SimpleCounter implements Counter {
*/
@Override
public void dec(long n) {
- count -= n;
+ count.addAndGet(-n);
}
/**
@@ -63,6 +65,6 @@ public class SimpleCounter implements Counter {
*/
@Override
public long getCount() {
- return count;
+ return count.get();
}
}