Blame SOURCES/0057-Ticket-47599-Reduce-lock-scope-in-retro-changelog-pl.patch

cc3dff
From a111165bab37e74bcaa76b1ba6182549a785361d Mon Sep 17 00:00:00 2001
cc3dff
From: Mark Reynolds <mreynolds@redhat.com>
cc3dff
Date: Wed, 20 Nov 2013 09:08:50 -0500
cc3dff
Subject: [PATCH 57/65] Ticket 47599 - Reduce lock scope in retro changelog
cc3dff
 plug-in
cc3dff
cc3dff
Description:  Use RW locks for protecting the change numbers.
cc3dff
cc3dff
              We still need to do the locking in retrocl_po.c as we need to
cc3dff
              serialize the actual updates.
cc3dff
cc3dff
https://fedorahosted.org/389/ticket/47599
cc3dff
cc3dff
Reviewed by: richm(Thanks!!)
cc3dff
(cherry picked from commit e2c42bced86bac235ac56ae98eed303f61ebd15e)
cc3dff
(cherry picked from commit 03f6347eb72d3cbb49ae33312f32df9f91a2fd4c)
cc3dff
---
cc3dff
 ldap/servers/plugins/retrocl/retrocl.c    |  3 ++-
cc3dff
 ldap/servers/plugins/retrocl/retrocl.h    |  1 +
cc3dff
 ldap/servers/plugins/retrocl/retrocl_cn.c | 42 +++++++++++++++++++++----------
cc3dff
 ldap/servers/plugins/retrocl/retrocl_po.c |  2 +-
cc3dff
 4 files changed, 33 insertions(+), 15 deletions(-)
cc3dff
cc3dff
diff --git a/ldap/servers/plugins/retrocl/retrocl.c b/ldap/servers/plugins/retrocl/retrocl.c
cc3dff
index 90c3455..3e426a7 100644
cc3dff
--- a/ldap/servers/plugins/retrocl/retrocl.c
cc3dff
+++ b/ldap/servers/plugins/retrocl/retrocl.c
cc3dff
@@ -465,7 +465,8 @@ retrocl_plugin_init(Slapi_PBlock *pb)
cc3dff
 	  if (!is_betxn) {
cc3dff
 	    rc= slapi_register_plugin_ext("internalpostoperation", 1 /* Enabled */, "retrocl_internalpostop_init", retrocl_internalpostop_init, "Retrocl internal postoperation plugin", NULL, identity, precedence);
cc3dff
 	  }
cc3dff
-
cc3dff
+	  retrocl_cn_lock = slapi_new_rwlock();
cc3dff
+	  if(retrocl_cn_lock == NULL) return -1;
cc3dff
 	  retrocl_internal_lock = PR_NewLock();
cc3dff
 	  if (retrocl_internal_lock == NULL) return -1;
cc3dff
 	}
cc3dff
diff --git a/ldap/servers/plugins/retrocl/retrocl.h b/ldap/servers/plugins/retrocl/retrocl.h
cc3dff
index 276912b..bfebe2e 100644
cc3dff
--- a/ldap/servers/plugins/retrocl/retrocl.h
cc3dff
+++ b/ldap/servers/plugins/retrocl/retrocl.h
cc3dff
@@ -130,6 +130,7 @@ extern const char *attr_nsuniqueid;
cc3dff
 extern const char *attr_isreplicated;
cc3dff
 
cc3dff
 extern PRLock *retrocl_internal_lock;
cc3dff
+extern Slapi_RWLock *retrocl_cn_lock;
cc3dff
 
cc3dff
 /* Functions */
cc3dff
 
cc3dff
diff --git a/ldap/servers/plugins/retrocl/retrocl_cn.c b/ldap/servers/plugins/retrocl/retrocl_cn.c
cc3dff
index d2b15a4..f816730 100644
cc3dff
--- a/ldap/servers/plugins/retrocl/retrocl_cn.c
cc3dff
+++ b/ldap/servers/plugins/retrocl/retrocl_cn.c
cc3dff
@@ -163,8 +163,9 @@ int retrocl_get_changenumbers(void)
cc3dff
 		       NULL,NULL,0,&cr,NULL,handle_cnum_result,
cc3dff
 		       handle_cnum_entry, NULL);
cc3dff
 
