@@ -98,15 +98,40 @@ qdrant_shard_on_leaving_peer() {
9898 local shard_id=" $2 "
9999 local peer_id=" $3 "
100100 local jq_bin=" ${JQ:- jq} "
101+ local ownership
101102
102- echo " $collection_cluster_info " | " $jq_bin " -e \
103+ ownership= " $( echo " $collection_cluster_info " | " $jq_bin " -er \
103104 --argjson shard " $shard_id " \
104105 --argjson peer " $peer_id " \
105- ' ((.result.remote_shards // [])
106- | any(.peer_id == $peer and .shard_id == $shard))
107- or
108- ((.result.local_shards // [])
109- | any((.peer_id? // $peer) == $peer and .shard_id == $shard))' > /dev/null
106+ ' if ((.result.remote_shards // [])
107+ | any(.peer_id == $peer and .shard_id == $shard)) then
108+ "on-leaving-peer"
109+ elif ((.result.local_shards // [])
110+ | any(.shard_id == $shard)) then
111+ if (.result.peer_id | type) == "number" then
112+ if .result.peer_id == $peer then "on-leaving-peer" else "off-leaving-peer" end
113+ else
114+ "unknown-local-peer"
115+ end
116+ else
117+ "off-leaving-peer"
118+ end' ) " || {
119+ echo " ERROR: failed to determine shard ${shard_id} ownership from collection cluster info" >&2
120+ return 2
121+ }
122+
123+ case " $ownership " in
124+ " on-leaving-peer" )
125+ return 0
126+ ;;
127+ " off-leaving-peer" )
128+ return 1
129+ ;;
130+ * )
131+ echo " ERROR: local shard without peer_id for shard ${shard_id} ; refusing to infer ownership" >&2
132+ return 2
133+ ;;
134+ esac
110135}
111136
112137qdrant_remaining_on_leaving_count () {
@@ -351,17 +376,26 @@ qdrant_collection_cluster_info_for_leaving_shard() {
351376 local fallback_info=" "
352377 local control_endpoint_uri
353378 local control_endpoint_uris=" ${control_uris:- $control_uri } "
379+ local shard_owner_rc
354380
355381 for control_endpoint_uri in $control_endpoint_uris ; do
356382 col_cluster_info=" $( qdrant_collection_cluster_info_from_uri " $control_endpoint_uri " " $col_name " ) " || return 1
357383 if [ -z " $fallback_info " ]; then
358384 fallback_info=" $col_cluster_info "
359385 fi
360- if qdrant_shard_transfer_exists " $col_cluster_info " " $shard_id " " $leave_peer_id " ||
361- qdrant_shard_on_leaving_peer " $col_cluster_info " " $shard_id " " $leave_peer_id " ; then
386+ if qdrant_shard_transfer_exists " $col_cluster_info " " $shard_id " " $leave_peer_id " ; then
362387 printf " %s\n" " $col_cluster_info "
363388 return 0
364389 fi
390+ if qdrant_shard_on_leaving_peer " $col_cluster_info " " $shard_id " " $leave_peer_id " ; then
391+ printf " %s\n" " $col_cluster_info "
392+ return 0
393+ else
394+ shard_owner_rc=$?
395+ if [ " $shard_owner_rc " -ne 1 ]; then
396+ return 1
397+ fi
398+ fi
365399 done
366400
367401 printf " %s\n" " $fallback_info "
@@ -373,15 +407,22 @@ qdrant_submit_shard_move_if_needed() {
373407 local col_cluster_info=" $3 "
374408 local move_target_peer_id
375409 local move_payload
410+ local shard_owner_rc
376411
377412 if qdrant_shard_transfer_exists " $col_cluster_info " " $shard_id " " $leave_peer_id " ; then
378413 echo " INFO: shard ${shard_id} in ${col_name} is already moving from peer ${leave_peer_id} "
379414 return 0
380415 fi
381416
382- if ! qdrant_shard_on_leaving_peer " $col_cluster_info " " $shard_id " " $leave_peer_id " ; then
383- echo " INFO: shard ${shard_id} in ${col_name} is already off peer ${leave_peer_id} "
384- return 0
417+ if qdrant_shard_on_leaving_peer " $col_cluster_info " " $shard_id " " $leave_peer_id " ; then
418+ :
419+ else
420+ shard_owner_rc=$?
421+ if [ " $shard_owner_rc " -eq 1 ]; then
422+ echo " INFO: shard ${shard_id} in ${col_name} is already off peer ${leave_peer_id} "
423+ return 0
424+ fi
425+ return 1
385426 fi
386427
387428 move_target_peer_id=" $( qdrant_select_target_peer_id_for_shard \
@@ -410,9 +451,15 @@ qdrant_submit_shard_move_if_needed() {
410451 echo " INFO: shard ${shard_id} in ${col_name} is already moving after failed submit"
411452 return 0
412453 fi
413- if ! qdrant_shard_on_leaving_peer " $col_cluster_info " " $shard_id " " $leave_peer_id " ; then
414- echo " INFO: shard ${shard_id} in ${col_name} moved off peer ${leave_peer_id} after failed submit"
415- return 0
454+ if qdrant_shard_on_leaving_peer " $col_cluster_info " " $shard_id " " $leave_peer_id " ; then
455+ :
456+ else
457+ shard_owner_rc=$?
458+ if [ " $shard_owner_rc " -eq 1 ]; then
459+ echo " INFO: shard ${shard_id} in ${col_name} moved off peer ${leave_peer_id} after failed submit"
460+ return 0
461+ fi
462+ return 1
416463 fi
417464
418465 echo " ERROR: failed to initiate shard ${shard_id} move in ${col_name} "
0 commit comments