Java Code Examples for org.apache.cassandra.utils.FBUtilities#waitOnFuture()

The following examples show how to use org.apache.cassandra.utils.FBUtilities#waitOnFuture() . 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: MigrationManager.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * actively announce a new version to active hosts via rpc
 * @param schema The schema mutation to be applied
 */
private static void announce(Mutation schema, boolean announceLocally)
{
    if (announceLocally)
    {
        try
        {
            DefsTables.mergeSchemaInternal(Collections.singletonList(schema), false);
        }
        catch (ConfigurationException | IOException e)
        {
            throw new RuntimeException(e);
        }
    }
    else
    {
        FBUtilities.waitOnFuture(announce(Collections.singletonList(schema)));
    }
}
 
Example 2
Source File: SecondaryIndex.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the index using the data in the underlying CFS
 * Blocks till it's complete
 */
protected void buildIndexBlocking()
{
    logger.info(String.format("Submitting index build of %s for data in %s",
            getIndexName(), StringUtils.join(baseCfs.getSSTables(), ", ")));

    try (Refs<SSTableReader> sstables = baseCfs.selectAndReference(ColumnFamilyStore.CANONICAL_SSTABLES).refs)
    {
        SecondaryIndexBuilder builder = new SecondaryIndexBuilder(baseCfs,
                                                                  Collections.singleton(getIndexName()),
                                                                  new ReducingKeyIterator(sstables));
        Future<?> future = CompactionManager.instance.submitIndexBuild(builder);
        FBUtilities.waitOnFuture(future);
        forceBlockingFlush();
        setIndexBuilt();
    }
    logger.info("Index build of {} complete", getIndexName());
}
 
Example 3
Source File: SecondaryIndexManager.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Does a full, blocking rebuild of the indexes specified by columns from the sstables.
 * Does nothing if columns is empty.
 *
 * Caller must acquire and release references to the sstables used here.
 *
 * @param sstables the data to build from
 * @param idxNames the list of columns to index, ordered by comparator
 */
public void maybeBuildSecondaryIndexes(Collection<SSTableReader> sstables, Set<String> idxNames)
{
    if (idxNames.isEmpty())
        return;

    logger.info(String.format("Submitting index build of %s for data in %s",
                              idxNames, StringUtils.join(sstables, ", ")));

    SecondaryIndexBuilder builder = new SecondaryIndexBuilder(baseCfs, idxNames, new ReducingKeyIterator(sstables));
    Future<?> future = CompactionManager.instance.submitIndexBuild(builder);
    FBUtilities.waitOnFuture(future);

    flushIndexesBlocking();

    logger.info("Index build of {} complete", idxNames);
}
 
Example 4
Source File: MigrationManager.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Clear all locally stored schema information and reset schema to initial state.
 * Called by user (via JMX) who wants to get rid of schema disagreement.
 *
 * @throws IOException if schema tables truncation fails
 */
public static void resetLocalSchema() throws IOException
{
    logger.info("Starting local schema reset...");

    logger.debug("Truncating schema tables...");

    // truncate schema tables
    for (String cf : SystemKeyspace.allSchemaCfs)
        SystemKeyspace.schemaCFS(cf).truncateBlocking();

    logger.debug("Clearing local schema keyspace definitions...");

    Schema.instance.clear();

    Set<InetAddress> liveEndpoints = Gossiper.instance.getLiveMembers();
    liveEndpoints.remove(FBUtilities.getBroadcastAddress());

    // force migration if there are nodes around
    for (InetAddress node : liveEndpoints)
    {
        if (shouldPullSchemaFrom(node))
        {
            logger.debug("Requesting schema from {}", node);
            FBUtilities.waitOnFuture(submitMigrationTask(node));
            break;
        }
    }

    logger.info("Local schema reset is complete.");
}
 
