You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jz...@apache.org on 2018/05/02 19:22:00 UTC

[6/6] cassandra git commit: Merge branch 'cassandra-3.11' into trunk

Merge branch 'cassandra-3.11' into trunk


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

Branch: refs/heads/trunk
Commit: 60ed982d5309b674abfb32584f75f676951c2668
Parents: 0143974 2d19de1
Author: Jay Zhuang <ja...@yahoo.com>
Authored: Wed May 2 11:05:25 2018 -0700
Committer: Jay Zhuang <ja...@yahoo.com>
Committed: Wed May 2 11:08:18 2018 -0700

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


http://git-wip-us.apache.org/repos/asf/cassandra/blob/60ed982d/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 27e69b8,837b891..5831978
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -246,7 -10,10 +246,8 @@@
   * 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)
   * Add missed CQL keywords to documentation (CASSANDRA-14359)
   * Fix unbounded validation compactions on repair / revert CASSANDRA-13797 (CASSANDRA-14332)
   * Avoid deadlock when running nodetool refresh before node is fully up (CASSANDRA-14310)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/60ed982d/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/schema/SchemaKeyspace.java
index ca3c69f,027b7cf..638e912
--- a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
+++ b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
@@@ -23,9 -25,9 +23,10 @@@ import java.util.*
  import java.util.concurrent.TimeUnit;
  import java.util.stream.Collectors;
  
+ import com.google.common.annotations.VisibleForTesting;
  import com.google.common.collect.*;
  import com.google.common.collect.Maps;
 +import com.google.common.hash.Hasher;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
@@@ -1012,8 -1097,12 +1019,12 @@@ public final class SchemaKeyspac
          if (columnRows.isEmpty())
              throw new MissingColumns("Columns not found in schema table for " + keyspace + "." + table);
  
 -        List<ColumnDefinition> columns = new ArrayList<>();
 +        List<ColumnMetadata> columns = new ArrayList<>();
          columnRows.forEach(row -> columns.add(createColumnFromRow(row, types)));
+ 
 -        if (columns.stream().noneMatch(ColumnDefinition::isPartitionKey))
++        if (columns.stream().noneMatch(ColumnMetadata::isPartitionKey))
+             throw new MissingColumns("No partition key columns found in schema table for " + keyspace + "." + table);
+ 
          return columns;
      }
  

http://git-wip-us.apache.org/repos/asf/cassandra/blob/60ed982d/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java
index d4c4bb4,f3ee85d..b3a7047
--- a/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java
+++ b/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java
@@@ -39,9 -47,22 +39,10 @@@ import org.apache.cassandra.db.Mutation
  import org.apache.cassandra.db.partitions.PartitionUpdate;
  import org.apache.cassandra.db.rows.UnfilteredRowIterators;
  import org.apache.cassandra.exceptions.ConfigurationException;
 -import org.apache.cassandra.io.util.DataInputBuffer;
 -import org.apache.cassandra.io.util.DataOutputBuffer;
 -import org.apache.cassandra.net.MessagingService;
 -import org.apache.cassandra.thrift.CfDef;
 -import org.apache.cassandra.thrift.ColumnDef;
 -import org.apache.cassandra.thrift.IndexType;
 -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
@@@ -131,7 -212,129 +132,35 @@@
          for (UntypedResultSet.Row row : columnsRows)
              columns.add(SchemaKeyspace.createColumnFromRow(row, Types.none()));
  
 -        assertEquals(cfm.params, params);
 -        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));
 +        assertEquals(metadata.params, params);
 +        assertEquals(new HashSet<>(metadata.columns()), columns);
      }
+ 
+     @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=?", 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=?", SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.COLUMNS);
+         executeOnceInternal(query, testKS, testTable);
+         SchemaKeyspace.fetchNonSystemKeyspaces();
+     }
  }


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