def METHOD_NAME(cls, domain, bucket_id):
    # select_for_update locks matching rows until the end of the transaction
    bucket, _ = (cls.objects
                 .select_for_update()
                 .get_or_create(domain=domain, bucket_id=bucket_id))
    bucket.current_value += 1
    bucket.save()
    return bucket.current_value