public DataFileAccessor openDataFileReader() throws IOException { DataFileAccessor rc = null; if (pool.isEmpty()) { rc = new DataFileAccessor(journal, file); } else { rc = pool.remove(pool.size() - 1); } openCounter++; return rc; }
synchronized void closeDataFileAccessor(DataFileAccessor reader) { Pool pool = pools.get(reader.getDataFile().getDataFileId()); if (pool == null || closed) { reader.dispose(); } else { pool.closeDataFileReader(reader); } }
public void corruptRecoveryLocation(Location recoveryPosition) throws IOException { DataFile dataFile = getDataFile(recoveryPosition); // with corruption on recovery we have no faith in the content - slip to the next batch record or eof DataFileAccessor reader = accessorPool.openDataFileAccessor(dataFile); try { RandomAccessFile randomAccessFile = reader.getRaf().getRaf(); randomAccessFile.seek(recoveryPosition.getOffset() + 1); byte[] data = new byte[getWriteBatchSize()]; ByteSequence bs = new ByteSequence(data, 0, randomAccessFile.read(data)); int nextOffset = 0; if (findNextBatchRecord(bs, randomAccessFile) >= 0) { nextOffset = Math.toIntExact(randomAccessFile.getFilePointer() - bs.remaining()); } else { nextOffset = Math.toIntExact(randomAccessFile.length()); } Sequence sequence = new Sequence(recoveryPosition.getOffset(), nextOffset - 1); LOG.warn("Corrupt journal records found in '{}' between offsets: {}", dataFile.getFile(), sequence); // skip corruption on getNextLocation recoveryPosition.setOffset(nextOffset); recoveryPosition.setSize(-1); dataFile.corruptedBlocks.add(sequence); } catch (IOException e) { } finally { accessorPool.closeDataFileAccessor(reader); } }
public synchronized void dispose() { for (DataFileAccessor reader : pool) { reader.dispose(); } pool.clear(); disposed = true; }
public ByteSequence read(Location location) throws IOException, IllegalStateException { DataFile dataFile = getDataFile(location); DataFileAccessor reader = accessorPool.openDataFileAccessor(dataFile); ByteSequence rc = null; try { rc = reader.readRecord(location); } finally { accessorPool.closeDataFileAccessor(reader); } return rc; }
public void update(Location location, ByteSequence data, boolean sync) throws IOException { DataFile dataFile = getDataFile(location); DataFileAccessor updater = accessorPool.openDataFileAccessor(dataFile); try { updater.updateRecord(location, data, sync); } finally { accessorPool.closeDataFileAccessor(updater); } }
public boolean isUnusedPreallocated(DataFile dataFile) throws IOException { if (preallocationScope == PreallocationScope.ENTIRE_JOURNAL_ASYNC) { DataFileAccessor reader = accessorPool.openDataFileAccessor(dataFile); try { byte[] firstFewBytes = new byte[BATCH_CONTROL_RECORD_HEADER.length]; reader.readFully(0, firstFewBytes); ByteSequence bs = new ByteSequence(firstFewBytes); return bs.startsWith(EOF_RECORD); } catch (Exception ignored) { } finally { accessorPool.closeDataFileAccessor(reader); } } return false; }
reader.readLocationDetails(cur); } catch (EOFException eof) { LOG.trace("EOF on next: " + location + ", cur: " + cur);
public synchronized void closeDataFileReader(DataFileAccessor reader) { openCounter--; if (pool.size() >= maxOpenReadersPerFile || disposed) { reader.dispose(); } else { pool.add(reader); } }
public ByteSequence read(Location location) throws IOException, IllegalStateException { DataFile dataFile = getDataFile(location); DataFileAccessor reader = accessorPool.openDataFileAccessor(dataFile); ByteSequence rc = null; try { rc = reader.readRecord(location); } finally { accessorPool.closeDataFileAccessor(reader); } return rc; }
public void update(Location location, ByteSequence data, boolean sync) throws IOException { DataFile dataFile = getDataFile(location); DataFileAccessor updater = accessorPool.openDataFileAccessor(dataFile); try { updater.updateRecord(location, data, sync); } finally { accessorPool.closeDataFileAccessor(updater); } }
public boolean isUnusedPreallocated(DataFile dataFile) throws IOException { if (preallocationScope == PreallocationScope.ENTIRE_JOURNAL_ASYNC) { DataFileAccessor reader = accessorPool.openDataFileAccessor(dataFile); try { byte[] firstFewBytes = new byte[BATCH_CONTROL_RECORD_HEADER.length]; reader.readFully(0, firstFewBytes); ByteSequence bs = new ByteSequence(firstFewBytes); return bs.startsWith(EOF_RECORD); } catch (Exception ignored) { } finally { accessorPool.closeDataFileAccessor(reader); } } return false; }
reader.readLocationDetails(cur); } catch (EOFException eof) { LOG.trace("EOF on next: " + location + ", cur: " + cur);
synchronized void closeDataFileAccessor(DataFileAccessor reader) { Pool pool = pools.get(reader.getDataFile().getDataFileId()); if (pool == null || closed) { reader.dispose(); } else { pool.closeDataFileReader(reader); } }
public synchronized void dispose() { for (DataFileAccessor reader : pool) { reader.dispose(); } pool.clear(); disposed = true; }
RandomAccessFile randomAccessFile = reader.getRaf().getRaf(); randomAccessFile.seek(0); final long totalFileLength = randomAccessFile.length();
public ByteSequence read(Location location) throws IOException, IllegalStateException { DataFile dataFile = getDataFile(location); DataFileAccessor reader = accessorPool.openDataFileAccessor(dataFile); ByteSequence rc = null; try { rc = reader.readRecord(location); } finally { accessorPool.closeDataFileAccessor(reader); } return rc; }
public void update(Location location, ByteSequence data, boolean sync) throws IOException { DataFile dataFile = getDataFile(location); DataFileAccessor updater = accessorPool.openDataFileAccessor(dataFile); try { updater.updateRecord(location, data, sync); } finally { accessorPool.closeDataFileAccessor(updater); } }
public DataFileAccessor openDataFileReader() throws IOException { DataFileAccessor rc = null; if (pool.isEmpty()) { rc = new DataFileAccessor(journal, file); } else { rc = pool.remove(pool.size() - 1); } openCounter++; return rc; }
public boolean isUnusedPreallocated(DataFile dataFile) throws IOException { if (preallocationScope == PreallocationScope.ENTIRE_JOURNAL_ASYNC) { DataFileAccessor reader = accessorPool.openDataFileAccessor(dataFile); try { byte[] firstFewBytes = new byte[BATCH_CONTROL_RECORD_HEADER.length]; reader.readFully(0, firstFewBytes); ByteSequence bs = new ByteSequence(firstFewBytes); return bs.startsWith(EOF_RECORD); } catch (Exception ignored) { } finally { accessorPool.closeDataFileAccessor(reader); } } return false; }