Logo Search packages:      
Sourcecode: s3ql version File versions  Download package

def s3ql::fsck::Fsck::check_keylist (   self )
Check the list of objects.
    
Checks that:
- all objects are referred in the object table
- all objects in the object table exist
- object has correct hash

Definition at line 390 of file fsck.py.

                           :
        """Check the list of objects.
    
        Checks that:
        - all objects are referred in the object table
        - all objects in the object table exist
        - object has correct hash
        """
    
        log.info('Checking object list...')
    
        lof_id = self.conn.get_val("SELECT inode FROM contents WHERE name=? AND parent_inode=?",
                              (b"lost+found", ROOT_INODE))
    
        # We use this table to keep track of the objects that we have
        # seen
        self.conn.execute("CREATE TEMP TABLE obj_ids (id INTEGER PRIMARY KEY)")
        try:
            for (i, obj_name) in enumerate(self.bucket.list('s3ql_data_')):
        
                if i != 0 and i % 5000 == 0:
                    log.info('..processed %d objects so far..', i)
        
                # We only bother with data objects
                obj_id = int(obj_name[10:])
        
                self.conn.execute('INSERT INTO obj_ids VALUES(?)', (obj_id,))
            
            for (obj_id,) in self.conn.query('SELECT id FROM obj_ids '
                                        'EXCEPT SELECT id FROM objects'):
                self.found_errors = True
                self.log_error("Deleting spurious object %d",  obj_id)
                try:
                    del self.bucket['s3ql_data_%d' % obj_id]
                except NoSuchObject:
                    if self.bucket.read_after_write_consistent():
                        raise
        
            self.conn.execute('CREATE TEMPORARY TABLE missing AS '
                         'SELECT id FROM objects EXCEPT SELECT id FROM obj_ids')
            for (obj_id,) in self.conn.query('SELECT * FROM missing'):
                self.found_errors = True
                self.log_error("object %s only exists in table but not in bucket, deleting", obj_id)
                self.log_error("The following files may lack data and have been moved to /lost+found:")
                for (id_,) in self.conn.query('SELECT inode FROM blocks WHERE obj_id=?', (obj_id,)):
                    for (name, id_p) in self.conn.query('SELECT name, parent_inode FROM contents '
                                                   'WHERE inode=?', (id_,)):
                        path = get_path(id_p, self.conn, name)
                        self.log_error(path)
                        (_, newname) = self.resolve_free(b"/lost+found",
                                                            path[1:].replace('_', '__').replace('/', '_')) 
                            
                        self.conn.execute('UPDATE contents SET name=?, parent_inode=? '
                                          'WHERE name=? AND parent_inode=?', 
                                          (newname, lof_id, name, id_p))
                        
                self.conn.execute("DELETE FROM blocks WHERE obj_id=?", (obj_id,))
                self.conn.execute("DELETE FROM objects WHERE id=?", (obj_id,))
        finally:
            self.conn.execute('DROP TABLE obj_ids')
            self.conn.execute('DROP TABLE IF EXISTS missing')
    
    

Generated by  Doxygen 1.6.0   Back to index