Search in sources :

Example 11 with AccessFactory

use of org.apache.derby.iapi.store.access.AccessFactory in project derby by apache.

the class FileContainer method createInfoFromProp.

/**
 *		Set container properties from the passed in createArgs.
 *		The following container properties are set:
 *
 *		pageSize
 *		spareSpace
 *		minimumRecordSize
 *		isReusableRecordId
 *		initialPages
 *
 *		RESOLVE - in the future setting parameters should be overridable
 *		by sub-class, e.g. one implementation of Container may require a
 *		minimum page size of 4k.
 */
private void createInfoFromProp(Properties createArgs) throws StandardException {
    // Need a TransactionController to get database/service wide properties.
    AccessFactory af = (AccessFactory) getServiceModule(dataFactory, AccessFactory.MODULE);
    // RESOLVE: sku defectid 2014
    TransactionController tc = (af == null) ? null : af.getTransaction(getContextService().getCurrentContextManager());
    pageSize = PropertyUtil.getServiceInt(tc, createArgs, Property.PAGE_SIZE_PARAMETER, Limits.DB2_MIN_PAGE_SIZE, Limits.DB2_MAX_PAGE_SIZE, RawStoreFactory.PAGE_SIZE_DEFAULT);
    // default if bad value given.
    if ((pageSize != 4096) && (pageSize != 8192) && (pageSize != 16384) && (pageSize != 32768)) {
        pageSize = RawStoreFactory.PAGE_SIZE_DEFAULT;
    }
    spareSpace = PropertyUtil.getServiceInt(tc, createArgs, RawStoreFactory.PAGE_RESERVED_SPACE_PARAMETER, 0, 100, 20);
    PreAllocSize = PropertyUtil.getServiceInt(tc, createArgs, RawStoreFactory.PRE_ALLOCATE_PAGE, MIN_PRE_ALLOC_SIZE, MAX_PRE_ALLOC_SIZE, DEFAULT_PRE_ALLOC_SIZE);
    // to be larger than pageSize, when long rows are supported.
    if (createArgs == null) {
        // if the createArgs is null, then the following method call
        // will get the system properties from the appropriete places.
        // we want to make sure minimumRecrodSize is set to at least
        // the default value MINIMUM_RECORD_SIZE_DEFAULT (12)
        // as set in rawStoreFactory.
        minimumRecordSize = PropertyUtil.getServiceInt(tc, RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER, // this is different from the next call
        RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT, // reserving 100 bytes for record/field headers
        (pageSize * (1 - spareSpace / 100) - 100), RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT);
    } else {
        // if the createArgs is not null, then it has already been set
        // by upper layer or create statement, then, we allow the minimum
        // value of this to be MINIMUM_RECORD_SIZE_MINIMUM (1).
        minimumRecordSize = PropertyUtil.getServiceInt(tc, createArgs, RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER, // this is different from the last call
        RawStoreFactory.MINIMUM_RECORD_SIZE_MINIMUM, // reserving 100 bytes for record/field headers
        (pageSize * (1 - spareSpace / 100) - 100), RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT);
    }
    // if container is to be created with a large number of pages
    if (createArgs != null) {
        String reusableRecordIdParameter = createArgs.getProperty(RawStoreFactory.PAGE_REUSABLE_RECORD_ID);
        if (reusableRecordIdParameter != null) {
            Boolean reusableRecordId = Boolean.parseBoolean(reusableRecordIdParameter);
            setReusableRecordIdState(reusableRecordId.booleanValue());
        }
        String containerInitialPageParameter = createArgs.getProperty(RawStoreFactory.CONTAINER_INITIAL_PAGES);
        if (containerInitialPageParameter != null) {
            initialPages = Short.parseShort(containerInitialPageParameter);
            if (initialPages > 1) {
                if (initialPages > RawStoreFactory.MAX_CONTAINER_INITIAL_PAGES)
                    initialPages = RawStoreFactory.MAX_CONTAINER_INITIAL_PAGES;
            }
        }
    }
}
Also used : TransactionController(org.apache.derby.iapi.store.access.TransactionController) AccessFactory(org.apache.derby.iapi.store.access.AccessFactory)

Example 12 with AccessFactory

use of org.apache.derby.iapi.store.access.AccessFactory in project derby by apache.

the class LogToFile method disableLogArchiveMode.

// disable the log archive mode
public void disableLogArchiveMode() throws StandardException {
    AccessFactory af = (AccessFactory) getServiceModule(this, AccessFactory.MODULE);
    if (af != null) {
        TransactionController tc = null;
        tc = af.getTransaction(getContextService().getCurrentContextManager());
        tc.setProperty(Property.LOG_ARCHIVE_MODE, "false", true);
    }
    logArchived = false;
}
Also used : TransactionController(org.apache.derby.iapi.store.access.TransactionController) AccessFactory(org.apache.derby.iapi.store.access.AccessFactory)

Example 13 with AccessFactory

