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 2010/06/11 17:53:25 UTC

svn commit: r953742 - in /directory/apacheds/trunk: core-api/src/main/java/org/apache/directory/server/core/interceptor/ core-api/src/main/java/org/apache/directory/server/core/interceptor/context/ core-integ/src/test/java/org/apache/directory/server/c...

Author: elecharny
Date: Fri Jun 11 15:53:24 2010
New Revision: 953742

URL: http://svn.apache.org/viewvc?rev=953742&view=rev
Log:
o Sped up the Compare operation, removing useless lookups, etc
o Renamed opContext to compareContext
o Moved the originalEntry from AbstractChangedOperationConext to AbstractOperationContext

Added:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/ComparePerfIT.java
Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractChangeOperationContext.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java Fri Jun 11 15:53:24 2010
@@ -186,9 +186,9 @@ public abstract class BaseInterceptor im
     }
 
 
-    public boolean compare( NextInterceptor next, CompareOperationContext opContext ) throws LdapException
+    public boolean compare( NextInterceptor next, CompareOperationContext compareContext ) throws LdapException
     {
-        return next.compare( opContext );
+        return next.compare( compareContext );
     }
 
 

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java Fri Jun 11 15:53:24 2010
@@ -94,9 +94,9 @@ public class InterceptorChain
         }
 
 
-        public boolean compare( NextInterceptor next, CompareOperationContext opContext ) throws LdapException
+        public boolean compare( NextInterceptor next, CompareOperationContext compareContext ) throws LdapException
         {
-            return nexus.compare( opContext );
+            return nexus.compare( compareContext );
         }
 
 
@@ -525,15 +525,16 @@ public class InterceptorChain
     }
 
 
