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;
}
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;
}
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();
}
}
}
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;
}
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();
}
Aggregations