Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/java/org/apache/cassandra/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public class Config
public volatile Integer stream_throughput_outbound_megabits_per_sec = 200;
public volatile Integer inter_dc_stream_throughput_outbound_megabits_per_sec = 200;

public String[] data_file_directories;
public String[] data_file_directories = new String[0];

public String saved_caches_directory;

Expand Down
6 changes: 3 additions & 3 deletions src/java/org/apache/cassandra/db/ColumnFamilyStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2426,9 +2426,9 @@ public void snapshotWithoutFlush(String snapshotName)
public Set<SSTableReader> snapshotWithoutFlush(String snapshotName, Predicate<SSTableReader> predicate, boolean ephemeral)
{
Set<SSTableReader> snapshottedSSTables = new HashSet<>();
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 @@ -2444,10 +2444,10 @@ public Set<SSTableReader> snapshotWithoutFlush(String snapshotName, Predicate<SS
logger.trace("Snapshot for {} keyspace data file {} created in {}", keyspace, ssTable.getFilename(), snapshotDirectory);
snapshottedSSTables.add(ssTable);
}

writeSnapshotManifest(filesJSONArr, snapshotName);
}
}

writeSnapshotManifest(filesJSONArr, snapshotName);
if (ephemeral)
createEphemeralSnapshotMarkerFile(snapshotName);
return snapshottedSSTables;
Expand Down
15 changes: 10 additions & 5 deletions src/java/org/apache/cassandra/db/Directories.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public static File getSnapshotDirectory(Descriptor desc, String snapshotName)
*/
public static File getSnapshotDirectory(File location, String snapshotName)
{
if (location.getName().startsWith(SECONDARY_INDEX_NAME_SEPARATOR))
if (isSecondaryIndexFolder(location))
{
return getOrCreate(location.getParentFile(), SNAPSHOT_SUBDIR, snapshotName, location.getName());
}
Expand Down Expand Up @@ -456,7 +456,7 @@ public static File getBackupsDirectory(Descriptor desc)

public static File getBackupsDirectory(File location)
{
if (location.getName().startsWith(SECONDARY_INDEX_NAME_SEPARATOR))
if (isSecondaryIndexFolder(location))
{
return getOrCreate(location.getParentFile(), BACKUPS_SUBDIR, location.getName());
}
Expand Down Expand Up @@ -680,7 +680,7 @@ private List<File> listSnapshots()
final List<File> snapshots = new LinkedList<>();
for (final File dir : dataPaths)
{
File snapshotDir = dir.getName().startsWith(SECONDARY_INDEX_NAME_SEPARATOR) ?
File snapshotDir = isSecondaryIndexFolder(dir) ?
new File(dir.getParent(), SNAPSHOT_SUBDIR) :
new File(dir, SNAPSHOT_SUBDIR);
if (snapshotDir.exists() && snapshotDir.isDirectory())
Expand All @@ -705,7 +705,7 @@ public boolean snapshotExists(String snapshotName)
for (File dir : dataPaths)
{
File snapshotDir;
if (dir.getName().startsWith(SECONDARY_INDEX_NAME_SEPARATOR))
if (isSecondaryIndexFolder(dir))
{
snapshotDir = new File(dir.getParentFile(), join(SNAPSHOT_SUBDIR, snapshotName, dir.getName()));
}
Expand Down Expand Up @@ -764,7 +764,7 @@ public long trueSnapshotsSize()
long result = 0L;
for (File dir : dataPaths)
{
File snapshotDir = dir.getName().startsWith(SECONDARY_INDEX_NAME_SEPARATOR) ?
File snapshotDir = isSecondaryIndexFolder(dir) ?
new File(dir.getParent(), SNAPSHOT_SUBDIR) :
new File(dir, SNAPSHOT_SUBDIR);
result += getTrueAllocatedSizeIn(snapshotDir);
Expand Down Expand Up @@ -809,6 +809,11 @@ public static List<File> getKSChildDirectories(String ksName)
return result;
}

public static boolean isSecondaryIndexFolder(File dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice new method

{
return dir.getName().startsWith(SECONDARY_INDEX_NAME_SEPARATOR);
}

public List<File> getCFDirectories()
{
List<File> result = new ArrayList<>();
Expand Down
7 changes: 6 additions & 1 deletion src/java/org/apache/cassandra/io/sstable/Descriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ private void appendFileName(StringBuilder buff)
public String relativeFilenameFor(Component component)
{
final StringBuilder buff = new StringBuilder();
if (Directories.isSecondaryIndexFolder(directory))
{
buff.append(directory.getName()).append(File.separator);
}

appendFileName(buff);
buff.append(separator).append(component.name());
return buff.toString();
Expand Down Expand Up @@ -271,7 +276,7 @@ else if (Descriptor.Type.TEMPLINK.marker.equals(nexttok))
File cfDirectory = parentDirectory;
// check if this is secondary index
String indexName = "";
if (cfDirectory.getName().startsWith(Directories.SECONDARY_INDEX_NAME_SEPARATOR))
if (Directories.isSecondaryIndexFolder(cfDirectory))
{
indexName = cfDirectory.getName();
cfDirectory = cfDirectory.getParentFile();
Expand Down
39 changes: 39 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 @@ -95,6 +96,9 @@
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Pair;
import org.apache.cassandra.utils.WrappedRunnable;
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 @@ -2356,4 +2360,39 @@ public void testRebuildSecondaryIndex() throws IOException

PerRowSecondaryIndexTest.TestIndex.reset();
}

@Test
public void testSnapshotWithoutFlushWithSecondaryIndexes() throws Exception
{
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_INDEX1);
cfs.truncateBlocking();

List<Mutation> rms = new LinkedList<>();
Mutation rm;

rm = new Mutation(KEYSPACE1, ByteBufferUtil.bytes("k1"));
rm.add(CF_INDEX1, cellname("birthdate"), ByteBufferUtil.bytes(1L), 0);
rm.add(CF_INDEX1, 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
assert files.size() == 2;

// Snapshot of the secondary index is stored in the subfolder with the same file name
String baseTableFile = (String) files.get(0);
String indexTableFile = (String) files.get(1);
assert !baseTableFile.equals(indexTableFile);
assert Directories.isSecondaryIndexFolder(new File(indexTableFile).getParentFile());
assert indexTableFile.endsWith(baseTableFile);
}
}