Blame SOURCES/0054-Ticket-47587-hard-coded-limit-of-64-masters-in-agree.patch

cc3dff
From 690fd89fb94621a4cafee1e4064d7e42ceaae6db Mon Sep 17 00:00:00 2001
cc3dff
From: Mark Reynolds <mreynolds@redhat.com>
cc3dff
Date: Thu, 5 Dec 2013 11:58:56 -0500
cc3dff
Subject: [PATCH 54/65] Ticket 47587 - hard coded limit of 64 masters in
cc3dff
 agreement and changelog code
cc3dff
cc3dff
Bug Description:  Need to remove hardcoded limit of 64 masters.
cc3dff
cc3dff
Fix Description:  Changed the default limit to 256, and then we resize the array
cc3dff
                  as needed.
cc3dff
cc3dff
https://fedorahosted.org/389/ticket/47587
cc3dff
cc3dff
Reviewed by: richm & tbordaz(Thanks!!)
cc3dff
(cherry picked from commit bae797c94207d15025e763cfea0634f42eeb1210)
cc3dff
(cherry picked from commit 457cd16908071f3faddb021c12c792d22f64ab5c)
cc3dff
---
cc3dff
 ldap/servers/plugins/replication/cl5_clcache.c | 22 +++++++++++++++++-----
cc3dff
 ldap/servers/plugins/replication/repl5.h       |  4 ++--
cc3dff
 ldap/servers/plugins/replication/repl5_agmt.c  | 18 ++++++++++++++----
cc3dff
 3 files changed, 33 insertions(+), 11 deletions(-)
