Search in sources :

Example 1 with CellName

use of org.apache.cassandra.db.composites.CellName in project titan by thinkaurelius.

the class CassandraEmbeddedStoreManager method retryDummyRead.

private void retryDummyRead(String ks, String cf) throws PermanentBackendException {
    final long limit = System.currentTimeMillis() + (60L * 1000L);
    while (System.currentTimeMillis() < limit) {
        try {
            SortedSet<CellName> names = new TreeSet<>(new Comparator<CellName>() {

                // This is a singleton set.  We need to define a comparator because SimpleDenseCellName is not
                // comparable, but it doesn't have to be a useful comparator
                @Override
                public int compare(CellName o1, CellName o2) {
                    return 0;
                }
            });
            names.add(CellNames.simpleDense(ByteBufferUtil.zeroByteBuffer(1)));
            NamesQueryFilter nqf = new NamesQueryFilter(names);
            SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(ks, ByteBufferUtil.zeroByteBuffer(1), cf, 1L, nqf);
            StorageProxy.read(ImmutableList.<ReadCommand>of(cmd), ConsistencyLevel.QUORUM);
            log.info("Read on CF {} in KS {} succeeded", cf, ks);
            return;
        } catch (Throwable t) {
            log.warn("Failed to read CF {} in KS {} following creation", cf, ks, t);
        }
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            throw new PermanentBackendException(e);
        }
    }
    throw new PermanentBackendException("Timed out while attempting to read CF " + cf + " in KS " + ks + " following creation");
}
Also used : SliceByNamesReadCommand(org.apache.cassandra.db.SliceByNamesReadCommand) CellName(org.apache.cassandra.db.composites.CellName) NamesQueryFilter(org.apache.cassandra.db.filter.NamesQueryFilter)

Example 2 with CellName

use of org.apache.cassandra.db.composites.CellName in project stargate-core by tuplejump.

the class ResultMapper method getPagedColumnSlices.

private ColumnSlice[] getPagedColumnSlices(DecoratedKey dk, Collection<IndexEntry> entries, int pageSize) {
    ArrayList<ColumnSlice> columnSlices = new ArrayList<>(Math.min(entries.size(), pageSize));
    for (IndexEntry entry : entries) {
        CellName cellName = entry.clusteringKey;
        if (!filter.columnFilter(dk.getKey()).maySelectPrefix(tableMapper.table.getComparator(), cellName.start())) {
            continue;
        }
        Composite start = tableMapper.start(cellName);
        Composite end = tableMapper.end(start);
        ColumnSlice columnSlice = new ColumnSlice(start, end);
        columnSlices.add(columnSlice);
        if (columnSlices.size() == pageSize) {
            break;
        }
    }
    return columnSlices.toArray(new ColumnSlice[columnSlices.size()]);
}
Also used : Composite(org.apache.cassandra.db.composites.Composite) ColumnSlice(org.apache.cassandra.db.filter.ColumnSlice) ArrayList(java.util.ArrayList) IndexEntry(com.tuplejump.stargate.lucene.IndexEntryCollector.IndexEntry) CellName(org.apache.cassandra.db.composites.CellName)

Example 3 with CellName

use of org.apache.cassandra.db.composites.CellName in project stargate-core by tuplejump.

the class RowFetcher method fetchSorted.

public List<Row> fetchSorted() throws IOException {
    List<Row> rows = new ArrayList<>();
    List<IndexEntryCollector.IndexEntry> docsSorted = resultMapper.docs();
    List<IndexEntryCollector.IndexEntry> sliceList;
    for (IndexEntryCollector.IndexEntry input : docsSorted) {
        CellName cellName = input.clusteringKey;
        DecoratedKey dk = input.decoratedKey;
        sliceList = new ArrayList<>();
        sliceList.add(input);
        Map<CellName, ColumnFamily> fullSlice = resultMapper.fetchRangeSlice(sliceList, dk);
        if (!resultMapper.filter.columnFilter(dk.getKey()).maySelectPrefix(table.getComparator(), cellName.start())) {
            continue;
        }
        ColumnFamily data = fullSlice.get(cellName);
        if (data == null || resultMapper.searchSupport.deleteIfNotLatest(dk, data.maxTimestamp(), input.pkName, data))
            continue;
        float score = input.score;
        ColumnFamily cleanColumnFamily = resultMapper.showScore ? scored(score, data) : data;
        rows.add(new Row(dk, cleanColumnFamily));
        columnsCount++;
        if (columnsCount > limit)
            break;
    }
    return rows;
}
Also used : ArrayList(java.util.ArrayList) CellName(org.apache.cassandra.db.composites.CellName) IndexEntryCollector(com.tuplejump.stargate.lucene.IndexEntryCollector)

