directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r1178150 - /directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/log/impl/LogFlushManager.java
Date Sun, 02 Oct 2011 08:45:22 GMT
Author: felixk
Date: Sun Oct  2 08:45:22 2011
New Revision: 1178150

URL: http://svn.apache.org/viewvc?rev=1178150&view=rev
Log:
In case of thrown Exception in between the add try finally block the file would stay lock
otherwise

Modified:
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/log/impl/LogFlushManager.java

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/log/impl/LogFlushManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/log/impl/LogFlushManager.java?rev=1178150&r1=1178149&r2=1178150&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/log/impl/LogFlushManager.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/log/impl/LogFlushManager.java
Sun Oct  2 08:45:22 2011
@@ -114,92 +114,96 @@ class LogFlushManager
         int recordSize = LogFileRecords.RECORD_HEADER_SIZE + LogFileRecords.RECORD_FOOTER_SIZE
+ length;
         
         appendLock.lock();
-        
-        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 )
+        try
         {
-            // Make sure everything outstanding goes to the current log file
-            this.flush( lsn, null, 0, 0, true);
+            lsn = logLSN++;
             
-            currentLogFile = logManager.switchToNextLogFile( currentLogFile );
-            appendedSize = currentLogFile.getLength();
-        }
-        
-        if ( recordSize <= logBufferSize )
-        {
-            ByteBuffer writeHead = logBuffer.writeHead;
+            if ( currentLogFile == null )
+            {
+                // We are just starting, get the current log file
+                currentLogFile = logManager.switchToNextLogFile( null );
+                appendedSize = currentLogFile.getLength();
+            }
             
-            while ( !appendedRecord )
+            if ( appendedSize > this.targetLogFileSize )
             {
-                // 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() ) ) )
+                // 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 )
                 {
-                    if ( writeHead.remaining() >= recordSize )
-                    {
-                        this.writeHeader( writeHead, length, lsn );
-                        writeHead.put( userBuffer, 0, length );
-                        this.writeFooter( writeHead, 0 );
-                        appendedRecord = true;
-                    }
-                    else // ( writeHead.remaining() < recordSize )
+                    // 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() >= LogFileRecords.RECORD_HEADER_SIZE
)
+                        if ( writeHead.remaining() >= recordSize )
                         {
-                            // Write a skip record
-                            this.writeHeader( writeHead, -1, -1 );
+                            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++;
                         }
-                        
-                        // 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
+                    else 
                     {
-                        this.flush( lsn, null, 0, 0, true);
+                        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;
         }
-        else
-        {   
-            this.flush( lsn, userBuffer, 0, length, true );
+        finally
+        {
+            appendLock.unlock();
         }
         
-        
-        
-        userLogAnchor.resetLogAnchor( currentLogFile.logFileNumber(), appendedSize, lsn );
-        this.appendedSize += recordSize;
-    
-        appendLock.unlock();
-        
         if ( sync )
             this.flush( lsn, null, 0, 0, false );
 



Mime
View raw message