Merge branch 'cassandra-2.1' into cassandra-2.2

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

Branch: refs/heads/cassandra-2.2
Commit: 85c724183a2caee3a9bb73441d27b3cbce7207c4
Parents: 263763a cee35e4
Author: Marcus Eriksson <marc...@apache.org>
Authored: Tue Dec 15 10:01:20 2015 +0100
Committer: Marcus Eriksson <marc...@apache.org>
Committed: Tue Dec 15 10:06:44 2015 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |   1 +
 .../org/apache/cassandra/config/CFMetaData.java |   4 +-
 .../cql3/statements/AlterTableStatement.java    |   2 +
 .../cassandra/cql3/statements/CFPropDefs.java   |  24 ++++-
 .../cql3/statements/CreateTableStatement.java   |   9 +-
 .../operations/DropRecreateAndRestoreTest.java  | 105 +++++++++++++++++++
 6 files changed, 135 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/85c72418/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 592ba0a,7f1d66b..c9074fc
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,10 -1,5 +1,11 @@@
 -2.1.13
 +2.2.5
 + * Add property to allow listening on broadcast interface (CASSANDRA-9748)
 + * Fix regression in split size on CqlInputFormat (CASSANDRA-10835)
 + * Better handling of SSL connection errors inter-node (CASSANDRA-10816)
 + * Disable reloading of GossipingPropertyFileSnitch (CASSANDRA-9474)
 + * Verify tables in pseudo-system keyspaces at startup (CASSANDRA-10761)
 +Merged from 2.1:
+  * Allow CREATE TABLE WITH ID (CASSANDRA-9179)
   * Make Stress compiles within eclipse (CASSANDRA-10807)
   * Cassandra Daemon should print JVM arguments (CASSANDRA-10764)
   * Allow cancellation of index summary redistribution (CASSANDRA-8805)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/85c72418/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/85c72418/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/85c72418/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/85c72418/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
----------------------------------------------------------------------
diff --cc 
src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
index 7810a8a,2c4b23b..1b3665c
--- a/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
@@@ -71,13 -72,21 +72,14 @@@ public class CreateTableStatement exten
          this.properties = properties;
          this.ifNotExists = ifNotExists;
          this.staticColumns = staticColumns;
+         this.id = id;
  
 -        try
 -        {
 -            if (!this.properties.hasProperty(CFPropDefs.KW_COMPRESSION) && 
CFMetaData.DEFAULT_COMPRESSOR != null)
 -                this.properties.addProperty(CFPropDefs.KW_COMPRESSION,
 -                                            new HashMap<String, String>()
 -                                            {{
 -                                                
put(CompressionParameters.SSTABLE_COMPRESSION, CFMetaData.DEFAULT_COMPRESSOR);
 -                                            }});
 -        }
 -        catch (SyntaxException e)
 -        {
 -            throw new AssertionError(e);
 -        }
 +        if (!this.properties.hasProperty(CFPropDefs.KW_COMPRESSION) && 
CFMetaData.DEFAULT_COMPRESSOR != null)
 +            this.properties.addProperty(CFPropDefs.KW_COMPRESSION,
 +                                        new HashMap<String, String>()
 +                                        {{
 +                                            
put(CompressionParameters.SSTABLE_COMPRESSION, CFMetaData.DEFAULT_COMPRESSOR);
 +                                        }});
      }
  
      public void checkAccess(ClientState state) throws UnauthorizedException, 
InvalidRequestException

