Search in sources :

Example 36 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey 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 37 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project coprhd-controller by CoprHD.

the class DbManager method hasPendingHintedHandoff.

/**
 * Check if there is pending hinted handoff logs for given node
 *
 * @param endpoint
 * @return true - pending hinted handoff logs exists. Otherwise, false
 */
private boolean hasPendingHintedHandoff(InetAddress endpoint) {
    List<String> endpointsWithPendingHints = HintedHandOffManager.instance.listEndpointsPendingHints();
    if (endpointsWithPendingHints.isEmpty()) {
        log.info("Skip data sync status check. No pending hinted handoff logs");
        return false;
    }
    log.info("Pending hinted hand off logs found at {}", endpointsWithPendingHints);
    UUID hostId = Gossiper.instance.getHostId(endpoint);
    final ByteBuffer hostIdBytes = ByteBuffer.wrap(UUIDGen.decompose(hostId));
    DecoratedKey epkey = StorageService.getPartitioner().decorateKey(hostIdBytes);
    Token.TokenFactory tokenFactory = StorageService.getPartitioner().getTokenFactory();
    String token = tokenFactory.toString(epkey.getToken());
    for (String unsyncedEndpoint : endpointsWithPendingHints) {
        if (token.equals(unsyncedEndpoint)) {
            log.info("Unsynced data found for : {}", endpoint);
            return true;
        }
    }
    return false;
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) Token(org.apache.cassandra.dht.Token) UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer)

Example 38 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class SnapshotDeletingTest method populate.

private void populate(int rowCount) {
    long timestamp = System.currentTimeMillis();
    TableMetadata cfm = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD1).metadata();
    for (int i = 0; i <= rowCount; i++) {
        DecoratedKey key = Util.dk(Integer.toString(i));
        for (int j = 0; j < 10; j++) {
            new RowUpdateBuilder(cfm, timestamp, 0, key.getKey()).clustering(Integer.toString(j)).add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
        }
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) DecoratedKey(org.apache.cassandra.db.DecoratedKey)

Example 39 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class HintsServiceTest method sendHintsAndResponses.

private MockMessagingSpy sendHintsAndResponses(int noOfHints, int noOfResponses) {
    // create spy for hint messages, but only create responses for noOfResponses hints
    MessageIn<HintResponse> messageIn = MessageIn.create(FBUtilities.getBroadcastAddress(), HintResponse.instance, Collections.emptyMap(), MessagingService.Verb.REQUEST_RESPONSE, MessagingService.current_version);
    MockMessagingSpy spy;
    if (noOfResponses != -1) {
        spy = MockMessagingService.when(verb(MessagingService.Verb.HINT)).respondN(messageIn, noOfResponses);
    } else {
        spy = MockMessagingService.when(verb(MessagingService.Verb.HINT)).respond(messageIn);
    }
    // create and write noOfHints using service
    UUID hostId = StorageService.instance.getLocalHostUUID();
    for (int i = 0; i < noOfHints; i++) {
        long now = System.currentTimeMillis();
        DecoratedKey dkey = dk(String.valueOf(i));
        TableMetadata metadata = Schema.instance.getTableMetadata(KEYSPACE, TABLE);
        PartitionUpdate.SimpleBuilder builder = PartitionUpdate.simpleBuilder(metadata, dkey).timestamp(now);
        builder.row("column0").add("val", "value0");
        Hint hint = Hint.create(builder.buildAsMutation(), now);
        HintsService.instance.write(hostId, hint);
    }
    return spy;
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) DecoratedKey(org.apache.cassandra.db.DecoratedKey) UUID(java.util.UUID) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 40 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class Validator method prepare.

public void prepare(ColumnFamilyStore cfs, MerkleTrees trees) {
    this.trees = trees;
    if (!trees.partitioner().preservesOrder() || evenTreeDistribution) {
        // You can't beat even trees distribution for md5
        trees.init();
    } else {
        List<DecoratedKey> keys = new ArrayList<>();
        Random random = new Random();
        for (Range<Token> range : trees.ranges()) {
            for (DecoratedKey sample : cfs.keySamples(range)) {
                assert range.contains(sample.getToken()) : "Token " + sample.getToken() + " is not within range " + desc.ranges;
                keys.add(sample);
            }
            if (keys.isEmpty()) {
                // use even trees distribution
                trees.init(range);
            } else {
                int numKeys = keys.size();
                // sample the column family using random keys from the index
                while (true) {
                    DecoratedKey dk = keys.get(random.nextInt(numKeys));
                    if (!trees.split(dk.getToken()))
                        break;
                }
                keys.clear();
            }
        }
    }
    logger.debug("Prepared AEService trees of size {} for {}", this.trees.size(), desc);
    ranges = trees.rangeIterator();
}
Also used : Random(java.util.Random) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token)

Aggregations

DecoratedKey (org.apache.cassandra.db.DecoratedKey)80 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)31 Test (org.junit.Test)28 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)22 ByteBuffer (java.nio.ByteBuffer)21 TableMetadata (org.apache.cassandra.schema.TableMetadata)20 Keyspace (org.apache.cassandra.db.Keyspace)18 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)16 ColumnFamily (org.apache.cassandra.db.ColumnFamily)8 QueryPath (org.apache.cassandra.db.filter.QueryPath)8 File (org.apache.cassandra.io.util.File)8 ArrayList (java.util.ArrayList)7 UUID (java.util.UUID)7 RowMutation (org.apache.cassandra.db.RowMutation)7 Table (org.apache.cassandra.db.Table)7 Row (org.apache.cassandra.db.rows.Row)7 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)7 Token (org.apache.cassandra.dht.Token)7 BufferDecoratedKey (org.apache.cassandra.db.BufferDecoratedKey)6 RowIndexEntry (org.apache.cassandra.db.RowIndexEntry)5