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

The following are top voted examples for showing how to use org.apache.cassandra.config.DatabaseDescriptor. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ACaZoo   File: BulkLoader.java   Source Code and License 7 votes vote down vote up
public static void main(String args[])
{
    LoaderOptions options = LoaderOptions.parseArgs(args);
    OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);
    SSTableLoader loader = new SSTableLoader(options.directory, new ExternalClient(options.hosts, options.rpcPort, options.user, options.passwd), handler);
    DatabaseDescriptor.setStreamThroughputOutboundMegabitsPerSec(options.throttle);
    StreamResultFuture future = loader.stream(options.ignores);
    future.addEventListener(new ProgressIndicator());
    try
    {
        future.get();
        System.exit(0); // We need that to stop non daemonized threads
    }
    catch (Exception e)
    {
        System.err.println("Streaming to the following hosts failed:");
        System.err.println(loader.getFailedHosts());
        System.err.println(e);
        if (options.debug)
            e.printStackTrace(System.err);
        System.exit(1);
    }
}
 
Example 2
Project: sstable-adaptor   File: JVMStabilityInspector.java   Source Code and License 6 votes vote down vote up
/**
 * Certain Throwables and Exceptions represent "Die" conditions for the server.
 * This recursively checks the input Throwable's cause hierarchy until null.
 * @param t
 *      The Throwable to check for server-stop conditions
 */
public static void inspectThrowable(Throwable t)
{
    boolean isUnstable = false;
    if (t instanceof OutOfMemoryError)
    {
        isUnstable = true;
        HeapUtils.generateHeapDump();
    }

    if (DatabaseDescriptor.getDiskFailurePolicy() == Config.DiskFailurePolicy.die)
        if (t instanceof FSError || t instanceof CorruptSSTableException)
        isUnstable = true;

    // Check for file handle exhaustion
    if (t instanceof FileNotFoundException || t instanceof SocketException)
        if (t.getMessage().contains("Too many open files"))
            isUnstable = true;

    if (isUnstable)
        killer.killCurrentJVM(t);

    if (t.getCause() != null)
        inspectThrowable(t.getCause());
}
 
Example 3
Project: brave-cassandra   File: CassandraRule.java   Source Code and License 6 votes vote down vote up
@Override protected void before() throws Throwable {
  if (server != null) return;

  DatabaseDescriptor.daemonInitialization();

  // Cleanup first
  try {
    cleanupAndLeaveDirs();
  } catch (IOException e) {
    throw new RuntimeException("Failed to cleanup and recreate directories.", e);
  }

  Keyspace.setInitialized();
  SystemKeyspace.persistLocalMetadata();
  SystemKeyspace.finishStartup();
  StorageService.instance.initServer();

  server = new Server.Builder().withHost(nativeAddr).withPort(nativePort).build();
  server.start();
}
 
Example 4
Project: scylla-tools-java   File: FileMessageHeader.java   Source Code and License 6 votes vote down vote up
public FileMessageHeader deserialize(DataInputPlus in, int version) throws IOException
{
    UUID cfId = UUIDSerializer.serializer.deserialize(in, MessagingService.current_version);
    int sequenceNumber = in.readInt();
    Version sstableVersion = DatabaseDescriptor.getSSTableFormat().info.getVersion(in.readUTF());

    SSTableFormat.Type format = SSTableFormat.Type.LEGACY;
    if (version >= StreamMessage.VERSION_22)
        format = SSTableFormat.Type.validate(in.readUTF());

    long estimatedKeys = in.readLong();
    int count = in.readInt();
    List<Pair<Long, Long>> sections = new ArrayList<>(count);
    for (int k = 0; k < count; k++)
        sections.add(Pair.create(in.readLong(), in.readLong()));
    CompressionInfo compressionInfo = CompressionInfo.serializer.deserialize(in, MessagingService.current_version);
    long repairedAt = in.readLong();
    int sstableLevel = in.readInt();
    SerializationHeader.Component header = version >= StreamMessage.VERSION_30 && sstableVersion.storeRows()
                                         ? SerializationHeader.serializer.deserialize(sstableVersion, in)
                                         : null;

    return new FileMessageHeader(cfId, sequenceNumber, sstableVersion, format, estimatedKeys, sections, compressionInfo, repairedAt, sstableLevel, header);
}
 
