Search in sources :

Example 6 with LogInstant

use of org.apache.derby.iapi.store.raw.log.LogInstant in project derby by apache.

the class LockCount method commit.

/**
 *	  @exception StandardException  Standard Derby exception policy
 *	  @see Transaction#commit
 */
private LogInstant commit(int commitflag) throws StandardException {
    if (SanityManager.DEBUG) {
        if (SanityManager.DEBUG_ON("XATrace"))
            SanityManager.DEBUG("XATrace", "commiting ");
    }
    LogInstant flushTo = prepareCommit(commitflag);
    completeCommit(commitflag);
    return (flushTo);
}
Also used : LogInstant(org.apache.derby.iapi.store.raw.log.LogInstant)

Example 7 with LogInstant

use of org.apache.derby.iapi.store.raw.log.LogInstant in project derby by apache.

the class LockCount method logAndUndo.

/**
 * Log and apply a compensation operation.
 *		Only need to write out the compensation op itself, the optional data has already
 *		been written by the rollforward operation this is attempting to undo.
 *
 *		@see RawTransaction#logAndDo
 *
 *		@exception StandardException  Standard Derby exception policy
 */
public void logAndUndo(Compensation compensation, LogInstant undoInstant, LimitObjectInput in) throws StandardException {
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(logStart != null);
    }
    setActiveState();
    if (state == ACTIVE)
        setUpdateState();
    seenUpdates = true;
    LogInstant clrInstant = logger.logAndUndo(this, compensation, undoInstant, in);
    setLastLogInstant(clrInstant);
    // set the top savepoint to rollback to this record if it doesn't yet have a point saved
    if ((savePoints != null) && !savePoints.empty()) {
        SavePoint sp = (SavePoint) savePoints.peek();
        if (sp.getSavePoint() == null)
            sp.setSavePoint(clrInstant);
    }
}
Also used : LogInstant(org.apache.derby.iapi.store.raw.log.LogInstant)

Example 8 with LogInstant

use of org.apache.derby.iapi.store.raw.log.LogInstant in project derby by apache.

the class LockCount method prepareCommit.

/**
 *	  @exception StandardException  Standard Derby exception policy
 *	  @see Transaction#commit
 */
/**
 * Do work of commit that is common to xa_prepare and commit.
 * <p>
 * Do all the work necessary as part of a commit up to and including
 * writing the commit log record.  This routine is used by both prepare
 * and commit.  The work post commit is done by completeCommit().
 * <p>
 *
 * @param commitflag various flavors of commit.
 *
 * @exception  StandardException  Standard exception policy.
 * @see Transaction#commit
 */
