replmd: Only modify the object if it actually changed
authorTim Beale <timbeale@catalyst.net.nz>
Sun, 11 Nov 2018 22:00:52 +0000 (11:00 +1300)
committerTim Beale <timbeale@samba.org>
Wed, 21 Nov 2018 00:51:11 +0000 (01:51 +0100)
Commit 775054afbe1512 reworked replmd_process_link_attribute() so that
we batch together DB operations for the same source object. However, it
was possible that the object had not actually changed at all, e.g.
- link was already processed by critical-objects-only during join, or
- we were doing a full-sync and processing info that was already
  up-to-date in our DB.

In these cases we modified the object anyway, even though nothing had
changed. This patch fixes it up, so we check that the object has
actually changed before modifying the DB.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/samdb/ldb_modules/repl_meta_data.c

index cd6e1cc0fd3b94ffc455d55f09741b66730e0390..b97c9db355fada37074cd9ee9243e56d61a09e7e 100644 (file)
@@ -8228,6 +8228,7 @@ static int replmd_process_la_group(struct ldb_module *module,
        struct ldb_context *ldb = ldb_module_get_ctx(module);
        const struct dsdb_attribute *attr = NULL;
        replmd_link_changed change_type;
+       uint32_t num_changes = 0;
 
        /*
         * get the attribute being modified and the search result for the
@@ -8287,6 +8288,10 @@ static int replmd_process_la_group(struct ldb_module *module,
                        return ret;
                }
 
+               if (change_type != LINK_CHANGE_NONE) {
+                       num_changes++;
+               }
+
                if ((++replmd_private->num_processed % 8192) == 0) {
                        DBG_NOTICE("Processed %u/%u linked attributes\n",
                                   replmd_private->num_processed,
@@ -8294,6 +8299,15 @@ static int replmd_process_la_group(struct ldb_module *module,
                }
        }
 
+       /*
+        * it's possible we're already up-to-date and so don't need to modify
+        * the object at all (e.g. doing a 'drs replicate --full-sync')
+        */
+       if (num_changes == 0) {
+               TALLOC_FREE(tmp_ctx);
+               return LDB_SUCCESS;
+       }
+
        /* apply the link changes to the source object */
        ret = linked_attr_modify(module, msg, NULL);
        if (ret != LDB_SUCCESS) {