Example 5
Project: scylla-tools-java   File: CommitLogFailurePolicyTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCommitFailurePolicy_stop() throws ConfigurationException
{
    CassandraDaemon daemon = new CassandraDaemon();
    daemon.completeSetup(); //startup must be completed, otherwise commit log failure must kill JVM regardless of failure policy
    StorageService.instance.registerDaemon(daemon);

    // Need storage service active so stop policy can shutdown gossip
    StorageService.instance.initServer();
    Assert.assertTrue(Gossiper.instance.isEnabled());

    Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
    try
    {
        DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.stop);
        CommitLog.handleCommitError("Test stop error", new Throwable());
        Assert.assertFalse(Gossiper.instance.isEnabled());
    }
    finally
    {
        DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
    }
}
 
Example 6
Project: scylla-tools-java   File: StorageService.java   Source Code and License 6 votes vote down vote up
/**
 * Remove the snapshot with the given name from the given keyspaces.
 * If no tag is specified we will remove all snapshots.
 */
public void clearSnapshot(String tag, String... keyspaceNames) throws IOException
{
    if(tag == null)
        tag = "";

    Set<String> keyspaces = new HashSet<>();
    for (String dataDir : DatabaseDescriptor.getAllDataFileLocations())
    {
        for(String keyspaceDir : new File(dataDir).list())
        {
            // Only add a ks if it has been specified as a param, assuming params were actually provided.
            if (keyspaceNames.length > 0 && !Arrays.asList(keyspaceNames).contains(keyspaceDir))
                continue;
            keyspaces.add(keyspaceDir);
        }
    }

    for (String keyspace : keyspaces)
        Keyspace.clearSnapshot(tag, keyspace);

    if (logger.isDebugEnabled())
        logger.debug("Cleared out snapshot directories");
}
 
Example 7
Project: cassandra-kmean   File: CommitLog.java   Source Code and License 6 votes vote down vote up
private CommitLog()
{
    DatabaseDescriptor.createAllDirectories();

    allocator = new CommitLogSegmentManager();

    executor = DatabaseDescriptor.getCommitLogSync() == Config.CommitLogSync.batch
             ? new BatchCommitLogService(this)
             : new PeriodicCommitLogService(this);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try
    {
        mbs.registerMBean(this, new ObjectName("org.apache.cassandra.db:type=Commitlog"));
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }

    // register metrics
    metrics = new CommitLogMetrics(executor, allocator);
}
 
Example 8
Project: scylla-tools-java   File: Util.java   Source Code and License 6 votes vote down vote up
/**
 * This is used by standalone tools to force static initialization of DatabaseDescriptor, and fail if configuration
 * is bad.
 */
public static void initDatabaseDescriptor()
{
    try
    {
        DatabaseDescriptor.forceStaticInitialization();
    }
    catch (ExceptionInInitializerError e)
    {
        Throwable cause = e.getCause();
        boolean logStackTrace = !(cause instanceof ConfigurationException) || ((ConfigurationException) cause).logStackTrace;
        System.out.println("Exception (" + cause.getClass().getName() + ") encountered during startup: " + cause.getMessage());

        if (logStackTrace)
        {
            cause.printStackTrace();
            System.exit(3);
        }
        else
        {
            System.err.println(cause.getMessage());
            System.exit(3);
        }
    }
}
 
