Create test for restoring a snapshot with dropped columns (CASSANDRA-13276)




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

Branch: refs/heads/master
Commit: e6b47064237ce4d9dc10313995fba34cb9cdefb7
Parents: 0692e2b
Author: Andrés de la Peña <[email protected]>
Authored: Tue Apr 25 20:38:53 2017 +0100
Committer: GitHub <[email protected]>
Committed: Tue Apr 25 20:38:53 2017 +0100

----------------------------------------------------------------------
 snapshot_test.py | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra-dtest/blob/e6b47064/snapshot_test.py
----------------------------------------------------------------------
diff --git a/snapshot_test.py b/snapshot_test.py
index ba184ee..7169a7c 100644
--- a/snapshot_test.py
+++ b/snapshot_test.py
@@ -9,6 +9,7 @@ from cassandra.concurrent import execute_concurrent_with_args
 
 from dtest import (Tester, cleanup_cluster, create_ccm_cluster, create_ks,
                    debug, get_test_path)
+from tools.assertions import assert_one
 from tools.files import replace_in_file, safe_mkdtemp
 from tools.hacks import advance_to_next_cl_segment
 from tools.misc import ImmutableMapping
@@ -70,6 +71,13 @@ class SnapshotTester(Tester):
                     raise Exception("sstableloader command '%s' failed; exit 
status: %d'; stdout: %s; stderr: %s" %
                                     (" ".join(args), exit_status, stdout, 
stderr))
 
+    def restore_snapshot_schema(self, snapshot_dir, node, ks, cf):
+        debug("Restoring snapshot schema....")
+        for x in xrange(0, self.cluster.data_dir_count):
+            schema_path = os.path.join(snapshot_dir, str(x), ks, cf, 
'schema.cql')
+            if os.path.exists(schema_path):
+                node.run_cqlsh(cmds="SOURCE '%s'" % schema_path)
+
 
 class TestSnapshot(SnapshotTester):
 
@@ -106,6 +114,41 @@ class TestSnapshot(SnapshotTester):
 
         self.assertEqual(rows[0][0], 100)
 
+    def test_snapshot_and_restore_dropping_a_column(self):
+        """
+        @jira_ticket CASSANDRA-13276
+
+        Can't load snapshots of tables with dropped columns.
+        """
+        cluster = self.cluster
+        cluster.populate(1).start()
+        node1, = cluster.nodelist()
+        session = self.patient_cql_connection(node1)
+
+        # Create schema and insert some data
+        create_ks(session, 'ks', 1)
+        session.execute("CREATE TABLE ks.cf (k int PRIMARY KEY, a text, b 
text)")
+        session.execute("INSERT INTO ks.cf (k, a, b) VALUES (1, 'a', 'b')")
+        assert_one(session, "SELECT * FROM ks.cf", [1, "a", "b"])
+
+        # Drop a column
+        session.execute("ALTER TABLE ks.cf DROP b")
+        assert_one(session, "SELECT * FROM ks.cf", [1, "a"])
+
+        # Take a snapshot and drop the table
+        snapshot_dir = self.make_snapshot(node1, 'ks', 'cf', 'basic')
+        session.execute("DROP TABLE ks.cf")
+
+        # Restore schema and data from snapshot
+        self.restore_snapshot_schema(snapshot_dir, node1, 'ks', 'cf')
+        self.restore_snapshot(snapshot_dir, node1, 'ks', 'cf')
+        node1.nodetool('refresh ks cf')
+        assert_one(session, "SELECT * FROM ks.cf", [1, "a"])
+
+        # Clean up
+        debug("removing snapshot_dir: " + snapshot_dir)
+        shutil.rmtree(snapshot_dir)
+
 
 class TestArchiveCommitlog(SnapshotTester):
     cluster_options = ImmutableMapping({'commitlog_segment_size_in_mb': 1})


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to