Search in sources :

Example 1 with IInstanceConfig

use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.

the class ClusterUtils method getDataDirectories.

/**
 * Get all data directories for the given instance.
 *
 * @param instance to get data directories for
 * @return data directories
 */
public static List<File> getDataDirectories(IInstance instance) {
    IInstanceConfig conf = instance.config();
    // this isn't safe as it assumes the implementation of InstanceConfig
    // might need to get smarter... some day...
    String[] ds = (String[]) conf.get("data_file_directories");
    List<File> files = new ArrayList<>(ds.length);
    for (int i = 0; i < ds.length; i++) files.add(new File(ds[i]));
    return files;
}
Also used : IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) ArrayList(java.util.ArrayList) File(org.apache.cassandra.io.util.File)

Example 2 with IInstanceConfig

use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.

the class ClusterUtils method getCommitLogDirectory.

/**
 * Get the commit log directory for the given instance.
 *
 * @param instance to get the commit log directory for
 * @return commit log directory
 */
public static File getCommitLogDirectory(IInstance instance) {
    IInstanceConfig conf = instance.config();
    // this isn't safe as it assumes the implementation of InstanceConfig
    // might need to get smarter... some day...
    String d = (String) conf.get("commitlog_directory");
    return new File(d);
}
Also used : IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) File(org.apache.cassandra.io.util.File)

Example 3 with IInstanceConfig

use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.

the class ClusterUtils method updateAddress.

/**
 * Changes the instance's address to the new address.  This method should only be called while the instance is
 * down, else has undefined behavior.
 *
 * @param conf to update address for
 * @param address to set
 */
private static void updateAddress(IInstanceConfig conf, String address) {
    InetSocketAddress previous = conf.broadcastAddress();
    for (String key : Arrays.asList("broadcast_address", "listen_address", "broadcast_rpc_address", "rpc_address")) conf.set(key, address);
    // InstanceConfig caches InetSocketAddress -> InetAddressAndPort
    // this causes issues as startup now ignores config, so force reset it to pull from conf.
    // TODO remove the need to null out the cache...
    ((InstanceConfig) conf).unsetBroadcastAddressAndPort();
    // are a risk
    if (!conf.broadcastAddress().equals(previous)) {
        conf.networkTopology().put(conf.broadcastAddress(), NetworkTopology.dcAndRack(conf.localDatacenter(), conf.localRack()));
        try {
            Field field = NetworkTopology.class.getDeclaredField("map");
            field.setAccessible(true);
            Map<InetSocketAddress, NetworkTopology.DcAndRack> map = (Map<InetSocketAddress, NetworkTopology.DcAndRack>) field.get(conf.networkTopology());
            map.remove(previous);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new AssertionError(e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) InstanceConfig(org.apache.cassandra.distributed.impl.InstanceConfig) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) InetSocketAddress(java.net.InetSocketAddress) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with IInstanceConfig

use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.

the class ClusterUtils method getSavedCachesDirectory.

/**
 * Get the saved caches directory for the given instance.
 *
 * @param instance to get the saved caches directory for
 * @return saved caches directory
 */
public static File getSavedCachesDirectory(IInstance instance) {
    IInstanceConfig conf = instance.config();
    // this isn't safe as it assumes the implementation of InstanceConfig
    // might need to get smarter... some day...
    String d = (String) conf.get("saved_caches_directory");
    return new File(d);
}
Also used : IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) File(org.apache.cassandra.io.util.File)

Example 5 with IInstanceConfig

use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.

the class ClusterUtils method replaceHostAndStart.

/**
 * Create and start a new instance that replaces an existing instance.
 *
 * The instance will be in the same datacenter and rack as the existing instance.
 *
 * @param cluster to add to
 * @param toReplace instance to replace
 * @param fn lambda to add additional properties or modify instance
 * @param <I> instance type
 * @return the instance added
 */
public static <I extends IInstance> I replaceHostAndStart(AbstractCluster<I> cluster, IInstance toReplace, BiConsumer<I, WithProperties> fn) {
    IInstanceConfig toReplaceConf = toReplace.config();
    I inst = addInstance(cluster, toReplaceConf, c -> c.set("auto_bootstrap", true));
    return start(inst, properties -> {
        // lower this so the replacement waits less time
        properties.setProperty("cassandra.broadcast_interval_ms", Long.toString(TimeUnit.SECONDS.toMillis(30)));
        // default is 30s, lowering as it should be faster
        properties.setProperty("cassandra.ring_delay_ms", Long.toString(TimeUnit.SECONDS.toMillis(10)));
        properties.set(BOOTSTRAP_SCHEMA_DELAY_MS, TimeUnit.SECONDS.toMillis(10));
        // state which node to replace
        properties.setProperty("cassandra.replace_address_first_boot", toReplace.config().broadcastAddress().getAddress().getHostAddress());
        fn.accept(inst, properties);
    });
}
Also used : IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig)

Aggregations

IInstanceConfig (org.apache.cassandra.distributed.api.IInstanceConfig)18 Cluster (org.apache.cassandra.distributed.Cluster)8 TokenSupplier (org.apache.cassandra.distributed.api.TokenSupplier)7 NetworkTopology (org.apache.cassandra.distributed.shared.NetworkTopology)7 Test (org.junit.Test)7 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)6 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)6 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)6 Map (java.util.Map)5 File (org.apache.cassandra.io.util.File)4 Assert (org.junit.Assert)4 InetAddress (java.net.InetAddress)3 InetSocketAddress (java.net.InetSocketAddress)3 UUID (java.util.UUID)3 GossipHelper.bootstrap (org.apache.cassandra.distributed.action.GossipHelper.bootstrap)3 GossipHelper.statusToBootstrap (org.apache.cassandra.distributed.action.GossipHelper.statusToBootstrap)3 GossipHelper.withProperty (org.apache.cassandra.distributed.action.GossipHelper.withProperty)3 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)3 TestBaseImpl (org.apache.cassandra.distributed.test.TestBaseImpl)3 Arrays.asList (java.util.Arrays.asList)2