directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1208350 [2/2] - in /directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared: partition/ txn/ txn/logedit/
Date Wed, 30 Nov 2011 09:53:28 GMT
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=1208350&r1=1208349&r2=1208350&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
Wed Nov 30 09:53:21 2011
@@ -22,6 +22,7 @@ package org.apache.directory.server.core
 import java.util.List;
 import java.util.LinkedList;
 import java.util.Iterator;
+import java.util.NavigableSet;
 import java.util.TreeSet;
 import java.util.Map;
 import java.util.HashMap;
@@ -210,7 +211,7 @@ import org.apache.directory.shared.ldap.
                             new TreeSet<IndexEntry<Object>>( index.getReverseIndexEntryComparator()
);
 
                         forwardIndices.put( indexChange.getOID(), forwardAdds );
-                        reverseIndices.put( indexChange.getOID(), forwardAdds );
+                        reverseIndices.put( indexChange.getOID(), reverseAdds );
                     }
 
                     TreeSet<IndexEntry<Object>> deletes = deletedIndices.get(
indexChange.getOID() );
@@ -284,93 +285,288 @@ 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
+     *
+     * @param partitionDn dn of the partition the entry lives in
+     * @param attributeOid oid of the indexed attribute
+     * @param indexEntry index entry to do the lookup on 
+     * @param valueComp value comparator
+     * @return current version of the index entry
+     */
+    public void updateForwardLookup(Dn partitionDn, String attributeOid, IndexEntry<Object>
indexEntry,  Comparator<Object> valueComp )
+    {
+        UUID id  = indexEntry.getId();
+        Object key = indexEntry.getValue();
+        NavigableSet<IndexEntry<Object>> changes = getForwardIndexChanges( partitionDn,
attributeOid );
+        
+        if ( changes == null )
+        {
+            // No add. If we have a value, check if it is deleted.
+            if ( id != null )
+            {
+                // Check if index entry is deleted
+                NavigableSet<IndexEntry<Object>> txnDeletes = getDeletesFor(
partitionDn, attributeOid );
+                
+                if ( txnDeletes != null && txnDeletes.contains( indexEntry ) )
+                {
+                    // Index entry is deleted
+                    id = null;
+                }
+                else
+                {
+                    // No update
+                }
+            }
+        }
+        else
+        {
+            boolean added = false;
+            indexEntry.setId( null );
+            changes = changes.tailSet( indexEntry, false );
+            Iterator<IndexEntry<Object>> it = changes.iterator();
+            
+            if ( it.hasNext() )
+            {
+                IndexEntry<Object> 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<IndexEntry<Object>> txnDeletes = getDeletesFor(
partitionDn, attributeOid );
+                
+                
+                if ( txnDeletes != null && txnDeletes.contains( indexEntry ) )
+                {
+                    // Index entry is deleted
+                    id = null;
+                }
+                else
+                {
+                    // No update
+                }
+            }
+        }
+        
+        // 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
+     *
+     * @param partitionDn dn of the partition the entry lives in
+     * @param attributeOid oid of the indexed attribute
+     * @param id key to do the lookup on 
+     * @return value corresponding to the id
+     */
+    public void updateReverseLookup(Dn partitionDn, String attributeOid, IndexEntry<Object>
indexEntry )
+    {
+        UUID id  = indexEntry.getId();
+        Object key = indexEntry.getValue();
+        NavigableSet<IndexEntry<Object>> changes = getReverseIndexChanges( partitionDn,
attributeOid );
+        
+        if ( changes == null )
+        {
+            // No add. If we have a value, check if it is deleted.
+            if ( key != null )
+            {
+                // Check if index entry is deleted
+                NavigableSet<IndexEntry<Object>> txnDeletes = getDeletesFor(
partitionDn, attributeOid );
+                
+                if ( txnDeletes != null && txnDeletes.contains( indexEntry ) )
+                {
+                    // Index entry is deleted
+                    key = null;
+                }
+                else
+                {
+                    // No update
+                }
+            }
+        }
+        else
+        {
+            boolean added = false;
+            indexEntry.setValue( null );
+            changes = changes.tailSet( indexEntry, false );
+            Iterator<IndexEntry<Object>> it = changes.iterator();
+            
+            if ( it.hasNext() )
+            {
+                IndexEntry<Object> 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<IndexEntry<Object>> txnDeletes = getDeletesFor(
partitionDn, attributeOid );
+                
+                
+                if ( txnDeletes != null && txnDeletes.contains( indexEntry ) )
+                {
+                    // Index entry is deleted
+                    key = null;
+                }
+                else
+                {
+                    // No update
+                }
+            }
+        }
+        
+        // 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
+     *
+     * @param partitionDn dn of the partition the entry lives in
+     * @param attributeOid oid of the indexed attribute
+     * @param indexEntry entry to do the check for 
+     * @param currentlyExists true if the index entry currently exists
+     * @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 )
+    {
+        NavigableSet<IndexEntry<Object>> changes; 
+
+        if ( forward )
+        {
+            changes = getForwardIndexChanges( partitionDn, attributeOid );
+        }
+        else
+        {
+            changes = getReverseIndexChanges( partitionDn, attributeOid );
+        }
+        
+        if ( changes == null )
+        {
+            // No adds, check if index entry is deleted
+            NavigableSet<IndexEntry<Object>> txnDeletes = getDeletesFor( partitionDn,
attributeOid );
+            
+            if ( txnDeletes != null && txnDeletes.contains( indexEntry ) )
+            {
+                // Index entry is delete
+                return false;
+            }
+            else
+            {
+                // No update on existence status
+                return currentlyExists;
+            }
+        }
+        else
+        {
+            if ( changes.contains( indexEntry ) )
+            {
+                return true;
+            }
+            else
+            {
+                // No add, check if index entry is deleted
+                NavigableSet<IndexEntry<Object>> txnDeletes = getDeletesFor(
partitionDn, attributeOid );
+                
+                if ( txnDeletes != null && txnDeletes.contains( indexEntry ) )
+                {
+                    // Index entry is delete
+                    return false;
+                }
+                else
+                {
+                    // No update on existence status
+                    return currentlyExists;
+                }
+            }
+        }
+    }
+    
 
     /**
-     * Returns true if this txn has deletes for the index identified by partitionDn + attributeOid
+     * Returns deletes his txn has for the index identified by partitionDn + attributeOid
      *
      * @param partitionDn dn of the partition
      * @param attributeOid oid of the indexed attribute
-     * @return
+     * @return deletes for the given index
      */
-    public boolean hasDeletesFor( Dn partitionDn, String attributeOid )
+    public NavigableSet<IndexEntry<Object>> getDeletesFor( Dn partitionDn, String
attributeOid )
     {
         Map<String, TreeSet<IndexEntry<Object>>> deletedIndices =
             indexDeletes.get( partitionDn );
 
         if ( deletedIndices != null )
         {
-            return ( deletedIndices.get( attributeOid ) != null );
+            return deletedIndices.get( attributeOid );
         }
 
-        return false;
+        return null;
     }
-
+    
+    
 
     /**
-     * Returns a cursor over the changes made by this txn on the index identified by partitionDn+attributeOid.

+     * Returns add this txn has for the forward index identified by partitionDn + attributeOid
      *
      * @param partitionDn dn of the partition
      * @param attributeOid oid of the indexed attribute
-     * @param forwardIndex true if forward index and reverse if reverse index
-     * @param onlyValueKey set if the cursor should be locked down by a key ( should be non
null only for forward indices )
-     * @param onlyIDKey  set if the cursor should be locked down by a key ( should be non
null only for reverse indices )
-     * @param comparator comparator that will be used to order index entries.
-     * @return
+     * @return adds for the given forward index 
      */
-    public IndexCursor<Object> getCursorFor( Dn partitionDn, String attributeOid, boolean
forwardIndex,
-        Object onlyValueKey, UUID onlyIDKey, IndexComparator<Object> comparator )
+    public NavigableSet<IndexEntry<Object>> getForwardIndexChanges( Dn partitionDn,
String attributeOid )
     {
-        TxnIndexCursor txnIndexCursor = null;
-
         Map<String, TreeSet<IndexEntry<Object>>> forwardIndices =
             forwardIndexAdds.get( partitionDn );
 
         if ( forwardIndices != null )
         {
-            TreeSet<IndexEntry<Object>> sortedSet = forwardIndices.get( attributeOid
);
-
-            if ( sortedSet != null )
-            {
-                txnIndexCursor = new TxnIndexCursor( sortedSet, forwardIndex, onlyValueKey,
onlyIDKey, comparator );
-            }
+            return  forwardIndices.get( attributeOid );
         }
 
-        return txnIndexCursor;
+        return null;
     }
-
-
+    
+    
     /**
-     * Returns true if the given index entry is deleted by this txn. partitionDn + attributeOid

-     * identifies the index. 
+     * Returns add this txn has for the reverse index identified by partitionDn + attributeOid
      *
-     * @param partitionDn dn of the partition index belongs to 
-     * @param attributeOid oid of the indexed attribute.
-     * @param indexEntry value to be checked
-     * @return true if the given value is deleted.
+     * @param partitionDn dn of the partition
+     * @param attributeOid oid of the indexed attribute
+     * @return adds for the given reverse index 
      */
-    public boolean isIndexEntryDeleted( Dn partitionDn, String attributeOid, IndexEntry<Object>
indexEntry )
+    public NavigableSet<IndexEntry<Object>> getReverseIndexChanges( Dn partitionDn,
String attributeOid )
     {
-        Map<String, TreeSet<IndexEntry<Object>>> deletedIndices =
-            indexDeletes.get( partitionDn );
+        Map<String, TreeSet<IndexEntry<Object>>> reverseIndices =
+            reverseIndexAdds.get( partitionDn );
 
-        if ( deletedIndices == null )
+        if ( reverseIndices != null )
         {
-            return false;
+            return  reverseIndices.get( attributeOid );
         }
 
-        TreeSet<IndexEntry<Object>> deletedEntries = deletedIndices.get( attributeOid
);
-
-        if ( deletedEntries == null )
-        {
-            return false;
-        }
-
-        boolean result = deletedEntries.contains( indexEntry );
-
-        return result;
+        return null;
     }
 
-
+    
     /**
      * Adds the given Dn to the read set of the current txn
      *

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java?rev=1208350&r1=1208349&r2=1208350&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java
Wed Nov 30 09:53:21 2011
@@ -19,9 +19,11 @@
  */
 package org.apache.directory.server.core.shared.txn;
 
+import java.util.Comparator;
 import java.util.List;
 import java.util.UUID;
 
+import org.apache.directory.server.core.api.partition.index.IndexEntry;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.name.Dn;
 
@@ -100,6 +102,44 @@ import org.apache.directory.shared.ldap.
      * @return
      */
     Entry mergeUpdates( Dn partitionDn, UUID entryID, Entry entry );
+    
+    
+    /**
+     * Checks all the updates done on the given index for the given key and returns 
+     * the latest version of the coressponding id
+     *
+     * @param partitionDN dn of the partition the entry lives in
+     * @param attributeOid oid of the indexed attribute
+     * @param key key to do the lookup on 
+     * @param valueComp value comparator
+     * @return id corresponding to the key
+     */
+    UUID mergeForwardLookup(Dn partitionDN, String attributeOid,  Object key, UUID curId,
Comparator<Object> valueComparator );
+    
+    
+    /**
+     * Checks all the updates done on the given index for the given id and returns 
+     * the latest version of the corressponding value
+     *
+     * @param partitionDN dn of the partition the entry lives in
+     * @param attributeOid oid of the indexed attribute
+     * @param id key to do the lookup on 
+     * @return value corresponding to the id
+     */
+    Object mergeReverseLookup(Dn partitionDN, String attributeOid,  UUID id, Object curValue
);
+    
+    
+    /**
+     * Checks all the updates on the given index entry and returns whether the it exists
or not
+     *
+     * @param partitionDN dn of the partition the entry lives in
+     * @param attributeOid oid of the indexed attribute
+     * @param indexEntry entry to do the check for 
+     * @param currentlyExists true if the index entry currently exists in the underlying
partition
+     * @return true if the given index entry exists
+     */
+    boolean mergeExistence(Dn partitionDN, String attributeOid,  IndexEntry<?> indexEntry,
boolean currentlyExists );
+
 
     enum State
     {

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=1208350&r1=1208349&r2=1208350&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 Nov 30 09:53:21 2011
@@ -80,6 +80,7 @@ public class DataChangeContainer extends
     public DataChangeContainer( Partition partition )
     {
         this.partitionDn = partition.getSuffixDn();
+        this.partition = partition;
     }
 
     public DataChangeContainer( Dn partitionDn )
@@ -143,6 +144,7 @@ public class DataChangeContainer extends
         long changeLsn = getLogAnchor().getLogLSN();
         Entry curEntry = null;
         boolean entryExisted = false;
+        Entry originalEntry = null;
 
         // TODO find the partition from the dn if changeContainer doesnt have it.
 
@@ -153,7 +155,7 @@ public class DataChangeContainer extends
 
             if ( curEntry != null )
             {
-                curEntry = curEntry.clone();
+                originalEntry = curEntry = curEntry.clone();
                 entryExisted = true;
             }
         }
@@ -188,7 +190,7 @@ public class DataChangeContainer extends
             if ( entryExisted )
             {
                 MasterTable master = partition.getMasterTable();
-                master.remove( entryID );
+                master.remove( entryID, originalEntry );
             }
         }
     }
@@ -252,7 +254,7 @@ public class DataChangeContainer extends
                         needToCloneOnChange = false;
                     }
 
-                    entryModification.applyModification( partition, curEntry, id, changeLsn,
true );
+                   curEntry = entryModification.applyModification( partition, curEntry, id,
changeLsn, true );
                 }
             }
 



Mime
View raw message