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

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