Example 4 with CellName

use of org.apache.cassandra.db.composites.CellName in project stargate-core by tuplejump.

the class MatchPartition method getAllMatches.

private List<Tuple> getAllMatches(ResultMapper resultMapper, Map<String, Integer> positions) {
    List<Tuple> allMatches = new ArrayList<>();
    TreeMultimap<DecoratedKey, IndexEntryCollector.IndexEntry> docs = resultMapper.docsByRowKey();
    for (final DecoratedKey dk : docs.keySet()) {
        List<IndexEntryCollector.IndexEntry> entries = new ArrayList<>(docs.get(dk));
        final Map<CellName, ColumnFamily> fullSlice = resultMapper.fetchRangeSlice(entries, dk);
        List<Tuple> tuples = new ArrayList<>(fullSlice.size());
        for (IndexEntryCollector.IndexEntry entry : entries) {
            CellName cellName = entry.clusteringKey;
            ColumnFamily cf = fullSlice.get(cellName);
            if (cf != null) {
                Tuple tuple = aggregateFunction.createTuple(options);
                resultMapper.tableMapper.load(positions, tuple, new Row(dk, cf));
                tuples.add(tuple);
            }
        }
        int splice = Math.min(tuples.size(), maxMatches);
        allMatches.addAll(matchPartition(tuples.subList(0, splice)));
    }
    return allMatches;
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) CellName(org.apache.cassandra.db.composites.CellName) ColumnFamily(org.apache.cassandra.db.ColumnFamily) IndexEntryCollector(com.tuplejump.stargate.lucene.IndexEntryCollector) Row(org.apache.cassandra.db.Row)

Example 5 with CellName

use of org.apache.cassandra.db.composites.CellName in project stargate-core by tuplejump.

the class RowIndexSupport method addCell.

private void addCell(ByteBuffer rowKey, IndexEntryBuilder builder, Cell cell) {
    CellName cellName = cell.name();
    ColumnIdentifier cql3ColName = cellName.cql3ColumnName(tableMapper.cfMetaData);
    String actualColName = cql3ColName.toString();
    if (logger.isTraceEnabled())
        logger.trace("Got column name {} from CF", actualColName);
    CellName clusteringKey = tableMapper.extractClusteringKey(cell.name());
    ByteBuffer primaryKeyBuff = tableMapper.primaryKey(rowKey, clusteringKey);
    String primaryKey = tableMapper.primaryKeyType.getString(primaryKeyBuff);
    if (builder.isNew(primaryKey)) {
        builder.newPrimaryKey(primaryKey, primaryKeyBuff);
        // new pk found
        if (logger.isTraceEnabled()) {
            logger.trace("New PK found {}", primaryKey);
        }
        //fields for partition key columns need to be added.
        addPartitionKeyFields(rowKey, cell.timestamp(), builder);
        //fields for clustering key columns need to be added.
        addClusteringKeyFields(clusteringKey, cell.timestamp(), builder);
    }
    addCell(cell, cql3ColName, actualColName, builder);
}
Also used : ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) CellName(org.apache.cassandra.db.composites.CellName) ByteBuffer(java.nio.ByteBuffer)

Aggregations

CellName (org.apache.cassandra.db.composites.CellName)10 IndexEntryCollector (com.tuplejump.stargate.lucene.IndexEntryCollector)3 ArrayList (java.util.ArrayList)3 ByteBuffer (java.nio.ByteBuffer)2 ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)2 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)2 Composite (org.apache.cassandra.db.composites.Composite)2 ColumnSlice (org.apache.cassandra.db.filter.ColumnSlice)2 IndexEntry (com.tuplejump.stargate.lucene.IndexEntryCollector.IndexEntry)1 ColumnFamily (org.apache.cassandra.db.ColumnFamily)1 DecoratedKey (org.apache.cassandra.db.DecoratedKey)1 Row (org.apache.cassandra.db.Row)1 SliceByNamesReadCommand (org.apache.cassandra.db.SliceByNamesReadCommand)1 CellNameType (org.apache.cassandra.db.composites.CellNameType)1 NamesQueryFilter (org.apache.cassandra.db.filter.NamesQueryFilter)1 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)1 SliceQueryFilter (org.apache.cassandra.db.filter.SliceQueryFilter)1 Field (org.apache.lucene.document.Field)1 FieldType (org.apache.lucene.document.FieldType)1