Example 9
Project: scylla-tools-java   File: OutOfSpaceTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testFlushUnwriteableDie() throws Throwable
{
    makeTable();

    KillerForTests killerForTests = new KillerForTests();
    JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
    DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
    try (Closeable c = Util.markDirectoriesUnwriteable(getCurrentColumnFamilyStore()))
    {
        DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.die);
        flushAndExpectError();
        Assert.assertTrue(killerForTests.wasKilled());
        Assert.assertFalse(killerForTests.wasKilledQuietly()); //only killed quietly on startup failure
    }
    finally
    {
        DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
        JVMStabilityInspector.replaceKiller(originalKiller);
    }
}
 
Example 10
Project: scylla-tools-java   File: Server.java   Source Code and License 6 votes vote down vote up
private void send(InetAddress endpoint, Event.NodeEvent event)
{
    if (logger.isTraceEnabled())
        logger.trace("Sending event for endpoint {}, rpc address {}", endpoint, event.nodeAddress());

    // If the endpoint is not the local node, extract the node address
    // and if it is the same as our own RPC broadcast address (which defaults to the rcp address)
    // then don't send the notification. This covers the case of rpc_address set to "localhost",
    // which is not useful to any driver and in fact may cauase serious problems to some drivers,
    // see CASSANDRA-10052
    if (!endpoint.equals(FBUtilities.getBroadcastAddress()) &&
        event.nodeAddress().equals(DatabaseDescriptor.getBroadcastRpcAddress()))
        return;

    send(event);
}
 
Example 11
Project: ACaZoo   File: StorageService.java   Source Code and License 6 votes vote down vote up
private void bootstrap(Collection<Token> tokens)
{
    isBootstrapMode = true;
    SystemKeyspace.updateTokens(tokens); // DON'T use setToken, that makes us part of the ring locally which is incorrect until we are done bootstrapping
    if (!DatabaseDescriptor.isReplacing())
    {
        // if not an existing token then bootstrap
        // order is important here, the gossiper can fire in between adding these two states.  It's ok to send TOKENS without STATUS, but *not* vice versa.
        Gossiper.instance.addLocalApplicationState(ApplicationState.TOKENS, valueFactory.tokens(tokens));
        Gossiper.instance.addLocalApplicationState(ApplicationState.STATUS,
                                                   valueFactory.bootstrapping(tokens));
        setMode(Mode.JOINING, "sleeping " + RING_DELAY + " ms for pending range setup", true);
        Uninterruptibles.sleepUninterruptibly(RING_DELAY, TimeUnit.MILLISECONDS);
    }
    else
    {
        // Dont set any state for the node which is bootstrapping the existing token...
        tokenMetadata.updateNormalTokens(tokens, FBUtilities.getBroadcastAddress());
    }
    if (!Gossiper.instance.seenAnySeed())
        throw new IllegalStateException("Unable to contact any seeds!");
    setMode(Mode.JOINING, "Starting to bootstrap...", true);
    new BootStrapper(FBUtilities.getBroadcastAddress(), tokens, tokenMetadata).bootstrap(); // handles token update
    logger.info("Bootstrap completed! for the tokens {}", tokens);
}
 
Example 12
Project: cassandra-kmean   File: OutboundTcpConnectionPool.java   Source Code and License 6 votes vote down vote up
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 13
Project: cassandra-kmean   File: CommitLog.java   Source Code and License 6 votes vote down vote up
@VisibleForTesting
public static boolean handleCommitError(String message, Throwable t)
{
    JVMStabilityInspector.inspectCommitLogThrowable(t);
    switch (DatabaseDescriptor.getCommitFailurePolicy())
    {
        // Needed here for unit tests to not fail on default assertion
        case die:
        case stop:
            StorageService.instance.stopTransports();
        case stop_commit:
            logger.error(String.format("%s. Commit disk failure policy is %s; terminating thread", message, DatabaseDescriptor.getCommitFailurePolicy()), t);
            return false;
        case ignore:
            logger.error(message, t);
            return true;
        default:
            throw new AssertionError(DatabaseDescriptor.getCommitFailurePolicy());
    }
}
 
