'Ensure consistency of reference counts in the DB.
Raise an AssertionError if something is amiss.
Does no locking.'

def _check_ref_counts(self):

    counts = {}
    for (key, rec) in self._data.items():
        counts.setdefault(key, 0)
        for dep in rec.spec.dependencies(_tracked_deps):
            dep_key = dep.dag_hash()
            counts.setdefault(dep_key, 0)
            counts[dep_key] += 1
    for rec in self._data.values():
        key = rec.spec.dag_hash()
        expected = counts[key]
        found = rec.ref_count
        if (not (expected == found)):
            raise AssertionError(('Invalid    ref_count:    %s:    %d    (expected    %d),    in    DB    %s' % (key, found, expected, self._index_path)))
