private OCachePointer cacheFileContent(long fileId, long pageIndex) throws IOException { final long startPosition = pageIndex * pageSize; final long endPosition = startPosition + pageSize; byte[] content = new byte[pageSize]; OCachePointer dataPointer; final OFileClassic fileClassic = files.get(fileId); if (fileClassic.getFilledUpTo() >= endPosition) { fileClassic.read(startPosition, content, content.length); final ODirectMemoryPointer pointer = new ODirectMemoryPointer(content); final OLogSequenceNumber storedLSN = ODurablePage.getLogSequenceNumberFromPage(pointer); dataPointer = new OCachePointer(pointer, storedLSN); } else { fileClassic.allocateSpace((int) (endPosition - fileClassic.getFilledUpTo())); final ODirectMemoryPointer pointer = new ODirectMemoryPointer(content); dataPointer = new OCachePointer(pointer, new OLogSequenceNumber(0, -1)); } return dataPointer; }
public OPageDataVerificationError[] checkStoredPages( OCommandOutputListener commandOutputListener) { final int notificationTimeOut = 5000; final List<OPageDataVerificationError> errors = new ArrayList<OPageDataVerificationError>(); synchronized (syncObject) { for (long fileId : files.keySet()) { OFileClassic fileClassic = files.get(fileId); boolean fileIsCorrect; try { if (commandOutputListener != null) commandOutputListener.onMessage("Flashing file " + fileClassic.getName() + "... "); flush(fileId); if (commandOutputListener != null) commandOutputListener.onMessage( "Start verification of content of " + fileClassic.getName() + "file ..."); long time = System.currentTimeMillis(); long filledUpTo = fileClassic.getFilledUpTo(); fileIsCorrect = true; for (long pos = 0; pos < filledUpTo; pos += pageSize) { boolean checkSumIncorrect = false; boolean magicNumberIncorrect = false; byte[] data = new byte[pageSize]; fileClassic.read(pos, data, data.length); long magicNumber = OLongSerializer.INSTANCE.deserializeNative(data, 0); if (magicNumber != MAGIC_NUMBER) { magicNumberIncorrect = true; if (commandOutputListener != null) commandOutputListener.onMessage( "Error: Magic number for page " + (pos / pageSize) + " in file " + fileClassic.getName() + " does not much !!!"); fileIsCorrect = false; } final int storedCRC32 = OIntegerSerializer.INSTANCE.deserializeNative(data, OLongSerializer.LONG_SIZE); final int calculatedCRC32 = calculatePageCrc(data); if (storedCRC32 != calculatedCRC32) { checkSumIncorrect = true; if (commandOutputListener != null) commandOutputListener.onMessage( "Error: Checksum for page " + (pos / pageSize) + " in file " + fileClassic.getName() + " is incorrect !!!"); fileIsCorrect = false; } if (magicNumberIncorrect || checkSumIncorrect) errors.add( new OPageDataVerificationError( magicNumberIncorrect, checkSumIncorrect, pos / pageSize, fileClassic.getName())); if (commandOutputListener != null && System.currentTimeMillis() - time > notificationTimeOut) { time = notificationTimeOut; commandOutputListener.onMessage((pos / pageSize) + " pages were processed ..."); } } } catch (IOException ioe) { if (commandOutputListener != null) commandOutputListener.onMessage( "Error: Error during processing of file " + fileClassic.getName() + ". " + ioe.getMessage()); fileIsCorrect = false; } if (!fileIsCorrect) { if (commandOutputListener != null) commandOutputListener.onMessage( "Verification of file " + fileClassic.getName() + " is finished with errors."); } else { if (commandOutputListener != null) commandOutputListener.onMessage( "Verification of file " + fileClassic.getName() + " is successfully finished."); } } return errors.toArray(new OPageDataVerificationError[errors.size()]); } }