Examples of RawTransaction


Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

                // allocate new context and associate new xact with it.
                ContextManager cm      = contextFactory.newContextManager();
                contextFactory.setCurrentContextManager(cm);

        try {
                RawTransaction rawtran =
                    startTransaction(
                        rawStoreFactory, cm,
                        AccessFactoryGlobals.USER_TRANS_NAME);

                if (ttab.getMostRecentPreparedRecoveredXact(rawtran))
                {
                    // found a prepared xact.  The reprepare() call will
                    // accumulate locks, and change the transaction table entry
                    // to not be "in-recovery" so that it won't show up again.
                    rawtran.reprepare();

                    if (SanityManager.DEBUG)
                        prepared_count++;
                }
                else
                {
                    // get rid of last transaction allocated.
                    rawtran.destroy();
                    break;
                }
        }
        finally
        {
View Full Code Here

Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

      backupDir = backupDirURL;


    // find the user transaction, it is necessary for online backup
    // to open the container through page cache
    RawTransaction t =
            xactFactory.findUserTransaction(this,
                ContextService.getFactory().getCurrentContextManager(),
                AccessFactoryGlobals.USER_TRANS_NAME);

    try {

            // check if  any backup blocking operations are in progress
            // in the same transaction backup is being executed? Backup is
            // not allowed if the transaction has uncommitted
            // unlogged operations that are blocking the backup.
           
            if (t.isBlockingBackup())
            {
                throw StandardException.newException(
                      SQLState.BACKUP_OPERATIONS_NOT_ALLOWED)
            }
View Full Code Here

Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

        // to encrypt the existing transactions logs.
        logFactory.checkpoint(this, dataFactory, xactFactory, true);

        // start a transaction that is to be used for encryting the database
        RawTransaction transaction =
            xactFactory.startTransaction(
                   this,
                    ContextService.getFactory().getCurrentContextManager(),
                    AccessFactoryGlobals.USER_TRANS_NAME);

        try
    {
     
            dataFactory.encryptAllContainers(transaction);

            // all the containers are (re) encrypted, now mark the database as
            // encrypted if a plain database is getting configured for encryption
            // or update the encryption the properties, in the
            // service.properties ..etc.

           
            if (SanityManager.DEBUG) {
                crashOnDebugFlag(TEST_REENCRYPT_CRASH_BEFORE_COMMT, reEncrypt);
            }

            // check if the checkpoint is currently in the last log file,
            // otherwise force a checkpoint and then do a log switch,
            // after setting up a new encryption key
            if (!logFactory.isCheckpointInLastLogFile())
            {
                // perfrom a checkpoint, this is a reference checkpoint
                // to find if the re(encryption) is complete.
                logFactory.checkpoint(this, dataFactory, xactFactory, true);
            }
               

            encryptDatabase = false;

            // let the log factory know that database is
            // (re) encrypted and ask it to flush the log,
            // before enabling encryption of the log with
            // the new key.
            logFactory.setDatabaseEncrypted(true);
           
            // let the log factory and data factory know that
            // database is encrypted.
            if (!reEncrypt) {
                // mark in the raw store that the database is
                // encrypted.
                databaseEncrypted = true;
                dataFactory.setDatabaseEncrypted();
            } else {
                // switch the encryption/decryption engine to the new ones.
                decryptionEngine = newDecryptionEngine; 
                encryptionEngine = newEncryptionEngine;
                currentCipherFactory = newCipherFactory;
            }

           
            // make the log factory ready to encrypt
            // the transaction log with the new encryption
            // key by switching to a new log file.
            // If re-encryption is aborted for any reason,
            // this new log file will be deleted, during
            // recovery.

            logFactory.startNewLogFile();

            // mark that re-encryption is in progress in the
            // service.properties, so that (re) encryption
            // changes that can not be undone using the transaction
            // log can be un-done before recovery starts.
            // (like the changes to service.properties and
            // any log files the can not be understood by the
            // old encryption key), incase engine crashes
            // after this point.

            // if the crash occurs before this point, recovery
            // will rollback the changes using the transaction
            // log.

            properties.put(RawStoreFactory.DB_ENCRYPTION_STATUS,
                           String.valueOf(
                               RawStoreFactory.DB_ENCRYPTION_IN_PROGRESS));

            if (reEncrypt)
            {
                // incase re-encryption, save the old
                // encryption related properties, before
                // doing updates with new values.

                if (externalKeyEncryption)
                {
                    // save the current copy of verify key file.
                    StorageFile verifyKeyFile =
                        storageFactory.newStorageFile(
                                 Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE);
                    StorageFile oldVerifyKeyFile =
                        storageFactory.newStorageFile(
                          RawStoreFactory.CRYPTO_OLD_EXTERNAL_KEY_VERIFY_FILE);

                    if(!privCopyFile(verifyKeyFile, oldVerifyKeyFile))
                        throw StandardException.
                            newException(SQLState.RAWSTORE_ERROR_COPYING_FILE,
                                         verifyKeyFile, oldVerifyKeyFile);

                    // update the verify key file with the new key info.
                    currentCipherFactory.verifyKey(reEncrypt,
                                                   storageFactory,
                                                   properties);
                } else
                {
                    // save the current generated encryption key
                    String keyString =
                        properties.getProperty(
                                               RawStoreFactory.ENCRYPTED_KEY);
                    if (keyString != null)
                        properties.put(RawStoreFactory.OLD_ENCRYPTED_KEY,
                                       keyString);
                }
            } else
            {
                // save the encryption block size;
                properties.put(RawStoreFactory.ENCRYPTION_BLOCKSIZE,
                               String.valueOf(encryptionBlockSize));
            }

            // save the new encryption properties into service.properties
            currentCipherFactory.saveProperties(properties) ;
            if (SanityManager.DEBUG) {
                crashOnDebugFlag(
                                 TEST_REENCRYPT_CRASH_AFTER_SWITCH_TO_NEWKEY,
                                 reEncrypt);
            }

            // commit the transaction that is used to
            // (re) encrypt the database. Note that
            // this will be logged with newly generated
            // encryption key in the new log file created
            // above.
            transaction.commit();

            if (SanityManager.DEBUG) {
                crashOnDebugFlag(TEST_REENCRYPT_CRASH_AFTER_COMMT,
                                 reEncrypt);
            }

            // force the checkpoint with new encryption key.
            logFactory.checkpoint(this, dataFactory, xactFactory, true);

            if (SanityManager.DEBUG) {
                crashOnDebugFlag(TEST_REENCRYPT_CRASH_AFTER_CHECKPOINT,
                                 reEncrypt);
            }

            // once the checkpont makes it to the log, re-encrption
            // is complete. only cleanup is remaining ; update the
            // re-encryption status flag to cleanup.
            properties.put(RawStoreFactory.DB_ENCRYPTION_STATUS,
                           String.valueOf(
                               RawStoreFactory.DB_ENCRYPTION_IN_CLEANUP));

            // database is (re)encrypted successfuly,
            // remove the old version of the container files.
            dataFactory.removeOldVersionOfContainers(false);
               
            if (reEncrypt)
            {
                if (externalKeyEncryption)
                {
                    // remove the saved copy of the verify.key file
                    StorageFile oldVerifyKeyFile =
                        storageFactory.newStorageFile(
                          RawStoreFactory.CRYPTO_OLD_EXTERNAL_KEY_VERIFY_FILE);
                    if (!privDelete(oldVerifyKeyFile))
                        throw StandardException.newException(
                                    SQLState.UNABLE_TO_DELETE_FILE,
                                    oldVerifyKeyFile);
                } else
                {
                    // remove the old encryption key property.
                    properties.remove(RawStoreFactory.OLD_ENCRYPTED_KEY);
                }
            }

            // (re) encrypion is done,  remove the (re)
            // encryption status property.

            properties.remove(RawStoreFactory.DB_ENCRYPTION_STATUS);

            // close the transaction.
            transaction.close();

        } catch (StandardException se) {

            throw StandardException.newException(
                      (reEncrypt ? SQLState.DATABASE_REENCRYPTION_FAILED :
View Full Code Here

Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

          redoScan = (StreamLogScan)
                        openForwardsScan(start, (LogInstant)null);
        }

        // open a transaction that is used for redo and rollback
        RawTransaction recoveryTransaction =
                    tf.startTransaction(
                        rawStoreFactory,
                        ContextService.getFactory().getCurrentContextManager(),
                        AccessFactoryGlobals.USER_TRANS_NAME);

        // make this transaction aware that it is a recovery transaction
        // and don't spew forth post commit work while replaying the log
        recoveryTransaction.recoveryTransaction();

        /////////////////////////////////////////////////////////////
        //
        //  Redo loop - in FileLogger
        //
        /////////////////////////////////////////////////////////////

        //
        // set log factory state to inRedo so that if redo caused any
        // dirty page to be written from the cache, it won't flush the
        // log since the end of the log has not been determined and we
        // know the log record that caused the page to change has
        // already been written to the log.  We need the page write to
        // go thru the log factory because if the redo has a problem,
        // the log factory is corrupt and the only way we know not to
        // write out the page in a checkpoint is if it check with the
        // log factory, and that is done via a flush - we use the WAL
        // protocol to stop corrupt pages from writing to the disk.
        //
        inRedo = true

        long logEnd =
                    logger.redo(
                        recoveryTransaction, tf, redoScan, redoLWM,
                        ttabInstant);

        inRedo = false;
       

                // Replication slave: When recovery has completed the
                // redo pass, the database is no longer in replication
                // slave mode and only the recover thread will access
                // this object until recover has complete. We
                // therefore do not need two versions of the log file
                // number anymore. From this point on, logFileNumber
                // is used for all references to the current log file
                // number; bootTimeLogFileNumber is no longer used.
                logFileNumber = bootTimeLogFileNumber;
       
        // if we are only interested in dumping the log, don't alter
        // the database and prevent anyone from using the log
        if (SanityManager.DEBUG)
        {
          if (SanityManager.DEBUG_ON(LogToFile.DUMP_LOG_ONLY))
          {
            Monitor.logMessage("_____________________________________________________");
            Monitor.logMessage("\n\t\t Log dump finished");
            Monitor.logMessage("_____________________________________________________");
                        // just in case, it has not been set anyway
            logOut = null;

            return;
          }
        }


        /////////////////////////////////////////////////////////////
        //
        // determine where the log ends
        //
        /////////////////////////////////////////////////////////////
        StorageRandomAccessFile theLog = null;


        // if logend == LogCounter.INVALID_LOG_SCAN, that means there
                // is no log record in the log - most likely it is corrupted in
                // some way ...
        if (logEnd == LogCounter.INVALID_LOG_INSTANT)
        {
          Monitor.logTextMessage(MessageId.LOG_LOG_NOT_FOUND);

          StorageFile logFile = getLogFileName(logFileNumber);

                    if (privExists(logFile))
          {
            // if we can delete this strange corrupted file, do so,
            // otherwise, skip it
                        if (!privDelete(logFile))
            {
              logFile = getLogFileName(++logFileNumber);
            }
          }
          IOException accessException = null;
          try
          {
                        theLog =   privRandomAccessFile(logFile, "rw");
          }
          catch (IOException ioe)
          {
            theLog = null;
            accessException = ioe;
          }

                    if (theLog == null || !privCanWrite(logFile))
          {
            if (theLog != null)
              theLog.close();

            theLog = null;
            Monitor.logTextMessage(MessageId.LOG_CHANGED_DB_TO_READ_ONLY);
            if (accessException != null)
              Monitor.logThrowable(accessException);
            ReadOnlyDB = true;
          }
          else
          {
            try
            {
              // no previous log file or previous log position
              if (!initLogFile(
                                    theLog, logFileNumber,
                                    LogCounter.INVALID_LOG_INSTANT))
                            {
                throw markCorrupt(
                                    StandardException.newException(
                                        SQLState.LOG_SEGMENT_NOT_EXIST,
                                        logFile.getPath()));
                            }
            }
            catch (IOException ioe)
            {
              throw markCorrupt(
                                StandardException.newException(
                                    SQLState.LOG_IO_ERROR, ioe));
            }

                        // successfully init'd the log file - set up markers,
                        // and position at the end of the log.
            endPosition = theLog.getFilePointer();
            lastFlush   = endPosition;
           
            //if write sync is true , prellocate the log file
            //and reopen the file in rwd mode.
            if(isWriteSynced)
            {
              //extend the file by wring zeros to it
              preAllocateNewLogFile(theLog);
              theLog.close();
              theLog = openLogFileInWriteMode(logFile);
              //postion the log at the current end postion
              theLog.seek(endPosition);
            }
           
            if (SanityManager.DEBUG)
            {
              SanityManager.ASSERT(
                                endPosition == LOG_FILE_HEADER_SIZE,
                                "empty log file has wrong size");
            }
           
            //because we already incrementing the log number
            //here, no special log switch required for
            //backup recoveries.
            logSwitchRequired = false;
          }
        }
        else
        {
          // logEnd is the instant of the next log record in the log
          // it is used to determine the last known good position of
          // the log
          logFileNumber = LogCounter.getLogFileNumber(logEnd);

          ReadOnlyDB = df.isReadOnly();

          StorageFile logFile = getLogFileName(logFileNumber);

          if (!ReadOnlyDB)
          {
            // if datafactory doesn't think it is readonly, we can
            // do some futher test of our own
            IOException accessException = null;
            try
            {
              if(isWriteSynced)
                theLog = openLogFileInWriteMode(logFile);
              else
                theLog = privRandomAccessFile(logFile, "rw");
            }
            catch (IOException ioe)
            {
              theLog = null;
                            accessException = ioe;
            }
                        if (theLog == null || !privCanWrite(logFile))
            {
              if (theLog != null)
                theLog.close();
              theLog = null;
              Monitor.logTextMessage(MessageId.LOG_CHANGED_DB_TO_READ_ONLY);
              if (accessException != null)
                Monitor.logThrowable(accessException)
              ReadOnlyDB = true;
                     
            }
          }

          if (!ReadOnlyDB)
          {
            endPosition = LogCounter.getLogFilePosition(logEnd);

            //
            // The end of the log is at endPosition.  Which is where
            // the next log should be appending.
            //
            // if the last log record ends before the end of the
                        // log file, then this log file has a fuzzy end.
                        // Zap all the bytes to between endPosition to EOF to 0.
            //
            // the end log marker is 4 bytes (of zeros)
            //
            // if endPosition + 4 == logOut.length, we have a
                        // properly terminated log file
            //
            // if endPosition + 4 is > logOut.length, there are 0,
                        // 1, 2, or 3 bytes of 'fuzz' at the end of the log. We
                        // can ignore that because it is guaranteed to be
                        // overwritten by the next log record.
            //
            // if endPosition + 4 is < logOut.length, we have a
                        // partial log record at the end of the log.
            //
            // We need to overwrite all of the incomplete log
                        // record, because if we start logging but cannot
                        // 'consume' all the bad log, then the log will truly
                        // be corrupted if the next 4 bytes (the length of the
                        // log record) after that is small enough that the next
                        // time the database is recovered, it will be
                        // interpreted that the whole log record is in the log
                        // and will try to objectify, only to get classNotFound
                        // error or worse.
            //

            //find out if log had incomplete log records at the end.
            if (redoScan.isLogEndFuzzy())
            {
              theLog.seek(endPosition);
              long eof = theLog.length();

              Monitor.logTextMessage(MessageId.LOG_INCOMPLETE_LOG_RECORD,
                logFile, new Long(endPosition), new Long(eof));

              /* Write zeros from incomplete log record to end of file */
              long nWrites = (eof - endPosition)/logBufferSize;
              int rBytes = (int)((eof - endPosition) % logBufferSize);
              byte zeroBuf[]= new byte[logBufferSize];
             
              //write the zeros to file
              while(nWrites-- > 0)
                theLog.write(zeroBuf);
              if(rBytes !=0)
                theLog.write(zeroBuf, 0, rBytes);
             
              if(!isWriteSynced)
                syncFile(theLog);
            }

            if (SanityManager.DEBUG)
            {
              if (theLog.length() != endPosition)
              {
                SanityManager.ASSERT(
                                    theLog.length() > endPosition,
                                    "log end > log file length, bad scan");
              }
            }

            // set the log to the true end position,
                        // and not the end of the file

            lastFlush = endPosition;
            theLog.seek(endPosition);
          }
        }

        if (theLog != null)
          logOut = new LogAccessFile(this, theLog, logBufferSize);
       
        if(logSwitchRequired)
          switchLogFile();


        boolean noInFlightTransactions = tf.noActiveUpdateTransaction();

        if (ReadOnlyDB)
        {
          // in the unlikely event that someone detects we are
          // dealing with a read only db, check to make sure the
          // database is quiesce when it was copied with no unflushed
          // dirty buffer
          if (!noInFlightTransactions)
                    {
            throw StandardException.newException(
                                SQLState.LOG_READ_ONLY_DB_NEEDS_UNDO);
                    }
        }

        /////////////////////////////////////////////////////////////
        //
        // Undo loop - in transaction factory.  It just gets one
        // transaction at a time from the transaction table and calls
        // undo, no different from runtime.
        //
        /////////////////////////////////////////////////////////////

                if (SanityManager.DEBUG)
                {
                    if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
                        SanityManager.DEBUG(LogToFile.DBG_FLAG,
                            "About to call undo(), transaction table =" +
                            tf.getTransactionTable());
                }

        if (!noInFlightTransactions)
        {
          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
              SanityManager.DEBUG(LogToFile.DBG_FLAG,
                                "In recovery undo, rollback inflight transactions");
          }

          tf.rollbackAllTransactions(recoveryTransaction, rawStoreFactory);

          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
              SanityManager.DEBUG(
                                LogToFile.DBG_FLAG, "finish recovery undo,");
          }
        }
        else
        {
          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
              SanityManager.DEBUG(LogToFile.DBG_FLAG,
                                "No in flight transaction, no recovery undo work");
          }
        }

        /////////////////////////////////////////////////////////////
        //
        // XA prepared xact loop - in transaction factory.  At this
                // point only prepared transactions should be left in the
                // transaction table, all others should have been aborted or
                // committed and removed from the transaction table.  It just
                // gets one transaction at a time from the transaction table,
                // creates a real context and transaction, reclaims locks,
                // and leaves the new xact in the transaction table.
        //
        /////////////////////////////////////////////////////////////

                if (SanityManager.DEBUG)
                {
                    if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
                        SanityManager.DEBUG(LogToFile.DBG_FLAG,
                            "About to call rePrepare(), transaction table =" +
                            tf.getTransactionTable());
                }

                tf.handlePreparedXacts(rawStoreFactory);

                if (SanityManager.DEBUG)
                {
                    if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
                        SanityManager.DEBUG(LogToFile.DBG_FLAG,
                            "Finished rePrepare(), transaction table =" +
                            tf.getTransactionTable());
                }

        /////////////////////////////////////////////////////////////
        //
        // End of recovery.
        //
        /////////////////////////////////////////////////////////////

        // recovery is finished.  Close the transaction
        recoveryTransaction.close();


        // notify the dataFactory that recovery is completed,
        // but before the checkpoint is written.
        dataFactory.postRecovery();
View Full Code Here

Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

          redoScan = (StreamLogScan)
                        openForwardsScan(start, (LogInstant)null);
        }

        // open a transaction that is used for redo and rollback
        RawTransaction recoveryTransaction =
                    tf.startTransaction(
                        rsf,
                        ContextService.getFactory().getCurrentContextManager(),
                        AccessFactoryGlobals.USER_TRANS_NAME);

        // make this transaction aware that it is a recovery transaction
        // and don't spew forth post commit work while replaying the log
        recoveryTransaction.recoveryTransaction();

        /////////////////////////////////////////////////////////////
        //
        //  Redo loop - in FileLogger
        //
        /////////////////////////////////////////////////////////////

        //
        // set log factory state to inRedo so that if redo caused any
        // dirty page to be written from the cache, it won't flush the
        // log since the end of the log has not been determined and we
        // know the log record that caused the page to change has
        // already been written to the log.  We need the page write to
        // go thru the log factory because if the redo has a problem,
        // the log factory is corrupt and the only way we know not to
        // write out the page in a checkpoint is if it check with the
        // log factory, and that is done via a flush - we use the WAL
        // protocol to stop corrupt pages from writing to the disk.
        //
        inRedo = true

        long logEnd =
                    logger.redo(
                        recoveryTransaction, tf, redoScan, redoLWM,
                        ttabInstant);

        inRedo = false;
       

       
        // if we are only interested in dumping the log, don't alter
        // the database and prevent anyone from using the log
        if (SanityManager.DEBUG)
        {
          if (SanityManager.DEBUG_ON(LogToFile.DUMP_LOG_ONLY))
          {
            Monitor.logMessage("_____________________________________________________");
            Monitor.logMessage("\n\t\t Log dump finished");
            Monitor.logMessage("_____________________________________________________");
                        // just in case, it has not been set anyway
            logOut = null;

            return;
          }
        }


        /////////////////////////////////////////////////////////////
        //
        // determine where the log ends
        //
        /////////////////////////////////////////////////////////////
        StorageRandomAccessFile theLog = null;


        // if logend == LogCounter.INVALID_LOG_SCAN, that means there
                // is no log record in the log - most likely it is corrupted in
                // some way ...
        if (logEnd == LogCounter.INVALID_LOG_INSTANT)
        {
          Monitor.logTextMessage(MessageId.LOG_LOG_NOT_FOUND);

          StorageFile logFile = getLogFileName(logFileNumber);

                    if (privExists(logFile))
          {
            // if we can delete this strange corrupted file, do so,
            // otherwise, skip it
                        if (!privDelete(logFile))
            {
              logFile = getLogFileName(++logFileNumber);
            }
          }

          try
          {
                        theLog =   privRandomAccessFile(logFile, "rw");
          }
          catch (IOException ioe)
          {
            theLog = null;
          }

                    if (theLog == null || !privCanWrite(logFile))
          {
            if (theLog != null)
              theLog.close();

            theLog = null;

            ReadOnlyDB = true;
          }
          else
          {
            try
            {
              // no previous log file or previous log position
              if (!initLogFile(
                                    theLog, logFileNumber,
                                    LogCounter.INVALID_LOG_INSTANT))
                            {
                throw markCorrupt(
                                    StandardException.newException(
                                        SQLState.LOG_SEGMENT_NOT_EXIST,
                                        logFile.getPath()));
                            }
            }
            catch (IOException ioe)
            {
              throw markCorrupt(
                                StandardException.newException(
                                    SQLState.LOG_IO_ERROR, ioe));
            }

                        // successfully init'd the log file - set up markers,
                        // and position at the end of the log.
            endPosition = theLog.getFilePointer();
            lastFlush   = endPosition;
           
            //if write sync is true , prellocate the log file
            //and reopen the file in rwd mode.
            if(isWriteSynced)
            {
              //extend the file by wring zeros to it
              preAllocateNewLogFile(theLog);
              theLog.close();
              theLog = openLogFileInWriteMode(logFile);
              //postion the log at the current end postion
              theLog.seek(endPosition);
            }
           
            if (SanityManager.DEBUG)
            {
              SanityManager.ASSERT(
                                endPosition == LOG_FILE_HEADER_SIZE,
                                "empty log file has wrong size");
            }
           
            //because we already incrementing the log number
            //here, no special log switch required for
            //backup recoveries.
            logSwitchRequired = false;
          }
        }
        else
        {
          // logEnd is the instant of the next log record in the log
          // it is used to determine the last known good position of
          // the log
          logFileNumber = LogCounter.getLogFileNumber(logEnd);

          ReadOnlyDB = df.isReadOnly();

          StorageFile logFile = getLogFileName(logFileNumber);

          if (!ReadOnlyDB)
          {
            // if datafactory doesn't think it is readonly, we can
            // do some futher test of our own
            try
            {
              if(isWriteSynced)
                theLog = openLogFileInWriteMode(logFile);
              else
                theLog = privRandomAccessFile(logFile, "rw");
            }
            catch (IOException ioe)
            {
              theLog = null;
            }
                        if (theLog == null || !privCanWrite(logFile))
            {
              if (theLog != null)
                theLog.close();
              theLog = null;

              ReadOnlyDB = true;
            }
          }

          if (!ReadOnlyDB)
          {
            endPosition = LogCounter.getLogFilePosition(logEnd);

            //
            // The end of the log is at endPosition.  Which is where
            // the next log should be appending.
            //
            // if the last log record ends before the end of the
                        // log file, then this log file has a fuzzy end.
                        // Zap all the bytes to between endPosition to EOF to 0.
            //
            // the end log marker is 4 bytes (of zeros)
            //
            // if endPosition + 4 == logOut.length, we have a
                        // properly terminated log file
            //
            // if endPosition + 4 is > logOut.length, there are 0,
                        // 1, 2, or 3 bytes of 'fuzz' at the end of the log. We
                        // can ignore that because it is guaranteed to be
                        // overwritten by the next log record.
            //
            // if endPosition + 4 is < logOut.length, we have a
                        // partial log record at the end of the log.
            //
            // We need to overwrite all of the incomplete log
                        // record, because if we start logging but cannot
                        // 'consume' all the bad log, then the log will truly
                        // be corrupted if the next 4 bytes (the length of the
                        // log record) after that is small enough that the next
                        // time the database is recovered, it will be
                        // interpreted that the whole log record is in the log
                        // and will try to objectify, only to get classNotFound
                        // error or worse.
            //

            //find out if log had incomplete log records at the end.
            if (redoScan.isLogEndFuzzy())
            {
              theLog.seek(endPosition);
              long eof = theLog.length();

              Monitor.logTextMessage(MessageId.LOG_INCOMPLETE_LOG_RECORD,
                logFile, new Long(endPosition), new Long(eof));

              /* Write zeros from incomplete log record to end of file */
              long nWrites = (eof - endPosition)/logBufferSize;
              int rBytes = (int)((eof - endPosition) % logBufferSize);
              byte zeroBuf[]= new byte[logBufferSize];
             
              //write the zeros to file
              while(nWrites-- > 0)
                theLog.write(zeroBuf);
              if(rBytes !=0)
                theLog.write(zeroBuf, 0, rBytes);
             
              if(!isWriteSynced)
                syncFile(theLog);
            }

            if (SanityManager.DEBUG)
            {
              if (theLog.length() != endPosition)
              {
                SanityManager.ASSERT(
                                    theLog.length() > endPosition,
                                    "log end > log file length, bad scan");
              }
            }

            // set the log to the true end position,
                        // and not the end of the file

            lastFlush = endPosition;
            theLog.seek(endPosition);
          }
        }

        if (theLog != null)
          logOut = new LogAccessFile(this, theLog, logBufferSize);
       
        if(logSwitchRequired)
          switchLogFile();


        boolean noInFlightTransactions = tf.noActiveUpdateTransaction();

        if (ReadOnlyDB)
        {
          // in the unlikely event that someone detects we are
          // dealing with a read only db, check to make sure the
          // database is quiesce when it was copied with no unflushed
          // dirty buffer
          if (!noInFlightTransactions)
                    {
            throw StandardException.newException(
                                SQLState.LOG_READ_ONLY_DB_NEEDS_UNDO);
                    }
        }

        /////////////////////////////////////////////////////////////
        //
        // Undo loop - in transaction factory.  It just gets one
        // transaction at a time from the transaction table and calls
        // undo, no different from runtime.
        //
        /////////////////////////////////////////////////////////////

                if (SanityManager.DEBUG)
                {
                    if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
                        SanityManager.DEBUG(LogToFile.DBG_FLAG,
                            "About to call undo(), transaction table =" +
                            tf.getTransactionTable());
                }

        if (!noInFlightTransactions)
        {
          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
              SanityManager.DEBUG(LogToFile.DBG_FLAG,
                                "In recovery undo, rollback inflight transactions");
          }

          tf.rollbackAllTransactions(recoveryTransaction, rsf);

          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
              SanityManager.DEBUG(
                                LogToFile.DBG_FLAG, "finish recovery undo,");
          }
        }
        else
        {
          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
              SanityManager.DEBUG(LogToFile.DBG_FLAG,
                                "No in flight transaction, no recovery undo work");
          }
        }

        /////////////////////////////////////////////////////////////
        //
        // XA prepared xact loop - in transaction factory.  At this
                // point only prepared transactions should be left in the
                // transaction table, all others should have been aborted or
                // committed and removed from the transaction table.  It just
                // gets one transaction at a time from the transaction table,
                // creates a real context and transaction, reclaims locks,
                // and leaves the new xact in the transaction table.
        //
        /////////////////////////////////////////////////////////////

                if (SanityManager.DEBUG)
                {
                    if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
                        SanityManager.DEBUG(LogToFile.DBG_FLAG,
                            "About to call rePrepare(), transaction table =" +
                            tf.getTransactionTable());
                }

                tf.handlePreparedXacts(rsf);

                if (SanityManager.DEBUG)
                {
                    if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
                        SanityManager.DEBUG(LogToFile.DBG_FLAG,
                            "Finished rePrepare(), transaction table =" +
                            tf.getTransactionTable());
                }

        /////////////////////////////////////////////////////////////
        //
        // End of recovery.
        //
        /////////////////////////////////////////////////////////////

        // recovery is finished.  Close the transaction
        recoveryTransaction.close();


        // notify the dataFactory that recovery is completed,
        // but before the checkpoint is written.
        dataFactory.postRecovery();
