use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class AbstractCompactionStrategyTest method insertKeyAndFlush.
private static void insertKeyAndFlush(String table, int key) {
long timestamp = System.currentTimeMillis();
DecoratedKey dk = Util.dk(String.format("%03d", key));
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(table);
new RowUpdateBuilder(cfs.metadata(), timestamp, dk.getKey()).clustering(String.valueOf(key)).add("val", "val").build().applyUnsafe();
cfs.forceBlockingFlush();
}
use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class SSTableReverseIteratorTest method emptyBlockTolerance.
/**
* SSTRI shouldn't bail out if it encounters empty blocks (due to dropped columns)
*/
@Test
public void emptyBlockTolerance() {
String table = "empty_block_tolerance";
QueryProcessor.executeInternal(String.format("CREATE TABLE %s.%s (k INT, c int, v1 blob, v2 blob, primary key (k, c))", KEYSPACE, table));
ColumnFamilyStore tbl = Keyspace.open(KEYSPACE).getColumnFamilyStore(table);
assert tbl != null;
int key = 100;
QueryProcessor.executeInternal(String.format("UPDATE %s.%s SET v1=?, v2=? WHERE k=? AND c=?", KEYSPACE, table), bytes(8), bytes(8), key, 0);
QueryProcessor.executeInternal(String.format("UPDATE %s.%s SET v1=? WHERE k=? AND c=?", KEYSPACE, table), bytes(0x20000), key, 1);
QueryProcessor.executeInternal(String.format("UPDATE %s.%s SET v1=? WHERE k=? AND c=?", KEYSPACE, table), bytes(0x20000), key, 2);
QueryProcessor.executeInternal(String.format("UPDATE %s.%s SET v1=? WHERE k=? AND c=?", KEYSPACE, table), bytes(0x20000), key, 3);
tbl.forceBlockingFlush();
SSTableReader sstable = Iterables.getOnlyElement(tbl.getLiveSSTables());
DecoratedKey dk = tbl.getPartitioner().decorateKey(Int32Type.instance.decompose(key));
RowIndexEntry indexEntry = sstable.getPosition(dk, SSTableReader.Operator.EQ);
Assert.assertTrue(indexEntry.isIndexed());
Assert.assertTrue(indexEntry.columnsIndexCount() > 2);
// drop v1 so the first 2 index blocks only contain empty unfiltereds
QueryProcessor.executeInternal(String.format("ALTER TABLE %s.%s DROP v1", KEYSPACE, table));
UntypedResultSet result = QueryProcessor.executeInternal(String.format("SELECT v2 FROM %s.%s WHERE k=? ORDER BY c DESC", KEYSPACE, table), key);
Assert.assertEquals(1, result.size());
}
use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class BlockingReadRepairs method createRepairMutation.
/**
* Create a read repair mutation from the given update, if the mutation is not larger than the maximum
* mutation size, otherwise return null. Or, if we're configured to be strict, throw an exception.
*/
public static Mutation createRepairMutation(PartitionUpdate update, ConsistencyLevel consistency, InetAddressAndPort destination, boolean suppressException) {
if (update == null)
return null;
DecoratedKey key = update.partitionKey();
Mutation mutation = new Mutation(update);
int messagingVersion = MessagingService.instance().versions.get(destination);
try {
mutation.validateSize(messagingVersion, 0);
return mutation;
} catch (MutationExceededMaxSizeException e) {
Keyspace keyspace = Keyspace.open(mutation.getKeyspaceName());
TableMetadata metadata = update.metadata();
if (DROP_OVERSIZED_READ_REPAIR_MUTATIONS) {
logger.debug("Encountered an oversized ({}/{}) read repair mutation for table {}, key {}, node {}", e.mutationSize, MAX_MUTATION_SIZE, metadata, metadata.partitionKeyType.getString(key.getKey()), destination);
} else {
logger.warn("Encountered an oversized ({}/{}) read repair mutation for table {}, key {}, node {}", e.mutationSize, MAX_MUTATION_SIZE, metadata, metadata.partitionKeyType.getString(key.getKey()), destination);
if (!suppressException) {
int blockFor = consistency.blockFor(keyspace.getReplicationStrategy());
Tracing.trace("Timed out while read-repairing after receiving all {} data and digest responses", blockFor);
throw new ReadTimeoutException(consistency, blockFor - 1, blockFor, true);
}
}
return null;
}
}
use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class SSTableReaderBuilder method buildSummaryAndBloomFilter.
/**
* Build index summary, first key, last key if {@code summaryLoaded} is false and recreate bloom filter if
* {@code recreteBloomFilter} is true by reading through Index.db file.
*
* @param recreateBloomFilter true if recreate bloom filter
* @param summaryLoaded true if index summary, first key and last key are already loaded and not need to build again
*/
void buildSummaryAndBloomFilter(boolean recreateBloomFilter, boolean summaryLoaded, Set<Component> components, StatsMetadata statsMetadata) throws IOException {
if (!components.contains(Component.PRIMARY_INDEX))
return;
if (logger.isDebugEnabled())
logger.debug("Attempting to build summary for {}", descriptor);
// we read the positions in a BRAF so we don't have to worry about an entry spanning a mmap boundary.
try (RandomAccessReader primaryIndex = RandomAccessReader.open(new File(descriptor.filenameFor(Component.PRIMARY_INDEX)))) {
long indexSize = primaryIndex.length();
long histogramCount = statsMetadata.estimatedPartitionSize.count();
long estimatedKeys = histogramCount > 0 && !statsMetadata.estimatedPartitionSize.isOverflowed() ? histogramCount : // statistics is supposed to be optional
SSTable.estimateRowsFromIndex(primaryIndex, descriptor);
if (recreateBloomFilter)
bf = FilterFactory.getFilter(estimatedKeys, metadata.params.bloomFilterFpChance);
try (IndexSummaryBuilder summaryBuilder = summaryLoaded ? null : new IndexSummaryBuilder(estimatedKeys, metadata.params.minIndexInterval, Downsampling.BASE_SAMPLING_LEVEL)) {
long indexPosition;
while ((indexPosition = primaryIndex.getFilePointer()) != indexSize) {
ByteBuffer key = ByteBufferUtil.readWithShortLength(primaryIndex);
RowIndexEntry.Serializer.skip(primaryIndex, descriptor.version);
DecoratedKey decoratedKey = metadata.partitioner.decorateKey(key);
if (!summaryLoaded) {
if (first == null)
first = decoratedKey;
last = decoratedKey;
}
if (recreateBloomFilter)
bf.add(decoratedKey);
// if summary was already read from disk we don't want to re-populate it using primary index
if (!summaryLoaded) {
summaryBuilder.maybeAddEntry(decoratedKey, indexPosition);
}
}
if (!summaryLoaded)
summary = summaryBuilder.build(metadata.partitioner);
}
}
if (!summaryLoaded) {
first = SSTable.getMinimalKey(first);
last = SSTable.getMinimalKey(last);
}
}
use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class QueryWithIndexedSSTableTest method queryIndexedSSTableTest.
@Test
public void queryIndexedSSTableTest() throws Throwable {
// That test reproduces the bug from CASSANDRA-10903 and the fact we have a static column is
// relevant to that reproduction in particular as it forces a slightly different code path that
// if there wasn't a static.
int ROWS = 1000;
int VALUE_LENGTH = 100;
createTable("CREATE TABLE %s (k int, t int, s text static, v text, PRIMARY KEY (k, t))");
// We create a partition that is big enough that the underlying sstable will be indexed
// For that, we use a large-ish number of row, and a value that isn't too small.
String text = TombstonesWithIndexedSSTableTest.makeRandomString(VALUE_LENGTH);
for (int i = 0; i < ROWS; i++) execute("INSERT INTO %s(k, t, v) VALUES (?, ?, ?)", 0, i, text + i);
flush();
compact();
// Sanity check that we're testing what we want to test, that is that we're reading from an indexed
// sstable. Note that we'll almost surely have a single indexed sstable in practice, but it's theorically
// possible for a compact strategy to yield more than that and as long as one is indexed we're pretty
// much testing what we want. If this check ever fails on some specific setting, we'll have to either
// tweak ROWS and VALUE_LENGTH, or skip the test on those settings.
DecoratedKey dk = Util.dk(ByteBufferUtil.bytes(0));
boolean hasIndexed = false;
for (SSTableReader sstable : getCurrentColumnFamilyStore().getLiveSSTables()) {
RowIndexEntry indexEntry = sstable.getPosition(dk, SSTableReader.Operator.EQ);
hasIndexed |= indexEntry != null && indexEntry.isIndexed();
}
assert hasIndexed;
assertRowCount(execute("SELECT s FROM %s WHERE k = ?", 0), ROWS);
assertRowCount(execute("SELECT s FROM %s WHERE k = ? ORDER BY t DESC", 0), ROWS);
assertRowCount(execute("SELECT DISTINCT s FROM %s WHERE k = ?", 0), 1);
assertRowCount(execute("SELECT DISTINCT s FROM %s WHERE k = ? ORDER BY t DESC", 0), 1);
}
Aggregations