mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
3 hours ago 8672f11245231e8d7eecc2054653a3e3b133f1a3
.github/scripts/replication/selftest-disturb-scale.sh
@@ -35,6 +35,7 @@
  ALL_NODES="$DS_NODES${RS_ONLY:+ $RS_ONLY}"
  PEERS=$(echo "$ALL_NODES" | tr ' ' ',')
  TOPOLOGY=$topology SCALE_VOLUME=$mode DISTURB_TIMEOUT=900 ROLLING_END=$((SECONDS + 900))
  NETWORK=fixture MONITOR_DOMAIN='cn=dc_example_dc_com,cn=Replication,cn=monitor'
  BASE_DN=dc=example,dc=com ROOT_PASSWORD=password
  . "$HERE/disturb-scale.sh"
  record() { printf '%s\n' "$*" >>"$OUT/calls"; }
@@ -72,7 +73,14 @@
  }
  start_server() { record "start $1 $2 $PEERS"; [ "$#" -le 2 ] || record "start-options $1 ${*:3}"; }
  admin_search() { echo 'scale checkpoint must not start an admin-search JVM' >&2; return 1; }
  scale_monitor_search() { record "search $1"; echo 'baseline'; }
  scale_monitor_search() {
    if [ "$2" = connected-to ]; then
      printf '%s:8989\n' "$(docker inspect "$1")"
    else
      record "search $1"; echo 'baseline'
    fi
  }
  scale_caught_up() { record "wait scale_caught_up $*"; [ "${FAIL_CHECKPOINT:-0}" != 1 ]; }
  window_open() { record "window $*"; }; window_close() { :; }
  window_open_key() { record "key-open $1"; shift; record "window $*"; }
  window_close_key() { record "window-close $1"; }
@@ -85,6 +93,7 @@
  record_rejoined_id() { REJOINED_WITH_NEW_ID=$new_id; record "identity $1"; }
  scale_backlog() { record "fill $REMOVED"; }
  wait_until() {
    case $3 in scale_prepare_routed_writer|scale_routed_checkpoint) "${@:3}"; return $? ;; esac
    record "wait ${*:3}"
    [ "${FAIL_CHECKPOINT:-0}" != 1 ] || [ "${3:-}" != scale_caught_up ] || return 1
    [ "${FAIL_RETURN_HISTORY:-0}" != 1 ] || [ "${3:-} ${4:-} ${5:-}" != 'scale_caught_up r2 r0' ] || return 1
@@ -102,6 +111,84 @@
  date() { echo 400; }
  sleep() { record "sleep $*"; }
  fail() { echo "$*" >&2; return 1; }
  # d0 writes through the departing RS. d1 starts on d0, switches to d3
  # while log windows open, then switches to the departing RS during catch-up.
  if [ "$topology-$mode-$new_id" = combined-kept-0 ]; then (
    scale_monitor_search() {
      [ "$2" = connected-to ] && [ "$3" = "$MONITOR_DOMAIN" ] || return 1
      case $1 in
        d0) echo 172.18.0.11:8989 ;;
        d1)
          if [ -e "$OUT/blip" ]; then
            rm "$OUT/blip"; touch "$OUT/blipped"; echo 172.18.0.12:8989
          elif [ -e "$OUT/switched" ]; then echo 172.18.0.11:8989
          elif [ -e "$OUT/opened" ]; then echo 172.18.0.12:8989
          else echo 172.18.0.9:8989; fi ;;
        d3) echo 172.18.0.10:8989 ;;
        *) return 1 ;;
      esac
    }
    rolling_clients_running() { record "active $1"; }
    scale_probe() {
      record "write $*"
      [ "${FAIL_MOVED_WRITE:-0}" = 0 ] || [ ! -e "$OUT/opened" ]
    }
    scale_caught_up() {
      record "checkpoint $*"
      if [ "$1" = d3 ]; then touch "$OUT/switched"; fi
    }
    window_open_key() {
      local node
      for node in $ALL_NODES; do
        [ ! -e "$OUT/logs/$node.window-$1" ] || return 1
        touch "$OUT/logs/$node.window-$1"
      done
      if [ "${ROUTE_BLIP:-0}" = 1 ] && [ ! -e "$OUT/blipped" ]; then
        touch "$OUT/blip"
      else
        touch "$OUT/opened"
      fi
    }
    wait_until() {
      shift 2
      local try rc
      for try in 1 2 3 4; do
        "$@" && return 0; rc=$?
        [ "$rc" != 200 ] || return 1
      done
      return 1
    }
    started_since() { :; }; bootstrap_ended() { :; }
    if (FAIL_MOVED_WRITE=1; scale_roll d2 "$FULL_PEERS"); then
      echo 'accepted an unconfirmed write after the same DS changed serving RS' >&2; exit 1
    fi
    if grep -q '^docker stop ' "$OUT/calls"; then echo 'stopped after a failed route probe' >&2; exit 1; fi
    rm -f "$OUT/opened" "$OUT/switched"
    : >"$OUT/calls"
    ROUTE_BLIP=1 scale_roll d2 "$FULL_PEERS" || { echo 'could not roll d2 with a surviving route' >&2; exit 1; }
    awk '
      /^active d1$/ && !first { first=NR }
      /^checkpoint d0 d2$/ { observed=NR }
      /^write d1 d2 checkpoint-up/ { probes++; confirmed=NR }
      /^checkpoint d3 d2$/ { moved=NR }
      /^active d3$/ && !replacement { replacement=NR }
      /^resume d0$/ && !stopped { exit 1 }
      /^request-pause d1$/ { held=NR }
      /^checkpoint d1 d2$/ { checked=NR }
      /^docker stop -t 120 d2$/ { stopped=NR }
      /^write d3 d2 up$/ { written=NR }
      END { if (!(probes == 3 && first && first < observed && observed < confirmed && confirmed < moved &&
                  moved < replacement && replacement < held && held < checked && checked < stopped &&
                  stopped < written)) exit 1 }
    ' "$OUT/calls" || { echo 'checkpoint did not follow the active writer to a surviving RS' >&2; exit 1; }
    : >"$OUT/calls"
    # d3 is absent on scale-in. d0 and d1 both use d2, leaving no safe route.
    if scale_roll d2 "$SHORT_PEERS"; then echo 'accepted only departing routes' >&2; exit 1; fi
    if grep -Eq '^(request-pause|docker stop|checkpoint) ' "$OUT/calls"; then
      echo 'changed the topology before finding a surviving route' >&2; exit 1
    fi
  ); fi
  : >"$OUT/calls"
  # No server is stopped if the surviving RS has not reached the departing RS's checkpoint.
  if (FAIL_CHECKPOINT=1; disturb) >/dev/null 2>&1; then
    echo 'failed checkpoint was accepted' >&2; exit 1
