Ejemplo n.º 1
0
 /**
  * Starts cache generation for the current file.
  *
  * This is done by creating a file named by the original file name, prefixed
  * with '.generating'.
  *
  * @return bool false if the file is being generated, true if it is not
  */
 public function startCacheGeneration()
 {
     eZDebugSetting::writeDebug('kernel-clustering', "Starting cache generation", "dfs::startCacheGeneration( '{$this->filePath}' )");
     $generatingFilePath = $this->filePath . '.generating';
     try {
         $ret = self::$dbbackend->_startCacheGeneration($this->filePath, $generatingFilePath);
     } catch (RuntimeException $e) {
         eZDebug::writeError($e->getMessage());
         return false;
     }
     // generation granted
     if ($ret['result'] == 'ok') {
         eZClusterFileHandler::addGeneratingFile($this);
         $this->realFilePath = $this->filePath;
         $this->filePath = $generatingFilePath;
         $this->generationStartTimestamp = $ret['mtime'];
         return true;
     } elseif ($ret['result'] == 'ko') {
         return $ret['remaining'];
     } else {
         eZLog::write("An error occured starting cache generation on '{$generatingFilePath}'", 'cluster.log');
         return false;
     }
 }
Ejemplo n.º 2
0
    /**
     * Starts cache generation for the current file.
     *
     * This is done by creating a file named by the original file name, prefixed
     * with '.generating'.
     *
     * @return bool false if the file is being generated, true if it is not
     */
    public function startCacheGeneration()
    {
        $generatingFilePath = $this->filePath . '.generating';
        $ret = self::$dbbackend->_startCacheGeneration( $this->filePath, $generatingFilePath );

        // generation granted
        if ( $ret['result'] == 'ok' )
        {
            eZClusterFileHandler::addGeneratingFile( $this );
            $this->realFilePath = $this->filePath;
            $this->filePath = $generatingFilePath;
            $this->generationStartTimestamp = $ret['mtime'];
            return true;
        }
        // failure: the file is being generated
        elseif ( $ret['result'] == 'ko' )
        {
            return $ret['remaining'];
        }
        // unhandled error case, should not happen
        else
        {
            eZLog::write( "An error occured starting cache generation on '$generatingFilePath'", 'cluster.log' );
            return false;
        }
    }
Ejemplo n.º 3
0
    /**
     * Starts cache generation for the current file.
     *
     * This is done by creating a file named by the original file name, prefixed
     * with '.generating'.
     *
     * @todo add timeout handling...
     *
     * @return mixed true if generation lock was granted, an integer matching the
     *               time before the current generation times out
     */
    public function startCacheGeneration()
    {
        eZDebugSetting::writeDebug( "kernel-clustering", $this->filePath, __METHOD__ );

        $ret = true;

        $generatingFilePath = $this->filePath . '.generating';

        // the x flag will throw a warning if the file exists. Allows existence
        // check AND creation at the same time
        if ( !$fp = @fopen( $generatingFilePath, 'x' ) )
        {
            $directory = dirname( $generatingFilePath ) . DIRECTORY_SEPARATOR;

            // the directory we're trying to create the file in does not exist
            eZDebugSetting::writeDebug( 'kernel-clustering', $this->filePath . " creation failed, checking if '$directory' exists", __METHOD__ );

            if ( !file_exists( $directory ) )
            {
                eZDebugSetting::writeDebug( 'kernel-clustering', $this->filePath . " target directory does not exist, creating and trying again", __METHOD__ );

                if ( eZDir::mkdir( $directory, false, true ) )
                    eZDebugSetting::writeDebug( 'kernel-clustering', "Directory '$directory' created, trying to start generation again", __METHOD__ );
                else
                    eZDebugSetting::writeDebug( 'kernel-clustering', "Directory '$directory' failed to be created, it might have been created by another process", __METHOD__ );

                // we check again since the folder may have been created by another
                // process in between. Not likely, though.
                if ( !$fp = @fopen( $generatingFilePath, 'x' ) )
                {
                    $ret = $this->remainingCacheGenerationTime( $generatingFilePath );
                }
            }
            // directory exists, we now check for timeout
            else
            {
                // timeout check
                if ( $mtime = @filemtime( $generatingFilePath ) )
                {
                    $remainingGenerationTime = $this->remainingCacheGenerationTime( $generatingFilePath );
                    eZDebugSetting::writeDebug( 'kernel-clustering', "Remaining generation time: $remainingGenerationTime", __METHOD__ );
                    if ( $remainingGenerationTime < 0 )
                    {
                        eZDebugSetting::writeDebug( 'kernel-clustering', $this->filePath . " generating file exists, but generation has timedout, taking over", __METHOD__ );
                        touch( $generatingFilePath, time(), time() );
                    }
                    else
                    {
                        eZDebugSetting::writeDebug( 'kernel-clustering', $this->filePath . " failed opening file for writing, generation is underway", __METHOD__ );
                        $ret = $remainingGenerationTime;
                    }
                }
            }
        }

        // if the generation lock was granted, we can perform our specific file
        // operations: change the file name to the generation name, and store
        // required generating informations
        if ( $ret === true )
        {
            // $fp might not be a valid handle if timeout has occured
            if ( $fp )
                fclose( $fp );

            eZClusterFileHandler::addGeneratingFile( $this );
            $this->realFilePath = $this->filePath;
            $this->filePath = $generatingFilePath;
            $this->generationStartTimestamp = filemtime( $this->filePath );
        }

        return $ret;
    }
Ejemplo n.º 4
0
 /**
  * Starts cache generation for the current file.
  *
  * This is done by creating a file named by the original file name, prefixed
  * with '.generating'.
  *
  * @return bool false if the file is being generated, true if it is not
  **/
 public function startCacheGeneration()
 {
     $generatingFilePath = $this->filePath . '.generating';
     $ret = $this->backend->_startCacheGeneration($this->filePath, $generatingFilePath);
     // generation granted
     if ($ret['result'] == 'ok') {
         eZClusterFileHandler::addGeneratingFile($this);
         $this->realFilePath = $this->filePath;
         $this->filePath = $generatingFilePath;
         $this->generationStartTimestamp = $ret['mtime'];
         return true;
     } elseif ($ret['result'] == 'ko') {
         return $ret['remaining'];
     } else {
         eZLog::write("An error occured starting cache generation on '{$generatingFilePath}'", 'cluster.log');
         return false;
     }
 }