|
16 | 16 | package org.springframework.data.redis.connection;
|
17 | 17 |
|
18 | 18 | import java.util.*;
|
19 |
| -import java.util.Map.Entry; |
20 | 19 | import java.util.concurrent.Callable;
|
21 | 20 | import java.util.concurrent.ExecutionException;
|
22 | 21 | import java.util.concurrent.Future;
|
@@ -227,48 +226,39 @@ public <S, T> MultiNodeResult<T> executeCommandAsyncOnNodes(ClusterCommandCallba
|
227 | 226 |
|
228 | 227 | <T> MultiNodeResult<T> collectResults(Map<NodeExecution, Future<NodeResult<T>>> futures) {
|
229 | 228 |
|
230 |
| - NodeExceptionCollector exceptionCollector = new NodeExceptionCollector(); |
231 | 229 | MultiNodeResult<T> result = new MultiNodeResult<>();
|
232 |
| - Object placeholder = new Object(); |
233 |
| - Map<Future<NodeResult<T>>, Object> safeguard = new IdentityHashMap<>(); |
| 230 | + NodeExceptionCollector exceptionCollector = new NodeExceptionCollector(); |
| 231 | + |
| 232 | + OUT: while (!futures.isEmpty()) { |
234 | 233 |
|
235 |
| - for (;;) { |
| 234 | + Iterator<Map.Entry<NodeExecution, Future<NodeResult<T>>>> entryIterator = futures.entrySet().iterator(); |
236 | 235 |
|
237 |
| - boolean timeout = false; |
238 |
| - for (Map.Entry<NodeExecution, Future<NodeResult<T>>> entry : futures.entrySet()) { |
| 236 | + while (entryIterator.hasNext()) { |
239 | 237 |
|
| 238 | + Map.Entry<NodeExecution, Future<NodeResult<T>>> entry = entryIterator.next(); |
240 | 239 | NodeExecution nodeExecution = entry.getKey();
|
241 | 240 | Future<NodeResult<T>> futureNodeResult = entry.getValue();
|
242 | 241 |
|
243 | 242 | try {
|
| 243 | + NodeResult<T> nodeResult = futureNodeResult.get(10L, TimeUnit.MICROSECONDS); |
244 | 244 |
|
245 |
| - if (!safeguard.containsKey(futureNodeResult)) { |
246 |
| - |
247 |
| - NodeResult<T> nodeResult = futureNodeResult.get(10L, TimeUnit.MICROSECONDS); |
248 |
| - |
249 |
| - if (nodeExecution.isPositional()) { |
250 |
| - result.add(nodeExecution.getPositionalKey(), nodeResult); |
251 |
| - } else { |
252 |
| - result.add(nodeResult); |
253 |
| - } |
254 |
| - |
255 |
| - safeguard.put(futureNodeResult, placeholder); |
| 245 | + if (nodeExecution.isPositional()) { |
| 246 | + result.add(nodeExecution.getPositionalKey(), nodeResult); |
| 247 | + } else { |
| 248 | + result.add(nodeResult); |
256 | 249 | }
|
| 250 | + |
| 251 | + entryIterator.remove(); |
257 | 252 | } catch (ExecutionException exception) {
|
258 |
| - safeguard.put(futureNodeResult, placeholder); |
| 253 | + entryIterator.remove(); |
259 | 254 | exceptionCollector.addException(nodeExecution, exception.getCause());
|
260 | 255 | } catch (TimeoutException ignore) {
|
261 |
| - timeout = true; |
262 | 256 | } catch (InterruptedException exception) {
|
263 | 257 | Thread.currentThread().interrupt();
|
264 | 258 | exceptionCollector.addException(nodeExecution, exception);
|
265 |
| - break; |
| 259 | + break OUT; |
266 | 260 | }
|
267 | 261 | }
|
268 |
| - |
269 |
| - if (!timeout) { |
270 |
| - break; |
271 |
| - } |
272 | 262 | }
|
273 | 263 |
|
274 | 264 | if (exceptionCollector.hasExceptions()) {
|
@@ -300,7 +290,7 @@ public <S, T> MultiNodeResult<T> executeMultiKeyCommand(MultiKeyClusterCommandCa
|
300 | 290 |
|
301 | 291 | Map<NodeExecution, Future<NodeResult<T>>> futures = new LinkedHashMap<>();
|
302 | 292 |
|
303 |
| - for (Entry<RedisClusterNode, PositionalKeys> entry : nodeKeyMap.entrySet()) { |
| 293 | + for (Map.Entry<RedisClusterNode, PositionalKeys> entry : nodeKeyMap.entrySet()) { |
304 | 294 |
|
305 | 295 | if (entry.getKey().isMaster()) {
|
306 | 296 | for (PositionalKey key : entry.getValue()) {
|
|
0 commit comments