def _populate_range(self, context, sa_range): first_id = sa_range["first_id"] last_id = sa_range["last_id"] id_range = xrange(first_id, last_id + 1) LOG.info("Starting segment allocation population for " "range:%s size:%s." % (sa_range["id"], len(id_range))) total_added = 0 for chunk in self._chunks(id_range, 5000): sa_dicts = [] for segment_id in chunk: sa_dict = self._make_segment_allocation_dict( segment_id, sa_range) sa_dicts.append(sa_dict) db_api.segment_allocation_range_populate_bulk(context, sa_dicts) context.session.flush() total_added = total_added + len(sa_dicts) LOG.info("Populated %s/%s segment ids for range:%s" % (total_added, len(id_range), sa_range["id"])) LOG.info("Finished segment allocation population for " "range:%s size:%s." % (sa_range["id"], len(id_range)))
def _populate_segment_allocation_range(self, sa_range): """Populate a given segment range.""" # Range of ids to allocate, first to last (inclusive) id_range = xrange(sa_range["first_id"], sa_range["last_id"] + 1) sa_dicts = [] total = 0 for i in id_range: sa_dicts.append( { "segment_id": sa_range["segment_id"], "segment_type": sa_range["segment_type"], "id": i, "segment_allocation_range_id": sa_range["id"], "deallocated": True, } ) total = total + 1 db_api.segment_allocation_range_populate_bulk(self.context, sa_dicts) self.context.session.flush() # assert our allocation were actually created allocs = db_api.segment_allocation_find(self.context, segment_allocation_range_id=sa_range["id"]).all() self.assertEqual(len(allocs), len(id_range))
def _populate_segment_allocation_range(self, sa_range): """Populate a given segment range.""" # Range of ids to allocate, first to last (inclusive) id_range = xrange(sa_range['first_id'], sa_range['last_id'] + 1) sa_dicts = [] total = 0 for i in id_range: sa_dicts.append({ 'segment_id': sa_range['segment_id'], 'segment_type': sa_range['segment_type'], 'id': i, 'segment_allocation_range_id': sa_range['id'], 'deallocated': True }) total = total + 1 db_api.segment_allocation_range_populate_bulk(self.context, sa_dicts) self.context.session.flush() # assert our allocation were actually created allocs = db_api.segment_allocation_find( self.context, segment_allocation_range_id=sa_range['id']).all() self.assertEqual(len(allocs), len(id_range))