more pre create-table property validation checks (compression, speculative retry)

patch by dbrosius reviewed by jbellis for cassandra 5693
This commit is contained in:
Dave Brosius 2013-06-24 01:38:00 -04:00
parent c0547983d3
commit 36ef643e42
3 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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<String, String> 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<String, String> remainingOptions = new HashMap<String, String>(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<? extends AbstractCompactionStrategy> getCompactionStrategy()

View File

@ -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)