please revert this commit.
On Wed, Mar 14, 2012 at 12:06 PM, <[email protected]> wrote: > Author: elecharny > Date: Wed Mar 14 19:06:17 2012 > New Revision: 1300690 > > URL: http://svn.apache.org/viewvc?rev=1300690&view=rev > Log: > o Added a type for LogEdit stored into UserLogRecord, in order to be able to > read them back from the stream knowing what is the stored data. > o Created an injectData() method to factorize the serialization of the > LogEdit instances > o Removed the readObject()/writeObject() calls in the IndexChange class > o Added some Javadoc > o Minor refactoring > > Added: > > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java > - copied, changed from r1299595, > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java > Modified: > > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/LogAnchor.java > > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/UserLogRecord.java > > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnLogManager.java > > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/AbstractLogEdit.java > > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/LogEdit.java > > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/DefaultLogFileManager.java > > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/LogFlushManager.java > > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java > > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java > > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java > > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/EntryChange.java > > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/IndexChange.java > > Modified: > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/LogAnchor.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/LogAnchor.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/LogAnchor.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/LogAnchor.java > Wed Mar 14 19:06:17 2012 > @@ -86,7 +86,7 @@ public class LogAnchor implements Extern > > public void resetLogAnchor( LogAnchor logAnchor ) > { > - resetLogAnchor( logAnchor.getLogFileNumber(), > logAnchor.getLogFileOffset(), logAnchor.getLogLSN() ); > + resetLogAnchor( logAnchor.logFileNumber, logAnchor.logFileOffset, > logAnchor.logLSN ); > } > > > > Modified: > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/UserLogRecord.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/UserLogRecord.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/UserLogRecord.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/log/UserLogRecord.java > Wed Mar 14 19:06:17 2012 > @@ -44,6 +44,18 @@ import java.io.ObjectOutput; > */ > public class UserLogRecord implements Externalizable > { > + /** > + * An enum used to distinguished the data type being serialized in the > UserLogRecord > + */ > + public enum LogEditType > + { > + TXN, > + DATA; > + } > + > + /** The serialized LogEdit type */ > + private LogEditType dataType; > + > /** array used to hold user log records */ > private byte[] recordHolder; > > @@ -101,12 +113,23 @@ public class UserLogRecord implements Ex > @Override > public void readExternal( ObjectInput in ) throws IOException, > ClassNotFoundException > { > + // Read the DataType : TXN or DATA > + int type = in.read(); > + > + dataType = LogEditType.values()[type]; > + > + // The data size > length = in.readInt(); > - int dataSize = in.readInt(); > > - recordHolder = new byte[dataSize]; > + // The buffer size > + int bufferSize = in.readInt(); > + > + recordHolder = new byte[bufferSize]; > + > + // The buffer > in.readFully( recordHolder ); > > + // The position > logAnchor = new LogAnchor(); > logAnchor.readExternal( in ); > } > @@ -124,13 +147,29 @@ public class UserLogRecord implements Ex > @Override > public void writeExternal( ObjectOutput out ) throws IOException > { > + // The inner data type : TXN or DATA > + out.write( dataType.ordinal() ); > + > + // The size of the stored data > out.writeInt( length ); > + > + // The size of the container buffer > out.writeInt( recordHolder.length ); > + > + // The buffer > out.write( recordHolder ); > + > + // The position > logAnchor.writeExternal( out ); > } > > > + public void setType( LogEditType dataType ) > + { > + this.dataType = dataType; > + } > + > + > /** > * @see Object#toString() > */ > > Modified: > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnLogManager.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnLogManager.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnLogManager.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnLogManager.java > Wed Mar 14 19:06:17 2012 > @@ -36,7 +36,6 @@ import org.apache.directory.shared.ldap. > import org.apache.directory.shared.ldap.model.name.Dn; > > > - > /** > * > * @author <a href="mailto:[email protected]">Apache Directory > Project</a> > @@ -72,8 +71,7 @@ public interface TxnLogManager > * @param entry current version of the entry the txn has > * @return > */ > - Entry mergeUpdates(Dn partitionDN, UUID entryID, Entry entry ); > - > + Entry mergeUpdates( Dn partitionDN, UUID entryID, Entry entry ); > > > /** > @@ -131,7 +129,6 @@ public interface TxnLogManager > String attributeOid, boolean forwardIndex, Object onlyValueKey, UUID > onlyIDKey ) throws Exception; > > > - > /** > * Returns an index which a provides a transactionally consistent view > over the given index > * > > Modified: > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/AbstractLogEdit.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/AbstractLogEdit.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/AbstractLogEdit.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/AbstractLogEdit.java > Wed Mar 14 19:06:17 2012 > @@ -20,7 +20,13 @@ > package org.apache.directory.server.core.api.txn.logedit; > > > +import java.io.ByteArrayOutputStream; > +import java.io.ObjectOutputStream; > + > import org.apache.directory.server.core.api.log.LogAnchor; > +import org.apache.directory.server.core.api.log.UserLogRecord; > +import org.slf4j.Logger; > +import org.slf4j.LoggerFactory; > > > /** > @@ -29,13 +35,21 @@ import org.apache.directory.server.core. > */ > public abstract class AbstractLogEdit implements LogEdit > { > - /** position in the wal */ > + /** A logger for this class */ > + private static final Logger LOG = LoggerFactory.getLogger( > AbstractLogEdit.class ); > + > + /** Position in the wal */ > private transient LogAnchor logAnchor = new LogAnchor(); > > /** Transaction under which the change is done */ > protected long txnID; > > > + /** > + * Create a new instance of AbstractLogEdit > + * > + * @param txnID The transaction ID to store > + */ > protected AbstractLogEdit( long txnID ) > { > this.txnID = txnID; > @@ -70,4 +84,44 @@ public abstract class AbstractLogEdit im > { > txnID = id; > } > + > + > + /** > + * {@inheritDoc} > + */ > + public void injectData( UserLogRecord logRecord, > UserLogRecord.LogEditType type ) throws Exception > + { > + logRecord.setType( type ); > + LOG.debug( "Serializing : " + this ); > + > + ObjectOutputStream out = null; > + ByteArrayOutputStream bout = null; > + byte[] data; > + > + try > + { > + bout = new ByteArrayOutputStream(); > + out = new ObjectOutputStream( bout ); > + > + // The LogEdit instance > + writeExternal( out ); > + > + out.flush(); > + data = bout.toByteArray(); > + } > + finally > + { > + if ( bout != null ) > + { > + bout.close(); > + } > + > + if ( out != null ) > + { > + out.close(); > + } > + } > + > + logRecord.setData( data, data.length ); > + } > } > > Modified: > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/LogEdit.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/LogEdit.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/LogEdit.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/LogEdit.java > Wed Mar 14 19:06:17 2012 > @@ -19,15 +19,18 @@ > */ > package org.apache.directory.server.core.api.txn.logedit; > > -import org.apache.directory.server.core.api.log.LogAnchor; > > import java.io.Externalizable; > > +import org.apache.directory.server.core.api.log.LogAnchor; > +import org.apache.directory.server.core.api.log.UserLogRecord; > + > + > /** > * > * @author <a href="mailto:[email protected]">Apache Directory > Project</a> > */ > -public interface LogEdit extends Externalizable > +public interface LogEdit extends Externalizable > { > /** > * Returns the position the edit is inserted in the wal. > @@ -37,11 +40,22 @@ public interface LogEdit extends Externa > * @return position of the log edit in the wal > */ > LogAnchor getLogAnchor(); > - > + > + > /** > * Applies the logedit to the underlying partitions > * > * @param recovery true if at recovery stage > */ > void apply( boolean recovery ) throws Exception; > + > + > + /** > + * Serialize the LogEdit into a UserLogRecord > + * > + * @param logRecord The UserLogRecord which will contain the serialized > LogEdit > + * @param type The type of data being written (TXN or DATA) > + * @throws Exception If the serialization failed > + */ > + void injectData( UserLogRecord logRecord, UserLogRecord.LogEditType type > ) throws Exception; > } > > Modified: > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/DefaultLogFileManager.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/DefaultLogFileManager.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/DefaultLogFileManager.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/DefaultLogFileManager.java > Wed Mar 14 19:06:17 2012 > @@ -22,16 +22,16 @@ package org.apache.directory.server.core > > import java.io.EOFException; > import java.io.File; > -import java.io.IOException; > import java.io.FileNotFoundException; > - > +import java.io.IOException; > 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.<br/> > - * Each log file has a name like > <b>logFileName/log_<logFileNumber>.suffix</b> > + * Each log file has a name like > <b>logFileName/log_<logFileNumber>.suffix</b><br/> > + * This class expose a reader and a writer for the given log file. > * > * @author <a href="mailto:[email protected]">Apache Directory > Project</a> > */ > > Modified: > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/LogFlushManager.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/LogFlushManager.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/LogFlushManager.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/LogFlushManager.java > Wed Mar 14 19:06:17 2012 > @@ -20,31 +20,29 @@ > package org.apache.directory.server.core.shared.log; > > > +import java.io.IOException; > import java.nio.ByteBuffer; > - > +import java.util.concurrent.atomic.AtomicInteger; > +import java.util.concurrent.locks.Condition; > import java.util.concurrent.locks.Lock; > import java.util.concurrent.locks.ReentrantLock; > -import java.util.concurrent.locks.Condition; > -import java.util.concurrent.atomic.AtomicInteger; > import java.util.zip.Adler32; > import java.util.zip.Checksum; > > +import org.apache.directory.server.core.api.log.InvalidLogException; > import org.apache.directory.server.core.api.log.LogAnchor; > import org.apache.directory.server.core.api.log.UserLogRecord; > -import org.apache.directory.server.core.api.log.InvalidLogException; > - > -import java.io.IOException; > - > import > org.apache.directory.server.core.shared.log.LogFileManager.LogFileWriter; > import org.apache.directory.server.i18n.I18n; > > > /** > - * Manages the flushing of log to media and scanning of logs. All appends to > the log file go through this class. > + * Manages the flushing of log to media and scanning of logs. All appends to > the log file go > + * through this class. > * > * 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. > + * 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. > * > * @author <a href="mailto:[email protected]">Apache Directory > Project</a> > */ > @@ -92,7 +90,7 @@ import org.apache.directory.server.i18n. > > /** > * 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 > + * size for each Log file (this maximum 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 > @@ -191,7 +189,7 @@ import org.apache.directory.server.i18n. > // Write the data > writeHead.put( userBuffer, 0, length ); > > - // Write the footeer > + // Write the footer > writeFooter( writeHead, ( int ) > checksum.getValue() ); > > appendedRecord = true; > > Modified: > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java > Wed Mar 14 19:06:17 2012 > @@ -20,9 +20,7 @@ > package org.apache.directory.server.core.shared.txn; > > > -import java.io.ByteArrayOutputStream; > import java.io.IOException; > -import java.io.ObjectOutputStream; > import java.util.Comparator; > import java.util.UUID; > > @@ -105,32 +103,7 @@ public class DefaultTxnLogManager implem > ReadWriteTxn txn = ( ReadWriteTxn ) curTxn; > UserLogRecord logRecord = txn.getUserLogRecord(); > > - ObjectOutputStream out = null; > - ByteArrayOutputStream bout = null; > - byte[] data; > - > - try > - { > - bout = new ByteArrayOutputStream(); > - out = new ObjectOutputStream( bout ); > - logEdit.writeExternal( out ); > - out.flush(); > - data = bout.toByteArray(); > - } > - finally > - { > - if ( bout != null ) > - { > - bout.close(); > - } > - > - if ( out != null ) > - { > - out.close(); > - } > - } > - > - logRecord.setData( data, data.length ); > + logEdit.injectData( logRecord, UserLogRecord.LogEditType.DATA ); > > log( logRecord, sync ); > > > Modified: > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java > Wed Mar 14 19:06:17 2012 > @@ -20,9 +20,7 @@ > package org.apache.directory.server.core.shared.txn; > > > -import java.io.ByteArrayOutputStream; > import java.io.IOException; > -import java.io.ObjectOutputStream; > import java.util.HashSet; > import java.util.Iterator; > import java.util.List; > @@ -43,6 +41,7 @@ import org.apache.directory.server.core. > import org.apache.directory.server.core.api.txn.TxnConflictException; > import org.apache.directory.server.core.api.txn.TxnHandle; > import org.apache.directory.server.core.api.txn.TxnLogManager; > +import org.apache.directory.server.core.api.txn.logedit.LogEdit; > import org.apache.directory.server.core.shared.txn.logedit.TxnStateChange; > > > @@ -64,7 +63,7 @@ class DefaultTxnManager implements TxnMa > > /** Used to assign start and commit version numbers to writeTxns */ > private Lock writeTxnsLock = new ReentrantLock(); > - > + > /** Used to order txns in case of conflicts */ > private ReadWriteLock optimisticLock = new ReentrantReadWriteLock(); > > @@ -175,6 +174,7 @@ class DefaultTxnManager implements TxnMa > syncer = null; > } > > + > /** > * {@inheritDoc} > */ > @@ -184,19 +184,19 @@ class DefaultTxnManager implements TxnMa > > // Should have a rw txn > if ( ( curTxn == null ) || > - !( curTxn instanceof ReadWriteTxn ) ) > + !( curTxn instanceof ReadWriteTxn ) ) > { > // Cannot start a TXN when a RW txn is ongoing > throw new IllegalStateException( "Unexpected txn state when > trying txn: " + > curTxn ); > } > - > + > // abort current txn and start a new read write txn > - > + > abortTransaction(); > return beginReadWriteTxn( true ); > } > - > + > > /** > * {@inheritDoc} > @@ -241,7 +241,7 @@ class DefaultTxnManager implements TxnMa > { > throw new IOException( "Flushing of txns failed" ); > } > - > + > prepareForEndingTxn( txn ); > > if ( txn instanceof ReadOnlyTxn ) > @@ -265,23 +265,23 @@ class DefaultTxnManager implements TxnMa > public void abortTransaction() throws Exception > { > Transaction txn = getCurTxn(); > - > + > if ( txn == null ) > { > - throw new IllegalStateException("Trying to abort while there is > not txn "); > + throw new IllegalStateException( "Trying to abort while there is > not txn " ); > } > - > + > boolean isExclusive = txn.isExclusive(); > > try > { > prepareForEndingTxn( txn ); > - > + > if ( txn instanceof ReadWriteTxn ) > { > abortReadWriteTxn( ( ReadWriteTxn ) txn ); > } > - > + > txn.abortTxn(); > setCurTxn( null ); > } > @@ -420,7 +420,7 @@ class DefaultTxnManager implements TxnMa > > buildCheckList( txn, lastTxnToCheck ); > > - optimisticLock.readLock().lock(); > + optimisticLock.readLock().lock(); > setCurTxn( txn ); > > //System.out.println( "TRAN: Started " + txn ); > @@ -440,35 +440,11 @@ class DefaultTxnManager implements TxnMa > ReadWriteTxn txn = new ReadWriteTxn(); > UserLogRecord logRecord = txn.getUserLogRecord(); > > - TxnStateChange txnRecord = new TxnStateChange( LogAnchor.UNKNOWN_LSN, > + LogEdit logEdit = new TxnStateChange( LogAnchor.UNKNOWN_LSN, > TxnStateChange.ChangeState.TXN_BEGIN ); > - ObjectOutputStream out = null; > - ByteArrayOutputStream bout = null; > - byte[] data; > > - try > - { > - bout = new ByteArrayOutputStream(); > - out = new ObjectOutputStream( bout ); > - txnRecord.writeExternal( out ); > - out.flush(); > - data = bout.toByteArray(); > - } > - finally > - { > - if ( bout != null ) > - { > - bout.close(); > - } > + logEdit.injectData( logRecord, UserLogRecord.LogEditType.TXN ); > > - if ( out != null ) > - { > - out.close(); > - } > - } > - > - logRecord.setData( data, data.length ); > - > if ( retry == false ) > { > optimisticLock.readLock().lock(); > @@ -506,7 +482,7 @@ class DefaultTxnManager implements TxnMa > } > while ( lastTxnToCheck != latestVerifiedTxn.get() ); > } > - catch( Exception e ) > + catch ( Exception e ) > { > if ( txn.isExclusive() == false ) > { > @@ -657,34 +633,10 @@ class DefaultTxnManager implements TxnMa > { > UserLogRecord logRecord = txn.getUserLogRecord(); > > - TxnStateChange txnRecord = new TxnStateChange( txn.getStartTime(), > + LogEdit logEdit = new TxnStateChange( txn.getStartTime(), > TxnStateChange.ChangeState.TXN_COMMIT ); > - ObjectOutputStream out = null; > - ByteArrayOutputStream bout = null; > - byte[] data; > > - try > - { > - bout = new ByteArrayOutputStream(); > - out = new ObjectOutputStream( bout ); > - txnRecord.writeExternal( out ); > - out.flush(); > - data = bout.toByteArray(); > - } > - finally > - { > - if ( bout != null ) > - { > - bout.close(); > - } > - > - if ( out != null ) > - { > - out.close(); > - } > - } > - > - logRecord.setData( data, data.length ); > + logEdit.injectData( logRecord, UserLogRecord.LogEditType.TXN ); > > verifyLock.lock(); > > @@ -738,34 +690,11 @@ class DefaultTxnManager implements TxnMa > { > UserLogRecord logRecord = txn.getUserLogRecord(); > > - TxnStateChange txnRecord = new TxnStateChange( txn.getStartTime(), > + LogEdit logEdit = new TxnStateChange( txn.getStartTime(), > TxnStateChange.ChangeState.TXN_ABORT ); > - ObjectOutputStream out = null; > - ByteArrayOutputStream bout = null; > - byte[] data; > > - try > - { > - bout = new ByteArrayOutputStream(); > - out = new ObjectOutputStream( bout ); > - out.writeObject( txnRecord ); > - out.flush(); > - data = bout.toByteArray(); > - } > - finally > - { > - if ( bout != null ) > - { > - bout.close(); > - } > - > - if ( out != null ) > - { > - out.close(); > - } > - } > + logEdit.injectData( logRecord, UserLogRecord.LogEditType.TXN ); > > - logRecord.setData( data, data.length ); > txnLogManager.log( logRecord, false ); > } > > > Modified: > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java > Wed Mar 14 19:06:17 2012 > @@ -72,6 +72,7 @@ public class DataChangeContainer extends > public DataChangeContainer( Partition partition ) > { > super( Long.MIN_VALUE ); > + > this.partitionDn = partition.getSuffixDn(); > this.partition = partition; > } > > Modified: > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/EntryChange.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/EntryChange.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/EntryChange.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/EntryChange.java > Wed Mar 14 19:06:17 2012 > @@ -92,7 +92,7 @@ public class EntryChange implements Entr > } > } > > - // TODO in reovery mode, check the version of the entry. > + // TODO in recovery mode, check the version of the entry. > try > { > AttributeUtils.applyModification( curEntry, redoChange ); > > Modified: > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/IndexChange.java > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/IndexChange.java?rev=1300690&r1=1300689&r2=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/IndexChange.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/IndexChange.java > Wed Mar 14 19:06:17 2012 > @@ -62,6 +62,15 @@ public class IndexChange implements Inde > } > > > + /** > + * Create a new IndexChange instance. > + * > + * @param index The changed index > + * @param key The index' key > + * @param id The entry's UUID > + * @param type The change type, Add or Delete > + * @param isSystemIndex Tells f the index is a system index or a user > index > + */ > public IndexChange( Index<?> index, Object key, UUID id, Type type, > boolean isSystemIndex ) > { > this.index = index; > @@ -155,7 +164,29 @@ public class IndexChange implements Inde > public void readExternal( ObjectInput in ) throws IOException, > ClassNotFoundException > { > oid = in.readUTF(); > - key = in.readObject(); > + KeyType keyType = KeyType.getType( in.readByte() ); > + > + switch ( keyType ) > + { > + case STRING: > + key = in.readUTF(); > + break; > + > + case LONG: > + key = in.readLong(); > + break; > + > + case BYTES: > + int length = in.readInt(); > + key = new byte[length]; > + in.read( ( byte[] ) key ); > + break; > + > + case OBJECT: > + key = in.readObject(); > + break; > + } > + > id = UUID.fromString( in.readUTF() ); > type = Type.values()[in.readInt()]; > } > @@ -165,7 +196,29 @@ public class IndexChange implements Inde > public void writeExternal( ObjectOutput out ) throws IOException > { > out.writeUTF( oid ); > - out.writeObject( key ); > + > + if ( key instanceof String ) > + { > + out.write( KeyType.STRING.getOrdinal() ); > + out.writeUTF( ( String ) key ); > + } > + else if ( key instanceof byte[] ) > + { > + out.write( KeyType.BYTES.getOrdinal() ); > + out.writeInt( ( ( byte[] ) key ).length ); > + out.write( ( byte[] ) key ); > + } > + else if ( key instanceof Long ) > + { > + out.write( KeyType.LONG.getOrdinal() ); > + out.writeLong( ( Long ) key ); > + } > + else > + { > + out.write( KeyType.OBJECT.getOrdinal() ); > + out.writeObject( key ); > + } > + > out.writeUTF( id.toString() ); > out.writeInt( type.ordinal() ); > } > @@ -185,6 +238,7 @@ public class IndexChange implements Inde > StringBuilder sb = new StringBuilder(); > > sb.append( "IndexChange '" ); > + > // The index's name > sb.append( index.getAttributeId() ).append( "': " ); > > @@ -201,4 +255,42 @@ public class IndexChange implements Inde > > return sb.toString(); > } > + > + private enum KeyType > + { > + STRING(0), > + LONG(1), > + BYTES(2), > + OBJECT(3); > + > + private int value; > + > + > + private KeyType( int value ) > + { > + this.value = value; > + } > + > + > + private byte getOrdinal() > + { > + return ( byte ) value; > + } > + > + > + private static KeyType getType( byte value ) > + { > + switch ( value ) > + { > + case 0: > + return STRING; > + case 1: > + return LONG; > + case 2: > + return BYTES; > + default: > + return OBJECT; > + } > + } > + } > } > > Copied: > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java > (from r1299595, > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java) > URL: > http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java?p2=directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java&p1=directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java&r1=1299595&r2=1300690&rev=1300690&view=diff > ============================================================================== > --- > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java > (original) > +++ > directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java > Wed Mar 14 19:06:17 2012 > @@ -28,31 +28,60 @@ import org.apache.directory.server.core. > > > /** > + * A class used to store a transaction changeState (either BEGIN, COMMIT or > ABORT). > * > * @author <a href="mailto:[email protected]">Apache Directory > Project</a> > */ > public class TxnStateChange extends AbstractLogEdit > { > + /** SerialVrsionUID as requested for serializable classes */ > + private static final long serialVersionUID = 1; > + > + /** > + * Change State, one of : > + * <ul> > + * <li>TXN_BEGIN : for a starting transaction</li> > + * <li>TXN_COMMIT : for a validated transaction</li> > + * <li>TXN_ABORT : for an aborted transaction</li> > + * </ul> > + */ > + public enum ChangeState > + { > + TXN_BEGIN, > + TXN_COMMIT, > + TXN_ABORT > + } > + > /** State to record for the txn */ > ChangeState txnState; > > - private static final long serialVersionUID = 1; > - > > - // For deserialization > + /** > + * A default constructor used by deserialization > + */ > public TxnStateChange() > { > super( Long.MIN_VALUE ); > } > > > + /** > + * Creates a new TxnStateChange instance, with a transaction ID and a > ChangeState. > + * > + * @param txnID The transaction ID > + * @param txnState The ChangeState > + */ > public TxnStateChange( long txnID, ChangeState txnState ) > { > super( txnID ); > + > this.txnState = txnState; > } > > > + /** > + * @return The ChangeState for this transaction > + */ > public ChangeState getTxnState() > { > return txnState; > @@ -74,10 +103,12 @@ public class TxnStateChange extends Abst > out.writeInt( txnState.ordinal() ); > } > > - public enum ChangeState > + > + /** > + * @see Object#toString() > + */ > + public String toString() > { > - TXN_BEGIN, > - TXN_COMMIT, > - TXN_ABORT > + return "TxnStateChange[" + txnID + "/" + txnState + "]"; > } > } > >
