Skip to content

Commit 887955c

Browse files
authored
IGNITE-23645 Added logging of cache group partition eviction (#11672)
1 parent f18d7d5 commit 887955c

File tree

6 files changed

+403
-15
lines changed

6 files changed

+403
-15
lines changed

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,14 @@ public void requestPartitions() {
12071207
return;
12081208
}
12091209

1210-
if (waitCnt.decrementAndGet() == 0)
1210+
if (waitCnt.decrementAndGet() == 0) {
1211+
U.log(log, "Eviction completed successfully" +
1212+
" [grp=" + grp.cacheOrGroupName() + ", reason='preparation for rebalancing'" +
1213+
", evictedPartsCount=" + parts.size() +
1214+
", evictedParts=" + S.toStringSortedDistinct(d.partitions().fullSet()) + "]");
1215+
12111216
ctx.kernalContext().closure().runLocalSafe((GridPlainRunnable)() -> requestPartitions0(node, parts, d));
1217+
}
12121218
}
12131219
});
12141220
}

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtLocalPartition.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements
132132

133133
/** Rent future. */
134134
@GridToStringExclude
135-
private final GridFutureAdapter<?> rent;
135+
private final RentFuture rent;
136136

137137
/** */
138138
@GridToStringExclude
@@ -212,11 +212,7 @@ public GridDhtLocalPartition(
212212
cacheMaps = null;
213213
}
214214

215-
rent = new GridFutureAdapter<Object>() {
216-
@Override public String toString() {
217-
return "PartitionRentFuture [part=" + GridDhtLocalPartition.this + ']';
218-
}
219-
};
215+
rent = new RentFuture();
220216

