Java Code Examples for org.apache.cassandra.config.DatabaseDescriptor#getClusterName()

The following examples show how to use org.apache.cassandra.config.DatabaseDescriptor#getClusterName() . 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: QueueProcessorTest.java    From debezium-incubator with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessChangeRecords() throws Exception {
    doNothing().when(emitter).emit(any());

    int recordSize = 5;
    ChangeEventQueue<Event> queue = context.getQueue();
    for (int i = 0; i < recordSize; i++) {
        CassandraConnectorConfig config = new CassandraConnectorConfig(Configuration.from(new Properties()));
        SourceInfo sourceInfo = new SourceInfo(config, DatabaseDescriptor.getClusterName(),
                new OffsetPosition("CommitLog-6-123.log", i),
                new KeyspaceTable(TEST_KEYSPACE, "cdc_table"), false,
                Conversions.toInstantFromMicros(System.currentTimeMillis() * 1000));
        Record record = new ChangeRecord(sourceInfo, new RowData(), Schema.INT32_SCHEMA, Schema.INT32_SCHEMA, Record.Operation.INSERT, false);
        queue.enqueue(record);
    }

    assertEquals(recordSize, queue.totalCapacity() - queue.remainingCapacity());
    queueProcessor.process();
    verify(emitter, times(recordSize)).emit(any());
    assertEquals(queue.totalCapacity(), queue.remainingCapacity());
}
 
Example 2
Source File: QueueProcessorTest.java    From debezium-incubator with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessTombstoneRecords() throws Exception {
    doNothing().when(emitter).emit(any());

    int recordSize = 5;
    ChangeEventQueue<Event> queue = context.getQueue();
    for (int i = 0; i < recordSize; i++) {
        CassandraConnectorConfig config = new CassandraConnectorConfig(Configuration.from(new Properties()));
        SourceInfo sourceInfo = new SourceInfo(config, DatabaseDescriptor.getClusterName(),
                new OffsetPosition("CommitLog-6-123.log", i),
                new KeyspaceTable(TEST_KEYSPACE, "cdc_table"), false,
                Conversions.toInstantFromMicros(System.currentTimeMillis() * 1000));
        Record record = new TombstoneRecord(sourceInfo, new RowData(), Schema.INT32_SCHEMA);
        queue.enqueue(record);
    }

    assertEquals(recordSize, queue.totalCapacity() - queue.remainingCapacity());
    queueProcessor.process();
    verify(emitter, times(recordSize)).emit(any());
    assertEquals(queue.totalCapacity(), queue.remainingCapacity());
}
 
Example 3
Source File: Gossiper.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 *  Do a single 'shadow' round of gossip, where we do not modify any state
 *  Only used when replacing a node, to get and assume its states
 */
public void doShadowRound()
{
    buildSeedsList();
    // send a completely empty syn
    List<GossipDigest> gDigests = new ArrayList<GossipDigest>();
    GossipDigestSyn digestSynMessage = new GossipDigestSyn(DatabaseDescriptor.getClusterName(),
            DatabaseDescriptor.getPartitionerName(),
            gDigests);
    MessageOut<GossipDigestSyn> message = new MessageOut<GossipDigestSyn>(MessagingService.Verb.GOSSIP_DIGEST_SYN,
            digestSynMessage,
            GossipDigestSyn.serializer);
    inShadowRound = true;
    for (InetAddress seed : seeds)
        MessagingService.instance().sendOneWay(message, seed);
    int slept = 0;
    try
    {
        while (true)
        {
            Thread.sleep(1000);
            if (!inShadowRound)
                break;
            slept += 1000;
            if (slept > StorageService.RING_DELAY)
                throw new RuntimeException("Unable to gossip with any seeds");
        }
    }
    catch (InterruptedException wtf)
    {
        throw new RuntimeException(wtf);
    }
}
 
Example 4
Source File: SystemKeyspace.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * One of three things will happen if you try to read the system keyspace:
 * 1. files are present and you can read them: great
 * 2. no files are there: great (new node is assumed)
 * 3. files are present but you can't read them: bad
 * @throws ConfigurationException
 */
