use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class PhysicalFlushableChannelTest method readFile.
private ByteBuffer readFile(File file) throws IOException {
try (StoreChannel channel = fileSystemRule.get().open(file, "r")) {
ByteBuffer buffer = ByteBuffer.allocate((int) channel.size());
channel.read(buffer);
buffer.flip();
return buffer;
}
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class LogTestUtils method filterNeostoreLogicalLog.
public static File filterNeostoreLogicalLog(FileSystemAbstraction fileSystem, File file, final LogHook<LogEntry> filter) throws IOException {
filter.file(file);
File tempFile = new File(file.getAbsolutePath() + ".tmp");
fileSystem.deleteFile(tempFile);
try (StoreChannel in = fileSystem.open(file, "r");
StoreChannel out = fileSystem.open(tempFile, "rw")) {
LogHeader logHeader = transferLogicalLogHeader(in, out, ByteBuffer.allocate(LOG_HEADER_SIZE));
PhysicalLogVersionedStoreChannel outChannel = new PhysicalLogVersionedStoreChannel(out, logHeader.logVersion, logHeader.logFormatVersion);
PhysicalLogVersionedStoreChannel inChannel = new PhysicalLogVersionedStoreChannel(in, logHeader.logVersion, logHeader.logFormatVersion);
ReadableLogChannel inBuffer = new ReadAheadLogChannel(inChannel, LogVersionBridge.NO_MORE_CHANNELS);
LogEntryReader<ReadableLogChannel> entryReader = new VersionAwareLogEntryReader<>();
LogEntry entry;
while ((entry = entryReader.readLogEntry(inBuffer)) != null) {
if (filter.test(entry)) {
// TODO allright, write to outBuffer
}
}
}
return tempFile;
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class LogTestUtils method copyLogicalLog.
public static NonCleanLogCopy copyLogicalLog(FileSystemAbstraction fileSystem, File logBaseFileName) throws IOException {
char active = '1';
File activeLog = new File(logBaseFileName.getPath() + ".active");
ByteBuffer buffer = ByteBuffer.allocate(1024);
File activeLogBackup;
try (StoreChannel af = fileSystem.open(activeLog, "r")) {
af.read(buffer);
buffer.flip();
activeLogBackup = new File(logBaseFileName.getPath() + ".bak.active");
try (StoreChannel activeCopy = fileSystem.open(activeLogBackup, "rw")) {
activeCopy.write(buffer);
}
}
buffer.flip();
active = buffer.asCharBuffer().get();
buffer.clear();
File currentLog = new File(logBaseFileName.getPath() + "." + active);
File currentLogBackup = new File(logBaseFileName.getPath() + ".bak." + active);
try (StoreChannel source = fileSystem.open(currentLog, "r");
StoreChannel dest = fileSystem.open(currentLogBackup, "rw")) {
int read = -1;
do {
read = source.read(buffer);
buffer.flip();
dest.write(buffer);
buffer.clear();
} while (read == 1024);
}
return new NonCleanLogCopy(new FileBackup(activeLog, activeLogBackup, fileSystem), new FileBackup(currentLog, currentLogBackup, fileSystem));
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class TestEphemeralFileChannel method absoluteVersusRelative.
@Test
public void absoluteVersusRelative() throws Exception {
// GIVEN
File file = new File("myfile");
EphemeralFileSystemAbstraction fs = fileSystemRule.get();
StoreChannel channel = fs.open(file, "rw");
byte[] bytes = "test".getBytes();
channel.write(ByteBuffer.wrap(bytes));
channel.close();
// WHEN
channel = fs.open(new File(file.getAbsolutePath()), "r");
byte[] readBytes = new byte[bytes.length];
int nrOfReadBytes = channel.read(ByteBuffer.wrap(readBytes));
// THEN
assertEquals(bytes.length, nrOfReadBytes);
assertTrue(Arrays.equals(bytes, readBytes));
fs.close();
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FailureStorage method storeIndexFailure.
/**
* Store failure in failure file for index with the given id
*
* @param failure message describing the failure that needs to be stored
* @throws IOException if the failure could not be stored
*/
public synchronized void storeIndexFailure(String failure) throws IOException {
File failureFile = failureFile();
try (StoreChannel channel = fs.open(failureFile, "rw")) {
byte[] existingData = new byte[(int) channel.size()];
channel.read(ByteBuffer.wrap(existingData));
channel.position(lengthOf(existingData));
byte[] data = UTF8.encode(failure);
channel.write(ByteBuffer.wrap(data, 0, Math.min(data.length, MAX_FAILURE_SIZE)));
channel.force(true);
channel.close();
}
}
Aggregations