zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone

Blame SOURCES/0084-Ticket-48118-backport-changelog-can-be-erronously-re.patch

61f723
From b0d593b001d4ef1fb19348335fb39bd45b31764c Mon Sep 17 00:00:00 2001
61f723
From: Ludwig Krispenz <lkrispen@redhat.com>
61f723
Date: Fri, 8 Dec 2017 14:26:06 +0100
61f723
Subject: [PATCH] Ticket 48118 - backport - changelog can be erronously rebuilt
61f723
 at startup
61f723
61f723
---
61f723
 ldap/servers/plugins/replication/cl5_api.c         | 39 ++++++++++++++++++++++
61f723
 ldap/servers/plugins/replication/repl5.h           |  1 -
61f723
 ldap/servers/plugins/replication/repl5_replica.c   | 39 ++--------------------
61f723
 .../plugins/replication/repl5_replica_config.c     |  2 --
61f723
 4 files changed, 41 insertions(+), 40 deletions(-)
61f723
61f723
diff --git a/ldap/servers/plugins/replication/cl5_api.c b/ldap/servers/plugins/replication/cl5_api.c
61f723
index 5c2233f82..1ce8d081f 100644
61f723
--- a/ldap/servers/plugins/replication/cl5_api.c
61f723
+++ b/ldap/servers/plugins/replication/cl5_api.c
61f723
@@ -304,6 +304,8 @@ static void _cl5ReadBerval (struct berval *bv, char** buff);
61f723
 static void _cl5WriteBerval (struct berval *bv, char** buff);
61f723
 static int _cl5ReadBervals (struct berval ***bv, char** buff, unsigned int size);
61f723
 static int _cl5WriteBervals (struct berval **bv, char** buff, u_int32_t *size);
61f723
+static int32_t _cl5CheckMaxRUV(CL5DBFile *file, RUV *maxruv);
61f723
+static int32_t _cl5CheckCSNinCL(const ruv_enum_data *element, void *arg);
61f723
 
61f723
 /* replay iteration */
61f723
 #ifdef FOR_DEBUGGING
61f723
@@ -2885,6 +2887,36 @@ static int _cl5WriteBervals (struct berval **bv, char** buff, u_int32_t *size)
61f723
     return CL5_SUCCESS;
61f723
 }
61f723
 
61f723
+static int32_t
61f723
+_cl5CheckCSNinCL(const ruv_enum_data *element, void *arg)
61f723
+{
61f723
+    CL5DBFile *file = (CL5DBFile *)arg;
61f723
+    int rc = 0;
61f723
+
61f723
+    DBT key = {0}, data = {0};
61f723
+    char csnStr[CSN_STRSIZE];
61f723
+
61f723
+    /* construct the key */
61f723
+    key.data = csn_as_string(element->csn, PR_FALSE, csnStr);
61f723
+    key.size = CSN_STRSIZE;
61f723
+
61f723
+    data.flags = DB_DBT_MALLOC;
61f723
+
61f723
+    rc = file->db->get(file->db, NULL /*txn*/, &key, &data, 0);
61f723
+
61f723
+    slapi_ch_free(&(data.data));
61f723
+    return rc;
61f723
+}
61f723
+
61f723
+static int32_t
61f723
+_cl5CheckMaxRUV(CL5DBFile *file, RUV *maxruv)
61f723
+{
61f723
+    int rc = 0;
61f723
+
61f723
+    rc = ruv_enumerate_elements(maxruv, _cl5CheckCSNinCL, (void *)file);
61f723
+
61f723
+    return rc;
61f723
+}
61f723
 /* upgrade from db33 to db41
61f723
  * 1. Run recovery on the database environment using the DB_ENV->open method
61f723
  * 2. Remove any Berkeley DB environment using the DB_ENV->remove method 
61f723
@@ -4248,6 +4280,13 @@ static int _cl5WriteRUV (CL5DBFile *file, PRBool purge)
61f723
 		rc = ruv_to_bervals(file->maxRUV, &vals);
61f723
 	}
61f723
 
61f723
+	if (!purge && _cl5CheckMaxRUV(file, file->maxRUV)) {
61f723
+		slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
61f723
+				"_cl5WriteRUV - changelog maxRUV not found in changelog for file %s\n",
61f723
+				file->name);
61f723
+		return CL5_DB_ERROR;
61f723
+	}
61f723
+
61f723
 	key.size = CSN_STRSIZE;
61f723
     
61f723
 	rc = _cl5WriteBervals (vals, &buff, &data.size);
61f723
diff --git a/ldap/servers/plugins/replication/repl5.h b/ldap/servers/plugins/replication/repl5.h
61f723
index 718f64ef1..9c4789f9e 100644
61f723
--- a/ldap/servers/plugins/replication/repl5.h
61f723
+++ b/ldap/servers/plugins/replication/repl5.h
61f723
@@ -620,7 +620,6 @@ Object *replica_get_for_backend (const char *be_name);
61f723
 void replica_set_purge_delay (Replica *r, PRUint32 purge_delay);
61f723
 void replica_set_tombstone_reap_interval (Replica *r, long interval);
61f723
 void replica_update_ruv_consumer (Replica *r, RUV *supplier_ruv);
61f723
-void replica_set_ruv_dirty (Replica *r);
61f723
 Slapi_Entry *get_in_memory_ruv(Slapi_DN *suffix_sdn);
61f723
 int replica_write_ruv (Replica *r);
61f723
 char *replica_get_dn(Replica *r);
61f723
diff --git a/ldap/servers/plugins/replication/repl5_replica.c b/ldap/servers/plugins/replication/repl5_replica.c
61f723
index 7927ac30a..3c7281a42 100644
61f723
--- a/ldap/servers/plugins/replication/repl5_replica.c
61f723
+++ b/ldap/servers/plugins/replication/repl5_replica.c
61f723
@@ -46,7 +46,6 @@ struct replica {
61f723
 	char*   legacy_purl;            /* partial url of the legacy supplier   */
