'Updates the metadata dict for the database. The metadata dict values
are tuples of (value, timestamp) where the timestamp indicates when
that key was set to that value. Key/values will only be overwritten if
the timestamp is newer. To delete a key, set its value to (\'\',
timestamp). These empty keys will eventually be removed by
:func:`reclaim`'

def update_metadata(self, metadata_updates, validate_metadata=False):

    old_metadata = self.metadata
    if set(metadata_updates).issubset(set(old_metadata)):
        for (key, (value, timestamp)) in metadata_updates.items():
            if (timestamp > old_metadata[key][1]):
                break
        else:
            return
    with self.get() as conn:
        try:
            md = conn.execute(('SELECT    metadata    FROM    %s_stat' % self.db_type)).fetchone()[0]
            md = (json.loads(md) if md else {})
            utf8encodekeys(md)
        except sqlite3.OperationalError as err:
            if ('no    such    column:    metadata' not in str(err)):
                raise
            conn.execute(("\n                                                                                ALTER    TABLE    %s_stat\n                                                                                ADD    COLUMN    metadata    TEXT    DEFAULT    ''    " % self.db_type))
            md = {}
        for (key, value_timestamp) in metadata_updates.items():
            (value, timestamp) = value_timestamp
            if ((key not in md) or (timestamp > md[key][1])):
                md[key] = value_timestamp
        if validate_metadata:
            DatabaseBroker.validate_metadata(md)
        conn.execute(('UPDATE    %s_stat    SET    metadata    =    ?' % self.db_type), (json.dumps(md),))
        conn.commit()
