diff --git a/CHANGES b/CHANGES
index 0914d6e62e0fb3b45991848b714b11239e30d8be..26d5228a74e5ff05f0bd1e15aa77b9c15f726a1c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,7 @@ OpenLDAP 2.4.10 Engineering
 	Fixed slapd multiple attrs in URI (ITS#5516)
 	Fixed slapd sasl_ssf retrieval (ITS#5403)
 	Fixed slapd socket assert (ITS#5489)
+	Fixed slapd syncrepl cookie (ITS#5536)
 	Fixed slapd-bdb/hdb MAXPATHLEN (ITS#5531)
 	Fixed slapd-bdb indexing in single ADD/MOD (ITS#5521)
 	Fixed slapd-ldap entry_get() op-dependent behavior (ITS#5513)
diff --git a/doc/man/man5/slapd-config.5 b/doc/man/man5/slapd-config.5
index 6c080725ce97f10c9d3ef8539a17814dcd016339..47a4af8f103889033cecbd3be89c4d527cddcaac 100644
--- a/doc/man/man5/slapd-config.5
+++ b/doc/man/man5/slapd-config.5
@@ -720,7 +720,9 @@ size allowed.  0 disables security layers.  The default is 65536.
 .B olcServerID: <integer> [<URL>]
 Specify an integer ID from 0 to 4095 for this server. These IDs are
 required when using multimaster replication and each master must have a
-unique ID. If the URL is provided, this directive may be specified
+unique ID. Note that this requirement also applies to separate masters
+contributing to a glued set of databases.
+If the URL is provided, this directive may be specified
 multiple times, providing a complete list of participating servers
 and their IDs. The fully qualified hostname of each server should be
 used in the supplied URLs. The IDs are used in the "replica id" field
diff --git a/doc/man/man5/slapd.conf.5 b/doc/man/man5/slapd.conf.5
index 18fa6b01f234b1bd0459993ce62a4f4a8365d468..9267801bbd6943f39456f24bd1752e1254774c82 100644
--- a/doc/man/man5/slapd.conf.5
+++ b/doc/man/man5/slapd.conf.5
@@ -871,7 +871,9 @@ Specify an integer ID from 0 to 4095 for this server (limited
 to 3 hexadecimal digits).
 These IDs are
 required when using multimaster replication and each master must have a
-unique ID. If the URL is provided, this directive may be specified
+unique ID. Note that this requirement also applies to separate masters
+contributing to a glued set of databases.
+If the URL is provided, this directive may be specified
 multiple times, providing a complete list of participating servers
 and their IDs. The fully qualified hostname of each server should be
 used in the supplied URLs. The IDs are used in the "replica id" field
diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c
index 0428dfb3ba4b6121a849af12c2145ede0547e3da..747435d8b1e5609264ca8579fb66c475283c8005 100644
--- a/servers/slapd/syncrepl.c
+++ b/servers/slapd/syncrepl.c
@@ -580,8 +580,10 @@ do_syncrep1(
 	ldap_set_option( si->si_ld, LDAP_OPT_TIMELIMIT, &si->si_tlimit );
 
 	si->si_syncCookie.rid = si->si_rid;
-	si->si_syncCookie.sid = SLAP_SINGLE_SHADOW( si->si_be ) ? -1 :
-		slap_serverID;
+
+	/* whenever there are multiple data sources possible, advertise sid */
+	si->si_syncCookie.sid = ( SLAP_MULTIMASTER( si->si_be ) || si->si_be != si->si_wbe ) ?
+		slap_serverID : -1;
 
 	/* We've just started up, or the remote server hasn't sent us
 	 * any meaningful state.
@@ -1240,7 +1242,8 @@ do_syncrepl(
 	 *
 	 * Typically there is a single syncprov mastering the entire
 	 * glued tree. In that case, our contextCSN updates should
-	 * go to the master DB.
+	 * go to the master DB. But if there is no syncprov on the
+	 * master DB, then nothing special is needed here.
 	 *
 	 * Alternatively, there may be individual syncprov overlays
 	 * on each glued branch. In that case, each syncprov only
@@ -1249,7 +1252,11 @@ do_syncrepl(
 	 */
 	if ( !si->si_wbe ) {
 		if ( SLAP_GLUE_SUBORDINATE( be ) && !overlay_is_inst( be, "syncprov" )) {
-			si->si_wbe = select_backend( &be->be_nsuffix[0], 1 );
+			BackendDB * top_be = select_backend( &be->be_nsuffix[0], 1 );
+			if ( overlay_is_inst( top_be, "syncprov" ))
+				si->si_wbe = select_backend( &be->be_nsuffix[0], 1 );
+			else
+				si->si_wbe = be;
 		} else {
 			si->si_wbe = be;
 		}