@Override public void readBuffer(ByteBuffer buffer) throws IOException { OIOUtils.readByteBuffer(buffer, channel); }
private ByteBuffer readData(final long iOffset, final int iSize) throws IOException { final ByteBuffer buffer = ByteBuffer.allocate(iSize); readByteBuffer(buffer, channel, iOffset, true); buffer.rewind(); return buffer; }
@Override public void readBuffer(ByteBuffer buffer) throws IOException { if (buffer.limit() % blockSize != 0) { throw new IOException( "In direct IO mode, size of the written buffers should be quantified by block size (block size : " + blockSize + ", buffer size: " + buffer.limit() + " )"); } OIOUtils.readByteBuffer(buffer, fd); }
private NameFileIdEntry readNextNameIdEntryV1() throws IOException { try { ByteBuffer buffer = ByteBuffer.allocate(OIntegerSerializer.INT_SIZE); OIOUtils.readByteBuffer(buffer, nameIdMapHolder); buffer.rewind(); final int nameSize = buffer.getInt(); buffer = ByteBuffer.allocate(nameSize + OLongSerializer.LONG_SIZE); OIOUtils.readByteBuffer(buffer, nameIdMapHolder); buffer.rewind(); final String name = stringSerializer.deserializeFromByteBufferObject(buffer); final int fileId = (int) buffer.getLong(); return new NameFileIdEntry(name, fileId); } catch (final EOFException ignore) { return null; } }
/** * Read page content with given index from cache or file. */ byte[] readPage(long pageIndex) throws IOException { synchronized (lockObject) { lastAccessTime = System.nanoTime(); if (pageIndex == lastWrittenPageIndex) { return lastWrittenPage.array(); } if (pageIndex >= firstCachedPage && pageIndex < firstCachedPage + pageCache.size()) { final ByteBuffer buffer = pageCache.get((int) (pageIndex - firstCachedPage)); return buffer.array(); } final ByteBuffer buffer = ByteBuffer.allocate(OWALPage.PAGE_SIZE).order(ByteOrder.nativeOrder()); initFile(); segChannel.position(pageIndex * OWALPage.PAGE_SIZE); readByteBuffer(buffer, segChannel); return buffer.array(); } }
private NameFileIdEntry readNextNameIdEntryV2() throws IOException { try { ByteBuffer buffer = ByteBuffer.allocate(2 * OIntegerSerializer.INT_SIZE); OIOUtils.readByteBuffer(buffer, nameIdMapHolder); buffer.rewind(); final int fileId = buffer.getInt(); final int nameSize = buffer.getInt(); buffer = ByteBuffer.allocate(nameSize); OIOUtils.readByteBuffer(buffer, nameIdMapHolder); buffer.rewind(); final String name = stringSerializer.deserializeFromByteBufferObject(buffer); buffer = ByteBuffer.allocate(OIntegerSerializer.INT_SIZE); OIOUtils.readByteBuffer(buffer, nameIdMapHolder); buffer.rewind(); final int fileNameSize = buffer.getInt(); buffer = ByteBuffer.allocate(fileNameSize); OIOUtils.readByteBuffer(buffer, nameIdMapHolder); buffer.rewind(); final String fileName = stringSerializer.deserializeFromByteBufferObject(buffer); return new NameFileIdEntry(name, fileId, fileName); } catch (final EOFException ignore) { return null; } }
/** * Reads page content from the cache to the <code>ByteBuffer</code> * <code>ByteBuffer</code> is not backed by the cache and can be freely changed */ ByteBuffer readPageBuffer(long pageIndex) throws IOException { synchronized (lockObject) { lastAccessTime = System.nanoTime(); if (pageIndex == lastWrittenPageIndex) { final ByteBuffer copy = ByteBuffer.allocate(OWALPage.PAGE_SIZE).order(ByteOrder.nativeOrder()); lastWrittenPage.position(0); copy.put(lastWrittenPage); return copy; } if (pageIndex >= firstCachedPage && pageIndex < firstCachedPage + pageCache.size()) { final ByteBuffer buffer = pageCache.get((int) (pageIndex - firstCachedPage)); final ByteBuffer copy = ByteBuffer.allocate(OWALPage.PAGE_SIZE).order(ByteOrder.nativeOrder()); buffer.position(0); copy.put(buffer); return copy; } final ByteBuffer buffer = ByteBuffer.allocate(OWALPage.PAGE_SIZE).order(ByteOrder.nativeOrder()); initFile(); segChannel.position(pageIndex * OWALPage.PAGE_SIZE); readByteBuffer(buffer, segChannel); buffer.position(0); return buffer; } }
public void open() throws IOException { lock.lock(); try { if (!Files.exists(dirtyFilePath)) { channel = FileChannel.open(dirtyFilePath, StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE); ByteBuffer buffer = ByteBuffer.allocate(1); OIOUtils.writeByteBuffer(buffer, channel, 0); } else { channel = FileChannel.open(dirtyFilePath, StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE); } if (OGlobalConfiguration.FILE_LOCK.getValueAsBoolean()) { lockFile(); } ByteBuffer buffer = ByteBuffer.allocate(1); OIOUtils.readByteBuffer(buffer, channel, 0, true); buffer.position(0); dirtyFlag = buffer.get() > 0; } finally { lock.unlock(); } }
OIOUtils.readByteBuffer(versionBuffer, channel, OFileClassic.VERSION_OFFSET, true); versionBuffer.position(0); if (fileVersion >= 42) { final ByteBuffer crc32buffer = ByteBuffer.allocate(OIntegerSerializer.INT_SIZE); OIOUtils.readByteBuffer(crc32buffer, channel, CRC_32_OFFSET, true); OIOUtils.readByteBuffer(byteBuffer, channel, OFileClassic.HEADER_SIZE, true);
private OLogSequenceNumber readMasterRecord(final int index) throws IOException { final long masterPosition = index * (OIntegerSerializer.INT_SIZE + 2L * OLongSerializer.LONG_SIZE); if (masterRecordLSNHolder.size() < masterPosition + MASTER_RECORD_SIZE) { OLogManager.instance().debugNoDb(this, "Cannot restore %d WAL master record for storage %s", null, index, storageName); return null; } final CRC32 crc32 = new CRC32(); try { final ByteBuffer buffer = ByteBuffer.allocate(MASTER_RECORD_SIZE); OIOUtils.readByteBuffer(buffer, masterRecordLSNHolder, masterPosition, true); buffer.rewind(); final int firstCRC = buffer.getInt(); final long segment = buffer.getLong(); final long position = buffer.getLong(); final byte[] serializedLSN = new byte[2 * OLongSerializer.LONG_SIZE]; OLongSerializer.INSTANCE.serializeLiteral(segment, serializedLSN, 0); OLongSerializer.INSTANCE.serializeLiteral(position, serializedLSN, OLongSerializer.LONG_SIZE); crc32.update(serializedLSN); if (firstCRC != ((int) crc32.getValue())) { OLogManager.instance() .errorNoDb(this, "Cannot restore %d WAL master record for storage %s crc check is failed", null, index, storageName); return null; } return new OLogSequenceNumber(segment, position); } catch (final EOFException eofException) { OLogManager.instance() .debugNoDb(this, "Cannot restore %d WAL master record for storage %s", eofException, index, storageName); return null; } }
public void read(long offset, final ByteBuffer buffer, final boolean throwOnEof) throws IOException { int attempts = 0; while (true) { try { acquireReadLock(); try { offset = checkRegions(offset, buffer.limit()); readByteBuffer(buffer, channel, offset, throwOnEof); break; } finally { releaseReadLock(); attempts++; } } catch (final IOException e) { OLogManager.instance().error(this, "Error during data read for file '" + getName() + "' " + attempts + "-th attempt", e); reopenFile(attempts, e); } } }
public void read(long offset, final byte[] iData, final int iLength, final int iArrayOffset) throws IOException { int attempts = 0; while (true) { try { acquireReadLock(); try { offset = checkRegions(offset, iLength); final ByteBuffer buffer = ByteBuffer.wrap(iData, iArrayOffset, iLength); readByteBuffer(buffer, channel, offset, true); break; } finally { releaseReadLock(); attempts++; } } catch (final IOException e) { OLogManager.instance().error(this, "Error during data read for file '" + getName() + "' " + attempts + "-th attempt", e); reopenFile(attempts, e); } } }