Merge branch 'cassandra-3.0' into cassandra-3.11

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

Branch: refs/heads/cassandra-3.11
Commit: 2d19de1cfabdc848477b33ba922c63013a7a9a1a
Parents: 783bbb3 eb68c31
Author: Jay Zhuang <jay.zhu...@yahoo.com>
Authored: Wed May 2 11:02:03 2018 -0700
Committer: Jay Zhuang <jay.zhu...@yahoo.com>
Committed: Wed May 2 11:03:34 2018 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../apache/cassandra/schema/SchemaKeyspace.java | 35 +++++++++++++-------
 .../cassandra/schema/SchemaKeyspaceTest.java    | 29 ++++++++++++++++
 3 files changed, 53 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/2d19de1c/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 443c298,39edeb1..837b891
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,15 -1,5 +1,16 @@@
 -3.0.17
 +3.11.3
 + * Allow existing nodes to use all peers in shadow round (CASSANDRA-13851)
 + * Fix cqlsh to read connection.ssl cqlshrc option again (CASSANDRA-14299)
 + * Downgrade log level to trace for CommitLogSegmentManager (CASSANDRA-14370)
 + * CQL fromJson(null) throws NullPointerException (CASSANDRA-13891)
 + * Serialize empty buffer as empty string for json output format 
(CASSANDRA-14245)
 + * Allow logging implementation to be interchanged for embedded testing 
(CASSANDRA-13396)
 + * SASI tokenizer for simple delimiter based entries (CASSANDRA-14247)
 + * Fix Loss of digits when doing CAST from varint/bigint to decimal 
(CASSANDRA-14170)
 + * RateBasedBackPressure unnecessarily invokes a lock on the Guava 
RateLimiter (CASSANDRA-14163)
 + * Fix wildcard GROUP BY queries (CASSANDRA-14209)
 +Merged from 3.0:
+  * Better handle missing partition columns in system_schema.columns 
(CASSANDRA-14379)
   * Delay hints store excise by write timeout to avoid race with decommission 
(CASSANDRA-13740)
   * Deprecate background repair and probablistic read_repair_chance table 
options
     (CASSANDRA-13910)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2d19de1c/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/schema/SchemaKeyspace.java
index 164e32d,81cc2e1..027b7cf
--- a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
+++ b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
@@@ -999,18 -961,24 +999,24 @@@ public final class SchemaKeyspac
              }
              catch (MissingColumns exc)
              {
-                 if (!IGNORE_CORRUPTED_SCHEMA_TABLES)
+                 String errorMsg = String.format("No partition columns found 
for table %s.%s in %s.%s.  This may be due to " +
+                                                 "corruption or concurrent 
dropping and altering of a table. If this table is supposed " +
+                                                 "to be dropped, {}run the 
following query to cleanup: " +
+                                                 "\"DELETE FROM %s.%s WHERE 
keyspace_name = '%s' AND table_name = '%s'; " +
+                                                 "DELETE FROM %s.%s WHERE 
keyspace_name = '%s' AND table_name = '%s';\" " +
+                                                 "If the table is not supposed 
to be dropped, restore %s.%s sstables from backups.",
 -                                                keyspaceName, tableName, 
NAME, COLUMNS,
 -                                                NAME, TABLES, keyspaceName, 
tableName,
 -                                                NAME, COLUMNS, keyspaceName, 
tableName,
 -                                                NAME, COLUMNS);
++                                                keyspaceName, tableName, 
SchemaConstants.SCHEMA_KEYSPACE_NAME, COLUMNS,
++                                                
SchemaConstants.SCHEMA_KEYSPACE_NAME, TABLES, keyspaceName, tableName,
++                                                
SchemaConstants.SCHEMA_KEYSPACE_NAME, COLUMNS, keyspaceName, tableName,
++                                                
SchemaConstants.SCHEMA_KEYSPACE_NAME, COLUMNS);
+ 
+                 if (IGNORE_CORRUPTED_SCHEMA_TABLES)
                  {
-                     logger.error("No columns found for table {}.{} in {}.{}.  
This may be due to " +
-                                  "corruption or concurrent dropping and 
altering of a table.  If this table " +
-                                  "is supposed to be dropped, restart 
cassandra with -Dcassandra.ignore_corrupted_schema_tables=true " +
-                                  "and run the following query: \"DELETE FROM 
{}.{} WHERE keyspace_name = '{}' AND table_name = '{}';\"." +
-                                  "If the table is not supposed to be dropped, 
restore {}.{} sstables from backups.",
-                                  keyspaceName, tableName,
-                                  SchemaConstants.SCHEMA_KEYSPACE_NAME, 
COLUMNS,
-                                  SchemaConstants.SCHEMA_KEYSPACE_NAME, TABLES,
-                                  keyspaceName, tableName,
-                                  SchemaConstants.SCHEMA_KEYSPACE_NAME, 
COLUMNS);
+                     logger.error(errorMsg, "", exc);
+                 }
+                 else
+                 {
+                     logger.error(errorMsg, "restart cassandra with 
-Dcassandra.ignore_corrupted_schema_tables=true and ");
                      throw exc;
                  }
              }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2d19de1c/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java
index 550deed,f76fc4f..f3ee85d
--- a/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java
+++ b/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java
@@@ -58,10 -51,9 +58,11 @@@ import org.apache.cassandra.thrift.Inde
  import org.apache.cassandra.thrift.ThriftConversion;
  import org.apache.cassandra.utils.ByteBufferUtil;
  import org.apache.cassandra.utils.FBUtilities;
 +import org.apache.cassandra.utils.Pair;
  
