From 36ef643e423e3683fd8cef339cdd95357140af4f Mon Sep 17 00:00:00 2001 From: Dave Brosius Date: Mon, 24 Jun 2013 01:38:00 -0400 Subject: [PATCH] more pre create-table property validation checks (compression, speculative retry) patch by dbrosius reviewed by jbellis for cassandra 5693 --- CHANGES.txt | 1 + .../org/apache/cassandra/cql3/CFPropDefs.java | 21 +++++++++++++++++++ .../io/compress/CompressionParameters.java | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3a242ac77e..ebcdd4eb15 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -62,6 +62,7 @@ (CASSANDRA-5149) * Streaming 2.0 (CASSANDRA-5286) * Conditional create/drop ks/table/index statements in CQL3 (CASSANDRA-2737) + * more pre-table creation property validation (CASSANDRA-5693) 1.2.7 diff --git a/src/java/org/apache/cassandra/cql3/CFPropDefs.java b/src/java/org/apache/cassandra/cql3/CFPropDefs.java index 7bd8fa33ff..2416df9b74 100644 --- a/src/java/org/apache/cassandra/cql3/CFPropDefs.java +++ b/src/java/org/apache/cassandra/cql3/CFPropDefs.java @@ -23,6 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.config.CFMetaData.SpeculativeRetry; import org.apache.cassandra.db.compaction.AbstractCompactionStrategy; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.SyntaxException; @@ -98,9 +99,29 @@ public class CFPropDefs extends PropertyDefinitions CFMetaData.validateCompactionOptions(compactionStrategyClass, compactionOptions); } + + Map compressionOptions = getCompressionOptions(); + if (!compressionOptions.isEmpty()) + { + String sstableCompressionClass = compressionOptions.get(CompressionParameters.SSTABLE_COMPRESSION); + if (sstableCompressionClass == null) + throw new ConfigurationException("Missing sub-option '" + CompressionParameters.SSTABLE_COMPRESSION + "' for the '" + KW_COMPRESSION + "' option."); + + String chunkLength = compressionOptions.get(CompressionParameters.CHUNK_LENGTH_KB); + if (chunkLength == null) + throw new ConfigurationException("Missing sub-option '" + CompressionParameters.CHUNK_LENGTH_KB + "' for the '" + KW_COMPRESSION + "' option."); + + Map remainingOptions = new HashMap(compressionOptions); + remainingOptions.remove(CompressionParameters.SSTABLE_COMPRESSION); + remainingOptions.remove(CompressionParameters.CHUNK_LENGTH_KB); + CompressionParameters cp = new CompressionParameters(sstableCompressionClass, CompressionParameters.parseChunkLength(chunkLength), remainingOptions); + cp.validate(); + } validateMinimumInt(KW_DEFAULT_TIME_TO_LIVE, 0, CFMetaData.DEFAULT_DEFAULT_TIME_TO_LIVE); validateMinimumInt(KW_INDEX_INTERVAL, 1, CFMetaData.DEFAULT_INDEX_INTERVAL); + + SpeculativeRetry.fromString(getString(KW_SPECULATIVE_RETRY, SpeculativeRetry.RetryType.NONE.name())); } public Class getCompactionStrategy() diff --git a/src/java/org/apache/cassandra/io/compress/CompressionParameters.java b/src/java/org/apache/cassandra/io/compress/CompressionParameters.java index 6448d84c6e..085018577e 100644 --- a/src/java/org/apache/cassandra/io/compress/CompressionParameters.java +++ b/src/java/org/apache/cassandra/io/compress/CompressionParameters.java @@ -203,7 +203,7 @@ public class CompressionParameters /** * Parse the chunk length (in KB) and returns it as bytes. */ - private static Integer parseChunkLength(String chLengthKB) throws ConfigurationException + public static Integer parseChunkLength(String chLengthKB) throws ConfigurationException { if (chLengthKB == null) return null; @@ -224,7 +224,7 @@ public class CompressionParameters // chunkLength must be a power of 2 because we assume so when // computing the chunk number from an uncompressed file offset (see // CompressedRandomAccessReader.decompresseChunk()) - private void validate() throws ConfigurationException + public void validate() throws ConfigurationException { // if chunk length was not set (chunkLength == null), this is fine, default will be used if (chunkLength != null)