From: Andrew Bartlett Date: Wed, 20 Dec 2017 23:07:46 +0000 (+1300) Subject: samba-tool domain schemaupgrade: Avoid reindex after every hunk X-Git-Tag: talloc-2.1.11~100 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6a6f0952a5769628bfa07d1bf1c04bd23d827492;p=thirdparty%2Fsamba.git samba-tool domain schemaupgrade: Avoid reindex after every hunk 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 Reviewed-by: Garming Sam Autobuild-User(master): Garming Sam Autobuild-Date(master): Thu Dec 21 08:28:51 CET 2017 on sn-devel-144 --- diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py index a3dd565871a..ada7d6b5f36 100644 --- a/python/samba/netcmd/domain.py +++ b/python/samba/netcmd/domain.py @@ -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):