Search in sources :

Example 1 with Config

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;
}
Also used : DataOutputBufferFixed(org.apache.cassandra.io.util.DataOutputBufferFixed) java.util(java.util) BufferedDataOutputStreamPlus(org.apache.cassandra.io.util.BufferedDataOutputStreamPlus) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) TableId(org.apache.cassandra.schema.TableId) EncryptionContext(org.apache.cassandra.security.EncryptionContext) LoggerFactory(org.slf4j.LoggerFactory) Config(org.apache.cassandra.config.Config) org.apache.cassandra.db(org.apache.cassandra.db) ICompressor(org.apache.cassandra.io.compress.ICompressor) StringUtils(org.apache.commons.lang3.StringUtils) FBUtilities.updateChecksum(org.apache.cassandra.utils.FBUtilities.updateChecksum) ByteBuffer(java.nio.ByteBuffer) Allocation(org.apache.cassandra.db.commitlog.CommitLogSegment.Allocation) MBeanServer(javax.management.MBeanServer) ManagementFactory(java.lang.management.ManagementFactory) CommitLogMetrics(org.apache.cassandra.metrics.CommitLogMetrics) FBUtilities.updateChecksumInt(org.apache.cassandra.utils.FBUtilities.updateChecksumInt) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) FSWriteError(org.apache.cassandra.io.FSWriteError) MessagingService(org.apache.cassandra.net.MessagingService) Logger(org.slf4j.Logger) FBUtilities(org.apache.cassandra.utils.FBUtilities) WriteTimeoutException(org.apache.cassandra.exceptions.WriteTimeoutException) StorageService(org.apache.cassandra.service.StorageService) ObjectName(javax.management.ObjectName) ENTRY_OVERHEAD_SIZE(org.apache.cassandra.db.commitlog.CommitLogSegment.ENTRY_OVERHEAD_SIZE) CompressionParams(org.apache.cassandra.schema.CompressionParams) java.io(java.io) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) FileUtils(org.apache.cassandra.io.util.FileUtils) CRC32(java.util.zip.CRC32) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CommitLogSegmentFileComparator(org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator) CommitLogSegmentFileComparator(org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator)

Example 2 with Config

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;
}
Also used : Config(org.apache.cassandra.config.Config)

Example 3 with 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();
}
Also used : Config(org.apache.cassandra.config.Config) Test(org.junit.Test)

Example 4 with Config

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);
}
Also used : UnknownHostException(java.net.UnknownHostException) Config(org.apache.cassandra.config.Config) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException)

Example 5 with Config

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();
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Config(org.apache.cassandra.config.Config)

Aggregations

Config (org.apache.cassandra.config.Config)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 java.io (java.io)1 ManagementFactory (java.lang.management.ManagementFactory)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ByteBuffer (java.nio.ByteBuffer)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 CRC32 (java.util.zip.CRC32)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 ParameterizedClass (org.apache.cassandra.config.ParameterizedClass)1 org.apache.cassandra.db (org.apache.cassandra.db)1 Allocation (org.apache.cassandra.db.commitlog.CommitLogSegment.Allocation)1 CommitLogSegmentFileComparator (org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator)1 ENTRY_OVERHEAD_SIZE (org.apache.cassandra.db.commitlog.CommitLogSegment.ENTRY_OVERHEAD_SIZE)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 WriteTimeoutException (org.apache.cassandra.exceptions.WriteTimeoutException)1