From 787e0e648854634d5457dde6792acfb3d97c3b66 Mon Sep 17 00:00:00 2001 From: Sylvain Lebresne Date: Thu, 12 Jul 2012 11:05:11 +0200 Subject: [PATCH] Fix LCS splitting sstables based on uncompressed length patch by slebresne; reviewed by jbellis for CASSANDRA-4419 --- CHANGES.txt | 1 + .../cassandra/db/compaction/CompactionTask.java | 4 ++-- .../db/compaction/LeveledCompactionTask.java | 4 ++-- .../io/compress/CompressedSequentialWriter.java | 6 ++++++ .../apache/cassandra/io/sstable/SSTableWriter.java | 5 +++++ .../apache/cassandra/io/util/SequentialWriter.java | 12 ++++++++++++ 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d3cca6c1e36f..66a7b9e9e037 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,6 +10,7 @@ * Oversize integer in CQL throws NumberFormatException (CASSANDRA-4291) * Set gc_grace on index CF to 0 (CASSANDRA-4314) * fix 1.0.x node join to mixed version cluster, other nodes >= 1.1 (CASSANDRA-4195) + * Fix LCS splitting sstable base on uncompressed size (CASSANDRA-4419) 1.0.10 diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionTask.java b/src/java/org/apache/cassandra/db/compaction/CompactionTask.java index 2a1b4156329b..f554c7b6e7d4 100644 --- a/src/java/org/apache/cassandra/db/compaction/CompactionTask.java +++ b/src/java/org/apache/cassandra/db/compaction/CompactionTask.java @@ -169,7 +169,7 @@ public int execute(CompactionExecutorStatsCollector collector) throws IOExceptio } } } - if (!nni.hasNext() || newSSTableSegmentThresholdReached(writer, position)) + if (!nni.hasNext() || newSSTableSegmentThresholdReached(writer)) { SSTableReader toIndex = writer.closeAndOpenReader(getMaxDataAge(toCompact)); cachedKeyMap.put(toIndex, cachedKeys); @@ -229,7 +229,7 @@ protected boolean partialCompactionsAcceptable() } //extensibility point for other strategies that may want to limit the upper bounds of the sstable segment size - protected boolean newSSTableSegmentThresholdReached(SSTableWriter writer, long position) + protected boolean newSSTableSegmentThresholdReached(SSTableWriter writer) throws IOException { return false; } diff --git a/src/java/org/apache/cassandra/db/compaction/LeveledCompactionTask.java b/src/java/org/apache/cassandra/db/compaction/LeveledCompactionTask.java index b0b605a9e26d..d8729705b93a 100644 --- a/src/java/org/apache/cassandra/db/compaction/LeveledCompactionTask.java +++ b/src/java/org/apache/cassandra/db/compaction/LeveledCompactionTask.java @@ -69,9 +69,9 @@ public boolean isDone() } @Override - protected boolean newSSTableSegmentThresholdReached(SSTableWriter writer, long position) + protected boolean newSSTableSegmentThresholdReached(SSTableWriter writer) throws IOException { - return position > sstableSizeInMB * 1024L * 1024L; + return writer.getOnDiskFilePointer() > sstableSizeInMB * 1024L * 1024L; } @Override diff --git a/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java b/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java index 545b09ec8979..702a3435294a 100644 --- a/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java +++ b/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java @@ -68,6 +68,12 @@ public CompressedSequentialWriter(File file, String indexFilePath, boolean skipI this.sstableMetadataCollector = sstableMetadataCollector; } + @Override + public long getOnDiskFilePointer() throws IOException + { + return out.getFilePointer(); + } + @Override public void sync() throws IOException { diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java b/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java index 53980ed73df0..f08bb4965b45 100644 --- a/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java +++ b/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java @@ -382,6 +382,11 @@ public long getFilePointer() return dataFile.getFilePointer(); } + public long getOnDiskFilePointer() throws IOException + { + return dataFile.getOnDiskFilePointer(); + } + /** * Encapsulates writing the index and filter for an SSTable. The state of this object is not valid until it has been closed. */ diff --git a/src/java/org/apache/cassandra/io/util/SequentialWriter.java b/src/java/org/apache/cassandra/io/util/SequentialWriter.java index 79af8c1ea398..dce9bc6314b5 100644 --- a/src/java/org/apache/cassandra/io/util/SequentialWriter.java +++ b/src/java/org/apache/cassandra/io/util/SequentialWriter.java @@ -211,6 +211,18 @@ public long getFilePointer() return current; } + /** + * Return the current file pointer of the underlying on-disk file. + * Note that since write works by buffering data, the value of this will increase by buffer + * size and not every write to the writer will modify this value. + * Furthermore, for compressed files, this value refers to compressed data, while the + * writer getFilePointer() refers to uncompressedFile + */ + public long getOnDiskFilePointer() throws IOException + { + return getFilePointer(); + } + public long length() throws IOException { return Math.max(Math.max(current, out.length()), bufferOffset + validBufferBytes);