Permalink
Browse files

Fix sstable file scan when one ColumnFamily starts with the name of a…

…nother

patch by Pavel Yaskevich; reviewed by Jonathan Ellis for CASSANDRA-3040

git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1159780 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 055a98e commit db2d62c22ab514efcb3c137f3b09f2270df84aa6 @xedin xedin committed Aug 19, 2011
@@ -478,13 +478,15 @@ public void scheduleCacheSaving(int rowCacheSavePeriodInSeconds, int keyCacheSav
private static List<Pair<Descriptor, Component>> files(File path, final String columnFamilyName)
{
final List<Pair<Descriptor, Component>> sstables = new ArrayList<Pair<Descriptor, Component>>();
+ final String sstableFilePrefix = columnFamilyName + Component.separator;
+
// NB: we never "accept" a file in the FilenameFilter sense: they are added to the sstable map
path.listFiles(new FileFilter()
{
public boolean accept(File file)
{
// we are only interested in the SSTable files that belong to the specific ColumnFamily
- if (file.isDirectory() || !file.getName().startsWith(columnFamilyName))
+ if (file.isDirectory() || !file.getName().startsWith(sstableFilePrefix))
return false;
Pair<Descriptor, Component> pair = SSTable.tryComponentFromFilename(file.getParentFile(), file.getName());
@@ -35,6 +35,8 @@
*/
public class Component
{
+ public static final char separator = '-';
+
final static EnumSet<Type> TYPES = EnumSet.allOf(Type.class);
enum Type
{
@@ -108,7 +110,7 @@ public String name()
case STATS:
return type.repr;
case BITMAP_INDEX:
- return String.format("%d-%s", id, type.repr);
+ return String.format("%d%c%s", id, separator, type.repr);
}
throw new IllegalStateException();
}
@@ -126,7 +128,7 @@ public String name()
// parse the component suffix
String repr = path.right;
int id = -1;
- int separatorPos = repr.indexOf('-');
+ int separatorPos = repr.indexOf(separator);
if (separatorPos != -1)
{
id = Integer.parseInt(repr.substring(0, separatorPos));
@@ -29,6 +29,8 @@
import org.apache.cassandra.db.Table;
import org.apache.cassandra.utils.Pair;
+import static org.apache.cassandra.io.sstable.Component.separator;
+
/**
* A SSTable is described by the keyspace and column family it contains data
* for, a generation (where higher generations contain more recent data) and
@@ -119,11 +121,11 @@ private String baseFilename()
{
StringBuilder buff = new StringBuilder();
buff.append(directory).append(File.separatorChar);
- buff.append(cfname).append("-");
+ buff.append(cfname).append(separator);
if (temporary)
- buff.append(SSTable.TEMPFILE_MARKER).append("-");
+ buff.append(SSTable.TEMPFILE_MARKER).append(separator);
if (!LEGACY_VERSION.equals(version))
- buff.append(version).append("-");
+ buff.append(version).append(separator);
buff.append(generation);
return buff.toString();
}
@@ -134,7 +136,7 @@ private String baseFilename()
*/
public String filenameFor(String suffix)
{
- return baseFilename() + "-" + suffix;
+ return baseFilename() + separator + suffix;
}
/**
@@ -163,7 +165,7 @@ public static Descriptor fromFilename(String filename)
String ksname = extractKeyspaceName(directory);
// tokenize the filename
- StringTokenizer st = new StringTokenizer(name, "-");
+ StringTokenizer st = new StringTokenizer(name, String.valueOf(separator));
String nexttok;
// all filenames must start with a column family
@@ -158,12 +158,13 @@ public String getTableName()
static Set<Component> componentsFor(final Descriptor desc, final Descriptor.TempState matchState)
{
final Set<Component> components = new HashSet<Component>();
+ final String sstableFilePrefix = desc.cfname + Component.separator;
desc.directory.listFiles(new FileFilter()
{
public boolean accept(File file)
{
- if (file.isDirectory() || !file.getName().startsWith(desc.cfname))
+ if (file.isDirectory() || !file.getName().startsWith(sstableFilePrefix))
return false;
Pair<Descriptor, Component> component = tryComponentFromFilename(file.getParentFile(), file.getName());

0 comments on commit db2d62c

Please sign in to comment.