cc3dff
cc3dff
diff --git a/ldap/servers/plugins/replication/cl5_clcache.c b/ldap/servers/plugins/replication/cl5_clcache.c
cc3dff
index 8218312..d86620f 100644
cc3dff
--- a/ldap/servers/plugins/replication/cl5_clcache.c
cc3dff
+++ b/ldap/servers/plugins/replication/cl5_clcache.c
cc3dff
@@ -113,8 +113,9 @@ struct clc_buffer {
cc3dff
 	CSN			*buf_missing_csn;	/* used to detect persistent missing of CSN */
cc3dff
 
cc3dff
 	/* fields for control the CSN sequence sent to the consumer */
cc3dff
-	struct csn_seq_ctrl_block *buf_cscbs [MAX_NUM_OF_MASTERS];
cc3dff
+	struct csn_seq_ctrl_block **buf_cscbs;
cc3dff
 	int			 buf_num_cscbs;		/* number of csn sequence ctrl blocks */
cc3dff
+	int			 buf_max_cscbs;
cc3dff
 
cc3dff
 	/* fields for debugging stat */
cc3dff
 	int		 	 buf_load_cnt;		/* number of loads for session */
cc3dff
@@ -256,12 +257,15 @@ clcache_get_buffer ( CLC_Buffer **buf, DB *db, ReplicaId consumer_rid, const RUV
cc3dff
 		(*buf)->buf_record_cnt = 0;
cc3dff
 		(*buf)->buf_record_skipped = 0;
cc3dff
 		(*buf)->buf_cursor = NULL;
cc3dff
-		(*buf)->buf_num_cscbs = 0;
cc3dff
 		(*buf)->buf_skipped_new_rid = 0;
cc3dff
 		(*buf)->buf_skipped_csn_gt_cons_maxcsn = 0;
cc3dff
 		(*buf)->buf_skipped_up_to_date = 0;
cc3dff
 		(*buf)->buf_skipped_csn_gt_ruv = 0;
cc3dff
 		(*buf)->buf_skipped_csn_covered = 0;
cc3dff
+		(*buf)->buf_cscbs  = (struct csn_seq_ctrl_block **) slapi_ch_calloc(MAX_NUM_OF_MASTERS + 1,
cc3dff
+			                 sizeof(struct csn_seq_ctrl_block *));
cc3dff
+		(*buf)->buf_num_cscbs = 0;
cc3dff
+		(*buf)->buf_max_cscbs = MAX_NUM_OF_MASTERS;
cc3dff
 	}
cc3dff
 	else {
cc3dff
 		*buf = clcache_new_buffer ( consumer_rid );
cc3dff
@@ -311,7 +315,7 @@ clcache_return_buffer ( CLC_Buffer **buf )
cc3dff
 	for ( i = 0; i < (*buf)->buf_num_cscbs; i++ ) {
cc3dff
 		clcache_free_cscb ( &(*buf)->buf_cscbs[i] );
cc3dff
 	}
cc3dff
-	(*buf)->buf_num_cscbs = 0;
cc3dff
+	slapi_ch_free((void **)&(*buf)->buf_cscbs);
cc3dff
 
cc3dff
 	if ( (*buf)->buf_cursor ) {
cc3dff
 
cc3dff
@@ -554,7 +558,7 @@ clcache_refresh_consumer_maxcsns ( CLC_Buffer *buf )
cc3dff
 static int
cc3dff
 clcache_refresh_local_maxcsn ( const ruv_enum_data *rid_data, void *data )
cc3dff
 {
cc3dff
-	CLC_Buffer *buf = (CLC_Buffer*) data;
cc3dff
+	struct clc_buffer *buf = (struct clc_buffer*) data;
cc3dff
 	ReplicaId rid;
cc3dff
 	int rc = 0;
cc3dff
 	int i;
cc3dff
@@ -575,7 +579,12 @@ clcache_refresh_local_maxcsn ( const ruv_enum_data *rid_data, void *data )
cc3dff
 			break;
cc3dff
 	}
cc3dff
 	if ( i >= buf->buf_num_cscbs ) {
cc3dff
-		buf->buf_cscbs[i] = clcache_new_cscb ();
cc3dff
+		if( i + 1 > buf->buf_max_cscbs){
cc3dff
+			buf->buf_cscbs = (struct csn_seq_ctrl_block **) slapi_ch_realloc((char *)buf->buf_cscbs,
cc3dff
+							 (i + 2) * sizeof(struct csn_seq_ctrl_block *));
cc3dff
+			buf->buf_max_cscbs = i + 1;
cc3dff
+		}
cc3dff
+		buf->buf_cscbs[i] = clcache_new_cscb();
cc3dff
 		if ( buf->buf_cscbs[i] == NULL ) {
cc3dff
 			return -1;
cc3dff
 		}
cc3dff
@@ -878,6 +887,9 @@ clcache_new_buffer ( ReplicaId consumer_rid )
cc3dff
 		buf->buf_agmt_name = get_thread_private_agmtname();
cc3dff
 		buf->buf_consumer_rid = consumer_rid;
cc3dff
 		buf->buf_num_cscbs = 0;
cc3dff
+		buf->buf_max_cscbs = MAX_NUM_OF_MASTERS;
cc3dff
+		buf->buf_cscbs  = (struct csn_seq_ctrl_block **) slapi_ch_calloc(MAX_NUM_OF_MASTERS + 1,
cc3dff
+					sizeof(struct csn_seq_ctrl_block *));
cc3dff
 
cc3dff
 		welldone = 1;
cc3dff
 
cc3dff
diff --git a/ldap/servers/plugins/replication/repl5.h b/ldap/servers/plugins/replication/repl5.h
cc3dff
index 5bec1c7..92a9229 100644
cc3dff
--- a/ldap/servers/plugins/replication/repl5.h
cc3dff
+++ b/ldap/servers/plugins/replication/repl5.h
cc3dff
@@ -140,11 +140,11 @@
cc3dff
 
cc3dff
 #define DEFAULT_PROTOCOL_TIMEOUT 120
cc3dff
 
cc3dff
-/* To Allow Consumer Initialisation when adding an agreement - */
cc3dff
+/* To Allow Consumer Initialization when adding an agreement - */
cc3dff
 #define STATE_PERFORMING_TOTAL_UPDATE 501
cc3dff
 #define STATE_PERFORMING_INCREMENTAL_UPDATE 502
cc3dff
 
cc3dff
-#define MAX_NUM_OF_MASTERS		64
cc3dff
+#define MAX_NUM_OF_MASTERS		256
cc3dff
 #define REPL_SESSION_ID_SIZE	64
cc3dff
 
cc3dff
 #define REPL_GET_DN(addrp) slapi_sdn_get_dn((addrp)->sdn)
cc3dff
diff --git a/ldap/servers/plugins/replication/repl5_agmt.c b/ldap/servers/plugins/replication/repl5_agmt.c
cc3dff
index b7d107e..90d94f8 100644
cc3dff
--- a/ldap/servers/plugins/replication/repl5_agmt.c
cc3dff
+++ b/ldap/servers/plugins/replication/repl5_agmt.c
cc3dff
@@ -111,8 +111,9 @@ typedef struct repl5agmt {
cc3dff
 	const Slapi_RDN *rdn; /* RDN of replication agreement entry */
cc3dff
 	char *long_name; /* Long name (rdn + host, port) of entry, for logging */
cc3dff
 	Repl_Protocol *protocol; /* Protocol object - manages protocol */
cc3dff
-	struct changecounter *changecounters[MAX_NUM_OF_MASTERS]; /* changes sent/skipped since server start up */
cc3dff
+	struct changecounter **changecounters; /* changes sent/skipped since server start up */
cc3dff
 	int num_changecounters;
cc3dff
+	int max_changecounters;
cc3dff
 	time_t last_update_start_time; /* Local start time of last update session */
cc3dff
 	time_t last_update_end_time; /* Local end time of last update session */
cc3dff
 	char last_update_status[STATUS_LEN]; /* Status of last update. Format = numeric code <space> textual description */
cc3dff
@@ -435,14 +436,17 @@ agmt_new_from_entry(Slapi_Entry *e)
cc3dff
 	/* Initialize status information */
cc3dff
 	ra->last_update_start_time = 0UL;
cc3dff
 	ra->last_update_end_time = 0UL;
cc3dff
-	ra->num_changecounters = 0;
cc3dff
 	ra->last_update_status[0] = '\0';
cc3dff
 	ra->update_in_progress = PR_FALSE;
cc3dff
 	ra->stop_in_progress = PR_FALSE;
cc3dff
 	ra->last_init_end_time = 0UL;
cc3dff
 	ra->last_init_start_time = 0UL;
cc3dff
 	ra->last_init_status[0] = '\0';
cc3dff
-	
cc3dff
+	ra->changecounters = (struct changecounter**) slapi_ch_calloc(MAX_NUM_OF_MASTERS + 1,
cc3dff
+	                     sizeof(struct changecounter *));
cc3dff
+	ra->num_changecounters = 0;
cc3dff
+	ra->max_changecounters = MAX_NUM_OF_MASTERS;
cc3dff
+
cc3dff
 	/* Fractional attributes */
cc3dff
 	slapi_entry_attr_find(e, type_nsds5ReplicatedAttributeList, &sattr);
cc3dff
 
cc3dff
@@ -599,6 +603,7 @@ agmt_delete(void **rap)
cc3dff
 	{
cc3dff
 	    slapi_ch_free((void **)&ra->changecounters[ra->num_changecounters]);
cc3dff
 	}
cc3dff
+	slapi_ch_free((void **)&ra->changecounters);
cc3dff
 
cc3dff
 	if (ra->agreement_type == REPLICA_TYPE_WINDOWS)
cc3dff
 	{
cc3dff
@@ -2305,7 +2310,12 @@ agmt_inc_last_update_changecount (Repl_Agmt *ra, ReplicaId rid, int skipped)
cc3dff
 		}
cc3dff
 		else
cc3dff
 		{
cc3dff
-			ra->num_changecounters ++;
cc3dff
+			ra->num_changecounters++;
cc3dff
+			if(ra->num_changecounters > ra->max_changecounters){
cc3dff
+				ra->changecounters = (struct changecounter**) slapi_ch_realloc((char *)ra->changecounters,
cc3dff
+				                     (ra->num_changecounters + 1) * sizeof(struct changecounter*));
cc3dff
+				ra->max_changecounters = ra->num_changecounters;
cc3dff
+			}
cc3dff
 			ra->changecounters[i] = (struct changecounter*) slapi_ch_calloc(1, sizeof(struct changecounter));
cc3dff
 			ra->changecounters[i]->rid = rid;
cc3dff
 			if ( skipped )
cc3dff
-- 
cc3dff
1.8.1.4
cc3dff