+ import static org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal;
  import static org.junit.Assert.assertEquals;
 +import static org.junit.Assert.assertFalse;
  import static org.junit.Assert.assertTrue;
  
  public class SchemaKeyspaceTest
@@@ -215,97 -207,31 +216,125 @@@
          assertEquals(new HashSet<>(cfm.allColumns()), columns);
      }
  
 +    private static boolean hasCDC(Mutation m)
 +    {
 +        for (PartitionUpdate p : m.getPartitionUpdates())
 +        {
 +            for (ColumnDefinition cd : p.columns())
 +            {
 +                if (cd.name.toString().equals("cdc"))
 +                    return true;
 +            }
 +        }
 +        return false;
 +    }
 +
 +    private static boolean hasSchemaTables(Mutation m)
 +    {
 +        for (PartitionUpdate p : m.getPartitionUpdates())
 +        {
 +            if (p.metadata().cfName.equals(SchemaKeyspace.TABLES))
 +                return true;
 +        }
 +        return false;
 +    }
 +
 +    @Test
 +    public void testConvertSchemaToMutationsWithoutCDC() throws IOException
 +    {
 +        boolean oldCDCOption = DatabaseDescriptor.isCDCEnabled();
 +        try
 +        {
 +            DatabaseDescriptor.setCDCEnabled(false);
 +            Collection<Mutation> mutations = 
SchemaKeyspace.convertSchemaToMutations();
 +            boolean foundTables = false;
 +            for (Mutation m : mutations)
 +            {
 +                if (hasSchemaTables(m))
 +                {
 +                    foundTables = true;
 +                    assertFalse(hasCDC(m));
 +                    try (DataOutputBuffer output = new DataOutputBuffer())
 +                    {
 +                        Mutation.serializer.serialize(m, output, 
MessagingService.current_version);
 +                        try (DataInputBuffer input = new 
DataInputBuffer(output.getData()))
 +                        {
 +                            Mutation out = 
Mutation.serializer.deserialize(input, MessagingService.current_version);
 +                            assertFalse(hasCDC(out));
 +                        }
 +                    }
 +                }
 +            }
 +            assertTrue(foundTables);
 +        }
 +        finally
 +        {
 +            DatabaseDescriptor.setCDCEnabled(oldCDCOption);
 +        }
 +    }
 +
 +    @Test
 +    public void testConvertSchemaToMutationsWithCDC()
 +    {
 +        boolean oldCDCOption = DatabaseDescriptor.isCDCEnabled();
 +        try
 +        {
 +            DatabaseDescriptor.setCDCEnabled(true);
 +            Collection<Mutation> mutations = 
SchemaKeyspace.convertSchemaToMutations();
 +            boolean foundTables = false;
 +            for (Mutation m : mutations)
 +            {
 +                if (hasSchemaTables(m))
 +                {
 +                    foundTables = true;
 +                    assertTrue(hasCDC(m));
 +                }
 +            }
 +            assertTrue(foundTables);
 +        }
 +        finally
 +        {
 +            DatabaseDescriptor.setCDCEnabled(oldCDCOption);
 +        }
 +    }
 +
 +    @Test
 +    public void testSchemaDigest()
 +    {
 +        Set<ByteBuffer> abc = 
Collections.singleton(ByteBufferUtil.bytes("abc"));
 +        Pair<UUID, UUID> versions = SchemaKeyspace.calculateSchemaDigest(abc);
 +        assertTrue(versions.left.equals(versions.right));
 +
 +        Set<ByteBuffer> cdc = 
Collections.singleton(ByteBufferUtil.bytes("cdc"));
 +        versions = SchemaKeyspace.calculateSchemaDigest(cdc);
 +        assertFalse(versions.left.equals(versions.right));
 +    }
++
+     @Test(expected = SchemaKeyspace.MissingColumns.class)
+     public void testSchemaNoPartition()
+     {
+         String testKS = "test_schema_no_partition";
+         String testTable = "invalid_table";
+         SchemaLoader.createKeyspace(testKS,
+                                     KeyspaceParams.simple(1),
+                                     SchemaLoader.standardCFMD(testKS, 
testTable));
+         // Delete partition column in the schema
 -        String query = String.format("DELETE FROM %s.%s WHERE keyspace_name=? 
and table_name=? and column_name=?", SchemaKeyspace.NAME, 
SchemaKeyspace.COLUMNS);
++        String query = String.format("DELETE FROM %s.%s WHERE keyspace_name=? 
and table_name=? and column_name=?", SchemaConstants.SCHEMA_KEYSPACE_NAME, 
SchemaKeyspace.COLUMNS);
+         executeOnceInternal(query, testKS, testTable, "key");
+         SchemaKeyspace.fetchNonSystemKeyspaces();
+     }
+ 
+     @Test(expected = SchemaKeyspace.MissingColumns.class)
+     public void testSchemaNoColumn()
+     {
+         String testKS = "test_schema_no_Column";
+         String testTable = "invalid_table";
+         SchemaLoader.createKeyspace(testKS,
+                                     KeyspaceParams.simple(1),
+                                     SchemaLoader.standardCFMD(testKS, 
testTable));
+         // Delete all colmns in the schema
 -        String query = String.format("DELETE FROM %s.%s WHERE keyspace_name=? 
and table_name=?", SchemaKeyspace.NAME, SchemaKeyspace.COLUMNS);
++        String query = String.format("DELETE FROM %s.%s WHERE keyspace_name=? 
and table_name=?", SchemaConstants.SCHEMA_KEYSPACE_NAME, 
SchemaKeyspace.COLUMNS);
+         executeOnceInternal(query, testKS, testTable);
+         SchemaKeyspace.fetchNonSystemKeyspaces();
+     }
  }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to