directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1195921 - in /directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log: DefaultLog.java DefaultLogScanner.java LogFileManager.java LogFileRecords.java LogFlushManager.java LogManager.java
Date Tue, 01 Nov 2011 10:47:39 GMT
Author: elecharny
Date: Tue Nov  1 10:47:39 2011
New Revision: 1195921

URL: http://svn.apache.org/viewvc?rev=1195921&view=rev
Log:
o Added some toString methods
o Added a getMilLogAnchor method in LogManager
o Added some missing Javadoc
o Added some comments
o Minor refactoring

Modified:
    directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLog.java
    directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLogScanner.java
    directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileManager.java
    directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileRecords.java
    directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFlushManager.java
    directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogManager.java

Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLog.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLog.java?rev=1195921&r1=1195920&r2=1195921&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLog.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLog.java
Tue Nov  1 10:47:39 2011
@@ -23,6 +23,7 @@ import java.io.IOException;
 
 
 /**
+ * Log interface default Implementation. 
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -91,6 +92,7 @@ public class DefaultLog implements Log
        logManager.advanceMinLogAnchor( newAnchor ); 
     }
     
+    
     /**
      * {@inheritDoc}
      */
@@ -98,4 +100,13 @@ public class DefaultLog implements Log
     {
        logFlushManager.sync( uptoLSN ); 
     }
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return "Log{" + logFileManager + "}";
+    }
 }

Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLogScanner.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLogScanner.java?rev=1195921&r1=1195920&r2=1195921&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLogScanner.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLogScanner.java
Tue Nov  1 10:47:39 2011
@@ -257,6 +257,9 @@ public class DefaultLogScanner implement
     }
     
     
+    /**
+     * Read the user record header
+     */
     private int readRecordHeader() throws IOException, InvalidLogException, EOFException
     {
         markerHead.rewind();
@@ -281,6 +284,9 @@ public class DefaultLogScanner implement
     }
     
     
+    /**
+     * Read the user record footer.
+     */
     private void readRecordFooter( int expectedChecksum ) throws IOException, InvalidLogException,
