directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r486824 - in /directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree: BTreePartition.java jdbm/JdbmPartition.java
Date Wed, 13 Dec 2006 20:07:51 GMT
Author: akarasulu
Date: Wed Dec 13 12:07:49 2006
New Revision: 486824

URL: http://svn.apache.org/viewvc?view=rev&rev=486824
Log:
simplified jdbm and btree partition init sequences in preparation for breaking up the core

Modified:
    directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
    directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java

Modified: directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java?view=diff&rev=486824&r1=486823&r2=486824
==============================================================================
--- directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
(original)
+++ directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
Wed Dec 13 12:07:49 2006
@@ -63,13 +63,11 @@
 {
     private static final Logger log = LoggerFactory.getLogger( BTreePartition.class );
 
-    /**
-     * the search engine used to search the database
-     */
+    /** the search engine used to search the database */
     private SearchEngine searchEngine = null;
     private Optimizer optimizer = new NoOpOptimizer();
     
-    protected BTreePartitionConfiguration btpConfig;
+    protected BTreePartitionConfiguration xbtpConfig;
     protected AttributeTypeRegistry attributeTypeRegistry = null;
     protected OidRegistry oidRegistry = null;
 
@@ -94,7 +92,22 @@
      * 
      * @param registries the schema entity registries
      */
-    public void setRegistries( Registries registries )
+    public void initRegistries( Registries registries )
+    {
+        initRegistries1( registries );
+    }
+    
+    
+    /**
+     * This should be called second after initializing the optimizer with 
+     * initOptimizer0.  This is the same as calling initRegistries() 
+     * (initRegistries actually calls initRegistries1) except it is protected 
+     * to hide the '1' at the end of the method name.  The '1' indicates it 
+     * is the 2nd thing that must be executed during initialization.
+     * 
+     * @param registries the schema entity registries
+     */
+    protected void initRegistries1( Registries registries )
     {
         attributeTypeRegistry = registries.getAttributeTypeRegistry();
         oidRegistry = registries.getOidRegistry();
@@ -103,19 +116,17 @@
         this.searchEngine = new DefaultSearchEngine( this, evaluator, enumerator, optimizer
);
     }
     
-
-    public void init( DirectoryServiceConfiguration factoryCfg, PartitionConfiguration cfg
)
-        throws NamingException
+    
+    /**
+     * Use this method to initialize the indices.  Only call this after
+     * the registries and the optimizer have been enabled.  The '2' at the end
+     * shows this is the 3rd init method called in the init sequence.
+     * 
+     * @param indices
+     * @throws NamingException
+     */
+    protected void initIndices2(Set<String> indices ) throws NamingException
     {
-        this.btpConfig = BTreePartitionConfiguration.convert( cfg );
-        if ( this.btpConfig.isOptimizerEnabled() )
-        {
-            optimizer = new DefaultOptimizer( this );
-        }
-
-        // Call this ONLY after trying to override the optimizer default above
-        setRegistries( factoryCfg.getRegistries() );
-
         Set<String> sysOidSet = new HashSet<String>();
         sysOidSet.add( Oid.EXISTANCE );
         sysOidSet.add( Oid.HIERARCHY );
@@ -128,7 +139,7 @@
         // Used to calculate the system indices we must automatically add
         Set<String> customAddedSystemIndices = new HashSet<String>();
         
-        for ( Iterator ii = cfg.getIndexedAttributes().iterator(); ii.hasNext(); /**/ )
+        for ( Iterator ii = indices.iterator(); ii.hasNext(); /**/ )
         {
             /*
              * NOTE
@@ -299,15 +310,54 @@
                 }
             }
         }
+    }
 
+    
+    /**
+     * Called last (4th) to check if the suffix entry has been created on disk,
+     * and if not it is created.
+     *  
+     * @param suffix
+     * @param entry
+     * @throws NamingException
+     */
+    protected void initSuffixEntry3( String suffix, Attributes entry ) throws NamingException
+    {
         // add entry for context, if it does not exist
         Attributes suffixOnDisk = getSuffixEntry();
         if ( suffixOnDisk == null )
         {
-            LdapDN suffix = new LdapDN( cfg.getSuffix() );
-            LdapDN normalizedSuffix = LdapDN.normalize( suffix, attributeTypeRegistry.getNormalizerMapping()
);
-            add( normalizedSuffix, cfg.getContextEntry() );
+            LdapDN dn = new LdapDN( suffix );
+            LdapDN normalizedSuffix = LdapDN.normalize( dn, attributeTypeRegistry.getNormalizerMapping()
);
+            add( normalizedSuffix, entry );
         }
+    }
+
+    
+    /**
+     * Call this first in the init sequence to initialize the optimizer.
+     * 
+     * @param cfg
+     */
+    protected void initOptimizer0( PartitionConfiguration cfg )
+    {
+        if ( cfg instanceof BTreePartitionConfiguration )
+        {
+            if ( ( ( BTreePartitionConfiguration ) cfg ).isOptimizerEnabled() )
+            {
+                optimizer = new DefaultOptimizer( this );
+            }
+        }
+    }
+
+    
+    public void init( DirectoryServiceConfiguration factoryCfg, PartitionConfiguration cfg
)
+        throws NamingException
+    {
+        initOptimizer0( cfg );
+        initRegistries1( factoryCfg.getRegistries() );
+        initIndices2( cfg.getIndexedAttributes() );
+        initSuffixEntry3( cfg.getSuffix(), cfg.getContextEntry() );
     }
 
 

Modified: directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java?view=diff&rev=486824&r1=486823&r2=486824
==============================================================================
--- directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
(original)
+++ directory/branches/trunks/schema2/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
Wed Dec 13 12:07:49 2006
@@ -52,7 +52,6 @@
 import org.apache.directory.server.core.partition.impl.btree.IndexAssertionEnumeration;
 import org.apache.directory.server.core.partition.impl.btree.IndexNotFoundException;
 import org.apache.directory.server.core.partition.impl.btree.IndexRecord;
-import org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration;
 
 import org.apache.directory.shared.ldap.exception.LdapAuthenticationNotSupportedException;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
@@ -96,6 +95,9 @@
 
     /** true if open */
     private boolean initialized;
+    /** true if we sync disks on every write operation */
+    private boolean isSyncOnWrite = true;
+    
 
     /** the normalized distinguished name index */
     private Index ndnIdx;
@@ -133,15 +135,11 @@
     {
         if ( cfg instanceof BTreePartitionConfiguration )
         {
-            btpConfig = ( BTreePartitionConfiguration ) cfg;
-        }
-        else
-        {
-            btpConfig = MutableBTreePartitionConfiguration.getConfiguration( cfg );
+            isSyncOnWrite = ( ( BTreePartitionConfiguration ) cfg ).isSynchOnWrite();
         }
         
-        oidRegistry = factoryCfg.getRegistries().getOidRegistry();
-        attributeTypeRegistry = factoryCfg.getRegistries().getAttributeTypeRegistry();
+        initOptimizer0( cfg );
+        initRegistries1( factoryCfg.getRegistries() );
 
         OBJECT_CLASS_AT = attributeTypeRegistry.lookup( "objectClass" );
         ALIAS_AT = attributeTypeRegistry.lookup( Partition.ALIAS_ATTRIBUTE );
@@ -187,7 +185,8 @@
         indices = new HashMap<String,Index>();
         sysIndices = new HashMap<String,Index>();
 
-        super.init( factoryCfg, cfg );
+        initIndices2( cfg.getIndexedAttributes() );
+        initSuffixEntry3( cfg.getSuffix(), cfg.getContextEntry() );
         initialized = true;
     }
 
@@ -870,7 +869,7 @@
 
         master.put( entry, id );
         
-        if ( btpConfig.isSynchOnWrite() )
+        if ( isSyncOnWrite )
         {
             sync();
         }
@@ -929,7 +928,7 @@
 
         master.delete( id );
         
-        if ( btpConfig.isSynchOnWrite() )
+        if ( isSyncOnWrite )
         {
             sync();
         }
@@ -1274,7 +1273,7 @@
 
         master.put( entry, id );
         
-        if ( btpConfig.isSynchOnWrite() )
+        if ( isSyncOnWrite )
         {
             sync();
         }
@@ -1308,7 +1307,7 @@
 
         master.put( entry, id );
         
-        if ( btpConfig.isSynchOnWrite() )
+        if ( isSyncOnWrite )
         {
             sync();
         }
@@ -1433,7 +1432,7 @@
         newUpdn.add( newUpdn.size(), newRdn ); // add da new upRdn
         modifyDn( id, newUpdn, false ); // propagate dn changes
         
-        if ( btpConfig.isSynchOnWrite() )
+        if ( isSyncOnWrite )
         {
             sync();
         }
@@ -1518,7 +1517,7 @@
         modifyRn( oldChildDn, newRdn, deleteOldRdn );
         move( oldChildDn, childId, newParentDn );
         
-        if ( btpConfig.isSynchOnWrite() )
+        if ( isSyncOnWrite )
         {
             sync();
         }
@@ -1530,7 +1529,7 @@
         BigInteger childId = getEntryId( oldChildDn.toString() );
         move( oldChildDn, childId, newParentDn );
         
-        if ( btpConfig.isSynchOnWrite() )
+        if ( isSyncOnWrite )
         {
             sync();
         }



Mime
View raw message