Replaced partsToEvict from queue to map to do not add the same partition several times.
@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReadWriteLock;
@@ -106,7 +107,7 @@ public class GridDhtPreloader extends GridCachePreloaderAdapter {
private final ReadWriteLock demandLock = new ReentrantReadWriteLock();
/** */
- private final ConcurrentLinkedDeque8<GridDhtLocalPartition> partsToEvict = new ConcurrentLinkedDeque8<>();
+ private final ConcurrentHashMap<Integer, GridDhtLocalPartition> partsToEvict = new ConcurrentHashMap<>();
/** */
private final AtomicInteger partsEvictOwning = new AtomicInteger();
@@ -774,28 +775,28 @@ public class GridDhtPreloader extends GridCachePreloaderAdapter {
/** {@inheritDoc} */
@Override public void evictPartitionAsync(GridDhtLocalPartition part) {
- partsToEvict.add(part);
+ partsToEvict.putIfAbsent(part.id(), part);
if (partsEvictOwning.get() == 0 && partsEvictOwning.compareAndSet(0, 1)) {
cctx.closures().callLocalSafe(new GPC<Boolean>() {
@Override public Boolean call() {
boolean locked = true;
- while (locked || !partsToEvict.isEmptyx()) {
+ while (locked || !partsToEvict.isEmpty()) {
if (!locked && !partsEvictOwning.compareAndSet(0, 1))
return false;
try {
- GridDhtLocalPartition part = partsToEvict.poll();
-
- if (part != null)
+ for (GridDhtLocalPartition part : partsToEvict.values()) {
try {
+ partsToEvict.remove(part.id());
+
part.tryEvict();
GridDhtPartitionState state = part.state();
if (state == RENTING || ((state == MOVING || state == OWNING) && part.shouldBeRenting()))
- partsToEvict.push(part);
+ partsToEvict.put(part.id(), part);
}
catch (Throwable ex) {
if (cctx.kernalContext().isStopping()) {
@@ -811,8 +812,9 @@ public class GridDhtPreloader extends GridCachePreloaderAdapter {
LT.error(log, ex, "Partition eviction failed, this can cause grid hang.");
}
}
+ }
finally {
- if (!partsToEvict.isEmptyx())
+ if (!partsToEvict.isEmpty())
locked = true;
else {
boolean res = partsEvictOwning.compareAndSet(1, 0);
