From commits-return-33170-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Fri Dec 23 16:39:59 2011 Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 87A207A4A for ; Fri, 23 Dec 2011 16:39:59 +0000 (UTC) Received: (qmail 85171 invoked by uid 500); 23 Dec 2011 16:39:59 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 85112 invoked by uid 500); 23 Dec 2011 16:39:59 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 85105 invoked by uid 99); 23 Dec 2011 16:39:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Dec 2011 16:39:58 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Dec 2011 16:39:54 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2E94F2388A9B for ; Fri, 23 Dec 2011 16:39:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1222739 - /directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java Date: Fri, 23 Dec 2011 16:39:33 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111223163933.2E94F2388A9B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Fri Dec 23 16:39:32 2011 New Revision: 1222739 URL: http://svn.apache.org/viewvc?rev=1222739&view=rev Log: Replaced iterators by for(T t : ts ) constructs Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java?rev=1222739&r1=1222738&r2=1222739&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java Fri Dec 23 16:39:32 2011 @@ -19,48 +19,45 @@ */ package org.apache.directory.server.core.shared.txn; -import java.util.List; -import java.util.LinkedList; + +import java.util.Comparator; +import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import java.util.NavigableSet; import java.util.Set; import java.util.TreeSet; -import java.util.Map; -import java.util.HashMap; import java.util.UUID; - import java.util.concurrent.atomic.AtomicInteger; -import java.util.Comparator; - -import org.apache.directory.server.core.api.txn.logedit.LogEdit; -import org.apache.directory.server.core.shared.txn.logedit.IndexChange; -import org.apache.directory.server.core.api.txn.logedit.DataChange; -import org.apache.directory.server.core.shared.txn.logedit.DataChangeContainer; import org.apache.directory.server.core.api.log.UserLogRecord; - import org.apache.directory.server.core.api.partition.Partition; import org.apache.directory.server.core.api.partition.index.ForwardIndexEntry; -import org.apache.directory.server.core.api.partition.index.ReverseIndexEntry; -import org.apache.directory.server.core.api.partition.index.IndexEntry; import org.apache.directory.server.core.api.partition.index.Index; +import org.apache.directory.server.core.api.partition.index.IndexEntry; +import org.apache.directory.server.core.api.partition.index.ReverseIndexEntry; import org.apache.directory.server.core.api.partition.index.UUIDComparator; - -import org.apache.directory.shared.ldap.model.name.Dn; +import org.apache.directory.server.core.api.txn.logedit.DataChange; +import org.apache.directory.server.core.api.txn.logedit.LogEdit; +import org.apache.directory.server.core.shared.txn.logedit.DataChangeContainer; +import org.apache.directory.server.core.shared.txn.logedit.IndexChange; import org.apache.directory.shared.ldap.model.entry.Entry; - - import org.apache.directory.shared.ldap.model.message.SearchScope; +import org.apache.directory.shared.ldap.model.name.Dn; + /** * * @author Apache Directory Project */ -/** Package protected */ class ReadWriteTxn extends AbstractTransaction -{ +/** Package protected */ +class ReadWriteTxn extends AbstractTransaction +{ /** list of log edits by the txn */ private List logEdits = new LinkedList(); - + /* * Number of txns that depend on this txn and previous committed * txns. This number is bumped up only after the txn is committed. @@ -69,49 +66,47 @@ import org.apache.directory.shared.ldap. * committed txns. */ private AtomicInteger txnRefCount = new AtomicInteger( 0 ); - + /** User record used to communicate data with log manager */ private UserLogRecord logRecord = new UserLogRecord(); - + /** A summary of forward index adds */ - private Map >>> forwardIndexAdds = - new HashMap >>>(); - + private Map>>> forwardIndexAdds = + new HashMap>>>(); + /** A summary of reverse index adds */ - private Map >>> reverseIndexAdds = - new HashMap >>>(); - + private Map>>> reverseIndexAdds = + new HashMap>>>(); + /** A summary of index deletes */ - private Map >>> indexDeletes = - new HashMap >>>(); - - + private Map>>> indexDeletes = + new HashMap>>>(); + /** List of Dn sets this txn depends */ private List readDns = new LinkedList(); - + /** List of Dn sets affected by the write operations of this txn */ private List writeDns = new LinkedList(); - - + + public AtomicInteger getRefCount() { return txnRefCount; } - - + + public UserLogRecord getUserLogRecord() { return logRecord; } - - + + public List getEdits() { return logEdits; } - - - + + /** * Logs the given log edit for this txn. If the edit contains index changes, it updates the summary * of changes for the changed index so that it is easier to provide a cursor view over the set of @@ -131,10 +126,8 @@ import org.apache.directory.shared.ldap. { DataChangeContainer dEdit = ( DataChangeContainer ) edit; List dataChanges = dEdit.getChanges(); - Iterator it = dataChanges.iterator(); Dn partitionDn = dEdit.getPartitionDn(); - DataChange nextChange; IndexChange indexChange; IndexChange.Type indexChangeType; ForwardIndexEntry indexEntry; @@ -173,10 +166,8 @@ import org.apache.directory.shared.ldap. indexDeletes.put( partitionDn, deletedIndices ); } - while ( it.hasNext() ) + for ( DataChange nextChange : dataChanges ) { - nextChange = it.next(); - if ( nextChange instanceof IndexChange ) { indexChange = ( IndexChange ) nextChange; @@ -242,6 +233,7 @@ import org.apache.directory.shared.ldap. } } + /** * Applies the updates made by this txn to the entry identified by the entryID and partition dn. * @@ -254,21 +246,16 @@ import org.apache.directory.shared.ldap. public Entry applyUpdatesToEntry( Dn partitionDn, UUID entryID, Entry curEntry, boolean cloneOnChange ) { boolean needToCloneOnChange = cloneOnChange; - LogEdit edit; DataChangeContainer container; - Iterator it = logEdits.iterator(); - - while ( it.hasNext() ) + for ( LogEdit edit : logEdits ) { - edit = it.next(); - if ( edit instanceof DataChangeContainer ) { container = ( DataChangeContainer ) edit; Entry nextEntry = container.mergeUpdates( partitionDn, entryID, curEntry, cloneOnChange ); - + if ( nextEntry != curEntry ) { cloneOnChange = false; @@ -279,8 +266,8 @@ import org.apache.directory.shared.ldap. return curEntry; } - - + + /** * Checks all the updates done on the given index for the given key and returns * the latest version of the coressponding id @@ -291,12 +278,13 @@ import org.apache.directory.shared.ldap. * @param valueComp value comparator * @return current version of the index entry */ - public void updateForwardLookup(Dn partitionDn, String attributeOid, IndexEntry indexEntry, Comparator valueComp ) + public void updateForwardLookup( Dn partitionDn, String attributeOid, IndexEntry indexEntry, + Comparator valueComp ) { - UUID id = indexEntry.getId(); + UUID id = indexEntry.getId(); Object key = indexEntry.getValue(); NavigableSet> changes = getForwardIndexChanges( partitionDn, attributeOid ); - + if ( changes == null ) { // No add. If we have a value, check if it is deleted. @@ -304,7 +292,7 @@ import org.apache.directory.shared.ldap. { // Check if index entry is deleted NavigableSet> txnDeletes = getDeletesFor( partitionDn, attributeOid ); - + if ( txnDeletes != null && txnDeletes.contains( indexEntry ) ) { // Index entry is deleted @@ -321,26 +309,22 @@ import org.apache.directory.shared.ldap. boolean added = false; indexEntry.setId( null ); changes = changes.tailSet( indexEntry, false ); - Iterator> it = changes.iterator(); - - if ( it.hasNext() ) + + for ( IndexEntry lookedUpEntry : changes ) { - IndexEntry lookedUpEntry = it.next(); - if ( valueComp.compare( key, lookedUpEntry.getValue() ) == 0 ) { id = lookedUpEntry.getId(); added = true; } } - + if ( added == false && id != null ) { // Check if index entry is deleted indexEntry.setId( id ); // reset the id NavigableSet> txnDeletes = getDeletesFor( partitionDn, attributeOid ); - - + if ( txnDeletes != null && txnDeletes.contains( indexEntry ) ) { // Index entry is deleted @@ -352,12 +336,12 @@ import org.apache.directory.shared.ldap. } } } - + // Set the current version of the id indexEntry.setId( id ); } - - + + /** * Checks all the updates done on the given index for the given id and returns * the latest version of the corressponding value @@ -367,12 +351,12 @@ import org.apache.directory.shared.ldap. * @param id key to do the lookup on * @return value corresponding to the id */ - public void updateReverseLookup(Dn partitionDn, String attributeOid, IndexEntry indexEntry ) + public void updateReverseLookup( Dn partitionDn, String attributeOid, IndexEntry indexEntry ) { - UUID id = indexEntry.getId(); + UUID id = indexEntry.getId(); Object key = indexEntry.getValue(); NavigableSet> changes = getReverseIndexChanges( partitionDn, attributeOid ); - + if ( changes == null ) { // No add. If we have a value, check if it is deleted. @@ -380,7 +364,7 @@ import org.apache.directory.shared.ldap. { // Check if index entry is deleted NavigableSet> txnDeletes = getDeletesFor( partitionDn, attributeOid ); - + if ( txnDeletes != null && txnDeletes.contains( indexEntry ) ) { // Index entry is deleted @@ -398,24 +382,23 @@ import org.apache.directory.shared.ldap. indexEntry.setValue( null ); changes = changes.tailSet( indexEntry, false ); Iterator> it = changes.iterator(); - + if ( it.hasNext() ) { IndexEntry lookedUpEntry = it.next(); - + if ( UUIDComparator.INSTANCE.compare( id, lookedUpEntry.getId() ) == 0 ) { key = lookedUpEntry.getValue(); } } - + if ( added == false && key != null ) { // Check if index entry is deleted indexEntry.setValue( key ); // reset the id NavigableSet> txnDeletes = getDeletesFor( partitionDn, attributeOid ); - - + if ( txnDeletes != null && txnDeletes.contains( indexEntry ) ) { // Index entry is deleted @@ -427,12 +410,12 @@ import org.apache.directory.shared.ldap. } } } - + // Set the current version of the value indexEntry.setValue( key ); } - - + + /** * Checks updates on the given index entry and returns whether the it exists or not * @@ -443,9 +426,10 @@ import org.apache.directory.shared.ldap. * @param forward true if lookup is on forward index, false otherwise * @return updated version of the existence status */ - public boolean updateExistence(Dn partitionDn, String attributeOid, IndexEntry indexEntry, boolean currentlyExists, boolean forward ) + public boolean updateExistence( Dn partitionDn, String attributeOid, IndexEntry indexEntry, + boolean currentlyExists, boolean forward ) { - NavigableSet> changes; + NavigableSet> changes; if ( forward ) { @@ -455,12 +439,12 @@ import org.apache.directory.shared.ldap. { changes = getReverseIndexChanges( partitionDn, attributeOid ); } - + if ( changes == null ) { // No adds, check if index entry is deleted NavigableSet> txnDeletes = getDeletesFor( partitionDn, attributeOid ); - + if ( txnDeletes != null && txnDeletes.contains( indexEntry ) ) { // Index entry is delete @@ -482,7 +466,7 @@ import org.apache.directory.shared.ldap. { // No add, check if index entry is deleted NavigableSet> txnDeletes = getDeletesFor( partitionDn, attributeOid ); - + if ( txnDeletes != null && txnDeletes.contains( indexEntry ) ) { // Index entry is delete @@ -496,7 +480,7 @@ import org.apache.directory.shared.ldap. } } } - + /** * Returns deletes his txn has for the index identified by partitionDn + attributeOid @@ -517,8 +501,7 @@ import org.apache.directory.shared.ldap. return null; } - - + /** * Returns add this txn has for the forward index identified by partitionDn + attributeOid @@ -534,13 +517,13 @@ import org.apache.directory.shared.ldap. if ( forwardIndices != null ) { - return forwardIndices.get( attributeOid ); + return forwardIndices.get( attributeOid ); } return null; } - - + + /** * Returns add this txn has for the reverse index identified by partitionDn + attributeOid * @@ -555,13 +538,13 @@ import org.apache.directory.shared.ldap. if ( reverseIndices != null ) { - return reverseIndices.get( attributeOid ); + return reverseIndices.get( attributeOid ); } return null; } - + /** * Adds the given Dn to the read set of the current txn * @@ -605,29 +588,23 @@ import org.apache.directory.shared.ldap. boolean result = false; List txnWriteDns = txn.getWriteSet(); - Iterator writeIt = txnWriteDns.iterator(); - Iterator readIt = readDns.iterator(); - + // If no write for any of the txns, then return - - if ( this.writeDns.size() == 0 || txnWriteDns.size() == 0 ) + + if ( ( this.writeDns.size() == 0 ) || ( txnWriteDns.size() == 0 ) ) { return false; } - DnSet readDnSet; SearchScope readScope; - DnSet writeDnSet; SearchScope writeScope; - while ( readIt.hasNext() ) + for ( DnSet readDnSet : readDns ) { - readDnSet = readIt.next(); readScope = readDnSet.getScope(); - while ( writeIt.hasNext() ) + for ( DnSet writeDnSet : txnWriteDns ) { - writeDnSet = writeIt.next(); writeScope = writeDnSet.getScope(); if ( readScope.equals( SearchScope.OBJECT ) ) @@ -679,20 +656,14 @@ import org.apache.directory.shared.ldap. return result; } - - + + public void flushLogEdits( Set affectedPartitions ) throws Exception { - Iterator it = logEdits.iterator(); - LogEdit edit; - - - while ( it.hasNext() ) + for ( LogEdit edit : logEdits ) { - edit = it.next(); - edit.apply( false ); - + if ( edit instanceof DataChangeContainer ) { affectedPartitions.add( ( ( DataChangeContainer ) edit ).getPartition() );