Example 14
Project: cassandra-kmean   File: StorageServiceServerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testRegularMode() throws ConfigurationException
{
    SchemaLoader.mkdirs();
    SchemaLoader.cleanup();
    StorageService.instance.initServer(0);
    for (String path : DatabaseDescriptor.getAllDataFileLocations())
    {
        // verify that storage directories are there.
        assertTrue(new File(path).exists());
    }
    // a proper test would be to call decommission here, but decommission() mixes both shutdown and datatransfer
    // calls.  This test is only interested in the shutdown-related items which a properly handled by just
    // stopping the client.
    //StorageService.instance.decommission();
    StorageService.instance.stopClient();
}
 
Example 15
Project: cassandra-kmean   File: SSTableWriter.java   Source Code and License 6 votes vote down vote up
IndexWriter(long keyCount, final SequentialWriter dataFile)
{
    indexFile = SequentialWriter.open(new File(descriptor.filenameFor(Component.PRIMARY_INDEX)));
    builder = SegmentedFile.getBuilder(DatabaseDescriptor.getIndexAccessMode());
    summary = new IndexSummaryBuilder(keyCount, metadata.getMinIndexInterval(), Downsampling.BASE_SAMPLING_LEVEL);
    bf = FilterFactory.getFilter(keyCount, metadata.getBloomFilterFpChance(), true);
    // register listeners to be alerted when the data files are flushed
    indexFile.setPostFlushListener(new Runnable()
    {
        public void run()
        {
            summary.markIndexSynced(indexFile.getLastFlushOffset());
        }
    });
    dataFile.setPostFlushListener(new Runnable()
    {
        public void run()
        {
            summary.markDataSynced(dataFile.getLastFlushOffset());
        }
    });
}
 
Example 16
Project: ACaZoo   File: AutoSavingCache.java   Source Code and License 6 votes vote down vote up
private void deleteOldCacheFiles()
{
    File savedCachesDir = new File(DatabaseDescriptor.getSavedCachesLocation());

    if (savedCachesDir.exists() && savedCachesDir.isDirectory())
    {
        for (File file : savedCachesDir.listFiles())
        {
            if (file.isFile() && file.getName().endsWith(cacheType.toString()))
            {
                if (!file.delete())
                    logger.warn("Failed to delete {}", file.getAbsolutePath());
            }

            if (file.isFile() && file.getName().endsWith(CURRENT_VERSION + ".db"))
            {
                if (!file.delete())
                    logger.warn("Failed to delete {}", file.getAbsolutePath());
            }
        }
    }
}
 
Example 17
Project: ACaZoo   File: TokenMetadata.java   Source Code and License 6 votes vote down vote up
/**
 * Stores current DC/rack assignment for ep
 */
protected void addEndpoint(InetAddress ep)
{
    IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
    String dc = snitch.getDatacenter(ep);
    String rack = snitch.getRack(ep);
    Pair<String, String> current = currentLocations.get(ep);
    if (current != null)
    {
        if (current.left.equals(dc) && current.right.equals(rack))
            return;
        dcRacks.get(current.left).remove(current.right, ep);
        dcEndpoints.remove(current.left, ep);
    }

    dcEndpoints.put(dc, ep);

    if (!dcRacks.containsKey(dc))
        dcRacks.put(dc, HashMultimap.<String, InetAddress>create());
    dcRacks.get(dc).put(rack, ep);

    currentLocations.put(ep, Pair.create(dc, rack));
}
 
Example 18
Project: ACaZoo   File: CreateKeyspaceStatement.java   Source Code and License 6 votes vote down vote up
/**
 * The <code>CqlParser</code> only goes as far as extracting the keyword arguments
 * from these statements, so this method is responsible for processing and
 * validating.
 *
 * @throws InvalidRequestException if arguments are missing or unacceptable
 */
