Java Code Examples for org.apache.cassandra.config.DatabaseDescriptor

The following examples show how to use org.apache.cassandra.config.DatabaseDescriptor. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public Optional<EndpointMetadata> endpointMetadata(final InetAddress endpoint) {
    final IEndpointSnitch endpointSnitch = DatabaseDescriptor.getEndpointSnitch();

    return Optional.of(new EndpointMetadata() {
        @Override
        public String dataCenter() {
            return endpointSnitch.getDatacenter(endpoint);
        }

        @Override
        public String rack() {
            return endpointSnitch.getRack(endpoint);
        }
    });
}
 
Example 2
Source Project: stratio-cassandra   Source File: StorageProxy.java    License: Apache License 2.0 6 votes vote down vote up
public final void run()
{

    if (TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - constructionTime) > DatabaseDescriptor.getTimeout(verb))
    {
        MessagingService.instance().incrementDroppedMessages(verb);
        return;
    }
    try
    {
        runMayThrow();
    } catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source Project: stratio-cassandra   Source File: CommitLogSegmentManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Indicates that a segment file should be deleted.
 *
 * @param segment segment to be discarded
 */
private void discardSegment(final CommitLogSegment segment, final boolean deleteFile)
{
    logger.debug("Segment {} is no longer active and will be deleted {}", segment, deleteFile ? "now" : "by the archive script");
    size.addAndGet(-DatabaseDescriptor.getCommitLogSegmentSize());

    segmentManagementTasks.add(new Callable<CommitLogSegment>()
    {
        public CommitLogSegment call()
        {
            segment.close();
            if (deleteFile)
                segment.delete();
            return null;
        }
    });
}
 
Example 4
Source Project: debezium-incubator   Source File: QueueProcessorTest.java    License: 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 5
Source Project: stratio-cassandra   Source File: IndexSummaryTest.java    License: Apache License 2.0 6 votes vote down vote up
private Pair<List<DecoratedKey>, IndexSummary> generateRandomIndex(int size, int interval)
{
    List<DecoratedKey> list = Lists.newArrayList();
    try (IndexSummaryBuilder builder = new IndexSummaryBuilder(list.size(), interval, BASE_SAMPLING_LEVEL))
    {
        for (int i = 0; i < size; i++)
        {
            UUID uuid = UUID.randomUUID();
            DecoratedKey key = DatabaseDescriptor.getPartitioner().decorateKey(ByteBufferUtil.bytes(uuid));
            list.add(key);
        }
        Collections.sort(list);
        for (int i = 0; i < size; i++)
            builder.maybeAddEntry(list.get(i), i);
        IndexSummary summary = builder.build(DatabaseDescriptor.getPartitioner());
        return Pair.create(list, summary);
    }
}
 
Example 6
Source Project: sasi   Source File: TermIterator.java    License: Apache License 2.0 6 votes vote down vote up
public ExecutorService initialValue()
{
    final String currentThread = Thread.currentThread().getName();
    final int concurrencyFactor = DatabaseDescriptor.searchConcurrencyFactor();

    logger.info("Search Concurrency Factor is set to {} for {}", concurrencyFactor, currentThread);

    return (concurrencyFactor <= 1)
            ? MoreExecutors.sameThreadExecutor()
            : Executors.newFixedThreadPool(concurrencyFactor, new ThreadFactory()
    {
        public final AtomicInteger count = new AtomicInteger();

        @Override
        public Thread newThread(Runnable task)
        {
            return new Thread(task, currentThread + "-SEARCH-" + count.incrementAndGet()) {{ setDaemon(true); }};
        }
    });
}
 
Example 7
Source Project: coming   Source File: 986499_AddColumnFamily_0_s.java    License: MIT License 6 votes vote down vote up
public void applyModels() throws IOException
{
    KSMetaData ksm = DatabaseDescriptor.getTableDefinition(cfm.tableName);
    ksm = makeNewKeyspaceDefinition(ksm);
    try
    {
        CFMetaData.map(cfm);
    }
    catch (ConfigurationException ex)
    {
        throw new IOException(ex);
    }
    Table.open(cfm.tableName); // make sure it's init-ed w/ the old definitions first, since we're going to call initCf on the new one manually
    DatabaseDescriptor.setTableDefinition(ksm, newVersion);
    if (!clientMode)
        Table.open(ksm.name).initCf(cfm.cfId, cfm.cfName);
 
    if (!clientMode)
        CommitLog.instance().forceNewSegment();
}
 
