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;
}
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);
}
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);
}
}
}
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);
}
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);
});
}
Aggregations