1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 def row_lock_for_priority_update container_uuid
6 ActiveRecord::Base.connection.exec_query %{
7 select 1 from containers where containers.uuid in (select pri_container_uuid from container_tree($1)) order by containers.uuid for update
8 }, 'select_for_update_priorities', [[nil, container_uuid]]
11 def update_priorities starting_container_uuid
12 # Ensure the row locks were taken in order
13 row_lock_for_priority_update starting_container_uuid
15 ActiveRecord::Base.connection.exec_query %{
16 update containers set priority=computed.upd_priority from container_tree_priorities($1) as computed
17 where containers.uuid = computed.pri_container_uuid and priority != computed.upd_priority
18 }, 'update_priorities', [[nil, starting_container_uuid]]