@Test(timeout = 5000) public void testTruncateHints() throws Exception { Keyspace systemKeyspace = Keyspace.open("system"); ColumnFamilyStore hintStore = systemKeyspace.getColumnFamilyStore(SystemKeyspace.HINTS_CF); hintStore.clearUnsafe(); // insert 1 hint RowMutation rm = new RowMutation(KEYSPACE4, ByteBufferUtil.bytes(1)); rm.add( STANDARD1_CF, ByteBufferUtil.bytes(String.valueOf(COLUMN1)), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis()); HintedHandOffManager.instance .hintFor( rm, System.currentTimeMillis(), HintedHandOffManager.calculateHintTTL(rm), UUID.randomUUID()) .apply(); assert getNoOfHints() == 1; HintedHandOffManager.instance.truncateAllHints(); while (getNoOfHints() > 0) { Thread.sleep(100); } assert getNoOfHints() == 0; }
// Test compaction of hints column family. It shouldn't remove all columns on compaction. @Test public void testCompactionOfHintsCF() throws Exception { // prepare hints column family Keyspace systemKeyspace = Keyspace.open("system"); ColumnFamilyStore hintStore = systemKeyspace.getColumnFamilyStore(SystemKeyspace.HINTS_CF); hintStore.clearUnsafe(); hintStore.metadata.gcGraceSeconds(36000); // 10 hours hintStore.setCompactionStrategyClass(SizeTieredCompactionStrategy.class.getCanonicalName()); hintStore.disableAutoCompaction(); // insert 1 hint RowMutation rm = new RowMutation(KEYSPACE4, ByteBufferUtil.bytes(1)); rm.add( STANDARD1_CF, ByteBufferUtil.bytes(String.valueOf(COLUMN1)), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis()); HintedHandOffManager.instance .hintFor( rm, System.currentTimeMillis(), HintedHandOffManager.calculateHintTTL(rm), UUID.randomUUID()) .apply(); // flush data to disk hintStore.forceBlockingFlush(); assertEquals(1, hintStore.getSSTables().size()); // submit compaction FBUtilities.waitOnFuture(HintedHandOffManager.instance.compact()); while (CompactionManager.instance.getPendingTasks() > 0 || CompactionManager.instance.getActiveCompactions() > 0) TimeUnit.SECONDS.sleep(1); // single row should not be removed because of gc_grace_seconds // is 10 hours and there are no any tombstones in sstable assertEquals(1, hintStore.getSSTables().size()); }