use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class CustomCassandraIndex method insert.
/**
* Called when adding a new entry to the index
*/
private void insert(ByteBuffer rowKey, Clustering clustering, Cell cell, LivenessInfo info, OpOrder.Group opGroup) {
DecoratedKey valueKey = getIndexKeyFor(getIndexedValue(rowKey, clustering, cell));
Row row = BTreeRow.noCellLiveRow(buildIndexClustering(rowKey, clustering, cell), info);
PartitionUpdate upd = partitionUpdate(valueKey, row);
indexCfs.apply(upd, UpdateTransaction.NO_OP, opGroup, null);
logger.debug("Inserted entry into index for value {}", valueKey);
}
use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class PartitionUpdateTest method testOperationCountWithCompactTable.
@Test
public void testOperationCountWithCompactTable() {
createTable("CREATE TABLE %s (key text PRIMARY KEY, a int) WITH COMPACT STORAGE");
TableMetadata cfm = currentTableMetadata();
PartitionUpdate update = new RowUpdateBuilder(cfm, FBUtilities.timestampMicros(), "key0").add("a", 1).buildUpdate();
Assert.assertEquals(1, update.operationCount());
update = new RowUpdateBuilder(cfm, FBUtilities.timestampMicros(), "key0").buildUpdate();
Assert.assertEquals(0, update.operationCount());
}
use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class HintTest method testApply.
@Test
public void testApply() {
long now = FBUtilities.timestampMicros();
String key = "testApply";
Mutation mutation = createMutation(key, now);
Hint hint = Hint.create(mutation, now / 1000);
// sanity check that there is no data inside yet
assertNoPartitions(key, TABLE0);
assertNoPartitions(key, TABLE1);
assertNoPartitions(key, TABLE2);
hint.apply();
// assert that we can read the inserted partitions
for (PartitionUpdate partition : mutation.getPartitionUpdates()) assertPartitionsEqual(partition, readPartition(key, partition.metadata().name, partition.columns()));
}
use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class HintTest method testApplyWithTruncation.
@Test
public void testApplyWithTruncation() {
long now = FBUtilities.timestampMicros();
String key = "testApplyWithTruncation";
Mutation mutation = createMutation(key, now);
// sanity check that there is no data inside yet
assertNoPartitions(key, TABLE0);
assertNoPartitions(key, TABLE1);
assertNoPartitions(key, TABLE2);
// truncate TABLE1
Keyspace.open(KEYSPACE).getColumnFamilyStore(TABLE1).truncateBlocking();
// create and apply a hint with creation time in the past (one second before the truncation)
Hint.create(mutation, now / 1000 - 1).apply();
// TABLE1 update should have been skipped and not applied, as expired
assertNoPartitions(key, TABLE1);
// TABLE0 and TABLE2 updates should have been applied successfully
PartitionUpdate upd0 = mutation.getPartitionUpdate(Schema.instance.getTableMetadata(KEYSPACE, TABLE0));
assertPartitionsEqual(upd0, readPartition(key, TABLE0, upd0.columns()));
PartitionUpdate upd2 = mutation.getPartitionUpdate(Schema.instance.getTableMetadata(KEYSPACE, TABLE2));
assertPartitionsEqual(upd2, readPartition(key, TABLE2, upd2.columns()));
}
use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class HintsTestUtil method assertHintsEqual.
static void assertHintsEqual(Hint expected, Hint actual) {
assertEquals(expected.mutation.getKeyspaceName(), actual.mutation.getKeyspaceName());
assertEquals(expected.mutation.key(), actual.mutation.key());
assertEquals(expected.mutation.getTableIds(), actual.mutation.getTableIds());
for (PartitionUpdate partitionUpdate : expected.mutation.getPartitionUpdates()) assertPartitionsEqual(partitionUpdate, actual.mutation.getPartitionUpdate(partitionUpdate.metadata()));
assertEquals(expected.creationTime, actual.creationTime);
assertEquals(expected.gcgs, actual.gcgs);
}
Aggregations