fix digest thread_safe bug (#12712)
* fix thread_safe bug * fix thread_safe bug * remove unused * add comment
This commit is contained in:
parent
d2eb2ba3d7
commit
d4856e2b0d
|
|
@ -119,8 +119,6 @@ public class DubboMergingDigest extends DubboAbstractTDigest {
|
|||
// weight limits.
|
||||
public static boolean useWeightLimit = true;
|
||||
|
||||
private volatile boolean merging = false;
|
||||
|
||||
/**
|
||||
* Allocates a buffer merging t-digest. This is the normally used constructor that
|
||||
* allocates default sized internal arrays. Other versions are available, but should
|
||||
|
|
@ -286,16 +284,13 @@ public class DubboMergingDigest extends DubboAbstractTDigest {
|
|||
if (Double.isNaN(x)) {
|
||||
throw new IllegalArgumentException("Cannot add NaN to t-digest");
|
||||
}
|
||||
while (merging) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
|
||||
synchronized (this) {
|
||||
// There is a small probability of entering here
|
||||
if (tempUsed.get() >= tempWeight.length - lastUsedCell.get() - 1) {
|
||||
mergeNewValues();
|
||||
}
|
||||
}
|
||||
if (tempUsed.get() >= tempWeight.length - lastUsedCell.get() - 1) {
|
||||
mergeNewValues();
|
||||
}
|
||||
int where = tempUsed.getAndIncrement();
|
||||
tempWeight[where] = w;
|
||||
tempMean[where] = x;
|
||||
|
|
@ -326,13 +321,8 @@ public class DubboMergingDigest extends DubboAbstractTDigest {
|
|||
throw new MetricsNeverHappenException("Method not used");
|
||||
}
|
||||
|
||||
private synchronized void mergeNewValues() {
|
||||
merging = true;
|
||||
try {
|
||||
mergeNewValues(false, compression);
|
||||
} finally {
|
||||
merging = false;
|
||||
}
|
||||
private void mergeNewValues() {
|
||||
mergeNewValues(false, compression);
|
||||
}
|
||||
|
||||
private void mergeNewValues(boolean force, double compression) {
|
||||
|
|
|
|||
|
|
@ -46,8 +46,9 @@ class TimeWindowQuantileTest {
|
|||
while (index < 100) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
int finalI = i;
|
||||
Assertions.assertDoesNotThrow(() -> quantile.add(finalI));
|
||||
executorService.execute(() ->
|
||||
Assertions.assertDoesNotThrow(() -> quantile.add(finalI)));
|
||||
quantile.add(finalI));
|
||||
}
|
||||
index++;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue