Search in sources :

Example 1 with Serviceable

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

the class PropertyValidation method doValidateApplyAndMap.

public Serializable doValidateApplyAndMap(TransactionController tc, String key, Serializable value, Dictionary d, boolean dbOnlyProperty) throws StandardException {
    Serializable mappedValue = null;
    if (notifyOnSet != null) {
        synchronized (this) {
            for (int i = 0; i < notifyOnSet.size(); i++) {
                PropertySetCallback psc = notifyOnSet.get(i);
                if (!psc.validate(key, value, d))
                    continue;
                if (mappedValue == null)
                    mappedValue = psc.map(key, value, d);
                if (!dbOnlyProperty && key.startsWith("derby.")) {
                    if (PropertyUtil.whereSet(key, d) == PropertyUtil.SET_IN_JVM)
                        continue;
                }
                Serviceable s;
                if ((s = psc.apply(key, value, d)) != null)
                    ((TransactionManager) tc).addPostCommitWork(s);
            }
        }
    }
    return mappedValue;
}
Also used : Serviceable(org.apache.derby.iapi.services.daemon.Serviceable) Serializable(java.io.Serializable) PropertySetCallback(org.apache.derby.iapi.services.property.PropertySetCallback)

Example 2 with Serviceable

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

the class BaseDataFileFactory method dropContainer.

/**
 *		Drop a container.
 *
 *	    <P><B>Synchronisation</B>
 *		<P>
 *		This call will mark the container as dropped and then obtain an CX lock
 *		(table level exclusive lock) on the container. Once a container has
 *        been marked as dropped it cannot be retrieved by an openContainer()
 *        call unless explicitly with droppedOK.
 *		<P>
 *		Once the exclusive lock has been obtained the container is removed
 *		and all its pages deallocated. The container will be fully removed
 *		at the commit time of the transaction.
 *
 *		@exception StandardException Standard Derby error policy
 */
public void dropContainer(RawTransaction t, ContainerKey ckey) throws StandardException {
    boolean tmpContainer = (ckey.getSegmentId() == ContainerHandle.TEMPORARY_SEGMENT);
    LockingPolicy cl = null;
    if (!tmpContainer) {
        if (isReadOnly()) {
            throw StandardException.newException(SQLState.DATA_CONTAINER_READ_ONLY);
        }
        cl = t.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true);
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(cl != null);
    }
    // close all open containers and 'onCommit' objects of this container
    t.notifyObservers(ckey);
    RawContainerHandle containerHdl = (RawContainerHandle) t.openContainer(ckey, cl, ContainerHandle.MODE_FORUPDATE);
    // happening thru some means other than the lock we are getting here.
    try {
        if (containerHdl == null || containerHdl.getContainerStatus() != RawContainerHandle.NORMAL) {
            // If we are a temp container, don't worry about it.
            if (tmpContainer) {
                if (containerHdl != null)
                    containerHdl.removeContainer((LogInstant) null);
                return;
            } else {
                throw StandardException.newException(SQLState.DATA_CONTAINER_VANISHED, ckey);
            }
        }
        // Container exist, is updatable and we got the lock.
        if (tmpContainer) {
            containerHdl.dropContainer((LogInstant) null, true);
            containerHdl.removeContainer((LogInstant) null);
        } else {
            ContainerOperation lop = new ContainerOperation(containerHdl, ContainerOperation.DROP);
            // mark the container as pre-dirtied so that if a checkpoint
            // happens after the log record is sent to the log stream, the
            // cache cleaning will wait for this change.
            containerHdl.preDirty(true);
            try {
                t.logAndDo(lop);
            } finally {
                // in case logAndDo fail, make sure the container is not
                // stuck in preDirty state.
                containerHdl.preDirty(false);
            }
            // remember this as a post commit work item
            Serviceable p = new ReclaimSpace(ReclaimSpace.CONTAINER, ckey, this, true);
            if (SanityManager.DEBUG) {
                if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) {
                    SanityManager.DEBUG(DaemonService.DaemonTrace, "Add post commit work " + p);
                }
            }
            t.addPostCommitWork(p);
        }
    } finally {
        if (containerHdl != null)
            containerHdl.close();
    }
}
Also used : Serviceable(org.apache.derby.iapi.services.daemon.Serviceable) LogInstant(org.apache.derby.iapi.store.raw.log.LogInstant) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy)

