directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r752977 - /directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java
Date Thu, 12 Mar 2009 19:19:35 GMT
Author: kayyagari
Date: Thu Mar 12 19:19:35 2009
New Revision: 752977

URL: http://svn.apache.org/viewvc?rev=752977&view=rev
Log:
o abstracted the code used for doing a sync search
o fixed an issue related to sleeping after performing a insitial syn search with refreshOnly
mode
o added some javadoc
o fixed a misunderstood property setting related to alias dereferencing

Modified:
    directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java

Modified: directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java?rev=752977&r1=752976&r2=752977&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java
(original)
+++ directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java
Thu Mar 12 19:19:35 2009
@@ -40,6 +40,7 @@
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.LdapResponse;
 import org.apache.directory.shared.ldap.codec.LdapResult;
 import org.apache.directory.shared.ldap.codec.TwixTransformer;
@@ -170,8 +171,6 @@
             if ( !connected )
             {
                 LOG.warn( "Failed to connect to the syncrepl provder host {} running at port
{}", providerHost, port );
-                // FIXME rmove this at the time of integration with ADS
-                //System.exit( 2 );
             }
             else
             {
@@ -224,6 +223,11 @@
     }
 
 
+    /**
+     * 
+     *  prepares a SearchRequest for syncing DIT content.
+     *
+     */
     public void prepareSyncSearchRequest()
     {
 
@@ -257,8 +261,8 @@
 
         searchRequest.setSizeLimit( config.getSearchSizeLimit() );
         searchRequest.setTimeLimit( config.getSearchTimeout() );
-        //TODO openLdap cries if this flag is set 
-        // searchRequest.setDerefAliases( LdapConstants.DEREF_ALWAYS );
+        // the only valid values are NEVER_DEREF_ALIASES and DEREF_FINDING_BASE_OBJ
+        searchRequest.setDerefAliases( LdapConstants.NEVER_DEREF_ALIASES );
         searchRequest.setScope( SearchScope.getSearchScope( config.getSearchScope() ) );
         searchRequest.setTypesOnly( false );
 
@@ -308,13 +312,6 @@
         Control ctrl = searchDone.getCurrentControl();
         SyncDoneValueControlCodec syncDoneCtrl = ( SyncDoneValueControlCodec ) ctrl.getControlValue();
 
-        if ( !config.isRefreshPersist() )
-        {
-        	// Now, switch to refreshAndPresist
-            config.setRefreshPersist( true );
-            LOG.debug( "Swithing to RefreshAndPersist" );
-        }
-
         if ( syncDoneCtrl.getCookie() != null )
         {
             syncCookie = syncDoneCtrl.getCookie();
@@ -325,6 +322,32 @@
             LOG.info( "cookie in syncdone message is null" );
         }
 
+        if ( !config.isRefreshPersist() )
+        {
+            // Now, switch to refreshAndPresist
+            config.setRefreshPersist( true );
+            LOG.debug( "Swithing to RefreshAndPersist" );
+         
+            try
+            {
+                // the below call is required to send the updated cookie
+                // and refresh mode change (i.e to refreshAndPersist stage)
+                // cause while the startSync() method sleeps even after the 'sync done'
+                // message arrives as part of initial searchRequest with 'refreshOnly' mode.
+                // During this sleep time any 'modifications' happened on the server 
+                // to already fetched entries will be sent as SearchResultEntries with
+                // SyncState value as 'ADD' which will conflict with the DNs of initially
received entries
+                
+                // TODO thinking of alternative ways to implement this in case of large DITs

+                // where the modification to entry(ies) can happen before the initial sync
is done
+                doSyncSearch();
+            }
+            catch( Exception e )
+            {
+                LOG.error( "Failed to send a search request with RefreshAndPersist mode",
e );
+            }
+        }
+
         LOG.debug( "//////////////// END handleSearchDone//////////////////////" );
     }
 
@@ -356,8 +379,8 @@
 
             SyncStateTypeEnum state = syncStateCtrl.getSyncStateType();
 
-            LOG.debug( "state name {}" + state.name() );
-            LOG.debug( "entryUUID = " + UUID.nameUUIDFromBytes( syncStateCtrl.getEntryUUID()
) );
+            LOG.debug( "state name {}", state.name() );
+            LOG.debug( "entryUUID = {}", UUID.nameUUIDFromBytes( syncStateCtrl.getEntryUUID()
) );
             CoreSession session = directoryService.getAdminSession();
 
             switch ( state )
@@ -389,13 +412,13 @@
 	                    if (  remoteAttr != null ) // would be better if we compare the values
also? or will it consume more time?
 	                    {
 	                        mod = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE,
remoteAttr );
+	                        remoteEntry.remove( remoteAttr );
 	                    }
 	                    else
 	                    {
 	                        mod = new ServerModification( ModificationOperation.REMOVE_ATTRIBUTE,
localAttr );
 	                    }
 	                
