Search in sources :

Example 11 with PartitionUpdate

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);
}
Also used : PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 12 with PartitionUpdate

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());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 13 with PartitionUpdate

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()));
}
Also used : PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 14 with PartitionUpdate

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()));
}
Also used : PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 15 with PartitionUpdate

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);
}
Also used : PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Aggregations

PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)40 Test (org.junit.Test)14 TableMetadata (org.apache.cassandra.schema.TableMetadata)7 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)3 Mutation (org.apache.cassandra.db.Mutation)3 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)3 Commit (org.apache.cassandra.service.paxos.Commit)3 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)2 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)2 TableId (org.apache.cassandra.schema.TableId)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 InetAddress (java.net.InetAddress)1 ByteBuffer (java.nio.ByteBuffer)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1