Skip to content

Commit

Permalink
Fix writing of snapshot manifest when the table has table-backed seco…
Browse files Browse the repository at this point in the history
…ndary indexes

patch by Aleksandr Sorokoumov; reviewed by Andrés de la Peña for CASSANDRA-10968
  • Loading branch information
Gerrrr authored and adelapena committed Jul 10, 2020
1 parent f3568c0 commit 976096a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 2 additions & 3 deletions src/java/org/apache/cassandra/db/ColumnFamilyStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2335,9 +2335,9 @@ public void snapshotWithoutFlush(String snapshotName)
*/
public void snapshotWithoutFlush(String snapshotName, Predicate<SSTableReader> 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)
Expand All @@ -2352,10 +2352,9 @@ public void snapshotWithoutFlush(String snapshotName, Predicate<SSTableReader> 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);
}
Expand Down
34 changes: 34 additions & 0 deletions test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Mutation> 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;
}
}

0 comments on commit 976096a

Please sign in to comment.