cc3dff
-    retrocl_first_cn = cr.cr_cnum;
cc3dff
+    slapi_rwlock_wrlock(retrocl_cn_lock);
cc3dff
 
cc3dff
+    retrocl_first_cn = cr.cr_cnum;
cc3dff
     slapi_ch_free(( void **) &cr.cr_time );
cc3dff
 
cc3dff
     slapi_seq_callback(RETROCL_CHANGELOG_DN,SLAPI_SEQ_LAST,
cc3dff
@@ -178,6 +179,8 @@ int retrocl_get_changenumbers(void)
cc3dff
 		    retrocl_first_cn,
cc3dff
 		    retrocl_internal_cn);
cc3dff
 
cc3dff
+    slapi_rwlock_unlock(retrocl_cn_lock);
cc3dff
+
cc3dff
     slapi_ch_free(( void **) &cr.cr_time );
cc3dff
 
cc3dff
     return 0;
cc3dff
@@ -238,10 +241,10 @@ time_t retrocl_getchangetime( int type, int *err )
cc3dff
 
cc3dff
 void retrocl_forget_changenumbers(void) 
cc3dff
 { 
cc3dff
-    PR_Lock(retrocl_internal_lock);
cc3dff
+    slapi_rwlock_wrlock(retrocl_cn_lock);
cc3dff
     retrocl_first_cn = 0;
cc3dff
     retrocl_internal_cn = 0;
cc3dff
-    PR_Unlock(retrocl_internal_lock);
cc3dff
+    slapi_rwlock_unlock(retrocl_cn_lock);
cc3dff
 }
cc3dff
 
cc3dff
 /*
cc3dff
@@ -258,9 +261,11 @@ void retrocl_forget_changenumbers(void)
cc3dff
 changeNumber retrocl_get_first_changenumber(void) 
cc3dff
 { 
cc3dff
     changeNumber cn;
cc3dff
-    PR_Lock(retrocl_internal_lock);
cc3dff
+
cc3dff
+    slapi_rwlock_rdlock(retrocl_cn_lock);
cc3dff
     cn = retrocl_first_cn;
cc3dff
-    PR_Unlock(retrocl_internal_lock);
cc3dff
+    slapi_rwlock_unlock(retrocl_cn_lock);
cc3dff
+
cc3dff
     return cn;
cc3dff
 }
cc3dff
 
cc3dff
@@ -277,9 +282,9 @@ changeNumber retrocl_get_first_changenumber(void)
cc3dff
 
cc3dff
 void retrocl_set_first_changenumber(changeNumber cn) 
cc3dff
 { 
cc3dff
-    PR_Lock(retrocl_internal_lock);
cc3dff
+    slapi_rwlock_wrlock(retrocl_cn_lock);
cc3dff
     retrocl_first_cn = cn;
cc3dff
-    PR_Unlock(retrocl_internal_lock);
cc3dff
+    slapi_rwlock_unlock(retrocl_cn_lock);
cc3dff
 }
cc3dff
 
cc3dff
 
cc3dff
@@ -297,9 +302,11 @@ void retrocl_set_first_changenumber(changeNumber cn)
cc3dff
 changeNumber retrocl_get_last_changenumber(void) 
cc3dff
 { 
cc3dff
     changeNumber cn;
cc3dff
-    PR_Lock(retrocl_internal_lock);
cc3dff
+
cc3dff
+    slapi_rwlock_rdlock(retrocl_cn_lock);
cc3dff
     cn = retrocl_internal_cn;
cc3dff
-    PR_Unlock(retrocl_internal_lock);
cc3dff
+    slapi_rwlock_unlock(retrocl_cn_lock);
cc3dff
+
cc3dff
     return cn;
cc3dff
 }
cc3dff
 
cc3dff
@@ -316,9 +323,11 @@ changeNumber retrocl_get_last_changenumber(void)
cc3dff
 
cc3dff
 void retrocl_commit_changenumber(void) 
cc3dff
 { 
cc3dff
+    slapi_rwlock_wrlock(retrocl_cn_lock);
cc3dff
     if ( retrocl_first_cn == 0) {
cc3dff
         retrocl_first_cn = retrocl_internal_cn;
cc3dff
     }
cc3dff
+    slapi_rwlock_unlock(retrocl_cn_lock);
cc3dff
 }
cc3dff
 
cc3dff
 /*
cc3dff
@@ -333,8 +342,10 @@ void retrocl_commit_changenumber(void)
cc3dff
  */