View Full Code Here

Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

        // TODO (mikem) - should a global scratch variable be used?

        // this is an overflow page purge, no need to lock the head row (it
        // has already been locked, hopefully).  No need to check for long rows
        // (they have already been deleted, hopefully).
        RawTransaction  t           = owner.getTransaction();
        int[]           recordId    = new int[1];

        recordId[0]                 = getHeaderAtSlot(slot).getId();

        owner.getActionSet().actionPurge(t, this, slot, 1, recordId, needDataLogged);
View Full Code Here

Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

                // that is being updated.
                Page firstPageOnColumnChain = getOverflowPage(overflowPage);
                PageTimeStamp ts = firstPageOnColumnChain.currentTimeStamp();
                firstPageOnColumnChain.unlatch();

                RawTransaction rxact = (RawTransaction)owner.getTransaction();

                ReclaimSpace work =
                    new ReclaimSpace(ReclaimSpace.COLUMN_CHAIN,
                                headRowHandle,
                                fieldId, // long column about to be orphaned by update
                                overflowPage, // page where the long column starts
                                overflowId, // record Id of the beginning of the long column
                                ts,
                                rxact.getDataFactory(), true);

                rxact.addPostCommitWork(work);

                rawDataIn.setPosition(saveOffset); // Just to be safe, reset data stream
            }

