andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

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

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