Make sure dirty aggregates are generated bottom-up to avoid generating new top-level aggregates from
previously generated, out-of-date aggregates. Add a lock for the list of dirty aggregates.