use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class StandaloneWalRecordsIteratorTest method testStrictBounds.
/**
* Check correct check bounds.
*
* @throws Exception if test failed.
*/
@Test
public void testStrictBounds() throws Exception {
String dir = createWalFiles();
FileWALPointer lowBound = null, highBound = null;
for (IgniteBiTuple<WALPointer, WALRecord> p : createWalIterator(dir, null, null, false)) {
if (lowBound == null)
lowBound = (FileWALPointer) p.get1();
highBound = (FileWALPointer) p.get1();
}
assertNotNull(lowBound);
assertNotNull(highBound);
createWalIterator(dir, lowBound, highBound, true);
final FileWALPointer lBound = lowBound;
final FileWALPointer hBound = highBound;
// noinspection ThrowableNotThrown
GridTestUtils.assertThrows(log, () -> {
createWalIterator(dir, new FileWALPointer(lBound.index() - 1, 0, 0), hBound, true);
return 0;
}, IgniteCheckedException.class, null);
// noinspection ThrowableNotThrown
GridTestUtils.assertThrows(log, () -> {
createWalIterator(dir, lBound, new FileWALPointer(hBound.index() + 1, 0, 0), true);
return 0;
}, IgniteCheckedException.class, null);
List<FileDescriptor> walFiles = listWalFiles(dir);
assertNotNull(walFiles);
assertTrue(!walFiles.isEmpty());
assertTrue(walFiles.get(new Random().nextInt(walFiles.size())).file().delete());
// noinspection ThrowableNotThrown
GridTestUtils.assertThrows(log, () -> {
createWalIterator(dir, lBound, hBound, true);
return 0;
}, IgniteCheckedException.class, null);
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project ignite by apache.
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, WALPointer lowBound, WALPointer 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));
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project ignite by apache.
the class IgniteWalIteratorFactory method addFileDescriptor.
/**
* @param file File.
* @param ioFactory IO factory.
* @param descriptors List of descriptors.
*/
private void addFileDescriptor(File file, FileIOFactory ioFactory, TreeSet<FileDescriptor> descriptors) {
if (file.length() < HEADER_RECORD_SIZE)
// Filter out this segment as it is too short.
return;
String fileName = file.getName();
if (!WAL_NAME_PATTERN.matcher(fileName).matches() && !WAL_SEGMENT_FILE_COMPACTED_PATTERN.matcher(fileName).matches())
// Filter out this because it is not segment file.
return;
FileDescriptor desc = readFileDescriptor(file, ioFactory);
if (desc != null)
descriptors.add(desc);
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project ignite by apache.
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 {
WALPointer 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 ignite by apache.
the class IgniteWalRebalanceTest method testSwitchHistoricalRebalanceToFullWhileIteratingOverWAL.
/**
* Tests that demander switches to full rebalance if the previously chosen supplier for a group has failed
* to perform historical rebalance due to an unexpected error while iterating over reserved wal.
*
* @throws Exception If failed
*/
@Test
public void testSwitchHistoricalRebalanceToFullWhileIteratingOverWAL() throws Exception {
testSwitchHistoricalRebalanceToFull(supplier1 -> {
try {
// Corrupt wal record in order to fail historical rebalance from supplier1 node.
IgniteWriteAheadLogManager walMgr = supplier1.context().cache().context().wal();
WALPointer ptr = walMgr.log(new DataRecord(new DataEntry(CU.cacheId("test-cache-1"), new KeyCacheObjectImpl(0, null, 0), null, GridCacheOperation.DELETE, new GridCacheVersion(0, 1, 1, 0), new GridCacheVersion(0, 1, 1, 0), 0, 0, 0, DataEntry.EMPTY_FLAGS)));
File walDir = U.field(walMgr, "walWorkDir");
List<FileDescriptor> walFiles = new IgniteWalIteratorFactory().resolveWalFiles(new IgniteWalIteratorFactory.IteratorParametersBuilder().filesOrDirs(walDir));
FileDescriptor lastWalFile = walFiles.get(walFiles.size() - 1);
WalTestUtils.corruptWalSegmentFile(lastWalFile, ptr);
IgniteCache<Integer, IndexedObject> c1 = supplier1.cache("test-cache-1");
for (int i = 0; i < PARTS_CNT * 100; i++) c1.put(i, new IndexedObject(i + PARTS_CNT));
} catch (IgniteCheckedException | IOException e) {
throw new RuntimeException(e);
}
}, () -> true);
}
Aggregations