dbcheck: skip reverse member link checks when cli option specified
authorJoe Guo <joeg@catalyst.net.nz>
Thu, 3 Jan 2019 02:55:16 +0000 (15:55 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 21 Feb 2019 03:09:19 +0000 (04:09 +0100)
currently dbcheck cmd tooks about 1 day to finish on a 100k user database.
We can skip member reverse link checks to speed it up dramatically.
A new cli option is added to enable the skipping.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/dbchecker.py
python/samba/netcmd/dbcheck.py

index bf999ddaab9daf21f3f94591199e5ef0997d2c98..705be388827e648e4c11b315953b6a28080aedc7 100644 (file)
@@ -60,6 +60,7 @@ class dbcheck(object):
 
     def __init__(self, samdb, samdb_schema=None, verbose=False, fix=False,
                  yes=False, quiet=False, in_transaction=False,
+                 quick_membership_checks=False,
                  reset_well_known_acls=False):
         self.samdb = samdb
         self.dict_oid_name = None
@@ -106,6 +107,7 @@ class dbcheck(object):
         self.fix_utf8_userparameters = False
         self.fix_doubled_userparameters = False
         self.fix_sid_rid_set_conflict = False
+        self.quick_membership_checks = quick_membership_checks
         self.reset_well_known_acls = reset_well_known_acls
         self.reset_all_well_known_acls = False
         self.in_transaction = in_transaction
@@ -1199,8 +1201,13 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
         else:
             reverse_syntax_oid = None
 
-        error_count, duplicate_dict, unique_dict = \
-            self.check_duplicate_links(obj, attrname, syntax_oid, linkID, reverse_link_name)
+        is_member_link = attrname in ("member", "memberOf")
+        if is_member_link and self.quick_membership_checks:
+            duplicate_dict = {}
+        else:
+            error_count, duplicate_dict, unique_dict = \
+                self.check_duplicate_links(obj, attrname, syntax_oid,
+                                           linkID, reverse_link_name)
 
         if len(duplicate_dict) != 0:
 
@@ -1387,6 +1394,9 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
                                                      dsdb_dn, res[0].dn)
                 continue
 
+            if is_member_link and self.quick_membership_checks:
+                continue
+
             # check the reverse_link is correct if there should be one
             match_count = 0
             if reverse_link_name in res[0]:
index 965288b4557387a3ffe03e7a3e3bd389cf7e6350..9006233bd3dfd6ceb0981bef39a267e4861f2baa 100644 (file)
@@ -72,6 +72,11 @@ class cmd_dbcheck(Command):
         Option("--reindex", dest="reindex", default=False, action="store_true", help="force database re-index"),
         Option("--force-modules", dest="force_modules", default=False, action="store_true", help="force loading of Samba modules and ignore the @MODULES record (for very old databases)"),
         Option("--reset-well-known-acls", dest="reset_well_known_acls", default=False, action="store_true", help="reset ACLs on objects with well known default ACL values to the default"),
+        Option("--quick-membership-checks", dest="quick_membership_checks",
+               help=("Skips missing/orphaned memberOf backlinks checks, "
+                     "but speeds up dbcheck dramatically for domains with "
+                     "large groups"),
+               default=False, action="store_true"),
         Option("-H", "--URL", help="LDB URL for database or target server (defaults to local SAM database)",
                type=str, metavar="URL", dest="H"),
     ]
@@ -80,6 +85,7 @@ class cmd_dbcheck(Command):
             cross_ncs=False, quiet=False,
             scope="SUB", credopts=None, sambaopts=None, versionopts=None,
             attrs=None, reindex=False, force_modules=False,
+            quick_membership_checks=False,
             reset_well_known_acls=False, yes_rules=[]):
 
         lp = sambaopts.get_loadparm()
@@ -130,7 +136,9 @@ class cmd_dbcheck(Command):
             started_transaction = True
         try:
             chk = dbcheck(samdb, samdb_schema=samdb_schema, verbose=verbose,
-                          fix=fix, yes=yes, quiet=quiet, in_transaction=started_transaction,
+                          fix=fix, yes=yes, quiet=quiet,
+                          in_transaction=started_transaction,
+                          quick_membership_checks=quick_membership_checks,
                           reset_well_known_acls=reset_well_known_acls)
 
             for option in yes_rules: