directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1553548 - in /directory/apacheds/trunk/mavibot-partition/src: main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/ test/java/org/apache/directory/server/core/partition/impl/btree/mavibot/
Date Thu, 26 Dec 2013 18:40:37 GMT
Author: elecharny
Date: Thu Dec 26 18:40:36 2013
New Revision: 1553548

URL: http://svn.apache.org/r1553548
Log:
o Fixed a wrong count when adding an element in a btree which does not allow duplicate values
o Fixed a test which was expecting the index to allow duplicate values, when it was not the
case
o The MavibotDnIndex forward index was not allowing duplicate Values wrongly

Modified:
    directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotDnIndex.java
    directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotTable.java
    directory/apacheds/trunk/mavibot-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotRdnIndexTest.java

Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotDnIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotDnIndex.java?rev=1553548&r1=1553547&r2=1553548&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotDnIndex.java
(original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotDnIndex.java
Thu Dec 26 18:40:36 2013
@@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
 
 /**
  * A special index which stores DN objects.
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class MavibotDnIndex extends MavibotIndex<Dn>
@@ -106,7 +106,7 @@ public class MavibotDnIndex extends Mavi
 
         String forwardTableName = attributeType.getOid() + FORWARD_BTREE;
         forward = new MavibotTable<Dn, String>( recordMan, schemaManager, forwardTableName,
dnSerializer,
-            new StringSerializer(), false );
+            new StringSerializer(), true );
 
         String reverseTableName = attributeType.getOid() + REVERSE_BTREE;
         reverse = new MavibotTable<String, Dn>( recordMan, schemaManager, reverseTableName,
new StringSerializer(),

Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotTable.java?rev=1553548&r1=1553547&r2=1553548&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotTable.java
(original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotTable.java
Thu Dec 26 18:40:36 2013
@@ -6,16 +6,16 @@
  *  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.partition.impl.btree.mavibot;
 
@@ -30,7 +30,6 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
 import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.BTreeFactory;
-import org.apache.directory.mavibot.btree.PersistedBTree;
 import org.apache.directory.mavibot.btree.RecordManager;
 import org.apache.directory.mavibot.btree.TupleCursor;
 import org.apache.directory.mavibot.btree.ValueCursor;
@@ -96,7 +95,7 @@ public class MavibotTable<K, V> extends 
         }
         else
         {
-            // it is important to set the serializers cause serializers will contain default

+            // it is important to set the serializers cause serializers will contain default
             // comparators when loaded from disk and we need schema aware comparators in
certain indices
             bt.setKeySerializer( keySerializer );
             bt.setValueSerializer( valueSerializer );
@@ -328,13 +327,21 @@ public class MavibotTable<K, V> extends 
                 throw new IllegalArgumentException( I18n.err( I18n.ERR_594 ) );
             }
 
-            if ( !bt.contains( key, value ) )
+            boolean existing = false;
+
+            if ( bt.contains( key, value ) )
             {
-                count++;
+                existing = true;
             }
-            
+
             // Always insert the entry. If it already exists, it will replace the previous
entry
             bt.insert( key, value );
+
+            /// The entry has been added, increment the count if it wasn't existing before
+            if ( ! existing )
+            {
+                count++;
+            }
         }
         catch ( Exception e )
         {
@@ -523,12 +530,12 @@ public class MavibotTable<K, V> extends 
             try
             {
                 ValueCursor<V> dupHolder = bt.getValues( key );
-    
+
                 return dupHolder.size();
             }
             catch ( KeyNotFoundException knfe )
             {
-                // No key 
+                // No key
                 return 0;
             }
         }

Modified: directory/apacheds/trunk/mavibot-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotRdnIndexTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotRdnIndexTest.java?rev=1553548&r1=1553547&r2=1553548&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotRdnIndexTest.java
(original)
+++ directory/apacheds/trunk/mavibot-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotRdnIndexTest.java
Thu Dec 26 18:40:36 2013
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.server.core.partition.impl.btree.mavibot;
 
@@ -39,6 +39,7 @@ import org.apache.directory.api.ldap.sch
 import org.apache.directory.api.util.Strings;
 import org.apache.directory.api.util.exception.Exceptions;
 import org.apache.directory.mavibot.btree.RecordManager;
+import org.apache.directory.mavibot.btree.exception.DuplicateValueNotAllowedException;
 import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.xdbm.Index;
 import org.apache.directory.server.xdbm.IndexEntry;
@@ -209,12 +210,22 @@ public class MavibotRdnIndexTest
         assertEquals( 2, idx.count() );
 
         //count shouldn't get affected cause of inserting the same key
-        idx.add( key, Strings.getUUID( 2L ) );
-        assertEquals( 3, idx.count() );
+        try
+        {
+            // We should not be able to add a new value to an existing key
+            idx.add( key, Strings.getUUID( 2L ) );
+            fail();
+        }
+        catch ( DuplicateValueNotAllowedException dvnae )
+        {
+            // expected
+        }
+
+        assertEquals( 2, idx.count() );
 
         key = new ParentIdAndRdn( Strings.getUUID( 2L ), new Rdn( "cn=key" ) );
         idx.add( key, Strings.getUUID( 3L ) );
-        assertEquals( 4, idx.count() );
+        assertEquals( 3, idx.count() );
     }
 
 



Mime
View raw message