EOFException 
     {
         markerHead.rewind();
@@ -302,7 +308,7 @@ public class DefaultLogScanner implement
     
     
     /**
-     * Read the data from the LogFile, excludinhg the header and footer. 
+     * Read the data from the LogFile, excluding the header and footer. 
      */
     private void readLogRecord( UserLogRecord userRecord, int length ) throws IOException,
EOFException
     {
@@ -369,7 +375,9 @@ public class DefaultLogScanner implement
         return logFileReader;
     }
     
-    
+    /**
+     * Verify that the Log is not closed.
+     */
     private void checkIfClosed()
     {
         if ( closed == true )
@@ -379,6 +387,9 @@ public class DefaultLogScanner implement
     }
     
     
+    /**
+     * Mark the file as invalid and throw an InvalidLogException
+     */
     private void markScanInvalid( Exception cause ) throws InvalidLogException
     {
         invalidLog = true;

Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileManager.java?rev=1195921&r1=1195920&r2=1195921&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileManager.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileManager.java
Tue Nov  1 10:47:39 2011
@@ -31,6 +31,7 @@ import java.io.FileNotFoundException;
  */
 /* Package protected */ interface LogFileManager
 {
+    /** The log file prefix */
     final static String LOG_NAME_PREFIX = "log_"; 
   
     /**
@@ -38,8 +39,8 @@ import java.io.FileNotFoundException;
      *
      * @param logFileNumber identifier of the log file to read
      * @return reader for the given logfile
-     * @throws IOException
-     * @throws FileNotFoundException
+     * @throws IOException If there is an issue accessing the LogFile
+     * @throws FileNotFoundException If the log file can't be found
      */
     LogFileReader getReaderForLogFile( long logFileNumber ) throws IOException, FileNotFoundException;
     
@@ -49,8 +50,8 @@ import java.io.FileNotFoundException;
      *
      * @param logFileNumber identifier of the log file to read
      * @return writer for the given logfile
-     * @throws IOException
-     * @throws FileNotFoundException
+     * @throws IOException If there is an issue accessing the LogFile
+     * @throws FileNotFoundException If the log file can't be found
      */
     LogFileWriter getWriterForLogFile( long logFileNumber ) throws IOException, FileNotFoundException;
     
@@ -60,7 +61,7 @@ import java.io.FileNotFoundException;
      * 
      * @param logFileNumber identifier of the log file to write to.
      * @return true if file already existed
-     * @throws IOException
+     * @throws IOException If there is an issue creating the LogFile
      */
     boolean createLogFile( long logFileNumber ) throws IOException;
     
@@ -71,7 +72,7 @@ import java.io.FileNotFoundException;
      *
      * @param logFileNumber identifier of the log file
      * @param size new size of the file
-     * @throws IOException
+     * @throws IOException If there is an issue truncating the LogFile
      */
     void truncateLogFile( long logFileNumber, long size ) throws IOException;
     
@@ -91,7 +92,7 @@ import java.io.FileNotFoundException;
      * @param newLongFileNumber identifier of the new file
      * @return true if the rename succeeded
      */
-    boolean rename(long orignalLogFileNumber, long newLongFileNumber);
+    boolean rename( long orignalLogFileNumber, long newLongFileNumber );
     
     
     /**

Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileRecords.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileRecords.java?rev=1195921&r1=1195920&r2=1195921&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileRecords.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFileRecords.java
Tue Nov  1 10:47:39 2011
@@ -21,6 +21,7 @@ package org.apache.directory.server.core
 
 
 /**
+ * A helper class defining the various magic numbers, headers and footers constants.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */

Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFlushManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFlushManager.java?rev=1195921&r1=1195920&r2=1195921&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFlushManager.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogFlushManager.java
Tue Nov  1 10:47:39 2011
@@ -85,10 +85,13 @@ import org.apache.directory.server.i18n.
     private Checksum checksum = new Adler32();
 
     /**
-     * TODO : doco
-     * @param logManager
-     * @param logMemoryBufferSize
-     * @param logFileSize
+     * Creates a LogFlushManager instance. We define the memory buffer size, and the default
maximum
+     * size for each Log file (this maximul size may be exceeded, if one user record is bigger
than 
+     * this maximum size. Log file may be smaller too.
+     * 
+     * @param logManager The associated LogManager
+     * @param logMemoryBufferSize The buffer size
+     * @param logFileSize The default max size for each Log file.
      */
     public LogFlushManager( LogManager logManager, int logMemoryBufferSize, long logFileSize
)
     {
@@ -111,33 +114,33 @@ import org.apache.directory.server.i18n.
      *
      * @param userLogRecord provides the user data to be appended to the log
      * @param sync if true, this calls returns after making sure that the appended data is
reflected to the underlying file
-     * @throws IOException
-     * @throws InvalidLogException
+     * @throws IOException If we had an issue while appending some record in the file
+     * @throws InvalidLogException If the log system is is declared as invalid, due to a
previous error
      */
     public void append( UserLogRecord userRecord, boolean sync ) throws IOException, InvalidLogException
     {
-        long lsn = LogAnchor.UNKNOWN_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;
+        int recordSize = LogFileRecords.RECORD_HEADER_SIZE + length + LogFileRecords.RECORD_FOOTER_SIZE;
         
         // The addition of a record is done in a protected section
         appendLock.lock();
         
+        // Get out immediately if the log system is invalid
         if ( logFailed )
         {
             appendLock.unlock();
             throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
         }
         
+        // Get a new sequence number for the logged data
+        long lsn = logLSN++;
+
         try
         {
-            lsn = logLSN++;
-            
-            
             // Compute the checksum for the user record
             checksum.reset();
             checksum.update( userBuffer, 0, length );
@@ -257,11 +260,14 @@ import org.apache.directory.server.i18n.
         }
     }
     
+    
     /**
      * Syncs the log upto the given lsn. If lsn is equal to unknow lsn, then the log is 
      * flushed upto the latest logged lsn.
      *
      * @param uptoLSN lsn to flush upto. Unkown lsn if caller just wants to sync the log
upto the latest logged lsn.
+     * @throws IOException If we had an issue while flushing some record in the file
+     * @throws InvalidLogException If the log system is is declared as invalid, due to a
previous error
      */
     void sync( long uptoLSN ) throws IOException, InvalidLogException
     {
@@ -299,15 +305,13 @@ import org.apache.directory.server.i18n.
      * complete, the thread that wakes up and does the sync will take it for the team and
sync upto flushStatus.uptoLSN so 
      * that logging is more efficient.
      * 
-     *  
-     *
      * @param flushLSN max LSN the calling thread wants to sync upto
      * @param userBuffer if not null, user buffer is appended to the log without any buffering
      * @param offset offset of data in user buffer
      * @param length length of user data
      * @param appendLockHeld true if append lock is held
-     * @throws IOException
-     * @throws InvalidLogException
+     * @throws IOException If we had an issue while flushing some record in the file
+     * @throws InvalidLogException If the log system is is declared as invalid, due to a
previous error
      */
     private void flush( long flushLSN, byte[] userBuffer, int offset, int length, 
                         boolean appendLockHeld ) throws IOException, InvalidLogException
@@ -552,6 +556,9 @@ import org.apache.directory.server.i18n.
     }
     
     
+    /**
+     * Write the log file header 
+     */
     private void writeHeader( ByteBuffer buffer, int length, long lsn )
     {
         buffer.putInt( LogFileRecords.RECORD_HEADER_MAGIC_NUMBER );
@@ -561,6 +568,9 @@ import org.apache.directory.server.i18n.
     }
     
     
+    /**
+     * Write the log file footer 
+     */
     private void writeFooter( ByteBuffer buffer, int checksum )
     {
         buffer.putInt( checksum );
@@ -602,8 +612,6 @@ import org.apache.directory.server.i18n.
         
         /**
          * Create a new instance of a LogBuffer
-         * @param bufferSize
-         * @param currentLogFile
          */
         private LogBuffer( int bufferSize, LogFileWriter currentLogFile )
         {

Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogManager.java?rev=1195921&r1=1195920&r2=1195921&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogManager.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogManager.java
Tue Nov  1 10:47:39 2011
@@ -87,6 +87,11 @@ import org.apache.directory.server.i18n.
     private Checksum checksum = new Adler32();
 
     
+    /**
+     * Creates a new instance of LogManager. It manages the control file and 
+     * 
+     * @param logFileManager The associated LogFileManager
+     */
     public LogManager( LogFileManager logFileManager )
     {
         this.logFileManager = logFileManager;
@@ -101,8 +106,8 @@ import org.apache.directory.server.i18n.
      * determine the end of the log.
      * This scan ends either when a properly ended log file is found or a partially written
log record is found. 
      *
-     * @throws IOException
-     * @throws InvalidLogException
+     * @throws IOException If we had an issue accessing the log files
+     * @throws InvalidLogException If any of the user record is invalid
      */
     public void initLogManager() throws IOException, InvalidLogException
     {
@@ -136,11 +141,13 @@ import org.apache.directory.server.i18n.
             logRecord = new UserLogRecord();
             scanner = new DefaultLogScanner( scanPoint, logFileManager );
             
+            // Now, scan all the logged user records to check if they are all valid
             try
             {
                 while ( scanner.getNextRecord( logRecord ) )
                 {
-                    // No need to do anything with the log record
+                    // No need to do anything with the log record, just
+                    // read all of them to check that they are all valid.
                 }
             }
             catch( InvalidLogException e )
@@ -187,7 +194,6 @@ import org.apache.directory.server.i18n.
                 try
                 {
                     reader = logFileManager.getReaderForLogFile( ( lastGoodLogFileNumber
+ 1 ) );
-                    
                 }
                 catch ( FileNotFoundException e )
                 {
@@ -267,9 +273,9 @@ import org.apache.directory.server.i18n.
      * of this tasks can be delegated to a background thread later. 
      *
      * @param currentWriter current log file used by the flush manager. Null if the flush
manager is just starting up.
-     * @return new lgo file to be used.
-     * @throws IOException
-     * @throws InvalidLogException
+     * @return new log file to be used.
+     * @throws IOException If we had an issue accessing the log files
+     * @throws InvalidLogException If any of the user record is invalid
      */
     public LogFileManager.LogFileWriter switchToNextLogFile( LogFileManager.LogFileWriter
currentWriter ) throws IOException, InvalidLogException
     {
@@ -291,6 +297,21 @@ import org.apache.directory.server.i18n.
         return writer;
     }
     
+    
+    /**
+     * @return The anchor associated with the last valid checkpoint.
+     */
+    /* Package protected */ LogAnchor getMinLogAnchor()
+    {
+        minLogAnchorLock.lock();
+        LogAnchor anchor = new LogAnchor();
+        anchor.resetLogAnchor( minLogAnchor );
+        minLogAnchorLock.unlock();
+        
+        return anchor;
+    }
+    
+    
     /**
      * Called when the logging subsystem is notified about the minimum position 
      * in the log files that is needed. Log manager uses this information to advance
@@ -333,7 +354,7 @@ import org.apache.directory.server.i18n.
      * </ul>
      * 
      *
-     * @throws IOException
+     * @throws IOException If we can't write the control file
      */
     private void writeControlFile() throws IOException
     {
@@ -396,9 +417,9 @@ import org.apache.directory.server.i18n.
     /**
      * Read and verifies the control file.
      *
-     * @throws IOException
-     * @throws InvalidLogException
-     * @throws FileNotFoundException
+     * @throws IOException If we can't read the control file
+     * @throws InvalidLogException If the control file is invalid
+     * @throws FileNotFoundException If the control file can't be found
      */
     private void readControlFile() throws IOException, InvalidLogException, FileNotFoundException
     {
@@ -445,8 +466,8 @@ import org.apache.directory.server.i18n.
      * its size is truncated to zero and file header is written again.
      *
      * @param reformatExistingFile log file already exists and should be formatted. If false,
log file should not exist.
-     * @throws IOException
-     * @throws InvalidLogException
+     * @throws IOException If we can't create the new log file
+     * @throws InvalidLogException If we already have a log file with the same number
      */
     private void createNextLogFile( boolean reformatExistingFile ) throws IOException, InvalidLogException
     {
@@ -493,6 +514,9 @@ import org.apache.directory.server.i18n.
     }
     
     
+    /**
+     * Purge the useless log files
+     */
     private void deleteUnnecessaryLogFiles( long startingLogFileNumber, long endingLogFileNumber
)
     {
         for ( long logFileNumber = startingLogFileNumber; logFileNumber < endingLogFileNumber;

@@ -509,10 +533,19 @@ import org.apache.directory.server.i18n.
      */
      private class ControlFileRecord
      {
-         long minExistingLogFile;
-         long minNeededLogFile;
-         long minNeededLogFileOffset;
-         long minNeededLSN;
-         long checksum;
+         /** The smallest existing log file number */
+         private long minExistingLogFile;
+         
+         /** The log file number associated with a checkpoint */
+         private long minNeededLogFile;
+         
+         /** The offset in the min needed log file */
+         private long minNeededLogFileOffset;
+         
+         /** The LSN of the first user record in the min needed log file at the offset position
*/
+         private long minNeededLSN;
+         
+         /** The control file checksum */
+         private long checksum;
      }
 }



Mime
View raw message