ghkang98 commented on code in PR #59569:
URL: https://github.com/apache/doris/pull/59569#discussion_r2666766381
##########
fe/fe-core/src/main/java/org/apache/doris/common/MarkedCountDownLatch.java:
##########
@@ -24,73 +24,143 @@
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
-public class MarkedCountDownLatch<K, V> extends CountDownLatch {
+public class MarkedCountDownLatch<K, V> {
+
+ private final Object lock = new Object();
private Multimap<K, V> marks;
private Multimap<K, V> failedMarks;
private Status st = Status.OK;
private int markCount = 0;
+ private CountDownLatch downLatch;
public MarkedCountDownLatch(int count) {
- super(count);
this.markCount = count;
+ this.downLatch = new CountDownLatch(count);
+ marks = HashMultimap.create();
+ failedMarks = HashMultimap.create();
+ }
+
+ public MarkedCountDownLatch() {
marks = HashMultimap.create();
failedMarks = HashMultimap.create();
+ markCount = 0;
+ downLatch = null;
}
public int getMarkCount() {
return markCount;
}
- public synchronized void addMark(K key, V value) {
- marks.put(key, value);
+ public long getCount() {
+ synchronized (lock) {
+ if (downLatch == null) {
+ throw new IllegalStateException("downLatch is not initialize
checkout usage is valid.");
+ }
+ }
+ return downLatch.getCount();
}
- public synchronized boolean markedCountDown(K key, V value) {
- if (marks.remove(key, value)) {
- super.countDown();
- return true;
+ public void countDown() {
+ synchronized (lock) {
+ if (downLatch == null) {
+ throw new IllegalStateException("downLatch is not initialize
checkout usage is valid.");
+ }
}
- return false;
+ downLatch.countDown();
}
- public synchronized boolean markedCountDownWithStatus(K key, V value,
Status status) {
- // update status first before countDown.
- // so that the waiting thread will get the correct status.
- if (st.ok()) {
- st = status;
+ public void addMark(K key, V value) {
+ synchronized (lock) {
+ marks.put(key, value);
Review Comment:
OK,这里可以增加一个判断的,之所以让这个行为存在主要是为了兼容之前的写入,我们可以让使用者在事先就知道目标的count是多少,然后调用有count的构造函数在构建MarkedCountDownLatch时就初始化downLatch,如果可以不兼容这种情况那么是需要在这里限制这种行为的。
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]