Skip to content

Commit

Permalink
IGNITE-8957 testFailGetLock() constantly fails. Last entry checkpoint…
Browse files Browse the repository at this point in the history
… history can be emp - Fixes #4334.

Signed-off-by: Ivan Rakov <irakov@apache.org>
  • Loading branch information
AMedvedev authored and glukos committed Jul 13, 2018
1 parent 9c57baa commit 62df2d9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 35 deletions.
Expand Up @@ -3208,19 +3208,22 @@ private void doCheckpoint() {

if (chp.hasDelta() || destroyedPartitionsCnt > 0) {
if (printCheckpointStats) {
if (log.isInfoEnabled())
if (log.isInfoEnabled()) {
String walSegsCoveredMsg = prepareWalSegsCoveredMsg(chp.walSegsCoveredRange);

log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " +
"walSegmentsCleared=%d, walSegmentsCovered=%s, markDuration=%dms, pagesWrite=%dms, fsync=%dms, " +
"total=%dms]",
chp.cpEntry != null ? chp.cpEntry.checkpointId() : "",
chp.pagesSize,
chp.cpEntry != null ? chp.cpEntry.checkpointMark() : "",
chp.walFilesDeleted,
chp.walSegmentsCovered,
walSegsCoveredMsg,
tracker.markDuration(),
tracker.pagesWriteDuration(),
tracker.fsyncDuration(),
tracker.totalDuration()));
}
}

persStoreMetrics.onCheckpoint(
Expand Down Expand Up @@ -3251,6 +3254,23 @@ private void doCheckpoint() {
}
}

/** */
private String prepareWalSegsCoveredMsg(IgniteBiTuple<Long, Long> walRange) {
String res;

long startIdx = walRange.get1();
long endIdx = walRange.get2();

if (endIdx < 0 || endIdx < startIdx)
res = "[]";
else if (endIdx == startIdx)
res = "[" + endIdx + "]";
else
res = "[" + startIdx + " - " + endIdx + "]";

return res;
}

/**
* Processes all evicted partitions scheduled for destroy.
*
Expand Down Expand Up @@ -3930,7 +3950,7 @@ public static class Checkpoint {
private int walFilesDeleted;

/** WAL segments fully covered by this checkpoint. */
private List<Long> walSegmentsCovered;
private IgniteBiTuple<Long, Long> walSegsCoveredRange;

/** */
private final int pagesSize;
Expand Down Expand Up @@ -3967,10 +3987,10 @@ public void walFilesDeleted(int walFilesDeleted) {
}

/**
* @param walSegmentsCovered WAL segments fully covered by this checkpoint.
* @param walSegsCoveredRange WAL segments fully covered by this checkpoint.
*/
public void walSegmentsCovered(final List<Long> walSegmentsCovered) {
this.walSegmentsCovered = walSegmentsCovered;
public void walSegsCoveredRange(final IgniteBiTuple<Long, Long> walSegsCoveredRange) {
this.walSegsCoveredRange = walSegsCoveredRange;
}
}

Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE;
Expand Down Expand Up @@ -198,33 +199,9 @@ public List<CheckpointEntry> onWalTruncated(WALPointer ptr) {
* @return List of checkpoints removed from history.
*/
public List<CheckpointEntry> onCheckpointFinished(GridCacheDatabaseSharedManager.Checkpoint chp, boolean truncateWal) {
List<CheckpointEntry> removed = new ArrayList<>();

final Map.Entry<Long, CheckpointEntry> lastEntry = histMap.lastEntry();

assert lastEntry != null;
List<CheckpointEntry> rmv = new ArrayList<>();

final Map.Entry<Long, CheckpointEntry> previousEntry = histMap.lowerEntry(lastEntry.getKey());

final WALPointer lastWALPointer = lastEntry.getValue().checkpointMark();

long lastIdx = 0;

long prevIdx = 0;

final ArrayList<Long> walSegmentsCovered = new ArrayList<>();

if (lastWALPointer instanceof FileWALPointer) {
lastIdx = ((FileWALPointer)lastWALPointer).index();

if (previousEntry != null)
prevIdx = ((FileWALPointer)previousEntry.getValue().checkpointMark()).index();
}

for (long walCovered = prevIdx; walCovered < lastIdx; walCovered++)
walSegmentsCovered.add(walCovered);

chp.walSegmentsCovered(walSegmentsCovered);
chp.walSegsCoveredRange(calculateWalSegmentsCovered());

int deleted = 0;

Expand All @@ -245,12 +222,46 @@ public List<CheckpointEntry> onCheckpointFinished(GridCacheDatabaseSharedManager

histMap.remove(entry.getKey());

removed.add(cpEntry);
rmv.add(cpEntry);
}

chp.walFilesDeleted(deleted);

return removed;
return rmv;
}

/**
* Calculates indexes of WAL segments covered by last checkpoint.
*
* @return list of indexes or empty list if there are no checkpoints.
*/
private IgniteBiTuple<Long, Long> calculateWalSegmentsCovered() {
IgniteBiTuple<Long, Long> tup = new IgniteBiTuple<>(-1L, -1L);

Map.Entry<Long, CheckpointEntry> lastEntry = histMap.lastEntry();

if (lastEntry == null)
return tup;

Map.Entry<Long, CheckpointEntry> previousEntry = histMap.lowerEntry(lastEntry.getKey());

WALPointer lastWALPointer = lastEntry.getValue().checkpointMark();

long lastIdx = 0;

long prevIdx = 0;

if (lastWALPointer instanceof FileWALPointer) {
lastIdx = ((FileWALPointer)lastWALPointer).index();

if (previousEntry != null)
prevIdx = ((FileWALPointer)previousEntry.getValue().checkpointMark()).index();
}

tup.set1(prevIdx);
tup.set2(lastIdx - 1);

return tup;
}

/**
Expand Down
Expand Up @@ -377,7 +377,7 @@ public void testCoveredWalLogged() throws Exception {
final String coveredMatcherGrp = coveredMatcher.group(1);

final long[] covered = coveredMatcherGrp.length() > 0 ?
Arrays.stream(coveredMatcherGrp.split(",")).mapToLong(e -> Integer.valueOf(e.trim())).toArray() :
Arrays.stream(coveredMatcherGrp.split(" - ")).mapToLong(e -> Integer.valueOf(e.trim())).toArray() :
new long[0];

assertEquals(nextCovered, covered[0]);
Expand Down

0 comments on commit 62df2d9

Please sign in to comment.