Search in sources :

Example 1 with TombstoneOverwhelmingException

use of org.apache.cassandra.db.filter.TombstoneOverwhelmingException in project cassandra by apache.

the class MessageDeliveryTask method handleFailure.

private void handleFailure(Throwable t) {
    if (message.doCallbackOnFailure()) {
        MessageOut response = new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE).withParameter(MessagingService.FAILURE_RESPONSE_PARAM, MessagingService.ONE_BYTE);
        if (t instanceof TombstoneOverwhelmingException) {
            try (DataOutputBuffer out = new DataOutputBuffer()) {
                out.writeShort(RequestFailureReason.READ_TOO_MANY_TOMBSTONES.code);
                response = response.withParameter(MessagingService.FAILURE_REASON_PARAM, out.getData());
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }
        MessagingService.instance().sendReply(response, id, message.from);
    }
}
Also used : DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) IOException(java.io.IOException) TombstoneOverwhelmingException(org.apache.cassandra.db.filter.TombstoneOverwhelmingException)

Example 2 with TombstoneOverwhelmingException

use of org.apache.cassandra.db.filter.TombstoneOverwhelmingException in project cassandra by apache.

the class TombstonesTest method testBeyondThresholdSelect.

@Test
public void testBeyondThresholdSelect() throws Throwable {
    String tableName = createTable("CREATE TABLE %s (a text, b text, c text, PRIMARY KEY (a, b));");
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore(tableName);
    long oldFailures = cfs.metric.tombstoneFailures.getCount();
    long oldWarnings = cfs.metric.tombstoneWarnings.getCount();
    // insert exactly the amount of tombstones that *SHOULD* trigger an exception
    for (int i = 0; i < FAILURE_THRESHOLD + 1; i++) execute("INSERT INTO %s (a, b, c) VALUES ('key', 'column" + i + "', null);");
    try {
        execute("SELECT * FROM %s WHERE a = 'key';");
        fail("SELECT with tombstones beyond the threshold should have failed, but hasn't");
    } catch (Throwable e) {
        String error = "Expected exception instanceof TombstoneOverwhelmingException instead got " + System.lineSeparator() + Throwables.getStackTraceAsString(e);
        assertTrue(error, e instanceof TombstoneOverwhelmingException);
        assertEquals(oldWarnings, cfs.metric.tombstoneWarnings.getCount());
        assertEquals(oldFailures + 1, cfs.metric.tombstoneFailures.getCount());
    }
}
Also used : ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) TombstoneOverwhelmingException(org.apache.cassandra.db.filter.TombstoneOverwhelmingException) Test(org.junit.Test)

Example 3 with TombstoneOverwhelmingException

use of org.apache.cassandra.db.filter.TombstoneOverwhelmingException in project cassandra by apache.

the class TombstonesTest method testExpiredTombstones.

@Test
public void testExpiredTombstones() throws Throwable {
    String tableName = createTable("CREATE TABLE %s (a text, b text, c text, PRIMARY KEY (a, b)) WITH gc_grace_seconds = 1;");
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore(tableName);
    long oldFailures = cfs.metric.tombstoneFailures.getCount();
    long oldWarnings = cfs.metric.tombstoneWarnings.getCount();
    for (int i = 0; i < FAILURE_THRESHOLD + 1; i++) execute("INSERT INTO %s (a, b, c) VALUES ('key', 'column" + i + "', null);");
    // not yet past gc grace - must throw a TOE
    try {
        execute("SELECT * FROM %s WHERE a = 'key';");
        fail("SELECT with tombstones beyond the threshold should have failed, but hasn't");
    } catch (Throwable e) {
        assertTrue(e instanceof TombstoneOverwhelmingException);
        assertEquals(++oldFailures, cfs.metric.tombstoneFailures.getCount());
        assertEquals(oldWarnings, cfs.metric.tombstoneWarnings.getCount());
    }
    // sleep past gc grace
    TimeUnit.SECONDS.sleep(2);
    // past gc grace - must not throw a TOE now
    try {
        execute("SELECT * FROM %s WHERE a = 'key';");
        assertEquals(oldFailures, cfs.metric.tombstoneFailures.getCount());
        assertEquals(oldWarnings, cfs.metric.tombstoneWarnings.getCount());
    } catch (Throwable e) {
        fail("SELECT with expired tombstones beyond the threshold should not have failed, but has: " + e);
    }
}
Also used : ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) TombstoneOverwhelmingException(org.apache.cassandra.db.filter.TombstoneOverwhelmingException) Test(org.junit.Test)

Aggregations

TombstoneOverwhelmingException (org.apache.cassandra.db.filter.TombstoneOverwhelmingException)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)1