Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9B0C573C3 for ; Mon, 24 Oct 2011 17:12:29 +0000 (UTC) Received: (qmail 34825 invoked by uid 500); 24 Oct 2011 17:12:29 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 34780 invoked by uid 500); 24 Oct 2011 17:12:29 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 34773 invoked by uid 99); 24 Oct 2011 17:12:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Oct 2011 17:12:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Oct 2011 17:12:24 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DA42923888FE for ; Mon, 24 Oct 2011 17:12:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1188237 - in /directory/apacheds/branches/apacheds-txns: core-api/src/main/java/org/apache/directory/server/core/log/ core/src/main/java/org/apache/directory/server/core/log/ core/src/test/java/org/apache/directory/server/core/log/ Date: Mon, 24 Oct 2011 17:12:02 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111024171202.DA42923888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Mon Oct 24 17:12:01 2011 New Revision: 1188237 URL: http://svn.apache.org/viewvc?rev=1188237&view=rev Log: o Added some toString() methods o Removed the LogFileManager.init() method, use the constructor instead o Added some javadoc in DefaultLogFileManager o The Reader/Writer classes in LogFileManager now create the randomAccessFile internally o Closed the RAF after having truncated it o Some minor refactoring Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/Log.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/LogAnchor.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/UserLogRecord.java 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/DefaultLogFileManager.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/LogFlushManager.java directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogManager.java directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/Log.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/Log.java?rev=1188237&r1=1188236&r2=1188237&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/Log.java (original) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/Log.java Mon Oct 24 17:12:01 2011 @@ -27,7 +27,6 @@ import java.io.IOException; */ public interface Log { - /** * Initializes the logging subsystem * Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/LogAnchor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/LogAnchor.java?rev=1188237&r1=1188236&r2=1188237&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/LogAnchor.java (original) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/LogAnchor.java Mon Oct 24 17:12:01 2011 @@ -84,19 +84,19 @@ public class LogAnchor public long getLogFileNumber() { - return this.logFileNumber; + return logFileNumber; } public long getLogFileOffset() { - return this.logFileOffset; + return logFileOffset; } public long getLogLSN() { - return this.logLSN; + return logLSN; } Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/UserLogRecord.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/UserLogRecord.java?rev=1188237&r1=1188236&r2=1188237&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/UserLogRecord.java (original) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/log/UserLogRecord.java Mon Oct 24 17:12:01 2011 @@ -70,6 +70,6 @@ public class UserLogRecord */ public String toString() { - return "Length: " + length + ", offset: " + offset + ", anchor: " + logAnchor; + return "Length: " + length + ", offset: " + offset + ", anchor: {" + logAnchor + "}"; } } 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=1188237&r1=1188236&r2=1188237&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 Mon Oct 24 17:12:01 2011 @@ -42,8 +42,7 @@ public class DefaultLog implements Log */ public void init( String logFilepath, String suffix, int logBufferSize, long logFileSize ) throws IOException, InvalidLogException { - logFileManager = new DefaultLogFileManager(); - logFileManager.init( logFilepath, suffix ); + logFileManager = new DefaultLogFileManager( logFilepath, suffix ); logManager = new LogManager( logFileManager ); logManager.initLogManager(); Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLogFileManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLogFileManager.java?rev=1188237&r1=1188236&r2=1188237&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLogFileManager.java (original) +++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/DefaultLogFileManager.java Mon Oct 24 17:12:01 2011 @@ -27,25 +27,28 @@ import java.io.FileNotFoundException; import java.io.RandomAccessFile; /** - * + * Creates and manages a LogFile on disk. The file name is the concatenation of a + * path on disk, and of a suffix.
+ * Each log file has a name like logFileName/log_<logFileNumber>.suffix + * * @author Apache Directory Project */ -/** Package protected */ class DefaultLogFileManager implements LogFileManager +class DefaultLogFileManager implements LogFileManager { - /** TODO: doco */ + /** The Log file path */ private String logFilePath; - /** TODO: doco */ + /** The Log file suffix */ private String suffix; /** - * Inits the log file manager to use the given logfile path and the suffix. Each log file + * Creates a log file manager to use the given logfile path and the suffix. Each log file * has name logFileName_.suffix * * @param logFilepath log file path * @param suffix suffix for log file. */ - public void init( String logFilePath, String suffix ) + public DefaultLogFileManager( String logFilePath, String suffix ) { this.logFilePath = logFilePath; this.suffix = suffix; @@ -59,10 +62,7 @@ import java.io.RandomAccessFile; { File logFile = makeLogFileName( logFileNumber ); - // This will throw a file not found exception if file does not exist - RandomAccessFile raf = new RandomAccessFile( logFile, "r" ); - - return new LogFileReader( raf, logFileNumber ); + return new LogFileReader( logFile, logFileNumber ); } @@ -73,10 +73,7 @@ import java.io.RandomAccessFile; { File logFile = makeLogFileName( logFileNumber ); - // This will throw a file not found exception if file does not exist - RandomAccessFile raf = new RandomAccessFile( logFile, "rw" ); - - return new LogFileWriter( raf, logFileNumber ); + return new LogFileWriter( logFile, logFileNumber ); } @@ -87,6 +84,7 @@ import java.io.RandomAccessFile; { File logFile = makeLogFileName( logFileNumber ); + // Create the files, unless it already exists. boolean fileAlreadyExists = !logFile.createNewFile(); return fileAlreadyExists; @@ -108,8 +106,10 @@ import java.io.RandomAccessFile; // This will throw a file not found exception if file does not exist RandomAccessFile raf = new RandomAccessFile( logFile, "rw" ); + // Now, truncate the file for real raf.setLength( size ); raf.getFD().sync(); + raf.close(); } @@ -131,16 +131,23 @@ import java.io.RandomAccessFile; { File oldLogFile = makeLogFileName( originalLogFileNumber ); boolean result = oldLogFile.renameTo( makeLogFileName( newLongFileNumber ) ); + return result; } - + /** + * Creates a log file name using the path, the prefix and the suffix + */ private File makeLogFileName( long logFileNumber ) { return new File( logFilePath + File.separatorChar + LogFileManager.LOG_NAME_PREFIX + logFileNumber + "." + suffix ); } - static class LogFileReader implements LogFileManager.LogFileReader + + /** + * An implementation of the {@link LogFileManager.LogFileReader} interface. + */ + private class LogFileReader implements LogFileManager.LogFileReader { /** Underlying log file */ RandomAccessFile raf; @@ -149,21 +156,28 @@ import java.io.RandomAccessFile; long logFileNumber; - public LogFileReader( RandomAccessFile raf, long logFileNumber ) + public LogFileReader( File logFile, long logFileNumber ) throws FileNotFoundException { - this.raf = raf; + // This will throw a file not found exception if file does not exist + raf = new RandomAccessFile( logFile, "r" ); + this.logFileNumber = logFileNumber; } + /** * {@inheritDoc} */ public int read( byte[] buffer, int offset, int length ) throws IOException, EOFException { + // carefully read all the bytes from disk. Don't use read(), as + // it does not span across blocks of data raf.readFully( buffer, offset, length ); + return length; } + /** * {@inheritDoc} */ @@ -172,6 +186,7 @@ import java.io.RandomAccessFile; raf.seek( position ); } + /** * {@inheritDoc} */ @@ -189,6 +204,7 @@ import java.io.RandomAccessFile; return logFileNumber; } + /** * {@inheritDoc} */ @@ -197,6 +213,7 @@ import java.io.RandomAccessFile; return raf.length(); } + /** * {@inheritDoc} */ @@ -204,10 +221,22 @@ import java.io.RandomAccessFile; { return raf.getFilePointer(); } + + + /** + * @see Object#toString() + */ + public String toString() + { + return "FileReader(" + raf + ", " + logFileNumber + ")"; + } } - static class LogFileWriter implements LogFileManager.LogFileWriter + /** + * An implementation of the {@link LogFileManager.LogFileWriter} interface. + */ + private class LogFileWriter implements LogFileManager.LogFileWriter { /** Underlying log file */ RandomAccessFile raf; @@ -216,11 +245,23 @@ import java.io.RandomAccessFile; long logFileNumber; - public LogFileWriter( RandomAccessFile raf, long logFileNumber ) - { - this.raf = raf; + /** + * Creates an instance of a LogFileWriter + * + * @param raf The file + * @param logFileNumber The file's number + * + * @throws FileNotFoundException If the file can't be found + */ + public LogFileWriter( File logFile, long logFileNumber ) throws FileNotFoundException + { + // This will throw a file not found exception if file does not exist + raf = new RandomAccessFile( logFile, "rw" ); + this.logFileNumber = logFileNumber; } + + /** * {@inheritDoc} */ @@ -229,6 +270,7 @@ import java.io.RandomAccessFile; raf.write( buffer, offset, length ); } + /** * {@inheritDoc} */ @@ -237,6 +279,7 @@ import java.io.RandomAccessFile; raf.getFD().sync(); } + /** * {@inheritDoc} */ @@ -245,6 +288,7 @@ import java.io.RandomAccessFile; raf.close(); } + /** * {@inheritDoc} */ @@ -253,6 +297,7 @@ import java.io.RandomAccessFile; return logFileNumber; } + /** * {@inheritDoc} */ @@ -261,6 +306,7 @@ import java.io.RandomAccessFile; return raf.length(); } + /** * {@inheritDoc} */ @@ -268,6 +314,15 @@ import java.io.RandomAccessFile; { raf.seek( position ); } + + + /** + * @see Object#toString() + */ + public String toString() + { + return "FileWriter(" + raf + ", " + logFileNumber + ")"; + } } 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=1188237&r1=1188236&r2=1188237&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 Mon Oct 24 17:12:01 2011 @@ -78,7 +78,7 @@ public class DefaultLogScanner implement /** * {@inheritDoc} */ - public boolean getNextRecord(UserLogRecord logRecord) throws IOException, InvalidLogException + public boolean getNextRecord( UserLogRecord logRecord ) throws IOException, InvalidLogException { boolean startingRead = false; @@ -119,7 +119,7 @@ public class DefaultLogScanner implement } startingRead = true; - } + } while ( true ) { @@ -169,7 +169,6 @@ public class DefaultLogScanner implement // Read and verify footer readRecordFooter(); - // 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 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=1188237&r1=1188236&r2=1188237&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 Mon Oct 24 17:12:01 2011 @@ -34,16 +34,6 @@ import java.io.FileNotFoundException; final static String LOG_NAME_PREFIX = "log_"; /** - * Inits the log file manager to use the given logfile path and the suffix. Each log file - * has name logFileName_.suffix - * - * @param logFilepath log file path - * @param suffix suffix for log file. - */ - void init( String logFilepath, String suffix ); - - - /** * Returns a reader for the given log file number * * @param logFileNumber identifier of the log file to read @@ -104,17 +94,20 @@ import java.io.FileNotFoundException; boolean rename(long orignalLogFileNumber, long newLongFileNumber); + /** + * An interface defining all the operations a reader can do on a File + */ interface LogFileReader { /** - * * Reads from the file at the current position * * @param buffer data destination * @param offset destination offset * @param length size of read * @return number of bytes actually read. - * @throws IOException + * @throws IOException If the read failed + * @throws EOFException If the file does not contain enough data */ int read( byte[] buffer, int offset, int length ) throws IOException, EOFException; @@ -122,13 +115,16 @@ import java.io.FileNotFoundException; /** * Repositions the reader at the given offset * - * @param position + * @param position The offset to seek + * @throws IOException If the seek operation failed */ void seek( long position ) throws IOException; + /** * Close the log file reader and releases the resources * + * @throws IOException If the close failed */ void close() throws IOException; @@ -143,39 +139,48 @@ import java.io.FileNotFoundException; /** - * returns the length of the file + * @return the length of the file + * @throws IOException If the operation failed */ long getLength() throws IOException; /** - * returns the offset of the next read + * @return the offset of the next read + * @throws IOException If the operation failed */ long getOffset() throws IOException; } + + /** + * An interface defining all the operations a writer can do on a File + */ interface LogFileWriter { /** - * Append the given data to the log file + * Append the given data to the log file at the given position * * @param buffer source of data * @param offset offset into buffer * @param length number of bytes to be appended + * @throws IOException If we cannot append data to the file */ void append( byte[] buffer, int offset, int length ) throws IOException; /** - * Sync the file contents to media - * + * Sync the file contents to media + * + * @throws IOException If we cannot sync on disk */ void sync() throws IOException; /** * Close the log file reader and releases the resources - * + * + * @throws IOException If we cannot close the file */ void close() throws IOException; @@ -190,15 +195,18 @@ import java.io.FileNotFoundException; /** - * returns the length of the file + * @return the length of the file + * + * @throws IOException If we cannot return the length */ long getLength() throws IOException; /** - * Repositions the reader at the given offset + * Repositions the reader at the given offset. * - * @param position + * @param position The new position to set + * @throws IOException If we cannot set the position */ void seek( long position ) throws IOException; } 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=1188237&r1=1188236&r2=1188237&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 Mon Oct 24 17:12:01 2011 @@ -36,7 +36,7 @@ import org.apache.directory.server.i18n. * * Internally it manages a circular buffer where appends initially go. Appends are first * appended to this in memory circular log. As the in memory circular log fills up or as the user requests - * memory buffer is flushed to the underlying media. + * memory buffer is flushed to the underlying media. * * @author Apache Directory Project */ 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=1188237&r1=1188236&r2=1188237&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 Mon Oct 24 17:12:01 2011 @@ -51,7 +51,7 @@ import org.apache.directory.server.i18n. /** buffer used to do IO on controlfile */ private byte controlFileBuffer[] = new byte[CONTROLFILE_RECORD_SIZE]; - /** ByteBuffer used to to IO on checkpoint file */ + /** ByteBuffer used to IO on checkpoint file */ private ByteBuffer controlFileMarker = ByteBuffer.wrap( controlFileBuffer ); /** Current checkpoint record in memory */ Modified: directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java?rev=1188237&r1=1188236&r2=1188237&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java (original) +++ directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java Mon Oct 24 17:12:01 2011 @@ -56,7 +56,7 @@ public class LogFlushScanTest /** * Get the Log folder */ - private String getLogFoler( ) throws IOException + private String getLogFolder( ) throws IOException { String file = folder.newFolder( LOG_SUFFIX ).getAbsolutePath(); @@ -68,7 +68,7 @@ public class LogFlushScanTest public void setup() throws IOException, InvalidLogException { log = new DefaultLog(); - log.init( getLogFoler(), LOG_SUFFIX, logBufferSize, logFileSize ); + log.init( getLogFolder(), LOG_SUFFIX, logBufferSize, logFileSize ); }