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 2013/10/27 09:58:48 UTC
svn commit: r1536068 -
/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/
Author: elecharny
Date: Sun Oct 27 08:58:47 2013
New Revision: 1536068
URL: http://svn.apache.org/r1536068
Log:
Applied the fixes needed to build the code with the changes made in Mavibot.
Note : we still have issues in some serialization (ParentAndRdn)
Modified:
directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/DnSerializer.java
directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/KeyTupleArrayCursor.java
directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotCursor.java
directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotEntrySerializer.java
directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotParentIdAndRdnSerializer.java
directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotPartition.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/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/ValueTreeCursor.java
Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/DnSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/DnSerializer.java?rev=1536068&r1=1536067&r2=1536068&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/DnSerializer.java (original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/DnSerializer.java Sun Oct 27 08:58:47 2013
@@ -30,9 +30,9 @@ import java.nio.ByteBuffer;
import java.util.Comparator;
import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.server.i18n.I18n;
import org.apache.directory.mavibot.btree.serializer.AbstractElementSerializer;
import org.apache.directory.mavibot.btree.serializer.BufferHandler;
+import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -89,7 +89,7 @@ public class DnSerializer extends Abstra
*/
public DnSerializer()
{
- super(comp);
+ super( comp );
}
@@ -159,4 +159,48 @@ public class DnSerializer extends Abstra
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Dn fromBytes( byte[] buffer ) throws IOException
+ {
+ return fromBytes( buffer, 0 );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Dn fromBytes( byte[] buffer, int pos ) throws IOException
+ {
+ int length = buffer.length - pos;
+ ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( buffer, pos, length ) );
+
+ try
+ {
+ Dn dn = new Dn();
+
+ dn.readExternal( in );
+
+ return dn;
+ }
+ catch ( ClassNotFoundException cnfe )
+ {
+ LOG.error( I18n.err( I18n.ERR_134, cnfe.getLocalizedMessage() ) );
+ throw new IOException( cnfe.getLocalizedMessage() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Class<?> getType()
+ {
+ return DnSerializer.class;
+ }
}
Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/KeyTupleArrayCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/KeyTupleArrayCursor.java?rev=1536068&r1=1536067&r2=1536068&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/KeyTupleArrayCursor.java (original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/KeyTupleArrayCursor.java Sun Oct 27 08:58:47 2013
@@ -27,7 +27,7 @@ import org.apache.directory.api.ldap.mod
import org.apache.directory.api.ldap.model.cursor.InvalidCursorPositionException;
import org.apache.directory.api.ldap.model.cursor.Tuple;
import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.mavibot.btree.managed.BTree;
+import org.apache.directory.mavibot.btree.ValueCursor;
import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,7 +48,7 @@ public class KeyTupleArrayCursor<K, V> e
/** Speedup for logs */
private static final boolean IS_DEBUG = LOG_CURSOR.isDebugEnabled();
- private final org.apache.directory.mavibot.btree.Cursor<V, V> wrapped;
+ private final ValueCursor<V> wrapped;
private final K key;
private Tuple<K, V> returnedTuple = new Tuple<K, V>();
@@ -61,18 +61,11 @@ public class KeyTupleArrayCursor<K, V> e
* @param arrayTree the ArrayTree to build a Tuple returning Cursor over
* @param key the constant key for which values are returned
*/
- public KeyTupleArrayCursor( BTree<V, V> arrayTree, K key )
+ public KeyTupleArrayCursor( ValueCursor<V> cursor, K key )
{
this.key = key;
- try
- {
- this.wrapped = arrayTree.browse();
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
+ this.wrapped = cursor;
if ( IS_DEBUG )
{
@@ -187,9 +180,8 @@ public class KeyTupleArrayCursor<K, V> e
{
if ( wrapped.hasPrev() )
{
- org.apache.directory.mavibot.btree.Tuple<V, V> t = wrapped.prev();
returnedTuple.setKey( key );
- returnedTuple.setValue( t.getKey() );
+ returnedTuple.setValue( wrapped.prev() );
return valueAvailable = true;
}
else
@@ -211,18 +203,20 @@ public class KeyTupleArrayCursor<K, V> e
public boolean next() throws LdapException, CursorException
{
checkNotClosed( "next()" );
+
try
{
if ( wrapped.hasNext() )
{
- org.apache.directory.mavibot.btree.Tuple<V, V> t = wrapped.next();
returnedTuple.setKey( key );
- returnedTuple.setValue( t.getKey() );
+ returnedTuple.setValue( wrapped.next() );
+
return valueAvailable = true;
}
else
{
clearValue();
+
return false;
}
}
Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotCursor.java?rev=1536068&r1=1536067&r2=1536068&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotCursor.java (original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotCursor.java Sun Oct 27 08:58:47 2013
@@ -26,6 +26,7 @@ import org.apache.directory.api.ldap.mod
import org.apache.directory.api.ldap.model.cursor.InvalidCursorPositionException;
import org.apache.directory.api.ldap.model.cursor.Tuple;
import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.mavibot.btree.TupleCursor;
import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,7 +47,7 @@ class MavibotCursor<K, V> extends Abstra
private Tuple<K, V> returnedTuple = new Tuple<K, V>();
private boolean valueAvailable;
- private org.apache.directory.mavibot.btree.Cursor<K, V> browser;
+ private TupleCursor<K, V> browser;
/**
@@ -324,7 +325,7 @@ class MavibotCursor<K, V> extends Abstra
}
- private void closeBrowser( org.apache.directory.mavibot.btree.Cursor<K, V> browser )
+ private void closeBrowser( TupleCursor<K, V> browser )
{
if ( browser != null )
{
Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotEntrySerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotEntrySerializer.java?rev=1536068&r1=1536067&r2=1536068&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotEntrySerializer.java (original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotEntrySerializer.java Sun Oct 27 08:58:47 2013
@@ -39,9 +39,9 @@ import org.apache.directory.api.ldap.mod
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
-import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.mavibot.btree.serializer.AbstractElementSerializer;
import org.apache.directory.mavibot.btree.serializer.BufferHandler;
-import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
+import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,7 +54,7 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class MavibotEntrySerializer implements ElementSerializer<Entry>
+public class MavibotEntrySerializer extends AbstractElementSerializer<Entry>
{
/** The serialVersionUID */
private static final long serialVersionUID = 1L;
@@ -70,6 +70,19 @@ public class MavibotEntrySerializer impl
/** The schemaManager reference */
private static SchemaManager schemaManager;
+ private static class EntryComparator implements Comparator<Entry>
+ {
+
+ @Override
+ public int compare( Entry entry1, Entry entry2 )
+ {
+ return entry1.getDn().getName().compareTo( entry1.getDn().getName() );
+ }
+
+ }
+
+ private static Comparator<Entry> comparator = new EntryComparator();
+
/**
* Creates a new instance of ServerEntrySerializer.
@@ -77,25 +90,17 @@ public class MavibotEntrySerializer impl
*/
public MavibotEntrySerializer()
{
+ super( comparator );
}
-
- @Override
- public int compare( Entry entry1, Entry entry2 )
- {
- return entry1.getDn().getName().compareTo( entry1.getDn().getName() );
- }
-
-
@Override
public Comparator<Entry> getComparator()
{
- return null;
+ return comparator;
}
-
/**
* <p>
*
@@ -130,13 +135,12 @@ public class MavibotEntrySerializer impl
baos.write( 0 );
baos.write( 0 );
baos.write( 0 );
-
+
ObjectOutput out = new ObjectOutputStream( baos );
-
-
+
// First, the Dn
Dn dn = entry.getDn();
-
+
// Write the Rdn of the Dn
if ( dn.isEmpty() )
{
@@ -148,10 +152,10 @@ public class MavibotEntrySerializer impl
Rdn rdn = dn.getRdn();
rdn.writeExternal( out );
}
-
+
// Then the attributes.
out.writeInt( entry.getAttributes().size() );
-
+
// Iterate through the keys. We store the Attribute
// here, to be able to restore it in the readExternal :
// we need access to the registries, which are not available
@@ -159,30 +163,30 @@ public class MavibotEntrySerializer impl
for ( Attribute attribute : entry.getAttributes() )
{
AttributeType attributeType = attribute.getAttributeType();
-
+
// Write the oid to be able to restore the AttributeType when deserializing
// the attribute
String oid = attributeType.getOid();
-
+
out.writeUTF( oid );
-
+
// Write the attribute
attribute.writeExternal( out );
}
-
+
out.flush();
-
+
// Note : we don't store the ObjectClassAttribute. It has already
// been stored as an attribute.
-
+
if ( IS_DEBUG )
{
LOG.debug( ">------------------------------------------------" );
LOG.debug( "Serialize " + entry );
}
-
+
byte[] bytes = baos.toByteArray();
-
+
totalBytes = bytes.length - 4; //subtract the first 4 dummy bytes
// replace the dummy length with the actual length
@@ -193,7 +197,7 @@ public class MavibotEntrySerializer impl
return bytes;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new RuntimeException( e );
}
@@ -213,7 +217,7 @@ public class MavibotEntrySerializer impl
int len = buffer.getInt();
ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( buffer.array(), buffer.position(), len ) );
-
+
try
{
Entry entry = new DefaultEntry( schemaManager );
@@ -271,7 +275,7 @@ public class MavibotEntrySerializer impl
}
buffer.position( buffer.position() + len ); // previous position + length
-
+
return entry;
}
catch ( ClassNotFoundException cnfe )
@@ -282,20 +286,109 @@ public class MavibotEntrySerializer impl
}
-
@Override
public Entry deserialize( BufferHandler bufferHandler ) throws IOException
{
return deserialize( ByteBuffer.wrap( bufferHandler.getBuffer() ) );
}
-
+
public static void setSchemaManager( SchemaManager schemaManager )
{
MavibotEntrySerializer.schemaManager = schemaManager;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Entry fromBytes( byte[] buffer ) throws IOException
+ {
+ return fromBytes( buffer, 0 );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Entry fromBytes( byte[] buffer, int pos ) throws IOException
+ {
+ // read the length
+ int len = buffer.length - pos;
+
+ ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( buffer, pos, len ) );
+
+ try
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ // Read the Dn, if any
+ byte hasDn = in.readByte();
+
+ if ( hasDn == 1 )
+ {
+ Rdn rdn = new Rdn( schemaManager );
+ rdn.readExternal( in );
+
+ try
+ {
+ entry.setDn( new Dn( schemaManager, rdn ) );
+ }
+ catch ( LdapInvalidDnException lide )
+ {
+ IOException ioe = new IOException( lide.getMessage() );
+ ioe.initCause( lide );
+ throw ioe;
+ }
+ }
+ else
+ {
+ entry.setDn( Dn.EMPTY_DN );
+ }
+
+ // Read the number of attributes
+ int nbAttributes = in.readInt();
+
+ // Read the attributes
+ for ( int i = 0; i < nbAttributes; i++ )
+ {
+ // Read the attribute's OID
+ String oid = in.readUTF();
+
+ try
+ {
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );
+
+ // Create the attribute we will read
+ Attribute attribute = new DefaultAttribute( attributeType );
+
+ // Read the attribute
+ attribute.readExternal( in );
+
+ entry.add( attribute );
+ }
+ catch ( LdapException ne )
+ {
+ // We weren't able to find the OID. The attribute will not be added
+ throw new ClassNotFoundException( ne.getMessage(), ne );
+ }
+ }
+
+ return entry;
+ }
+ catch ( ClassNotFoundException cnfe )
+ {
+ LOG.error( I18n.err( I18n.ERR_134, cnfe.getLocalizedMessage() ) );
+ throw new IOException( cnfe.getLocalizedMessage() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
@Override
public Class<?> getType()
{
Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotParentIdAndRdnSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotParentIdAndRdnSerializer.java?rev=1536068&r1=1536067&r2=1536068&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotParentIdAndRdnSerializer.java (original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotParentIdAndRdnSerializer.java Sun Oct 27 08:58:47 2013
@@ -31,8 +31,8 @@ import java.util.Comparator;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.mavibot.btree.serializer.AbstractElementSerializer;
import org.apache.directory.mavibot.btree.serializer.BufferHandler;
-import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
import org.apache.directory.server.i18n.I18n;
import org.apache.directory.server.xdbm.ParentIdAndRdn;
import org.slf4j.Logger;
@@ -46,7 +46,7 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class MavibotParentIdAndRdnSerializer implements ElementSerializer<ParentIdAndRdn>
+public class MavibotParentIdAndRdnSerializer extends AbstractElementSerializer<ParentIdAndRdn>
{
/** The serialVersionUID */
private static final long serialVersionUID = 1L;
@@ -62,7 +62,7 @@ public class MavibotParentIdAndRdnSerial
/** The schemaManager reference */
private static SchemaManager schemaManager;
- private Comparator<ParentIdAndRdn> comparator = new Comparator<ParentIdAndRdn>()
+ private static Comparator<ParentIdAndRdn> comparator = new Comparator<ParentIdAndRdn>()
{
@Override
@@ -80,6 +80,7 @@ public class MavibotParentIdAndRdnSerial
*/
public MavibotParentIdAndRdnSerializer()
{
+ super( comparator );
}
@@ -105,7 +106,16 @@ public class MavibotParentIdAndRdnSerial
ObjectOutput out = new ObjectOutputStream( baos );
// First, the Dn
- Rdn[] rdns = parentIdAndRdn.getRdns();
+ Rdn[] rdns;
+
+ try
+ {
+ rdns = parentIdAndRdn.getRdns();
+ }
+ catch ( NullPointerException npe )
+ {
+ throw npe;
+ }
// Write the Rdn of the Dn
if ( ( rdns == null ) || ( rdns.length == 0 ) )
@@ -248,10 +258,79 @@ public class MavibotParentIdAndRdnSerial
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public Class<?> getType()
+ public ParentIdAndRdn fromBytes( byte[] buffer ) throws IOException
{
- return MavibotParentIdAndRdnSerializer.class;
+ return fromBytes( buffer, 4 );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ParentIdAndRdn fromBytes( byte[] buffer, int pos ) throws IOException
+ {
+ int len = buffer.length - pos;
+
+ ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( buffer, pos, len ) );
+
+ try
+ {
+ ParentIdAndRdn parentIdAndRdn = new ParentIdAndRdn();
+
+ // Read the number of rdns, if any
+ byte nbRdns = in.readByte();
+
+ if ( nbRdns == 0 )
+ {
+ parentIdAndRdn.setRdns( new Rdn[0] );
+ }
+ else
+ {
+ Rdn[] rdns = new Rdn[nbRdns];
+
+ for ( int i = 0; i < nbRdns; i++ )
+ {
+ Rdn rdn = new Rdn( schemaManager );
+ rdn.readExternal( in );
+ rdns[i] = rdn;
+ }
+
+ parentIdAndRdn.setRdns( rdns );
+ }
+
+ // Read the parent ID
+ String uuid = in.readUTF();
+
+ parentIdAndRdn.setParentId( uuid );
+
+ // Read the nulber of children and descendants
+ int nbChildren = in.readInt();
+ int nbDescendants = in.readInt();
+
+ parentIdAndRdn.setNbChildren( nbChildren );
+ parentIdAndRdn.setNbDescendants( nbDescendants );
+
+ return parentIdAndRdn;
+ }
+ catch ( ClassNotFoundException cnfe )
+ {
+ LOG.error( I18n.err( I18n.ERR_134, cnfe.getLocalizedMessage() ) );
+ throw new IOException( cnfe.getLocalizedMessage() );
+ }
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Class<?> getType()
+ {
+ return ParentIdAndRdn.class;
+ }
}
Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotPartition.java?rev=1536068&r1=1536067&r2=1536068&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotPartition.java (original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/MavibotPartition.java Sun Oct 27 08:58:47 2013
@@ -28,16 +28,29 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.cursor.Cursor;
import org.apache.directory.api.ldap.model.cursor.Tuple;
import org.apache.directory.api.ldap.model.entry.Attribute;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Value;
+import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.api.util.exception.MultiException;
import org.apache.directory.mavibot.btree.managed.RecordManager;
import org.apache.directory.server.constants.ApacheSchemaConstants;
import org.apache.directory.server.core.api.DnFactory;
+import org.apache.directory.server.core.api.entry.ClonedServerEntry;
+import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition;
import org.apache.directory.server.i18n.I18n;
@@ -77,6 +90,9 @@ public class MavibotPartition extends Ab
private RecordManager recordMan;
+ /** the entry cache */
+ private Cache entryCache;
+
public MavibotPartition( SchemaManager schemaManager, DnFactory dnFactory )
{
@@ -119,11 +135,22 @@ public class MavibotPartition extends Ab
// Create the underlying directories (only if needed)
File partitionDir = new File( getPartitionPath() );
+
if ( !partitionDir.exists() && !partitionDir.mkdirs() )
{
throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, partitionDir ) );
}
+ if ( cacheSize < 0 )
+ {
+ cacheSize = DEFAULT_CACHE_SIZE;
+ LOG.debug( "Using the default entry cache size of {} for {} partition", cacheSize, id );
+ }
+ else
+ {
+ LOG.debug( "Using the custom configured cache size of {} for {} partition", cacheSize, id );
+ }
+
recordMan = new RecordManager( partitionDir.getPath() );
// Initialize the indexes
@@ -178,6 +205,12 @@ public class MavibotPartition extends Ab
deleteUnusedIndexFiles( allIndices, allIndexDbFiles );
*/
+
+ if ( cacheService != null )
+ {
+ entryCache = cacheService.getCache( getId() );
+ }
+
// We are done !
initialized = true;
}
@@ -223,6 +256,53 @@ public class MavibotPartition extends Ab
}
+ /**
+ * {@inheritDoc}
+ */
+ protected synchronized void doDestroy() throws Exception
+ {
+ MultiException errors = new MultiException( I18n.err( I18n.ERR_577 ) );
+
+ if ( !initialized )
+ {
+ return;
+ }
+
+ try
+ {
+ super.doDestroy();
+ }
+ catch ( Exception e )
+ {
+ errors.addThrowable( e );
+ }
+
+ // This is specific to the MAVIBOT store : close the record manager
+ try
+ {
+ recordMan.close();
+ LOG.debug( "Closed record manager for {} partition.", suffixDn );
+ }
+ catch ( Throwable t )
+ {
+ LOG.error( I18n.err( I18n.ERR_127 ), t );
+ errors.addThrowable( t );
+ }
+ finally
+ {
+ if ( entryCache != null )
+ {
+ entryCache.removeAll();
+ }
+ }
+
+ if ( errors.size() > 0 )
+ {
+ throw errors;
+ }
+ }
+
+
@Override
protected Index createSystemIndex( String indexOid, URI path, boolean withReverse ) throws Exception
{
@@ -353,4 +433,83 @@ public class MavibotPartition extends Ab
return recordMan;
}
+
+ public Entry lookupCache( String id )
+ {
+ if ( entryCache == null )
+ {
+ return null;
+ }
+
+ Element el = entryCache.get( id );
+
+ if ( el != null )
+ {
+ return ( Entry ) el.getValue();
+ }
+
+ return null;
+ }
+
+
+ @Override
+ public void addToCache( String id, Entry entry )
+ {
+ if ( entryCache == null )
+ {
+ return;
+ }
+
+ if ( entry instanceof ClonedServerEntry )
+ {
+ entry = ( ( ClonedServerEntry ) entry ).getOriginalEntry();
+ }
+
+ entryCache.put( new Element( id, entry ) );
+ }
+
+
+ @Override
+ public void updateCache( OperationContext opCtx )
+ {
+ if ( entryCache == null )
+ {
+ return;
+ }
+
+ try
+ {
+ if ( opCtx instanceof ModifyOperationContext )
+ {
+ // replace the entry
+ ModifyOperationContext modCtx = ( ModifyOperationContext ) opCtx;
+ Entry entry = modCtx.getAlteredEntry();
+ String id = entry.get( SchemaConstants.ENTRY_UUID_AT ).getString();
+
+ if ( entry instanceof ClonedServerEntry )
+ {
+ entry = ( ( ClonedServerEntry ) entry ).getOriginalEntry();
+ }
+
+ entryCache.replace( new Element( id, entry ) );
+ }
+ else if ( ( opCtx instanceof MoveOperationContext ) ||
+ ( opCtx instanceof MoveAndRenameOperationContext ) ||
+ ( opCtx instanceof RenameOperationContext ) )
+ {
+ // clear the cache it is not worth updating all the children
+ entryCache.removeAll();
+ }
+ else if ( opCtx instanceof DeleteOperationContext )
+ {
+ // delete the entry
+ DeleteOperationContext delCtx = ( DeleteOperationContext ) opCtx;
+ entryCache.remove( delCtx.getEntry().get( SchemaConstants.ENTRY_UUID_AT ).getString() );
+ }
+ }
+ catch ( LdapException e )
+ {
+ LOG.warn( "Failed to update entry cache", e );
+ }
+ }
}
\ No newline at end of file
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=1536068&r1=1536067&r2=1536068&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 Sun Oct 27 08:58:47 2013
@@ -28,10 +28,11 @@ import org.apache.directory.api.ldap.mod
import org.apache.directory.api.ldap.model.cursor.Tuple;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.mavibot.btree.TupleCursor;
+import org.apache.directory.mavibot.btree.ValueCursor;
import org.apache.directory.mavibot.btree.exception.BTreeAlreadyManagedException;
import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
import org.apache.directory.mavibot.btree.managed.BTree;
-import org.apache.directory.mavibot.btree.managed.DuplicateKeyVal;
import org.apache.directory.mavibot.btree.managed.RecordManager;
import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
import org.apache.directory.server.core.avltree.ArrayMarshaller;
@@ -129,7 +130,8 @@ public class MavibotTable<K, V> extends
@Override
public boolean hasGreaterOrEqual( K key ) throws Exception
{
- org.apache.directory.mavibot.btree.Cursor<K, V> cursor = null;
+ TupleCursor<K, V> cursor = null;
+
try
{
cursor = bt.browseFrom( key );
@@ -149,7 +151,7 @@ public class MavibotTable<K, V> extends
@Override
public boolean hasLessOrEqual( K key ) throws Exception
{
- org.apache.directory.mavibot.btree.Cursor<K, V> cursor = null;
+ TupleCursor<K, V> cursor = null;
try
{
@@ -205,7 +207,7 @@ public class MavibotTable<K, V> extends
throw new UnsupportedOperationException( I18n.err( I18n.ERR_593 ) );
}
- org.apache.directory.mavibot.btree.Cursor<V, V> cursor = null;
+ TupleCursor<V, V> cursor = null;
try
{
@@ -214,20 +216,11 @@ public class MavibotTable<K, V> extends
return false;
}
- DuplicateKeyVal<V> dupHolder = bt.getValues( key );
- if ( dupHolder.isSingleValue() )
- {
- int equal = bt.getValueSerializer().compare( val, dupHolder.getSingleValue() );
- return ( equal == 0 );
- }
- else
- {
- BTree<V, V> dups = dupHolder.getSubTree();
+ ValueCursor<V> dupHolder = bt.getValues( key );
- cursor = dups.browseFrom( val );
+ int equal = bt.getValueSerializer().compare( val, dupHolder.next() );
- return cursor.hasNext();
- }
+ return ( equal == 0 );
}
catch ( Exception e )
{
@@ -261,55 +254,9 @@ public class MavibotTable<K, V> extends
return false;
}
- DuplicateKeyVal<V> dupHolder = bt.getValues( key );
-
- if ( dupHolder.isSingleValue() )
- {
- return true;
- }
-
- BTree<V, V> dups = dupHolder.getSubTree();
-
- org.apache.directory.mavibot.btree.Cursor<V, V> cursor = null;
-
- try
- {
- cursor = dups.browseFrom( val );
-
- org.apache.directory.mavibot.btree.Tuple<V, V> tuple = null;
-
- if ( cursor.hasNext() )
- {
- tuple = cursor.next();
- }
-
- // Test for equality first since it satisfies both greater/less than
- if ( null != tuple && keyComparator.compare( ( K ) tuple.getKey(), key ) == 0 )
- {
- return true;
- }
-
- if ( null == tuple )
- {
- return count > 0;
- }
- else
- {
- if ( cursor.hasPrev() )
- {
- return true;
- }
- }
+ ValueCursor<V> dupHolder = bt.getValues( key );
- return false;
- }
- finally
- {
- if ( cursor != null )
- {
- cursor.close();
- }
- }
+ return dupHolder.hasNext();
}
@@ -442,15 +389,9 @@ public class MavibotTable<K, V> extends
}
else
{
- DuplicateKeyVal<V> dupHolder = bt.getValues( key );
- if ( dupHolder.isSingleValue() )
- {
- return new SingletonCursor<Tuple<K, V>>( new Tuple<K, V>( key, dupHolder.getSingleValue() ) );
- }
+ ValueCursor<V> dupHolder = bt.getValues( key );
- BTree<V, V> dups = dupHolder.getSubTree();
-
- return new KeyTupleArrayCursor<K, V>( dups, key );
+ return new KeyTupleArrayCursor<K, V>( dupHolder, key );
}
}
catch ( KeyNotFoundException knfe )
@@ -482,15 +423,9 @@ public class MavibotTable<K, V> extends
}
else
{
- DuplicateKeyVal<V> dupHolder = bt.getValues( key );
- if ( dupHolder.isSingleValue() )
- {
- return new SingletonCursor<V>( dupHolder.getSingleValue() );
- }
- else
- {
- return new ValueTreeCursor<V>( dupHolder.getSubTree() );
- }
+ ValueCursor<V> dupHolder = bt.getValues( key );
+
+ return new ValueTreeCursor<V>( dupHolder );
}
}
catch ( KeyNotFoundException knfe )
@@ -516,15 +451,9 @@ public class MavibotTable<K, V> extends
{
if ( bt.isAllowDuplicates() )
{
- DuplicateKeyVal<V> dupHolder = bt.getValues( key );
- if ( dupHolder.isSingleValue() )
- {
- return 1;
- }
-
- BTree<V, V> values = dupHolder.getSubTree();
+ ValueCursor<V> dupHolder = bt.getValues( key );
- return values.getNbElems();
+ return dupHolder.size();
}
else
{
Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/ValueTreeCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/ValueTreeCursor.java?rev=1536068&r1=1536067&r2=1536068&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/ValueTreeCursor.java (original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/mavibot/ValueTreeCursor.java Sun Oct 27 08:58:47 2013
@@ -26,7 +26,7 @@ import java.io.IOException;
import org.apache.directory.api.ldap.model.cursor.AbstractCursor;
import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.mavibot.btree.managed.BTree;
+import org.apache.directory.mavibot.btree.ValueCursor;
import org.apache.directory.server.i18n.I18n;
@@ -38,7 +38,7 @@ import org.apache.directory.server.i18n.
public class ValueTreeCursor<V> extends AbstractCursor<V>
{
- private org.apache.directory.mavibot.btree.Cursor<V, V> wrapped;
+ private ValueCursor<V> wrapped;
private V available;
@@ -46,16 +46,9 @@ public class ValueTreeCursor<V> extends
private V NOT_AVAILABLE = ( V ) new Object();
- public ValueTreeCursor( BTree<V, V> dupsTree )
+ public ValueTreeCursor( ValueCursor<V> cursor )
{
- try
- {
- this.wrapped = dupsTree.browse();
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
+ this.wrapped = cursor;
}
@@ -114,7 +107,7 @@ public class ValueTreeCursor<V> extends
{
if ( wrapped.hasPrev() )
{
- available = wrapped.prev().getKey();
+ available = wrapped.prev();
return true;
}
else
@@ -137,7 +130,7 @@ public class ValueTreeCursor<V> extends
{
if ( wrapped.hasNext() )
{
- available = wrapped.next().getKey();
+ available = wrapped.next();
return true;
}
else