use of org.apache.cassandra.config.Config in project cassandra by apache.
the class CommitLog method recoverSegmentsOnDisk.
/**
* Perform recovery on commit logs located in the directory specified by the config file.
*
* @return the number of mutations replayed
* @throws IOException
*/
public int recoverSegmentsOnDisk() throws IOException {
FilenameFilter unmanagedFilesFilter = (dir, name) -> CommitLogDescriptor.isValid(name) && CommitLogSegment.shouldReplay(name);
// archiving pass, which we should not treat as serious.
for (File file : new File(segmentManager.storageDirectory).listFiles(unmanagedFilesFilter)) {
archiver.maybeArchive(file.getPath(), file.getName());
archiver.maybeWaitForArchiving(file.getName());
}
assert archiver.archivePending.isEmpty() : "Not all commit log archive tasks were completed before restore";
archiver.maybeRestoreArchive();
// List the files again as archiver may have added segments.
File[] files = new File(segmentManager.storageDirectory).listFiles(unmanagedFilesFilter);
int replayed = 0;
if (files.length == 0) {
logger.info("No commitlog files found; skipping replay");
} else {
Arrays.sort(files, new CommitLogSegmentFileComparator());
logger.info("Replaying {}", StringUtils.join(files, ", "));
replayed = recoverFiles(files);
logger.info("Log replay complete, {} replayed mutations", replayed);
for (File f : files) segmentManager.handleReplayedSegment(f);
}
return replayed;
}
use of org.apache.cassandra.config.Config in project cassandra by apache.
the class OffsetAwareConfigurationLoader method loadConfig.
@Override
public Config loadConfig() throws ConfigurationException {
Config config = super.loadConfig();
String sep = File.pathSeparator;
config.native_transport_port += offset;
config.storage_port += offset;
config.commitlog_directory += sep + offset;
config.saved_caches_directory += sep + offset;
config.hints_directory += sep + offset;
config.cdc_raw_directory += sep + offset;
for (int i = 0; i < config.data_file_directories.length; i++) config.data_file_directories[i] += sep + offset;
return config;
}
use of org.apache.cassandra.config.Config in project cassandra by apache.
the class FBUtilitiesTest method testGetBroadcastRpcAddress.
@Test
public void testGetBroadcastRpcAddress() throws Exception {
//When both rpc_address and broadcast_rpc_address are null, it should return the local address (from DD.applyAddressConfig)
FBUtilities.reset();
Config testConfig = DatabaseDescriptor.loadConfig();
testConfig.rpc_address = null;
testConfig.broadcast_rpc_address = null;
DatabaseDescriptor.applyAddressConfig(testConfig);
assertEquals(FBUtilities.getLocalAddress(), FBUtilities.getBroadcastRpcAddress());
//When rpc_address is defined and broadcast_rpc_address is null, it should return the rpc_address
FBUtilities.reset();
testConfig.rpc_address = "127.0.0.2";
testConfig.broadcast_rpc_address = null;
DatabaseDescriptor.applyAddressConfig(testConfig);
assertEquals(InetAddress.getByName("127.0.0.2"), FBUtilities.getBroadcastRpcAddress());
//When both rpc_address and broadcast_rpc_address are defined, it should return broadcast_rpc_address
FBUtilities.reset();
testConfig.rpc_address = "127.0.0.2";
testConfig.broadcast_rpc_address = "127.0.0.3";
DatabaseDescriptor.applyAddressConfig(testConfig);
assertEquals(InetAddress.getByName("127.0.0.3"), FBUtilities.getBroadcastRpcAddress());
FBUtilities.reset();
}
use of org.apache.cassandra.config.Config in project cassandra by apache.
the class SimpleSeedProvider method getSeeds.
public List<InetAddress> getSeeds() {
Config conf;
try {
conf = DatabaseDescriptor.loadConfig();
} catch (Exception e) {
throw new AssertionError(e);
}
String[] hosts = conf.seed_provider.parameters.get("seeds").split(",", -1);
List<InetAddress> seeds = new ArrayList<InetAddress>(hosts.length);
for (String host : hosts) {
try {
seeds.add(InetAddress.getByName(host.trim()));
} catch (UnknownHostException ex) {
// not fatal... DD will bark if there end up being zero seeds.
logger.warn("Seed provider couldn't lookup host {}", host);
}
}
return Collections.unmodifiableList(seeds);
}
use of org.apache.cassandra.config.Config in project cassandra by apache.
the class AuthConfig method applyAuth.
public static void applyAuth() {
// some tests need this
if (initialized)
return;
initialized = true;
Config conf = DatabaseDescriptor.getRawConfig();
IAuthenticator authenticator = new AllowAllAuthenticator();
/* Authentication, authorization and role management backend, implementing IAuthenticator, IAuthorizer & IRoleMapper*/
if (conf.authenticator != null)
authenticator = FBUtilities.newAuthenticator(conf.authenticator);
// is in use and non-default values are detected
if (!(authenticator instanceof PasswordAuthenticator) && (conf.credentials_update_interval_in_ms != -1 || conf.credentials_validity_in_ms != 2000 || conf.credentials_cache_max_entries != 1000)) {
logger.info("Configuration options credentials_update_interval_in_ms, credentials_validity_in_ms and " + "credentials_cache_max_entries may not be applicable for the configured authenticator ({})", authenticator.getClass().getName());
}
DatabaseDescriptor.setAuthenticator(authenticator);
// authorizer
IAuthorizer authorizer = new AllowAllAuthorizer();
if (conf.authorizer != null)
authorizer = FBUtilities.newAuthorizer(conf.authorizer);
if (!authenticator.requireAuthentication() && authorizer.requireAuthorization())
throw new ConfigurationException(conf.authenticator + " can't be used with " + conf.authorizer, false);
DatabaseDescriptor.setAuthorizer(authorizer);
// role manager
IRoleManager roleManager;
if (conf.role_manager != null)
roleManager = FBUtilities.newRoleManager(conf.role_manager);
else
roleManager = new CassandraRoleManager();
if (authenticator instanceof PasswordAuthenticator && !(roleManager instanceof CassandraRoleManager))
throw new ConfigurationException("CassandraRoleManager must be used with PasswordAuthenticator", false);
DatabaseDescriptor.setRoleManager(roleManager);
// authenticator
IInternodeAuthenticator internodeAuthenticator;
if (conf.internode_authenticator != null)
internodeAuthenticator = FBUtilities.construct(conf.internode_authenticator, "internode_authenticator");
else
internodeAuthenticator = new AllowAllInternodeAuthenticator();
DatabaseDescriptor.setInternodeAuthenticator(internodeAuthenticator);
// Validate at last to have authenticator, authorizer, role-manager and internode-auth setup
// in case these rely on each other.
authenticator.validateConfiguration();
authorizer.validateConfiguration();
roleManager.validateConfiguration();
internodeAuthenticator.validateConfiguration();
}
Aggregations