Example 3 with Serviceable

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

the class RemoveFile method removeJarDir.

/**
 * @see FileResource#removeJarDir
 */
public void removeJarDir(String f) throws StandardException {
    if (factory.isReadOnly())
        throw StandardException.newException(SQLState.FILE_READ_ONLY);
    ContextManager cm = FileContainer.getContextService().getCurrentContextManager();
    RawTransaction tran = factory.getRawStoreFactory().getXactFactory().findUserTransaction(factory.getRawStoreFactory(), cm, AccessFactoryGlobals.USER_TRANS_NAME);
    StorageFile ff = factory.storageFactory.newStorageFile(f);
    Serviceable s = new RemoveFile(ff);
    // Since this code is only used during upgrade to post-10.8 databases
    // we do no bother to build code for a special RemoveDirOperation and
    // do tran.logAndDo (cf. logic in #remove). If the post-commit removal
    // doesn't get completed, that is no big issue, the dirs can be removed
    // by hand if need be. A prudent DBA will rerun the upgrade from a
    // backup if something crashes anyway..
    tran.addPostCommitWork(s);
}
Also used : Serviceable(org.apache.derby.iapi.services.daemon.Serviceable) ContextManager(org.apache.derby.iapi.services.context.ContextManager) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) StorageFile(org.apache.derby.io.StorageFile)

Example 4 with Serviceable

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

the class RemoveFile method remove.

/**
 *	  @see FileResource#remove
 *	  @exception StandardException Oops
 */
public void remove(String name, long currentGenerationId) throws StandardException {
    if (factory.isReadOnly())
        throw StandardException.newException(SQLState.FILE_READ_ONLY);
    ContextManager cm = FileContainer.getContextService().getCurrentContextManager();
    RawTransaction tran = factory.getRawStoreFactory().getXactFactory().findUserTransaction(factory.getRawStoreFactory(), cm, AccessFactoryGlobals.USER_TRANS_NAME);
    // Block the backup, If backup is already in progress wait
    // for the backup to finish. Jar files are unlogged but the
    // changes to the  references to the jar file in the catalogs
    // is logged. A consistent backup can not be made when jar file
    // is being removed.
    tran.blockBackup(true);
    tran.logAndDo(new RemoveFileOperation(name, currentGenerationId, true));
    Serviceable s = new RemoveFile(getAsFile(name, currentGenerationId));
    tran.addPostCommitWork(s);
}
Also used : Serviceable(org.apache.derby.iapi.services.daemon.Serviceable) ContextManager(org.apache.derby.iapi.services.context.ContextManager) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction)

Example 5 with Serviceable

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

the class BasicDaemon method serviceClient.

protected void serviceClient(ServiceRecord clientRecord) {
    clientRecord.serviced();
    Serviceable client = clientRecord.client;
    // client may have unsubscribed while it had items queued
    if (client == null)
        return;
    ContextManager cm = contextMgr;
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(cm != null, "Context manager is null");
        SanityManager.ASSERT(client != null, "client is null");
    }
    try {
        int status = client.performWork(cm);
        if (clientRecord.subscriber)
            return;
        if (status == Serviceable.REQUEUE) {
            List<ServiceRecord> queue = client.serviceASAP() ? highPQ : normPQ;
            synchronized (this) {
                queue.add(clientRecord);
                if (SanityManager.DEBUG) {
                    if (SanityManager.DEBUG_ON("memoryLeakTrace")) {
                        if (queue.size() > (OPTIMAL_QUEUE_SIZE * 2))
                            System.out.println("memoryLeakTrace:BasicDaemon " + queue.size());
                    }
                }
            }
        }
        return;
    } catch (Throwable e) {
        if (SanityManager.DEBUG)
            SanityManager.showTrace(e);
        // Assume database is not active. DERBY-4856 thread dump
        cm.cleanupOnError(e, false);
    }
}
Also used : Serviceable(org.apache.derby.iapi.services.daemon.Serviceable) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Aggregations

Serviceable (org.apache.derby.iapi.services.daemon.Serviceable)5 ContextManager (org.apache.derby.iapi.services.context.ContextManager)3 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)2 Serializable (java.io.Serializable)1 PropertySetCallback (org.apache.derby.iapi.services.property.PropertySetCallback)1 LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)1 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)1 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)1 StorageFile (org.apache.derby.io.StorageFile)1