Package org.apache.derby.io

Examples of org.apache.derby.io.StorageFile


    <P> MT- read only
    @exception StandardException Cloudscape Standard Error Policy
  */
  public StorageFile getLogDirectory() throws StandardException
  {
    StorageFile logDir = null;

    logDir = logStorageFactory.newStorageFile( LogFactory.LOG_DIRECTORY_NAME);

        if (!privExists(logDir))
    {
      throw StandardException.newException(
                    SQLState.LOG_SEGMENT_NOT_EXIST, logDir.getPath());
    }

    return logDir;
  }
View Full Code Here


    checkCorrupt();

    long filenum = LogCounter.getLogFileNumber(logInstant);
    long filepos = LogCounter.getLogFilePosition(logInstant);

    StorageFile fileName = getLogFileName(filenum);
        if (!privExists(fileName))
    {
      if (SanityManager.DEBUG)
      {
        if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
          SanityManager.DEBUG(LogToFile.DBG_FLAG, fileName.getPath() + " does not exist");
      }

      return null;
    }


    StorageRandomAccessFile log = null;

    try
    {
            log = privRandomAccessFile(fileName, "r");

      // verify that the log file is of the right format
      if (!verifyLogFormat(log, filenum))
      {
        if (SanityManager.DEBUG)
        {
          if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
            SanityManager.DEBUG(LogToFile.DBG_FLAG, fileName.getPath() + " format mismatch");
        }

        log.close();
        log = null;
      }
      else
      {
        log.seek(filepos);
      }
    }
    catch (IOException ioe)
    {
      try
      {
        if (log != null)
        {
          log.close();
          log = null;
        }

        if (SanityManager.DEBUG)
        {
          SanityManager.THROWASSERT("cannot get to position " + filepos +
                        " for log file " + fileName.getPath(), ioe);
        }
      }
      catch (IOException ioe2)
      {}
      throw ioe;
View Full Code Here

                    // Make sure we find the log, do not assume
                    // it is OK that the log is not there because
                    // it could be a user typo(like when users edit
                    // service.properties to change the log device
                    // while restoring from backups using OS copy.
                    StorageFile checklogDir =
                        logStorageFactory.newStorageFile(
                                 LogFactory.LOG_DIRECTORY_NAME);
                    if (!privExists(checklogDir))
                    {
                        throw
                            StandardException.newException(
                            SQLState.LOG_FILE_NOT_FOUND, checklogDir.getPath());

                    }
                }
            }
        }
           
    //if user does not set the right value for the log buffer size,
    //default value is used instead.
    logBufferSize =  PropertyUtil.getSystemInt(org.apache.derby.iapi.reference.Property.LOG_BUFFER_SIZE,
                           LOG_BUFFER_SIZE_MIN,
                           LOG_BUFFER_SIZE_MAX,
                           DEFAULT_LOG_BUFFER_SIZE);
    jbmsVersion = Monitor.getMonitor().getEngineVersion();

   
    String logArchiveMode =
            startParams.getProperty(Property.LOG_ARCHIVE_MODE);
    logArchived = Boolean.valueOf(logArchiveMode).booleanValue();
   
    //get log factorty properties if any set in derby.properties
    getLogFactoryProperties(null);

    /* check if the storage factory supports write sync(rws).  If so, use it unless
     * derby.storage.fileSyncTransactionLog property is set true by user.
     */

    if (logStorageFactory.supportsRws())
        {
      //write sync can be used in the jvm that database is running on.
      //disable write sync if derby.storage.fileSyncTransactionLog is true
      isWriteSynced =
        !(PropertyUtil.getSystemBoolean(Property.FILESYNC_TRANSACTION_LOG));
        }
    else
    {
      isWriteSynced = false;
    }


        // If derby.system.durability=test is set,then set flag to
        // disable sync of log records at commit and log file before
        // data page makes it to disk
        if (Property.DURABILITY_TESTMODE_NO_SYNC.equalsIgnoreCase(
               PropertyUtil.getSystemProperty(Property.DURABILITY_PROPERTY)))
        {
        // disable syncing of log.
        logNotSynced = true;
          //if log not being synced;files shouldn't be open in write sync mode
        isWriteSynced = false
    }
        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. 

            logNotSynced =
                PropertyUtil.getSystemBoolean(
                    Property.STORAGE_LOG_NOT_SYNCED);

            if (logNotSynced)
            {
                isWriteSynced = false;
                Monitor.logMessage("Performance.logNotSynced = true");
            }
        }

    // try to access the log
    // if it doesn't exist, create it.
    // if it does exist, run recovery

    boolean createNewLog = create;

    if (SanityManager.DEBUG)
      SanityManager.ASSERT(fid != -1, "invalid log format Id");

    checkpointInstant = LogCounter.INVALID_LOG_INSTANT;
    try
    {
      StorageFile logControlFileName = getControlFileName();

      StorageFile logFile;

      if (!createNewLog)
      {
                if (privExists(logControlFileName))
        {
          checkpointInstant =
                        readControlFile(logControlFileName, startParams);

          // in case system was running previously with
                    // derby.system.durability=test then print a message
                    // to the derby log
                    if (wasDBInDurabilityTestModeNoSync)
                    {
                        // print message stating that the database was
                        // previously atleast at one time running with
                        // derby.system.durability=test mode
                        Monitor.logMessage(MessageService.getTextMessage(
                     MessageId.LOG_WAS_IN_DURABILITY_TESTMODE_NO_SYNC,
                     Property.DURABILITY_PROPERTY,
                            Property.DURABILITY_TESTMODE_NO_SYNC));
                    }
           
          if (checkpointInstant == LogCounter.INVALID_LOG_INSTANT &&
                    privExists(getMirrorControlFileName()))
                    {
            checkpointInstant =
                            readControlFile(
                                getMirrorControlFileName(), startParams);
                    }

        }
        else if (logDevice != null)
        {
          // Do not throw this error if logDevice is null because
          // in a read only configuration, it is acceptable
          // to not have a log directory.  But clearly, if the
          // logDevice property is set, then it should be there.
          throw StandardException.newException(
                            SQLState.LOG_FILE_NOT_FOUND,
                            logControlFileName.getPath());
        }

        if (checkpointInstant != LogCounter.INVALID_LOG_INSTANT)
          logFileNumber = LogCounter.getLogFileNumber(checkpointInstant);
        else
          logFileNumber = 1;

        logFile = getLogFileName(logFileNumber);

        // if log file is not there or if it is of the wrong format, create a
        // brand new log file and do not attempt to recover the database

                if (!privExists(logFile))
        {
          if (logDevice != null)
                    {
                        throw StandardException.newException(
                                SQLState.LOG_FILE_NOT_FOUND,
                                logControlFileName.getPath());
                    }

          logErrMsg(MessageService.getTextMessage(
                        MessageId.LOG_MAYBE_INCONSISTENT,
                        logFile.getPath()));

          createNewLog = true;
        }
        else if (!verifyLogFormat(logFile, logFileNumber))
        {
          Monitor.logTextMessage(MessageId.LOG_DELETE_INCOMPATIBLE_FILE, logFile);

          // blow away the log file if possible
                    if (!privDelete(logFile) && logFileNumber == 1)
                    {
                        logErrMsgForDurabilityTestModeNoSync();
            throw StandardException.newException(
                            SQLState.LOG_INCOMPATIBLE_FORMAT, dataDirectory);
                    }

          // If logFileNumber > 1, we are not going to write that
                    // file just yet.  Just leave it be and carry on.  Maybe
                    // when we get there it can be deleted.

          createNewLog = true;
        }
      }

      if (createNewLog)
      {
        // brand new log.  Start from log file number 1.

        // create or overwrite the log control file with an invalid
        // checkpoint instant since there is no checkpoint yet
        if (writeControlFile(logControlFileName,
                   LogCounter.INVALID_LOG_INSTANT))
        {
          firstLogFileNumber = 1;
          logFileNumber = 1;
          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON(TEST_MAX_LOGFILE_NUMBER))
            {
              // set the value to be two less than max possible
              // log number, test case will perform some ops to
              // hit the max number case.
              firstLogFileNumber =
                                LogCounter.MAX_LOGFILE_NUMBER -2;

              logFileNumber = LogCounter.MAX_LOGFILE_NUMBER -2;
            }
          }
          logFile = getLogFileName(logFileNumber);

                    if (privExists(logFile))
          {
            // this log file maybe there because the system may have
            // crashed right after a log switch but did not write
                        // out any log record
            Monitor.logTextMessage(
                            MessageId.LOG_DELETE_OLD_FILE, logFile);

                        if (!privDelete(logFile))
                        {
                            logErrMsgForDurabilityTestModeNoSync();
              throw StandardException.newException(
                                    SQLState.LOG_INCOMPATIBLE_FORMAT,
                                    dataDirectory);
                        }
          }

          // don't need to try to delete it, we know it isn't there
                    firstLog = privRandomAccessFile(logFile, "rw");

          if (!initLogFile(firstLog, logFileNumber, LogCounter.INVALID_LOG_INSTANT))
                    {
            throw StandardException.newException(
                            SQLState.LOG_SEGMENT_NOT_EXIST, logFile.getPath());
                    }

          endPosition = firstLog.getFilePointer();
          lastFlush = firstLog.getFilePointer();

View Full Code Here

   * immediately after the checkpoint before truncations of logs completed.
   * see bug no: 3519 , for more details.
   */

  private void deleteObsoleteLogfiles(){
    StorageFile logDir;
    //find the first  log file number that is  useful
    long firstLogNeeded = getFirstLogNeeded(currentCheckpoint);
        if (firstLogNeeded == -1)
      return;

        // when  backup is in progress, log files that are yet to
        // be copied to the backup should not be deleted,  even
        // if they are not required  for crash recovery.
        if(backupInProgress) {
            long logFileNeededForBackup = logFileToBackup;
            // check if the log file number is yet to be copied
            // to the backup is less than the log file required
            // for crash recovery, if it is then make the first
            // log file that should not be deleted is the log file
            // that is yet to  be copied to the backup. 
            if (logFileNeededForBackup < firstLogNeeded)
                firstLogNeeded = logFileNeededForBackup;
        }

    try{
      logDir = getLogDirectory();
    }catch (StandardException se)
    {
      if (SanityManager.DEBUG)
        if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
          SanityManager.DEBUG(DBG_FLAG, "error opening log segment dir");
      return;
    }
     
    String[] logfiles = privList(logDir);
    if (logfiles != null)
    {
      StorageFile uselessLogFile = null;
      long fileNumber;
      for(int i=0 ; i < logfiles.length; i++)
      {
        // delete the log files that are not needed any more
        if(logfiles[i].startsWith("log") && logfiles[i].endsWith(".dat"))
        {
          fileNumber = Long.parseLong(logfiles[i].substring(3, (logfiles[i].length() -4)));
          if(fileNumber < firstLogNeeded )
          {
            uselessLogFile = logStorageFactory.newStorageFile(logDir, logfiles[i]);
            if (privDelete(uselessLogFile))
            {
              if (SanityManager.DEBUG)
              {
                if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
                  SanityManager.DEBUG(DBG_FLAG, "truncating obsolete log file " + uselessLogFile.getPath());
              }
            }
            else
            {
              if (SanityManager.DEBUG)
              {
                if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
                  SanityManager.DEBUG(DBG_FLAG, "Fail to truncate obsolete log file " + uselessLogFile.getPath());
              }
            }
          }
        }
      }
View Full Code Here

            LogCounter.getLogFileNumber(checkpointInstant) + 1;

        // check if there is a log file after
        // the log file that has the last
        // checkpoint record.
        StorageFile logFileAfterCheckpoint =
            getLogFileName(logFileNumberAfterCheckpoint);
        // System.out.println("checking " + logFileAfterCheckpoint);
        if (privExists(logFileAfterCheckpoint))
            return false;
        else
View Full Code Here

        throws StandardException
    {
        long logFileNumberAfterCheckpoint =
            LogCounter.getLogFileNumber(checkpointInstant) + 1;

        StorageFile logFileAfterCheckpoint =
            getLogFileName(logFileNumberAfterCheckpoint);

        // System.out.println("deleting " + logFileAfterCheckpoint);

        if (privExists(logFileAfterCheckpoint))
View Full Code Here

  {
    if (SanityManager.DEBUG)
    {
      //long filenum = LogCounter.getLogFileNumber(logInstant);
      //      long filepos = LogCounter.getLogFilePosition(logInstant);
      StorageFile fileName = getLogFileName(filenum);
      StorageRandomAccessFile log = null;
      return privRandomAccessFile(fileName, "rw");
    }
   
    return null;
View Full Code Here

      }
   
      backupInProgress = true;
   
      // copy the control files.
      StorageFile fromFile;
      File toFile;
      // copy the log control file
      fromFile = getControlFileName();
      toFile = new File(toDir,fromFile.getName());
      if(!privCopyFile(fromFile, toFile))
      {
        throw StandardException.newException(
                    SQLState.RAWSTORE_ERROR_COPYING_FILE, fromFile, toFile);
      }

      // copy the log mirror control file
      fromFile = getMirrorControlFileName();
      toFile = new File(toDir,fromFile.getName());
      if(!privCopyFile(fromFile, toFile))
      {
        throw StandardException.newException(
                    SQLState.RAWSTORE_ERROR_COPYING_FILE, fromFile, toFile);
      }
View Full Code Here

        throws StandardException
  {

    while(logFileToBackup <= lastLogFileToBackup)
    {
      StorageFile fromFile = getLogFileName(logFileToBackup);
      File toFile = new File(toDir, fromFile.getName());
      if(!privCopyFile(fromFile, toFile))
      {
        throw StandardException.newException(
                    SQLState.RAWSTORE_ERROR_COPYING_FILE, fromFile, toFile);
      }
View Full Code Here

                        properties.getProperty(Property.LOG_DEVICE_AT_BACKUP);
        }
      }  
       
            getLogStorageFactory();
      StorageFile logDir;
      logDir = logStorageFactory.newStorageFile(
                             LogFactory.LOG_DIRECTORY_NAME);
       
      //remove the log directory in case of restoreFrom
      //if it exist, this happens if the log device is on seperate
      //location than the db home.
      if (isRestoreFrom && logDevice != null)
      {
        if(!privRemoveDirectory(logDir))
        {
          //it may be just a file, try deleting it
          if(!privDelete(logDir))
                    {
            throw StandardException.newException(
                            SQLState.UNABLE_TO_REMOVE_DATA_DIRECTORY,
                            getLogDirPath( logDir));
                    }
        }
      }

            // if it is a create/restore from backup,
            // create the log directory.
            if (isCreateFrom || isRestoreFrom) {
                createLogDirectory();
            }

      File backupLogDir = new File(backupPath, LogFactory.LOG_DIRECTORY_NAME);
      String[] logfilelist = privList(backupLogDir);
      if(logfilelist !=null)
      {
        for (int i = 0; i < logfilelist.length; i++)
        {
          File blogFile = new File(backupLogDir, logfilelist[i]);
          StorageFile clogFile = logStorageFactory.newStorageFile(logDir, logfilelist[i]);
          if(!privCopyFile(blogFile , clogFile))
          {
            throw
              StandardException.newException(SQLState.UNABLE_TO_COPY_LOG_FILE, blogFile, clogFile);
          }
View Full Code Here

TOP

Related Classes of org.apache.derby.io.StorageFile

Copyright © 2018 www.massapicom. 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.