diff --git a/CHANGES.txt b/CHANGES.txt index d0d09930cc..0a6268ccc9 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 2989b9d6ea..df9b046d07 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -2335,9 +2335,9 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean */ 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 class ColumnFamilyStore implements ColumnFamilyStoreMBean 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 35814f05e7..1fc202954d 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.SlicePredicate; 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 class ColumnFamilyStoreTest extends SchemaLoader 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; + } }