@@ -446,6 +533,7 @@
  [ ! -e "$OUT/logs/$target.offline" ]
  # A failed observer query identifies the node and status in the checkpoint diagnostic.
  (
    . "$HERE/disturb-scale.sh"
    scale_monitor_search() { [ "$1" != observer ] || return 124; echo baseline; }
    scale_checkpoint_init observer departing
    if scale_caught_up observer departing; then echo 'failed checkpoint query accepted' >&2; exit 1; fi
@@ -465,6 +553,49 @@
    if (FAIL_PROBE=1; scale_probe_batch d2 up d0 d1 r0); then echo 'failed batch accepted' >&2; exit 1; fi
  fi
)
check_checkpoint_budget() ( # <load end> <caught up at> <expected result> <expected time> [route change at]
  local caught_up_at=$2 switch_at=${5:-} result=0
  OUT="$OUT/budget-$1-$2-$switch_at"
  mkdir -p "$OUT"
  TOPOLOGY=combined SCALE_VOLUME=kept
  . "$HERE/lib.sh"
  . "$HERE/disturb-scale.sh"
  # Use the real wait loop with a deterministic clock. Writer preparation takes 80 s.
  unset SECONDS
  SECONDS=0 ROLLING_END=$1 DISTURB_TIMEOUT=900
  sleep() { SECONDS=$((SECONDS + $1)); }
  rolling_request_pause() { :; }
  rolling_pause() { [ "$1" != "$REMOVED" ] || sleep 80; }
  rolling_clients_running() { :; }
  scale_probe() { :; }
  docker() {
    local node=${*: -1}
    [ "$1" = inspect ] && echo "172.18.0.1${node##*-c}"
  }
  scale_monitor_search() {
    if [ -n "$switch_at" ] && [ "$SECONDS" -ge "$switch_at" ]; then
      echo '172.18.0.11:8989'
    else
      echo '172.18.0.10:8989'
    fi
  }
  scale_caught_up() { [ "$SECONDS" -ge "$caught_up_at" ]; }
  dns_window_open() { :; }
  window_open() { :; }
  scale_combined_checkpoint "$REMOVED" down >"$OUT/result" 2>&1 || result=$?
  if [ "$result" != "$3" ] || [ "$SECONDS" != "$4" ]; then
    cat "$OUT/result" >&2
    echo "checkpoint with load end $1 and catch-up at $2 returned $result at $SECONDS, expected $3 at $4" >&2
    exit 1
  fi
)
check_checkpoint_budget 2580 940 0 940
check_checkpoint_budget 880 940 1 880
check_checkpoint_budget 2580 1000 1 980
# Switching RS at 900 starts a fresh checkpoint, still bounded by the same load end.
check_checkpoint_budget 2580 1700 0 1700 900
check_checkpoint_budget 1500 1700 1 1500 900
for topology in rs534 combined; do
  for mode in kept empty; do run_case "$topology" "$mode"; done
done