dbcheck: cope with objects disappearing during checking
authorAndrew Tridgell <tridge@samba.org>
Thu, 8 Dec 2011 00:47:59 +0000 (11:47 +1100)
committerAndrew Tridgell <tridge@samba.org>
Thu, 8 Dec 2011 02:23:49 +0000 (03:23 +0100)
Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Thu Dec  8 03:23:49 CET 2011 on sn-devel-104

source4/scripting/python/samba/dbchecker.py
source4/scripting/python/samba/netcmd/dbcheck.py

index 6792538f7583d4862a9b33f3e675baef97e48c19..ff3fd6ee3869197f0023dcf0b768751175fe116f 100644 (file)
@@ -30,7 +30,8 @@ from samba.common import dsdb_Dn
 class dbcheck(object):
     """check a SAM database for errors"""
 
-    def __init__(self, samdb, samdb_schema=None, verbose=False, fix=False, yes=False, quiet=False):
+    def __init__(self, samdb, samdb_schema=None, verbose=False, fix=False, yes=False,
+                 quiet=False, in_transaction=False):
         self.samdb = samdb
         self.dict_oid_name = None
         self.samdb_schema = (samdb_schema or samdb)
@@ -48,6 +49,7 @@ class dbcheck(object):
         self.fix_time_metadata = False
         self.fix_all_missing_backlinks = False
         self.fix_all_orphaned_backlinks = False
+        self.in_transaction = in_transaction
 
     def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=['*']):
         '''perform a database check, returning the number of errors found'''
@@ -423,11 +425,19 @@ class dbcheck(object):
         if '*' in attrs:
             attrs.append("replPropertyMetaData")
 
-        res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE,
-                controls=["extended_dn:1:1", "show_recycled:1", "show_deleted:1"],
-                                attrs=attrs)
+        try:
+            res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE,
+                                    controls=["extended_dn:1:1", "show_recycled:1", "show_deleted:1"],
+                                    attrs=attrs)
+        except ldb.LdbError, (enum, estr):
+            if enum == ldb.ERR_NO_SUCH_OBJECT:
+                if self.in_transaction:
+                    self.report("ERROR: Object %s disappeared during check" % dn)
+                    return 1
+                return 0
+            raise
         if len(res) != 1:
-            self.report("Object %s disappeared during check" % dn)
+            self.report("ERROR: Object %s failed to load during check" % dn)
             return 1
         obj = res[0]
         error_count = 0
index 1d4a5b4f3387149b6f217bdc4f32c3f91d25354d..bd250eb6be5aae0e290678837dbf669d9546d822 100644 (file)
@@ -102,7 +102,7 @@ class cmd_dbcheck(Command):
             started_transaction = True
         try:
             chk = dbcheck(samdb, samdb_schema=samdb_schema, verbose=verbose,
-                    fix=fix, yes=yes, quiet=quiet)
+                    fix=fix, yes=yes, quiet=quiet, in_transaction=started_transaction)
 
             if reindex:
                 self.outf.write("Re-indexing...\n")