use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer in project ignite by apache.
the class GridCacheDatabaseSharedManager method nodeStartedPointers.
/**
*/
public List<T2<Long, WALPointer>> nodeStartedPointers() throws IgniteCheckedException {
List<T2<Long, WALPointer>> res = new ArrayList<>();
File[] files = cpDir.listFiles(NODE_STARTED_FILE_FILTER);
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
String n1 = o1.getName();
String n2 = o2.getName();
Long ts1 = Long.valueOf(n1.substring(0, n1.length() - NODE_STARTED_FILE_NAME_SUFFIX.length()));
Long ts2 = Long.valueOf(n2.substring(0, n2.length() - NODE_STARTED_FILE_NAME_SUFFIX.length()));
if (ts1 == ts2)
return 0;
else if (ts1 < ts2)
return -1;
else
return 1;
}
});
ByteBuffer buf = ByteBuffer.allocate(20);
buf.order(ByteOrder.nativeOrder());
for (File f : files) {
String name = f.getName();
Long ts = Long.valueOf(name.substring(0, name.length() - NODE_STARTED_FILE_NAME_SUFFIX.length()));
try (FileChannel ch = FileChannel.open(f.toPath(), READ)) {
ch.read(buf);
buf.flip();
FileWALPointer ptr = new FileWALPointer(buf.getLong(), buf.getInt(), buf.getInt());
res.add(new T2<Long, WALPointer>(ts, ptr));
buf.clear();
} catch (IOException e) {
throw new IgniteCheckedException("Failed to read node started marker file: " + f.getAbsolutePath(), e);
}
}
return res;
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer in project ignite by apache.
the class GridCacheDatabaseSharedManager method writeCheckpointEntry.
/**
* @param cpId Checkpoint ID.
* @param ptr Wal pointer of current checkpoint.
*/
private CheckpointEntry writeCheckpointEntry(ByteBuffer tmpWriteBuf, long cpTs, UUID cpId, WALPointer ptr, CheckpointRecord rec, CheckpointEntryType type) throws IgniteCheckedException {
assert ptr instanceof FileWALPointer;
FileWALPointer filePtr = (FileWALPointer) ptr;
String fileName = checkpointFileName(cpTs, cpId, type);
try (FileChannel ch = FileChannel.open(Paths.get(cpDir.getAbsolutePath(), fileName), StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND)) {
tmpWriteBuf.rewind();
tmpWriteBuf.putLong(filePtr.index());
tmpWriteBuf.putInt(filePtr.fileOffset());
tmpWriteBuf.putInt(filePtr.length());
tmpWriteBuf.flip();
ch.write(tmpWriteBuf);
tmpWriteBuf.clear();
if (!skipSync)
ch.force(true);
return createCheckPointEntry(cpTs, ptr, cpId, rec, type);
} catch (IOException e) {
throw new IgniteCheckedException(e);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer in project ignite by apache.
the class GridCacheDatabaseSharedManager method nodeStart.
/**
* @param ptr Memory recovery wal pointer.
*/
private void nodeStart(WALPointer ptr) throws IgniteCheckedException {
FileWALPointer p = (FileWALPointer) ptr;
String fileName = U.currentTimeMillis() + "-node-started.bin";
ByteBuffer buf = ByteBuffer.allocate(20);
buf.order(ByteOrder.nativeOrder());
try (FileChannel ch = FileChannel.open(Paths.get(cpDir.getAbsolutePath(), fileName), StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND)) {
buf.putLong(p.index());
buf.putInt(p.fileOffset());
buf.putInt(p.length());
buf.flip();
ch.write(buf);
buf.clear();
ch.force(true);
} catch (IOException e) {
throw new IgniteCheckedException(e);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer in project ignite by apache.
the class StandaloneWalRecordsIterator method scanIndexesFromFileHeaders.
/**
* This methods checks all provided files to be correct WAL segment.
* Header record and its position is checked. WAL position is used to determine real index.
* File index from file name is ignored.
*
* @param allFiles files to scan.
* @return list of file descriptors with checked header records, having correct file index is set
*/
private List<FileWriteAheadLogManager.FileDescriptor> scanIndexesFromFileHeaders(@Nullable final File[] allFiles) {
if (allFiles == null || allFiles.length == 0)
return Collections.emptyList();
final List<FileWriteAheadLogManager.FileDescriptor> resultingDescs = new ArrayList<>();
for (File file : allFiles) {
if (file.length() < HEADER_RECORD_SIZE)
// filter out this segment as it is too short
continue;
FileWALPointer ptr;
try (FileIO fileIO = ioFactory.create(file);
ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())) {
final DataInput in = new FileInput(fileIO, buf);
// Header record must be agnostic to the serializer version.
final int type = in.readUnsignedByte();
if (type == WALRecord.RecordType.STOP_ITERATION_RECORD_TYPE) {
if (log.isInfoEnabled())
log.info("Reached logical end of the segment for file " + file);
// filter out this segment
continue;
}
ptr = RecordV1Serializer.readPosition(in);
} catch (IOException e) {
U.warn(log, "Failed to scan index from file [" + file + "]. Skipping this file during iteration", e);
// filter out this segment
continue;
}
resultingDescs.add(new FileWriteAheadLogManager.FileDescriptor(file, ptr.index()));
}
Collections.sort(resultingDescs);
return resultingDescs;
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer in project ignite by apache.
the class WalStat method registerRecord.
/**
* Handles WAL record.
*
* @param record record to handle.
* @param walPointer pointer, used to extract segment index.
* @param workDir true for work, false for archive folder.
*/
void registerRecord(WALRecord record, WALPointer walPointer, boolean workDir) {
WALRecord.RecordType type = record.type();
if (type == WALRecord.RecordType.PAGE_RECORD)
registerPageSnapshot((PageSnapshot) record);
else if (type == WALRecord.RecordType.DATA_RECORD)
registerDataRecord((DataRecord) record);
else if (type == WALRecord.RecordType.TX_RECORD)
registerTxRecord((TxRecord) record);
incrementStat(type.toString(), record, recTypeSizes);
if (walPointer instanceof FileWALPointer) {
final FileWALPointer fPtr = (FileWALPointer) walPointer;
incrementStat(Long.toString(fPtr.index()), record, segmentsIndexes);
incrementStat(workDir ? "work" : "archive", record, segmentsFolder);
}
}
Aggregations