221217
int delQueueSize = grp.systemCache() ? 100 :
222218
Math.max(MAX_DELETE_QUEUE_SIZE / grp.affinity().partitions(), 20);
@@ -694,7 +690,7 @@ public boolean markLost() {
694690
* @return Future to signal that this node is no longer an owner or backup or null if corresponding partition
695691
* state is {@code RENTING} or {@code EVICTED}.
696692
*/
697-
public IgniteInternalFuture<?> rent() {
693+
public RentFuture rent() {
698694
long state0 = this.state.get();
699695

700696
GridDhtPartitionState partState = getPartState(state0);
@@ -1409,4 +1405,17 @@ public void dumpDebugInfo(SB buf) {
14091405

14101406
buf.a(']');
14111407
}
1408+
1409+
/** */
1410+
public class RentFuture extends GridFutureAdapter<Void> {
1411+
/** */
1412+
public int partitionId() {
1413+
return id;
1414+
}
1415+
1416+
/** {@inheritDoc} */
1417+
@Override public String toString() {
1418+
return S.toString(RentFuture.class, this);
1419+
}
1420+
}
14121421
}

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtPartitionTopologyImpl.java

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.apache.ignite.internal.util.GridLongList;
6363
import org.apache.ignite.internal.util.GridPartitionStateMap;
6464
import org.apache.ignite.internal.util.StripedCompositeReadWriteLock;
65+
import org.apache.ignite.internal.util.future.GridCompoundFuture;
6566
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
6667
import org.apache.ignite.internal.util.typedef.F;
6768
import org.apache.ignite.internal.util.typedef.X;
@@ -467,6 +468,8 @@ else if (added)
467468
else {
468469
// If preloader is disabled, then we simply clear out
469470
// the partitions this node is not responsible for.
471+
GridCompoundFuture<Void, Void> grpRentFut = new GridCompoundFuture<>();
472+
470473
for (int p = 0; p < partitions; p++) {
471474
GridDhtLocalPartition locPart = localPartition0(p, affVer, false, true);
472475

@@ -477,7 +480,7 @@ else if (added)
477480
GridDhtPartitionState state = locPart.state();
478481

479482
if (state.active()) {
480-
locPart.rent();
483+
grpRentFut.add(locPart.rent());
481484

482485
updateSeq = updateLocal(p, locPart.state(), updateSeq, affVer);
483486

@@ -502,6 +505,8 @@ else if (belongs) {
502505
updateLocal(p, locPart.state(), updateSeq, affVer);
503506
}
504507
}
508+
509+
logEvictionResults(grpRentFut, "rebalancing is disabled (partitions do not belong to affinity)");
505510
}
506511
}
507512

@@ -804,6 +809,8 @@ private boolean partitionLocalNode(int p, AffinityTopologyVersion topVer) {
804809

805810
// Skip partition updates in case of not real exchange.
806811
if (!ctx.localNode().isClient() && exchFut.exchangeType() == ALL) {
812+
GridCompoundFuture<Void, Void> grpRentFut = new GridCompoundFuture<>();
813+
807814
for (int p = 0; p < partitions; p++) {
808815
GridDhtLocalPartition locPart = localPartition0(p, topVer, false, true);
809816

@@ -835,7 +842,7 @@ private boolean partitionLocalNode(int p, AffinityTopologyVersion topVer) {
835842
GridDhtPartitionState state = locPart.state();
836843

837844
if (state == MOVING) {
838-
locPart.rent();
845+
grpRentFut.add(locPart.rent());
839846

840847
updateSeq = updateLocal(p, locPart.state(), updateSeq, topVer);
841848

@@ -849,6 +856,8 @@ private boolean partitionLocalNode(int p, AffinityTopologyVersion topVer) {
849856
}
850857
}
851858
}
859+
860+
logEvictionResults(grpRentFut, "MOVING partitions do not belong to affinity");
852861
}
853862

854863
AffinityAssignment aff = grp.affinity().readyAffinity(topVer);
@@ -2538,6 +2547,8 @@ private boolean checkEvictions(long updateSeq, AffinityAssignment aff) {
25382547

25392548
UUID locId = ctx.localNodeId();
25402549

2550+
GridCompoundFuture<Void, Void> grpRentFut = new GridCompoundFuture<>();
2551+
25412552
for (int p = 0; p < locParts.length(); p++) {
25422553
GridDhtLocalPartition part = locParts.get(p);
25432554

@@ -2557,7 +2568,7 @@ private boolean checkEvictions(long updateSeq, AffinityAssignment aff) {
25572568
if (nodeIds.containsAll(nodeIds(affNodes))) {
25582569
GridDhtPartitionState state0 = part.state();
25592570

2560-
part.rent();
2571+
grpRentFut.add(part.rent());
25612572

25622573
updateSeq = updateLocal(part.id(), part.state(), updateSeq, aff.topologyVersion());
25632574

@@ -2586,7 +2597,7 @@ private boolean checkEvictions(long updateSeq, AffinityAssignment aff) {
25862597
if (locId.equals(n.id())) {
25872598
GridDhtPartitionState state0 = part.state();
25882599

2589-
part.rent();
2600+
grpRentFut.add(part.rent());
25902601

25912602
updateSeq = updateLocal(part.id(), part.state(), updateSeq, aff.topologyVersion());
25922603

@@ -2607,6 +2618,8 @@ private boolean checkEvictions(long updateSeq, AffinityAssignment aff) {
26072618
}
26082619
}
26092620

2621+
logEvictionResults(grpRentFut, "partitions no longer belong to affinity");
2622+
26102623
return hasEvictedPartitions;
26112624
}
26122625

@@ -3360,6 +3373,41 @@ private String dumpPartitionStates() {
33603373
return sb.toString();
33613374
}
33623375

3376+
/**
3377+
* Prints eviction results to the log.
3378+
*
3379+
* @param grpRentFut Group rent future.
3380+
* @param reason Eviction reason.
3381+
*/
3382+
private void logEvictionResults(GridCompoundFuture<Void, Void> grpRentFut, String reason) {
3383+
grpRentFut.markInitialized();
3384+
3385+
grpRentFut.listen(() -> {
3386+
Collection<GridDhtLocalPartition.RentFuture> futs =
3387+
F.viewReadOnly(grpRentFut.futures(), f -> (GridDhtLocalPartition.RentFuture)f);
3388+
3389+
if (futs.isEmpty())
3390+
return;
3391+
3392+
Collection<Integer> evicted = F.viewReadOnly(futs, GridDhtLocalPartition.RentFuture::partitionId, f -> f.error() == null);
3393+
Collection<Integer> failed = F.viewReadOnly(futs, GridDhtLocalPartition.RentFuture::partitionId, f -> f.error() != null);
3394+
3395+
boolean allEvicted = failed.isEmpty();
3396+
3397+
String msg = "Eviction completed" +
3398+
(allEvicted ? " successfully" : " with failures (some partitions failed to evict)") +
3399+
" [grp=" + grp.cacheOrGroupName() + ", reason='" + reason + "'" +
3400+
", evictedPartsCount=" + evicted.size() + ", evictedParts=" + S.toStringSortedDistinct(evicted) +
3401+
(allEvicted ? "" : ", nonEvictedPartsCount=" + failed.size() +
3402+
", nonEvictedParts=" + S.toStringSortedDistinct(failed)) + "]";
3403+
3404+
if (allEvicted)
3405+
log.info(msg);
3406+
else
3407+
log.warning(msg);
3408+
});
3409+
}
3410+
33633411
/**
33643412
* Iterator over current local partitions.
33653413
*/

modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtLocalPartitionSyncEviction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.concurrent.CountDownLatch;
2121
import java.util.concurrent.TimeUnit;
22-
import org.apache.ignite.internal.IgniteInternalFuture;
2322
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
2423
import org.apache.ignite.internal.NodeStoppingException;
2524
import org.apache.ignite.internal.processors.cache.CacheGroupContext;
@@ -75,7 +74,7 @@ public GridDhtLocalPartitionSyncEviction(
7574
}
7675

7776
/** {@inheritDoc} */
78-
@Override public IgniteInternalFuture<?> rent() {
77+
@Override public RentFuture rent() {
7978
if (mode == 0)
8079
sync();
8180

0 commit comments

Comments
 (0)