61f723
 	ReplicaId repl_rid;				/* replicaID							*/
61f723
 	Object	*repl_ruv;				/* replica update vector				*/
61f723
-	PRBool repl_ruv_dirty;          /* Dirty flag for ruv                   */
61f723
 	CSNPL *min_csn_pl;              /* Pending list for minimal CSN         */
61f723
 	void *csn_pl_reg_id;            /* registration assignment for csn callbacks */
61f723
 	unsigned long repl_state_flags;	/* state flags							*/
61f723
@@ -855,7 +854,6 @@ replica_set_ruv (Replica *r, RUV *ruv)
61f723
     }
61f723
 
61f723
 	r->repl_ruv = object_new((void*)ruv, (FNFree)ruv_destroy);
61f723
-	r->repl_ruv_dirty = PR_TRUE;
61f723
 
61f723
 	replica_unlock(r->repl_lock);
61f723
 }
61f723
@@ -941,11 +939,6 @@ replica_update_ruv(Replica *r, const CSN *updated_csn, const char *replica_purl)
61f723
 						slapi_sdn_get_dn(r->repl_root),
61f723
 						csn_as_string(updated_csn, PR_FALSE, csn_str));
61f723
 				}
61f723
-				else
61f723
-				{
61f723
-					/* RUV updated - mark as dirty */
61f723
-					r->repl_ruv_dirty = PR_TRUE;
61f723
-				}
61f723
 			}
61f723
 			else
61f723
 			{
61f723
@@ -1526,8 +1519,6 @@ replica_dump(Replica *r)
61f723
     slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "\tupdate dn: %s\n",
61f723
             updatedn_list? updatedn_list : "not configured");
61f723
     slapi_ch_free_string(&updatedn_list);
61f723
-    slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "\truv: %s configured and is %sdirty\n",
61f723
-                    r->repl_ruv ? "" : "not", r->repl_ruv_dirty ? "" : "not ");
61f723
     slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "\tCSN generator: %s configured\n",
61f723
                     r->repl_csngen ? "" : "not");
61f723
 	/* JCMREPL - Dump Referrals */
61f723
@@ -1877,7 +1868,6 @@ int replica_check_for_data_reload (Replica *r, void *arg)
61f723
 
61f723
                     ruv_force_csn_update_from_ruv(upper_bound_ruv, r_ruv, 
61f723
                             "Force update of database RUV (from CL RUV) -> ", SLAPI_LOG_NOTICE);
61f723
-                    replica_set_ruv_dirty(r);
61f723
                 }
61f723
                 