-    public boolean compare( CompareOperationContext opContext ) throws LdapException
+    public boolean compare( CompareOperationContext compareContext ) throws LdapException
     {
         Element entry = getStartingEntry();
         Interceptor head = entry.interceptor;
         NextInterceptor next = entry.nextInterceptor;
+        compareContext.setOriginalEntry( getOriginalEntry( compareContext ) );
 
         try
         {
-            return head.compare( next, opContext );
+            return head.compare( next, compareContext );
         }
         catch ( LdapException le )
         {

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractChangeOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractChangeOperationContext.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractChangeOperationContext.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractChangeOperationContext.java Fri Jun 11 15:53:24 2010
@@ -40,9 +40,6 @@ public abstract class AbstractChangeOper
     /** The flag used to tell the server to store the changes into the changeLog */
     protected LogChange logChange;
     
-    /** The original Entry */
-    protected Entry originalEntry;
-
     /** The modified Entry as it will be stored into the backend */
     protected Entry modifiedEntry;
 
@@ -72,24 +69,6 @@ public abstract class AbstractChangeOper
 
     
     /**
-     * @return the originalEntry
-     */
-    public Entry getOriginalEntry()
-    {
-        return originalEntry;
-    }
-
-
-    /**
-     * @param originalEntry the originalEntry to set
-     */
-    public void setOriginalEntry( Entry originalEntry )
-    {
-        this.originalEntry = originalEntry;
-    }
-
-
-    /**
      * @return the modifiedEntry
      */
     public Entry getModifiedEntry()

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java Fri Jun 11 15:53:24 2010
@@ -52,6 +52,9 @@ public abstract class AbstractOperationC
     
     /** The entry associated with the target entry of this OperationContext */
     protected ClonedServerEntry entry;
+
+    /** The original Entry */
+    protected Entry originalEntry;
     
     /** The associated request's controls */
     protected Map<String, Control> requestControls = new HashMap<String, Control>(4);
@@ -225,6 +228,24 @@ public abstract class AbstractOperationC
 
 
     /**
+     * @return the originalEntry
+     */
+    public Entry getOriginalEntry()
+    {
+        return originalEntry;
+    }
+
+
+    /**
+     * @param originalEntry the originalEntry to set
+     */
+    public void setOriginalEntry( Entry originalEntry )
+    {
+        this.originalEntry = originalEntry;
+    }
+
+
+    /**
      * Gets the set of bypassed Interceptors.
      *
      * @return the set of bypassed Interceptors

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java Fri Jun 11 15:53:24 2010
@@ -27,6 +27,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 
@@ -40,6 +41,9 @@ public class CompareOperationContext ext
 {
     /** The entry OID */
     private String oid;
+    
+    /** The associated AttributeType */
+    private AttributeType attributeType;
 
     /** The value to be compared */
     private Value<?> value;
@@ -161,6 +165,26 @@ public class CompareOperationContext ext
 
 
     /**
+     *  @return The AttributeType for the compared value
+     */
+    public AttributeType getAttributeType()
+    {
+        return attributeType;
+    }
+
+
+    /**
+     * Set the AttributeType associated with the OID
+     * 
+     * @param attributeType The AttributeType
+     */
+    public void setAttributeType( AttributeType attributeType )
+    {
+        this.attributeType = attributeType;
+    }
+    
+    
+    /**
      * @return the operation name
      */
     public String getName()

Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/ComparePerfIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/ComparePerfIT.java?rev=953742&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/ComparePerfIT.java (added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/ComparePerfIT.java Fri Jun 11 15:53:24 2010
@@ -0,0 +1,119 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.operations.compare;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.message.CompareResponse;
+import org.apache.directory.server.core.annotations.ContextEntry;
+import org.apache.directory.server.core.annotations.CreateDS;
+import org.apache.directory.server.core.annotations.CreateIndex;
+import org.apache.directory.server.core.annotations.CreatePartition;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests performance of the compare operation
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith ( FrameworkRunner.class )
+@CreateDS(
+        name="ComparePerfDS",
+        partitions =
+        {
+            @CreatePartition(
+                name = "example",
+                suffix = "dc=example,dc=com",
+                contextEntry = @ContextEntry( 
+                    entryLdif =
+                        "dn: dc=example,dc=com\n" +
+                        "dc: example\n" +
+                        "objectClass: top\n" +
+                        "objectClass: domain\n\n" ),
+                indexes = 
+                {
+                    @CreateIndex( attribute = "objectClass", cacheSize = 1000 ),
+                    @CreateIndex( attribute = "sn", cacheSize = 1000 ),
+                    @CreateIndex( attribute = "cn", cacheSize = 1000 )
+                } )
+                
+        },
+        enableChangeLog = false )
+public class ComparePerfIT extends AbstractLdapTestUnit
+{
+    /**
+     * Compare a member attribute. This test is used to check DIRSERVER-1139
+     */
+    @Test
+    public void testComparePerf() throws Exception
+    {
+        LdapConnection connection = IntegrationUtils.getAdminConnection( service );
+        
+        DN dn = new DN( "cn=test,dc=example,dc=com" );
+        Entry entry = new DefaultEntry( service.getSchemaManager(), dn );
+        entry.add( "ObjectClass", "top", "person" );
+        entry.add( "sn", "TEST" );
+        entry.add( "cn", "test" );
+        
+        connection.add(entry );
+        int nbIterations = 150000;
+        
+        long t0 = System.currentTimeMillis();
+        long t00 = 0L;
+        long tt0 = System.currentTimeMillis();
+        
+        for ( int i = 0; i < nbIterations; i++ )
+        {
+            if ( i % 1000 == 0 )
+            {
+                long tt1 = System.currentTimeMillis();
+
+                System.out.println( i + ", " + ( tt1 - tt0 ) );
+                tt0 = tt1;
+            }
+
+            if ( i == 50000 )
+            {
+                t00 = System.currentTimeMillis();
+            }
+                        
+            CompareResponse response = connection.compare( dn, "sn", "TEST" );
+            
+            assertEquals( ResultCodeEnum.COMPARE_TRUE, response.getLdapResult().getResultCode() );
+        }
+        
+        long t1 = System.currentTimeMillis();
+
+        Long deltaWarmed = ( t1 - t00 );
+        System.out.println( "Delta copare: " + deltaWarmed + "( " + ( ( ( nbIterations - 50000 ) * 1000 ) / deltaWarmed ) + " per s ) /" + ( t1 - t0 ) );
+
+        connection.close();
+    }
+}

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java Fri Jun 11 15:53:24 2010
@@ -301,17 +301,17 @@ public class DefaultOperationManager imp
     /**
      * {@inheritDoc}
      */
-    public boolean compare( CompareOperationContext opContext ) throws LdapException
+    public boolean compare( CompareOperationContext compareContext ) throws LdapException
     {
-        LOG.debug( ">> CompareOperation : {}", opContext );
+        LOG.debug( ">> CompareOperation : {}", compareContext );
 
         ensureStarted();
-        push( opContext );
+        push( compareContext );
 
         try
         {
             // Normalize the opContext DN
-            DN dn = opContext.getDn();
+            DN dn = compareContext.getDn();
             dn.normalize( directoryService.getSchemaManager().getNormalizerMapping() );
 
             // We have to deal with the referral first
@@ -323,13 +323,13 @@ public class DefaultOperationManager imp
             if ( parentEntry != null )
             {
                 // We have found a parent referral for the current DN 
-                DN childDn = ( DN ) dn.getSuffix( parentEntry.getDn().size() );
+                DN childDn = dn.getSuffix( parentEntry.getDn().size() );
 
                 if ( directoryService.getReferralManager().isReferral( dn ) )
                 {
                     // This is a referral. We can delete it if the ManageDsaIt flag is true
                     // Otherwise, we just throw a LdapReferralException
-                    if ( !opContext.isReferralIgnored() )
+                    if ( !compareContext.isReferralIgnored() )
                     {
                         // Throw a Referral Exception
                         // Unlock the referral manager
@@ -343,7 +343,7 @@ public class DefaultOperationManager imp
                 {
                     // Depending on the Context.REFERRAL property value, we will throw
                     // a different exception.
-                    if ( opContext.isReferralIgnored() )
+                    if ( compareContext.isReferralIgnored() )
                     {
                         directoryService.getReferralManager().unlock();
 
@@ -366,7 +366,7 @@ public class DefaultOperationManager imp
 
             // Call the Add method
             InterceptorChain interceptorChain = directoryService.getInterceptorChain();
-            return interceptorChain.compare( opContext );
+            return interceptorChain.compare( compareContext );
         }
         finally
         {

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java Fri Jun 11 15:53:24 2010
@@ -309,17 +309,21 @@ public class AuthenticationInterceptor e
         invalidateAuthenticatorCaches( opContext.getDn() );
     }
 
-
-    public boolean compare( NextInterceptor next, CompareOperationContext opContext ) throws LdapException
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean compare( NextInterceptor next, CompareOperationContext compareContext ) throws LdapException
     {
         if ( IS_DEBUG )
         {
-            LOG.debug( "Operation Context: {}", opContext );
+            LOG.debug( "Operation Context: {}", compareContext );
         }
 
-        checkAuthenticated( opContext );
-        boolean result = next.compare( opContext );
-        invalidateAuthenticatorCaches( opContext.getDn() );
+        checkAuthenticated( compareContext );
+        boolean result = next.compare( compareContext );
+        invalidateAuthenticatorCaches( compareContext.getDn() );
+        
         return result;
     }
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java Fri Jun 11 15:53:24 2010
@@ -1029,35 +1029,38 @@ public class AciAuthorizationInterceptor
     }
 
 
-    public boolean compare( NextInterceptor next, CompareOperationContext opContext ) throws LdapException
+    /**
+     * {@inheritDoc}
+     */
+    public boolean compare( NextInterceptor next, CompareOperationContext copmpareContext ) throws LdapException
     {
-        DN name = opContext.getDn();
-        String oid = opContext.getOid();
-        Value<?> value = ( Value<?> ) opContext.getValue();
+        CoreSession session = copmpareContext.getSession();
+        DN dn = copmpareContext.getDn();
+        String oid = copmpareContext.getOid();
+        Value<?> value = copmpareContext.getValue();
 
-        Entry entry = opContext.lookup( name, ByPassConstants.LOOKUP_BYPASS );
+        Entry entry = copmpareContext.getOriginalEntry();
 
-        LdapPrincipal principal = opContext.getSession().getEffectivePrincipal();
+        LdapPrincipal principal = session.getEffectivePrincipal();
         DN principalDn = principal.getDN();
 
-        if ( isPrincipalAnAdministrator( principalDn )
-            || !opContext.getSession().getDirectoryService().isAccessControlEnabled() )
+        if ( isPrincipalAnAdministrator( principalDn ) || !session.getDirectoryService().isAccessControlEnabled() )
         {
-            return next.compare( opContext );
+            return next.compare( copmpareContext );
         }
 
         Set<DN> userGroups = groupCache.getGroups( principalDn.getNormName() );
         Collection<ACITuple> tuples = new HashSet<ACITuple>();
-        addPerscriptiveAciTuples( opContext, tuples, name, ( ( ClonedServerEntry ) entry ).getOriginalEntry() );
+        addPerscriptiveAciTuples( copmpareContext, tuples, dn, entry );
         addEntryAciTuples( tuples, entry );
-        addSubentryAciTuples( opContext, tuples, name, entry );
+        addSubentryAciTuples( copmpareContext, tuples, dn, entry );
 
-        engine.checkPermission( schemaManager, opContext, userGroups, principalDn, principal.getAuthenticationLevel(),
-            name, null, null, READ_PERMS, tuples, entry, null );
-        engine.checkPermission( schemaManager, opContext, userGroups, principalDn, principal.getAuthenticationLevel(),
-            name, oid, value, COMPARE_PERMS, tuples, entry, null );
+        engine.checkPermission( schemaManager, copmpareContext, userGroups, principalDn, principal.getAuthenticationLevel(),
+            dn, null, null, READ_PERMS, tuples, entry, null );
+        engine.checkPermission( schemaManager, copmpareContext, userGroups, principalDn, principal.getAuthenticationLevel(),
+            dn, oid, value, COMPARE_PERMS, tuples, entry, null );
 
-        return next.compare( opContext );
+        return next.compare( copmpareContext );
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java Fri Jun 11 15:53:24 2010
@@ -40,11 +40,13 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.partition.DefaultPartitionNexus;
+import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.ldap.cursor.EmptyCursor;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.StringValue;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeTypeException;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.name.AVA;
 import org.apache.directory.shared.ldap.name.DN;
@@ -325,20 +327,33 @@ public class NormalizationInterceptor ex
     /**
      * {@inheritDoc}
      */
-    public boolean compare( NextInterceptor next, CompareOperationContext opContext ) throws LdapException
+    public boolean compare( NextInterceptor next, CompareOperationContext compareContext ) throws LdapException
     {
-        opContext.getDn().normalize( schemaManager.getNormalizerMapping() );
-
-        AttributeType at = opContext.getSession().getDirectoryService().getSchemaManager().lookupAttributeTypeRegistry(
-            opContext.getOid() );
+        if ( !compareContext.getDn().isNormalized() )
+        {
+            compareContext.getDn().normalize( schemaManager.getNormalizerMapping() );
+        }
 
-        if ( at.getSyntax().isHumanReadable() && ( opContext.getValue().isBinary() ) )
+        // Get the attributeType from the OID
+        try
+        {
+            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( compareContext.getOid() );
+    
+            // Translate the value from binary to String if the AT is HR
+            if ( attributeType.getSyntax().isHumanReadable() && ( compareContext.getValue().isBinary() ) )
+            {
+                String value = compareContext.getValue().getString();
+                compareContext.setValue( new StringValue( value ) );
+            }
+            
+            compareContext.setAttributeType( attributeType );
+        }
+        catch ( LdapException le )
         {
-            String value = opContext.getValue().getString();
-            opContext.setValue( new StringValue( value ) );
+            throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) );
         }
 
-        return next.compare( opContext );
+        return next.compare( compareContext );
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=953742&r1=953741&r2=953742&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java Fri Jun 11 15:53:24 2010
@@ -41,6 +41,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.interceptor.BaseInterceptor;
 import org.apache.directory.server.core.interceptor.NextInterceptor;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.interceptor.context.CompareOperationContext;
 import org.apache.directory.server.core.interceptor.context.ListOperationContext;
 import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
 import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
@@ -395,6 +396,29 @@ public class SchemaInterceptor extends B
         return cursor;
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean compare( NextInterceptor next, CompareOperationContext compareContext ) throws LdapException
+    {
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "Operation Context: {}", compareContext );
+        }
+
+        // Check that the requested AT exists
+        // complain if we do not recognize the attribute being compared
+        if ( !schemaManager.getAttributeTypeRegistry().contains( compareContext.getOid() ) )
+        {
+            throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) );
+        }
+
+        boolean result = next.compare( compareContext );
+        
+        return result;
+    }
+
 
     /**
      * Remove all unknown attributes from the searchControls, to avoid an exception.