This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 5abb53be7b3 Fix sonar issue of ResultIterator (#25640)
5abb53be7b3 is described below
commit 5abb53be7b36e808aceda8b5b2f769d8e84fb2c4
Author: Liang Zhang <[email protected]>
AuthorDate: Sat May 13 20:00:40 2023 +0800
Fix sonar issue of ResultIterator (#25640)
* Fix sonar issue of ResultIterator
* Fix sonar issue of ResultIterator
---
...actStreamingDataConsistencyCalculateAlgorithm.java | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/AbstractStreamingDataConsistencyCalculateAlgorithm.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/AbstractStreamingDataConsistencyCalculateAlgorithm.java
index 41aa4874a30..e0a93d76d3f 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/AbstractStreamingDataConsistencyCalculateAlgorithm.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/AbstractStreamingDataConsistencyCalculateAlgorithm.java
@@ -24,7 +24,9 @@ import
org.apache.shardingsphere.data.pipeline.api.check.consistency.DataConsist
import
org.apache.shardingsphere.data.pipeline.api.check.consistency.DataConsistencyCalculatedResult;
import java.util.Iterator;
+import java.util.NoSuchElementException;
import java.util.Optional;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Streaming data consistency calculate algorithm.
@@ -63,29 +65,28 @@ public abstract class
AbstractStreamingDataConsistencyCalculateAlgorithm extends
@RequiredArgsConstructor
private final class ResultIterator implements
Iterator<DataConsistencyCalculatedResult> {
- private final DataConsistencyCalculateParameter param;
+ private final
AtomicReference<Optional<DataConsistencyCalculatedResult>> nextResult = new
AtomicReference<>();
- private volatile Optional<DataConsistencyCalculatedResult> nextResult;
+ private final DataConsistencyCalculateParameter param;
@Override
public boolean hasNext() {
calculateIfNecessary();
- return nextResult.isPresent();
+ return nextResult.get().isPresent();
}
@Override
public DataConsistencyCalculatedResult next() {
calculateIfNecessary();
- Optional<DataConsistencyCalculatedResult> nextResult =
this.nextResult;
- this.nextResult = null;
- return nextResult.orElse(null);
+ Optional<DataConsistencyCalculatedResult> nextResult =
this.nextResult.get();
+ this.nextResult.set(null);
+ return nextResult.orElseThrow(NoSuchElementException::new);
}
private void calculateIfNecessary() {
- if (null != nextResult) {
- return;
+ if (null == nextResult.get()) {
+ nextResult.set(calculateChunk(param));
}
- nextResult = calculateChunk(param);
}
}
}