From 6eefa588bee4e2a342fb2d625b992f9940997dd5 Mon Sep 17 00:00:00 2001 From: Ludwig Krispenz Date: Mon, 6 Nov 2017 11:04:07 +0100 Subject: [PATCH] Ticket 48118 - part2 - write changelog maxruv only if maxcsn is in database --- ldap/servers/plugins/replication/cl5_api.c | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/ldap/servers/plugins/replication/cl5_api.c b/ldap/servers/plugins/replication/cl5_api.c index ec648c0..68ed39e 100644 --- a/ldap/servers/plugins/replication/cl5_api.c +++ b/ldap/servers/plugins/replication/cl5_api.c @@ -250,6 +250,7 @@ static void _cl5ReadBerval(struct berval *bv, char **buff); static void _cl5WriteBerval(struct berval *bv, char **buff); static int _cl5ReadBervals(struct berval ***bv, char **buff, unsigned int size); static int _cl5WriteBervals(struct berval **bv, char **buff, u_int32_t *size); +static int _cl5CheckMaxRUV(CL5DBFile *file, RUV *maxruv); /* replay iteration */ #ifdef FOR_DEBUGGING @@ -2716,6 +2717,36 @@ _cl5WriteBervals(struct berval **bv, char **buff, u_int32_t *size) return CL5_SUCCESS; } +static int +_cl5CheckCSNinCL(const ruv_enum_data *element, void *arg) +{ + CL5DBFile *file = (CL5DBFile *)arg; + int rc = 0; + + DBT key = {0}, data = {0}; + char csnStr[CSN_STRSIZE]; + + /* construct the key */ + key.data = csn_as_string(element->csn, PR_FALSE, csnStr); + key.size = CSN_STRSIZE; + + data.flags = DB_DBT_MALLOC; + + rc = file->db->get(file->db, NULL /*txn*/, &key, &data, 0); + + slapi_ch_free(&(data.data)); + return rc; +} + +static int +_cl5CheckMaxRUV(CL5DBFile *file, RUV *maxruv) +{ + int rc = 0; + + rc = ruv_enumerate_elements(maxruv, _cl5CheckCSNinCL, (void *)file); + + return rc; +} /* upgrade from db33 to db41 * 1. Run recovery on the database environment using the DB_ENV->open method * 2. Remove any Berkeley DB environment using the DB_ENV->remove method @@ -4010,6 +4041,13 @@ _cl5WriteRUV(CL5DBFile *file, PRBool purge) rc = ruv_to_bervals(file->maxRUV, &vals); } + if (!purge && _cl5CheckMaxRUV(file, file->maxRUV)) { + slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, + "_cl5WriteRUV - changelog maxRUV not found in changelog for file %s\n", + file->name); + return CL5_DB_ERROR; + } + key.size = CSN_STRSIZE; rc = _cl5WriteBervals(vals, &buff, &data.size); -- 2.5.5