def allocate_tc_class_for_queue(context, qos_queue):
        if qos_queue.tc_class:
            return
        tc_class = None

        with context.session.begin(subtransactions=True):
            try:
                if qos_queue.id == qos_queue.qos.default_queue_id:
                    tc_class = 65534
                else:
                    tc_class = QosDb._try_allocate_new_tc_class(
                        context, qos_queue.qos)
            except ext_qos.AllocateTCClassFailure:
                QosDb._rebuild_tc_class_range(context, qos_queue.qos)

            if not tc_class:
                tc_class = QosDb._try_allocate_new_tc_class(
                    context, qos_queue.qos)

            qos_queue.update({'tc_class': tc_class})