dsdb: Remove use of schema USN in samldb_add_handle_msDS_IntId
authorAndrew Bartlett <abartlet@samba.org>
Tue, 5 Jul 2016 23:38:28 +0000 (11:38 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 6 Jul 2016 13:35:17 +0000 (15:35 +0200)
This is not a frequent enough operation to warrent a cache, and the USN will be removed
from the schema code shortly

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/dsdb/samdb/ldb_modules/repl_meta_data.c
source4/dsdb/samdb/ldb_modules/samldb.c
source4/dsdb/samdb/samdb.h

index b551e34e1e37fee8866e1e1ee2f18e3fd971fd61..0c94b2aa6b8ac739dc14e75789b828a109d1cb3a 100644 (file)
@@ -832,7 +832,6 @@ static int replmd_add_fix_la(struct ldb_module *module, struct ldb_message_eleme
  */
 static int replmd_add(struct ldb_module *module, struct ldb_request *req)
 {
-       struct samldb_msds_intid_persistant *msds_intid_struct;
        struct ldb_context *ldb;
         struct ldb_control *control;
        struct replmd_replicated_request *ac;
@@ -1149,14 +1148,6 @@ static int replmd_add(struct ldb_module *module, struct ldb_request *req)
        if (control) {
                control->critical = 0;
        }
-       if (ldb_dn_compare_base(replmd_private->schema_dn, req->op.add.message->dn) != 0) {
-
-               /* Update the usn in the SAMLDB_MSDS_INTID_OPAQUE opaque */
-               msds_intid_struct = (struct samldb_msds_intid_persistant *) ldb_get_opaque(ldb, SAMLDB_MSDS_INTID_OPAQUE);
-               if (msds_intid_struct) {
-                       msds_intid_struct->usn = ac->seq_num;
-               }
-       }
        /* go on with the call chain */
        return ldb_next_request(module, down_req);
 }
@@ -2519,7 +2510,6 @@ static int replmd_modify_handle_linked_attribs(struct ldb_module *module,
 
 static int replmd_modify(struct ldb_module *module, struct ldb_request *req)
 {
-       struct samldb_msds_intid_persistant *msds_intid_struct;
        struct ldb_context *ldb;
        struct replmd_replicated_request *ac;
        struct ldb_request *down_req;
@@ -2674,14 +2664,6 @@ static int replmd_modify(struct ldb_module *module, struct ldb_request *req)
                }
        }
 
-       if (!ldb_dn_compare_base(replmd_private->schema_dn, msg->dn)) {
-               /* Update the usn in the SAMLDB_MSDS_INTID_OPAQUE opaque */
-               msds_intid_struct = (struct samldb_msds_intid_persistant *) ldb_get_opaque(ldb, SAMLDB_MSDS_INTID_OPAQUE);
-               if (msds_intid_struct) {
-                       msds_intid_struct->usn = ac->seq_num;
-               }
-       }
-
        /* go on with the call chain */
        return ldb_next_request(module, down_req);
 }
index 811262427fa8c068c328c73b1bf6eea5d768d6c4..cc101a6ea4d7bd7bd1c3c211be5ccd25bd12ca06 100644 (file)
@@ -576,7 +576,6 @@ static int samldb_add_handle_msDS_IntId(struct samldb_ctx *ac)
                msds_intid = generate_random() % 0X3FFFFFFF;
                msds_intid += 0x80000000;
                msds_intid_struct->msds_intid = msds_intid;
-               msds_intid_struct->usn = schema->loaded_usn;
                DEBUG(2, ("No samldb_msds_intid_persistant struct, allocating a new one\n"));
        } else {
                msds_intid = msds_intid_struct->msds_intid;
@@ -584,22 +583,22 @@ static int samldb_add_handle_msDS_IntId(struct samldb_ctx *ac)
 
        /* probe id values until unique one is found */
        do {
-               uint64_t current_usn;
                msds_intid++;
                if (msds_intid > 0xBFFFFFFF) {
                        msds_intid = 0x80000001;
                }
                /*
-                * Alternative strategy to a costly (even indexed search) to the
-                * database.
-                * We search in the schema if we have already this intid (using dsdb_attribute_by_attributeID_id because
-                * in the range 0x80000000 0xBFFFFFFFF, attributeID is a DSDB_ATTID_TYPE_INTID).
+                * We search in the schema if we have already this
+                * intid (using dsdb_attribute_by_attributeID_id
+                * because in the range 0x80000000 0xBFFFFFFFF,
+                * attributeID is a DSDB_ATTID_TYPE_INTID).
+                *
                 * If so generate another random value.
-                * If not check if the highest USN in the database for the schema partition is the
-                * one that we know.
-                * If so it means that's only this ldb context that is touching the schema in the database.
-                * If not it means that's someone else has modified the database while we are doing our changes too
-                * (this case should be very bery rare) in order to be sure do the search in the database.
+                *
+                * We have to check the DB in case someone else has
+                * modified the database while we are doing our
+                * changes too (this case should be very bery rare) in
+                * order to be sure.
                 */
                if (dsdb_attribute_by_attributeID_id(schema, msds_intid)) {
                        msds_intid = generate_random() % 0X3FFFFFFF;
@@ -607,45 +606,22 @@ static int samldb_add_handle_msDS_IntId(struct samldb_ctx *ac)
                        continue;
                }
 
-               ret = dsdb_module_load_partition_usn(ac->module, schema_dn,
-                                                    &current_usn, NULL, NULL);
+
+               ret = dsdb_module_search(ac->module, ac,
+                                        &ldb_res,
+                                        schema_dn, LDB_SCOPE_ONELEVEL, NULL,
+                                        DSDB_FLAG_NEXT_MODULE,
+                                        ac->req,
+                                        "(msDS-IntId=%d)", msds_intid);
                if (ret != LDB_SUCCESS) {
                        ldb_debug_set(ldb, LDB_DEBUG_ERROR,
-                                     __location__": Searching for schema USN failed: %s\n",
+                                     __location__": Searching for msDS-IntId=%d failed - %s\n",
+                                     msds_intid,
                                      ldb_errstring(ldb));
                        return ldb_operr(ldb);
                }
-
-               /* current_usn can be lesser than msds_intid_struct-> if there is
-                * uncommited changes.
-                */
-               if (current_usn > msds_intid_struct->usn) {
-                       /* oups something has changed, someone/something
-                        * else is modifying or has modified the schema
-                        * we'd better check this intid is the database directly
-                        */
-
-                       DEBUG(2, ("Schema has changed, searching the database for the unicity of %d\n",
-                                       msds_intid));
-
-                       ret = dsdb_module_search(ac->module, ac,
-                                               &ldb_res,
-                                               schema_dn, LDB_SCOPE_ONELEVEL, NULL,
-                                               DSDB_FLAG_NEXT_MODULE,
-                                               ac->req,
-                                               "(msDS-IntId=%d)", msds_intid);
-                       if (ret != LDB_SUCCESS) {
-                               ldb_debug_set(ldb, LDB_DEBUG_ERROR,
-                                       __location__": Searching for msDS-IntId=%d failed - %s\n",
-                                       msds_intid,
-                                       ldb_errstring(ldb));
-                               return ldb_operr(ldb);
-                       }
-                       id_exists = (ldb_res->count > 0);
-                       talloc_free(ldb_res);
-               } else {
-                       id_exists = 0;
-               }
+               id_exists = (ldb_res->count > 0);
+               talloc_free(ldb_res);
 
        } while(id_exists);
        msds_intid_struct->msds_intid = msds_intid;
index 20a55fecb754dc421462dc20a715a38b981f8429..12971dd6d93570f1afbbf891006c9a3f1e200829 100644 (file)
@@ -257,7 +257,6 @@ struct dsdb_openldap_dereference_result_control {
 
 struct samldb_msds_intid_persistant {
        uint32_t msds_intid;
-       uint64_t usn;
 };
 
 #define SAMLDB_MSDS_INTID_OPAQUE "SAMLDB_MSDS_INTID_OPAQUE"