Search in sources :

Example 1 with DaemonFactory

use of org.apache.derby.iapi.services.daemon.DaemonFactory in project derby by apache.

the class RawStore method boot.

public void boot(boolean create, Properties properties) throws StandardException {
    boolean transformExistingData = false;
    boolean inReplicationSlaveMode = false;
    String slave = properties.getProperty(SlaveFactory.REPLICATION_MODE);
    if (slave != null && slave.equals(SlaveFactory.SLAVE_MODE)) {
        inReplicationSlaveMode = true;
    }
    DaemonFactory daemonFactory = (DaemonFactory) startSystemModule(org.apache.derby.shared.common.reference.Module.DaemonFactory);
    rawStoreDaemon = daemonFactory.createNewDaemon("rawStoreDaemon");
    xactFactory = (TransactionFactory) bootServiceModule(create, this, getTransactionFactoryModule(), properties);
    dataFactory = (DataFactory) bootServiceModule(create, this, getDataFactoryModule(), properties);
    storageFactory = dataFactory.getStorageFactory();
    String restoreFromBackup = null;
    if (properties != null) {
        // check if this is a restore from a backup copy.
        restoreFromBackup = properties.getProperty(Attribute.CREATE_FROM);
        if (restoreFromBackup == null)
            restoreFromBackup = properties.getProperty(Attribute.RESTORE_FROM);
        if (restoreFromBackup == null)
            restoreFromBackup = properties.getProperty(Attribute.ROLL_FORWARD_RECOVERY_FROM);
    }
    // setup database encryption engines.
    if (create) {
        transformExistingData = setupEncryptionEngines(create, properties);
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(!transformExistingData, "no crypto data transformation for a new db");
        }
    }
    // let everyone knows who their rawStoreFactory is and they can use it
    // to get to other modules
    // pass in create and properties to dataFactory so it can boot the log
    // factory
    dataFactory.setRawStoreFactory(this, create, properties);
    xactFactory.setRawStoreFactory(this);
    if (properties instanceof UpdateServiceProperties) {
        if (storageFactory instanceof WritableStorageFactory)
            ((UpdateServiceProperties) properties).setStorageFactory((WritableStorageFactory) storageFactory);
    }
    // log factory is booted by the data factory
    logFactory = (LogFactory) findServiceModule(this, getLogFactoryModule());
    // if this is a restore from backup, restore the jar files.
    if (restoreFromBackup != null) {
        restoreRemainingFromBackup(restoreFromBackup);
    }
    // If the log is at another location, make sure  service.properties
    // file has it.
    String logDevice = properties.getProperty(Attribute.LOG_DEVICE);
    if (logDevice != null) {
        if (// We do not care about log location if read only
        !isReadOnly() && (create || !logDevice.equals(logFactory.getCanonicalLogPath()) || restoreFromBackup != null)) {
            // get the real location from the log factory
            properties.put(Attribute.LOG_DEVICE, logFactory.getCanonicalLogPath());
            // make the log device param stored in backup is same as current log device.
            properties.put(Property.LOG_DEVICE_AT_BACKUP, logFactory.getCanonicalLogPath());
        }
    } else {
        // into service.propertues in such cases.
        if (restoreFromBackup != null && logFactory.getCanonicalLogPath() != null) {
            // logdevice might have got changed because of backup restore.
            properties.put(Attribute.LOG_DEVICE, logFactory.getCanonicalLogPath());
        } else {
            // might have been OS copy restore. We default log to db home
            properties.remove(Property.LOG_DEVICE_AT_BACKUP);
        }
    }
    // restore from. This marks the end of restore from backup.
    if (restoreFromBackup != null) {
        ((UpdateServiceProperties) properties).saveServiceProperties();
    }
    // setup database encryption engine
    if (!create) {
        // existing database.
        if (properties.getProperty(RawStoreFactory.DB_ENCRYPTION_STATUS) != null) {
            handleIncompleteDbCryptoOperation(properties);
        }
        transformExistingData = setupEncryptionEngines(create, properties);
    }
    if (isEncryptedDatabase) {
        // let log factory know if the database is encrypted .
        logFactory.setDatabaseEncrypted(true, false);
        // let data factory know if the database is encrypted.
        dataFactory.setDatabaseEncrypted(true);
    }
    // RawStoreFactory is used by LogFactory.recover() and by
    // SlaveFactory.startSlave (for the SlaveFactory case, it is
    // only used if the database is encrypted)
    logFactory.setRawStoreFactory(this);
    // when in replication slave mode.
    if (inReplicationSlaveMode) {
        // The LogFactory has already been booted in slave mode.
        // Can now start slave replication by booting the
        // SlaveFactory service
        slaveFactory = (SlaveFactory) bootServiceModule(create, this, getSlaveFactoryModule(), properties);
        slaveFactory.startSlave(this, logFactory);
    }
    // no need to tell log factory which raw store factory it belongs to
    // since this is passed into the log factory for recovery
    // after the factories are loaded, recover the database
    logFactory.recover(dataFactory, xactFactory);
    // a new alogorithm then do that now.
    if (transformExistingData) {
        applyBulkCryptoOperation(properties, newCipherFactory);
    }
}
Also used : WritableStorageFactory(org.apache.derby.io.WritableStorageFactory) UpdateServiceProperties(org.apache.derby.impl.services.monitor.UpdateServiceProperties) DaemonFactory(org.apache.derby.iapi.services.daemon.DaemonFactory)

Aggregations

DaemonFactory (org.apache.derby.iapi.services.daemon.DaemonFactory)1 UpdateServiceProperties (org.apache.derby.impl.services.monitor.UpdateServiceProperties)1 WritableStorageFactory (org.apache.derby.io.WritableStorageFactory)1