private LogInstant prepareCommit(int commitflag) throws StandardException {
    LogInstant flushTo = null;
    if (state == CLOSED) {
        throw StandardException.newException(SQLState.XACT_PROTOCOL_VIOLATION_DETAILED, toInternalDetailString());
    }
    if (SanityManager.DEBUG) {
        if ((commitflag & Transaction.KEEP_LOCKS) != 0) {
            // RESOLVE (mikem) - prepare actually want's to keep locks
            // during a prepare.
            SanityManager.ASSERT((((commitflag & COMMIT_NO_SYNC) != 0) || ((commitflag & COMMIT_PREPARE) != 0)), "can keep locks around only in commitNoSync or prepare");
            SanityManager.ASSERT(isUserTransaction(), "KEEP_LOCKS can only be set on user transaction commits");
        }
    }
    try {
        preComplete(COMMIT);
        if (seenUpdates) {
            EndXact ex = new EndXact(getGlobalId(), ((commitflag & COMMIT_PREPARE) == 0 ? END_COMMITTED : END_PREPARED) | statusForEndXactLog());
            flushTo = logger.logAndDo(this, ex);
            if (flush_log_on_xact_end) {
                if ((commitflag & COMMIT_SYNC) == 0) {
                    // not flushing the log right now, subsequent commit
                    // will need to flush the log
                    needSync = true;
                } else {
                    logger.flush(flushTo);
                    needSync = false;
                }
            }
        } else if (needSync && (commitflag & COMMIT_SYNC) != 0) {
            // this transaction object was used to lazily commit some
            // previous transaction without syncing.  Now that we commit
            // for real, make sure any outstanding log is flushed.
            logger.flushAll();
            needSync = false;
        }
    } catch (StandardException se) {
        if (se.getSeverity() < ExceptionSeverity.TRANSACTION_SEVERITY) {
            throw StandardException.newException(SQLState.XACT_COMMIT_EXCEPTION, se);
        }
        throw se;
    }
    return flushTo;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LogInstant(org.apache.derby.iapi.store.raw.log.LogInstant)

Example 9 with LogInstant

use of org.apache.derby.iapi.store.raw.log.LogInstant in project derby by apache.

the class BaseDataFileFactory method boot.

public void boot(boolean create, Properties startParams) throws StandardException {
    jbmsVersion = getMonitor().getEngineVersion();
    jvmVersion = buildJvmVersion();
    osInfo = buildOSinfo();
    jarCPath = jarClassPath(getClass());
    dataDirectory = startParams.getProperty(PersistentService.ROOT);
    UUIDFactory uf = getMonitor().getUUIDFactory();
    identifier = uf.createUUID();
    PersistentService ps = getMonitor().getServiceType(this);
    try {
        storageFactory = ps.getStorageFactoryInstance(true, dataDirectory, startParams.getProperty(Property.STORAGE_TEMP_DIRECTORY, PropertyUtil.getSystemProperty(Property.STORAGE_TEMP_DIRECTORY)), identifier.toANSIidentifier());
    } catch (IOException ioe) {
        if (create) {
            throw StandardException.newException(SQLState.SERVICE_DIRECTORY_CREATE_ERROR, ioe, dataDirectory);
        } else {
            throw StandardException.newException(SQLState.DATABASE_NOT_FOUND, ioe, dataDirectory);
        }
    }
    // you can't encrypt a database if the Lucene plugin is loaded
    if (luceneLoaded()) {
        String encryptionProp = startParams.getProperty(Attribute.DATA_ENCRYPTION);
        if ((encryptionProp != null) && "TRUE".equals(encryptionProp.toUpperCase())) {
            throw StandardException.newException(SQLState.LUCENE_ENCRYPTED_DB);
        }
    }
    if (storageFactory instanceof WritableStorageFactory)
        writableStorageFactory = (WritableStorageFactory) storageFactory;
    actionCode = BOOT_ACTION;
    try {
        AccessController.doPrivileged(this);
    } catch (PrivilegedActionException pae) {
    // BOOT_ACTION does not throw any exceptions.
    }
    String value = startParams.getProperty(Property.FORCE_DATABASE_LOCK, PropertyUtil.getSystemProperty(Property.FORCE_DATABASE_LOCK));
    throwDBlckException = Boolean.valueOf((value != null ? value.trim() : value)).booleanValue();
    if (// read only db, not interested in filelock
    !isReadOnly())
        getJBMSLockOnDB(identifier, uf, dataDirectory);
    // If the database is being restored/created from backup
    // the restore the data directory(seg*) from backup
    String restoreFrom = null;
    restoreFrom = startParams.getProperty(Attribute.CREATE_FROM);
    if (restoreFrom == null)
        restoreFrom = startParams.getProperty(Attribute.RESTORE_FROM);
    if (restoreFrom == null)
        restoreFrom = startParams.getProperty(Attribute.ROLL_FORWARD_RECOVERY_FROM);
    if (restoreFrom != null) {
        try {
            // restoreFrom and createFrom operations also need to know if database
            // is encrypted
            String dataEncryption = startParams.getProperty(Attribute.DATA_ENCRYPTION);
            databaseEncrypted = Boolean.valueOf(dataEncryption).booleanValue();
            restoreDataDirectory(restoreFrom);
        } catch (StandardException se) {
            releaseJBMSLockOnDB();
            throw se;
        }
    }
    logMsg(LINE);
    String messageID = (isReadOnly()) ? MessageId.STORE_BOOT_MSG_READ_ONLY : MessageId.STORE_BOOT_MSG;
    boolean logBootTrace = Boolean.valueOf(startParams.getProperty(Property.LOG_BOOT_TRACE, PropertyUtil.getSystemProperty(Property.LOG_BOOT_TRACE))).booleanValue();
    logMsg(new Date() + MessageService.getTextMessage(messageID, jbmsVersion, identifier, dataDirectory, // cast to Object so we get object hash code
    (Object) this.getClass().getClassLoader(), jarCPath));
    // Log the JVM version info
    logMsg(jvmVersion);
    // Log the OS info
    logMsg(osInfo);
    // Log derby.system.home It will have null value if user didn't set it
    logMsg(Property.SYSTEM_HOME_PROPERTY + "=" + PropertyUtil.getSystemProperty(Property.SYSTEM_HOME_PROPERTY));
    // Log properties related to redirection of derby.log
    String target = PropertyUtil.getSystemProperty(Property.ERRORLOG_STYLE_PROPERTY);
    if (target != null)
        logMsg(Property.ERRORLOG_STYLE_PROPERTY + "=" + target);
    target = PropertyUtil.getSystemProperty(Property.ERRORLOG_FILE_PROPERTY);
    if (target != null)
        logMsg(Property.ERRORLOG_FILE_PROPERTY + "=" + target);
    target = PropertyUtil.getSystemProperty(Property.ERRORLOG_METHOD_PROPERTY);
    if (target != null)
        logMsg(Property.ERRORLOG_METHOD_PROPERTY + "=" + target);
    target = PropertyUtil.getSystemProperty(Property.ERRORLOG_FIELD_PROPERTY);
    if (target != null)
        logMsg(Property.ERRORLOG_FIELD_PROPERTY + "=" + target);
    if (logBootTrace)
        Monitor.logThrowable(new Throwable("boot trace"));
    uf = null;
    CacheFactory cf = (CacheFactory) startSystemModule(org.apache.derby.shared.common.reference.Module.CacheFactory);
    // Initialize the page cache
    int pageCacheSize = getIntParameter(RawStoreFactory.PAGE_CACHE_SIZE_PARAMETER, null, RawStoreFactory.PAGE_CACHE_SIZE_DEFAULT, RawStoreFactory.PAGE_CACHE_SIZE_MINIMUM, RawStoreFactory.PAGE_CACHE_SIZE_MAXIMUM);
    pageCache = cf.newCacheManager(this, "PageCache", pageCacheSize / 2, pageCacheSize);
    // Initialize the container cache
    int fileCacheSize = getIntParameter(RawStoreFactory.CONTAINER_CACHE_SIZE_PARAMETER, null, RawStoreFactory.CONTAINER_CACHE_SIZE_DEFAULT, RawStoreFactory.CONTAINER_CACHE_SIZE_MINIMUM, RawStoreFactory.CONTAINER_CACHE_SIZE_MAXIMUM);
    containerCache = cf.newCacheManager(this, "ContainerCache", fileCacheSize / 2, fileCacheSize);
    // Register MBeans that allow users to monitor the page cache
    // and the container cache.
    pageCache.registerMBean(dataDirectory);
    containerCache.registerMBean(dataDirectory);
    if (create) {
        String noLog = startParams.getProperty(Property.CREATE_WITH_NO_LOG);
        inCreateNoLog = (noLog != null && Boolean.valueOf(noLog).booleanValue());
    }
    droppedTableStubInfo = new Hashtable<LogInstant, Object[]>();
    // writes during checkpoint
    if (Property.DURABILITY_TESTMODE_NO_SYNC.equalsIgnoreCase(PropertyUtil.getSystemProperty(Property.DURABILITY_PROPERTY))) {
        // - disable syncing of data during checkpoint.
        dataNotSyncedAtCheckpoint = true;
        // log message stating that derby.system.durability
        // is set to a mode, where syncs wont be forced and the
        // possible consequences of setting this mode
        Monitor.logMessage(MessageService.getTextMessage(MessageId.STORE_DURABILITY_TESTMODE_NO_SYNC, Property.DURABILITY_PROPERTY, Property.DURABILITY_TESTMODE_NO_SYNC));
    } else if (Performance.MEASURE) {
        // development build only feature, must by hand set the
        // Performance.MEASURE variable and rebuild.  Useful during
        // development to compare/contrast effect of syncing, release
        // users can use the above relaxed durability option to disable
        // all syncing.
        // debug only flag - disable syncing of data during checkpoint.
        dataNotSyncedAtCheckpoint = PropertyUtil.getSystemBoolean(Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT);
        if (dataNotSyncedAtCheckpoint)
            Monitor.logMessage("Warning: " + Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT + "set to true.");
    }
    fileHandler = new RFResource(this);
}
Also used : LogInstant(org.apache.derby.iapi.store.raw.log.LogInstant) PrivilegedActionException(java.security.PrivilegedActionException) UUIDFactory(org.apache.derby.iapi.services.uuid.UUIDFactory) WritableStorageFactory(org.apache.derby.io.WritableStorageFactory) IOException(java.io.IOException) Date(java.util.Date) StandardException(org.apache.derby.shared.common.error.StandardException) PersistentService(org.apache.derby.iapi.services.monitor.PersistentService) CacheFactory(org.apache.derby.iapi.services.cache.CacheFactory)

Example 10 with LogInstant

use of org.apache.derby.iapi.store.raw.log.LogInstant in project derby by apache.

the class BaseDataFileFactory method removeDroppedContainerFileStubs.

/**
 * Delete the stub files that are not required for recovery. A stub file
 * is not required to be around if the recovery is not going to see
 * any log record that belongs to that container. Since the stub files
 * are created as a post commit operation, they are not necessary during
 * undo operation of the recovery.
 *
 * To remove a stub file we have to be sure that it was created before the
 * redoLWM in the check point record. We can be sure that the stub is not
 * required if the log instant when it was created is less than the redoLWM.
 */
public void removeDroppedContainerFileStubs(LogInstant redoLWM) throws StandardException {
    if (droppedTableStubInfo != null) {
        synchronized (droppedTableStubInfo) {
            for (Enumeration<LogInstant> e = droppedTableStubInfo.keys(); e.hasMoreElements(); ) {
                LogInstant logInstant = e.nextElement();
                if (logInstant.lessThan(redoLWM)) {
                    Object[] removeInfo = droppedTableStubInfo.get(logInstant);
                    Object identity = removeInfo[1];
                    // delete the entry in the container cache.
                    Cacheable ccentry = containerCache.findCached(identity);
                    if (ccentry != null)
                        containerCache.remove(ccentry);
                    // delete the stub we don't require it during recovery
                    synchronized (this) {
                        actionFile = (StorageFile) removeInfo[0];
                        actionCode = DELETE_IF_EXISTS_ACTION;
                        try {
                            if (AccessController.doPrivileged(this) != null) {
                                // if we successfuly delete the file remove
                                // it from the hash table.
                                droppedTableStubInfo.remove(logInstant);
                            }
                        } catch (PrivilegedActionException pae) {
                        // DELETE_IF_EXISTS does not throw an exception
                        }
                    }
                }
            }
        }
    }
}
Also used : LogInstant(org.apache.derby.iapi.store.raw.log.LogInstant) Cacheable(org.apache.derby.iapi.services.cache.Cacheable) PrivilegedActionException(java.security.PrivilegedActionException)

Aggregations

LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)19 StandardException (org.apache.derby.shared.common.error.StandardException)8 IOException (java.io.IOException)7 PrivilegedActionException (java.security.PrivilegedActionException)2 PersistentService (org.apache.derby.iapi.services.monitor.PersistentService)2 TransactionId (org.apache.derby.iapi.store.raw.xact.TransactionId)2 LogCounter (org.apache.derby.impl.store.raw.log.LogCounter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Date (java.util.Date)1 Properties (java.util.Properties)1 CacheFactory (org.apache.derby.iapi.services.cache.CacheFactory)1 Cacheable (org.apache.derby.iapi.services.cache.Cacheable)1 Serviceable (org.apache.derby.iapi.services.daemon.Serviceable)1 ArrayInputStream (org.apache.derby.iapi.services.io.ArrayInputStream)1 Formatable (org.apache.derby.iapi.services.io.Formatable)1 UUIDFactory (org.apache.derby.iapi.services.uuid.UUIDFactory)1 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)1 LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)1