From 976096abd2ba786f747774ee5160c4cba6fefce2 Mon Sep 17 00:00:00 2001 From: Aleksandr Sorokoumov Date: Fri, 10 Jul 2020 16:57:40 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20writing=20of=20snapshot=20manifest=20when?= =?UTF-8?q?=20the=20table=20has=20table-backed=20secondary=20indexes=20pat?= =?UTF-8?q?ch=20by=20Aleksandr=20Sorokoumov;=20reviewed=20by=20Andr=C3=A9s?= =?UTF-8?q?=20de=20la=20Pe=C3=B1a=20for=20CASSANDRA-10968?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.txt | 1 + .../cassandra/db/ColumnFamilyStore.java | 5 ++- .../cassandra/db/ColumnFamilyStoreTest.java | 34 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d0d09930cc18..0a6268ccc966 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.1.21 + * Fix writing of snapshot manifest when the table has table-backed secondary indexes (CASSANDRA-10968) * Fix parse error in cqlsh COPY FROM and formatting for map of blobs (CASSANDRA-15679) * Paged Range Slice queries with DISTINCT can drop rows from results (CASSANDRA-14956) * Update release checksum algorithms to SHA-256, SHA-512 (CASSANDRA-14970) diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 2989b9d6ea27..df9b046d074e 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -2335,9 +2335,9 @@ public void snapshotWithoutFlush(String snapshotName) */ public void snapshotWithoutFlush(String snapshotName, Predicate predicate, boolean ephemeral) { + final JSONArray filesJSONArr = new JSONArray(); for (ColumnFamilyStore cfs : concatWithIndexes()) { - final JSONArray filesJSONArr = new JSONArray(); try (RefViewFragment currentView = cfs.selectAndReference(CANONICAL_SSTABLES)) { for (SSTableReader ssTable : currentView.sstables) @@ -2352,10 +2352,9 @@ public void snapshotWithoutFlush(String snapshotName, Predicate p if (logger.isDebugEnabled()) logger.debug("Snapshot for {} keyspace data file {} created in {}", keyspace, ssTable.getFilename(), snapshotDirectory); } - - writeSnapshotManifest(filesJSONArr, snapshotName); } } + writeSnapshotManifest(filesJSONArr, snapshotName); if (ephemeral) createEphemeralSnapshotMarkerFile(snapshotName); } diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java index 35814f05e7f6..1fc202954d3f 100644 --- a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java +++ b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java @@ -19,6 +19,7 @@ package org.apache.cassandra.db; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; @@ -57,6 +58,9 @@ import org.apache.cassandra.thrift.SliceRange; import org.apache.cassandra.thrift.ThriftValidation; import org.apache.cassandra.utils.*; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; import static org.apache.cassandra.Util.cellname; import static org.apache.cassandra.Util.column; @@ -2233,4 +2237,34 @@ public void testRebuildSecondaryIndex() throws IOException PerRowSecondaryIndexTest.TestIndex.reset(); } + + @Test + public void testSnapshotWithoutFlushWithSecondaryIndexes() throws Exception + { + String keyspaceName = "Keyspace1"; + String cfName = "Indexed1"; + Keyspace keyspace = Keyspace.open(keyspaceName); + ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName); + cfs.truncateBlocking(); + + List rms = new LinkedList<>(); + Mutation rm; + + rm = new Mutation(keyspaceName, ByteBufferUtil.bytes("k1")); + rm.add(cfName, cellname("birthdate"), ByteBufferUtil.bytes(1L), 0); + rm.add(cfName, cellname("nobirthdate"), ByteBufferUtil.bytes(1L), 0); + rms.add(rm); + Util.writeColumnFamily(rms); + + String snapshotName = "newSnapshot"; + cfs.snapshotWithoutFlush(snapshotName); + + File snapshotManifestFile = cfs.directories.getSnapshotManifestFile(snapshotName); + JSONParser parser = new JSONParser(); + JSONObject manifest = (JSONObject) parser.parse(new FileReader(snapshotManifestFile)); + JSONArray files = (JSONArray) manifest.get("files"); + + // Keyspace1-Indexed1 and the corresponding index CFS + assert files.size() == 2; + } }