samba-tool domain schemaupgrade: Avoid reindex after every hunk
authorAndrew Bartlett <abartlet@samba.org>
Wed, 20 Dec 2017 23:07:46 +0000 (12:07 +1300)
committerGarming Sam <garming@samba.org>
Thu, 21 Dec 2017 07:28:51 +0000 (08:28 +0100)
This takes advantage of the fact that a single LDB operation is atomic
even inside our transaction and so we can retry it after updating the
schema.

This makes the smaba-tool domain schemaupgrade take 1m30s compared with 4m4s.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Autobuild-User(master): Garming Sam <garming@samba.org>
Autobuild-Date(master): Thu Dec 21 08:28:51 CET 2017 on sn-devel-144

python/samba/netcmd/domain.py

index a3dd565871a52521e69ba853d7a18c2ec04d21e8..ada7d6b5f3640eb93004fac66a234249b4de5292 100644 (file)
@@ -3915,7 +3915,21 @@ schemaUpdateNow: 1
         """Applies a single LDIF update to the schema"""
 
         try:
-            samdb.modify_ldif(self.ldif, controls=['relax:0'])
+            try:
+                samdb.modify_ldif(self.ldif, controls=['relax:0'])
+            except ldb.LdbError as e:
+                if e.args[0] == ldb.ERR_INVALID_ATTRIBUTE_SYNTAX:
+
+                    # REFRESH after a failed change
+
+                    # Otherwise the OID-to-attribute mapping in
+                    # _apply_updates_in_file() won't work, because it
+                    # can't lookup the new OID in the schema
+                    self._ldap_schemaUpdateNow(samdb)
+
+                    samdb.modify_ldif(self.ldif, controls=['relax:0'])
+                else:
+                    raise
         except ldb.LdbError as e:
             if self.can_ignore_failure(e):
                 return 0
@@ -3927,11 +3941,6 @@ schemaUpdateNow: 1
 
                 raise
 
-        # REFRESH AFTER EVERY CHANGE
-        # Otherwise the OID-to-attribute mapping in _apply_updates_in_file()
-        # won't work, because it can't lookup the new OID in the schema
-        self._ldap_schemaUpdateNow(samdb)
-
         return 1
 
 class cmd_domain_schema_upgrade(Command):