use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project ignite by apache.
the class WalDeletionArchiveAbstractTest method testCorrectDeletedArchivedWalFiles.
/**
* Correct delete archived wal files.
*/
@Test
public void testCorrectDeletedArchivedWalFiles() throws Exception {
// given: configured grid with setted max wal archive size
long maxWalArchiveSize = 2 * 1024 * 1024;
Ignite ignite = startGrid(dbCfg -> dbCfg.setMaxWalArchiveSize(maxWalArchiveSize));
GridCacheDatabaseSharedManager dbMgr = gridDatabase(ignite);
CheckpointHistory hist = dbMgr.checkpointHistory();
assertNotNull(hist);
IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cacheConfiguration());
// when: put to cache more than 2 MB
for (int i = 0; i < 500; i++) {
if (i % 100 == 0)
forceCheckpoint();
cache.put(i, i);
}
// then: total archive size less than of maxWalArchiveSize(by current logic)
FileWriteAheadLogManager wal = wal(ignite);
assertTrue(waitForCondition(() -> wal.lastTruncatedSegment() >= 0, 10_000));
FileDescriptor[] files = wal.walArchiveFiles();
long totalSize = wal.totalSize(files);
assertTrue(files.length >= 1);
assertTrue(totalSize < maxWalArchiveSize);
assertFalse(Stream.of(files).anyMatch(desc -> desc.file().getName().endsWith("00001.wal")));
assertTrue(!hist.checkpoints().isEmpty());
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project ignite by apache.
the class IgniteWalConverter method getCurrentWalFilePath.
/**
* Get current wal file path, used in {@code WALIterator}.
*
* @param it WALIterator.
* @return Current wal file path.
*/
private static String getCurrentWalFilePath(WALIterator it) {
String res = null;
try {
WALIterator walIter = it instanceof FilteredWalIterator ? U.field(it, "delegateWalIter") : it;
Integer curIdx = U.field(walIter, "curIdx");
List<FileDescriptor> walFileDescriptors = U.field(walIter, "walFileDescriptors");
if (curIdx != null && walFileDescriptors != null && curIdx < walFileDescriptors.size())
res = walFileDescriptors.get(curIdx).getAbsolutePath();
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class IgniteWalConverter method getCurrentWalFilePath.
/**
* Get current wal file path, used in {@code WALIterator}.
*
* @param it WALIterator.
* @return Current wal file path.
*/
private static String getCurrentWalFilePath(WALIterator it) {
String res = null;
try {
WALIterator walIter = it instanceof FilteredWalIterator ? U.field(it, "delegateWalIter") : it;
Integer curIdx = U.field(walIter, "curIdx");
List<FileDescriptor> walFileDescriptors = U.field(walIter, "walFileDescriptors");
if (curIdx != null && walFileDescriptors != null && curIdx < walFileDescriptors.size())
res = walFileDescriptors.get(curIdx).getAbsolutePath();
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class StandaloneWalRecordsIterator method advanceSegment.
/**
* {@inheritDoc}
*/
@Override
protected AbstractReadFileHandle advanceSegment(@Nullable final AbstractReadFileHandle curWalSegment) throws IgniteCheckedException {
if (curWalSegment != null)
curWalSegment.close();
FileDescriptor fd;
do {
curWalSegmIdx++;
curIdx++;
if (curIdx >= walFileDescriptors.size())
return null;
fd = walFileDescriptors.get(curIdx);
} while (!checkBounds(fd.idx()));
if (log.isDebugEnabled())
log.debug("Reading next file [absIdx=" + curWalSegmIdx + ", file=" + fd.file().getAbsolutePath() + ']');
assert fd != null;
curRec = null;
try {
FileWALPointer initPtr = null;
if (lowBound.index() == fd.idx())
initPtr = lowBound;
return initReadHandle(fd, initPtr);
} catch (FileNotFoundException e) {
if (log.isInfoEnabled())
log.info("Missing WAL segment in the archive: " + e.getMessage());
return null;
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class StandaloneWalRecordsIterator method strictCheck.
/**
* @param walFiles Wal files.
* @param lowBound Low bound.
* @param highBound High bound.
*
* @throws IgniteCheckedException if failed
*/
private static void strictCheck(List<FileDescriptor> walFiles, FileWALPointer lowBound, FileWALPointer highBound) throws IgniteCheckedException {
int idx = 0;
if (lowBound.index() > Long.MIN_VALUE) {
for (; idx < walFiles.size(); idx++) {
FileDescriptor desc = walFiles.get(idx);
assert desc != null;
if (desc.idx() == lowBound.index())
break;
}
}
if (idx == walFiles.size())
throw new StrictBoundsCheckException("Wal segments not in bounds. loBoundIndex=" + lowBound.index() + ", indexes=" + printIndexes(walFiles));
long curWalSegmIdx = walFiles.get(idx).idx();
for (; idx < walFiles.size() && curWalSegmIdx <= highBound.index(); idx++, curWalSegmIdx++) {
FileDescriptor desc = walFiles.get(idx);
assert desc != null;
if (curWalSegmIdx != desc.idx())
throw new StrictBoundsCheckException("Wal segment " + curWalSegmIdx + " not found in files " + printIndexes(walFiles));
}
if (highBound.index() < Long.MAX_VALUE && curWalSegmIdx <= highBound.index())
throw new StrictBoundsCheckException("Wal segments not in bounds. hiBoundIndex=" + highBound.index() + ", indexes=" + printIndexes(walFiles));
}
Aggregations