public void validate(ClientState state) throws RequestValidationException
{
    ThriftValidation.validateKeyspaceNotSystem(name);

    // keyspace name
    if (!name.matches("\\w+"))
        throw new InvalidRequestException(String.format("\"%s\" is not a valid keyspace name", name));
    if (name.length() > Schema.NAME_LENGTH)
        throw new InvalidRequestException(String.format("Keyspace names shouldn't be more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, name));

    attrs.validate();

    if (attrs.getReplicationStrategyClass() == null)
        throw new ConfigurationException("Missing mandatory replication strategy class");

    // The strategy is validated through KSMetaData.validate() in announceNewKeyspace below.
    // However, for backward compatibility with thrift, this doesn't validate unexpected options yet,
    // so doing proper validation here.
    AbstractReplicationStrategy.validateReplicationStrategy(name,
                                                            AbstractReplicationStrategy.getClass(attrs.getReplicationStrategyClass()),
                                                            StorageService.instance.getTokenMetadata(),
                                                            DatabaseDescriptor.getEndpointSnitch(),
                                                            attrs.getReplicationOptions());
}
 
Example 19
Project: cassandra-kmean   File: IndexSummaryTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testSerialization() throws IOException
{
    Pair<List<DecoratedKey>, IndexSummary> random = generateRandomIndex(100, 1);
    DataOutputBuffer dos = new DataOutputBuffer();
    IndexSummary.serializer.serialize(random.right, dos, false);
    // write junk
    dos.writeUTF("JUNK");
    dos.writeUTF("JUNK");
    FileUtils.closeQuietly(dos);
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dos.toByteArray()));
    IndexSummary is = IndexSummary.serializer.deserialize(dis, DatabaseDescriptor.getPartitioner(), false, 1, 1);
    for (int i = 0; i < 100; i++)
        assertEquals(i, is.binarySearch(random.left.get(i)));
    // read the junk
    assertEquals(dis.readUTF(), "JUNK");
    assertEquals(dis.readUTF(), "JUNK");
    is.close();
    FileUtils.closeQuietly(dis);
}
 
Example 20
Project: cassandra-kmean   File: StorageProxy.java   Source Code and License 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 21
Project: sstable-adaptor   File: RowIndexEntry.java   Source Code and License 5 votes vote down vote up
public RowIndexEntry<IndexInfo> deserialize(DataInputPlus in, long indexFilePosition) throws IOException
{
    if (!version.storeRows())
        return LegacyShallowIndexedEntry.deserialize(in, indexFilePosition, idxInfoSerializer);

    long position = in.readUnsignedVInt();

    int size = (int)in.readUnsignedVInt();
    if (size == 0)
    {
        return new RowIndexEntry<>(position);
    }
    else
    {
        long headerLength = in.readUnsignedVInt();
        DeletionTime deletionTime = DeletionTime.serializer.deserialize(in);
        int columnsIndexCount = (int) in.readUnsignedVInt();

        int indexedPartSize = size - serializedSize(deletionTime, headerLength, columnsIndexCount);

        if (size <= DatabaseDescriptor.getColumnIndexCacheSize())
        {
            return new IndexedEntry(position, in, deletionTime, headerLength, columnsIndexCount,
                                    idxInfoSerializer, version, indexedPartSize);
        }
        else
        {
            in.skipBytes(indexedPartSize);

            return new ShallowIndexedEntry(position,
                                           indexFilePosition,
                                           deletionTime, headerLength, columnsIndexCount,
                                           indexedPartSize, idxInfoSerializer);
        }
    }
}
 
Example 22
Project: sstable-adaptor   File: ColumnIndex.java   Source Code and License 5 votes vote down vote up
public List<IndexInfo> indexSamples()
{
    if (indexSamplesSerializedSize + columnIndexCount * TypeSizes.sizeof(0) <= DatabaseDescriptor.getColumnIndexCacheSize())
    {
        return indexSamples;
    }

    return null;
}
 
