You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/10/21 19:01:35 UTC
svn commit: r1187466 [1/2] - in
/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core:
log/ txn/ txn/logedit/
Author: elecharny
Date: Fri Oct 21 17:01:34 2011
New Revision: 1187466
URL: http://svn.apache.org/viewvc?rev=1187466&view=rev
Log:
o Added the missing class header
o Some minor cleanup (mainly formating)
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/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/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
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogScannerInternal.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/AbstractTransaction.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnLogManager.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnManager.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexCursorWrapper.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexWrapper.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/MasterTableWrapper.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/ReadOnlyTxn.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/ReadWriteTxn.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/Transaction.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/TxnIndexCursor.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/TxnManagerFactory.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/TxnManagerInternal.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/logedit/DataChangeContainer.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/logedit/EntryAddDelete.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/logedit/EntryChange.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/logedit/IndexChange.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/logedit/TxnStateChange.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=1187466&r1=1187465&r2=1187466&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 Fri Oct 21 17:01:34 2011
@@ -22,6 +22,10 @@ package org.apache.directory.server.core
import java.io.IOException;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public class DefaultLog implements Log
{
/** Log manager */
@@ -30,15 +34,14 @@ public class DefaultLog implements Log
/** Log File Manager */
LogFileManager logFileManager;
-
/** LogFlushManager */
LogFlushManager logFlushManager;
/**
* {@inheritDoc}
*/
- public void init( String logFilepath, String suffix, int logBufferSize, long logFileSize ) throws IOException, InvalidLogException
- {
+ public void init( String logFilepath, String suffix, int logBufferSize, long logFileSize ) throws IOException, InvalidLogException
+ {
logFileManager = new DefaultLogFileManager();
logFileManager.init( logFilepath, suffix );
@@ -46,7 +49,8 @@ public class DefaultLog implements Log
logManager.initLogManager();
logFlushManager = new LogFlushManager( logManager, logBufferSize, logFileSize );
- }
+ }
+
/**
* {@inheritDoc}
@@ -64,9 +68,11 @@ public class DefaultLog implements Log
{
LogScannerInternal logScanner = new DefaultLogScanner();
logScanner.init( startPoint, logFileManager );
+
return logScanner;
}
+
/**
* {@inheritDoc}
*/
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=1187466&r1=1187465&r2=1187466&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 Fri Oct 21 17:01:34 2011
@@ -26,9 +26,16 @@ import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
-class DefaultLogFileManager implements LogFileManager
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+/** Package protected */ class DefaultLogFileManager implements LogFileManager
{
+ /** TODO: doco */
private String logFilePath;
+
+ /** TODO: doco */
private String suffix;
/**
@@ -49,8 +56,8 @@ class DefaultLogFileManager implements L
* {@inheritDoc}
*/
public LogFileReader getReaderForLogFile( long logFileNumber ) throws IOException, FileNotFoundException
- {
- File logFile = this.makeLogFileName( logFileNumber );
+ {
+ File logFile = makeLogFileName( logFileNumber );
// This will throw a file not found exception if file does not exist
RandomAccessFile raf = new RandomAccessFile( logFile, "r" );
@@ -58,12 +65,13 @@ class DefaultLogFileManager implements L
return new LogFileReader( raf, logFileNumber );
}
+
/**
* {@inheritDoc}
*/
public LogFileWriter getWriterForLogFile( long logFileNumber ) throws IOException, FileNotFoundException
{
- File logFile = this.makeLogFileName( logFileNumber );
+ File logFile = makeLogFileName( logFileNumber );
// This will throw a file not found exception if file does not exist
RandomAccessFile raf = new RandomAccessFile( logFile, "rw" );
@@ -77,7 +85,7 @@ class DefaultLogFileManager implements L
*/
public boolean createLogFile( long logFileNumber ) throws IOException
{
- File logFile = this.makeLogFileName( logFileNumber );
+ File logFile = makeLogFileName( logFileNumber );
boolean fileAlreadyExists = !logFile.createNewFile();
@@ -95,7 +103,7 @@ class DefaultLogFileManager implements L
throw new IllegalArgumentException( "Invalid file size is specified for the log file: " + logFileNumber + " " + size );
}
- File logFile = this.makeLogFileName( logFileNumber );
+ File logFile = makeLogFileName( logFileNumber );
// This will throw a file not found exception if file does not exist
RandomAccessFile raf = new RandomAccessFile( logFile, "rw" );
@@ -110,7 +118,7 @@ class DefaultLogFileManager implements L
*/
public void deleteLogFile( long logFileNumber )
{
- File logFile = this.makeLogFileName( logFileNumber );
+ File logFile = makeLogFileName( logFileNumber );
logFile.delete();
}
@@ -121,8 +129,8 @@ class DefaultLogFileManager implements L
*/
public boolean rename(long originalLogFileNumber, long newLongFileNumber)
{
- File oldLogFile = this.makeLogFileName( originalLogFileNumber );
- boolean result = oldLogFile.renameTo( this.makeLogFileName( newLongFileNumber ) );
+ File oldLogFile = makeLogFileName( originalLogFileNumber );
+ boolean result = oldLogFile.renameTo( makeLogFileName( newLongFileNumber ) );
return result;
}
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=1187466&r1=1187465&r2=1187466&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 Fri Oct 21 17:01:34 2011
@@ -26,6 +26,10 @@ import java.nio.ByteBuffer;
import org.apache.directory.server.i18n.I18n;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public class DefaultLogScanner implements LogScannerInternal
{
/** LSN of the last successfully read log record */
@@ -70,6 +74,7 @@ public class DefaultLogScanner implement
this.logFileManager = logFileManager;
}
+
/**
* {@inheritDoc}
*/
@@ -87,16 +92,14 @@ public class DefaultLogScanner implement
long fileLength;
long fileOffset;
-
try
{
if ( currentLogFile == null )
{
-
long startingOffset = startingLogAnchor.getLogFileOffset();
// Read and verify header
- currentLogFile = this.readFileHeader( startingLogAnchor.getLogFileNumber() );
+ currentLogFile = readFileHeader( startingLogAnchor.getLogFileNumber() );
if ( currentLogFile == null )
{
@@ -108,12 +111,13 @@ public class DefaultLogScanner implement
if ( startingOffset < LogFileRecords.LOG_FILE_HEADER_SIZE )
{
// Offset should be at log file marker boundary
- this.markScanInvalid( null );
+ markScanInvalid( null );
}
prevLogFileOffset = Math.max( startingOffset, currentLogFile.getLength() );
currentLogFile.seek( startingOffset );
}
+
startingRead = true;
}
@@ -124,19 +128,19 @@ public class DefaultLogScanner implement
if ( fileOffset > fileLength )
{
- this.markScanInvalid( null );
+ markScanInvalid( null );
}
else if ( fileOffset == fileLength )
{
// Switch to next file.. This reads and verifies the header of the new file
long nextLogFileNumber = currentLogFile.logFileNumber() + 1;
currentLogFile.close();
- currentLogFile = this.readFileHeader( nextLogFileNumber );
+ currentLogFile = readFileHeader( nextLogFileNumber );
if ( currentLogFile == null )
+ {
return false; // Done.. End of log stream
-
-
+ }
}
else
{
@@ -145,7 +149,7 @@ public class DefaultLogScanner implement
}
// Read and verify record header
- int recordLength = this.readRecordHeader();
+ int recordLength = readRecordHeader();
// If starting read, then check if we have the expected lsn in case
// expected lsn is known
@@ -155,15 +159,15 @@ public class DefaultLogScanner implement
if ( ( startingLSN != LogAnchor.UNKNOWN_LSN ) && ( startingLSN != lastReadLSN ) )
{
- this.markScanInvalid( null );
+ markScanInvalid( null );
}
}
// Read and verify user block
- this.readLogRecord( logRecord, recordLength - ( LogFileRecords.RECORD_HEADER_SIZE + LogFileRecords.RECORD_FOOTER_SIZE ));
+ readLogRecord( logRecord, recordLength - ( LogFileRecords.RECORD_HEADER_SIZE + LogFileRecords.RECORD_FOOTER_SIZE ));
// Read and verify footer
- this.readRecordFooter();
+ readRecordFooter();
// If we are here, then we successfully read the log record.
@@ -182,30 +186,29 @@ public class DefaultLogScanner implement
{
// This means either the log record or the log file header was
// partially written. Treat this as invalid log content
- this.markScanInvalid( e );
+ markScanInvalid( e );
}
catch( IOException e)
{
- this.close();
+ close();
throw e;
}
catch( InvalidLogException e)
{
- this.close();
+ close();
throw e;
}
-
return true;
-
}
+
/**
* {@inheritDoc}
*/
public long getLastGoodFileNumber()
{
- return this.prevLogFileNumber;
+ return prevLogFileNumber;
}
@@ -214,9 +217,8 @@ public class DefaultLogScanner implement
*/
public long getLastGoodOffset()
{
- return this.prevLogFileOffset;
+ return prevLogFileOffset;
}
-
/**
@@ -227,6 +229,7 @@ public class DefaultLogScanner implement
if ( closed == false )
{
closed = true;
+
if (currentLogFile != null)
{
try
@@ -240,7 +243,6 @@ public class DefaultLogScanner implement
}
}
}
-
}
@@ -277,11 +279,12 @@ public class DefaultLogScanner implement
if ( invalid == true )
{
- this.markScanInvalid( null );
+ markScanInvalid( null );
}
// Everything went fine
lastReadLSN = lsn;
+
return length;
}
@@ -304,10 +307,11 @@ public class DefaultLogScanner implement
if ( invalid == true )
{
- this.markScanInvalid( null );
+ markScanInvalid( null );
}
}
+
private void readLogRecord( UserLogRecord userRecord, int length ) throws IOException, EOFException
{
byte dataBuffer[] = userRecord.getDataBuffer();
@@ -322,6 +326,7 @@ public class DefaultLogScanner implement
userRecord.setData( dataBuffer, length );
}
+
private LogFileManager.LogFileReader readFileHeader( long logFileNumber ) throws IOException, InvalidLogException, EOFException
{
boolean invalid = false;
@@ -337,8 +342,8 @@ public class DefaultLogScanner implement
}
// File exists
- this.prevLogFileNumber = logFileNumber;
- this.prevLogFileOffset = 0;
+ prevLogFileNumber = logFileNumber;
+ prevLogFileOffset = 0;
markerHead.rewind();
logFile.read( markerBuffer, 0, LogFileRecords.LOG_FILE_HEADER_SIZE );
@@ -358,14 +363,15 @@ public class DefaultLogScanner implement
if ( invalid == true )
{
- this.markScanInvalid( null );
+ markScanInvalid( null );
}
// Everything is fine, advance good file offset and return
- this.prevLogFileOffset = LogFileRecords.LOG_FILE_HEADER_SIZE;
+ prevLogFileOffset = LogFileRecords.LOG_FILE_HEADER_SIZE;
return logFile;
}
+
private void checkIfClosed()
{
if ( closed == true )
@@ -374,6 +380,7 @@ public class DefaultLogScanner implement
}
}
+
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=1187466&r1=1187465&r2=1187466&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 Fri Oct 21 17:01:34 2011
@@ -29,7 +29,7 @@ import java.io.FileNotFoundException;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-interface LogFileManager
+/** Package protected */ interface LogFileManager
{
final static String LOG_NAME_PREFIX = "log_";
@@ -40,7 +40,7 @@ interface LogFileManager
* @param logFilepath log file path
* @param suffix suffix for log file.
*/
- public void init( String logFilepath, String suffix );
+ void init( String logFilepath, String suffix );
/**
@@ -51,7 +51,7 @@ interface LogFileManager
* @throws IOException
* @throws FileNotFoundException
*/
- public LogFileReader getReaderForLogFile( long logFileNumber ) throws IOException, FileNotFoundException;
+ LogFileReader getReaderForLogFile( long logFileNumber ) throws IOException, FileNotFoundException;
/**
@@ -62,7 +62,7 @@ interface LogFileManager
* @throws IOException
* @throws FileNotFoundException
*/
- public LogFileWriter getWriterForLogFile( long logFileNumber ) throws IOException, FileNotFoundException;
+ LogFileWriter getWriterForLogFile( long logFileNumber ) throws IOException, FileNotFoundException;
/**
@@ -72,7 +72,7 @@ interface LogFileManager
* @return true if file already existed
* @throws IOException
*/
- public boolean createLogFile( long logFileNumber ) throws IOException;
+ boolean createLogFile( long logFileNumber ) throws IOException;
/**
@@ -83,14 +83,15 @@ interface LogFileManager
* @param size new size of the file
* @throws IOException
*/
- public void truncateLogFile( long logFileNumber, long size ) throws IOException;
+ void truncateLogFile( long logFileNumber, long size ) throws IOException;
+
/**
* Deletes the underlying log file.
*
* @param logFileNumber identifier of the log file
*/
- public void deleteLogFile( long logFileNumber );
+ void deleteLogFile( long logFileNumber );
/**
@@ -100,7 +101,7 @@ interface LogFileManager
* @param newLongFileNumber identifier of the new file
* @return true if the rename succeeded
*/
- public boolean rename(long orignalLogFileNumber, long newLongFileNumber);
+ boolean rename(long orignalLogFileNumber, long newLongFileNumber);
interface LogFileReader
@@ -115,7 +116,7 @@ interface LogFileManager
* @return number of bytes actually read.
* @throws IOException
*/
- public int read( byte[] buffer, int offset, int length ) throws IOException, EOFException;
+ int read( byte[] buffer, int offset, int length ) throws IOException, EOFException;
/**
@@ -123,13 +124,13 @@ interface LogFileManager
*
* @param position
*/
- public void seek( long position ) throws IOException;
+ void seek( long position ) throws IOException;
/**
* Close the log file reader and releases the resources
*
*/
- public void close() throws IOException;
+ void close() throws IOException;
/**
@@ -138,17 +139,19 @@ interface LogFileManager
*
* @return number assigned to this log file
*/
- public long logFileNumber();
+ long logFileNumber();
+
/**
* returns the length of the file
*/
- public long getLength() throws IOException;
+ long getLength() throws IOException;
+
/**
* returns the offset of the next read
*/
- public long getOffset() throws IOException;
+ long getOffset() throws IOException;
}
interface LogFileWriter
@@ -160,21 +163,22 @@ interface LogFileManager
* @param offset offset into buffer
* @param length number of bytes to be appended
*/
- public void append( byte[] buffer, int offset, int length ) throws IOException;
-
+ void append( byte[] buffer, int offset, int length ) throws IOException;
/**
* Sync the file contents to media
*
*/
- public void sync() throws IOException;
+ void sync() throws IOException;
+
/**
* Close the log file reader and releases the resources
*
*/
- public void close() throws IOException;
+ void close() throws IOException;
+
/**
* Each log file is assigned a sequence number. This method
@@ -182,20 +186,20 @@ interface LogFileManager
*
* @return number assigned to this log file
*/
- public long logFileNumber();
+ long logFileNumber();
+
/**
* returns the length of the file
*/
- public long getLength() throws IOException;
+ long getLength() throws IOException;
+
/**
* Repositions the reader at the given offset
*
* @param position
*/
- public void seek( long position ) throws IOException;
-
+ void seek( long position ) throws IOException;
}
-
}
\ No newline at end of file
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=1187466&r1=1187465&r2=1187466&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 Fri Oct 21 17:01:34 2011
@@ -20,6 +20,10 @@
package org.apache.directory.server.core.log;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public class LogFileRecords
{
/**
@@ -28,7 +32,7 @@ public class LogFileRecords
* into the log. Header and footer information makes
* it easier to scan the log, detect the end of
* log during log scan and verify the integrity of log.
- */
+ */
/**
* Record Header marker
@@ -76,5 +80,4 @@ public class LogFileRecords
int markerSize = Math.max( RECORD_HEADER_SIZE, RECORD_FOOTER_SIZE );
MAX_MARKER_SIZE = Math.max( markerSize, LOG_FILE_HEADER_SIZE );
}
-
}
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=1187466&r1=1187465&r2=1187466&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 Fri Oct 21 17:01:34 2011
@@ -40,9 +40,8 @@ import org.apache.directory.server.i18n.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-class LogFlushManager
+/** Package protected */ class LogFlushManager
{
-
/** Ever increasing logical log sequence number assigned to user log records. Bumped up under append lock */
private long logLSN = Long.MIN_VALUE + 1;
@@ -79,6 +78,12 @@ class LogFlushManager
/** If logging cannot succeed, then loggingFailed is set to true and further logging is prevented */
boolean logFailed;
+ /**
+ * TODO : doco
+ * @param logManager
+ * @param logMemoryBufferSize
+ * @param logFileSize
+ */
public LogFlushManager(LogManager logManager, int logMemoryBufferSize, long logFileSize )
{
if ( ( logMemoryBufferSize < 0 ) || ( logFileSize < 0 ) )
@@ -91,9 +96,9 @@ class LogFlushManager
this.logManager = logManager;
logBuffer = new LogBuffer( logBufferSize, currentLogFile );
-
}
+
/**
* Appends the given user record to the log. Position where the record is appended is returned as part of
* userRecord.
@@ -132,10 +137,10 @@ class LogFlushManager
appendedSize = currentLogFile.getLength();
}
- if ( appendedSize > this.targetLogFileSize )
+ if ( appendedSize > targetLogFileSize )
{
// Make sure everything outstanding goes to the current log file
- this.flush( lsn, null, 0, 0, true);
+ flush( lsn, null, 0, 0, true);
currentLogFile = logManager.switchToNextLogFile( currentLogFile );
appendedSize = currentLogFile.getLength();
@@ -157,9 +162,9 @@ class LogFlushManager
{
if ( writeHead.remaining() >= recordSize )
{
- this.writeHeader( writeHead, recordSize, lsn );
+ writeHeader( writeHead, recordSize, lsn );
writeHead.put( userBuffer, 0, length );
- this.writeFooter( writeHead, 0 );
+ writeFooter( writeHead, 0 );
appendedRecord = true;
}
else // ( writeHead.remaining() < recordSize )
@@ -167,7 +172,7 @@ class LogFlushManager
if ( writeHead.remaining() >= LogFileRecords.RECORD_HEADER_SIZE )
{
// Write a skip record
- this.writeHeader( writeHead, -1, -1 );
+ writeHeader( writeHead, -1, -1 );
}
// rewind buffer now
@@ -185,28 +190,25 @@ class LogFlushManager
if ( ( readHeadPosition - writeHead.position() ) > recordSize )
{
- this.writeHeader( writeHead, recordSize, lsn );
+ writeHeader( writeHead, recordSize, lsn );
writeHead.put( userBuffer, 0, length );
- this.writeFooter( writeHead, 0 );
+ writeFooter( writeHead, 0 );
appendedRecord = true;
}
else
{
- this.flush( lsn, null, 0, 0, true);
+ flush( lsn, null, 0, 0, true);
}
}
}
-
}
else
{
- this.flush( lsn, userBuffer, 0, length, true );
+ flush( lsn, userBuffer, 0, length, true );
}
-
-
userLogAnchor.resetLogAnchor( currentLogFile.logFileNumber(), appendedSize, lsn );
- this.appendedSize += recordSize;
+ appendedSize += recordSize;
}
catch( IOException e )
{
@@ -224,10 +226,12 @@ class LogFlushManager
}
if ( sync )
- this.flush( lsn, null, 0, 0, false );
-
+ {
+ flush( lsn, null, 0, 0, false );
+ }
}
+
/**
* Flushes the changes in the log buffer upto the given point. The given point is determined as follows:
* appendLock is held: flushLSN is the highest lsn generated by the logging system and no more appends can
@@ -257,7 +261,7 @@ class LogFlushManager
*/
private void flush( long flushLSN, byte[] userBuffer, int offset, int length,
boolean appendLockHeld ) throws IOException, InvalidLogException
- {
+ {
long uptoLSN = flushLSN;
if ( appendLockHeld == true )
@@ -277,7 +281,6 @@ class LogFlushManager
* Check if we need to do flush and wait for ongoing flush if
* necessary
*/
-
while ( true )
{
if ( logFailed )
@@ -285,6 +288,7 @@ class LogFlushManager
flushLock.unlock();
throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
}
+
if ( ( flushStatus.flushedLSN >= uptoLSN ) && ( appendLockHeld == false ) )
{
flushLock.unlock();
@@ -318,10 +322,9 @@ class LogFlushManager
long flushedLSN = LogAnchor.UNKNOWN_LSN;
-
try
{
- flushedLSN = this.doFlush( uptoLSN, appendLockHeld );
+ flushedLSN = doFlush( uptoLSN, appendLockHeld );
// Now if there is a user buffer, flush from that
if ( userBuffer != null )
@@ -330,13 +333,13 @@ class LogFlushManager
int recordSize = LogFileRecords.RECORD_HEADER_SIZE + LogFileRecords.RECORD_FOOTER_SIZE + length;
headerFooterHead.rewind();
- this.writeHeader( headerFooterHead, recordSize, flushLSN );
+ writeHeader( headerFooterHead, recordSize, flushLSN );
currentLogFile.append( logBuffer.headerFooterBuffer, 0, LogFileRecords.RECORD_HEADER_MAGIC_NUMBER );
currentLogFile.append( userBuffer, offset, length );
headerFooterHead.rewind();
- this.writeFooter( headerFooterHead, 0 );
+ writeFooter( headerFooterHead, 0 );
currentLogFile.append( logBuffer.headerFooterBuffer, 0, LogFileRecords.RECORD_FOOTER_SIZE );
flushedLSN = flushLSN;
@@ -412,6 +415,7 @@ class LogFlushManager
while ( !done )
{
int totalLength = 0;
+
while( true )
{
/*
@@ -430,7 +434,9 @@ class LogFlushManager
// If less than header length left to process, then break and flush whatever we got so far
if ( readHead.remaining() < LogFileRecords.RECORD_HEADER_SIZE )
+ {
break;
+ }
magicNumber = readHead.getInt();
@@ -445,13 +451,11 @@ class LogFlushManager
// Did we hit a skip record at the end of the buffer?
if ( length == LogBuffer.SKIP_RECORD_LENGTH )
+ {
break;
-
-
-
+ }
// Sanitize length, it includes header and footer overhead
-
if ( length <= ( LogFileRecords.RECORD_HEADER_SIZE + LogFileRecords.RECORD_FOOTER_SIZE) )
{
throw new IllegalStateException( "Record length doesnt make sense:" + length + " expected:" +
@@ -471,13 +475,12 @@ class LogFlushManager
done = true;
break;
}
-
}
// If there is something to flush, then do it now
if ( totalLength > 0 )
{
- int offset;
+ int offset;
offset = logBuffer.readHeadPosition;
currentLogFile.append( logBuffer.buffer, offset, totalLength );
@@ -496,10 +499,10 @@ class LogFlushManager
}
return lsn;
-
}
- private void writeHeader ( ByteBuffer buffer, int length, long lsn )
+
+ private void writeHeader( ByteBuffer buffer, int length, long lsn )
{
buffer.putInt( LogFileRecords.RECORD_HEADER_MAGIC_NUMBER );
buffer.putInt( length );
@@ -507,7 +510,8 @@ class LogFlushManager
buffer.putLong( length ^ lsn );
}
- private void writeFooter ( ByteBuffer buffer, int checksum )
+
+ private void writeFooter( ByteBuffer buffer, int checksum )
{
buffer.putInt( checksum );
buffer.putInt( LogFileRecords.RECORD_FOOTER_MAGIC_NUMBER );
@@ -571,11 +575,9 @@ class LogFlushManager
/** Current flush request */
long uptoLSN = LogAnchor.UNKNOWN_LSN;
-
/** Current flushed lsn */
long flushedLSN = LogAnchor.UNKNOWN_LSN;
-
/** Keeps track of the number of waiters */
int numWaiters;
}
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=1187466&r1=1187465&r2=1187466&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 Fri Oct 21 17:01:34 2011
@@ -30,9 +30,12 @@ import java.io.EOFException;
import org.apache.directory.server.i18n.I18n;
-class LogManager
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+/** Package protected*/ class LogManager
{
-
/** Controlfile record size */
private final static int CONTROLFILE_RECORD_SIZE = 44;
@@ -81,6 +84,7 @@ class LogManager
this.logFileManager = logFileManager;
}
+
/**
*Initializes the log management:
* 1) Checks if control file exists and creates it if necesssary. If it exists, it reads it and loads the latest checkpoint.
@@ -101,9 +105,10 @@ class LogManager
// Read and verify control file
boolean controlFileExists = true;
+
try
{
- this.readControlFile();
+ readControlFile();
}
catch( FileNotFoundException e )
{
@@ -171,6 +176,7 @@ class LogManager
{
// Check if next log file exists
reader = null;
+
try
{
reader = logFileManager.getReaderForLogFile( ( lastGoodLogFileNumber + 1 ) );
@@ -200,54 +206,53 @@ class LogManager
else
{
// Reformat the existing log file
- this.createNextLogFile( true);
- }
+ createNextLogFile( true);
+ }
}
-
}
+
+ /*
+ * Control file does not exist. Either we are at the very beginning or
+ * maybe we crashed in the middle of creating the first log file.
+ * We should have the min log file at most with the file header formatted.
+ */
+ reader = null;
+ boolean fileExists = false;
+ currentLogFileNumber = LogAnchor.MIN_LOG_NUMBER - 1;
+
+ try
{
- /*
- * Control file does not exist. Either we are at the very beginning or
- * maybe we crashed in the middle of creating the first log file.
- * We should have the min log file at most with the file header formatted.
- */
- reader = null;
- boolean fileExists = false;
- currentLogFileNumber = LogAnchor.MIN_LOG_NUMBER - 1;
- try
- {
- reader = logFileManager.getReaderForLogFile( LogAnchor.MIN_LOG_NUMBER );
-
- if ( reader.getLength() > LogFileRecords.LOG_FILE_HEADER_SIZE )
- {
- throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
- }
- fileExists = true;
- currentLogFileNumber++;
- }
- catch ( FileNotFoundException e )
- {
- // Fine, we will create the file
- }
- finally
- {
- if ( reader != null )
- {
- reader.close();
- }
- }
-
+ reader = logFileManager.getReaderForLogFile( LogAnchor.MIN_LOG_NUMBER );
+ if ( reader.getLength() > LogFileRecords.LOG_FILE_HEADER_SIZE )
+ {
+ throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
+ }
- this.createNextLogFile( fileExists );
-
- // Prepare the min log anchor and control file and write the control file
- minLogAnchor.resetLogAnchor( LogAnchor.MIN_LOG_NUMBER, LogFileRecords.LOG_FILE_HEADER_SIZE, LogAnchor.UNKNOWN_LSN );
-
- this.writeControlFile();
+ fileExists = true;
+ currentLogFileNumber++;
}
+ catch ( FileNotFoundException e )
+ {
+ // Fine, we will create the file
+ }
+ finally
+ {
+ if ( reader != null )
+ {
+ reader.close();
+ }
+ }
+
+ createNextLogFile( fileExists );
+
+ // Prepare the min log anchor and control file and write the control file
+ minLogAnchor.resetLogAnchor( LogAnchor.MIN_LOG_NUMBER, LogFileRecords.LOG_FILE_HEADER_SIZE, LogAnchor.UNKNOWN_LSN );
+
+ writeControlFile();
}
+
/**
* Called by LogFlushManager to switch to the next file.
*
@@ -264,17 +269,19 @@ class LogManager
if ( currentWriter != null )
{
currentWriter.close();
- this.writeControlFile();
- this.createNextLogFile( false );
+ writeControlFile();
+ createNextLogFile( false );
}
- LogFileManager.LogFileWriter writer = logFileManager.getWriterForLogFile( this.currentLogFileNumber );
+ LogFileManager.LogFileWriter writer = logFileManager.getWriterForLogFile( currentLogFileNumber );
long currentOffset = writer.getLength();
+
if ( currentOffset > 0 )
{
writer.seek( currentOffset );
}
- return writer;
+
+ return writer;
}
/**
@@ -301,6 +308,7 @@ class LogManager
minLogAnchorLock.unlock();
}
+
/**
* Writes the control file. To make paritally written control files unlikely,
* data is first written to a shadow file and then moved(renamed) to the controlfile.
@@ -323,14 +331,13 @@ class LogManager
if ( controlFileRecord.minNeededLogFile > controlFileRecord.minExistingLogFile )
{
- this.deleteUnnecessaryLogFiles( controlFileRecord.minExistingLogFile,controlFileRecord.minNeededLogFile );
+ deleteUnnecessaryLogFiles( controlFileRecord.minExistingLogFile,controlFileRecord.minNeededLogFile );
controlFileRecord.minExistingLogFile = controlFileRecord.minNeededLogFile;
}
// TODO compute checksum for log record here
-
controlFileMarker.rewind();
controlFileMarker.putLong( controlFileRecord.minExistingLogFile );
controlFileMarker.putLong( controlFileRecord.minNeededLogFile );
@@ -361,10 +368,9 @@ class LogManager
// Do the move now
logFileManager.rename( CONTROLFILE_SHADOW_LOG_FILE_NUMBER , CONTROLFILE_LOG_FILE_NUMBER );
-
-
}
+
/**
* Read and verifies the control file.
*
@@ -415,7 +421,7 @@ class LogManager
invalidControlFile = true;
}
- if ( magicNumber != this.CONTROLFILE_MAGIC_NUMBER )
+ if ( magicNumber != CONTROLFILE_MAGIC_NUMBER )
{
invalidControlFile = true;
}
@@ -426,9 +432,9 @@ class LogManager
{
throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
}
-
}
+
/**
* Creates the next log file. If the log file already exists, then it is reformatted, that is,
* its size is truncated to zero and file header is writtten again.
@@ -440,8 +446,8 @@ class LogManager
private void createNextLogFile( boolean reformatExistingFile ) throws IOException, InvalidLogException
{
LogFileManager.LogFileWriter writer = null;
-
- long logFileNumber = this.currentLogFileNumber;
+
+ long logFileNumber = currentLogFileNumber;
if ( reformatExistingFile == false )
{
@@ -477,17 +483,17 @@ class LogManager
markerHead.putLong( logFileNumber );
markerHead.putInt( LogFileRecords.LOG_FILE_HEADER_MAGIC_NUMBER );
writer.append( markerBuffer, 0, LogFileRecords.LOG_FILE_HEADER_SIZE );
- writer.sync();
+ writer.sync();
}
finally
{
writer.close();
}
- this.currentLogFileNumber = logFileNumber;
-
+ currentLogFileNumber = logFileNumber;
}
+
private void deleteUnnecessaryLogFiles( long startingLogFileNumber, long endingLogFileNumber )
{
for ( long logFileNumber = startingLogFileNumber; logFileNumber < endingLogFileNumber;
@@ -498,6 +504,7 @@ class LogManager
}
}
+
/**
* Checkpoint record
*/
@@ -509,7 +516,4 @@ class LogManager
long minNeededLSN;
long checksum;
}
-
-
-
}
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogScannerInternal.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogScannerInternal.java?rev=1187466&r1=1187465&r2=1187466&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogScannerInternal.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/log/LogScannerInternal.java Fri Oct 21 17:01:34 2011
@@ -20,6 +20,10 @@
package org.apache.directory.server.core.log;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public interface LogScannerInternal extends LogScanner
{
/**
@@ -28,5 +32,5 @@ public interface LogScannerInternal exte
* @param startingPoint
* @param logFileManager log file manager to use
*/
- public void init( LogAnchor startingPoint, LogFileManager logFileManager );
+ void init( LogAnchor startingPoint, LogFileManager logFileManager );
}
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/AbstractTransaction.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/AbstractTransaction.java?rev=1187466&r1=1187465&r2=1187466&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/AbstractTransaction.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/AbstractTransaction.java Fri Oct 21 17:01:34 2011
@@ -26,6 +26,10 @@ import java.util.Iterator;
import org.apache.directory.shared.ldap.model.entry.Entry;
import org.apache.directory.shared.ldap.model.name.Dn;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
abstract class AbstractTransaction<ID> implements Transaction<ID>
{
/** Logical time(LSN in the wal) when the txn began */
@@ -41,37 +45,44 @@ abstract class AbstractTransaction<ID> i
List<ReadWriteTxn<ID>> txnsToCheck = new ArrayList<ReadWriteTxn<ID>>();
+ /**
+ * TODO : doco
+ */
public AbstractTransaction( )
{
txnState = State.INITIAL;
}
+
/**
* {@inheritDoc}
*/
public void startTxn( long startTime )
{
this.startTime = startTime;
- this.setState( State.READ );
+ setState( State.READ );
}
+
/**
* {@inheritDoc}
*/
public long getStartTime()
{
- return this.startTime;
+ return startTime;
}
+
/**
* {@inheritDoc}
*/
public void commitTxn( long commitTime )
{
this.commitTime = commitTime;
- this.setState( State.COMMIT );
+ setState( State.COMMIT );
}
+
/**
* {@inheritDoc}
*/
@@ -80,12 +91,13 @@ abstract class AbstractTransaction<ID> i
return commitTime;
}
+
/**
* {@inheritDoc}
*/
public void abortTxn()
{
- this.setState( State.ABORT );
+ setState( State.ABORT );
}
@@ -94,25 +106,28 @@ abstract class AbstractTransaction<ID> i
*/
public List<ReadWriteTxn<ID>> getTxnsToCheck()
{
- return this.txnsToCheck;
+ return txnsToCheck;
}
+
/**
* {@inheritDoc}
*/
public State getState()
{
- return this.txnState;
+ return txnState;
}
+
/**
* {@inheritDoc}
*/
public void setState( State newState )
{
- this.txnState = newState;
+ txnState = newState;
}
+
public Entry mergeUpdates( Dn partitionDn, ID entryID, Entry entry )
{
Entry prevEntry = entry;
@@ -135,6 +150,4 @@ abstract class AbstractTransaction<ID> i
return curEntry;
}
-
-
}
\ No newline at end of file
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnLogManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnLogManager.java?rev=1187466&r1=1187465&r2=1187466&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnLogManager.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnLogManager.java Fri Oct 21 17:01:34 2011
@@ -35,104 +35,117 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.server.core.txn.logedit.LogEdit;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public class DefaultTxnLogManager<ID> implements TxnLogManager<ID>
{
- /** Write ahea log */
- Log wal;
+ /** Write ahead log */
+ private Log wal;
/** Txn Manager */
- TxnManagerInternal<ID> txnManager;
+ private TxnManagerInternal<ID> txnManager;
+
+ /**
+ * TODO : doco
+ * @param logger
+ * @param txnManager
+ */
public void init( Log logger, TxnManagerInternal<ID> txnManager )
{
this.wal = logger;
this.txnManager = txnManager;
}
+
+
/**
* {@inheritDoc}
*/
- public void log( LogEdit<ID> logEdit, boolean sync ) throws IOException
- {
- Transaction<ID> curTxn = txnManager.getCurTxn();
-
- if ( ( curTxn == null ) || ( ! ( curTxn instanceof ReadWriteTxn ) ) )
- {
- throw new IllegalStateException( "Trying to log logedit without ReadWriteTxn" );
- }
-
- ReadWriteTxn<ID> txn = (ReadWriteTxn<ID>)curTxn;
- UserLogRecord logRecord = txn.getUserLogRecord();
-
-
- ObjectOutputStream out = null;
- ByteArrayOutputStream bout = null;
- byte[] data;
+ public void log( LogEdit<ID> logEdit, boolean sync ) throws IOException
+ {
+ Transaction<ID> curTxn = txnManager.getCurTxn();
+
+ if ( ( curTxn == null ) || ( ! ( curTxn instanceof ReadWriteTxn ) ) )
+ {
+ throw new IllegalStateException( "Trying to log logedit without ReadWriteTxn" );
+ }
+
+ ReadWriteTxn<ID> txn = (ReadWriteTxn<ID>)curTxn;
+ UserLogRecord logRecord = txn.getUserLogRecord();
+
+ ObjectOutputStream out = null;
+ ByteArrayOutputStream bout = null;
+ byte[] data;
- try
- {
- bout = new ByteArrayOutputStream();
- out = new ObjectOutputStream( bout );
- out.writeObject( logEdit );
- out.flush();
- data = bout.toByteArray();
- }
- finally
- {
- if ( bout != null )
- {
- bout.close();
- }
+ try
+ {
+ bout = new ByteArrayOutputStream();
+ out = new ObjectOutputStream( bout );
+ out.writeObject( logEdit );
+ out.flush();
+ data = bout.toByteArray();
+ }
+ finally
+ {
+ if ( bout != null )
+ {
+ bout.close();
+ }
- if ( out != null )
- {
- out.close();
- }
- }
-
- logRecord.setData( data, data.length );
-
- this.log( logRecord, sync );
-
- logEdit.getLogAnchor().resetLogAnchor( logRecord.getLogAnchor() );
- txn.addLogEdit( logEdit );
- }
-
- /**
- * {@inheritDoc}
- */
- public void log( UserLogRecord logRecord, boolean sync ) throws IOException
- {
- try
- {
- wal.log( logRecord, sync );
- }
- catch ( InvalidLogException e )
- {
- throw new IOException(e);
- }
- }
+ if ( out != null )
+ {
+ out.close();
+ }
+ }
+
+ logRecord.setData( data, data.length );
+
+ log( logRecord, sync );
+
+ logEdit.getLogAnchor().resetLogAnchor( logRecord.getLogAnchor() );
+ txn.addLogEdit( logEdit );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void log( UserLogRecord logRecord, boolean sync ) throws IOException
+ {
+ try
+ {
+ wal.log( logRecord, sync );
+ }
+ catch ( InvalidLogException e )
+ {
+ throw new IOException(e);
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public Entry mergeUpdates(Dn partitionDn, ID entryID, Entry entry )
- {
- Transaction<ID> curTxn = txnManager.getCurTxn();
-
- if ( ( curTxn == null ) )
- {
- throw new IllegalStateException( "Trying to merge with log wihout txn" );
- }
-
- return curTxn.mergeUpdates( partitionDn, entryID, entry );
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Entry mergeUpdates(Dn partitionDn, ID entryID, Entry entry )
+ {
+ Transaction<ID> curTxn = txnManager.getCurTxn();
+
+ if ( ( curTxn == null ) )
+ {
+ throw new IllegalStateException( "Trying to merge with log wihout txn" );
+ }
+
+ return curTxn.mergeUpdates( partitionDn, entryID, entry );
+ }
+
- /**
- * {@inheritDoc}
- */
- public IndexCursor<Object, Entry, ID> wrap( Dn partitionDn, IndexCursor<Object, Entry, ID> wrappedCursor, IndexComparator<Object,ID> comparator, String attributeOid, boolean forwardIndex, Object onlyValueKey, ID onlyIDKey ) throws Exception
- {
- return new IndexCursorWrapper<ID>( partitionDn, wrappedCursor, comparator, attributeOid, forwardIndex, onlyValueKey, onlyIDKey );
- }
-}
+ /**
+ * {@inheritDoc}
+ */
+ public IndexCursor<Object, Entry, ID> wrap( Dn partitionDn, IndexCursor<Object, Entry, ID> wrappedCursor, IndexComparator<Object,ID> comparator, String attributeOid, boolean forwardIndex, Object onlyValueKey, ID onlyIDKey ) throws Exception
+ {
+ return new IndexCursorWrapper<ID>( partitionDn, wrappedCursor, comparator, attributeOid, forwardIndex, onlyValueKey, onlyIDKey );
+ }
+}
\ No newline at end of file
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnManager.java?rev=1187466&r1=1187465&r2=1187466&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnManager.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/DefaultTxnManager.java Fri Oct 21 17:01:34 2011
@@ -43,6 +43,10 @@ import org.apache.directory.server.core.
import java.io.IOException;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public class DefaultTxnManager<ID> implements TxnManagerInternal<ID>
{
/** wal log manager */
@@ -83,6 +87,12 @@ public class DefaultTxnManager<ID> imple
}
};
+ /**
+ * TODO : doco
+ * @param txnLogManager
+ * @param idComparator
+ * @param idSerializer
+ */
public void init( TxnLogManager<ID> txnLogManager, Comparator<ID> idComparator, Serializer idSerializer )
{
this.txnLogManager = txnLogManager;
@@ -90,28 +100,31 @@ public class DefaultTxnManager<ID> imple
this.idSerializer = idSerializer;
}
+
/**
* {@inheritDoc}
*/
public Comparator<ID> getIDComparator()
{
- return this.idComparator;
+ return idComparator;
}
+
/**
* {@inheritDoc}
*/
public Serializer getIDSerializer()
{
- return this.idSerializer;
+ return idSerializer;
}
+
/**
* {@inheritDoc}
*/
public void beginTransaction( boolean readOnly ) throws IOException
{
- Transaction<ID> curTxn = this.getCurTxn();
+ Transaction<ID> curTxn = getCurTxn();
if ( curTxn != null )
{
@@ -121,28 +134,28 @@ public class DefaultTxnManager<ID> imple
if ( readOnly )
{
- this.beginReadOnlyTxn();
+ beginReadOnlyTxn();
}
else
{
- this.beginReadWriteTxn();
+ beginReadWriteTxn();
}
-
}
+
/**
* {@inheritDoc}
*/
public void commitTransaction() throws IOException
{
- Transaction<ID> txn = this.getCurTxn();
+ Transaction<ID> txn = getCurTxn();
if ( txn == null )
{
throw new IllegalStateException(" trying to commit non existent txn ");
}
- this.prepareForEndingTxn( txn );
+ prepareForEndingTxn( txn );
if ( txn instanceof ReadOnlyTxn )
{
@@ -150,19 +163,19 @@ public class DefaultTxnManager<ID> imple
}
else
{
- this.commitReadWriteTxn( (ReadWriteTxn<ID>)txn );
+ commitReadWriteTxn( (ReadWriteTxn<ID>)txn );
}
txnVar.set( null );
-
}
+
/**
* {@inheritDoc}
*/
public void abortTransaction() throws IOException
{
- Transaction<ID> txn = this.getCurTxn();
+ Transaction<ID> txn = getCurTxn();
if ( txn == null )
{
@@ -170,17 +183,18 @@ public class DefaultTxnManager<ID> imple
return;
}
- this.prepareForEndingTxn( txn );
+ prepareForEndingTxn( txn );
if ( txn instanceof ReadWriteTxn )
{
- this.abortReadWriteTxn( (ReadWriteTxn<ID>)txn );
+ abortReadWriteTxn( (ReadWriteTxn<ID>)txn );
}
txn.abortTxn();
txnVar.set( null );
}
+
/**
* {@inheritDoc}
*/
@@ -190,6 +204,7 @@ public class DefaultTxnManager<ID> imple
return (Transaction<ID>)txnVar.get();
}
+
private void beginReadOnlyTxn()
{
ReadOnlyTxn<ID> txn = new ReadOnlyTxn<ID>();
@@ -204,7 +219,7 @@ public class DefaultTxnManager<ID> imple
lastTxnToCheck = latestCommittedTxn.get();
lastTxnToCheck.getRefCount().getAndIncrement();
- }while ( lastTxnToCheck != latestCommittedTxn.get() );
+ } while ( lastTxnToCheck != latestCommittedTxn.get() );
// Determine start time
long startTime;
@@ -220,10 +235,11 @@ public class DefaultTxnManager<ID> imple
txn.startTxn( startTime );
- this.buildCheckList( txn, lastTxnToCheck );
+ buildCheckList( txn, lastTxnToCheck );
txnVar.set( txn );
}
+
private void beginReadWriteTxn() throws IOException
{
@@ -257,7 +273,6 @@ public class DefaultTxnManager<ID> imple
}
}
-
logRecord.setData( data, data.length );
ReadWriteTxn<ID> lastTxnToCheck = null;
@@ -286,13 +301,12 @@ public class DefaultTxnManager<ID> imple
}
// Finally build the check list
- this.buildCheckList( txn, lastTxnToCheck );
+ buildCheckList( txn, lastTxnToCheck );
txnVar.set( txn );
}
-
private void buildCheckList( Transaction<ID> txn, ReadWriteTxn<ID> lastTxnToCheck )
{
if ( lastTxnToCheck != null )
@@ -302,6 +316,7 @@ public class DefaultTxnManager<ID> imple
List<ReadWriteTxn<ID>> toCheckList = txn.getTxnsToCheck();
Iterator<ReadWriteTxn<ID>> it = committedQueue.iterator();
+
while ( it.hasNext() )
{
toAdd = it.next();
@@ -321,17 +336,17 @@ public class DefaultTxnManager<ID> imple
it = toCheckList.iterator();
ReadWriteTxn<ID> toCheck;
+
while ( it.hasNext() )
{
toCheck = it.next();
+
if ( toCheck.commitTime <= flushedLSN )
{
it.remove();
}
}
-
}
-
}
@@ -359,6 +374,7 @@ public class DefaultTxnManager<ID> imple
}
}
+
private void commitReadWriteTxn( ReadWriteTxn<ID> txn ) throws IOException
{
UserLogRecord logRecord = txn.getUserLogRecord();
@@ -395,9 +411,9 @@ public class DefaultTxnManager<ID> imple
verifyLock.lock();
// TODO verify txn here throw conflict exception if necessary
-
writeTxnsLock.lock();
+
try
{
// TODO sync of log can be done outside the locks.
@@ -450,7 +466,5 @@ public class DefaultTxnManager<ID> imple
logRecord.setData( data, data.length );
txnLogManager.log( logRecord, false );
-
}
-
}
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexCursorWrapper.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexCursorWrapper.java?rev=1187466&r1=1187465&r2=1187466&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexCursorWrapper.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexCursorWrapper.java Fri Oct 21 17:01:34 2011
@@ -32,6 +32,10 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.model.name.Dn;
import org.apache.directory.shared.ldap.model.entry.Entry;;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public class IndexCursorWrapper<ID> extends AbstractIndexCursor<Object, Entry, ID>
{
/** Cursors to merge */
@@ -67,16 +71,13 @@ public class IndexCursorWrapper<ID> exte
/** unsupported operation message */
private static final String UNSUPPORTED_MSG = I18n.err( I18n.ERR_722 );
-
public IndexCursorWrapper( Dn partitionDn, IndexCursor<Object, Entry, ID> wrappedCursor, IndexComparator<Object,ID> comparator, String attributeOid, boolean forwardIndex, Object onlyValueKey, ID onlyIDKey )
{
-
this.partitionDn = partitionDn;
this.forwardIndex = forwardIndex;
this.attributeOid = attributeOid;
this.comparator = comparator;
-
TxnManagerInternal<ID> txnManager = TxnManagerFactory.<ID>txnManagerInternalInstance();
Transaction<ID> curTxn = txnManager.getCurTxn();
List<ReadWriteTxn<ID>> toCheck = curTxn.getTxnsToCheck();
@@ -108,6 +109,7 @@ public class IndexCursorWrapper<ID> exte
}
}
+
/**
* {@inheritDoc}
*/
@@ -124,7 +126,8 @@ public class IndexCursorWrapper<ID> exte
{
values.set( idx, null );
cursor = cursors.get( idx );
- if( cursor != null )
+
+ if ( cursor != null )
{
cursor.after( element );
}
@@ -149,7 +152,8 @@ public class IndexCursorWrapper<ID> exte
{
values.set( idx, null );
cursor = cursors.get( idx );
- if( cursor != null )
+
+ if ( cursor != null )
{
cursor.before( element );
}
@@ -175,7 +179,8 @@ public class IndexCursorWrapper<ID> exte
{
values.set( idx, null );
cursor = cursors.get( idx );
- if( cursor != null )
+
+ if ( cursor != null )
{
cursor.afterValue( id, value );
}
@@ -201,7 +206,8 @@ public class IndexCursorWrapper<ID> exte
{
values.set( idx, null );
cursor = cursors.get( idx );
- if( cursor != null )
+
+ if ( cursor != null )
{
cursor.beforeValue( id, value );
}
@@ -227,7 +233,8 @@ public class IndexCursorWrapper<ID> exte
{
values.set( idx, null );
cursor = cursors.get( idx );
- if( cursor != null )
+
+ if ( cursor != null )
{
cursor.beforeFirst();
}
@@ -253,7 +260,8 @@ public class IndexCursorWrapper<ID> exte
{
values.set( idx, null );
cursor = cursors.get( idx );
- if( cursor != null )
+
+ if ( cursor != null )
{
cursor.afterLast( );
}
@@ -262,25 +270,30 @@ public class IndexCursorWrapper<ID> exte
getIndex = -1;
}
+
/**
* {@inheritDoc}
*/
public boolean first() throws Exception
{
- this.beforeFirst();
- return this.next();
+ beforeFirst();
+
+ return next();
}
+
/**
* {@inheritDoc}
*/
public boolean last() throws Exception
{
- this.afterLast();
- return this.previous();
+ afterLast();
+
+ return previous();
}
+
/**
* {@inheritDoc}
*/
@@ -293,27 +306,32 @@ public class IndexCursorWrapper<ID> exte
checkNotClosed( "next()" );
IndexEntry<Object,ID> lastValue = null;
+
if ( getIndex >= 0 )
{
lastValue = values.get( getIndex );
}
int idx;
+
if ( positioned == false )
{
afterLast();
}
- if ( movingNext == false || ( getIndex < 0 ) )
+ if (( movingNext == false ) || ( getIndex < 0 ) )
{
minValue = null;
getIndex = -1;
+
for ( idx = 0; idx < values.size(); idx++ )
{
cursor = cursors.get( idx );
- if ( cursor != null && cursor.next() )
+
+ if ( ( cursor != null ) && cursor.next() )
{
value = cursor.get();
+
if ( ( getIndex < 0 ) || ( comparator.compare( value, minValue ) < 0 ) )
{
minValue = value;
@@ -327,17 +345,17 @@ public class IndexCursorWrapper<ID> exte
values.set( idx, null );
}
}
-
}
else
{
// Move the last cursor we did a get from and recompute minimum
- this.recomputeMinimum();
+ recomputeMinimum();
}
int txnIdx;
ReadWriteTxn<ID> curTxn;
boolean valueDeleted;
+
do
{
if ( getIndex < 0 )
@@ -348,12 +366,14 @@ public class IndexCursorWrapper<ID> exte
value = values.get( getIndex );
txnIdx = getIndex;
+
if ( txnIdx > 0 )
{
txnIdx--;
}
valueDeleted = false;
+
for ( ; txnIdx < txns.size(); txnIdx++ )
{
curTxn = txns.get( txnIdx );
@@ -366,18 +386,17 @@ public class IndexCursorWrapper<ID> exte
}
}
- if ( valueDeleted == false && ( lastValue == null || ( comparator.compare( value, lastValue ) > 0 ) ) )
+ if ( ( valueDeleted == false ) && ( ( lastValue == null ) || ( comparator.compare( value, lastValue ) > 0 ) ) )
{
break;
}
// Recompute minimum
- this.recomputeMinimum();
+ recomputeMinimum();
} while ( true );
return ( getIndex >= 0 );
-
}
@@ -393,27 +412,32 @@ public class IndexCursorWrapper<ID> exte
checkNotClosed( "previous()" );
IndexEntry<Object,ID> lastValue = null;
+
if ( getIndex >= 0 )
{
lastValue = values.get( getIndex );
}
int idx;
+
if ( positioned == false )
{
afterLast();
}
- if ( movingNext == false || ( getIndex < 0 ) )
+ if ( ( movingNext == false ) || ( getIndex < 0 ) )
{
maxValue = null;
getIndex = -1;
+
for ( idx = 0; idx < values.size(); idx++ )
{
cursor = cursors.get( idx );
- if ( cursor != null && cursor.next() )
+
+ if ( ( cursor != null ) && cursor.next() )
{
value = cursor.get();
+
if ( ( getIndex < 0 ) || ( comparator.compare( value, maxValue ) > 0 ) )
{
maxValue = value;
@@ -427,17 +451,17 @@ public class IndexCursorWrapper<ID> exte
values.set( idx, null );
}
}
-
}
else
{
// Move the last cursor we did a get from and recompute maximum
- this.recomputeMaximum();
+ recomputeMaximum();
}
int txnIdx;
ReadWriteTxn<ID> curTxn;
boolean valueDeleted;
+
do
{
if ( getIndex < 0 )
@@ -448,12 +472,14 @@ public class IndexCursorWrapper<ID> exte
value = values.get( getIndex );
txnIdx = getIndex;
+
if ( txnIdx > 0 )
{
txnIdx--;
}
valueDeleted = false;
+
for ( ; txnIdx < txns.size(); txnIdx++ )
{
curTxn = txns.get( txnIdx );
@@ -466,22 +492,19 @@ public class IndexCursorWrapper<ID> exte
}
}
- if ( valueDeleted == false && ( lastValue == null || ( comparator.compare( value, lastValue ) < 0 ) ) )
+ if ( ( valueDeleted == false ) && ( ( lastValue == null ) || ( comparator.compare( value, lastValue ) < 0 ) ) )
{
break;
}
// Recompute maximum
- this.recomputeMaximum();
-
+ recomputeMaximum();
} while ( true );
return ( getIndex >= 0 );
-
}
-
/**
* {@inheritDoc}
*/
@@ -511,7 +534,6 @@ public class IndexCursorWrapper<ID> exte
@Override
public void close() throws Exception
{
-
super.close();
IndexCursor<Object,Entry,ID> cursor;
@@ -520,6 +542,7 @@ public class IndexCursorWrapper<ID> exte
for ( idx = 0; idx < cursors.size(); idx++ )
{
cursor = cursors.get( idx );
+
if ( cursor != null )
{
cursor.close();
@@ -542,6 +565,7 @@ public class IndexCursorWrapper<ID> exte
for ( idx = 0; idx < cursors.size(); idx++ )
{
cursor = cursors.get( idx );
+
if ( cursor != null )
{
cursor.close( cause );
@@ -549,6 +573,7 @@ public class IndexCursorWrapper<ID> exte
}
}
+
/**
* {@inheritDoc}
*/
@@ -566,6 +591,7 @@ public class IndexCursorWrapper<ID> exte
int idx;
cursor = cursors.get( getIndex );
+
if ( cursor.next() )
{
values.set( getIndex , cursor.get() );
@@ -578,9 +604,11 @@ public class IndexCursorWrapper<ID> exte
minValue = null;
getIndex = -1;
+
for ( idx = 0; idx < values.size(); idx++ )
{
value = values.get( idx );
+
if ( value != null )
{
if ( ( getIndex < 0 ) || ( comparator.compare( value, minValue ) < 0 ) )
@@ -592,6 +620,7 @@ public class IndexCursorWrapper<ID> exte
}
}
+
private void recomputeMaximum() throws Exception
{
IndexCursor<Object,Entry,ID> cursor;
@@ -600,6 +629,7 @@ public class IndexCursorWrapper<ID> exte
int idx;
cursor = cursors.get( getIndex );
+
if ( cursor.next() )
{
values.set( getIndex , cursor.get() );
@@ -612,9 +642,11 @@ public class IndexCursorWrapper<ID> exte
maxValue = null;
getIndex = -1;
+
for ( idx = 0; idx < values.size(); idx++ )
{
value = values.get( idx );
+
if ( value != null )
{
if ( ( getIndex < 0 ) || ( comparator.compare( value, maxValue ) > 0 ) )
@@ -625,5 +657,4 @@ public class IndexCursorWrapper<ID> exte
}
}
}
-
}
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexWrapper.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexWrapper.java?rev=1187466&r1=1187465&r2=1187466&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexWrapper.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/IndexWrapper.java Fri Oct 21 17:01:34 2011
@@ -33,6 +33,10 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.model.name.Dn;
import org.apache.directory.shared.ldap.model.schema.AttributeType;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public class IndexWrapper<ID> implements Index<Object, Entry, ID>
{
/** wrapped index */
@@ -153,11 +157,12 @@ public class IndexWrapper<ID> implements
*/
public ID forwardLookup( Object attrVal ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.forwardCursor( attrVal );
+ IndexCursor<Object, Entry, ID> cursor = forwardCursor( attrVal );
try
{
cursor.beforeValue( null, attrVal );
+
if ( cursor.next() )
{
return cursor.get().getId();
@@ -177,11 +182,12 @@ public class IndexWrapper<ID> implements
*/
public Object reverseLookup( ID id ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.reverseCursor( id );
+ IndexCursor<Object, Entry, ID> cursor = reverseCursor( id );
try
{
cursor.beforeValue( id, null );
+
if ( cursor.next() )
{
return cursor.get().getValue();
@@ -236,7 +242,8 @@ public class IndexWrapper<ID> implements
{
wrappedCursor = logManager.wrap( partitionDn, cursor, wrappedIndex.getReverseIndexEntryComparator(),
wrappedIndex.getAttribute().getOid(), false, null, null );
- } catch (Exception e)
+ }
+ catch (Exception e)
{
cursor.close( e );
throw e;
@@ -259,7 +266,8 @@ public class IndexWrapper<ID> implements
{
wrappedCursor = logManager.wrap( partitionDn, cursor, wrappedIndex.getForwardIndexEntryComparator(),
wrappedIndex.getAttribute().getOid(), true, null, null );
- } catch (Exception e)
+ }
+ catch (Exception e)
{
cursor.close( e );
throw e;
@@ -267,6 +275,7 @@ public class IndexWrapper<ID> implements
return wrappedCursor;
}
+
/**
* {@inheritDoc}
@@ -281,7 +290,8 @@ public class IndexWrapper<ID> implements
{
wrappedCursor = logManager.wrap( partitionDn, cursor, wrappedIndex.getReverseIndexEntryComparator(),
wrappedIndex.getAttribute().getOid(), false, null, id );
- } catch (Exception e)
+ }
+ catch (Exception e)
{
cursor.close( e );
throw e;
@@ -289,6 +299,7 @@ public class IndexWrapper<ID> implements
return wrappedCursor;
}
+
/**
* {@inheritDoc}
@@ -303,7 +314,8 @@ public class IndexWrapper<ID> implements
{
wrappedCursor = logManager.wrap( partitionDn, cursor, wrappedIndex.getForwardIndexEntryComparator(),
wrappedIndex.getAttribute().getOid(), true, key, null );
- } catch (Exception e)
+ }
+ catch (Exception e)
{
cursor.close( e );
throw e;
@@ -311,6 +323,7 @@ public class IndexWrapper<ID> implements
return wrappedCursor;
}
+
/**
* {@inheritDoc}
@@ -319,6 +332,7 @@ public class IndexWrapper<ID> implements
{
throw new UnsupportedOperationException();
}
+
/**
* {@inheritDoc}
@@ -327,13 +341,14 @@ public class IndexWrapper<ID> implements
{
throw new UnsupportedOperationException();
}
+
/**
* {@inheritDoc}
*/
public boolean forward( Object attrVal ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.forwardCursor( attrVal );
+ IndexCursor<Object, Entry, ID> cursor = forwardCursor( attrVal );
try
{
@@ -349,18 +364,20 @@ public class IndexWrapper<ID> implements
cursor.close();
}
}
+
/**
* {@inheritDoc}
*/
public boolean forward( Object attrVal, ID id ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.forwardCursor( attrVal );
+ IndexCursor<Object, Entry, ID> cursor = forwardCursor( attrVal );
Comparator<ID> idComp = wrappedIndex.getForwardIndexEntryComparator().getIDComparator();
try
{
cursor.beforeValue( id, attrVal );
+
if ( cursor.next() && ( idComp.compare( cursor.get().getId(), id ) == 0 ) )
{
return true;
@@ -371,15 +388,16 @@ public class IndexWrapper<ID> implements
finally
{
cursor.close();
- }
+ }
}
+
/**
* {@inheritDoc}
*/
public boolean reverse( ID id ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.reverseCursor( id );
+ IndexCursor<Object, Entry, ID> cursor = reverseCursor( id );
try
{
@@ -396,17 +414,19 @@ public class IndexWrapper<ID> implements
}
}
+
/**
* {@inheritDoc}
*/
public boolean reverse( ID id, Object attrVal ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.reverseCursor( id );
+ IndexCursor<Object, Entry, ID> cursor = reverseCursor( id );
Comparator<Object> valueComp = wrappedIndex.getForwardIndexEntryComparator().getValueComparator();
try
{
cursor.beforeValue( id, attrVal );
+
if ( cursor.next() && ( valueComp.compare( cursor.get().getValue(), attrVal ) == 0 ))
{
return true;
@@ -419,17 +439,19 @@ public class IndexWrapper<ID> implements
cursor.close();
}
}
+
/**
* {@inheritDoc}
*/
public boolean forwardGreaterOrEq( Object attrVal ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.forwardCursor();
+ IndexCursor<Object, Entry, ID> cursor = forwardCursor();
try
{
cursor.beforeValue( null, attrVal );
+
if ( cursor.next() )
{
return true;
@@ -442,17 +464,19 @@ public class IndexWrapper<ID> implements
cursor.close();
}
}
+
/**
* {@inheritDoc}
*/
public boolean forwardGreaterOrEq( Object attrVal, ID id ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.forwardCursor();
+ IndexCursor<Object, Entry, ID> cursor = forwardCursor();
try
{
cursor.beforeValue( id, attrVal );
+
if ( cursor.next() )
{
return true;
@@ -465,17 +489,19 @@ public class IndexWrapper<ID> implements
cursor.close();
}
}
+
/**
* {@inheritDoc}
*/
public boolean reverseGreaterOrEq( ID id ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.reverseCursor();
+ IndexCursor<Object, Entry, ID> cursor = reverseCursor();
try
{
cursor.beforeValue( id, null );
+
if ( cursor.next() )
{
return true;
@@ -488,17 +514,19 @@ public class IndexWrapper<ID> implements
cursor.close();
}
}
+
/**
* {@inheritDoc}
*/
public boolean reverseGreaterOrEq( ID id, Object attrVal ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.reverseCursor();
+ IndexCursor<Object, Entry, ID> cursor = reverseCursor();
try
{
cursor.beforeValue( id, attrVal );
+
if ( cursor.next() )
{
return true;
@@ -511,18 +539,19 @@ public class IndexWrapper<ID> implements
cursor.close();
}
}
+
/**
* {@inheritDoc}
*/
public boolean forwardLessOrEq( Object attrVal ) throws Exception
{
-
- IndexCursor<Object, Entry, ID> cursor = this.forwardCursor();
+ IndexCursor<Object, Entry, ID> cursor = forwardCursor();
try
{
cursor.afterValue( null, attrVal );
+
if ( cursor.previous() )
{
return true;
@@ -535,17 +564,19 @@ public class IndexWrapper<ID> implements
cursor.close();
}
}
+
/**
* {@inheritDoc}
*/
public boolean forwardLessOrEq( Object attrVal, ID id ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.forwardCursor();
+ IndexCursor<Object, Entry, ID> cursor = forwardCursor();
try
{
cursor.afterValue( id, attrVal );
+
if ( cursor.previous() )
{
return true;
@@ -558,17 +589,19 @@ public class IndexWrapper<ID> implements
cursor.close();
}
}
+
/**
* {@inheritDoc}
*/
public boolean reverseLessOrEq( ID id ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.reverseCursor();
+ IndexCursor<Object, Entry, ID> cursor = reverseCursor();
try
{
cursor.afterValue( id, null );
+
if ( cursor.previous() )
{
return true;
@@ -581,17 +614,19 @@ public class IndexWrapper<ID> implements
cursor.close();
}
}
+
/**
* {@inheritDoc}
*/
public boolean reverseLessOrEq( ID id, Object attrVal ) throws Exception
{
- IndexCursor<Object, Entry, ID> cursor = this.reverseCursor();
+ IndexCursor<Object, Entry, ID> cursor = reverseCursor();
try
{
cursor.afterValue( id, attrVal );
+
if ( cursor.previous() )
{
return true;
@@ -605,6 +640,7 @@ public class IndexWrapper<ID> implements
}
}
+
/**
* {@inheritDoc}
*/
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/MasterTableWrapper.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/MasterTableWrapper.java?rev=1187466&r1=1187465&r2=1187466&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/MasterTableWrapper.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/txn/MasterTableWrapper.java Fri Oct 21 17:01:34 2011
@@ -28,6 +28,10 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.model.entry.Entry;
import org.apache.directory.shared.ldap.model.name.Dn;
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public class MasterTableWrapper<ID> implements MasterTable<ID, Entry>
{
/** Wrapped master table */
@@ -53,6 +57,7 @@ public class MasterTableWrapper<ID> impl
wrappedTable.resetCounter();
}
+
/**
* {@inheritDoc}
*/
@@ -89,13 +94,12 @@ public class MasterTableWrapper<ID> impl
}
-
/**
* {@inheritDoc}
*/
public boolean has( ID key ) throws Exception
{
- return ( this.get( key ) != null );
+ return ( get( key ) != null );
}
@@ -104,9 +108,9 @@ public class MasterTableWrapper<ID> impl
*/
public boolean has( ID key, Entry value ) throws Exception
{
- Entry stored = this.get( key );
+ Entry stored = get( key );
- return ( stored != null && stored.equals( value ) );
+ return ( ( stored != null ) && stored.equals( value ) );
}
@@ -151,7 +155,6 @@ public class MasterTableWrapper<ID> impl
*/
public Entry get( ID key ) throws Exception
{
-
if ( key == null )
{
return null;
@@ -160,6 +163,7 @@ public class MasterTableWrapper<ID> impl
TxnLogManager<ID> logManager = TxnManagerFactory.<ID>txnLogManagerInstance();
Entry entry = wrappedTable.get( key );
entry = logManager.mergeUpdates( partitionDn, key, entry );
+
return entry;
}
@@ -169,7 +173,7 @@ public class MasterTableWrapper<ID> impl
*/
public void put( ID key, Entry value ) throws Exception
{
- wrappedTable.put( key, value );
+ wrappedTable.put( key, value );
}
@@ -178,7 +182,7 @@ public class MasterTableWrapper<ID> impl
*/
public void remove( ID key ) throws Exception
{
- wrappedTable.remove( key );
+ wrappedTable.remove( key );
}
@@ -198,6 +202,7 @@ public class MasterTableWrapper<ID> impl
{
return wrappedTable.cursor();
}
+
/**
* {@inheritDoc}
@@ -233,6 +238,7 @@ public class MasterTableWrapper<ID> impl
{
return wrappedTable.count( key );
}
+
/**
* {@inheritDoc}
@@ -259,5 +265,4 @@ public class MasterTableWrapper<ID> impl
{
wrappedTable.close();
}
-
}