use of org.apache.derby.iapi.store.access.AccessFactory in project derby by apache.

the class SequenceUpdater method updateCurrentValueOnDisk.

// /////////////////////////////////////////////////////////////////////////////////
// 
// DISK WRITING MINIONS
// 
// /////////////////////////////////////////////////////////////////////////////////
/**
 * <p>
 * Update the value on disk. Does its work in a subtransaction of the user's
 * execution transaction. If that fails, raises a TOO MUCH CONTENTION exception.
 * </p>
 *
 * @return Returns true if the value was successfully updated, false if we lost a race with another session.
 */
public synchronized boolean updateCurrentValueOnDisk(Long oldValue, Long newValue) throws StandardException {
    LanguageConnectionContext lcc = getLCC();
    // 
    if (lcc == null) {
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(oldValue == null, "We should be flushing unused sequence values here.");
        }
        ContextService csf = getContextService();
        ContextManager cm = csf.getCurrentContextManager();
        AccessFactory af = _dd.af;
        TransactionController dummyTransaction = af.getTransaction(cm);
        boolean retval = updateCurrentValueOnDisk(dummyTransaction, oldValue, newValue, false);
        dummyTransaction.commit();
        dummyTransaction.destroy();
        return retval;
    }
    TransactionController executionTransaction = lcc.getTransactionExecute();
    TransactionController nestedTransaction = executionTransaction.startNestedUserTransaction(false, true);
    if (nestedTransaction != null) {
        boolean retval = false;
        boolean escalateToParentTransaction = false;
        try {
            retval = updateCurrentValueOnDisk(nestedTransaction, oldValue, newValue, false);
        } catch (StandardException se) {
            if (!se.isLockTimeout()) {
                if (se.isSelfDeadlock()) {
                    // We're blocked by a lock held by our parent transaction.
                    // Escalate into the parent transaction now. See DERBY-6554.
                    escalateToParentTransaction = true;
                } else {
                    Monitor.logThrowable(se);
                    throw se;
                }
            }
        } finally {
            // DERBY-5494, if this commit does not flush log then an
            // unorderly shutdown could lose the update.  Do not use
            // commitNoSync(), and store needs to flush user nested update
            // transaction commits by default.
            nestedTransaction.commit();
            nestedTransaction.destroy();
            if (escalateToParentTransaction) {
                retval = updateCurrentValueOnDisk(executionTransaction, oldValue, newValue, false);
            }
            return retval;
        }
    }
    throw tooMuchContentionException();
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ContextService(org.apache.derby.iapi.services.context.ContextService) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ContextManager(org.apache.derby.iapi.services.context.ContextManager) TransactionController(org.apache.derby.iapi.store.access.TransactionController) AccessFactory(org.apache.derby.iapi.store.access.AccessFactory)

Example 14 with AccessFactory

use of org.apache.derby.iapi.store.access.AccessFactory in project derby by apache.

the class CacheLock method bootPasswordChange.

private boolean bootPasswordChange(TransactionController tc, String key, Serializable value) throws StandardException {
    // boot password in clear text
    if (key.equals(Attribute.BOOT_PASSWORD)) {
        // The user is trying to change the secret key.
        // The secret key is never stored in clear text, but we
        // store the encrypted form in the services.properties
        // file.  Swap the secret key with the encrypted form and
        // put that in the services.properties file.
        AccessFactory af = ((TransactionManager) tc).getAccessManager();
        RawStoreFactory rsf = (RawStoreFactory) findServiceModule(af, RawStoreFactory.MODULE);
        // remove secret key from properties list if possible
        serviceProperties.remove(Attribute.BOOT_PASSWORD);
        value = rsf.changeBootPassword(serviceProperties, value);
        serviceProperties.put(RawStoreFactory.ENCRYPTED_KEY, value);
        return true;
    } else {
        return false;
    }
}
Also used : TransactionManager(org.apache.derby.iapi.store.access.conglomerate.TransactionManager) AccessFactory(org.apache.derby.iapi.store.access.AccessFactory) RawStoreFactory(org.apache.derby.iapi.store.raw.RawStoreFactory)

Aggregations

AccessFactory (org.apache.derby.iapi.store.access.AccessFactory)14 TransactionController (org.apache.derby.iapi.store.access.TransactionController)11 StandardException (org.apache.derby.shared.common.error.StandardException)4 ContextManager (org.apache.derby.iapi.services.context.ContextManager)2 Properties (java.util.Properties)1 ContextService (org.apache.derby.iapi.services.context.ContextService)1 Diagnosticable (org.apache.derby.iapi.services.diag.Diagnosticable)1 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)1 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)1 TransactionManager (org.apache.derby.iapi.store.access.conglomerate.TransactionManager)1 XAXactId (org.apache.derby.iapi.store.access.xa.XAXactId)1 RawStoreFactory (org.apache.derby.iapi.store.raw.RawStoreFactory)1 ShutdownException (org.apache.derby.shared.common.error.ShutdownException)1