Example 23
Project: sstable-adaptor   File: ColumnIndex.java   Source Code and License 5 votes vote down vote up
private DataOutputBuffer reuseOrAllocateBuffer()
{
    // Check whether a reusable DataOutputBuffer already exists for this
    // ColumnIndex instance and return it.
    if (reusableBuffer != null) {
        DataOutputBuffer buffer = reusableBuffer;
        buffer.clear();
        return buffer;
    }
    // don't use the standard RECYCLER as that only recycles up to 1MB and requires proper cleanup
    return new DataOutputBuffer(DatabaseDescriptor.getColumnIndexCacheSize() * 2);
}
 
Example 24
Project: sstable-adaptor   File: ColumnIndex.java   Source Code and License 5 votes vote down vote up
private void add(Unfiltered unfiltered) throws IOException
{
    long pos = currentPosition();

    if (firstClustering == null)
    {
        // Beginning of an index block. Remember the start and position
        firstClustering = unfiltered.clustering();
        startPosition = pos;
    }

    UnfilteredSerializer.serializer.serialize(unfiltered, header, writer, pos - previousRowStart, version);

    // notify observers about each new row
    if (!observers.isEmpty())
        observers.forEach((o) -> o.nextUnfilteredCluster(unfiltered));

    lastClustering = unfiltered.clustering();
    previousRowStart = pos;
    ++written;

    if (unfiltered.kind() == Unfiltered.Kind.RANGE_TOMBSTONE_MARKER)
    {
        RangeTombstoneMarker marker = (RangeTombstoneMarker) unfiltered;
        openMarker = marker.isOpen(false) ? marker.openDeletionTime(false) : null;
    }

    // if we hit the column index size that we have to index after, go ahead and index it.
    if (currentPosition() - startPosition >= DatabaseDescriptor.getColumnIndexSize())
        addIndexBlock();
}
 
Example 25
Project: sstable-adaptor   File: BigTableWriter.java   Source Code and License 5 votes vote down vote up
private void maybeLogLargePartitionWarning(DecoratedKey key, long rowSize)
{
    if (rowSize > DatabaseDescriptor.getCompactionLargePartitionWarningThreshold())
    {
        String keyString = metadata.getKeyValidator().getString(key.getKey());
        logger.warn("Writing large partition {}/{}:{} ({}) to sstable {}", metadata.ksName, metadata.cfName, keyString, FBUtilities.prettyPrintMemory(rowSize), getFilename());
    }
}
 
Example 26
Project: sstable-adaptor   File: SSTableWriter.java   Source Code and License 5 votes vote down vote up
protected SSTableWriter(Descriptor descriptor,
                        long keyCount,
                        long repairedAt,
                        CFMetaData metadata,
                        MetadataCollector metadataCollector,
                        SerializationHeader header)
{
    super(descriptor, components(metadata), metadata, DatabaseDescriptor.getDiskOptimizationStrategy());
    this.keyCount = keyCount;
    this.repairedAt = repairedAt;
    this.metadataCollector = metadataCollector;
    this.header = header != null ? header : SerializationHeader.makeWithoutStats(metadata); //null header indicates streaming from pre-3.0 sstable
    this.rowIndexEntrySerializer = descriptor.version.getSSTableFormat().getIndexSerializer(metadata, descriptor.version, header);
    this.observers = Collections.emptySet();
}
 
Example 27
Project: sstable-adaptor   File: SSTableReader.java   Source Code and License 5 votes vote down vote up
private static ScheduledThreadPoolExecutor initSyncExecutor()
{
    if (DatabaseDescriptor.isClientOrToolInitialized())
        return null;

    // Do NOT start this thread pool in client mode

    ScheduledThreadPoolExecutor syncExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("read-hotness-tracker"));
    // Immediately remove readMeter sync task when cancelled.
    syncExecutor.setRemoveOnCancelPolicy(true);
    return syncExecutor;
}
 