Example 8
Source Project: coming   Source File: 986499_AddColumnFamily_0_s.java    License: MIT License 6 votes vote down vote up
public AddColumnFamily(CFMetaData cfm) throws ConfigurationException, IOException
{
    super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getLocalAddress()), DatabaseDescriptor.getDefsVersion());
    this.cfm = cfm;
    KSMetaData ksm = DatabaseDescriptor.getTableDefinition(cfm.tableName);
    
    if (ksm == null)
        throw new ConfigurationException("Keyspace does not already exist.");
    else if (ksm.cfMetaData().containsKey(cfm.cfName))
        throw new ConfigurationException("CF is already defined in that keyspace.");
    else if (!Migration.isLegalName(cfm.cfName))
        throw new ConfigurationException("Invalid column family name: " + cfm.cfName);
    
    KSMetaData newKsm = makeNewKeyspaceDefinition(ksm);
    
    rm = Migration.makeDefinitionMutation(newKsm, null, newVersion);
}
 
Example 9
Source Project: coming   Source File: 986499_AddColumnFamily_0_s.java    License: MIT License 6 votes vote down vote up
public void applyModels() throws IOException
{
    KSMetaData ksm = DatabaseDescriptor.getTableDefinition(cfm.tableName);
    ksm = makeNewKeyspaceDefinition(ksm);
    try
    {
        CFMetaData.map(cfm);
    }
    catch (ConfigurationException ex)
    {
        throw new IOException(ex);
    }
    Table.open(cfm.tableName); 
    DatabaseDescriptor.setTableDefinition(ksm, newVersion);
    if (!clientMode)
        Table.open(ksm.name).initCf(cfm.cfId, cfm.cfName);
 
    if (!clientMode)
        CommitLog.instance().forceNewSegment();
}
 
Example 10
Source Project: coming   Source File: 986499_AddColumnFamily_0_t.java    License: MIT License 6 votes vote down vote up
public void applyModels() throws IOException
{
    KSMetaData ksm = DatabaseDescriptor.getTableDefinition(cfm.tableName);
    ksm = makeNewKeyspaceDefinition(ksm);
    try
    {
        CFMetaData.map(cfm);
    }
    catch (ConfigurationException ex)
    {
        throw new IOException(ex);
    }
    Table.open(cfm.tableName); 
    DatabaseDescriptor.setTableDefinition(ksm, newVersion);
   CFMetaData.fixMaxId();
    if (!clientMode)
        Table.open(ksm.name).initCf(cfm.cfId, cfm.cfName);
 
    if (!clientMode)
        CommitLog.instance().forceNewSegment();
}
 
Example 11
Source Project: coming   Source File: 986499_AddColumnFamily_0_s.java    License: MIT License 6 votes vote down vote up
public AddColumnFamily(CFMetaData cfm) throws ConfigurationException, IOException
{
    super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getLocalAddress()), DatabaseDescriptor.getDefsVersion());
    this.cfm = cfm;
    KSMetaData ksm = DatabaseDescriptor.getTableDefinition(cfm.tableName);
    
    if (ksm == null)
        throw new ConfigurationException("Keyspace does not already exist.");
    else if (ksm.cfMetaData().containsKey(cfm.cfName))
        throw new ConfigurationException("CF is already defined in that keyspace.");
    else if (!Migration.isLegalName(cfm.cfName))
        throw new ConfigurationException("Invalid column family name: " + cfm.cfName);
    
    KSMetaData newKsm = makeNewKeyspaceDefinition(ksm);
    
    rm = Migration.makeDefinitionMutation(newKsm, null, newVersion);
}
 
