mirror of https://github.com/apache/cassandra
(CQL) compaction_strategy_options and compression_parameters for CREATE COLUMNFAMILY statement
patch by Pavel Yaskevich; reviewed by Paul Cannon for CASSANDRA-3374 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-1.0@1223003 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3150815d27
commit
76897cdcff
|
|
@ -10,6 +10,8 @@
|
||||||
* Avoid creating empty and non cleaned writer during compaction (CASSANDRA-3616)
|
* Avoid creating empty and non cleaned writer during compaction (CASSANDRA-3616)
|
||||||
* stop thrift service in shutdown hook so we can quiesce MessagingService
|
* stop thrift service in shutdown hook so we can quiesce MessagingService
|
||||||
(CASSANDRA-3335)
|
(CASSANDRA-3335)
|
||||||
|
* (CQL) compaction_strategy_options and compression_parameters for
|
||||||
|
CREATE COLUMNFAMILY statement (CASSANDRA-3374)
|
||||||
Merged from 0.8:
|
Merged from 0.8:
|
||||||
* avoid logging (harmless) exception when GC takes < 1ms (CASSANDRA-3656)
|
* avoid logging (harmless) exception when GC takes < 1ms (CASSANDRA-3656)
|
||||||
* prevent new nodes from thinking down nodes are up forever (CASSANDRA-3626)
|
* prevent new nodes from thinking down nodes are up forever (CASSANDRA-3626)
|
||||||
|
|
|
||||||
|
|
@ -488,9 +488,14 @@ bc(syntax).
|
||||||
<createColumnFamilyStatement> ::= "CREATE" "COLUMNFAMILY" <name>
|
<createColumnFamilyStatement> ::= "CREATE" "COLUMNFAMILY" <name>
|
||||||
"(" <term> <storageType> "PRIMARY" "KEY"
|
"(" <term> <storageType> "PRIMARY" "KEY"
|
||||||
( "," <term> <storageType> )* ")"
|
( "," <term> <storageType> )* ")"
|
||||||
( "WITH" <identifier> "=" <cfOptionVal>
|
( "WITH" <optionName> "=" <cfOptionVal>
|
||||||
( "AND" <identifier> "=" <cfOptionVal> )* )?
|
( "AND" <optionName> "=" <cfOptionVal> )* )?
|
||||||
;
|
;
|
||||||
|
<optionName> ::= <identifier>
|
||||||
|
| <optionName> ":" <identifier>
|
||||||
|
| <optionName> ":" <integer>
|
||||||
|
;
|
||||||
|
|
||||||
<cfOptionVal> ::= <storageType>
|
<cfOptionVal> ::= <storageType>
|
||||||
| <identifier>
|
| <identifier>
|
||||||
| <stringLiteral>
|
| <stringLiteral>
|
||||||
|
|
@ -549,6 +554,8 @@ A number of optional keyword arguments can be supplied to control the configurat
|
||||||
|row_cache_save_period_in_seconds|0|Number of seconds between saving row caches.|
|
|row_cache_save_period_in_seconds|0|Number of seconds between saving row caches.|
|
||||||
|key_cache_save_period_in_seconds|14400|Number of seconds between saving key caches.|
|
|key_cache_save_period_in_seconds|14400|Number of seconds between saving key caches.|
|
||||||
|replicate_on_write|false| |
|
|replicate_on_write|false| |
|
||||||
|
|compaction_strategy_options|none|CompactionStrategy specific options such as "sstable_size_in_mb" for LeveledCompactionStrategy and "min_sstable_size" for SizeTieredCompactionStrategy|
|
||||||
|
|compression_parameters|none|Compression parameters such as "sstable_compressor" and "chunk_length_kb"|
|
||||||
|
|
||||||
h2. CREATE INDEX
|
h2. CREATE INDEX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -377,8 +377,8 @@ createKeyspaceStatement returns [CreateKeyspaceStatement expr]
|
||||||
createColumnFamilyStatement returns [CreateColumnFamilyStatement expr]
|
createColumnFamilyStatement returns [CreateColumnFamilyStatement expr]
|
||||||
: K_CREATE K_COLUMNFAMILY name=( IDENT | STRING_LITERAL | INTEGER ) { $expr = new CreateColumnFamilyStatement($name.text); }
|
: K_CREATE K_COLUMNFAMILY name=( IDENT | STRING_LITERAL | INTEGER ) { $expr = new CreateColumnFamilyStatement($name.text); }
|
||||||
( '(' createCfamColumns[expr] ( ',' createCfamColumns[expr] )* ')' )?
|
( '(' createCfamColumns[expr] ( ',' createCfamColumns[expr] )* ')' )?
|
||||||
( K_WITH prop1=IDENT '=' arg1=createCfamKeywordArgument { $expr.addProperty($prop1.text, $arg1.arg); }
|
( K_WITH prop1=(COMPIDENT | IDENT) '=' arg1=createCfamKeywordArgument { $expr.addProperty($prop1.text, $arg1.arg); }
|
||||||
( K_AND propN=IDENT '=' argN=createCfamKeywordArgument { $expr.addProperty($propN.text, $argN.arg); } )*
|
( K_AND propN=(COMPIDENT | IDENT) '=' argN=createCfamKeywordArgument { $expr.addProperty($propN.text, $argN.arg); } )*
|
||||||
)?
|
)?
|
||||||
endStmnt
|
endStmnt
|
||||||
;
|
;
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ import org.apache.cassandra.db.marshal.TypeParser;
|
||||||
import org.apache.cassandra.thrift.InvalidRequestException;
|
import org.apache.cassandra.thrift.InvalidRequestException;
|
||||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||||
import org.apache.cassandra.utils.FBUtilities;
|
import org.apache.cassandra.utils.FBUtilities;
|
||||||
|
import org.apache.cassandra.io.compress.CompressionParameters;
|
||||||
|
|
||||||
/** A <code>CREATE COLUMNFAMILY</code> parsed from a CQL query statement. */
|
/** A <code>CREATE COLUMNFAMILY</code> parsed from a CQL query statement. */
|
||||||
public class CreateColumnFamilyStatement
|
public class CreateColumnFamilyStatement
|
||||||
|
|
@ -61,12 +62,16 @@ public class CreateColumnFamilyStatement
|
||||||
private static final String KW_KEYCACHESAVEPERIODSECS = "key_cache_save_period_in_seconds";
|
private static final String KW_KEYCACHESAVEPERIODSECS = "key_cache_save_period_in_seconds";
|
||||||
private static final String KW_REPLICATEONWRITE = "replicate_on_write";
|
private static final String KW_REPLICATEONWRITE = "replicate_on_write";
|
||||||
private static final String KW_ROW_CACHE_PROVIDER = "row_cache_provider";
|
private static final String KW_ROW_CACHE_PROVIDER = "row_cache_provider";
|
||||||
|
private static final String KW_COMPACTION_STRATEGY_CLASS = "compaction_strategy_class";
|
||||||
|
|
||||||
// Maps CQL short names to the respective Cassandra comparator/validator class names
|
// Maps CQL short names to the respective Cassandra comparator/validator class names
|
||||||
public static final Map<String, String> comparators = new HashMap<String, String>();
|
public static final Map<String, String> comparators = new HashMap<String, String>();
|
||||||
private static final Set<String> keywords = new HashSet<String>();
|
private static final Set<String> keywords = new HashSet<String>();
|
||||||
private static final Set<String> obsoleteKeywords = new HashSet<String>();
|
private static final Set<String> obsoleteKeywords = new HashSet<String>();
|
||||||
|
|
||||||
|
private static final String COMPACTION_OPTIONS_PREFIX = "compaction_strategy_options";
|
||||||
|
private static final String COMPRESSION_PARAMETERS_PREFIX = "compression_parameters";
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
comparators.put("ascii", "AsciiType");
|
comparators.put("ascii", "AsciiType");
|
||||||
|
|
@ -97,6 +102,7 @@ public class CreateColumnFamilyStatement
|
||||||
keywords.add(KW_KEYCACHESAVEPERIODSECS);
|
keywords.add(KW_KEYCACHESAVEPERIODSECS);
|
||||||
keywords.add(KW_REPLICATEONWRITE);
|
keywords.add(KW_REPLICATEONWRITE);
|
||||||
keywords.add(KW_ROW_CACHE_PROVIDER);
|
keywords.add(KW_ROW_CACHE_PROVIDER);
|
||||||
|
keywords.add(KW_COMPACTION_STRATEGY_CLASS);
|
||||||
|
|
||||||
obsoleteKeywords.add("memtable_throughput_in_mb");
|
obsoleteKeywords.add("memtable_throughput_in_mb");
|
||||||
obsoleteKeywords.add("memtable_operations_in_millions");
|
obsoleteKeywords.add("memtable_operations_in_millions");
|
||||||
|
|
@ -108,6 +114,8 @@ public class CreateColumnFamilyStatement
|
||||||
private final Map<String, String> properties = new HashMap<String, String>();
|
private final Map<String, String> properties = new HashMap<String, String>();
|
||||||
private List<String> keyValidator = new ArrayList<String>();
|
private List<String> keyValidator = new ArrayList<String>();
|
||||||
private ByteBuffer keyAlias = null;
|
private ByteBuffer keyAlias = null;
|
||||||
|
private final Map<String, String> compactionStrategyOptions = new HashMap<String, String>();
|
||||||
|
private final Map<String, String> compressionParameters = new HashMap<String, String>();
|
||||||
|
|
||||||
public CreateColumnFamilyStatement(String name)
|
public CreateColumnFamilyStatement(String name)
|
||||||
{
|
{
|
||||||
|
|
@ -117,6 +125,34 @@ public class CreateColumnFamilyStatement
|
||||||
/** Perform validation of parsed params */
|
/** Perform validation of parsed params */
|
||||||
private void validate() throws InvalidRequestException
|
private void validate() throws InvalidRequestException
|
||||||
{
|
{
|
||||||
|
// we need to remove parent:key = value pairs from the main properties
|
||||||
|
Set<String> propsToRemove = new HashSet<String>();
|
||||||
|
|
||||||
|
// check if we have compaction/compression options
|
||||||
|
for (String property : properties.keySet())
|
||||||
|
{
|
||||||
|
if (!property.contains(":"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String key = property.split(":")[1];
|
||||||
|
String val = properties.get(property);
|
||||||
|
|
||||||
|
if (property.startsWith(COMPACTION_OPTIONS_PREFIX))
|
||||||
|
{
|
||||||
|
compactionStrategyOptions.put(key, val);
|
||||||
|
propsToRemove.add(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property.startsWith(COMPRESSION_PARAMETERS_PREFIX))
|
||||||
|
{
|
||||||
|
compressionParameters.put(key, val);
|
||||||
|
propsToRemove.add(property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String property : propsToRemove)
|
||||||
|
properties.remove(property);
|
||||||
|
|
||||||
// Column family name
|
// Column family name
|
||||||
if (!name.matches("\\w+"))
|
if (!name.matches("\\w+"))
|
||||||
throw new InvalidRequestException(String.format("\"%s\" is not a valid column family name", name));
|
throw new InvalidRequestException(String.format("\"%s\" is not a valid column family name", name));
|
||||||
|
|
@ -302,6 +338,8 @@ public class CreateColumnFamilyStatement
|
||||||
.keyValidator(TypeParser.parse(comparators.get(getKeyType())))
|
.keyValidator(TypeParser.parse(comparators.get(getKeyType())))
|
||||||
.rowCacheProvider(FBUtilities.newCacheProvider(getPropertyString(KW_ROW_CACHE_PROVIDER, CFMetaData.DEFAULT_ROW_CACHE_PROVIDER.getClass().getName())))
|
.rowCacheProvider(FBUtilities.newCacheProvider(getPropertyString(KW_ROW_CACHE_PROVIDER, CFMetaData.DEFAULT_ROW_CACHE_PROVIDER.getClass().getName())))
|
||||||
.keyAlias(keyAlias)
|
.keyAlias(keyAlias)
|
||||||
|
.compactionStrategyOptions(compactionStrategyOptions)
|
||||||
|
.compressionParameters(CompressionParameters.create(compressionParameters))
|
||||||
.validate();
|
.validate();
|
||||||
}
|
}
|
||||||
catch (ConfigurationException e)
|
catch (ConfigurationException e)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue