Package org.apache.directory.server.log

Examples of org.apache.directory.server.log.LogAnchor


     * @throws IOException
     * @throws InvalidLogException
     */
    public void initLogManager() throws IOException, InvalidLogException
    {
        LogAnchor scanPoint = new LogAnchor();
        LogScanner scanner;
        UserLogRecord logRecord;
        LogFileManager.LogFileReader reader;

        // Read and verify control file
        boolean controlFileExists = true;
        try
        {
            this.readControlFile();
        }
        catch ( FileNotFoundException e )
        {
            controlFileExists = false;
        }

        if ( controlFileExists )
        {
            boolean invalidLog = false;

            // Set the min log anchor from the control file
            minLogAnchor.resetLogAnchor( controlFileRecord.minNeededLogFile,
                controlFileRecord.minNeededLogFileOffset, controlFileRecord.minNeededLSN );

            scanPoint.resetLogAnchor( minLogAnchor );

            logRecord = new UserLogRecord();
            scanner = new DefaultLogScanner( scanPoint, logFileManager );

            try
            {
                while ( scanner.getNextRecord( logRecord ) )
                {
                    // No need to do anything with the log record
                }
            }
            catch ( InvalidLogException e )
            {
                invalidLog = true;
            }
            finally
            {
                scanner.close();
            }

            long lastGoodLogFileNumber = scanner.getLastGoodFileNumber();
            long lastGoodLogFileOffset = scanner.getLastGoodOffset();
            currentLogFileNumber = lastGoodLogFileNumber;

            if ( ( lastGoodLogFileNumber < LogAnchor.MIN_LOG_NUMBER ) ||
                ( lastGoodLogFileOffset < LogAnchor.MIN_LOG_OFFSET ) )
            {
                throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
            }

            scanPoint.resetLogAnchor( lastGoodLogFileNumber, lastGoodLogFileOffset,
                LogAnchor.UNKNOWN_LSN );

            if ( anchorComparator.compare( scanPoint, minLogAnchor ) < 0 )
            {
                throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
View Full Code Here


    {
        long lsn;
        boolean appendedRecord = false;
        byte[] userBuffer = userRecord.getDataBuffer();
        int length = userRecord.getDataLength();
        LogAnchor userLogAnchor = userRecord.getLogAnchor();

        int recordSize = LogFileRecords.RECORD_HEADER_SIZE + LogFileRecords.RECORD_FOOTER_SIZE + length;

        appendLock.lock();
        try
        {
            lsn = logLSN++;

            if ( currentLogFile == null )
            {
                // We are just starting, get the current log file
                currentLogFile = logManager.switchToNextLogFile( null );
                appendedSize = currentLogFile.getLength();
            }

            if ( appendedSize > this.targetLogFileSize )
            {
                // Make sure everything outstanding goes to the current log file
                this.flush( lsn, null, 0, 0, true );

                currentLogFile = logManager.switchToNextLogFile( currentLogFile );
                appendedSize = currentLogFile.getLength();
            }

            if ( recordSize <= logBufferSize )
            {
                ByteBuffer writeHead = logBuffer.writeHead;

                while ( !appendedRecord )
                {
                    // First get the rewind count then the position to which the readhead advanced
                    int readHeadRewindCount = logBuffer.readHeadRewindCount.get();
                    int readHeadPosition = logBuffer.readHeadPosition;

                    if ( ( logBuffer.writeHeadRewindCount == readHeadRewindCount ) ||
                        ( ( logBuffer.writeHeadRewindCount == readHeadRewindCount + 1 ) &&
                        ( readHeadPosition < writeHead.position() ) ) )
                    {
                        if ( writeHead.remaining() >= recordSize )
                        {
                            this.writeHeader( writeHead, length, lsn );
                            writeHead.put( userBuffer, 0, length );
                            this.writeFooter( writeHead, 0 );
                            appendedRecord = true;
                        }
                        else
                        // ( writeHead.remaining() < recordSize )
                        {
                            if ( writeHead.remaining() >= LogFileRecords.RECORD_HEADER_SIZE )
                            {
                                // Write a skip record
                                this.writeHeader( writeHead, -1, -1 );
                            }

                            // rewind buffer now
                            writeHead.rewind();
                            logBuffer.writeHeadRewindCount++;
                        }
                    }
                    else
                    {
                        assert ( logBuffer.writeHeadRewindCount == ( readHeadRewindCount + 1 ) ) : "Unexpected sequence number for read/write heads:"
                            + logBuffer.writeHeadRewindCount +
                            " " + readHeadRewindCount;

                        if ( ( readHeadPosition - writeHead.position() ) > recordSize )
                        {
                            this.writeHeader( writeHead, length, lsn );
                            writeHead.put( userBuffer, 0, length );
                            this.writeFooter( writeHead, 0 );
                            appendedRecord = true;
                        }
                        else
                        {
                            this.flush( lsn, null, 0, 0, true );
                        }
                    }
                }

            }
            else
            {
                this.flush( lsn, userBuffer, 0, length, true );
            }

            userLogAnchor.resetLogAnchor( currentLogFile.logFileNumber(), appendedSize, lsn );
            this.appendedSize += recordSize;
        }
        finally
        {
            appendLock.unlock();
View Full Code Here

            // If we are here, then we successfully read the log record.
            // Set the read record's position, uptate last read good location
            // and then return
            fileOffset = currentLogFile.getOffset();

            LogAnchor userLogAnchor = logRecord.getLogAnchor();
            userLogAnchor.resetLogAnchor( currentLogFile.logFileNumber(), fileOffset - recordLength, lastReadLSN );

            prevLogFileOffset = fileOffset;
            prevLogFileNumber = currentLogFile.logFileNumber();
            prevLSN = lastReadLSN;
        }
View Full Code Here

TOP

Related Classes of org.apache.directory.server.log.LogAnchor

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.