Example 12
Source Project: coming   Source File: 986499_AddColumnFamily_0_t.java    License: MIT License 6 votes vote down vote up
public AddColumnFamily(CFMetaData cfm) throws ConfigurationException, IOException
{
    super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getLocalAddress()), DatabaseDescriptor.getDefsVersion());
    this.cfm = cfm;
    KSMetaData ksm = DatabaseDescriptor.getTableDefinition(cfm.tableName);
    
    if (ksm == null)
        throw new ConfigurationException("Keyspace does not already exist.");
    else if (ksm.cfMetaData().containsKey(cfm.cfName))
        throw new ConfigurationException("CF is already defined in that keyspace.");
    else if (!Migration.isLegalName(cfm.cfName))
        throw new ConfigurationException("Invalid column family name: " + cfm.cfName);
    
    KSMetaData newKsm = makeNewKeyspaceDefinition(ksm);
    
    rm = Migration.makeDefinitionMutation(newKsm, null, newVersion);
}
 
Example 13
Source Project: stratio-cassandra   Source File: AlterUserStatement.java    License: Apache License 2.0 6 votes vote down vote up
public void checkAccess(ClientState state) throws UnauthorizedException
{
    AuthenticatedUser user = state.getUser();

    boolean isSuper = user.isSuper();

    if (superuser != null && user.getName().equals(username))
        throw new UnauthorizedException("You aren't allowed to alter your own superuser status");

    if (superuser != null && !isSuper)
        throw new UnauthorizedException("Only superusers are allowed to alter superuser status");

    if (!user.isSuper() && !user.getName().equals(username))
        throw new UnauthorizedException("You aren't allowed to alter this user");

    if (!isSuper)
    {
        for (IAuthenticator.Option option : opts.getOptions().keySet())
        {
            if (!DatabaseDescriptor.getAuthenticator().alterableOptions().contains(option))
                throw new UnauthorizedException(String.format("You aren't allowed to alter %s option", option));
        }
    }
}
 
