cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject [2/4] cassandra git commit: Disallow default_time_to_live on counter tables
Date Fri, 30 Jan 2015 22:42:32 GMT
Disallow default_time_to_live on counter tables

Patch by Jeff Jirsa; reviewed by Tyler Hobbs for CASSANDRA-8678


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/d0005a83
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/d0005a83
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/d0005a83

Branch: refs/heads/trunk
Commit: d0005a83ef9bfc1042747cbe45708ded1f2002ba
Parents: 6ae8ada
Author: Jeff Jirsa <jeff@jeffjirsa.net>
Authored: Fri Jan 30 16:33:56 2015 -0600
Committer: Tyler Hobbs <tyler@datastax.com>
Committed: Fri Jan 30 16:33:56 2015 -0600

----------------------------------------------------------------------
 CHANGES.txt                                                    | 5 ++++-
 src/java/org/apache/cassandra/config/CFMetaData.java           | 5 +++++
 .../apache/cassandra/cql3/statements/AlterTableStatement.java  | 4 ++++
 src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java  | 5 +++++
 .../apache/cassandra/cql3/statements/CreateTableStatement.java | 6 ++++++
 src/java/org/apache/cassandra/db/marshal/AbstractType.java     | 5 +++++
 .../org/apache/cassandra/db/marshal/CounterColumnType.java     | 5 +++++
 7 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/d0005a83/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 7fa5f63..4754867 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,8 @@
 2.0.13:
- * Fix SSTableSimpleUnsortedWriter ConcurrentModificationException (CASSANDRA-8619)
+ * Prevent non-zero default_time_to_live on tables with counters
+   (CASSANDRA-8678)
+ * Fix SSTableSimpleUnsortedWriter ConcurrentModificationException
+   (CASSANDRA-8619)
  * Round up time deltas lower than 1ms in BulkLoader (CASSANDRA-8645)
  * Add batch remove iterator to ABSC (CASSANDRA-8414, 8666)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/d0005a83/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java
index 9d69710..04a5b01 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -2192,6 +2192,11 @@ public final class CFMetaData
         return true;
     }
 
+    public boolean isCounter()
+    {
+        return defaultValidator.isCounter();
+    }
+
     public boolean hasStaticColumns()
     {
         return !staticColumns.isEmpty();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/d0005a83/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
index 32f949f..f74670f 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -268,6 +268,10 @@ public class AlterTableStatement extends SchemaAlteringStatement
                     throw new InvalidRequestException(String.format("ALTER COLUMNFAMILY WITH
invoked, but no parameters found"));
 
                 cfProps.validate();
+
+                if (meta.isCounter() && cfProps.getDefaultTimeToLive() > 0)
+                    throw new InvalidRequestException("Cannot set default_time_to_live on
a table with counters");
+
                 cfProps.applyToCFMetadata(cfm);
                 break;
             case RENAME:

http://git-wip-us.apache.org/repos/asf/cassandra/blob/d0005a83/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java b/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java
index 6ce6406..11aa9b2 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java
@@ -138,6 +138,11 @@ public class CFPropDefs extends PropertyDefinitions
         return compressionOptions;
     }
 
+    public Integer getDefaultTimeToLive() throws SyntaxException
+    {
+        return getInt(KW_DEFAULT_TIME_TO_LIVE, 0);
+    }
+
     public void applyToCFMetadata(CFMetaData cfm) throws ConfigurationException, SyntaxException
     {
         if (hasProperty(KW_COMMENT))

http://git-wip-us.apache.org/repos/asf/cassandra/blob/d0005a83/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
index 5160d6f..5215118 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
@@ -207,6 +207,7 @@ public class CreateTableStatement extends SchemaAlteringStatement
 
             CreateTableStatement stmt = new CreateTableStatement(cfName, properties, ifNotExists,
staticColumns);
 
+            boolean hasCounters = false;
             Map<ByteBuffer, CollectionType> definedCollections = null;
             for (Map.Entry<ColumnIdentifier, CQL3Type> entry : definitions.entrySet())
             {
@@ -218,6 +219,9 @@ public class CreateTableStatement extends SchemaAlteringStatement
                         definedCollections = new HashMap<ByteBuffer, CollectionType>();
                     definedCollections.put(id.key, (CollectionType)pt.getType());
                 }
+                else if (entry.getValue().isCounter())
+                    hasCounters = true;
+
                 stmt.columns.put(id, pt.getType()); // we'll remove what is not a column
below
             }
 
@@ -225,6 +229,8 @@ public class CreateTableStatement extends SchemaAlteringStatement
                 throw new InvalidRequestException("No PRIMARY KEY specifed (exactly one required)");
             else if (keyAliases.size() > 1)
                 throw new InvalidRequestException("Multiple PRIMARY KEYs specifed (exactly
one required)");
+            else if (hasCounters && properties.getDefaultTimeToLive() > 0)
+                throw new InvalidRequestException("Cannot set default_time_to_live on a table
with counters");
 
             List<ColumnIdentifier> kAliases = keyAliases.get(0);
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/d0005a83/src/java/org/apache/cassandra/db/marshal/AbstractType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/AbstractType.java b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
index e92f272..dce521b 100644
--- a/src/java/org/apache/cassandra/db/marshal/AbstractType.java
+++ b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
@@ -212,6 +212,11 @@ public abstract class AbstractType<T> implements Comparator<ByteBuffer>
         return false;
     }
 
+    public boolean isCounter()
+    {
+        return false;
+    }
+
     public static AbstractType<?> parseDefaultParameters(AbstractType<?> baseType,
TypeParser parser) throws SyntaxException
     {
         Map<String, String> parameters = parser.getKeyValueParameters();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/d0005a83/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java b/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
index 6a77458..1ecdad9 100644
--- a/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
+++ b/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
@@ -31,6 +31,11 @@ public class CounterColumnType extends AbstractCommutativeType
 
     CounterColumnType() {} // singleton
 
+    public boolean isCounter()
+    {
+        return true;
+    }
+
     public int compare(ByteBuffer o1, ByteBuffer o2)
     {
         if (o1 == null)


Mime
View raw message