Example 5
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private Future<StreamState> streamHints()
{
    // StreamPlan will not fail if there are zero files to transfer, so flush anyway (need to get any in-memory hints, as well)
    ColumnFamilyStore hintsCF = Keyspace.open(Keyspace.SYSTEM_KS).getColumnFamilyStore(SystemKeyspace.HINTS_CF);
    FBUtilities.waitOnFuture(hintsCF.forceFlush());

    // gather all live nodes in the cluster that aren't also leaving
    List<InetAddress> candidates = new ArrayList<>(StorageService.instance.getTokenMetadata().cloneAfterAllLeft().getAllEndpoints());
    candidates.remove(FBUtilities.getBroadcastAddress());
    for (Iterator<InetAddress> iter = candidates.iterator(); iter.hasNext(); )
    {
        InetAddress address = iter.next();
        if (!FailureDetector.instance.isAlive(address))
            iter.remove();
    }

    if (candidates.isEmpty())
    {
        logger.warn("Unable to stream hints since no live endpoints seen");
        return Futures.immediateFuture(null);
    }
    else
    {
        // stream to the closest peer as chosen by the snitch
        DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getBroadcastAddress(), candidates);
        InetAddress hintsDestinationHost = candidates.get(0);
        InetAddress preferred = SystemKeyspace.getPreferredIP(hintsDestinationHost);

        // stream all hints -- range list will be a singleton of "the entire ring"
        Token token = StorageService.getPartitioner().getMinimumToken();
        List<Range<Token>> ranges = Collections.singletonList(new Range<>(token, token));

        return new StreamPlan("Hints").transferRanges(hintsDestinationHost,
                                                      preferred,
                                                                  Keyspace.SYSTEM_KS,
                                                                  ranges,
                                                                  SystemKeyspace.HINTS_CF)
                                                  .execute();
    }
}
 
Example 6
Source File: AbstractSimplePerColumnSecondaryIndex.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void forceBlockingFlush()
{
    Future<?> wait;
    // we synchronise on the baseCfs to make sure we are ordered correctly with other flushes to the base CFS
    synchronized (baseCfs.getDataTracker())
    {
        wait = indexCfs.forceFlush();
    }
    FBUtilities.waitOnFuture(wait);
}
 
Example 7
Source File: SSTableDeletingTask.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/** for tests */
public static void waitForDeletions()
{
    Runnable runnable = new Runnable()
    {
        public void run()
        {
        }
    };

    FBUtilities.waitOnFuture(ScheduledExecutors.nonPeriodicTasks.schedule(runnable, 0, TimeUnit.MILLISECONDS));
}
 
Example 8
Source File: SSTableAttachedSecondaryIndex.java    From sasi with Apache License 2.0 4 votes vote down vote up
@Override
public void buildIndexes(Collection<SSTableReader> sstablesToRebuild, Set<String> indexNames)
{
    NavigableMap<SSTableReader, Map<ByteBuffer, ColumnIndex>> sstables = new TreeMap<>(new Comparator<SSTableReader>()
    {
        @Override
        public int compare(SSTableReader a, SSTableReader b)
        {
            return Integer.compare(a.descriptor.generation, b.descriptor.generation);
        }
    });

    Map<ByteBuffer, ColumnIndex> indexes = new HashMap<>();
    for (ColumnIndex index : indexedColumns.values())
    {
        Iterator<String> iterator = indexNames.iterator();

        while (iterator.hasNext())
        {
            String indexName = iterator.next();
            if (index.getIndexName().equals(indexName))
            {
                index.dropData(FBUtilities.timestampMicros());

                ColumnDefinition indexToBuild = index.getDefinition();
                indexes.put(indexToBuild.name, index);
                iterator.remove();
                break;
            }
        }
    }

    if (indexes.isEmpty())
        return;

    for (SSTableReader sstable : sstablesToRebuild)
        sstables.put(sstable, indexes);

    try
    {
        FBUtilities.waitOnFuture(CompactionManager.instance.submitIndexBuild(new IndexBuilder(sstables)));
    }
    catch (Exception e)
    {
        logger.error("Failed index build task", e);
    }
}