Example 28
Project: sstable-adaptor   File: SSTableReader.java   Source Code and License 5 votes vote down vote up
protected SSTableReader(final Descriptor desc,
                        Set<Component> components,
                        CFMetaData metadata,
                        long maxDataAge,
                        StatsMetadata sstableMetadata,
                        OpenReason openReason,
                        SerializationHeader header)
{
    super(desc, components, metadata, DatabaseDescriptor.getDiskOptimizationStrategy());
    this.sstableMetadata = sstableMetadata;
    this.header = header;
    this.maxDataAge = maxDataAge;
    this.openReason = openReason;
    this.rowIndexEntrySerializer = descriptor.version.getSSTableFormat().getIndexSerializer(metadata, desc.version, header);
}
 
Example 29
Project: xm-ms-timeline   File: CassandraTestConfiguration.java   Source Code and License 5 votes vote down vote up
/**
 * Override how to get the port to connect to the Cassandra cluster
 * When deployed, the port is read by properties
 * For the tests we need to read the port dynamically to discover on which random port Cassandra-unit has started the
 * embedded cluster
 * @param properties
 * @return
 */
@Override
protected int getPort(CassandraProperties properties) {
    int port = properties.getPort();
    if (port == 0) {
        // random port for the tests
        int randomPort = DatabaseDescriptor.getNativeTransportPort();
        log.info("Starting the cassandra cluster connection to a random port for the tests: {}", randomPort);
        return randomPort;
    } else {
        return port;
    }
}
 
Example 30
Project: brave-cassandra   File: CassandraRule.java   Source Code and License 5 votes vote down vote up
private static void cleanupAndLeaveDirs() throws IOException {
  CommitLog.instance.stopUnsafe(true);
  DatabaseDescriptor.createAllDirectories();
  cleanup();
  DatabaseDescriptor.createAllDirectories();
  CommitLog.instance.restartUnsafe();
}
 
Example 31
Project: reactor-spring5-example   File: CassandraSetup.java   Source Code and License 5 votes vote down vote up
/**
 * Creates the base storage directories required for running a Cassandra instance.
 */
private static void setupCassandraDirectories() throws IOException {
    final Path root = Files.createTempDirectory("cassandra");
    final Path config = root.resolve("cassandra.yaml");
    Files.copy(ReactorExampleApplication.class.getResourceAsStream("/cassandra.yaml"), config);
    System.setProperty("cassandra.config", "file:" + config.toString());
    System.setProperty("cassandra.storagedir", root.toString());
    System.setProperty("cassandra-foreground", "true");
    Stream.of(DatabaseDescriptor.getAllDataFileLocations())
        .map(root::resolve)
        .map(Path::toFile)
        .forEach(FileUtils::createDirectory);
}
 
Example 32
Project: cassandra-kmean   File: CounterMutationVerbHandler.java   Source Code and License 5 votes vote down vote up
public void doVerb(final MessageIn<CounterMutation> message, final int id)
{
    try
    {
        final CounterMutation cm = message.payload;
        logger.debug("Applying forwarded {}", cm);

        String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress());
        // We should not wait for the result of the write in this thread,
        // otherwise we could have a distributed deadlock between replicas
        // running this VerbHandler (see #4578).
        // Instead, we use a callback to send the response. Note that the callback
        // will not be called if the request timeout, but this is ok
        // because the coordinator of the counter mutation will timeout on
        // it's own in that case.
        StorageProxy.applyCounterMutationOnLeader(cm, localDataCenter, new Runnable()
        {
            public void run()
            {
                MessagingService.instance().sendReply(new WriteResponse().createMessage(), id, message.from);
            }
        });
    }
    catch (RequestExecutionException e)
    {
        // The coordinator will timeout on it's own so ignore
        logger.debug("counter error", e);
    }
}
 
Example 33
Project: cassandra-kmean   File: Gossiper.java   Source Code and License 5 votes vote down vote up
private void buildSeedsList()
{
    for (InetAddress seed : DatabaseDescriptor.getSeeds())
    {
        if (seed.equals(FBUtilities.getBroadcastAddress()))
            continue;
        seeds.add(seed);
    }
}
 