-	                    remoteEntry.remove( remoteAttr );
 	                    mods.add( mod );
 	                }
 	
@@ -465,9 +488,6 @@
 
     /**
      * starts the syn operation
-     * 
-     * TODO should run in a separate thread
-     * 
      */
     public void startSync()
     {
@@ -476,70 +496,73 @@
             return;
         }
 
-        try
-        {
-            int pass = 1;
+        int pass = 1;
 
-            do
+        // continue till refreshAndPersist mode is not set
+        while( !config.isRefreshPersist() )
+        {
+            
+            try
             {
-                if( config.isRefreshPersist() )
+                if ( config.isRefreshPersist() )
                 {
-                    syncReq.setMode( SynchronizationModeEnum.REFRESH_AND_PERSIST );
+                    LOG.debug( "==================== Refresh And Persist ==========" );
                 }
-
-                if ( syncCookie != null )
+                else
                 {
-                    syncReq.setCookie( syncCookie );
+                    LOG.debug( "==================== Initial Content ==========" );
                 }
                 
-                searchRequest.getCurrentControl().setControlValue( syncReq.getEncodedValue()
);
-                
-                try
+                if ( ( syncReq.getCookie() == null ) || ( syncReq.getCookie().length == 0
) )
                 {
-                	if ( config.isRefreshPersist() )
-                	{
-                		LOG.debug( "==================== Refresh And Persist ==========" );
-                	}
-                	else
-                	{
-                		LOG.debug( "==================== Initial Content ==========" );
-                	}
-                    
-                    if ( ( syncReq.getCookie() == null ) || ( syncReq.getCookie().length
== 0 ) )
-                    {
-                    	LOG.debug( "First search (no cookie)" );
-                    }
-                    else
-                    {
-                    	LOG.debug( "searching with searchRequest, cookie '{}'", StringTools.utf8ToString(
syncReq.getCookie() ) );
-                    }
-                    
-                    connection.search( searchRequest );
-
-                    if ( !config.isRefreshPersist() )
-                    {
-                        LOG.info( "--------------------- Sleep for a little while ------------------"
);
-                        Thread.sleep( config.getConsumerInterval() );
-                        LOG.debug( "--------------------- syncing again ------------------"
);
-                    }
-
+                    LOG.debug( "First search (no cookie)" );
                 }
-                catch ( Exception e )
+                else
                 {
-                    LOG.error( "Failed to sync", e );
+                    LOG.debug( "searching with searchRequest, cookie '{}'", StringTools.utf8ToString(
syncReq.getCookie() ) );
                 }
+                
+                doSyncSearch();
+
+                LOG.info( "--------------------- Sleep for a little while ------------------"
);
+                Thread.sleep( config.getConsumerInterval() );
+                LOG.debug( "--------------------- syncing again ------------------" );
+
+            }
+            catch ( Exception e )
+            {
+                LOG.error( "Failed to sync with refresh only mode", e );
             }
-            while( syncReq.getMode() != SynchronizationModeEnum.REFRESH_AND_PERSIST );//
end of while loop
-            
-            LOG.debug( "**************** Done with the sync ***************" );
         }
-        catch ( Exception e )
+        
+        LOG.debug( "**************** Done with the initial sync ***************" );
+    }
+
+    
+    /**
+     * 
+     * performs a search on connection with updated syncrequest control.
+     *
+     * @throws Exception in case of any problems encountered while searching
+     */
+    private void doSyncSearch() throws Exception
+    {
+        if( config.isRefreshPersist() )
         {
-            e.printStackTrace();
+            syncReq.setMode( SynchronizationModeEnum.REFRESH_AND_PERSIST );
         }
-    }
 
+        if ( syncCookie != null )
+        {
+            syncReq.setCookie( syncCookie );
+        }
+        
+        searchRequest.getCurrentControl().setControlValue( syncReq.getEncodedValue() );
+
+        connection.search( searchRequest );
+    }
 
+    
     public void disconnet()
     {
         try



Mime
View raw message