mirror of https://github.com/apache/cassandra
implement a legacy sstable test. Patch by Stu Hood, reviewed by Gary Dusbabek. CASSANDRA-767
git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@934149 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
04e8d18129
commit
12eb0571e2
|
|
@ -39,6 +39,7 @@
|
|||
<property name="test.resources" value="${test.dir}/resources"/>
|
||||
<property name="test.classes" value="${build.dir}/test/classes"/>
|
||||
<property name="test.conf" value="${test.dir}/conf"/>
|
||||
<property name="test.data" value="${test.dir}/data"/>
|
||||
<property name="test.name" value="*Test"/>
|
||||
<property name="test.unit.src" value="${test.dir}/unit"/>
|
||||
<property name="dist.dir" value="${build.dir}/dist"/>
|
||||
|
|
@ -369,6 +370,7 @@
|
|||
<formatter type="brief" usefile="false"/>
|
||||
<jvmarg value="-Dstorage-config=${test.conf}"/>
|
||||
<jvmarg value="-Dlog4j.configuration=log4j-junit.properties" />
|
||||
<jvmarg value="-Dlegacy-sstable-root=${test.data}/legacy-sstables"/>
|
||||
<jvmarg value="-ea"/>
|
||||
<classpath>
|
||||
<path refid="cassandra.classpath" />
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cassandra.io.sstable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.io.util.BufferedRandomAccessFile;
|
||||
import org.apache.cassandra.db.DecoratedKey;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
|
||||
/**
|
||||
* Tests backwards compatibility for SSTables. Requires that older SSTables match up with the existing config file,
|
||||
* and currently only tests specific cases for specific upgrades.
|
||||
*/
|
||||
public class LegacySSTableTest extends CleanupHelper
|
||||
{
|
||||
public static final String LEGACY_SSTABLE_PROP = "legacy-sstable-root";
|
||||
public static final String KSNAME = "Keyspace1";
|
||||
public static final String CFNAME = "Standard1";
|
||||
|
||||
public static SortedMap<String, byte[]> TEST_DATA;
|
||||
public static File LEGACY_SSTABLE_ROOT;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass()
|
||||
{
|
||||
String scp = System.getProperty(LEGACY_SSTABLE_PROP);
|
||||
assert scp != null;
|
||||
LEGACY_SSTABLE_ROOT = new File(scp);
|
||||
assert LEGACY_SSTABLE_ROOT.isDirectory();
|
||||
|
||||
TEST_DATA = new TreeMap<String,byte[]>();
|
||||
for ( int i = 100; i < 1000; ++i )
|
||||
{
|
||||
TEST_DATA.put(Integer.toString(i), ("Avinash Lakshman is a good man: " + i).getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a descriptor for the legacy sstable at the given version.
|
||||
*/
|
||||
protected SSTable.Descriptor getDescriptor(String ver) throws IOException
|
||||
{
|
||||
File directory = new File(LEGACY_SSTABLE_ROOT + File.separator + ver + File.separator + KSNAME);
|
||||
return new SSTable.Descriptor(ver, directory, KSNAME, CFNAME, 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a test SSTable for use in this classes' tests. Uncomment and run against an older build
|
||||
* and the output will be copied to a version subdirectory in 'LEGACY_SSTABLE_ROOT'
|
||||
*
|
||||
@Test
|
||||
public void buildTestSSTable() throws IOException
|
||||
{
|
||||
// write the output in a version specific directory
|
||||
SSTable.Descriptor dest = getDescriptor(SSTable.Descriptor.CURRENT_VERSION);
|
||||
assert dest.directory.mkdirs() : "Could not create " + dest.directory + ". Might it already exist?";
|
||||
|
||||
SSTableReader ssTable = SSTableUtils.writeRawSSTable(new File(dest.filenameFor(SSTable.COMPONENT_DATA)),
|
||||
KSNAME,
|
||||
CFNAME,
|
||||
TEST_DATA);
|
||||
assert ssTable.desc.generation == 0 :
|
||||
"In order to create a generation 0 sstable, please run this test alone.";
|
||||
System.out.println(">>> Wrote " + dest);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Between version b and c, on disk bloom filters became incompatible, and needed to be regenerated.
|
||||
*/
|
||||
@Test
|
||||
public void testVerB() throws IOException
|
||||
{
|
||||
SSTableReader reader = SSTableReader.open(getDescriptor("b"));
|
||||
|
||||
List<String> keys = new ArrayList<String>(TEST_DATA.keySet());
|
||||
Collections.shuffle(keys);
|
||||
BufferedRandomAccessFile file = new BufferedRandomAccessFile(reader.getFilename(), "r");
|
||||
for (String key : keys)
|
||||
{
|
||||
// confirm that the bloom filter does not reject any keys
|
||||
file.seek(reader.getPosition(reader.partitioner.decorateKey(key)).position);
|
||||
assert key.equals(file.readUTF());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -38,13 +38,8 @@ import org.apache.cassandra.io.util.DataOutputBuffer;
|
|||
public class SSTableUtils
|
||||
{
|
||||
// first configured table and cf
|
||||
public static String TABLENAME;
|
||||
public static String CFNAME;
|
||||
static
|
||||
{
|
||||
TABLENAME = DatabaseDescriptor.getTables().iterator().next();
|
||||
CFNAME = Table.open(TABLENAME).getColumnFamilies().iterator().next();
|
||||
}
|
||||
public static String TABLENAME = "Keyspace1";
|
||||
public static String CFNAME = "Standard1";
|
||||
|
||||
public static ColumnFamily createCF(long mfda, int ldt, IColumn... cols)
|
||||
{
|
||||
|
|
@ -97,13 +92,26 @@ public class SSTableUtils
|
|||
|
||||
public static SSTableReader writeRawSSTable(String tablename, String cfname, SortedMap<String, byte[]> entries) throws IOException
|
||||
{
|
||||
File f = tempSSTableFile(tablename, cfname);
|
||||
SSTableWriter writer = new SSTableWriter(f.getAbsolutePath(), entries.size(), StorageService.getPartitioner());
|
||||
return writeRawSSTable(null, tablename, cfname, entries);
|
||||
}
|
||||
|
||||
public static SSTableReader writeRawSSTable(File datafile, String tablename, String cfname, SortedMap<String, byte[]> entries) throws IOException
|
||||
{
|
||||
boolean temporary = false;
|
||||
if (datafile == null)
|
||||
{
|
||||
datafile = tempSSTableFile(tablename, cfname);
|
||||
temporary = true;
|
||||
}
|
||||
SSTableWriter writer = new SSTableWriter(datafile.getAbsolutePath(), entries.size(), StorageService.getPartitioner());
|
||||
for (Map.Entry<String, byte[]> entry : entries.entrySet())
|
||||
writer.append(writer.partitioner.decorateKey(entry.getKey()),
|
||||
entry.getValue());
|
||||
new File(writer.indexFilename()).deleteOnExit();
|
||||
new File(writer.filterFilename()).deleteOnExit();
|
||||
if (temporary)
|
||||
{
|
||||
new File(writer.indexFilename()).deleteOnExit();
|
||||
new File(writer.filterFilename()).deleteOnExit();
|
||||
}
|
||||
return writer.closeAndOpenReader();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue