Search in sources :

Example 36 with Descriptor

use of org.apache.cassandra.io.sstable.Descriptor in project eiger by wlloyd.

the class ColumnFamilyStore method loadNewSSTables.

/**
     * #{@inheritDoc}
     */
public synchronized void loadNewSSTables() {
    logger.info("Loading new SSTables for " + table.name + "/" + columnFamily + "...");
    // current view over ColumnFamilyStore
    DataTracker.View view = data.getView();
    // descriptors of currently registered SSTables
    Set<Descriptor> currentDescriptors = new HashSet<Descriptor>();
    // going to hold new SSTable view of the CFS containing old and new SSTables
    Set<SSTableReader> sstables = new HashSet<SSTableReader>();
    // get the max generation number, to prevent generation conflicts
    int generation = 0;
    for (SSTableReader reader : view.sstables) {
        // first of all, add old SSTables
        sstables.add(reader);
        currentDescriptors.add(reader.descriptor);
        if (reader.descriptor.generation > generation)
            generation = reader.descriptor.generation;
    }
    SSTableReader reader;
    // set to true if we have at least one new SSTable to load
    boolean atLeastOneNew = false;
    Directories.SSTableLister lister = directories.sstableLister().skipCompacted(true).skipTemporary(true);
    for (Map.Entry<Descriptor, Set<Component>> rawSSTable : lister.list().entrySet()) {
        Descriptor descriptor = rawSSTable.getKey();
        if (currentDescriptors.contains(descriptor))
            // old (initialized) SSTable found, skipping
            continue;
        if (!descriptor.isCompatible())
            throw new RuntimeException(String.format("Can't open incompatible SSTable! Current version %s, found file: %s", Descriptor.CURRENT_VERSION, descriptor));
        logger.info("Initializing new SSTable {}", rawSSTable);
        try {
            Set<DecoratedKey> savedKeys = CacheService.instance.keyCache.readSaved(descriptor.ksname, descriptor.cfname);
            reader = SSTableReader.open(rawSSTable.getKey(), rawSSTable.getValue(), savedKeys, data, metadata, partitioner);
        } catch (IOException e) {
            SSTableReader.logOpenException(rawSSTable.getKey(), e);
            continue;
        }
        sstables.add(reader);
        if (descriptor.generation > generation)
            generation = descriptor.generation;
        if (// set flag only once
        !atLeastOneNew)
            atLeastOneNew = true;
    }
    if (!atLeastOneNew) {
        logger.info("No new SSTables where found for " + table.name + "/" + columnFamily);
        return;
    }
    logger.info("Loading new SSTables and building secondary indexes for " + table.name + "/" + columnFamily + ": " + sstables);
    SSTableReader.acquireReferences(sstables);
    data.addSSTables(sstables);
    try {
        indexManager.maybeBuildSecondaryIndexes(sstables, indexManager.getIndexedColumns());
    } catch (IOException e) {
        throw new IOError(e);
    } finally {
        SSTableReader.releaseReferences(sstables);
    }
    logger.info("Setting up new generation: " + generation);
    fileIndexGenerator.set(generation);
    logger.info("Done loading load new SSTables for " + table.name + "/" + columnFamily);
}
Also used : Descriptor(org.apache.cassandra.io.sstable.Descriptor) NonBlockingHashMap(org.cliffc.high_scale_lib.NonBlockingHashMap)

Example 37 with Descriptor

use of org.apache.cassandra.io.sstable.Descriptor in project eiger by wlloyd.

the class BootstrapTest method testGetNewNames.

@Test
public void testGetNewNames() throws IOException {
    Descriptor desc = Descriptor.fromFilename(new File("Keyspace1", "Keyspace1-Standard1-f-500-Data.db").toString());
    // deliberately test old version
    assert !desc.isLatestVersion;
    PendingFile inContext = new PendingFile(null, desc, "Data.db", Arrays.asList(new Pair<Long, Long>(0L, 1L)), OperationType.BOOTSTRAP);
    PendingFile outContext = StreamIn.getContextMapping(inContext);
    // filename and generation are expected to have changed
    assert !inContext.getFilename().equals(outContext.getFilename());
    // nothing else should
    assertEquals(inContext.component, outContext.component);
    assertEquals(desc.ksname, outContext.desc.ksname);
    assertEquals(desc.cfname, outContext.desc.cfname);
    assertEquals(desc.version, outContext.desc.version);
}
Also used : Descriptor(org.apache.cassandra.io.sstable.Descriptor) File(java.io.File) Pair(org.apache.cassandra.utils.Pair) Test(org.junit.Test)

Example 38 with Descriptor

use of org.apache.cassandra.io.sstable.Descriptor in project eiger by wlloyd.

the class SerializationsTest method makePendingFile.

private static PendingFile makePendingFile(boolean sst, int numSecs, OperationType op) {
    Descriptor desc = new Descriptor("z", new File("path/doesn't/matter"), "Keyspace1", "Standard1", 23, false);
    List<Pair<Long, Long>> sections = new ArrayList<Pair<Long, Long>>();
    for (int i = 0; i < numSecs; i++) sections.add(new Pair<Long, Long>(new Long(i), new Long(i * i)));
    return new PendingFile(sst ? makeSSTable() : null, desc, SSTable.COMPONENT_DATA, sections, op);
}
Also used : Descriptor(org.apache.cassandra.io.sstable.Descriptor) File(java.io.File) Pair(org.apache.cassandra.utils.Pair)

Aggregations

Descriptor (org.apache.cassandra.io.sstable.Descriptor)38 File (java.io.File)24 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)15 Test (org.junit.Test)12 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)9 Component (org.apache.cassandra.io.sstable.Component)8 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)8 TableMetadata (org.apache.cassandra.schema.TableMetadata)6 Pair (org.apache.cassandra.utils.Pair)6 IOException (java.io.IOException)5 Map (java.util.Map)4 Directories (org.apache.cassandra.db.Directories)4 Keyspace (org.apache.cassandra.db.Keyspace)4 PrintStream (java.io.PrintStream)3 ByteBuffer (java.nio.ByteBuffer)3 Set (java.util.Set)3 DecoratedKey (org.apache.cassandra.db.DecoratedKey)3 SerializationHeader (org.apache.cassandra.db.SerializationHeader)3 NonBlockingHashMap (org.cliffc.high_scale_lib.NonBlockingHashMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2