mirror of https://github.com/apache/cassandra
Merge branch 'cassandra-3.0' into cassandra-3.11
This commit is contained in:
commit
61a47afc0f
|
|
@ -4,6 +4,7 @@
|
|||
* Duplicate the buffer before passing it to analyser in SASI operation (CASSANDRA-13512)
|
||||
* Properly evict pstmts from prepared statements cache (CASSANDRA-13641)
|
||||
Merged from 3.0:
|
||||
* Log warn message until legacy auth tables have been migrated (CASSANDRA-13371)
|
||||
* Fix incorrect [2.1 <- 3.0] serialization of counter cells created in 2.0 (CASSANDRA-13691)
|
||||
* Fix invalid writetime for null cells (CASSANDRA-13711)
|
||||
* Fix ALTER TABLE statement to atomically propagate changes to the table and its MVs (CASSANDRA-12952)
|
||||
|
|
|
|||
|
|
@ -23,9 +23,12 @@ import java.io.IOException;
|
|||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -38,6 +41,8 @@ import org.apache.cassandra.config.SchemaConstants;
|
|||
import org.apache.cassandra.db.ColumnFamilyStore;
|
||||
import org.apache.cassandra.db.Directories;
|
||||
import org.apache.cassandra.db.SystemKeyspace;
|
||||
import org.apache.cassandra.cql3.QueryProcessor;
|
||||
import org.apache.cassandra.cql3.UntypedResultSet;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.cassandra.exceptions.StartupException;
|
||||
import org.apache.cassandra.io.sstable.Descriptor;
|
||||
|
|
@ -87,7 +92,8 @@ public class StartupChecks
|
|||
checkSSTablesFormat,
|
||||
checkSystemKeyspaceState,
|
||||
checkDatacenter,
|
||||
checkRack);
|
||||
checkRack,
|
||||
checkLegacyAuthTables);
|
||||
|
||||
public StartupChecks withDefaultTests()
|
||||
{
|
||||
|
|
@ -425,4 +431,28 @@ public class StartupChecks
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static final StartupCheck checkLegacyAuthTables = () -> checkLegacyAuthTablesMessage().ifPresent(logger::warn);
|
||||
|
||||
static final Set<String> LEGACY_AUTH_TABLES = ImmutableSet.of("credentials", "users", "permissions");
|
||||
|
||||
@VisibleForTesting
|
||||
static Optional<String> checkLegacyAuthTablesMessage()
|
||||
{
|
||||
List<String> existing = new ArrayList<>(LEGACY_AUTH_TABLES).stream().filter((legacyAuthTable) ->
|
||||
{
|
||||
UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT table_name FROM %s.%s WHERE keyspace_name='%s' AND table_name='%s'",
|
||||
SchemaConstants.SCHEMA_KEYSPACE_NAME,
|
||||
"tables",
|
||||
SchemaConstants.AUTH_KEYSPACE_NAME,
|
||||
legacyAuthTable));
|
||||
return result != null && !result.isEmpty();
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (!existing.isEmpty())
|
||||
return Optional.of(String.format("Legacy auth tables %s in keyspace %s still exist and have not been properly migrated.",
|
||||
Joiner.on(", ").join(existing), SchemaConstants.AUTH_KEYSPACE_NAME));
|
||||
else
|
||||
return Optional.empty();
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* 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.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.cassandra.config.SchemaConstants;
|
||||
import org.apache.cassandra.cql3.CQLTester;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class LegacyAuthFailTest extends CQLTester
|
||||
{
|
||||
@Test
|
||||
public void testStartupChecks() throws Throwable
|
||||
{
|
||||
createKeyspace();
|
||||
|
||||
List<String> legacyTables = new ArrayList<>(StartupChecks.LEGACY_AUTH_TABLES);
|
||||
|
||||
// test reporting for individual tables
|
||||
for (String legacyTable : legacyTables)
|
||||
{
|
||||
createLegacyTable(legacyTable);
|
||||
|
||||
Optional<String> errMsg = StartupChecks.checkLegacyAuthTablesMessage();
|
||||
assertEquals(format("Legacy auth tables %s in keyspace %s still exist and have not been properly migrated.",
|
||||
legacyTable,
|
||||
SchemaConstants.AUTH_KEYSPACE_NAME), errMsg.get());
|
||||
dropLegacyTable(legacyTable);
|
||||
}
|
||||
|
||||
// test reporting of multiple existing tables
|
||||
for (String legacyTable : legacyTables)
|
||||
createLegacyTable(legacyTable);
|
||||
|
||||
while (!legacyTables.isEmpty())
|
||||
{
|
||||
Optional<String> errMsg = StartupChecks.checkLegacyAuthTablesMessage();
|
||||
assertEquals(format("Legacy auth tables %s in keyspace %s still exist and have not been properly migrated.",
|
||||
Joiner.on(", ").join(legacyTables),
|
||||
SchemaConstants.AUTH_KEYSPACE_NAME), errMsg.get());
|
||||
|
||||
dropLegacyTable(legacyTables.remove(0));
|
||||
}
|
||||
|
||||
// no legacy tables found
|
||||
Optional<String> errMsg = StartupChecks.checkLegacyAuthTablesMessage();
|
||||
assertFalse(errMsg.isPresent());
|
||||
}
|
||||
|
||||
private void dropLegacyTable(String legacyTable) throws Throwable
|
||||
{
|
||||
execute(format("DROP TABLE %s.%s", SchemaConstants.AUTH_KEYSPACE_NAME, legacyTable));
|
||||
}
|
||||
|
||||
private void createLegacyTable(String legacyTable) throws Throwable
|
||||
{
|
||||
execute(format("CREATE TABLE %s.%s (id int PRIMARY KEY, val text)", SchemaConstants.AUTH_KEYSPACE_NAME, legacyTable));
|
||||
}
|
||||
|
||||
private void createKeyspace() throws Throwable
|
||||
{
|
||||
execute(format("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", SchemaConstants.AUTH_KEYSPACE_NAME));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue