Fix bug in compact storage metadata handling patch by slebresne; reviewed by jasobrown for CASSANDRA-5189
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/be36736d Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/be36736d Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/be36736d Branch: refs/heads/trunk Commit: be36736d38eb5793bab6040817260fd5c6cd166b Parents: 4feb87d Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Tue Jan 29 19:08:41 2013 +0100 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Tue Jan 29 19:08:41 2013 +0100 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../statements/CreateColumnFamilyStatement.java | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/be36736d/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 46d79cc..e1af9ee 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,6 @@ 1.2.2 * fix symlinks under data dir not working (CASSANDRA-5185) + * fix bug in compact storage metadata handling (CASSANDRA-5189) 1.2.1 * stream undelivered hints on decommission (CASSANDRA-5128) http://git-wip-us.apache.org/repos/asf/cassandra/blob/be36736d/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java index 4b96167..483e083 100644 --- a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java @@ -276,13 +276,10 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement } } - if (useCompactStorage && stmt.columns.size() <= 1) + if (useCompactStorage && !stmt.columnAliases.isEmpty()) { if (stmt.columns.isEmpty()) { - if (columnAliases.isEmpty()) - throw new InvalidRequestException(String.format("COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY (got: %s)", StringUtils.join(stmt.columns.keySet(), ", "))); - // The only value we'll insert will be the empty one, so the default validator don't matter stmt.defaultValidator = BytesType.instance; // We need to distinguish between @@ -293,6 +290,9 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement } else { + if (stmt.columns.size() > 1) + throw new InvalidRequestException(String.format("COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY (got: %s)", StringUtils.join(stmt.columns.keySet(), ", "))); + Map.Entry<ColumnIdentifier, AbstractType> lastEntry = stmt.columns.entrySet().iterator().next(); stmt.defaultValidator = lastEntry.getValue(); stmt.valueAlias = lastEntry.getKey().key; @@ -301,8 +301,10 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement } else { - if (useCompactStorage && !columnAliases.isEmpty()) - throw new InvalidRequestException(String.format("COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY (got: %s)", StringUtils.join(stmt.columns.keySet(), ", "))); + // For compact, we are in the "static" case, so we need at least one column defined. For non-compact however, having + // just the PK is fine since we have CQL3 row marker. + if (useCompactStorage && stmt.columns.isEmpty()) + throw new InvalidRequestException("COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY, none given"); // There is no way to insert/access a column that is not defined for non-compact storage, so // the actual validator don't matter much (except that we want to recognize counter CF as limitation apply to them).