public static void checkHealth() throws ConfigurationException
{
    Keyspace keyspace;
    try
    {
        keyspace = Keyspace.open(Keyspace.SYSTEM_KS);
    }
    catch (AssertionError err)
    {
        // this happens when a user switches from OPP to RP.
        ConfigurationException ex = new ConfigurationException("Could not read system keyspace!");
        ex.initCause(err);
        throw ex;
    }
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(LOCAL_CF);

    String req = "SELECT cluster_name FROM system.%s WHERE key='%s'";
    UntypedResultSet result = executeInternal(String.format(req, LOCAL_CF, LOCAL_KEY));

    if (result.isEmpty() || !result.one().has("cluster_name"))
    {
        // this is a brand new node
        if (!cfs.getSSTables().isEmpty())
            throw new ConfigurationException("Found system keyspace files, but they couldn't be loaded!");

        // no system files.  this is a new node.
        req = "INSERT INTO system.%s (key, cluster_name) VALUES ('%s', ?)";
        executeInternal(String.format(req, LOCAL_CF, LOCAL_KEY), DatabaseDescriptor.getClusterName());
        return;
    }

    String savedClusterName = result.one().getString("cluster_name");
    if (!DatabaseDescriptor.getClusterName().equals(savedClusterName))
        throw new ConfigurationException("Saved cluster name " + savedClusterName + " != configured name " + DatabaseDescriptor.getClusterName());
}
 
Example 5
Source File: InternalMetadataFactory.java    From cassandra-exporter with Apache License 2.0 4 votes vote down vote up
@Override
public String clusterName() {
    return DatabaseDescriptor.getClusterName();
}
 
Example 6
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/** Returns the name of the cluster */
public String getClusterName()
{
    return DatabaseDescriptor.getClusterName();
}
 
Example 7
Source File: Gossiper.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public void run()
{
    try
    {
        //wait on messaging service to start listening
        MessagingService.instance().waitUntilListening();

        taskLock.lock();

        /* Update the local heartbeat counter. */
        endpointStateMap.get(FBUtilities.getBroadcastAddress()).getHeartBeatState().updateHeartBeat();
        if (logger.isTraceEnabled())
            logger.trace("My heartbeat is now " + endpointStateMap.get(FBUtilities.getBroadcastAddress()).getHeartBeatState().getHeartBeatVersion());
        final List<GossipDigest> gDigests = new ArrayList<GossipDigest>();
        Gossiper.instance.makeRandomGossipDigest(gDigests);

        if (gDigests.size() > 0)
        {
            GossipDigestSyn digestSynMessage = new GossipDigestSyn(DatabaseDescriptor.getClusterName(),
                                                                   DatabaseDescriptor.getPartitionerName(),
                                                                   gDigests);
            MessageOut<GossipDigestSyn> message = new MessageOut<GossipDigestSyn>(MessagingService.Verb.GOSSIP_DIGEST_SYN,
                                                                                  digestSynMessage,
                                                                                  GossipDigestSyn.serializer);
            /* Gossip to some random live member */
            boolean gossipedToSeed = doGossipToLiveMember(message);

            /* Gossip to some unreachable member with some probability to check if he is back up */
            doGossipToUnreachableMember(message);

            /* Gossip to a seed if we did not do so above, or we have seen less nodes
               than there are seeds.  This prevents partitions where each group of nodes
               is only gossiping to a subset of the seeds.

               The most straightforward check would be to check that all the seeds have been
               verified either as live or unreachable.  To avoid that computation each round,
               we reason that:

               either all the live nodes are seeds, in which case non-seeds that come online
               will introduce themselves to a member of the ring by definition,

               or there is at least one non-seed node in the list, in which case eventually
               someone will gossip to it, and then do a gossip to a random seed from the
               gossipedToSeed check.

               See CASSANDRA-150 for more exposition. */
            if (!gossipedToSeed || liveEndpoints.size() < seeds.size())
                doGossipToSeed(message);

            doStatusCheck();
        }
    }
    catch (Exception e)
    {
        JVMStabilityInspector.inspectThrowable(e);
        logger.error("Gossip error", e);
    }
    finally
    {
        taskLock.unlock();
    }
}
 
Example 8
Source File: CassandraServer.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public String describe_cluster_name() throws TException
{
    return DatabaseDescriptor.getClusterName();
}