Merge branch 'cassandra-3.11' into trunk

This commit is contained in:
Jay Zhuang 2018-05-02 11:05:25 -07:00
commit 60ed982d53
3 changed files with 54 additions and 12 deletions

View File

@ -246,6 +246,7 @@
* 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)
* Add missed CQL keywords to documentation (CASSANDRA-14359)
* Fix unbounded validation compactions on repair / revert CASSANDRA-13797 (CASSANDRA-14332)

View File

@ -23,6 +23,7 @@ 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;
@ -941,18 +942,24 @@ public final class SchemaKeyspace
}
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, 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;
}
}
@ -1014,6 +1021,10 @@ public final class SchemaKeyspace
List<ColumnMetadata> columns = new ArrayList<>();
columnRows.forEach(row -> columns.add(createColumnFromRow(row, types)));
if (columns.stream().noneMatch(ColumnMetadata::isPartitionKey))
throw new MissingColumns("No partition key columns found in schema table for " + keyspace + "." + table);
return columns;
}
@ -1345,7 +1356,8 @@ public final class SchemaKeyspace
.collect(toList());
}
private static class MissingColumns extends RuntimeException
@VisibleForTesting
static class MissingColumns extends RuntimeException
{
MissingColumns(String message)
{

View File

@ -41,6 +41,7 @@ import org.apache.cassandra.db.rows.UnfilteredRowIterators;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.utils.FBUtilities;
import static org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -134,4 +135,32 @@ public class SchemaKeyspaceTest
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();
}
}