Example 34
Project: scylla-tools-java   File: CreateRoleStatement.java   Source Code and License 5 votes vote down vote up
public void validate(ClientState state) throws RequestValidationException
{
    opts.validate();

    if (role.getRoleName().isEmpty())
        throw new InvalidRequestException("Role name can't be an empty string");

    // validate login here before checkAccess to avoid leaking role existence to anonymous users.
    state.ensureNotAnonymous();

    if (!ifNotExists && DatabaseDescriptor.getRoleManager().isExistingRole(role))
        throw new InvalidRequestException(String.format("%s already exists", role.getRoleName()));
}
 
Example 35
Project: cassandra-kmean   File: ThriftClientState.java   Source Code and License 5 votes vote down vote up
public String getSchedulingValue()
{
    switch(DatabaseDescriptor.getRequestSchedulerId())
    {
        case keyspace: return getRawKeyspace();
    }
    return "default";
}
 
Example 36
Project: ACaZoo   File: EmbeddedCassandraServiceTest.java   Source Code and License 5 votes vote down vote up
/**
 * 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 37
Project: scylla-tools-java   File: CommitLogSegmentManager.java   Source Code and License 5 votes vote down vote up
private long unusedCapacity()
{
    long total = DatabaseDescriptor.getTotalCommitlogSpaceInMB() * 1024 * 1024;
    long currentSize = size.get();
    logger.trace("Total active commitlog segment space used is {} out of {}", currentSize, total);
    return total - currentSize;
}
 
Example 38
Project: ACaZoo   File: StorageService.java   Source Code and License 5 votes vote down vote up
/**
 * Return the rpc address associated with an endpoint as a string.
 * @param endpoint The endpoint to get rpc address for
 * @return the rpc address
 */
public String getRpcaddress(InetAddress endpoint)
{
    if (endpoint.equals(FBUtilities.getBroadcastAddress()))
        return DatabaseDescriptor.getRpcAddress().getHostAddress();
    else if (Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.RPC_ADDRESS) == null)
        return endpoint.getHostAddress();
    else
        return Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.RPC_ADDRESS).value;
}
 
Example 39
Project: scylla-tools-java   File: DefaultConnectionFactory.java   Source Code and License 5 votes vote down vote up
/**
 * Connect to peer and start exchanging message.
 * When connect attempt fails, this retries for maximum of MAX_CONNECT_ATTEMPTS times.
 *
 * @param peer the peer to connect to.
 * @return the created socket.
 *
 * @throws IOException when connection failed.
 */
public Socket createConnection(InetAddress peer) throws IOException
{
    int attempts = 0;
    while (true)
    {
        try
        {
            Socket socket = OutboundTcpConnectionPool.newSocket(peer);
            socket.setSoTimeout(DatabaseDescriptor.getStreamingSocketTimeout());
            socket.setKeepAlive(true);
            return socket;
        }
        catch (IOException e)
        {
            if (++attempts >= MAX_CONNECT_ATTEMPTS)
                throw e;

            long waitms = DatabaseDescriptor.getRpcTimeout() * (long)Math.pow(2, attempts);
            logger.warn("Failed attempt {} to connect to {}. Retrying in {} ms. ({})", attempts, peer, waitms, e);
            try
            {
                Thread.sleep(waitms);
            }
            catch (InterruptedException wtf)
            {
                throw new IOException("interrupted", wtf);
            }
        }
    }
}
 
Example 40
Project: ACaZoo   File: StorageServiceClientTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testClientOnlyMode() throws IOException, ConfigurationException
{
    SchemaLoader.mkdirs();
    SchemaLoader.cleanup();
    StorageService.instance.initClient();

    // verify that no storage directories were created.
    for (String path : DatabaseDescriptor.getAllDataFileLocations())
    {
        assertFalse(new File(path).exists());
    }
    StorageService.instance.stopClient();
}