use of org.apache.cassandra.io.sstable.format.Version in project cassandra by apache.
the class SSTableHeaderFixTest method buildFakeSSTable.
private File buildFakeSSTable(File dir, int generation, TableMetadata.Builder cols, Function<ColumnMetadata, ColumnMetadata> freezer) {
TableMetadata headerMetadata = cols.build();
TableMetadata.Builder schemaCols = TableMetadata.builder("ks", "cf");
for (ColumnMetadata cm : cols.columns()) schemaCols.addColumn(freezer.apply(cm));
tableMetadata = schemaCols.build();
try {
Descriptor desc = new Descriptor(version, dir, "ks", "cf", generation, SSTableFormat.Type.BIG);
// Just create the component files - we don't really need those.
for (Component component : requiredComponents) assertTrue(new File(desc.filenameFor(component)).createFileIfNotExists());
AbstractType<?> partitionKey = headerMetadata.partitionKeyType;
List<AbstractType<?>> clusteringKey = headerMetadata.clusteringColumns().stream().map(cd -> cd.type).collect(Collectors.toList());
Map<ByteBuffer, AbstractType<?>> staticColumns = headerMetadata.columns().stream().filter(cd -> cd.kind == ColumnMetadata.Kind.STATIC).collect(Collectors.toMap(cd -> cd.name.bytes, cd -> cd.type, (a, b) -> a));
Map<ByteBuffer, AbstractType<?>> regularColumns = headerMetadata.columns().stream().filter(cd -> cd.kind == ColumnMetadata.Kind.REGULAR).collect(Collectors.toMap(cd -> cd.name.bytes, cd -> cd.type, (a, b) -> a));
File statsFile = new File(desc.filenameFor(Component.STATS));
SerializationHeader.Component header = SerializationHeader.Component.buildComponentForTools(partitionKey, clusteringKey, staticColumns, regularColumns, EncodingStats.NO_STATS);
try (SequentialWriter out = new SequentialWriter(statsFile)) {
desc.getMetadataSerializer().serialize(Collections.singletonMap(MetadataType.HEADER, header), out, version);
out.finish();
}
return new File(desc.filenameFor(Component.DATA));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.cassandra.io.sstable.format.Version in project cassandra by apache.
the class MetadataSerializerTest method pendingRepairCompatibility.
@Test
public void pendingRepairCompatibility() {
Version mc = BigFormat.instance.getVersion("mc");
assertFalse(mc.hasPendingRepair());
Version md = BigFormat.instance.getVersion("md");
assertTrue(md.hasPendingRepair());
}
use of org.apache.cassandra.io.sstable.format.Version in project cassandra by apache.
the class Descriptor method fromFilenameWithComponent.
/**
* Parse a sstable filename, extracting both the {@code Descriptor} and {@code Component} part.
*
* @param file the {@code File} object for the filename to parse.
* @return a pair of the descriptor and component corresponding to the provided {@code file}.
*
* @throws IllegalArgumentException if the provided {@code file} does point to a valid sstable filename. This could
* mean either that the filename doesn't look like a sstable file, or that it is for an old and unsupported
* versions.
*/
public static Pair<Descriptor, Component> fromFilenameWithComponent(File file) {
// absolute path.
if (!file.isAbsolute())
file = file.toAbsolute();
String name = file.name();
List<String> tokens = filenameSplitter.splitToList(name);
int size = tokens.size();
if (size != 4) {
// but we're just trying to be helpful, not perfect.
if (size == 5 || size == 6)
throw new IllegalArgumentException(String.format("%s is of version %s which is now unsupported and cannot be read.", name, tokens.get(size - 3)));
throw new IllegalArgumentException(String.format("Invalid sstable file %s: the name doesn't look like a supported sstable file name", name));
}
String versionString = tokens.get(0);
if (!Version.validate(versionString))
throw invalidSSTable(name, "invalid version %s", versionString);
int generation;
try {
generation = Integer.parseInt(tokens.get(1));
} catch (NumberFormatException e) {
throw invalidSSTable(name, "the 'generation' part of the name doesn't parse as a number");
}
String formatString = tokens.get(2);
SSTableFormat.Type format;
try {
format = SSTableFormat.Type.validate(formatString);
} catch (IllegalArgumentException e) {
throw invalidSSTable(name, "unknown 'format' part (%s)", formatString);
}
Component component = Component.parse(tokens.get(3));
Version version = format.info.getVersion(versionString);
if (!version.isCompatible())
throw invalidSSTable(name, "incompatible sstable version (%s); you should have run upgradesstables before upgrading", versionString);
File directory = parentOf(name, file);
File tableDir = directory;
// Check if it's a 2ndary index directory (not that it doesn't exclude it to be also a backup or snapshot)
String indexName = "";
if (Directories.isSecondaryIndexFolder(tableDir)) {
indexName = tableDir.name();
tableDir = parentOf(name, tableDir);
}
// Then it can be a backup or a snapshot
if (tableDir.name().equals(Directories.BACKUPS_SUBDIR))
tableDir = tableDir.parent();
else if (parentOf(name, tableDir).name().equals(Directories.SNAPSHOT_SUBDIR))
tableDir = parentOf(name, parentOf(name, tableDir));
String table = tableDir.name().split("-")[0] + indexName;
String keyspace = parentOf(name, tableDir).name();
return Pair.create(new Descriptor(version, directory, keyspace, table, generation, format), component);
}
Aggregations