Example 14
Source Project: stratio-cassandra   Source File: StorageProxy.java    License: Apache License 2.0 6 votes vote down vote up
public final void run()
{
    if (System.currentTimeMillis() > constructionTime + DatabaseDescriptor.getTimeout(MessagingService.Verb.MUTATION))
    {
        MessagingService.instance().incrementDroppedMessages(MessagingService.Verb.MUTATION);
        HintRunnable runnable = new HintRunnable(FBUtilities.getBroadcastAddress())
        {
            protected void runMayThrow() throws Exception
            {
                LocalMutationRunnable.this.runMayThrow();
            }
        };
        submitHint(runnable);
        return;
    }

    try
    {
        runMayThrow();
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 15
Source Project: stratio-cassandra   Source File: CommitLogSegmentManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Differs from the above because it can work on any file instead of just existing
 * commit log segments managed by this manager.
 *
 * @param file segment file that is no longer in use.
 */
void recycleSegment(final File file)
{
    if (isCapExceeded()
        || CommitLogDescriptor.fromFileName(file.getName()).getMessagingVersion() != MessagingService.current_version)
    {
        // (don't decrease managed size, since this was never a "live" segment)
        logger.debug("(Unopened) segment {} is no longer needed and will be deleted now", file);
        FileUtils.deleteWithConfirm(file);
        return;
    }

    logger.debug("Recycling {}", file);
    // this wasn't previously a live segment, so add it to the managed size when we make it live
    size.addAndGet(DatabaseDescriptor.getCommitLogSegmentSize());
    segmentManagementTasks.add(new Callable<CommitLogSegment>()
    {
        public CommitLogSegment call()
        {
            return new CommitLogSegment(file.getPath());
        }
    });
}
 
Example 16
Source Project: stratio-cassandra   Source File: StorageProxy.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean shouldHint(InetAddress ep)
{
    if (DatabaseDescriptor.shouldHintByDC())
    {
        final String dc = DatabaseDescriptor.getEndpointSnitch().getDatacenter(ep);
        //Disable DC specific hints
        if(!DatabaseDescriptor.hintedHandoffEnabled(dc))
        {
            HintedHandOffManager.instance.metrics.incrPastWindow(ep);
            return false;
        }
    }
    else if (!DatabaseDescriptor.hintedHandoffEnabled())
    {
        HintedHandOffManager.instance.metrics.incrPastWindow(ep);
        return false;
    }

    boolean hintWindowExpired = Gossiper.instance.getEndpointDowntime(ep) > DatabaseDescriptor.getMaxHintWindow();
    if (hintWindowExpired)
    {
        HintedHandOffManager.instance.metrics.incrPastWindow(ep);
        Tracing.trace("Not hinting {} which has been down {}ms", ep, Gossiper.instance.getEndpointDowntime(ep));
    }
    return !hintWindowExpired;
}
 
Example 17
Source Project: stratio-cassandra   Source File: RangeStreamer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get a map of all ranges and their respective sources that are candidates for streaming the given ranges
 * to us. For each range, the list of sources is sorted by proximity relative to the given destAddress.
 */
private Multimap<Range<Token>, InetAddress> getAllRangesWithSourcesFor(String keyspaceName, Collection<Range<Token>> desiredRanges)
{
    AbstractReplicationStrategy strat = Keyspace.open(keyspaceName).getReplicationStrategy();
    Multimap<Range<Token>, InetAddress> rangeAddresses = strat.getRangeAddresses(metadata.cloneOnlyTokenMap());

    Multimap<Range<Token>, InetAddress> rangeSources = ArrayListMultimap.create();
    for (Range<Token> desiredRange : desiredRanges)
    {
        for (Range<Token> range : rangeAddresses.keySet())
        {
            if (range.contains(desiredRange))
            {
                List<InetAddress> preferred = DatabaseDescriptor.getEndpointSnitch().getSortedListByProximity(address, rangeAddresses.get(range));
                rangeSources.putAll(desiredRange, preferred);
                break;
            }
        }

        if (!rangeSources.keySet().contains(desiredRange))
            throw new IllegalStateException("No sources found for " + desiredRange);
    }

    return rangeSources;
}
 
Example 18
public static Socket newSocket(InetAddress endpoint) throws IOException
{
    // zero means 'bind on any available port.'
    if (isEncryptedChannel(endpoint))
    {
        if (Config.getOutboundBindAny())
            return SSLFactory.getSocket(DatabaseDescriptor.getServerEncryptionOptions(), endpoint, DatabaseDescriptor.getSSLStoragePort());
        else
            return SSLFactory.getSocket(DatabaseDescriptor.getServerEncryptionOptions(), endpoint, DatabaseDescriptor.getSSLStoragePort(), FBUtilities.getLocalAddress(), 0);
    }
    else
    {
        Socket socket = SocketChannel.open(new InetSocketAddress(endpoint, DatabaseDescriptor.getStoragePort())).socket();
        if (Config.getOutboundBindAny() && !socket.isBound())
            socket.bind(new InetSocketAddress(FBUtilities.getLocalAddress(), 0));
        return socket;
    }
}
 
Example 19
Source Project: stratio-cassandra   Source File: CommitLogTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCommitFailurePolicy_die()
{
    KillerForTests killerForTests = new KillerForTests();
    JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
    Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
    try
    {
        DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.die);
        CommitLog.handleCommitError("Testing die policy", new Throwable());
        Assert.assertTrue(killerForTests.wasKilled());
    }
    finally
    {
        DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
        JVMStabilityInspector.replaceKiller(originalKiller);
    }
}
 
Example 20
Source Project: stratio-cassandra   Source File: BatchTests.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass()
public static void setup() throws ConfigurationException, IOException
{
    cassandra = new EmbeddedCassandraService();
    cassandra.start();

    cluster = Cluster.builder().addContactPoint("127.0.0.1").withPort(DatabaseDescriptor.getNativeTransportPort()).build();
    session = cluster.connect();

    session.execute("drop keyspace if exists junit;");
    session.execute("create keyspace junit WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };");
    session.execute("CREATE TABLE junit.noncounter (\n" +
            "  id int PRIMARY KEY,\n" +
            "  val text\n" +
            ");");
    session.execute("CREATE TABLE junit.counter (\n" +
            "  id int PRIMARY KEY,\n" +
            "  val counter,\n" +
            ");");


    noncounter = session.prepare("insert into junit.noncounter(id, val)values(?,?)");
    counter = session.prepare("update junit.counter set val = val + ? where id = ?");
}
 
Example 21
Source Project: stratio-cassandra   Source File: FileUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void handleFSError(FSError e)
{
    JVMStabilityInspector.inspectThrowable(e);
    switch (DatabaseDescriptor.getDiskFailurePolicy())
    {
        case stop_paranoid:
        case stop:
            StorageService.instance.stopTransports();
            break;
        case best_effort:
            // for both read and write errors mark the path as unwritable.
            BlacklistedDirectories.maybeMarkUnwritable(e.path);
            if (e instanceof FSReadError)
            {
                File directory = BlacklistedDirectories.maybeMarkUnreadable(e.path);
                if (directory != null)
                    Keyspace.removeUnreadableSSTables(directory);
            }
            break;
        case ignore:
            // already logged, so left nothing to do
            break;
        default:
            throw new IllegalStateException();
    }
}
 
Example 22
/**
 * Handle a valid event resulted from a row-level modification by converting Cassandra representation of
 * this event into a {@link Record} object and queue the record to {@link ChangeEventQueue}. A valid event
 * implies this must be an insert, update, or delete.
 *
 * The steps are:
 *      (1) Populate the "source" field for this event
 *      (2) Fetch the cached key/value schemas from {@link SchemaHolder}
 *      (3) Populate the "after" field for this event
 *          a. populate partition columns
 *          b. populate clustering columns
 *          c. populate regular columns
 *          d. for deletions, populate regular columns with null values
 *      (4) Assemble a {@link Record} object from the populated data and queue the record
 */
private void handleRowModifications(Row row, RowType rowType, PartitionUpdate pu, OffsetPosition offsetPosition, KeyspaceTable keyspaceTable) {

    SchemaHolder.KeyValueSchema schema = schemaHolder.getOrUpdateKeyValueSchema(keyspaceTable);
    Schema keySchema = schema.keySchema();
    Schema valueSchema = schema.valueSchema();

    RowData after = new RowData();
    populatePartitionColumns(after, pu);
    populateClusteringColumns(after, row, pu);
    populateRegularColumns(after, row, rowType, schema);

    long ts = rowType == DELETE ? row.deletion().time().markedForDeleteAt() : pu.maxTimestamp();

    switch (rowType) {
        case INSERT:
            recordMaker.insert(DatabaseDescriptor.getClusterName(), offsetPosition, keyspaceTable, false,
                    Conversions.toInstantFromMicros(ts), after, keySchema, valueSchema, MARK_OFFSET, queue::enqueue);
            break;

        case UPDATE:
            recordMaker.update(DatabaseDescriptor.getClusterName(), offsetPosition, keyspaceTable, false,
                    Conversions.toInstantFromMicros(ts), after, keySchema, valueSchema, MARK_OFFSET, queue::enqueue);
            break;

        case DELETE:
            recordMaker.delete(DatabaseDescriptor.getClusterName(), offsetPosition, keyspaceTable, false,
                    Conversions.toInstantFromMicros(ts), after, keySchema, valueSchema, MARK_OFFSET, queue::enqueue);
            break;

        default:
            throw new CassandraConnectorTaskException("Unsupported row type " + rowType + " should have been skipped");
    }
}
 
Example 23
Source Project: stratio-cassandra   Source File: THsHaDisruptorServer.java    License: Apache License 2.0 5 votes vote down vote up
public TServer buildTServer(Args args)
{
    if (DatabaseDescriptor.getClientEncryptionOptions().enabled)
        throw new RuntimeException("Client SSL is not supported for non-blocking sockets (hsha). Please remove client ssl from the configuration.");

    final InetSocketAddress addr = args.addr;
    TNonblockingServerTransport serverTransport;
    try
    {
        serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize);
    }
    catch (TTransportException e)
    {
        throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e);
    }

    ThreadPoolExecutor invoker = new JMXEnabledThreadPoolExecutor(DatabaseDescriptor.getRpcMinThreads(),
                                                                  DatabaseDescriptor.getRpcMaxThreads(),
                                                                  60L,
                                                                  TimeUnit.SECONDS,
                                                                  new SynchronousQueue<Runnable>(),
                                                                  new NamedThreadFactory("RPC-Thread"), "RPC-THREAD-POOL");

    com.thinkaurelius.thrift.util.TBinaryProtocol.Factory protocolFactory = new com.thinkaurelius.thrift.util.TBinaryProtocol.Factory(true, true);

    TDisruptorServer.Args serverArgs = new TDisruptorServer.Args(serverTransport).useHeapBasedAllocation(true)
                                                                                 .inputTransportFactory(args.inTransportFactory)
                                                                                 .outputTransportFactory(args.outTransportFactory)
                                                                                 .inputProtocolFactory(protocolFactory)
                                                                                 .outputProtocolFactory(protocolFactory)
                                                                                 .processor(args.processor)
                                                                                 .maxFrameSizeInBytes(DatabaseDescriptor.getThriftFramedTransportSize())
                                                                                 .invocationExecutor(invoker)
                                                                                 .alwaysReallocateBuffers(true);

    return new THsHaDisruptorServer(serverArgs);
}
 
