This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 372a6cf Restore snapshotting of system ks on version change
372a6cf is described below
commit 372a6cfa7b0c5cf52b2db84edf210fa3d5c7f78e
Author: Sam Tunnicliffe <[email protected]>
AuthorDate: Thu Apr 19 11:51:35 2018 +0100
Restore snapshotting of system ks on version change
Patch by Sam Tunnicliffe; reviewed by Tommy Stendahl and Aleksey Yeschenko
for CASSANDRA-14412
---
CHANGES.txt | 1 +
src/java/org/apache/cassandra/db/SystemKeyspace.java | 17 +++++++----------
.../org/apache/cassandra/service/CassandraDaemon.java | 9 +++++++++
.../org/apache/cassandra/db/SystemKeyspaceTest.java | 13 +++++++++----
4 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 50152aa..b1a43e4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
4.0
+ * Restore snapshotting of system keyspaces on version change (CASSANDRA-14412)
* Fix AbstractBTreePartition locking in java 11 (CASSANDRA-14607)
* SimpleClient should pass connection properties as options (CASSANDRA-15056)
* Set repaired data tracking flag on range reads if enabled (CASSANDRA-15019)
diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java
b/src/java/org/apache/cassandra/db/SystemKeyspace.java
index ddf6475..d48f84f 100644
--- a/src/java/org/apache/cassandra/db/SystemKeyspace.java
+++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java
@@ -1389,30 +1389,27 @@ public final class SystemKeyspace
/**
* Compare the release version in the system.local table with the one
included in the distro.
- * If they don't match, snapshot all tables in the system keyspace. This
is intended to be
- * called at startup to create a backup of the system tables during an
upgrade
+ * If they don't match, snapshot all tables in the system and schema
keyspaces. This is intended
+ * to be called at startup to create a backup of the system tables during
an upgrade
*
* @throws IOException
*/
- public static boolean snapshotOnVersionChange() throws IOException
+ public static void snapshotOnVersionChange() throws IOException
{
String previous = getPreviousVersionString();
String next = FBUtilities.getReleaseVersionString();
- // if we're restarting after an upgrade, snapshot the system keyspace
+ // if we're restarting after an upgrade, snapshot the system and
schema keyspaces
if (!previous.equals(NULL_VERSION.toString()) &&
!previous.equals(next))
{
- logger.info("Detected version upgrade from {} to {}, snapshotting
system keyspace", previous, next);
+ logger.info("Detected version upgrade from {} to {}, snapshotting
system keyspaces", previous, next);
String snapshotName =
Keyspace.getTimestampedSnapshotName(format("upgrade-%s-%s",
previous,
next));
- Keyspace systemKs =
Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME);
- systemKs.snapshot(snapshotName, null);
- return true;
+ for (String keyspace : SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES)
+ Keyspace.open(keyspace).snapshot(snapshotName, null);
}
-
- return false;
}
/**
diff --git a/src/java/org/apache/cassandra/service/CassandraDaemon.java
b/src/java/org/apache/cassandra/service/CassandraDaemon.java
index af781d5..b8f06f6 100644
--- a/src/java/org/apache/cassandra/service/CassandraDaemon.java
+++ b/src/java/org/apache/cassandra/service/CassandraDaemon.java
@@ -204,6 +204,15 @@ public class CassandraDaemon
exitOrFail(e.returnCode, e.getMessage(), e.getCause());
}
+ try
+ {
+ SystemKeyspace.snapshotOnVersionChange();
+ }
+ catch (IOException e)
+ {
+ exitOrFail(3, e.getMessage(), e.getCause());
+ }
+
// We need to persist this as soon as possible after startup checks.
// This should be the first write to SystemKeyspace (CASSANDRA-11742)
SystemKeyspace.persistLocalMetadata();
diff --git a/test/unit/org/apache/cassandra/db/SystemKeyspaceTest.java
b/test/unit/org/apache/cassandra/db/SystemKeyspaceTest.java
index 3bc04c1..aca13b3 100644
--- a/test/unit/org/apache/cassandra/db/SystemKeyspaceTest.java
+++ b/test/unit/org/apache/cassandra/db/SystemKeyspaceTest.java
@@ -31,6 +31,7 @@ import org.apache.cassandra.cql3.QueryProcessor;
import org.apache.cassandra.cql3.UntypedResultSet;
import org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken;
import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.schema.SchemaKeyspace;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.CassandraVersion;
@@ -94,7 +95,7 @@ public class SystemKeyspaceTest
if (FBUtilities.isWindows)
assertEquals(expectedCount, getDeferredDeletionCount());
else
- assertTrue(getSystemSnapshotFiles().isEmpty());
+
assertTrue(getSystemSnapshotFiles(SchemaConstants.SYSTEM_KEYSPACE_NAME).isEmpty());
}
private int getDeferredDeletionCount()
@@ -131,7 +132,11 @@ public class SystemKeyspaceTest
// Compare versions again & verify that snapshots were created for all
tables in the system ks
SystemKeyspace.snapshotOnVersionChange();
- assertEquals(SystemKeyspace.metadata().tables.size(),
getSystemSnapshotFiles().size());
+
+ Set<String> snapshottedSystemTables =
getSystemSnapshotFiles(SchemaConstants.SYSTEM_KEYSPACE_NAME);
+ SystemKeyspace.metadata().tables.forEach(t ->
assertTrue(snapshottedSystemTables.contains(t.name)));
+ Set<String> snapshottedSchemaTables =
getSystemSnapshotFiles(SchemaConstants.SCHEMA_KEYSPACE_NAME);
+ SchemaKeyspace.metadata().tables.forEach(t ->
assertTrue(snapshottedSchemaTables.contains(t.name)));
// clear out the snapshots & set the previous recorded version equal
to the latest, we shouldn't
// see any new snapshots created this time.
@@ -156,10 +161,10 @@ public class SystemKeyspaceTest
return (String.format("%s.%s.%s", semver.major - 1, semver.minor,
semver.patch));
}
- private Set<String> getSystemSnapshotFiles()
+ private Set<String> getSystemSnapshotFiles(String keyspace)
{
Set<String> snapshottedTableNames = new HashSet<>();
- for (ColumnFamilyStore cfs :
Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStores())
+ for (ColumnFamilyStore cfs :
Keyspace.open(keyspace).getColumnFamilyStores())
{
if (!cfs.getSnapshotDetails().isEmpty())
snapshottedTableNames.add(cfs.getTableName());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]