use of org.corfudb.format.Types.LogEntry in project CorfuDB by CorfuDB.
the class StreamLogFiles method getCompactedEntries.
private CompactedEntry getCompactedEntries(String filePath, Set<Long> pendingTrim) throws IOException {
FileChannel fc = getChannel(filePath, true);
// Skip the header
ByteBuffer headerMetadataBuf = ByteBuffer.allocate(METADATA_SIZE);
fc.read(headerMetadataBuf);
headerMetadataBuf.flip();
Metadata headerMetadata = Metadata.parseFrom(headerMetadataBuf.array());
ByteBuffer headerBuf = ByteBuffer.allocate(headerMetadata.getLength());
fc.read(headerBuf);
headerBuf.flip();
LogHeader header = LogHeader.parseFrom(headerBuf.array());
ByteBuffer o = ByteBuffer.allocate((int) fc.size() - (int) fc.position());
fc.read(o);
fc.close();
o.flip();
LinkedHashMap<Long, LogEntry> compacted = new LinkedHashMap<>();
while (o.hasRemaining()) {
//Skip delimiter
o.getShort();
byte[] metadataBuf = new byte[METADATA_SIZE];
o.get(metadataBuf);
try {
Metadata metadata = Metadata.parseFrom(metadataBuf);
byte[] logEntryBuf = new byte[metadata.getLength()];
o.get(logEntryBuf);
LogEntry entry = LogEntry.parseFrom(logEntryBuf);
if (!noVerify) {
if (metadata.getChecksum() != getChecksum(entry.toByteArray())) {
log.error("Checksum mismatch detected while trying to read address {}", entry.getGlobalAddress());
throw new DataCorruptionException();
}
}
if (!pendingTrim.contains(entry.getGlobalAddress())) {
compacted.put(entry.getGlobalAddress(), entry);
}
} catch (InvalidProtocolBufferException e) {
throw new DataCorruptionException();
}
}
return new CompactedEntry(header, compacted.values());
}
Aggregations