Java Code Examples for org.apache.cassandra.utils.FBUtilities#waitOnFutures()
The following examples show how to use
org.apache.cassandra.utils.FBUtilities#waitOnFutures() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActiveRepairService.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public synchronized void finishParentSession(UUID parentSession, Set<InetAddress> neighbors, boolean doAntiCompaction) throws InterruptedException, ExecutionException, IOException { try { if (doAntiCompaction) { for (InetAddress neighbor : neighbors) { AnticompactionRequest acr = new AnticompactionRequest(parentSession); MessageOut<RepairMessage> req = acr.createMessage(); MessagingService.instance().sendOneWay(req, neighbor); } List<Future<?>> futures = doAntiCompaction(parentSession); FBUtilities.waitOnFutures(futures); } } finally { parentRepairSessions.remove(parentSession); } }
Example 2
Source File: LongCompactionsTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
private void forceCompactions(ColumnFamilyStore cfs) throws ExecutionException, InterruptedException { // re-enable compaction with thresholds low enough to force a few rounds cfs.setCompactionThresholds(2, 4); // loop submitting parallel compactions until they all return 0 do { ArrayList<Future<?>> compactions = new ArrayList<Future<?>>(); for (int i = 0; i < 10; i++) compactions.addAll(CompactionManager.instance.submitBackground(cfs)); // another compaction attempt will be launched in the background by // each completing compaction: not much we can do to control them here FBUtilities.waitOnFutures(compactions); } while (CompactionManager.instance.getPendingTasks() > 0 || CompactionManager.instance.getActiveCompactions() > 0); if (cfs.getSSTables().size() > 1) { CompactionManager.instance.performMaximal(cfs); } }
Example 3
Source File: CacheService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public void saveCaches() throws ExecutionException, InterruptedException { List<Future<?>> futures = new ArrayList<>(3); logger.debug("submitting cache saves"); futures.add(keyCache.submitWrite(DatabaseDescriptor.getKeyCacheKeysToSave())); futures.add(rowCache.submitWrite(DatabaseDescriptor.getRowCacheKeysToSave())); futures.add(counterCache.submitWrite(DatabaseDescriptor.getCounterCacheKeysToSave())); FBUtilities.waitOnFutures(futures); logger.debug("cache saves completed"); }
Example 4
Source File: StreamSession.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Flushes matching column families from the given keyspace, or all columnFamilies * if the cf list is empty. */ private void flushSSTables(Iterable<ColumnFamilyStore> stores) { List<Future<?>> flushes = new ArrayList<>(); for (ColumnFamilyStore cfs : stores) flushes.add(cfs.forceFlush()); FBUtilities.waitOnFutures(flushes); }
Example 5
Source File: CompactionsPurgeTest.java From stratio-cassandra with Apache License 2.0 | 4 votes |
@Test public void testRowTombstoneObservedBeforePurging() throws InterruptedException, ExecutionException { String keyspace = "cql_keyspace"; String table = "table1"; ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(table); cfs.disableAutoCompaction(); // write a row out to one sstable executeInternal(String.format("INSERT INTO %s.%s (k, v1, v2) VALUES (%d, '%s', %d)", keyspace, table, 1, "foo", 1)); cfs.forceBlockingFlush(); UntypedResultSet result = executeInternal(String.format("SELECT * FROM %s.%s WHERE k = %d", keyspace, table, 1)); assertEquals(1, result.size()); // write a row tombstone out to a second sstable executeInternal(String.format("DELETE FROM %s.%s WHERE k = %d", keyspace, table, 1)); cfs.forceBlockingFlush(); // basic check that the row is considered deleted assertEquals(2, cfs.getSSTables().size()); result = executeInternal(String.format("SELECT * FROM %s.%s WHERE k = %d", keyspace, table, 1)); assertEquals(0, result.size()); // compact the two sstables with a gcBefore that does *not* allow the row tombstone to be purged FBUtilities.waitOnFutures(CompactionManager.instance.submitMaximal(cfs, (int) (System.currentTimeMillis() / 1000) - 10000)); // the data should be gone, but the tombstone should still exist assertEquals(1, cfs.getSSTables().size()); result = executeInternal(String.format("SELECT * FROM %s.%s WHERE k = %d", keyspace, table, 1)); assertEquals(0, result.size()); // write a row out to one sstable executeInternal(String.format("INSERT INTO %s.%s (k, v1, v2) VALUES (%d, '%s', %d)", keyspace, table, 1, "foo", 1)); cfs.forceBlockingFlush(); assertEquals(2, cfs.getSSTables().size()); result = executeInternal(String.format("SELECT * FROM %s.%s WHERE k = %d", keyspace, table, 1)); assertEquals(1, result.size()); // write a row tombstone out to a different sstable executeInternal(String.format("DELETE FROM %s.%s WHERE k = %d", keyspace, table, 1)); cfs.forceBlockingFlush(); // compact the two sstables with a gcBefore that *does* allow the row tombstone to be purged FBUtilities.waitOnFutures(CompactionManager.instance.submitMaximal(cfs, (int) (System.currentTimeMillis() / 1000) + 10000)); // both the data and the tombstone should be gone this time assertEquals(0, cfs.getSSTables().size()); result = executeInternal(String.format("SELECT * FROM %s.%s WHERE k = %d", keyspace, table, 1)); assertEquals(0, result.size()); }
Example 6
Source File: CompactionsTest.java From stratio-cassandra with Apache License 2.0 | 4 votes |
@Test public void testUncheckedTombstoneSizeTieredCompaction() throws Exception { Keyspace keyspace = Keyspace.open(KEYSPACE1); ColumnFamilyStore store = keyspace.getColumnFamilyStore(STANDARD1); store.clearUnsafe(); store.metadata.gcGraceSeconds(1); store.metadata.compactionStrategyOptions.put("tombstone_compaction_interval", "1"); store.metadata.compactionStrategyOptions.put("unchecked_tombstone_compaction", "false"); store.reload(); store.setCompactionStrategyClass(SizeTieredCompactionStrategy.class.getName()); // disable compaction while flushing store.disableAutoCompaction(); //Populate sstable1 with with keys [0..9] populate(KEYSPACE1, STANDARD1, 0, 9, 3); //ttl=3s store.forceBlockingFlush(); //Populate sstable2 with with keys [10..19] (keys do not overlap with SSTable1) long timestamp2 = populate(KEYSPACE1, STANDARD1, 10, 19, 3); //ttl=3s store.forceBlockingFlush(); assertEquals(2, store.getSSTables().size()); Iterator<SSTableReader> it = store.getSSTables().iterator(); long originalSize1 = it.next().uncompressedLength(); long originalSize2 = it.next().uncompressedLength(); // wait enough to force single compaction TimeUnit.SECONDS.sleep(5); // enable compaction, submit background and wait for it to complete store.enableAutoCompaction(); FBUtilities.waitOnFutures(CompactionManager.instance.submitBackground(store)); while (CompactionManager.instance.getPendingTasks() > 0 || CompactionManager.instance.getActiveCompactions() > 0) TimeUnit.SECONDS.sleep(1); // even though both sstables were candidate for tombstone compaction // it was not executed because they have an overlapping token range assertEquals(2, store.getSSTables().size()); it = store.getSSTables().iterator(); long newSize1 = it.next().uncompressedLength(); long newSize2 = it.next().uncompressedLength(); assertEquals("candidate sstable should not be tombstone-compacted because its key range overlap with other sstable", originalSize1, newSize1); assertEquals("candidate sstable should not be tombstone-compacted because its key range overlap with other sstable", originalSize2, newSize2); // now let's enable the magic property store.metadata.compactionStrategyOptions.put("unchecked_tombstone_compaction", "true"); store.reload(); //submit background task again and wait for it to complete FBUtilities.waitOnFutures(CompactionManager.instance.submitBackground(store)); while (CompactionManager.instance.getPendingTasks() > 0 || CompactionManager.instance.getActiveCompactions() > 0) TimeUnit.SECONDS.sleep(1); //we still have 2 sstables, since they were not compacted against each other assertEquals(2, store.getSSTables().size()); it = store.getSSTables().iterator(); newSize1 = it.next().uncompressedLength(); newSize2 = it.next().uncompressedLength(); assertTrue("should be less than " + originalSize1 + ", but was " + newSize1, newSize1 < originalSize1); assertTrue("should be less than " + originalSize2 + ", but was " + newSize2, newSize2 < originalSize2); // make sure max timestamp of compacted sstables is recorded properly after compaction. assertMaxTimestamp(store, timestamp2); }