Fix formatting and set buffer size in test

This commit is contained in:
nivy 2026-07-28 13:21:26 -07:00
parent e83c85aed0
commit 8214ae208d
2 changed files with 5 additions and 8 deletions

View File

@ -18,13 +18,13 @@
package org.apache.cassandra.io.util; package org.apache.cassandra.io.util;
import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.apache.cassandra.io.compress.BufferType; import org.apache.cassandra.io.compress.BufferType;
import org.apache.cassandra.io.compress.CorruptBlockException;
import org.apache.cassandra.io.sstable.CorruptSSTableException; import org.apache.cassandra.io.sstable.CorruptSSTableException;
import org.apache.cassandra.utils.Closeable; import org.apache.cassandra.utils.Closeable;
import org.apache.cassandra.utils.memory.MemoryUtil; import org.apache.cassandra.utils.memory.MemoryUtil;
@ -106,9 +106,8 @@ public class ThreadLocalReadAheadBuffer implements Closeable
Block block = getBlock(); Block block = getBlock();
ByteBuffer blockBuffer = block.buffer; ByteBuffer blockBuffer = block.buffer;
if (position >= channelSize) if (position >= channelSize)
throw new CorruptSSTableException(new IOException(String.format("Chunk read past EOF: requested position %d must be less than file size %d", throw new CorruptSSTableException(new CorruptBlockException(channel.filePath(), position, bufferSize),
position, channelSize)), channel.filePath());
channel.filePath());
int blockNo = (int) (position / bufferSize); int blockNo = (int) (position / bufferSize);
long blockPosition = blockNo * (long) bufferSize; long blockPosition = blockNo * (long) bufferSize;

View File

@ -130,7 +130,7 @@ public class StandardCompressedChunkReaderTest extends CompressedChunkReaderTest
long longsToWrite = 600; // 4800 uncompressed bytes -> 2 compressed chunks (second one partial) long longsToWrite = 600; // 4800 uncompressed bytes -> 2 compressed chunks (second one partial)
CompressionMetadata metadata; CompressionMetadata metadata;
try (CompressedSequentialWriter writer = new CompressedSequentialWriter(f, offsets, digest, writerOption, params,new MetadataCollector(new ClusteringComparator()))) try (CompressedSequentialWriter writer = new CompressedSequentialWriter(f, offsets, digest, writerOption, params, new MetadataCollector(new ClusteringComparator())))
{ {
for (long i = 0; i < longsToWrite; i++) for (long i = 0; i < longsToWrite; i++)
writer.writeLong(i); writer.writeLong(i);
@ -139,9 +139,7 @@ public class StandardCompressedChunkReaderTest extends CompressedChunkReaderTest
metadata = writer.open(0); metadata = writer.open(0);
} }
// Sanity: read-ahead must actually engage for this test to exercise the scan path DatabaseDescriptor.setCompressedReadAheadBufferSizeInKb(256);
Assert.assertTrue("read-ahead must be larger than chunk length for scanReader to be non-null",
DatabaseDescriptor.getCompressedReadAheadBufferSize() > metadata.chunkLength());
// Truncate file so that chunk metadata expects a chunk to extend further than the actual file size // Truncate file so that chunk metadata expects a chunk to extend further than the actual file size
long originalSize = Files.size(f.toPath()); long originalSize = Files.size(f.toPath());