http://git-wip-us.apache.org/repos/asf/cassandra/blob/85c72418/test/unit/org/apache/cassandra/cql3/validation/operations/DropRecreateAndRestoreTest.java
----------------------------------------------------------------------
diff --cc 
test/unit/org/apache/cassandra/cql3/validation/operations/DropRecreateAndRestoreTest.java
index 0000000,385ed3d..4a3a51d
mode 000000,100644..100644
--- 
a/test/unit/org/apache/cassandra/cql3/validation/operations/DropRecreateAndRestoreTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/operations/DropRecreateAndRestoreTest.java
@@@ -1,0 -1,105 +1,105 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one
+  * or more contributor license agreements.  See the NOTICE file
+  * distributed with this work for additional information
+  * regarding copyright ownership.  The ASF licenses this file
+  * to you under the Apache License, Version 2.0 (the
+  * "License"); you may not use this file except in compliance
+  * with the License.  You may obtain a copy of the License at
+  *
+  *     http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+ package org.apache.cassandra.cql3.validation.operations;
+ 
+ import java.io.File;
+ import java.util.List;
+ import java.util.UUID;
+ 
+ import org.junit.Test;
+ 
+ import org.apache.cassandra.config.DatabaseDescriptor;
+ import org.apache.cassandra.cql3.CQLTester;
+ import org.apache.cassandra.db.commitlog.CommitLog;
+ import org.apache.cassandra.exceptions.AlreadyExistsException;
+ import org.apache.cassandra.exceptions.ConfigurationException;
+ import org.apache.cassandra.exceptions.InvalidRequestException;
+ import org.apache.cassandra.io.util.FileUtils;
+ 
+ public class DropRecreateAndRestoreTest extends CQLTester
+ {
+     @Test
+     public void testCreateWithIdRestore() throws Throwable
+     {
+         createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY(a, 
b))");
+ 
+         execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0, 0);
+         execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, 1);
+ 
+ 
+         long time = System.currentTimeMillis();
+         UUID id = currentTableMetadata().cfId;
+         assertRows(execute("SELECT * FROM %s"), row(0, 0, 0), row(0, 1, 1));
+         Thread.sleep(5);
+ 
+         execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 1, 0, 2);
+         execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 1, 1, 3);
+         assertRows(execute("SELECT * FROM %s"), row(1, 0, 2), row(1, 1, 3), 
row(0, 0, 0), row(0, 1, 1));
+ 
+         // Drop will flush and clean segments. Hard-link them so that they 
can be restored later.
+         List<String> segments = CommitLog.instance.getActiveSegmentNames();
+         File logPath = new File(DatabaseDescriptor.getCommitLogLocation());
+         for (String segment: segments)
+             FileUtils.createHardLink(new File(logPath, segment), new 
File(logPath, segment + ".save"));
+ 
+         execute("DROP TABLE %s");
+ 
+         assertInvalidThrow(InvalidRequestException.class, "SELECT * FROM %s");
+ 
+         execute(String.format("CREATE TABLE %%s (a int, b int, c int, PRIMARY 
KEY(a, b)) WITH ID = %s", id));
+ 
+         // Restore saved segments
+         for (String segment: segments)
+             FileUtils.renameWithConfirm(new File(logPath, segment + ".save"), 
new File(logPath, segment));
+         try
+         {
+             // Restore to point in time.
+             CommitLog.instance.archiver.restorePointInTime = time;
 -            CommitLog.instance.resetUnsafe();
++            CommitLog.instance.resetUnsafe(true);
+             CommitLog.instance.recover();
+         }
+         finally
+         {
+             CommitLog.instance.archiver.restorePointInTime = Long.MAX_VALUE;
+         }
+ 
+         assertRows(execute("SELECT * FROM %s"), row(0, 0, 0), row(0, 1, 1));
+     }
+ 
+     @Test(expected = AlreadyExistsException.class)
+     public void testCreateWithIdDuplicate() throws Throwable
+     {
+         createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY(a, 
b))");
+         UUID id = currentTableMetadata().cfId;
+         execute(String.format("CREATE TABLE %%s (a int, b int, c int, PRIMARY 
KEY(a, b)) WITH ID = %s", id));
+     }
+ 
+     @Test(expected = ConfigurationException.class)
+     public void testCreateWithIdInvalid() throws Throwable
+     {
+         createTableMayThrow(String.format("CREATE TABLE %%s (a int, b int, c 
int, PRIMARY KEY(a, b)) WITH ID = %s", 55));
+     }
+ 
+     @Test(expected = ConfigurationException.class)
+     public void testAlterWithId() throws Throwable
+     {
+         createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY(a, 
b))");
+         UUID id = currentTableMetadata().cfId;
+         execute(String.format("ALTER TABLE %%s WITH ID = %s", id));
+     }
+ }

Reply via email to