View Full Code Here

Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

        // Back to the head page.  Get rid of all reserved space in the entire
        // row post commit.
        if (rowHasReservedSpace)
        {
            RawTransaction rxact = (RawTransaction)owner.getTransaction();

            ReclaimSpace work =
                new ReclaimSpace(ReclaimSpace.ROW_RESERVE,
                                 headRowHandle,
                                 rxact.getDataFactory(), true);
            rxact.addPostCommitWork(work);
        }
    }
View Full Code Here

Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

    }

    if (arg.equals(RawTransaction.COMMIT) ||
            arg.equals(RawTransaction.ABORT)) {

      RawTransaction xact = (RawTransaction) obj;

      try {

        if (this.isStreamContainer)
          xact.dropStreamContainer(
                        identity.getSegmentId(), identity.getContainerId());
        else
          xact.dropContainer(identity);

      } catch (StandardException se) {

        xact.setObserverException(se);

      }

      obj.deleteObserver(this);

            // DERBY-3993
            // make sure any observer that may have been added by either
            // dropContainer() or dropStreamContainer() is also handled.
            // The calling notifyObservers() call from Xact.doComplete()
            // may not "see" new observers added during processing of the
            // initial observer list.
            xact.notifyObservers(arg);
    }
  }
View Full Code Here

Examples of org.apache.derby.iapi.store.raw.xact.RawTransaction

        // TODO (mikem) - should a global scratch variable be used?

    // this is an overflow page purge, no need to lock the head row (it
    // has already been locked, hopefully).  No need to check for long rows
    // (they have already been deleted, hopefully).
    RawTransaction  t           = owner.getTransaction();
    int[]           recordId    = new int[1];

    recordId[0]                 = getHeaderAtSlot(slot).getId();

    owner.getActionSet().actionPurge(t, this, slot, 1, recordId, needDataLogged);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.