use of org.apache.cassandra.io.util.ChannelProxy in project cassandra by apache.
the class CompressedStreamWriter method write.
@Override
public void write(DataOutputStreamPlus out) throws IOException {
long totalSize = totalSize();
logger.debug("[Stream #{}] Start streaming file {} to {}, repairedAt = {}, totalSize = {}", session.planId(), sstable.getFilename(), session.peer, sstable.getSSTableMetadata().repairedAt, totalSize);
try (ChannelProxy fc = sstable.getDataChannel().sharedCopy()) {
long progress = 0L;
// calculate chunks to transfer. we want to send continuous chunks altogether.
List<Pair<Long, Long>> sections = getTransferSections(compressionInfo.chunks);
int sectionIdx = 0;
// stream each of the required sections of the file
for (final Pair<Long, Long> section : sections) {
// length of the section to stream
long length = section.right - section.left;
logger.trace("[Stream #{}] Writing section {} with length {} to stream.", session.planId(), sectionIdx++, length);
// tracks write progress
long bytesTransferred = 0;
while (bytesTransferred < length) {
final long bytesTransferredFinal = bytesTransferred;
final int toTransfer = (int) Math.min(CHUNK_SIZE, length - bytesTransferred);
limiter.acquire(toTransfer);
long lastWrite = out.applyToChannel((wbc) -> fc.transferTo(section.left + bytesTransferredFinal, toTransfer, wbc));
bytesTransferred += lastWrite;
progress += lastWrite;
session.progress(sstable.descriptor.filenameFor(Component.DATA), ProgressInfo.Direction.OUT, progress, totalSize);
}
}
logger.debug("[Stream #{}] Finished streaming file {} to {}, bytesTransferred = {}, totalSize = {}", session.planId(), sstable.getFilename(), session.peer, FBUtilities.prettyPrintMemory(progress), FBUtilities.prettyPrintMemory(totalSize));
}
}
use of org.apache.cassandra.io.util.ChannelProxy in project cassandra by apache.
the class MappedBufferTest method testOpenWithoutPageBits.
@Test
public void testOpenWithoutPageBits() throws IOException {
File tmp = File.createTempFile("mapped-buffer", "tmp");
tmp.deleteOnExit();
RandomAccessFile file = new RandomAccessFile(tmp, "rw");
long numValues = 1000;
for (long i = 0; i < numValues; i++) file.writeLong(i);
file.getFD().sync();
try (MappedBuffer buffer = new MappedBuffer(new ChannelProxy(tmp.getAbsolutePath(), file.getChannel()))) {
Assert.assertEquals(numValues * 8, buffer.limit());
Assert.assertEquals(numValues * 8, buffer.capacity());
for (long i = 0; i < numValues; i++) {
Assert.assertEquals(i * 8, buffer.position());
Assert.assertEquals(i, buffer.getLong());
}
} finally {
FileUtils.closeQuietly(file);
}
}
use of org.apache.cassandra.io.util.ChannelProxy in project cassandra by apache.
the class MappedBufferTest method createTestFile.
private MappedBuffer createTestFile(long numCount, int typeSize, int numPageBits, int padding) throws IOException {
final File testFile = File.createTempFile("mapped-buffer-test", "db");
testFile.deleteOnExit();
RandomAccessFile file = new RandomAccessFile(testFile, "rw");
for (long i = 0; i < numCount; i++) {
switch(typeSize) {
case 1:
file.write((byte) i);
break;
case 2:
file.writeShort((short) i);
break;
case 4:
file.writeInt((int) i);
break;
case 8:
// bunch of longs
file.writeLong(i);
break;
default:
throw new IllegalArgumentException("unknown byte size: " + typeSize);
}
for (int j = 0; j < padding; j++) file.write(0);
}
file.getFD().sync();
try {
return new MappedBuffer(new ChannelProxy(testFile.getAbsolutePath(), file.getChannel()), numPageBits);
} finally {
FileUtils.closeQuietly(file);
}
}
use of org.apache.cassandra.io.util.ChannelProxy in project cassandra by apache.
the class CompressedChecksummedDataInput method upgradeInput.
// Closing the ChecksummedDataInput will close the underlying channel.
@SuppressWarnings("resource")
public static ChecksummedDataInput upgradeInput(ChecksummedDataInput input, ICompressor compressor) {
long position = input.getPosition();
input.close();
return new CompressedChecksummedDataInput(new ChannelProxy(input.getPath()), compressor, position);
}
use of org.apache.cassandra.io.util.ChannelProxy in project cassandra by apache.
the class EncryptedChecksummedDataInput method upgradeInput.
@SuppressWarnings("resource")
public static ChecksummedDataInput upgradeInput(ChecksummedDataInput input, Cipher cipher, ICompressor compressor) {
long position = input.getPosition();
input.close();
return new EncryptedChecksummedDataInput(new ChannelProxy(input.getPath()), cipher, compressor, position);
}
Aggregations