61f723
             } else {
61f723
@@ -2994,12 +2984,6 @@ replica_write_ruv (Replica *r)
61f723
 
61f723
 	replica_lock(r->repl_lock);
61f723
 
61f723
-	if (!r->repl_ruv_dirty)
61f723
-	{
61f723
-		replica_unlock(r->repl_lock);
61f723
-		return rc;
61f723
-	}
61f723
-
61f723
 	PR_ASSERT (r->repl_ruv);
61f723
 	
61f723
 	ruv_to_smod ((RUV*)object_get_data(r->repl_ruv), &smod);
61f723
@@ -3034,19 +3018,13 @@ replica_write_ruv (Replica *r)
61f723
     /* ruv does not exist - create one */
61f723
     replica_lock(r->repl_lock);
61f723
 
61f723
-    if (rc == LDAP_SUCCESS)
61f723
-    {
61f723
-        r->repl_ruv_dirty = PR_FALSE;
61f723
-    }
61f723
-    else if (rc == LDAP_NO_SUCH_OBJECT)
61f723
+    if (rc == LDAP_NO_SUCH_OBJECT)
61f723
     {
61f723
         /* this includes an internal operation - but since this only happens
61f723
            during server startup - its ok that we have lock around it */
61f723
         rc = _replica_configure_ruv  (r, PR_TRUE);
61f723
-        if (rc == 0)
61f723
-            r->repl_ruv_dirty = PR_FALSE;
61f723
     }
61f723
-	else /* error */
61f723
+	else if (rc != LDAP_SUCCESS) /* error */
61f723
 	{
61f723
 		slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, 
61f723
 			"replica_write_ruv - Failed to update RUV tombstone for %s; "
61f723
@@ -3570,7 +3548,6 @@ replica_create_ruv_tombstone(Replica *r)
61f723
 
61f723
             if (ruv_init_new(csnstr, r->repl_rid, purl, &ruv) == RUV_SUCCESS){
61f723
                 r->repl_ruv = object_new((void*)ruv, (FNFree)ruv_destroy);
61f723
-                r->repl_ruv_dirty = PR_TRUE;
61f723
                 return_value = LDAP_SUCCESS;
61f723
             } else {
61f723
                 slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_create_ruv_tombstone - "
61f723
@@ -3610,8 +3587,6 @@ replica_create_ruv_tombstone(Replica *r)
61f723
     slapi_add_internal_pb(pb);
61f723
     e = NULL; /* add consumes e, upon success or failure */
61f723
     slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &return_value);
61f723
-    if (return_value == LDAP_SUCCESS)
61f723
-        r->repl_ruv_dirty = PR_FALSE;
61f723
 		
61f723
 done:
61f723
     slapi_entry_free (e);
61f723
@@ -3930,7 +3905,6 @@ replica_strip_cleaned_rids(Replica *r)
61f723
     ruv_get_cleaned_rids(ruv, rid);
61f723
     while(rid[i] != 0){
61f723
         ruv_delete_replica(ruv, rid[i]);
61f723
-        replica_set_ruv_dirty(r);
61f723
         if (replica_write_ruv(r)) {
61f723
             slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
61f723
                     "replica_strip_cleaned_rids - Failed to write RUV\n");
61f723
@@ -4052,15 +4026,6 @@ replica_update_ruv_consumer(Replica *r, RUV *supplier_ruv)
61f723
 	}
61f723
 }
61f723
 
61f723
-void 
61f723
-replica_set_ruv_dirty(Replica *r)
61f723
-{
61f723
-	PR_ASSERT(r);
61f723
-	replica_lock(r->repl_lock);
61f723
-	r->repl_ruv_dirty = PR_TRUE;
61f723
-	replica_unlock(r->repl_lock);
61f723
-}
61f723
-
61f723
 PRBool
61f723
 replica_is_state_flag_set(Replica *r, PRInt32 flag)
61f723
 {
61f723
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
61f723
index 814f1cac0..128c9423a 100644
61f723
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
61f723
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
61f723
@@ -1034,7 +1034,6 @@ replica_config_change_type_and_id (Replica *r, const char *new_type,
61f723
                     replica_reset_csn_pl(r);
61f723
                 }
61f723
                 ruv_delete_replica(ruv, oldrid);
61f723
-                replica_set_ruv_dirty(r);
61f723
                 cl5CleanRUV(oldrid);
61f723
                 replica_set_csn_assigned(r);
61f723
             }
61f723
@@ -1454,7 +1453,6 @@ replica_execute_cleanruv_task (Object *r, ReplicaId rid, char *returntext /* not
61f723
 		return LDAP_UNWILLING_TO_PERFORM;
61f723
 	}
61f723
 	rc = ruv_delete_replica(local_ruv, rid);
61f723
-	replica_set_ruv_dirty(replica);
61f723
 	if (replica_write_ruv(replica)) {
61f723
 		slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "cleanAllRUV_task - Could not write RUV\n");
61f723
 	}
61f723
-- 
61f723
2.13.6
61f723