cc3dff
 
cc3dff
 void retrocl_release_changenumber(void) 
cc3dff
-{ 
cc3dff
+{
cc3dff
+    slapi_rwlock_wrlock(retrocl_cn_lock);
cc3dff
     retrocl_internal_cn--;
cc3dff
+    slapi_rwlock_unlock(retrocl_cn_lock);
cc3dff
 }
cc3dff
 
cc3dff
 /*
cc3dff
@@ -342,7 +353,7 @@ void retrocl_release_changenumber(void)
cc3dff
  *
cc3dff
  * Returns: 0/-1
cc3dff
  *
cc3dff
- * Arguments: none
cc3dff
+ * Arguments: none.  The caller should have taken write lock for the change numbers
cc3dff
  *
cc3dff
  * Description: reads the last entry in the changelog to obtain
cc3dff
  * the last change number.
cc3dff
@@ -355,6 +366,7 @@ int retrocl_update_lastchangenumber(void)
cc3dff
 
cc3dff
     if (retrocl_be_changelog == NULL) return -1;
cc3dff
 
cc3dff
+    slapi_rwlock_unlock(retrocl_cn_lock);
cc3dff
     cr.cr_cnum = 0;
cc3dff
     cr.cr_time = 0;
cc3dff
     slapi_seq_callback(RETROCL_CHANGELOG_DN,SLAPI_SEQ_LAST,
cc3dff
@@ -362,7 +374,7 @@ int retrocl_update_lastchangenumber(void)
cc3dff
                NULL,NULL,0,&cr,NULL,handle_cnum_result,
cc3dff
                handle_cnum_entry, NULL);
cc3dff
 
cc3dff
-
cc3dff
+    slapi_rwlock_wrlock(retrocl_cn_lock);
cc3dff
     retrocl_internal_cn = cr.cr_cnum;
cc3dff
     slapi_log_error(SLAPI_LOG_PLUGIN,"retrocl","Refetched last changenumber =  %lu \n",
cc3dff
             retrocl_internal_cn);
cc3dff
@@ -394,6 +406,8 @@ changeNumber retrocl_assign_changenumber(void)
cc3dff
      * validity of the internal assignment of retrocl_internal_cn 
cc3dff
      * we had from the startup */  
cc3dff
 
cc3dff
+    slapi_rwlock_wrlock(retrocl_cn_lock);
cc3dff
+
cc3dff
     if(retrocl_internal_cn <= retrocl_first_cn){ 
cc3dff
         /* the numbers have become out of sync - retrocl_get_changenumbers
cc3dff
          * gets called only once during startup and it may have had a problem 
cc3dff
@@ -404,8 +418,10 @@ changeNumber retrocl_assign_changenumber(void)
cc3dff
          */                                                         
cc3dff
         retrocl_update_lastchangenumber();                                   
cc3dff
     }                             
cc3dff
-
cc3dff
     retrocl_internal_cn++;
cc3dff
     cn = retrocl_internal_cn;
cc3dff
+
cc3dff
+    slapi_rwlock_unlock(retrocl_cn_lock);
cc3dff
+
cc3dff
     return cn;
cc3dff
 }
cc3dff
diff --git a/ldap/servers/plugins/retrocl/retrocl_po.c b/ldap/servers/plugins/retrocl/retrocl_po.c
cc3dff
index 382c98a..cd290f2 100644
cc3dff
--- a/ldap/servers/plugins/retrocl/retrocl_po.c
cc3dff
+++ b/ldap/servers/plugins/retrocl/retrocl_po.c
cc3dff
@@ -372,7 +372,7 @@ write_replog_db(
cc3dff
 	    retrocl_release_changenumber();
cc3dff
 	} else {
cc3dff
 	/* Tell the change numbering system this one's committed to disk  */
cc3dff
-	    retrocl_commit_changenumber( );
cc3dff
+	    retrocl_commit_changenumber();
cc3dff
 	}
cc3dff
     } else {
cc3dff
 	slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, 
cc3dff
-- 
cc3dff
1.8.1.4
cc3dff