use of org.apache.cassandra.thrift.IndexExpression in project eiger by wlloyd.
the class RangeSliceCommandSerializer method deserialize.
public RangeSliceCommand deserialize(DataInput dis, int version) throws IOException {
String keyspace = dis.readUTF();
String columnFamily = dis.readUTF();
int scLength = dis.readInt();
ByteBuffer superColumn = null;
if (scLength > 0) {
byte[] buf = new byte[scLength];
dis.readFully(buf);
superColumn = ByteBuffer.wrap(buf);
}
TDeserializer dser = new TDeserializer(new TBinaryProtocol.Factory());
SlicePredicate pred = new SlicePredicate();
FBUtilities.deserialize(dser, pred, dis);
List<IndexExpression> rowFilter = null;
if (version >= MessagingService.VERSION_11) {
int filterCount = dis.readInt();
rowFilter = new ArrayList<IndexExpression>(filterCount);
for (int i = 0; i < filterCount; i++) {
IndexExpression expr = new IndexExpression();
FBUtilities.deserialize(dser, expr, dis);
rowFilter.add(expr);
}
}
AbstractBounds<RowPosition> range = AbstractBounds.serializer().deserialize(dis, version).toRowBounds();
int maxResults = dis.readInt();
boolean maxIsColumns = false;
if (version >= MessagingService.VERSION_11) {
maxIsColumns = dis.readBoolean();
}
return new RangeSliceCommand(keyspace, columnFamily, superColumn, pred, range, rowFilter, maxResults, maxIsColumns);
}
use of org.apache.cassandra.thrift.IndexExpression in project eiger by wlloyd.
the class KeysSearcher method highestSelectivityPredicate.
private IndexExpression highestSelectivityPredicate(List<IndexExpression> clause) {
IndexExpression best = null;
int bestMeanCount = Integer.MAX_VALUE;
for (IndexExpression expression : clause) {
//skip columns belonging to a different index type
if (!columns.contains(expression.column_name))
continue;
SecondaryIndex index = indexManager.getIndexForColumn(expression.column_name);
if (index == null || (expression.op != IndexOperator.EQ))
continue;
int columns = index.getIndexCfs().getMeanColumns();
if (columns < bestMeanCount) {
best = expression;
bestMeanCount = columns;
}
}
return best;
}
use of org.apache.cassandra.thrift.IndexExpression in project eiger by wlloyd.
the class CleanupTest method testCleanupWithIndexes.
@Test
public void testCleanupWithIndexes() throws IOException, ExecutionException, InterruptedException {
Table table = Table.open(TABLE1);
ColumnFamilyStore cfs = table.getColumnFamilyStore(CF1);
assertEquals(cfs.indexManager.getIndexedColumns().iterator().next(), COLUMN);
List<Row> rows;
// insert data and verify we get it back w/ range query
fillCF(cfs, LOOPS);
rows = Util.getRangeSlice(cfs);
assertEquals(LOOPS, rows.size());
SecondaryIndex index = cfs.indexManager.getIndexForColumn(COLUMN);
long start = System.currentTimeMillis();
while (!index.isIndexBuilt(COLUMN) && System.currentTimeMillis() < start + 10000) Thread.sleep(10);
// verify we get it back w/ index query too
IndexExpression expr = new IndexExpression(COLUMN, IndexOperator.EQ, VALUE);
List<IndexExpression> clause = Arrays.asList(expr);
IFilter filter = new IdentityQueryFilter();
IPartitioner p = StorageService.getPartitioner();
Range<RowPosition> range = Util.range("", "");
rows = table.getColumnFamilyStore(CF1).search(clause, range, Integer.MAX_VALUE, filter);
assertEquals(LOOPS, rows.size());
// we don't allow cleanup when the local host has no range to avoid wipping up all data when a node has not join the ring.
// So to make sure cleanup erase everything here, we give the localhost the tiniest possible range.
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
byte[] tk1 = new byte[1], tk2 = new byte[1];
tk1[0] = 2;
tk2[0] = 1;
tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2"));
CompactionManager.instance.performCleanup(cfs, new NodeId.OneShotRenewer());
// row data should be gone
rows = Util.getRangeSlice(cfs);
assertEquals(0, rows.size());
// not only should it be gone but there should be no data on disk, not even tombstones
assert cfs.getSSTables().isEmpty();
// 2ary indexes should result in no results, too (although tombstones won't be gone until compacted)
rows = cfs.search(clause, range, Integer.MAX_VALUE, filter);
assertEquals(0, rows.size());
}
use of org.apache.cassandra.thrift.IndexExpression in project eiger by wlloyd.
the class SSTableReaderTest method assertIndexQueryWorks.
private void assertIndexQueryWorks(ColumnFamilyStore indexedCFS) {
assert "Indexed1".equals(indexedCFS.getColumnFamilyName());
// make sure all sstables including 2ary indexes load from disk
indexedCFS.clearUnsafe();
for (ColumnFamilyStore indexCfs : indexedCFS.indexManager.getIndexesBackedByCfs()) {
indexCfs.clearUnsafe();
// v1.0.4 would fail here (see CASSANDRA-3540)
indexCfs.loadNewSSTables();
}
indexedCFS.loadNewSSTables();
// query using index to see if sstable for secondary index opens
IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L));
List<IndexExpression> clause = Arrays.asList(expr);
IPartitioner p = StorageService.getPartitioner();
Range<RowPosition> range = Util.range("", "");
List<Row> rows = indexedCFS.search(clause, range, 100, new IdentityQueryFilter());
assert rows.size() == 1;
}
use of org.apache.cassandra.thrift.IndexExpression in project eiger by wlloyd.
the class StreamingTransferTest method testTransferTable.
@Test
public void testTransferTable() throws Exception {
final Table table = Table.open("Keyspace1");
final ColumnFamilyStore cfs = table.getColumnFamilyStore("Indexed1");
List<String> keys = createAndTransfer(table, cfs, new Mutator() {
public void mutate(String key, String col, long timestamp) throws Exception {
long val = key.hashCode();
RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes(key));
ColumnFamily cf = ColumnFamily.create(table.name, cfs.columnFamily);
cf.addColumn(column(col, "v", timestamp));
cf.addColumn(new Column(ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(val), timestamp));
rm.add(cf);
logger.debug("Applying row to transfer " + rm);
rm.apply();
}
});
// confirm that the secondary index was recovered
for (String key : keys) {
long val = key.hashCode();
IPartitioner p = StorageService.getPartitioner();
IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(val));
List<IndexExpression> clause = Arrays.asList(expr);
IFilter filter = new IdentityQueryFilter();
Range<RowPosition> range = Util.range("", "");
List<Row> rows = cfs.search(clause, range, 100, filter);
assertEquals(1, rows.size());
assert rows.get(0).key.key.equals(ByteBufferUtil.bytes(key));
}
}
Aggregations