directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1203122 [2/2] - in /directory/apacheds/branches/apacheds-txns: core-api/src/main/java/org/apache/directory/server/core/api/partition/ core-api/src/main/java/org/apache/directory/server/core/api/txn/logedit/ core-shared/src/main/java/org/ap...
Date Thu, 17 Nov 2011 09:23:58 GMT
Added: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/EntryReplace.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/EntryReplace.java?rev=1203122&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/EntryReplace.java
(added)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/EntryReplace.java
Thu Nov 17 09:23:57 2011
@@ -0,0 +1,88 @@
+
+package org.apache.directory.server.core.shared.txn.logedit;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.UUID;
+
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.txn.logedit.AbstractDataChange;
+import org.apache.directory.server.core.api.txn.logedit.EntryModification;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+
+public class EntryReplace extends AbstractDataChange implements EntryModification
+{
+    /** New Entry */
+    private Entry newEntry;
+    
+    /** Old enty */
+    private Entry oldEntry;
+    
+    // For externalizable
+    public EntryReplace()
+    {
+        
+    }
+    
+    public EntryReplace( Entry newEntry, Entry oldEntry )
+    {
+        this.newEntry = newEntry;
+        this.oldEntry = oldEntry;
+    }
+    
+    
+    public Entry getNewEntry()
+    {
+        return newEntry;
+    }
+    
+    
+    public Entry getOldEntry()
+    {
+        return oldEntry;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public Entry applyModification( Partition partition, Entry curEntry, UUID entryId, long
changeLsn, boolean recovery )
+    {
+        // Currently this log edit is only for existing exntries
+        if ( curEntry == null )
+        {
+            if ( recovery == false )
+            {
+                throw new IllegalStateException(" Trying to replace a non existing entry:"
+ entryId + " entry:" + newEntry);
+            }
+            else
+            {
+                return null;
+            }
+        }
+        
+        // TODO check the version of the entry and see which entry is more recent
+        return newEntry;
+    }
+    
+    
+    @Override
+    public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
+    {
+     newEntry = new DefaultEntry();
+     newEntry.readExternal( in );
+     
+     oldEntry = new DefaultEntry();
+     oldEntry.readExternal( in );
+    }
+
+
+    @Override
+    public void writeExternal( ObjectOutput out ) throws IOException
+    {
+       newEntry.writeExternal( out );
+       oldEntry.writeExternal( out );
+    }
+}

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=1203122&r1=1203121&r2=1203122&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
Thu Nov 17 09:23:57 2011
@@ -25,9 +25,11 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.UUID;
 
+import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.core.api.partition.index.Index;
 import org.apache.directory.server.core.api.partition.index.Serializer;
 import org.apache.directory.server.core.api.txn.logedit.AbstractDataChange;
+import org.apache.directory.server.core.api.txn.logedit.IndexModification;
 import org.apache.directory.server.core.shared.txn.TxnManagerFactory;
 
 import org.apache.directory.shared.ldap.model.entry.Value;
@@ -37,7 +39,7 @@ import org.apache.directory.shared.ldap.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class IndexChange extends AbstractDataChange
+public class IndexChange extends AbstractDataChange implements IndexModification
 {
     /** Index this change is done on */
     private transient Index<?> index;
@@ -103,7 +105,53 @@ public class IndexChange extends Abstrac
         return type;
     }
 
-
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void applyModification( Partition partition, boolean recovery ) throws Exception
+    {
+        Index<Object> index = ( Index<Object> )partition.getIndex( oid );
+        
+        if ( index == null )
+        {
+            // TODO decide how to handle index add drop
+        }
+        
+        if ( type == Type.ADD )
+        {
+            // During recovery, idex might have already been added. But it should not hurt
to readd the index entry.
+            index.add( key, id );
+        }
+        else // delete
+        {
+            if ( recovery == false )
+            {
+                index.drop( key, id );
+            }
+            else
+            {
+                //If forward or reverse index entry existence diffes, first add the index
entry and then delete it.
+                boolean forwardExists = index.forward( key, id );
+                boolean reverseExists = index.reverse( id, key );
+                
+                if ( forwardExists != reverseExists )
+                {
+                    // We assume readding the same entry to an index wont hurt
+                    index.add( key, id );
+                    
+                    index.drop( key, id );
+                }
+                else if ( forwardExists )
+                {
+                    // Index entry exists both for reverse and forward index
+                    index.drop( key, id );
+                }
+            }
+        }
+    }
+    
+    
     @Override
     @SuppressWarnings("unchecked")
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException



Mime
View raw message