Search in sources :

Example 11 with SSTableReader

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

the class ColumnFamilyStoreTest method testGetColumnWithWrongBF.

@Test
public void testGetColumnWithWrongBF() throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore cfs = table.getColumnFamilyStore("Standard1");
    cfs.truncate().get();
    List<IMutation> rms = new LinkedList<IMutation>();
    RowMutation rm;
    rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1"));
    rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0);
    rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column2")), ByteBufferUtil.bytes("asdf"), 0);
    rms.add(rm);
    Util.writeColumnFamily(rms);
    List<SSTableReader> ssTables = table.getAllSSTables();
    assertEquals(1, ssTables.size());
    ssTables.get(0).forceFilterFailures();
    ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("key2"), new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1"))));
    assertNull(cf);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) SSTable(org.apache.cassandra.io.sstable.SSTable) Test(org.junit.Test)

Example 12 with SSTableReader

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

the class StreamInSession method closeIfFinished.

public void closeIfFinished() throws IOException {
    if (files.isEmpty()) {
        HashMap<ColumnFamilyStore, List<SSTableReader>> cfstores = new HashMap<ColumnFamilyStore, List<SSTableReader>>();
        try {
            for (SSTableReader sstable : readers) {
                assert sstable.getTableName().equals(table);
                // so it can't get compacted out of existence in between
                if (!sstable.acquireReference())
                    throw new AssertionError("We shouldn't fail acquiring a reference on a sstable that has just been transfered");
                ColumnFamilyStore cfs = Table.open(sstable.getTableName()).getColumnFamilyStore(sstable.getColumnFamilyName());
                cfs.addSSTable(sstable);
                if (!cfstores.containsKey(cfs))
                    cfstores.put(cfs, new ArrayList<SSTableReader>());
                cfstores.get(cfs).add(sstable);
            }
            // build secondary indexes
            for (Map.Entry<ColumnFamilyStore, List<SSTableReader>> entry : cfstores.entrySet()) {
                if (entry.getKey() != null)
                    entry.getKey().indexManager.maybeBuildSecondaryIndexes(entry.getValue(), entry.getKey().indexManager.getIndexedColumns());
            }
        } finally {
            for (List<SSTableReader> referenced : cfstores.values()) SSTableReader.releaseReferences(referenced);
        }
        // send reply to source that we're done
        StreamReply reply = new StreamReply("", getSessionId(), StreamReply.Status.SESSION_FINISHED);
        logger.info("Finished streaming session {} from {}", getSessionId(), getHost());
        try {
            if (socket != null)
                OutboundTcpConnection.write(reply.getMessage(Gossiper.instance.getVersion(getHost())), context.right.toString(), new DataOutputStream(socket.getOutputStream()));
            else
                logger.debug("No socket to reply to {} with!", getHost());
        } finally {
            if (socket != null)
                socket.close();
        }
        if (callback != null)
            callback.run();
        sessions.remove(context);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) NonBlockingHashMap(org.cliffc.high_scale_lib.NonBlockingHashMap) DataOutputStream(java.io.DataOutputStream) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) NonBlockingHashMap(org.cliffc.high_scale_lib.NonBlockingHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 13 with SSTableReader

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

the class StreamOut method transferRanges.

/**
 * Stream the given ranges to the target endpoint from each of the given CFs.
 */
public static void transferRanges(StreamOutSession session, Iterable<ColumnFamilyStore> cfses, Collection<Range<Token>> ranges, OperationType type) {
    assert ranges.size() > 0;
    logger.info("Beginning transfer to {}", session.getHost());
    logger.debug("Ranges are {}", StringUtils.join(ranges, ","));
    try {
        flushSSTables(cfses);
        Iterable<SSTableReader> sstables = Collections.emptyList();
        for (ColumnFamilyStore cfStore : cfses) sstables = Iterables.concat(sstables, cfStore.markCurrentSSTablesReferenced());
        transferSSTables(session, sstables, ranges, type);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) IOError(java.io.IOError) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) IOException(java.io.IOException)

Example 14 with SSTableReader

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

the class StreamingRepairTask method initiateStreaming.

private void initiateStreaming() {
    ColumnFamilyStore cfstore = Table.open(tableName).getColumnFamilyStore(cfName);
    try {
        logger.info(String.format("[streaming task #%s] Performing streaming repair of %d ranges with %s", id, ranges.size(), dst));
        // We acquire references for transferSSTables
        Collection<SSTableReader> sstables = cfstore.markCurrentSSTablesReferenced();
        // send ranges to the remote node
        StreamOutSession outsession = StreamOutSession.create(tableName, dst, callback);
        StreamOut.transferSSTables(outsession, sstables, ranges, OperationType.AES);
        // request ranges from the remote node
        StreamIn.requestRanges(dst, tableName, Collections.singleton(cfstore), ranges, callback, OperationType.AES);
    } catch (Exception e) {
        throw new RuntimeException("Streaming repair failed", e);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Example 15 with SSTableReader

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

the class LeveledManifest method serialize.

public synchronized void serialize() {
    File manifestFile = cfs.directories.getOrCreateLeveledManifest();
    File oldFile = new File(manifestFile.getPath().replace(EXTENSION, "-old.json"));
    File tmpFile = new File(manifestFile.getPath().replace(EXTENSION, "-tmp.json"));
    JsonFactory f = new JsonFactory();
    try {
        JsonGenerator g = f.createJsonGenerator(tmpFile, JsonEncoding.UTF8);
        g.useDefaultPrettyPrinter();
        g.writeStartObject();
        g.writeArrayFieldStart("generations");
        for (int level = 0; level < generations.length; level++) {
            g.writeStartObject();
            g.writeNumberField("generation", level);
            g.writeArrayFieldStart("members");
            for (SSTableReader ssTableReader : generations[level]) g.writeNumber(ssTableReader.descriptor.generation);
            // members
            g.writeEndArray();
            // generation
            g.writeEndObject();
        }
        // for field generations
        g.writeEndArray();
        // write global object
        g.writeEndObject();
        g.close();
        if (oldFile.exists() && manifestFile.exists())
            FileUtils.deleteWithConfirm(oldFile);
        if (manifestFile.exists())
            FileUtils.renameWithConfirm(manifestFile, oldFile);
        assert tmpFile.exists();
        FileUtils.renameWithConfirm(tmpFile, manifestFile);
        logger.debug("Saved manifest {}", manifestFile);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) IOError(java.io.IOError) JsonFactory(org.codehaus.jackson.JsonFactory) JsonGenerator(org.codehaus.jackson.JsonGenerator) IOException(java.io.IOException) File(java.io.File)

Aggregations

SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)45 Test (org.junit.Test)16 File (java.io.File)14 ColumnFamily (org.apache.cassandra.db.ColumnFamily)10 QueryPath (org.apache.cassandra.db.filter.QueryPath)10 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)9 IOException (java.io.IOException)8 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)7 SSTableWriter (org.apache.cassandra.io.sstable.SSTableWriter)7 IColumnIterator (org.apache.cassandra.db.columniterator.IColumnIterator)6 PrintStream (java.io.PrintStream)5 FileReader (java.io.FileReader)4 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)4 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)4 IColumn (org.apache.cassandra.db.IColumn)4 Token (org.apache.cassandra.dht.Token)4 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 ByteBuffer (java.nio.ByteBuffer)3 CounterColumn (org.apache.cassandra.db.CounterColumn)3