Example 24
Source Project: stratio-cassandra   Source File: CompactionManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets compaction rate limiter. When compaction_throughput_mb_per_sec is 0 or node is bootstrapping,
 * this returns rate limiter with the rate of Double.MAX_VALUE bytes per second.
 * Rate unit is bytes per sec.
 *
 * @return RateLimiter with rate limit set
 */
public RateLimiter getRateLimiter()
{
    double currentThroughput = DatabaseDescriptor.getCompactionThroughputMbPerSec() * 1024.0 * 1024.0;
    // if throughput is set to 0, throttling is disabled
    if (currentThroughput == 0 || StorageService.instance.isBootstrapMode())
        currentThroughput = Double.MAX_VALUE;
    if (compactionRateLimiter.getRate() != currentThroughput)
        compactionRateLimiter.setRate(currentThroughput);
    return compactionRateLimiter;
}
 
Example 25
Source Project: stratio-cassandra   Source File: OutboundTcpConnection.java    License: Apache License 2.0 5 votes vote down vote up
private static CoalescingStrategy newCoalescingStrategy(String displayName)
{
    return CoalescingStrategies.newCoalescingStrategy(DatabaseDescriptor.getOtcCoalescingStrategy(),
                                                      DatabaseDescriptor.getOtcCoalescingWindow(),
                                                      logger,
                                                      displayName);
}
 
Example 26
/**
 * Gets a connection to the localhost client
 *
 * @return
 * @throws TTransportException
 */
private Cassandra.Client getClient() throws TTransportException
{
    TTransport tr = new TFramedTransport(new TSocket("localhost", DatabaseDescriptor.getRpcPort()));
    TProtocol proto = new TBinaryProtocol(tr);
    Cassandra.Client client = new Cassandra.Client(proto);
    tr.open();
    return client;
}
 
Example 27
Source Project: stratio-cassandra   Source File: StreamSession.java    License: Apache License 2.0 5 votes vote down vote up
public void doRetry(FileMessageHeader header, Throwable e)
{
    logger.warn("[Stream #{}] Retrying for following error", planId(), e);
    // retry
    retries++;
    if (retries > DatabaseDescriptor.getMaxStreamingRetries())
        onError(new IOException("Too many retries for " + header, e));
    else
        handler.sendMessage(new RetryMessage(header.cfId, header.sequenceNumber));
}
 
Example 28
Source Project: stratio-cassandra   Source File: SystemKeyspace.java    License: 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 29
Source Project: stratio-cassandra   Source File: StorageService.java    License: 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 30
Source Project: stratio-cassandra   Source File: Gossiper.java    License: 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);
    }
}