| 28.25.2026 | Valery Kharseko | ![]() |
| 28.24.2026 | Valery Kharseko | ![]() |
| 28.31.2026 | Valery Kharseko | ![]() |
.github/scripts/replication/assert-converged.sh
@@ -141,12 +141,18 @@ # The number of lines each server's errors log held once the topology was up: the joins log # replication errors of their own while the servers come up one after the other, and only what # follows is the run's # follows is the run's. A log that cannot be read fails the run: a cat that fails in a pipe # would count 0 lines and exit 0, and window_open would take that for a window from the first # line, while a redirect that fails ends sh with 2 errors_lines() { # <node> docker exec $1 sh -c 'wc -l </opt/opendj/data/logs/errors' } mark_logs() { local n mkdir -p "$OUT/logs" for n in $ALL_NODES; do docker exec $n sh -c 'cat /opt/opendj/data/logs/errors | wc -l' >"$OUT/logs/$n.mark" errors_lines $n >"$OUT/logs/$n.mark" done } @@ -154,6 +160,57 @@ docker exec $1 tail -n +$(($(cat "$OUT/logs/$1.mark") + 1)) /opt/opendj/data/logs/errors } # A disturbance window over the errors log of every server (#1208): window_open before the # disturbance, window_close once the disturbed server serves again, a line "<lines before> # <lines after>" in logs/<node>.windows window_open() { local n for n in $ALL_NODES; do errors_lines $n >"$OUT/logs/$n.window" done } window_close() { local n lines for n in $ALL_NODES; do lines=$(errors_lines $n) echo "$(cat "$OUT/logs/$n.window") $lines" >>"$OUT/logs/$n.windows" rm "$OUT/logs/$n.window" done } # The replication errors <node> logged after mark_logs. A disturbance window expects the # handshakes that a server starting on a loaded runner fails, the other end giving up first: a # directory server (178) or a replication server (179) that disconnected in the handshake, both # at ERROR on the replication server it connected to, a replication server whose connection # crossed one the other way and lost the domain lock to it (145, a warning that abortStart logs # at ERROR, as it does 178 and 179: #1241), and the SSLHandshakeException of a server whose peer # closed the handshake once its read timed out. In run 39909337627 a restarted directory server # timed out connecting (212) and its replication server logged 178, and a replication server # logged 311 with SocketTimeoutException when the restarted server logged 119 with "Remote host # terminated the handshake"; in run 40463887505 a replication server logged 145 on the # connection of the restarted one. Those go to logs/<node>.expected; outside a window, and # anything else inside one, they are errors. A window expects them on any server, not only on # the connections of the disturbed one: 178 and 179 name the servers by id alone, and a server # has one in each of its domains and another for its replication server. A handshake that fails # is followed by a connection elsewhere, and a change it lost the checks of the data find replication_errors() { # <node> local windows= [ ! -f "$OUT/logs/$1.windows" ] || windows=$(tr '\n' ' ' <"$OUT/logs/$1.windows") since_mark $1 | awk -v first=$(($(cat "$OUT/logs/$1.mark") + 1)) -v windows="$windows" \ -v expected="$OUT/logs/$1.expected" ' BEGIN { n = split(windows, w, " ") } !/category=SYNC severity=ERROR|SSLHandshakeException|bad_certificate/ { next } { line = first + NR - 1 if (/category=SYNC severity=ERROR msgID=(145|178|179) / \ || /category=SYNC severity=WARNING .*SSLHandshakeException\(Remote host terminated the handshake\)/) for (i = 1; i < n; i += 2) if (line > w[i] + 0 && line <= w[i + 1] + 0) { print >expected; next } }' } # How often each directory server connected to a replication server again after the topology # came up, whatever made it: a switch the broker decided on (msgID 188, or 213 to spread the # load), a replication server that closed the connection (63), a connection that broke. Each @@ -218,10 +275,9 @@ fi done for n in $ALL_NODES; do if ! lines=$(since_mark $n); then if ! lines=$(replication_errors $n); then echo "::error::the errors log of $n could not be read"; failed=1; continue fi lines=$(grep -E "category=SYNC severity=ERROR|SSLHandshakeException|bad_certificate" <<<"$lines" || true) [ -z "$lines" ] || { printf '%s\n' "$lines" >"$OUT/logs/$n.errors"; echo "::error::$n logged replication errors, see logs/$n.errors"; failed=1; } done assert_rs_mesh || failed=1 .github/scripts/replication/changelog-gaps.py
@@ -35,12 +35,15 @@ What it cannot tell. A change lost at either end of a replica's changes in the window - its last ones, or its first ones when no earlier change of the replica is in the changelog - leaves no gap between two changes that are there; the data of the other replicas shows such a change unless a later change of another server overwrites it. And not every sequence number that no record holds is a lost change: a directory server that goes offline (a restart, its domain disabled) numbers its ReplicaOfflineMsg like a change, and the changelog keeps only the newest of them, in the offline.state of the replica, not in a log file. The convergence run restarts no server after the topology is up; a run that did would read each restart in the window as a lost change. unless a later change of another server overwrites it. A restart leaves no gap of its own. A directory server that stops numbers its ReplicaOfflineMsg like a change, and no log file holds the message - only the offline.state of the replica, the newest one. But the message does not enter the ServerState of the replica (ReplicaOfflineMsg.contributesToDomainState()), from whose newest change of its own the server numbers again once it starts (CSNGenerator), so its first change after the restart takes the sequence number of the message again, at a later time: the changes of the restarted server had no gap in run 39834888428 (#1208). A gap around a restart is a lost change, the kind #1195 lost. The file format is the one of FileReplicaDB: every log file is cut into blocks of 256 bytes, and every block after the first starts with a 4-byte offset (BlockLogWriter); in between, a .github/scripts/replication/collect.sh
@@ -56,6 +56,15 @@ echo "| servers | $ALL_NODES |" echo "| load | $DURATION s on each directory server, at most $LOAD_MOD_RATE modifications and $LOAD_ADD_RATE adds or deletes a second |" echo "| seeded users | $SAMPLE_DATA |" if [ -s "$OUT/disturbances.txt" ]; then awk -v start="${LOAD_START_MS:-0}" '{ printf "| disturbance | %s of %s %d s into the load, serving again %d s later |\n", $4, $3, ($1 - start) / 1000, ($2 - $1) / 1000 }' "$OUT/disturbances.txt" elif [ "$DISTURBANCE" != none ] && [ -z "${LOAD_START_MS:-}" ]; then # run.sh sets LOAD_START_MS as the load starts echo "| disturbance | $DISTURBANCE at $DISTURB_AT s into the load, not started: the run ended before the load |" elif [ "$DISTURBANCE" != none ]; then echo "| disturbance | $DISTURBANCE at $DISTURB_AT s into the load, not completed |" fi echo "| converged | ${CONVERGED_IN:--} s after the load |" if [ -s "$OUT/samples.txt" ]; then awk '{ t[$1] = 1 } END { for (s in t) { n++; if (!min || s < min) min = s; if (s > max) max = s } @@ -85,6 +94,16 @@ done | grep . || echo "none" echo '```' fi if ls "$OUT"/logs/*.expected >/dev/null 2>&1; then echo echo "Handshakes failed while a disturbed server came back, which the disturbance expects (logs/*.expected):" echo echo '```' for f in "$OUT"/logs/*.expected; do sed "s/^/$(basename "$f" .expected): /" "$f" done echo '```' fi if ls "$OUT"/load/*.csv >/dev/null 2>&1; then echo echo "| client | average ops/s | intervals |" .github/scripts/replication/disturb-restart-ds.sh
New file @@ -0,0 +1,53 @@ # # # The contents of this file are subject to the terms of the Common Development and # Distribution License (the License). You may not use this file except in compliance with the # License. # # You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the # specific language governing permission and limitations under the License. # # When distributing Covered Software, include this CDDL Header Notice in each file and include # the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL # Header, with the fields enclosed by brackets [] replaced by your own identifying # information: "Portions copyright [year] [name of copyright owner]". # # Copyright 2026 3A Systems, LLC. # The disturbance restart-ds of the replication convergence run (#1208), sourced by run.sh: a # directory server restarts DISTURB_AT seconds into the load, as docker restart or a rolling # update restarts it, while the others go on taking the load. run_load stops its clients # before and starts others once it serves again. It is the second directory server, the one # inject_divergence writes to: in rs534 it runs no replication server, in combined the one it # runs restarts with it. DISTURBED=$(echo $DS_NODES | cut -d' ' -f2) # docker restart sends SIGTERM and kills the server once its timeout is over: 10 s by default, # less than a server under load may need to stop, and a killed server is another disturbance. # stop_all gives it 120 s as well. The restart goes to disturbances.txt for the summary, from # the restart until the server serves again, and is a window of the errors logs: the handshakes # its start fails on a loaded runner are expected there (replication_errors). The window closes # 10 s after the server serves again: a handshake its start began can still fail then, and a # peer logs 145 only once its wait for the domain lock, of up to 8 s, is over # (ServerHandler.lockDomainWithTimeout). A handshake that fails later is an error again disturb() { local from served echo " [$SECONDS s] restarting $DISTURBED" window_open from=$(date +%s) docker restart -t 120 $DISTURBED >/dev/null wait_until $DISTURB_TIMEOUT "$DISTURBED serves again" started_since $DISTURBED $from served=$(date +%s) echo " [$SECONDS s] $DISTURBED serves again" sleep 10 window_close echo "$((from * 1000)) $((served * 1000)) $DISTURBED restart" >>"$OUT/disturbances.txt" } # After the load, before the wait for convergence: the join of the restarted server, which runs # again on every start, has ended, as topology_up waits for it. Its container is not waited to # be healthy again: the probe may not get through while the replicas catch up either settle() { wait_until $DISTURB_TIMEOUT "the join of $DISTURBED ends" bootstrap_ended $DISTURBED } .github/scripts/replication/lib.sh
@@ -18,8 +18,17 @@ # setting comes from the environment, so that the same run goes in CI and on a laptop. TOPOLOGY=${TOPOLOGY:-rs534} # seconds of load DURATION=${DURATION:-120} # what disturbs the topology during the load (#1208): none, or the <name> of a disturb-<name>.sh # next to this script, which names the DISTURBED server and defines disturb, run during the load, # and settle, run after it DISTURBANCE=${DISTURBANCE:-none} # seconds of load. A disturbed run takes the load of its CI rows: a restarted server served # again 131 to 225 s after the restart there, and the load has to go on after that if [ "$DISTURBANCE" = none ]; then DURATION=${DURATION:-120} else DURATION=${DURATION:-900} fi # the most modifications, and adds or deletes, per second the load sends to each directory # server; a runner that cannot keep up sends fewer, which the summary shows LOAD_MOD_RATE=${LOAD_MOD_RATE:-423} @@ -38,6 +47,10 @@ QUIESCE_TIMEOUT=${QUIESCE_TIMEOUT:-900} # 1: write to one replica only, which the run must report (a self-test of its checks) INJECT_DIVERGENCE=${INJECT_DIVERGENCE:-0} # seconds into the load at which the disturbance starts DISTURB_AT=${DISTURB_AT:-$((DURATION / 3))} # seconds a disturbed server is given to serve again, and its join to end after the load DISTURB_TIMEOUT=${DISTURB_TIMEOUT:-900} # where the summary, the samples, the exports, the differences and a failed run's state go: a # directory that is new or empty OUT=${OUT:-$PWD/replication-out} @@ -128,6 +141,15 @@ [ "$(docker inspect --format='{{.State.Health.Status}}' "$1")" = healthy ] } # The server of the container logged that it started (msgID 135, once its connection handlers # listen) after the Unix time <seconds>: it serves. Not the health of the container: its probe, # a JVM of its own, does not get through its 30 s on a runner under load - in run 39834888428 a # restarted server served 7 minutes before its container was healthy again. No grep -q: it # would cut docker logs off, and pipefail would take that for no match started_since() { # <container> <seconds> docker logs --since "$2" "$1" 2>&1 | grep 'category=CORE severity=NOTICE msgID=135 ' >/dev/null } # The background join of the image goes on once the container reports itself healthy: it adds # replication servers to the replication server lists while its peers register # (repair_replication_servers in join.sh). Ended once no bootstrap script runs any more, as .github/scripts/replication/load.sh
@@ -17,7 +17,8 @@ # The load of the replication convergence run (#1090), sourced by run.sh: every directory # server is written to at once, for DURATION seconds, by rate tools that run in containers of # the same image on the network of the topology. Only writes: a read sends nothing to the # replication servers. # replication servers. The server a disturbance takes down (#1208) is written to before it and # after it, by clients of their own. # <client> <tool> <argument>... : a container that runs one tool of the image against one server start_client() { @@ -31,19 +32,21 @@ # seconds between two lines of the output of a rate tool STAT_INTERVAL=10 # The clients of one directory server for <seconds> of the load, a modrate and an addrate. # Segment 1 starts with the load; a later one once a disturbance let the server serve again, # and it adds entries of its own: the 100 newest of the segment before are still there. # Plain LDAP: the run is after the changes the replication carries, and TLS between a client # and its server only takes CPU from them. --noRebind: every client keeps its connections open # and binds once, as an application does, rather than connecting and binding for every # operation, which would cost more than the operation itself. --connectTimeout: the clients # start at once next to the servers, and a runner that is short of CPU for a while accepts # their connections late run_load() { local n c failed mkdir -p "$OUT/load" for n in $DS_NODES; do # entries of its own on each server, so that the adds and deletes of two servers never meet # on one DN: a naming conflict is not what this load is after cat >"$OUT/load/addrate-$n.template" <<TEMPLATE start_clients() { # <node> <segment> <seconds> local n=$1 name=$1 c [ "$2" -eq 1 ] || name=$1-$2 # entries of its own on each server, so that the adds and deletes of two servers never meet # on one DN: a naming conflict is not what this load is after cat >"$OUT/load/addrate-$name.template" <<TEMPLATE define suffix=$BASE_DN branch: ou=People,[suffix] @@ -55,30 +58,56 @@ objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson uid: addrate-$n.<sequential:0> uid: addrate-$name.<sequential:0> cn: AddRate {uid} sn: AddRate userPassword: password TEMPLATE chmod 644 "$OUT/load/addrate-$n.template" # the same entries from every server at once: concurrent modifications of one attribute of # one entry, applied in the order of their change numbers on every replica (#139). The value # starts with the name of the server: rand and randstr are seeded alike in every client, so # all of them write the same values in the same order, and a change lost on its way would # hide behind the same value written later by another server; the name also tells which # server a value in a diff or a changelog comes from (#1206) start_client load-mod-$n modrate --hostname $n --port 1389 --connectTimeout 120000 --noRebind \ --bindDN "cn=Directory Manager" --bindPassword "$ROOT_PASSWORD" --maxDuration "$DURATION" \ --statInterval $STAT_INTERVAL --numConnections 8 --numThreads 1 --scriptFriendly --targetThroughput "$LOAD_MOD_RATE" \ --targetDN "uid=user.%d,ou=People,$BASE_DN" --argument "rand(0,$((SAMPLE_DATA - 1)))" \ --argument "randstr(16)" "description:$n-%2\$s" # adds, and deletes of the oldest once 100 of them are there: a slow runner gets to the deletes as well start_client load-add-$n addrate --hostname $n --port 1389 --connectTimeout 120000 --noRebind \ --bindDN "cn=Directory Manager" --bindPassword "$ROOT_PASSWORD" --maxDuration "$DURATION" \ --statInterval $STAT_INTERVAL --numConnections 8 --numThreads 1 --scriptFriendly --targetThroughput "$LOAD_ADD_RATE" \ --deleteMode fifo --deleteSizeThreshold 100 "/load/addrate-$n.template" CLIENTS="$CLIENTS load-mod-$n load-add-$n" chmod 644 "$OUT/load/addrate-$name.template" # the same entries from every server at once: concurrent modifications of one attribute of # one entry, applied in the order of their change numbers on every replica (#139). The value # starts with the name of the server, and of the segment after the first (cv-d1-2): rand and # randstr are seeded alike in every client, so all of them write the same values in the same # order - the two segments of one server as well - and a change lost on its way would hide # behind the same value written later by another client; the name also tells which server, # and which segment, a value in a diff or a changelog comes from (#1206) start_client load-mod-$name modrate --hostname $n --port 1389 --connectTimeout 120000 --noRebind \ --bindDN "cn=Directory Manager" --bindPassword "$ROOT_PASSWORD" --maxDuration "$3" \ --statInterval $STAT_INTERVAL --numConnections 8 --numThreads 1 --scriptFriendly --targetThroughput "$LOAD_MOD_RATE" \ --targetDN "uid=user.%d,ou=People,$BASE_DN" --argument "rand(0,$((SAMPLE_DATA - 1)))" \ --argument "randstr(16)" "description:$name-%2\$s" # adds, and deletes of the oldest once 100 of them are there: a slow runner gets to the deletes as well start_client load-add-$name addrate --hostname $n --port 1389 --connectTimeout 120000 --noRebind \ --bindDN "cn=Directory Manager" --bindPassword "$ROOT_PASSWORD" --maxDuration "$3" \ --statInterval $STAT_INTERVAL --numConnections 8 --numThreads 1 --scriptFriendly --targetThroughput "$LOAD_ADD_RATE" \ --deleteMode fifo --deleteSizeThreshold 100 "/load/addrate-$name.template" # check_client reads how long each client was to run for c in load-mod-$name load-add-$name; do echo "$3" >"$OUT/load/$c.seconds" done CLIENTS="$CLIENTS load-mod-$name load-add-$name" } run_load() { local n c failed start=$SECONDS left mkdir -p "$OUT/load" for n in $DS_NODES; do if [ "$n" = "${DISTURBED:-}" ]; then start_clients $n 1 "$DISTURB_AT" else start_clients $n 1 "$DURATION" fi done if [ "$DISTURBANCE" != none ]; then # the clients of the disturbed server end on their own before the disturbance, which then # cuts none of their operations off: one that had its CSN would read as a lost change docker wait load-mod-$DISTURBED load-add-$DISTURBED >/dev/null disturb left=$((DURATION - (SECONDS - start))) [ "$left" -ge $((3 * STAT_INTERVAL)) ] \ || fail "$DISTURBED served again $((SECONDS - start)) s into the load of $DURATION s, too late to take load again" start_clients $DISTURBED 2 $left fi for c in $CLIENTS; do docker wait $c >/dev/null done @@ -100,10 +129,10 @@ # too, leaves out the line of its last interval - the one that would count the error - and # prints the error to its error output, which goes to the same file. So the client has to have # done work, every interval of its CSV output has to report no errors (the "Errors/second" # column), the output has to cover the load - a line every STAT_INTERVAL seconds, of which the # last may be missing - and hold nothing but the CSV # column), the output has to cover the seconds the client was to run - a line every # STAT_INTERVAL seconds, of which the last may be missing - and hold nothing but the CSV check_client() { # <client> awk -F, -v c=$1 -v exit_state="$(cat "$OUT/load/$1.exit")" -v want=$((DURATION / STAT_INTERVAL - 1)) ' awk -F, -v c=$1 -v exit_state="$(cat "$OUT/load/$1.exit")" -v want=$(($(cat "$OUT/load/$1.seconds") / STAT_INTERVAL - 1)) ' /^Time \(seconds\)/ { for (i = 1; i <= NF; i++) { if ($i == "Recent throughput (ops/second)") t = i; if ($i == "Errors/second") e = i }; next } t && $1 ~ /^[0-9.]+$/ { rows++; ops += $t; errors += $e; last = $0; next } NF { other++ } .github/scripts/replication/monitor.sh
@@ -71,10 +71,10 @@ MONITORING_PERIOD=60 # Three converged samples in a row, the last one started more than a monitoring period (and # the publisher's 5 s latch) after the first ended. Sets CONVERGED_IN to the seconds until the # first of them wait_converged() { local start=$SECONDS hits=0 first= last= # the publisher's 5 s latch) after the first ended. Sets CONVERGED_IN to the seconds from # <start> (a value of SECONDS, now by default) until the first of them wait_converged() { # [<start>] local start=${1:-$SECONDS} hits=0 first= last= until [ $hits -ge 3 ] && [ $((last - first)) -gt $((MONITORING_PERIOD + 5)) ]; do last=$SECONDS if converged_once; then hits=$((hits + 1)); first=${first:-$SECONDS}; else hits=0; first=; fi .github/scripts/replication/run.sh
@@ -33,6 +33,13 @@ . "$HERE/load.sh" . "$HERE/assert-converged.sh" . "$HERE/collect.sh" if [ "$DISTURBANCE" != none ]; then [ -f "$HERE/disturb-$DISTURBANCE.sh" ] \ || { echo "unknown DISTURBANCE $DISTURBANCE: none, or the <name> of a disturb-<name>.sh in $HERE" >&2; exit 2; } [ "$DISTURB_AT" -gt 0 ] && [ "$DISTURB_AT" -lt "$DURATION" ] \ || { echo "DISTURB_AT=$DISTURB_AT is not within the load of $DURATION s" >&2; exit 2; } . "$HERE/disturb-$DISTURBANCE.sh" fi # the files of an earlier run would mix into this one's: the samples are appended to, and the # summary of a run that failed early would show what a run that got further left @@ -67,7 +74,7 @@ mark_logs record_server_ids phase "load ($DURATION s)" phase "load ($DURATION s${DISTURBED:+, $DISTURBANCE of $DISTURBED at $DISTURB_AT s})" # the changes of the load: assert_changelogs looks for gaps among the changes made in between LOAD_START_MS=$(($(date +%s) * 1000)) sampler_start @@ -75,7 +82,11 @@ sampler_stop phase "converge" wait_converged load_end=$SECONDS # a disturbed server is left as topology_up leaves every server, and the wait for convergence # still counts from the end of the load [ "$DISTURBANCE" = none ] || settle wait_converged $load_end echo "converged in $CONVERGED_IN s" LOAD_END_MS=$(($(date +%s) * 1000)) .github/scripts/replication/selftest-disturb-restart-ds.sh
New file @@ -0,0 +1,58 @@ #!/usr/bin/env bash # # # The contents of this file are subject to the terms of the Common Development and # Distribution License (the License). You may not use this file except in compliance with the # License. # # You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the # specific language governing permission and limitations under the License. # # When distributing Covered Software, include this CDDL Header Notice in each file and include # the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL # Header, with the fields enclosed by brackets [] replaced by your own identifying # information: "Portions copyright [year] [name of copyright owner]". # # Copyright 2026 3A Systems, LLC. # A self-test of the disturbance restart-ds of the replication convergence run (#1208), with no # topology: what disturb and settle call, in which order, and what disturb writes to # disturbances.txt. The window of the errors logs opens before the restart and closes 10 s after # the server serves again, and the restart ends when the server served, not after the grace. A # restart-ds row shows neither, unless a handshake record lands where the order moved. docker, # wait_until, window_open, window_close, date and sleep are stubs that record their calls, and # the clock moves in the stubs alone: the restart takes 5 s, the wait for the server 30 s. # # Usage: selftest-disturb-restart-ds.sh set -eE -o pipefail HERE=$(cd "$(dirname "$0")" && pwd) DS_NODES="d0 d1" DISTURB_TIMEOUT=900 OUT=$(mktemp -d) trap 'rm -rf "$OUT"' EXIT . "$HERE/disturb-restart-ds.sh" now=100 calls= date() { echo $now; } sleep() { calls="$calls sleep $1"; now=$((now + $1)); } docker() { calls="$calls docker $*"; now=$((now + 5)); } wait_until() { calls="$calls wait_until $*"; now=$((now + 30)); } window_open() { calls="$calls window_open"; } window_close() { calls="$calls window_close"; } failed=0 check() { # <what> <got> <want> [ "$2" = "$3" ] || { echo "::error::$1:$2, not$3"; failed=$((failed + 1)); } } disturb >/dev/null check "disturb called" "$calls" \ " window_open docker restart -t 120 d1 wait_until 900 d1 serves again started_since d1 100 sleep 10 window_close" check "disturbances.txt holds" " $(cat "$OUT/disturbances.txt")" " 100000 135000 d1 restart" calls= settle check "settle called" "$calls" " wait_until 900 the join of d1 ends bootstrap_ended d1" echo "disturb-restart-ds: $((3 - failed)) checks passed, $failed failed" [ "$failed" -eq 0 ] .github/scripts/replication/selftest-replication-errors.sh
New file @@ -0,0 +1,108 @@ #!/usr/bin/env bash # # # The contents of this file are subject to the terms of the Common Development and # Distribution License (the License). You may not use this file except in compliance with the # License. # # You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the # specific language governing permission and limitations under the License. # # When distributing Covered Software, include this CDDL Header Notice in each file and include # the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL # Header, with the fields enclosed by brackets [] replaced by your own identifying # information: "Portions copyright [year] [name of copyright owner]". # # Copyright 2026 3A Systems, LLC. # A self-test of the errors log check of the replication convergence run (#1208), with no # topology: which records replication_errors takes for errors and which ones a disturbance # window expects. A green row does not show it - nothing a disturbance expects is logged outside # its window there, and the base rows have no window - so docker-convergence runs this first. # docker is a stub that reads a local errors log: mark_logs, window_open and window_close count # its lines, since_mark reads it, as they do in a container. # # Usage: selftest-replication-errors.sh set -eE -o pipefail HERE=$(cd "$(dirname "$0")" && pwd) . "$HERE/assert-converged.sh" ALL_NODES=n0 OUT=$(mktemp -d) trap 'rm -rf "$OUT"' EXIT LOG=$OUT/errors docker() { # exec <node> sh -c <the line count of the errors log> | exec <node> tail -n +<first> <errors log> case "$1 $3" in "exec sh") wc -l <"$LOG" | tr -d ' ' ;; "exec tail") tail -n "$5" "$LOG" ;; *) echo "unexpected docker $*" >&2; return 1 ;; esac } E178='[t] category=SYNC severity=ERROR msgID=178 msg=Directory server 32536 was attempting to connect to replication server 31531 but has disconnected in handshake phase' E179='[t] category=SYNC severity=ERROR msgID=179 msg=Replication server 1 was attempting to connect to replication server 2 but has disconnected in handshake phase' E145='[t] category=SYNC severity=ERROR msgID=145 msg=Timed out while trying to acquire the domain lock for domain "dc=example,dc=com". The connection attempt from replication server RS(29892) at cv-c1.convergence/172.18.0.3:52382 to this replication server RS(27915) will be aborted. This is probably benign and a result of a simultaneous cross connection attempt' W119='[t] category=SYNC severity=WARNING msgID=119 msg=Directory server DS(24329) encountered an unexpected error while connecting to replication server cv-r0:8989 for domain "cn=schema": SSLHandshakeException(Remote host terminated the handshake)' E119=${W119/severity=WARNING/severity=ERROR} W119CORE=${W119/category=SYNC/category=CORE} WBAD='[t] category=SYNC severity=WARNING msgID=119 msg=Directory server DS(1) encountered an unexpected error while connecting: SSLHandshakeException(Received fatal alert: bad_certificate)' WBADCORE='[t] category=CORE severity=WARNING msgID=1 msg=SSLException(Received fatal alert: bad_certificate)' E106='[t] category=SYNC severity=ERROR msgID=106 msg=another replication error' E1450='[t] category=SYNC severity=ERROR msgID=1450 msg=an id that starts like one a window expects' E45='[t] category=SYNC severity=ERROR msgID=45 msg=an id that ends like one a window expects' E106ID='[t] category=SYNC severity=ERROR msgID=106 msg=Replication server 32179 lost its connection' N62='[t] category=SYNC severity=NOTICE msgID=62 msg=Directory server DS(1) has connected' CORE178='[t] category=CORE severity=ERROR msgID=178 msg=not a replication error' passed=0 failed=0 # case <name> <errors> <expected> <record, [ or ]>...: the errors log holds two errors before # mark_logs, which are not the run's, then the records given; [ opens a window and ] closes it. # The number of records replication_errors prints, and of those it sends to logs/n0.expected case_() { local name=$1 want_errors=$2 want_expected=$3 record errors expected shift 3 rm -rf "$OUT/logs" printf '%s\n' "$E178" "$E106" >"$LOG" mark_logs for record; do case $record in '[') window_open ;; ']') window_close ;; *) echo "$record" >>"$LOG" ;; esac done errors=$(replication_errors n0 | grep -c . || true) expected=$( [ ! -f "$OUT/logs/n0.expected" ] || grep -c . "$OUT/logs/n0.expected" || true) if [ "$errors" = "$want_errors" ] && [ "${expected:-0}" = "$want_expected" ]; then passed=$((passed + 1)) else failed=$((failed + 1)) echo "::error::$name: $errors errors and ${expected:-0} expected, not $want_errors and $want_expected" fi } case_ 178-outside-a-window 1 0 "$E178" case_ 145-outside-a-window 1 0 "$E145" case_ 178-in-a-window 0 1 '[' "$E178" ']' case_ 179-in-a-window 0 1 '[' "$E179" ']' case_ 145-in-a-window 0 1 '[' "$E145" ']' case_ terminated-handshake 0 1 '[' "$W119" ']' case_ terminated-handshake-error 1 0 '[' "$E119" ']' case_ terminated-elsewhere 1 0 '[' "$W119CORE" ']' case_ bad-certificate 1 0 '[' "$WBAD" ']' case_ bad-certificate-elsewhere 1 0 '[' "$WBADCORE" ']' case_ another-error-in-a-window 1 0 '[' "$E106" ']' case_ ids-like-expected-ones 2 0 '[' "$E1450" "$E45" ']' case_ an-id-in-the-message 1 0 '[' "$E106ID" ']' case_ another-category 0 0 '[' "$CORE178" ']' case_ a-notice 0 0 "$N62" case_ before-a-window 1 1 "$E178" '[' "$E178" ']' case_ after-a-window 1 1 '[' "$N62" "$E178" ']' "$E178" case_ two-windows 0 2 '[' "$E178" ']' "$N62" '[' "$E179" ']' case_ between-two-windows 1 2 '[' "$E178" ']' "$E179" '[' "$E178" ']' case_ mixed 2 2 '[' "$E178" "$E106" "$W119" "$WBAD" "$N62" ']' echo "replication_errors: $passed cases passed, $failed failed" [ "$failed" -eq 0 ] .github/workflows/build.yml
@@ -686,6 +686,10 @@ shell: bash run: | trap 'code=$?; echo "::group::container logs (test)"; docker logs test 2>&1 || true; echo "::endgroup::"; exit $code' ERR # the image draws nothing: the OS carries none of what AWT needs to, freetype with brotli, X11 or ALSA. # The temurin JRE of the default image keeps a freetype of its own in /opt/java, linking nothing but libc (#1238) awt=$(docker run --rm --entrypoint sh localhost:5000/${GITHUB_REPOSITORY,,}:${{ env.release_version }}${{ matrix.suffix }} -c 'find / -xdev \( -name "libfreetype.so*" ! -path "/opt/java/*" -o -name "libbrotli*.so*" -o -name "libX11.so*" -o -name "libasound.so*" \) 2>/dev/null; true') if [ -n "$awt" ]; then echo "::error::The image carries libraries only AWT needs:"; echo "$awt"; false; fi docker run -it -d --memory="512m" --name=test localhost:5000/${GITHUB_REPOSITORY,,}:${{ env.release_version }}${{ matrix.suffix }} # the bootstrap's server is down before the marker the health check waits for is # written: the stop has logged its record by the time the marker is there @@ -1120,11 +1124,11 @@ docker-convergence: # #1090: writes to every directory server of a replication topology at once, then checks # that the replicas hold the same data; next to docker-test, on the image of build-docker # that the replicas hold the same data; next to docker-test, on the image of build-docker. # Each row but the base one disturbs the topology during the load in one way (#1208) needs: build-docker # a red row turns the Build run red, and deploy.yml then skips the snapshot deploy and the # publishing of the docs of a push to master: rs534 fails until #1206 is fixed and can fail # until #1215 is, combined can fail until #1195 is # publishing of the docs of a push to master runs-on: 'ubuntu-latest' permissions: contents: read @@ -1132,11 +1136,21 @@ fail-fast: false matrix: topology: [rs534, combined] # none: the base run; restart-ds: a directory server restarts during the load disturbance: [none, restart-ds] steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: sparse-checkout: | .github/scripts/replication # what a green row does not show: what a disturbance window of the errors log check # expects - nothing it expects is logged outside the window there, and a base row has # none - and where restart-ds opens and closes the window - name: Self-tests of the errors log check and of restart-ds shell: bash run: | .github/scripts/replication/selftest-replication-errors.sh .github/scripts/replication/selftest-disturb-restart-ds.sh - name: Download the image uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: @@ -1145,11 +1159,15 @@ - name: Load the image shell: bash run: docker load -i "$RUNNER_TEMP/image/image.tar" - name: Convergence run (${{ matrix.topology }}) - name: Convergence run (${{ matrix.topology }}, ${{ matrix.disturbance }}) shell: bash env: TOPOLOGY: ${{ matrix.topology }} DURATION: "1800" DISTURBANCE: ${{ matrix.disturbance }} # a disturbed row runs half the load of the base one: what it is after happens around # the disturbance, a third of the way in, and for as long as it runs it holds one of # the runners the whole organization shares DURATION: ${{ matrix.disturbance == 'none' && '1800' || '900' }} # the replicas fall behind during the load and catch up after it: 900 s at 325 and 65 # a second converged in 396 s (run 38944365728), 1800 s at 423 and 85 in 2489 s (run # 39043600905), the backlog growing faster than the load above the replay capacity; a @@ -1162,7 +1180,8 @@ if: always() uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: convergence-${{ matrix.topology }} # the base rows keep the names they had before the disturbed ones came name: convergence-${{ matrix.topology }}${{ matrix.disturbance != 'none' && format('-{0}', matrix.disturbance) || '' }} path: ${{ runner.temp }}/replication-out if-no-files-found: warn retention-days: 5 opendj-doc-generated-ref/src/main/asciidoc/reference/appendix-log-messages.adoc
@@ -12,7 +12,7 @@ information: "Portions copyright [year] [name of copyright owner]". Copyright 2017 ForgeRock AS. Portions Copyright 2024 3A Systems LLC. Portions Copyright 2024-2026 3A Systems LLC. //// :figure-caption!: @@ -12676,20 +12676,6 @@ + Message: Could not retrieve the configuration for a replication domain matching the entry %s. [#log-ref-log-ref-ERR_DS_DISCONNECTED_DURING_HANDSHAKE_178] ID: 178:: Severity: ERROR + Message: Directory server %s was attempting to connect to replication server %s but has disconnected in handshake phase. Error: %s. [#log-ref-log-ref-ERR_RS_DISCONNECTED_DURING_HANDSHAKE_179] ID: 179:: Severity: ERROR + Message: Replication server %s was attempting to connect to replication server %s but has disconnected in handshake phase. Error: %s. [#log-ref-log-ref-ERR_RS_BADLY_DISCONNECTED_181] ID: 181:: Severity: ERROR opendj-packages/opendj-docker/Dockerfile
@@ -55,6 +55,12 @@ #COPY opendj-*.zip $OPENDJ_DIST_FILENAME # The JRE of the base image has no headless variant, but it draws nothing here: X11 and ALSA are # not installed, and the freetype it renders fonts with is a copy of its own that links nothing # but libc. What the base image adds for it - fontconfig with the freetype of the OS, brotli and # the fonts - is purged along with curl and unzip, and --auto-remove takes the libraries they # pulled in (libcurl with its Kerberos, LDAP and SASL libraries among them). The GUI tools # (control-panel) are run outside the container, against its admin port. RUN printf 'Acquire::ForceIPv4 "true";\nAcquire::Retries "5";\n' > /etc/apt/apt.conf.d/99-ci-network \ && apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \ @@ -62,7 +68,7 @@ && if [ -z "$VERSION" ] ; then VERSION="$(curl -i -o - --silent https://api.github.com/repos/OpenIdentityPlatform/OpenDJ/releases/latest | grep -m1 "\"name\"" | cut -d\" -f4)"; fi \ && if [ ! -f "$OPENDJ_DIST_FILENAME" ]; then echo file exists && curl -L https://github.com/OpenIdentityPlatform/OpenDJ/releases/download/$VERSION/opendj-$VERSION.zip --output $OPENDJ_DIST_FILENAME; fi \ && unzip $OPENDJ_DIST_FILENAME \ && apt-get remove -y --purge curl unzip \ && apt-get purge -y --auto-remove curl unzip fontconfig libfreetype6 \ && rm -rf /var/lib/apt/lists/* /etc/apt/apt.conf.d/99-ci-network \ && rm -r $OPENDJ_DIST_FILENAME \ && groupadd $OPENDJ_USER \ opendj-packages/opendj-docker/Dockerfile-alpine
@@ -57,9 +57,12 @@ #COPY opendj-*.zip $OPENDJ_DIST_FILENAME # The headless JRE: the server and the command-line tools do not draw, and the full JRE only # adds what AWT needs to - X11, ALSA, freetype with brotli, the image codecs - along with their # CVEs. The GUI tools (control-panel) are run outside the container, against its admin port. RUN apk add --update --no-cache --virtual builddeps curl unzip \ && apk upgrade --update --no-cache \ && if [ "$TARGETARCH" = "386" ]; then JDK=openjdk11-jre; else JDK=openjdk25-jre; fi \ && if [ "$TARGETARCH" = "386" ]; then JDK=openjdk11-jre-headless; else JDK=openjdk25-jre-headless; fi \ && apk add bash coreutils "$JDK" \ && if [ -z "$VERSION" ] ; then VERSION="$(curl -i -o - --silent https://api.github.com/repos/OpenIdentityPlatform/OpenDJ/releases/latest | grep -m1 "\"name\"" | cut -d\" -f4)"; fi \ && if [ ! -f "$OPENDJ_DIST_FILENAME" ]; then echo file exists && curl -L https://github.com/OpenIdentityPlatform/OpenDJ/releases/download/$VERSION/opendj-$VERSION.zip --output $OPENDJ_DIST_FILENAME; fi \ opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/PacketTooLargeException.java
New file @@ -0,0 +1,44 @@ /* * The contents of this file are subject to the terms of the Common Development and * Distribution License (the License). You may not use this file except in compliance with the * License. * * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the * specific language governing permission and limitations under the License. * * When distributing Covered Software, include this CDDL Header Notice in each file and include * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions copyright [year] [name of copyright owner]". * * Copyright 2026 3A Systems, LLC. */ package org.opends.server.replication.protocol; import java.io.IOException; /** * Raised by {@link Session#receive()} when this server runs out of heap for a frame: most * likely one whose length header announces more bytes than it can allocate, though an * {@link OutOfMemoryError} reading or decoding a frame of an ordinary size is raised as this too. * <p> * It is an {@link IOException}, so that every caller which takes it for a session to give up * still does. A handshake tells it apart from the other ones, which are the peer going away: * either the peer breaks the protocol, no handshake message coming near the size such a header * announces, or this server is short of heap, and either is an error. */ public class PacketTooLargeException extends IOException { private static final long serialVersionUID = 4264358734106531071L; /** * Creates the exception for a frame of the provided length. * * @param length * the length the header of the frame announced */ public PacketTooLargeException(int length) { super("Packet too large, can't allocate " + length + " bytes."); } } opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/Session.java
@@ -738,7 +738,9 @@ * need to implement any replication. * * @return The ReplicationMsg that was received. * @throws IOException When error happened during IO process. * @throws IOException When error happened during IO process, a * {@link PacketTooLargeException} when this server runs out of heap * for the frame received. * @throws DataFormatException When the data received is not formatted as a * ReplicationMsg. * @throws NotSupportedOldVersionPDUException If the received PDU is part of @@ -773,8 +775,7 @@ } catch (final OutOfMemoryError e) { throw new IOException("Packet too large, can't allocate " + totalLength + " bytes."); throw new PacketTooLargeException(totalLength); } } catch (final IOException | DataFormatException | NotSupportedOldVersionPDUException | RuntimeException e) opendj-server-legacy/src/main/java/org/opends/server/replication/server/DataServerHandler.java
@@ -40,6 +40,7 @@ import org.opends.server.replication.common.StatusMachine; import org.opends.server.replication.common.StatusMachineEvent; import org.opends.server.replication.protocol.ChangeStatusMsg; import org.opends.server.replication.protocol.PacketTooLargeException; import org.opends.server.replication.protocol.ProtocolVersion; import org.opends.server.replication.protocol.ReplServerStartDSMsg; import org.opends.server.replication.protocol.ReplicationMsg; @@ -465,11 +466,19 @@ logStartSessionHandshake(inStartSessionMsg, outTopoMsg); } catch (PacketTooLargeException e) { // Not the peer going away, see PacketTooLargeException. logger.traceException(e); abortStart(LocalizableMessage.raw( e.getLocalizedMessage() + " Peer: " + session.getReadableRemoteAddress())); return; } catch(IOException e) { LocalizableMessage errMessage = ERR_DS_DISCONNECTED_DURING_HANDSHAKE.get( inServerStartMsg.getServerId(), replicationServer.getServerId()); throw new DirectoryException(ResultCode.OTHER, errMessage); abortStartWithWarning(WARN_DS_DISCONNECTED_DURING_HANDSHAKE.get( inServerStartMsg.getServerId(), replicationServer.getServerId())); return; } catch (Exception e) { opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServer.java
@@ -770,19 +770,23 @@ * returns false from then on, so the next real outage of it is not reported at all. * * What the handshake did next is reported all the same, because it is not the log which * can be left to it. ReplicationServerHandler.connect() aborts at seven places, and the * can be left to it. ReplicationServerHandler.connect() aborts at eight places, and the * three which pass no message log nothing at all, abortStart() logging nothing without * one: a StopMsg read where the peer's ReplServerStartMsg was due, a cross connect this * server resolves against a peer it is already connected to, and a phase two the peer * leaves unanswered. Those would otherwise leave "connected" as the last thing said * about a domain which has no session for it. The remaining four have their reason * about a domain which has no session for it. The remaining five have their reason * logged here by abortStart(), and they are not all of one kind: this server rejecting * the peer, the peer going away while the handshake ran, and whatever else fails on * this side of it. So the message reported for an answer without a session tells the * two apart by where a reason was logged rather than by naming a side: the operator is * sent to the log of the peer only where nothing was logged here, and that is also the * abort the peer may have logged nothing about either -- it resolves a cross connect * with the same silent abortStart(null), one line up in startFromRemoteRS(). * this side of it -- the second logged as a warning, being no error of this server, and * the other two as errors. A peer silent past the connection timeout is of the second * kind. A frame this server has no heap for is of the first kind or of the third, though * the session reports it as an IOException, which the second kind is as well. So the * message reported for an answer without a session tells the two apart by where a * reason was logged rather than by naming a side: the operator is sent to the log of the * peer only where nothing was logged here, and that is also the abort the peer may have * logged nothing about either -- it resolves a cross connect with the same silent * abortStart(null), one line up in startFromRemoteRS(). * * The cross connect this server resolves is the one abort of the three where a session * for the domain does exist: it is the connection the peer made. For a peer which names opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServerHandler.java
@@ -37,6 +37,7 @@ import org.opends.server.replication.common.RSInfo; import org.opends.server.replication.common.ServerState; import org.opends.server.replication.common.ServerStatus; import org.opends.server.replication.protocol.PacketTooLargeException; import org.opends.server.replication.protocol.ProtocolVersion; import org.opends.server.replication.protocol.ReplServerStartMsg; import org.opends.server.replication.protocol.ReplicationMsg; @@ -160,7 +161,7 @@ * on an outgoing connection. * <p> * A handshake which does not complete is aborted rather than thrown out of here, and * three of its seven aborts carry no message at all: a peer which stops the handshake * three of its eight aborts carry no message at all: a peer which stops the handshake * answers with a {@link StopMsg}, which {@code Session.close()} publishes for every * abort of its own, and {@link #abortStart} logs nothing when the reason is null. The * caller is what is left to tell a connection from an attempt which only reached the @@ -285,13 +286,20 @@ super.finalizeStart(); return true; } catch (PacketTooLargeException e) { // Not the peer going away, see PacketTooLargeException. logger.traceException(e); abortStart(LocalizableMessage.raw( e.getLocalizedMessage() + " Peer: " + session.getReadableRemoteAddress())); return false; } catch (IOException e) { logger.traceException(e); LocalizableMessage errMessage = ERR_RS_DISCONNECTED_DURING_HANDSHAKE.get( abortStartWithWarning(WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get( getReplicationServerId(), session.getReadableRemoteAddress()); abortStart(errMessage); session.getReadableRemoteAddress())); return false; } catch (DirectoryException e) @@ -325,7 +333,13 @@ // The initiator decides if the session is encrypted sslEncryption = processStartFromRemote(inReplServerStartMsg); lockDomainWithTimeout(); if (!lockDomainWithTimeout()) { // This server gives way to a cross connection, see lockDomainWithTimeout(). abortStartWithWarning(WARN_TIMEOUT_WHEN_CROSS_CONNECTION.get(getBaseDN(), serverId, session.getReadableRemoteAddress(), getReplicationServerId())); return; } if (replicationServerDomain.isAlreadyConnectedToRS(this)) { @@ -414,10 +428,17 @@ super.finalizeStart(); } catch (PacketTooLargeException e) { // Not the peer going away, see PacketTooLargeException. logger.traceException(e); abortStart(LocalizableMessage.raw( e.getLocalizedMessage() + " Peer: " + session.getReadableRemoteAddress())); } catch (IOException e) { logger.traceException(e); abortStart(ERR_RS_DISCONNECTED_DURING_HANDSHAKE.get( abortStartWithWarning(WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get( inReplServerStartMsg.getServerId(), replicationServer.getServerId())); } catch (DirectoryException e) @@ -440,15 +461,22 @@ * Wait receiving the TopologyMsg from the remote RS and process it. * @return the topologyMsg received or {@code null} if stop was received. * @throws DirectoryException * @throws IOException * If the session failed, which the caller reports as it does a * failure of the session in the first phase of the handshake. */ private TopologyMsg waitAndProcessTopoFromRemoteRS() throws DirectoryException throws DirectoryException, IOException { ReplicationMsg msg; try { msg = session.receive(); } catch (IOException e) { throw e; } catch(Exception e) { LocalizableMessage message = LocalizableMessage.raw(e.getLocalizedMessage()); opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java
@@ -205,11 +205,41 @@ } /** * Abort a start procedure currently establishing. * Abort a start procedure currently establishing, logging the reason as an error. * @param reason The provided reason. */ protected void abortStart(LocalizableMessage reason) { abortStart(reason, false); } /** * Abort a start procedure currently establishing, logging the reason as a warning. * <p> * For the aborts which are no error of this server and no fault of its peer * either: the peer going away while the handshake ran, which the peer logs * as a warning itself when it gave up on its own timeout, and this server * giving way to a cross connection. Both are what a peer restarting under * load leaves behind, and logged as errors they read as errors of every * server it was handshaking with. * <p> * The peer going away is an {@code IOException} of the session, in either * phase of the handshake. A peer silent past the connection timeout is one * too: it is also what the connect thread of a cross connection reads while * the listen thread of its peer waits for the domain lock. The exception is a * {@link org.opends.server.replication.protocol.PacketTooLargeException}: * a frame this server has no heap for is not the peer going away, and is an * error. * * @param reason The provided reason. */ protected void abortStartWithWarning(LocalizableMessage reason) { abortStart(reason, true); } private void abortStart(LocalizableMessage reason, boolean isWarning) { // We did not recognize the message, close session as what can happen after // is undetermined and we do not want the server to be disturbed Session localSession = session; @@ -221,7 +251,14 @@ { logger.trace("In " + this + " closing session with err=" + reason); } logger.error(reason); if (isWarning) { logger.warn(reason); } else { logger.error(reason); } } // This method is only called when aborting a failing handshake and @@ -790,25 +827,18 @@ * thread to take the lock it was waiting for and process the connection * attempt. * * @throws DirectoryException * When an exception occurs. * @return {@code true} if the lock was acquired, {@code false} if the wait * timed out, which is the connection attempt to abort * @throws InterruptedException * If the current thread was interrupted while waiting for the lock. */ public void lockDomainWithTimeout() throws DirectoryException, InterruptedException public boolean lockDomainWithTimeout() throws InterruptedException { final Random random = new Random(); final int randomTime = random.nextInt(6); // Random from 0 to 5 // Wait at least 3 seconds + (0 to 5 seconds) final long timeout = 3000 + randomTime * 1000L; final boolean lockAcquired = replicationServerDomain.tryLock(timeout); if (!lockAcquired) { LocalizableMessage message = WARN_TIMEOUT_WHEN_CROSS_CONNECTION.get( getBaseDN(), serverId, session.getReadableRemoteAddress(), getReplicationServerId()); throw new DirectoryException(ResultCode.OTHER, message); } return replicationServerDomain.tryLock(timeout); } /** opendj-server-legacy/src/messages/org/opends/messages/replication.properties
@@ -285,10 +285,10 @@ for importing suffix %s data has been stopped due to fractional configuration \ inconsistency : imported data set has some fractional configuration but not \ local server ERR_DS_DISCONNECTED_DURING_HANDSHAKE_178=Directory server %s was \ WARN_DS_DISCONNECTED_DURING_HANDSHAKE_178=Directory server %s was \ attempting to connect to replication server %s but has disconnected in \ handshake phase ERR_RS_DISCONNECTED_DURING_HANDSHAKE_179=Replication server %s was \ WARN_RS_DISCONNECTED_DURING_HANDSHAKE_179=Replication server %s was \ attempting to connect to replication server %s but has disconnected in \ handshake phase NOTE_ERR_UNABLE_TO_ENABLE_ECL_VIRTUAL_ATTR_182=Error when loading a virtual \ opendj-server-legacy/src/messages/org/opends/messages/replication_de.properties
@@ -12,6 +12,7 @@ # # Copyright 2006-2010 Sun Microsystems, Inc. # Portions Copyright 2011-2016 ForgeRock AS. # Portions Copyright 2026 3A Systems, LLC. # This file contains the primary Directory Server configuration. It must not # be directly edited while the server is online. The server configuration @@ -148,8 +149,8 @@ ERR_FRACTIONAL_COULD_NOT_RETRIEVE_CONFIG_175=Die Konfiguration f\u00fcr eine Replikationsdom\u00e4ne, die mit dem Eintrag %s \u00fcbereinstimmt, ist fehlgeschlagen NOTE_ERR_LDIF_IMPORT_FRACTIONAL_BAD_DATA_SET_176=Der LDIF-Import f\u00fcr die %s Suffix-Daten wurde aufgrund einer partiellen Konfigurationsinkonsistenz angehalten: Der importierte Datensatz besitzt nicht dieselbe Konfiguration wie der lokale Server NOTE_ERR_LDIF_IMPORT_FRACTIONAL_DATA_SET_IS_FRACTIONAL_177=Der LDIF-Import f\u00fcr die %s Suffix-Daten wurde aufgrund einer partiellen Konfigurationsinkonsistenz angehalten: Der importierte Datensatz besitzt dieselbe partielle Konfiguration, der lokale Server jedoch nicht ERR_DS_DISCONNECTED_DURING_HANDSHAKE_178=Directory-Server %s hat versucht, eine Verbindung zum Replikationsserver %s herzustellen, wurde aber in der Handshake-Phase getrennt ERR_RS_DISCONNECTED_DURING_HANDSHAKE_179=Replikationsserver %s hat versucht, eine Verbindung zum Replikationsserver %s herzustellen, wurde aber in der Handshake-Phase getrennt WARN_DS_DISCONNECTED_DURING_HANDSHAKE_178=Directory-Server %s hat versucht, eine Verbindung zum Replikationsserver %s herzustellen, wurde aber in der Handshake-Phase getrennt WARN_RS_DISCONNECTED_DURING_HANDSHAKE_179=Replikationsserver %s hat versucht, eine Verbindung zum Replikationsserver %s herzustellen, wurde aber in der Handshake-Phase getrennt NOTE_ERR_UNABLE_TO_ENABLE_ECL_VIRTUAL_ATTR_182=Fehler beim Laden eines virtuellen Attributs f\u00fcr externes \u00c4nderungsprotokoll: %s , Fehler: %s NOTE_ERR_UNABLE_TO_ENABLE_ECL_183=Fehler in %s beim Aktivieren des externen \u00c4nderungsprotokolls: %s ERR_RESYNC_REQUIRED_UNKNOWN_DOMAIN_IN_PROVIDED_COOKIE_185=Vollst\u00e4ndige Neusynchronisierung erforderlich. Ursache: Das angegebene Cookie enth\u00e4lt eine unbekannte replizierte Dom\u00e4ne %s. Aktuelle ab Cookie ist <%s> opendj-server-legacy/src/messages/org/opends/messages/replication_es.properties
@@ -12,6 +12,7 @@ # # Copyright 2006-2010 Sun Microsystems, Inc. # Portions Copyright 2011-2016 ForgeRock AS. # Portions Copyright 2026 3A Systems, LLC. # This file contains the primary Directory Server configuration. It must not # be directly edited while the server is online. The server configuration @@ -148,8 +149,8 @@ ERR_FRACTIONAL_COULD_NOT_RETRIEVE_CONFIG_175=No pudo recuperarse la configuraci\u00f3n para un dominio de repetici\u00f3n que coincida con la entrada %s NOTE_ERR_LDIF_IMPORT_FRACTIONAL_BAD_DATA_SET_176=La importaci\u00f3n de LDIF para importar los datos del sufijo %s se ha detenido debido a una inconsistencia de la configuraci\u00f3n de repetici\u00f3n fraccional: el conjunto de datos importados no tiene la misma configuraci\u00f3n fraccional que el servidor local NOTE_ERR_LDIF_IMPORT_FRACTIONAL_DATA_SET_IS_FRACTIONAL_177=La importaci\u00f3n de LDIF para importar los datos del sufijo %s se ha detenido debido a una inconsistencia de la configuraci\u00f3n de repetici\u00f3n fraccional: el conjunto de datos importados tiene alguna configuraci\u00f3n fraccional, pero no el servidor local ERR_DS_DISCONNECTED_DURING_HANDSHAKE_178=El Servidor de directorios %s ha tratado de conectarse al servidor de repetici\u00f3n %s, pero se ha desconectado en la fase de protocolo de enlace ERR_RS_DISCONNECTED_DURING_HANDSHAKE_179=El Servidor de repetici\u00f3n %s ha tratado de conectarse al servidor de repetici\u00f3n %s, pero se ha desconectado en la fase de protocolo de enlace WARN_DS_DISCONNECTED_DURING_HANDSHAKE_178=El Servidor de directorios %s ha tratado de conectarse al servidor de repetici\u00f3n %s, pero se ha desconectado en la fase de protocolo de enlace WARN_RS_DISCONNECTED_DURING_HANDSHAKE_179=El Servidor de repetici\u00f3n %s ha tratado de conectarse al servidor de repetici\u00f3n %s, pero se ha desconectado en la fase de protocolo de enlace NOTE_ERR_UNABLE_TO_ENABLE_ECL_VIRTUAL_ATTR_182=Error al cargar un atributo virtual para el registro de cambios externo: Atributo: %s, Error: %s NOTE_ERR_UNABLE_TO_ENABLE_ECL_183=Error en %s al habilitar el registro de cambios externo: %s ERR_RESYNC_REQUIRED_UNKNOWN_DOMAIN_IN_PROVIDED_COOKIE_185=Se requiere una resincronizaci\u00f3n completa. Raz\u00f3n: la cookie proporcionada contiene un dominio repetido desconocido %s. La cookie actual de partida es <%s> opendj-server-legacy/src/messages/org/opends/messages/replication_fr.properties
@@ -12,6 +12,7 @@ # # Copyright 2006-2010 Sun Microsystems, Inc. # Portions Copyright 2011-2016 ForgeRock AS. # Portions Copyright 2026 3A Systems, LLC. # This file contains the primary Directory Server configuration. It must not # be directly edited while the server is online. The server configuration @@ -148,8 +149,8 @@ ERR_FRACTIONAL_COULD_NOT_RETRIEVE_CONFIG_175=Impossible de r\u00e9cup\u00e9rer la configuration pour un domaine de r\u00e9plication correspondant \u00e0 l'entr\u00e9e %s NOTE_ERR_LDIF_IMPORT_FRACTIONAL_BAD_DATA_SET_176=L\u2019importation LDIF des donn\u00e9es %s de suffixe a \u00e9t\u00e9 interrompue en raison d\u2019une incoh\u00e9rence de configuration partielle\u00a0: l\u2019ensemble de donn\u00e9es import\u00e9es n\u2019a pas la m\u00eame configuration partielle que le serveur local NOTE_ERR_LDIF_IMPORT_FRACTIONAL_DATA_SET_IS_FRACTIONAL_177=L\u2019importation LDIF des donn\u00e9es %s de suffixe a \u00e9t\u00e9 interrompue en raison d\u2019une incoh\u00e9rence de configuration partielle\u00a0: l\u2019ensemble de donn\u00e9es import\u00e9es a une configuration partielle mais le serveur local pas ERR_DS_DISCONNECTED_DURING_HANDSHAKE_178=Le serveur d'annuaire %s a tent\u00e9 de se connect\u00e9 au serveur de r\u00e9plication %s mais s'est d\u00e9connect\u00e9 lors de la phase de n\u00e9gociation (handshake) ERR_RS_DISCONNECTED_DURING_HANDSHAKE_179=Le serveur de r\u00e9plication %s a tent\u00e9 de se connect\u00e9 au serveur de r\u00e9plication %s mais s'est d\u00e9connect\u00e9 lors de la phase de n\u00e9gociation (handshake) WARN_DS_DISCONNECTED_DURING_HANDSHAKE_178=Le serveur d'annuaire %s a tent\u00e9 de se connect\u00e9 au serveur de r\u00e9plication %s mais s'est d\u00e9connect\u00e9 lors de la phase de n\u00e9gociation (handshake) WARN_RS_DISCONNECTED_DURING_HANDSHAKE_179=Le serveur de r\u00e9plication %s a tent\u00e9 de se connect\u00e9 au serveur de r\u00e9plication %s mais s'est d\u00e9connect\u00e9 lors de la phase de n\u00e9gociation (handshake) NOTE_ERR_UNABLE_TO_ENABLE_ECL_VIRTUAL_ATTR_182=Erreur lors du chargement d'un attribut virtuel pour le journal des modifications externe\u00a0: attribut\u00a0: %s, erreur\u00a0: %s NOTE_ERR_UNABLE_TO_ENABLE_ECL_183=Erreur de %s lors de l'activation du journal des modifications externe\u00a0: %s ERR_RESYNC_REQUIRED_UNKNOWN_DOMAIN_IN_PROVIDED_COOKIE_185=Resynchronisation compl\u00e8te requise. Raison\u00a0: le cookie fourni contient un domaine r\u00e9pliqu\u00e9 inconnu (%s). Le cookie actuel de base est <%s> opendj-server-legacy/src/messages/org/opends/messages/replication_ja.properties
@@ -12,6 +12,7 @@ # # Copyright 2006-2010 Sun Microsystems, Inc. # Portions Copyright 2011-2016 ForgeRock AS. # Portions Copyright 2026 3A Systems, LLC. # This file contains the primary Directory Server configuration. It must not # be directly edited while the server is online. The server configuration @@ -147,8 +148,8 @@ ERR_FRACTIONAL_COULD_NOT_RETRIEVE_CONFIG_175=\u30a8\u30f3\u30c8\u30ea %s \u306b\u4e00\u81f4\u3059\u308b\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30c9\u30e1\u30a4\u30f3\u306e\u69cb\u6210\u3092\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f NOTE_ERR_LDIF_IMPORT_FRACTIONAL_BAD_DATA_SET_176=\u30b5\u30d5\u30a3\u30c3\u30af\u30b9 %s \u30c7\u30fc\u30bf\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u305f\u3081\u306e LDIF \u30a4\u30f3\u30dd\u30fc\u30c8\u304c\u3001\u90e8\u5206\u69cb\u6210\u306e\u4e0d\u4e00\u81f4\u304c\u539f\u56e0\u3067\u4e2d\u6b62\u3055\u308c\u307e\u3057\u305f: \u30a4\u30f3\u30dd\u30fc\u30c8\u3055\u308c\u305f\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306b\u306f\u30ed\u30fc\u30ab\u30eb\u30b5\u30fc\u30d0\u30fc\u3068\u540c\u3058\u90e8\u5206\u69cb\u6210\u304c\u5b58\u5728\u3057\u307e\u305b\u3093 NOTE_ERR_LDIF_IMPORT_FRACTIONAL_DATA_SET_IS_FRACTIONAL_177=\u30b5\u30d5\u30a3\u30c3\u30af\u30b9 %s \u30c7\u30fc\u30bf\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u305f\u3081\u306e LDIF \u30a4\u30f3\u30dd\u30fc\u30c8\u304c\u3001\u90e8\u5206\u69cb\u6210\u306e\u4e0d\u4e00\u81f4\u304c\u539f\u56e0\u3067\u4e2d\u6b62\u3055\u308c\u307e\u3057\u305f: \u30a4\u30f3\u30dd\u30fc\u30c8\u3055\u308c\u305f\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306b\u306f\u3044\u304f\u3064\u304b\u306e\u90e8\u5206\u69cb\u6210\u304c\u5b58\u5728\u3057\u307e\u3059\u304c\u3001\u30ed\u30fc\u30ab\u30eb\u30b5\u30fc\u30d0\u30fc\u306f\u3042\u308a\u307e\u305b\u3093 ERR_DS_DISCONNECTED_DURING_HANDSHAKE_178=\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30b5\u30fc\u30d0\u30fc %s \u306f\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u30fc %s \u306b\u63a5\u7d9a\u3057\u3088\u3046\u3068\u3057\u307e\u3057\u305f\u304c\u3001\u30cf\u30f3\u30c9\u30b7\u30a7\u30fc\u30af\u30d5\u30a7\u30fc\u30ba\u3067\u63a5\u7d9a\u89e3\u9664\u3055\u308c\u307e\u3057\u305f ERR_RS_DISCONNECTED_DURING_HANDSHAKE_179=\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u30fc %s \u306f\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u30fc %s \u306b\u63a5\u7d9a\u3057\u3088\u3046\u3068\u3057\u307e\u3057\u305f\u304c\u3001\u30cf\u30f3\u30c9\u30b7\u30a7\u30fc\u30af\u30d5\u30a7\u30fc\u30ba\u3067\u63a5\u7d9a\u89e3\u9664\u3055\u308c\u307e\u3057\u305f WARN_DS_DISCONNECTED_DURING_HANDSHAKE_178=\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30b5\u30fc\u30d0\u30fc %s \u306f\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u30fc %s \u306b\u63a5\u7d9a\u3057\u3088\u3046\u3068\u3057\u307e\u3057\u305f\u304c\u3001\u30cf\u30f3\u30c9\u30b7\u30a7\u30fc\u30af\u30d5\u30a7\u30fc\u30ba\u3067\u63a5\u7d9a\u89e3\u9664\u3055\u308c\u307e\u3057\u305f WARN_RS_DISCONNECTED_DURING_HANDSHAKE_179=\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u30fc %s \u306f\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u30fc %s \u306b\u63a5\u7d9a\u3057\u3088\u3046\u3068\u3057\u307e\u3057\u305f\u304c\u3001\u30cf\u30f3\u30c9\u30b7\u30a7\u30fc\u30af\u30d5\u30a7\u30fc\u30ba\u3067\u63a5\u7d9a\u89e3\u9664\u3055\u308c\u307e\u3057\u305f NOTE_ERR_UNABLE_TO_ENABLE_ECL_VIRTUAL_ATTR_182=\u5916\u90e8\u66f4\u65b0\u5c65\u6b74\u30ed\u30b0\u306e\u4eee\u60f3\u5c5e\u6027\u3092\u8aad\u307f\u8fbc\u307f\u4e2d\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f: \u5c5e\u6027: %s\u3001\u30a8\u30e9\u30fc: %s NOTE_ERR_UNABLE_TO_ENABLE_ECL_183=\u5916\u90e8\u66f4\u65b0\u5c65\u6b74\u30ed\u30b0\u3092\u6709\u52b9\u306b\u3059\u308b\u3068\u304d\u306b\u3001%s \u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f: %s ERR_RESYNC_REQUIRED_UNKNOWN_DOMAIN_IN_PROVIDED_COOKIE_185=\u5b8c\u5168\u306a\u518d\u540c\u671f\u304c\u5fc5\u8981\u3067\u3059\u3002\u7406\u7531: \u63d0\u4f9b\u3055\u308c\u305f Cookie \u306b\u542b\u307e\u308c\u308b\u3001\u30ec\u30d7\u30ea\u30b1\u30fc\u30c8\u3055\u308c\u305f\u30c9\u30e1\u30a4\u30f3 %s \u304c\u4e0d\u660e\u3067\u3059\u3002Cookie <%s> opendj-server-legacy/src/messages/org/opends/messages/replication_zh_CN.properties
@@ -12,6 +12,7 @@ # # Copyright 2006-2010 Sun Microsystems, Inc. # Portions Copyright 2011-2016 ForgeRock AS. # Portions Copyright 2026 3A Systems, LLC. # This file contains the primary Directory Server configuration. It must not # be directly edited while the server is online. The server configuration @@ -146,8 +147,8 @@ ERR_FRACTIONAL_COULD_NOT_RETRIEVE_CONFIG_175=\u65e0\u6cd5\u68c0\u7d22\u4e0e\u6761\u76ee %s \u5339\u914d\u7684\u590d\u5236\u57df\u914d\u7f6e NOTE_ERR_LDIF_IMPORT_FRACTIONAL_BAD_DATA_SET_176=\u7531\u4e8e\u90e8\u5206\u914d\u7f6e\u4e0d\u4e00\u81f4\uff0c\u56e0\u6b64\u5bfc\u5165\u540e\u7f00 %s \u6570\u636e\u7684 LDIF \u5bfc\u5165\u5df2\u505c\u6b62\uff1a\u5bfc\u5165\u7684\u6570\u636e\u96c6\u4e0e\u672c\u5730\u670d\u52a1\u5668\u7684\u90e8\u5206\u914d\u7f6e\u4e0d\u540c NOTE_ERR_LDIF_IMPORT_FRACTIONAL_DATA_SET_IS_FRACTIONAL_177=\u7531\u4e8e\u90e8\u5206\u914d\u7f6e\u4e0d\u4e00\u81f4\uff0c\u56e0\u6b64\u5bfc\u5165\u540e\u7f00 %s \u6570\u636e\u7684 LDIF \u5bfc\u5165\u5df2\u505c\u6b62\uff1a\u5bfc\u5165\u7684\u6570\u636e\u96c6\u5305\u542b\u672c\u5730\u670d\u52a1\u5668\u6240\u6ca1\u6709\u7684\u4e00\u4e9b\u90e8\u5206\u914d\u7f6e ERR_DS_DISCONNECTED_DURING_HANDSHAKE_178=\u76ee\u5f55\u670d\u52a1\u5668 %s \u5c1d\u8bd5\u8fde\u63a5\u5230\u590d\u5236\u670d\u52a1\u5668 %s\uff0c\u4f46\u662f\u5728\u63e1\u624b\u9636\u6bb5\u4e2d\u65ad\u5f00\u8fde\u63a5 ERR_RS_DISCONNECTED_DURING_HANDSHAKE_179=\u590d\u5236\u670d\u52a1\u5668 %s \u5c1d\u8bd5\u8fde\u63a5\u5230\u590d\u5236\u670d\u52a1\u5668 %s\uff0c\u4f46\u662f\u5728\u63e1\u624b\u9636\u6bb5\u4e2d\u65ad\u5f00\u8fde\u63a5 WARN_DS_DISCONNECTED_DURING_HANDSHAKE_178=\u76ee\u5f55\u670d\u52a1\u5668 %s \u5c1d\u8bd5\u8fde\u63a5\u5230\u590d\u5236\u670d\u52a1\u5668 %s\uff0c\u4f46\u662f\u5728\u63e1\u624b\u9636\u6bb5\u4e2d\u65ad\u5f00\u8fde\u63a5 WARN_RS_DISCONNECTED_DURING_HANDSHAKE_179=\u590d\u5236\u670d\u52a1\u5668 %s \u5c1d\u8bd5\u8fde\u63a5\u5230\u590d\u5236\u670d\u52a1\u5668 %s\uff0c\u4f46\u662f\u5728\u63e1\u624b\u9636\u6bb5\u4e2d\u65ad\u5f00\u8fde\u63a5 NOTE_ERR_UNABLE_TO_ENABLE_ECL_VIRTUAL_ATTR_182=\u4e3a\u5916\u90e8\u66f4\u6539\u65e5\u5fd7\u52a0\u8f7d\u865a\u62df\u5c5e\u6027\u65f6\u51fa\u73b0\u9519\u8bef\uff1a\u5c5e\u6027: %s\uff0c\u9519\u8bef: %s NOTE_ERR_UNABLE_TO_ENABLE_ECL_183=\u542f\u7528\u5916\u90e8\u66f4\u6539\u65e5\u5fd7\u65f6\u5728 %s \u4e2d\u51fa\u73b0\u9519\u8bef: %s ERR_RESYNC_REQUIRED_UNKNOWN_DOMAIN_IN_PROVIDED_COOKIE_185=\u8981\u6c42\u5b8c\u5168\u518d\u540c\u6b65\u3002\u539f\u56e0\uff1a\u63d0\u4f9b\u7684 cookie \u5305\u542b\u672a\u77e5\u7684\u590d\u5236\u57df %s\u3002Cookie <%s> opendj-server-legacy/src/test/java/org/opends/server/replication/server/HandshakeAbortSeverityTest.java
New file @@ -0,0 +1,846 @@ /* * The contents of this file are subject to the terms of the Common Development and * Distribution License (the License). You may not use this file except in compliance with the * License. * * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the * specific language governing permission and limitations under the License. * * When distributing Covered Software, include this CDDL Header Notice in each file and include * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions copyright [year] [name of copyright owner]". * * Copyright 2026 3A Systems, LLC. */ package org.opends.server.replication.server; import static org.assertj.core.api.Assertions.assertThat; import static org.opends.messages.ReplicationMessages.*; import static org.opends.server.TestCaseUtils.*; import static org.testng.Assert.*; import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.Field; import java.net.ServerSocket; import java.net.Socket; import java.util.Collections; import java.util.List; import java.util.TreeSet; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLSocket; import org.forgerock.i18n.LocalizableMessage; import org.forgerock.opendj.ldap.DN; import org.opends.server.TestCaseUtils; import org.opends.server.replication.ReplicationTestCase; import org.opends.server.replication.common.DSInfo; import org.opends.server.replication.common.RSInfo; import org.opends.server.replication.common.ServerState; import org.opends.server.replication.protocol.ReplServerStartMsg; import org.opends.server.replication.protocol.ReplSessionSecurity; import org.opends.server.replication.protocol.ReplicationMsg; import org.opends.server.replication.protocol.ServerStartMsg; import org.opends.server.replication.protocol.Session; import org.opends.server.replication.protocol.TopologyMsg; import org.testng.annotations.Test; /** * Tests for issue #1241: the severity an aborted replication handshake is logged with. * <p> * {@code abortStart} used to log the reason of every abort at ERROR, so a peer which * restarts under load reads as an error of every server it was handshaking with: the * listen thread which gives way to a cross connection * ({@code WARN_TIMEOUT_WHEN_CROSS_CONNECTION}, a warning by its own name), and the * handshake its peer left ({@code *_DISCONNECTED_DURING_HANDSHAKE}, where a peer which gave * up on its own timeout logs that timeout at WARNING itself). Both are warnings now, in * either phase of the handshake, and so is a peer which stays silent past the connection * timeout: this server gives up on it as it does on a peer which went away. * <p> * What this server rejects, a peer which breaks the protocol, a frame which does not decode * and a frame too large to allocate are still errors. Each call site picks the severity of its * own abort, so a case pins only the one it reaches: the cases which say so reach every * {@code abortStart} of a reason in the handshakes of a replication server and of a data * server but two, so that logging an abort as a warning is not a way to pass them. The two are * the {@code catch (Exception)} of {@code startFromRemoteRS()}, which a peer reaches only * through a failure of the JDK (a topology without the replication server which sent it fails * on {@code get(0)}), and the {@code catch (DirectoryException)} of * {@code startFromRemoteDS()}, which no peer reaches with a message. * <p> * Each test drives one handler on a session pair of its own, as the listen thread or the * connect thread of the server would, and reads the severity off the record of the reason. * The peer which goes away aborts its end of the session rather than closing it: * {@code Session.close()} publishes a {@code StopMsg}, which is a peer ending the handshake * in order, and is aborted on silently. */ @SuppressWarnings("javadoc") public class HandshakeAbortSeverityTest extends ReplicationTestCase { private static final int SOCKET_TIMEOUT_MS = 30000; /** The connection timeout of a handshake whose peer stays silent: nothing comes before it. */ private static final int SILENT_PEER_TIMEOUT_MS = 500; /** Longer than the longest wait of {@code lockDomainWithTimeout()}, which is 8 seconds. */ private static final long LOCK_TIMEOUT_MS = 30000; private static final int REMOTE_DS_ID = 61; private static final int REMOTE_RS_ID = 62; private static final String REMOTE_RS_URL = "127.0.0.1:8989"; /** What {@code Session.receive()} reports of the frame {@link #sendTooLargeFrameHeader} announces. */ private static final LocalizableMessage PACKET_TOO_LARGE = LocalizableMessage.raw( "Packet too large, can't allocate " + Integer.MAX_VALUE + " bytes."); /** * The listen thread waits a random 3 to 8 seconds for the domain lock, so that of two * replication servers connecting to each other at the same time one gives way: the * connect thread holding the lock here is the one which goes on. */ @Test public void aCrossConnectionGivenWayToIsAWarning() throws Exception { final int rsId = 8261; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityCrossDb", rsId, (replicationServer, remoteEnd, session) -> { final ReplicationServerDomain domain = replicationServer.getReplicationServerDomain(baseDN, true); final ReplServerStartMsg startMsg = (ReplServerStartMsg) sendThrough(remoteEnd, session, replServerStartMsg(baseDN)); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); // The lock is held by a thread of its own, as the connect thread holds it: the // domain lock is reentrant, so the thread of the handshake would take it. final ExecutorService lockHolder = Executors.newSingleThreadExecutor(); final List<String> records; try { final CountDownLatch locked = new CountDownLatch(1); final CountDownLatch handshakeDone = new CountDownLatch(1); final Future<Void> holding = lockHolder.submit(() -> { domain.lock(); try { locked.countDown(); handshakeDone.await(); } finally { domain.release(); } return null; }); assertTrue(locked.await(LOCK_TIMEOUT_MS, TimeUnit.MILLISECONDS), "the domain lock should have been taken"); try { records = errorLogRecordsOf(() -> { handler.startFromRemoteRS(startMsg); return null; }); } finally { handshakeDone.countDown(); } holding.get(LOCK_TIMEOUT_MS, TimeUnit.MILLISECONDS); } finally { lockHolder.shutdownNow(); } assertThat(recordOf(records, WARN_TIMEOUT_WHEN_CROSS_CONNECTION.get( baseDN, REMOTE_RS_ID, session.getReadableRemoteAddress(), rsId))) .as("giving way to a cross connection is a warning, as its message says") .contains("severity=WARNING"); assertThat(countRecordsOf(records, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(REMOTE_RS_ID, rsId).toString())) .as("the handshake ends where this server gives way to the cross connection") .isZero(); }); } @Test public void aDataServerGoneDuringTheHandshakeIsAWarning() throws Exception { final int rsId = 8262; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityDSDb", rsId, (replicationServer, remoteEnd, session) -> { final ServerStartMsg startMsg = (ServerStartMsg) sendThrough(remoteEnd, session, serverStartMsg(baseDN)); remoteEnd.abort(new IOException("the directory server gave up on the handshake")); final DataServerHandler handler = new DataServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { handler.startFromRemoteDS(startMsg); return null; }); assertThat(recordOf(records, WARN_DS_DISCONNECTED_DURING_HANDSHAKE.get(REMOTE_DS_ID, rsId))) .as("a directory server which went away during the handshake is a warning") .contains("severity=WARNING"); assertAbortedHandshakeWentNoFurther(session); }); } /** * A peer which stays connected and says nothing past the connection timeout is given up on * as one which went away. */ @Test public void aDataServerSilentDuringTheHandshakeIsAWarning() throws Exception { final int rsId = 8274; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeveritySilentDSDb", rsId, (replicationServer, remoteEnd, session) -> { final ServerStartMsg startMsg = (ServerStartMsg) sendThrough(remoteEnd, session, serverStartMsg(baseDN)); session.setSoTimeout(SILENT_PEER_TIMEOUT_MS); final DataServerHandler handler = new DataServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { handler.startFromRemoteDS(startMsg); return null; }); assertThat(recordOf(records, WARN_DS_DISCONNECTED_DURING_HANDSHAKE.get(REMOTE_DS_ID, rsId))) .as("a directory server silent past the connection timeout is a warning") .contains("severity=WARNING"); assertAbortedHandshakeWentNoFurther(session); }); } /** * A directory server which sends something else where its start session message is due * breaks the protocol, and that is still an error. */ @Test public void aDataServerWhichSendsNoStartSessionIsAnError() throws Exception { final int rsId = 8275; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityNoStartSessionDb", rsId, (replicationServer, remoteEnd, session) -> { final ServerStartMsg startMsg = (ServerStartMsg) sendThrough(remoteEnd, session, serverStartMsg(baseDN)); // Published ahead of the start message it answers: the session reads it all the same. remoteEnd.publish(serverStartMsg(baseDN)); final DataServerHandler handler = new DataServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { handler.startFromRemoteDS(startMsg); return null; }); assertThat(recordOf(records, LocalizableMessage.raw("Protocol error: StartSessionMsg required."))) .as("a directory server which breaks the protocol is an error") .contains("severity=ERROR"); assertAbortedHandshakeWentNoFurther(session); }); } @Test public void aReplicationServerGoneDuringTheHandshakeItStartedIsAWarning() throws Exception { final int rsId = 8263; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityFromRSDb", rsId, (replicationServer, remoteEnd, session) -> { final ReplServerStartMsg startMsg = (ReplServerStartMsg) sendThrough(remoteEnd, session, replServerStartMsg(baseDN)); remoteEnd.abort(new IOException("the replication server gave up on the handshake")); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { handler.startFromRemoteRS(startMsg); return null; }); assertThat(recordOf(records, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(REMOTE_RS_ID, rsId))) .as("a replication server which went away during the handshake it started is a warning") .contains("severity=WARNING"); }); } @Test public void aReplicationServerGoneDuringTheHandshakeThisServerStartedIsAWarning() throws Exception { final int rsId = 8264; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityToRSDb", rsId, (replicationServer, remoteEnd, session) -> { remoteEnd.abort(new IOException("the replication server went away")); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { assertFalse(handler.connect(baseDN, true), "the peer went away, so this is no session"); return null; }); assertThat(recordOf(records, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(rsId, session.getReadableRemoteAddress()))) .as("a replication server which went away during the handshake this server started" + " is a warning") .contains("severity=WARNING"); }); } /** * What the connect thread of a cross connection reads, when the listen thread of its peer * waits for the domain lock longer than the connection timeout: up to 8 seconds against 5 by * default. */ @Test public void aReplicationServerSilentDuringTheHandshakeThisServerStartedIsAWarning() throws Exception { final int rsId = 8276; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeveritySilentToRSDb", rsId, (replicationServer, remoteEnd, session) -> { session.setSoTimeout(SILENT_PEER_TIMEOUT_MS); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { assertFalse(handler.connect(baseDN, true), "the peer did not answer, so this is no session"); return null; }); assertThat(recordOf(records, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(rsId, session.getReadableRemoteAddress()))) .as("a replication server silent past the connection timeout is a warning") .contains("severity=WARNING"); }); } /** * The second phase of the handshake reads the topology of the peer through a method of its * own, which used to report every failure of the session as the error of a raw message. */ @Test public void aReplicationServerGoneBeforeItsTopologyInTheHandshakeItStartedIsAWarning() throws Exception { final int rsId = 8266; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityFromRSTopoDb", rsId, (replicationServer, remoteEnd, session) -> { final ReplServerStartMsg startMsg = (ReplServerStartMsg) sendThrough(remoteEnd, session, replServerStartMsg(baseDN)); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { // Gone once it has read the start message of this server: that is sent, and the // handshake waits for the topology of the peer. goneAfterReading(1, remoteEnd, () -> { handler.startFromRemoteRS(startMsg); return null; }); return null; }); assertThat(recordOf(records, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(REMOTE_RS_ID, rsId))) .as("a replication server which went away before it sent its topology is a warning") .contains("severity=WARNING"); }); } /** * The case above for a peer which stays silent: the second phase used to log the timeout * as the error of the raw "Read timed out". */ @Test public void aReplicationServerSilentBeforeItsTopologyInTheHandshakeItStartedIsAWarning() throws Exception { final int rsId = 8277; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeveritySilentFromRSTopoDb", rsId, (replicationServer, remoteEnd, session) -> { final ReplServerStartMsg startMsg = (ReplServerStartMsg) sendThrough(remoteEnd, session, replServerStartMsg(baseDN)); session.setSoTimeout(SILENT_PEER_TIMEOUT_MS); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { handler.startFromRemoteRS(startMsg); return null; }); assertThat(recordOf(records, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(REMOTE_RS_ID, rsId))) .as("a replication server silent past the connection timeout before it sent its topology" + " is a warning") .contains("severity=WARNING"); }); } @Test public void aReplicationServerGoneBeforeItsTopologyInTheHandshakeThisServerStartedIsAWarning() throws Exception { final int rsId = 8267; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityToRSTopoDb", rsId, (replicationServer, remoteEnd, session) -> { // Published ahead of the start message it answers: the session reads it all the same. remoteEnd.publish(replServerStartMsg(baseDN)); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { // Gone once it has read the start message and the topology of this server: both // are sent, and the handshake waits for the topology of the peer. assertFalse(goneAfterReading(2, remoteEnd, () -> handler.connect(baseDN, true)), "the peer went away, so this is no session"); return null; }); assertThat(recordOf(records, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(rsId, session.getReadableRemoteAddress()))) .as("a replication server which went away before it sent its topology is a warning") .contains("severity=WARNING"); }); } /** * A peer which answers the start message of this server with something else breaks the * protocol, and that is still an error: of the aborts, only the peer going away and the * cross connection are warnings. */ @Test public void aPeerWhichBreaksTheProtocolIsStillAnError() throws Exception { final int rsId = 8265; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityProtocolDb", rsId, (replicationServer, remoteEnd, session) -> { // Published ahead of the start message it answers: the session reads it all the same. remoteEnd.publish(new TopologyMsg( Collections.<DSInfo> emptyList(), Collections.<RSInfo> emptyList())); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { assertFalse(handler.connect(baseDN, true), "the peer broke the protocol, so this is no session"); return null; }); assertThat(recordOf(records, ERR_REPLICATION_PROTOCOL_MESSAGE_TYPE.get( TopologyMsg.class.getCanonicalName(), "ReplServerStartMsg"))) .as("a peer which breaks the protocol is an error") .contains("severity=ERROR"); }); } /** * The case above in the second phase, which is aborted from the {@code DirectoryException} * arm of the handshake: a peer which sends its start message again where its topology is * due. */ @Test public void aPeerWhichSendsNoTopologyInTheHandshakeItStartedIsAnError() throws Exception { final int rsId = 8268; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityFromRSNoTopoDb", rsId, (replicationServer, remoteEnd, session) -> { final ReplServerStartMsg startMsg = (ReplServerStartMsg) sendThrough(remoteEnd, session, replServerStartMsg(baseDN)); remoteEnd.publish(replServerStartMsg(baseDN)); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { handler.startFromRemoteRS(startMsg); return null; }); assertThat(recordOf(records, ERR_REPLICATION_PROTOCOL_MESSAGE_TYPE.get( ReplServerStartMsg.class.getCanonicalName(), "TopologyMsg"))) .as("a peer which breaks the protocol is an error") .contains("severity=ERROR"); }); } @Test public void aPeerWhichSendsNoTopologyInTheHandshakeThisServerStartedIsAnError() throws Exception { final int rsId = 8269; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityToRSNoTopoDb", rsId, (replicationServer, remoteEnd, session) -> { // Published ahead of the messages they answer: the session reads them all the same. remoteEnd.publish(replServerStartMsg(baseDN)); remoteEnd.publish(replServerStartMsg(baseDN)); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { assertFalse(handler.connect(baseDN, true), "the peer broke the protocol, so this is no session"); return null; }); assertThat(recordOf(records, ERR_REPLICATION_PROTOCOL_MESSAGE_TYPE.get( ReplServerStartMsg.class.getCanonicalName(), "TopologyMsg"))) .as("a peer which breaks the protocol is an error") .contains("severity=ERROR"); }); } /** * A rejection by this server: a peer which names the server id of a replication server the * domain already holds a session with, at another address. */ @Test public void aServerIdAnotherReplicationServerHoldsIsAnError() throws Exception { final int rsId = 8270; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityDuplicateDb", rsId, (replicationServer, firstEnd, first) -> { // The first peer completes its handshake, so that the domain holds it: its topology is // published ahead of the start message of this server it answers. final ReplServerStartMsg firstStartMsg = (ReplServerStartMsg) sendThrough(firstEnd, first, replServerStartMsg(baseDN)); firstEnd.publish(new TopologyMsg(Collections.<DSInfo> emptyList(), Collections.singletonList(new RSInfo(REMOTE_RS_ID, REMOTE_RS_URL, -1, (byte) 1, 1)))); final ReplicationServerHandler registered = new ReplicationServerHandler(first, 100, replicationServer, 100); registered.startFromRemoteRS(firstStartMsg); // The precondition of the case rather than an assumption. assertThat(replicationServer.getReplicationServerDomain(baseDN).getConnectedRSs().get(REMOTE_RS_ID)) .as("the first peer should hold its session") .isSameAs(registered); try (ServerSocket listen = TestCaseUtils.bindFreePort()) { listen.setSoTimeout(SOCKET_TIMEOUT_MS); final Session[] sessionPair = connectSessionPair(listen, getReplSessionSecurity()); try (Session remoteEnd = sessionPair[0]; Session session = sessionPair[1]) { final ReplServerStartMsg startMsg = (ReplServerStartMsg) sendThrough(remoteEnd, session, replServerStartMsg(baseDN, "127.0.0.1:8990")); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { handler.startFromRemoteRS(startMsg); return null; }); assertThat(recordOf(records, ERR_DUPLICATE_REPLICATION_SERVER_ID.get( replicationServer.getMonitorInstanceName(), registered.getServerAddressURL(), handler.getServerAddressURL(), REMOTE_RS_ID))) .as("a peer this server rejects is an error") .contains("severity=ERROR"); } } }); } /** * A frame too large to allocate is not the peer going away, though the session reports it * as an {@code IOException}: either the peer breaks the protocol, a handshake message being * nowhere near that size, or this server has no heap to spare it, and both are errors. */ @Test public void aFrameTooLargeForTheStartMessageOfTheHandshakeThisServerStartedIsAnError() throws Exception { final int rsId = 8271; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityToRSFrameDb", rsId, (replicationServer, remoteEnd, session) -> { sendTooLargeFrameHeader(remoteEnd); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { assertFalse(handler.connect(baseDN, true), "the frame cannot be read, so this is no session"); return null; }); assertTooLargeFrameIsAnError(records, session, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(rsId, session.getReadableRemoteAddress())); }); } /** * A frame which does not decode fails in {@code Session.receive()} with neither an * {@code IOException} nor a {@code DirectoryException}, and is aborted on from the * {@code catch (Exception)} of the handshake, still as an error. */ @Test public void aFrameWhichDoesNotDecodeInTheHandshakeThisServerStartedIsAnError() throws Exception { final int rsId = 8278; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityToRSUndecodableDb", rsId, (replicationServer, remoteEnd, session) -> { // A frame of one byte, a message type which no message has. sendRaw(remoteEnd, new byte[] { '0', '0', '0', '0', '0', '0', '0', '1', 0 }); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { assertFalse(handler.connect(baseDN, true), "the frame cannot be decoded, so this is no session"); return null; }); assertThat(recordOf(records, LocalizableMessage.raw("received message with unknown type"))) .as("a frame which does not decode is an error") .contains("severity=ERROR"); assertThat(countRecordsOf(records, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(rsId, session.getReadableRemoteAddress()) .toString())) .as("a frame which does not decode is not the peer going away") .isZero(); }); } @Test public void aFrameTooLargeForTheTopologyInTheHandshakeItStartedIsAnError() throws Exception { final int rsId = 8272; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityFromRSFrameDb", rsId, (replicationServer, remoteEnd, session) -> { final ReplServerStartMsg startMsg = (ReplServerStartMsg) sendThrough(remoteEnd, session, replServerStartMsg(baseDN)); sendTooLargeFrameHeader(remoteEnd); final ReplicationServerHandler handler = new ReplicationServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { handler.startFromRemoteRS(startMsg); return null; }); assertTooLargeFrameIsAnError(records, session, WARN_RS_DISCONNECTED_DURING_HANDSHAKE.get(REMOTE_RS_ID, rsId)); }); } @Test public void aFrameTooLargeForTheStartSessionOfADataServerIsAnError() throws Exception { final int rsId = 8273; final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); runCase("handshakeAbortSeverityDSFrameDb", rsId, (replicationServer, remoteEnd, session) -> { final ServerStartMsg startMsg = (ServerStartMsg) sendThrough(remoteEnd, session, serverStartMsg(baseDN)); sendTooLargeFrameHeader(remoteEnd); final DataServerHandler handler = new DataServerHandler(session, 100, replicationServer, 100); final List<String> records = errorLogRecordsOf(() -> { handler.startFromRemoteDS(startMsg); return null; }); assertTooLargeFrameIsAnError(records, session, WARN_DS_DISCONNECTED_DURING_HANDSHAKE.get(REMOTE_DS_ID, rsId)); assertAbortedHandshakeWentNoFurther(session); }); } /** One case: the replication server under test, and a session pair to it. */ private interface HandshakeCase { void run(ReplicationServer replicationServer, Session remoteEnd, Session session) throws Exception; } /** * Runs the provided case on a replication server of its own and a session pair to it, * which are torn down once it ran. */ private void runCase(String dbName, int rsId, HandshakeCase handshakeCase) throws Exception { ReplicationServer replicationServer = null; try (ServerSocket listen = TestCaseUtils.bindFreePort()) { listen.setSoTimeout(SOCKET_TIMEOUT_MS); replicationServer = newReplicationServer(dbName, rsId); final Session[] sessionPair = connectSessionPair(listen, getReplSessionSecurity()); try (Session remoteEnd = sessionPair[0]; Session session = sessionPair[1]) { handshakeCase.run(replicationServer, remoteEnd, session); } } finally { removeQuietly(replicationServer); } } /** * Runs the provided handshake on a thread of its own, as the listen thread or the connect * thread of the server would, while the remote end reads the provided number of messages * and goes away: the handshake then fails on what it waits for next, rather than on a * message it sends. */ private static <T> T goneAfterReading(int messages, Session remoteEnd, Callable<T> handshake) throws Exception { final ExecutorService handshakeThread = Executors.newSingleThreadExecutor(); try { final Future<T> done = handshakeThread.submit(handshake); for (int i = 0; i < messages; i++) { remoteEnd.receive(); } remoteEnd.abort(new IOException("the replication server went away")); return done.get(SOCKET_TIMEOUT_MS, TimeUnit.MILLISECONDS); } finally { handshakeThread.shutdownNow(); } } /** * Writes the length header of a frame of {@link Integer#MAX_VALUE} bytes from the remote * end, and nothing after it: more than any array can hold, so the local end fails to * allocate it whatever its heap. The session writes no frame it did not encode itself, so * the header goes to the socket under it. */ private static void sendTooLargeFrameHeader(Session remoteEnd) throws Exception { sendRaw(remoteEnd, String.format("%08x", Integer.MAX_VALUE).getBytes()); } /** Writes the provided bytes from the remote end to the socket under it, as they are. */ private static void sendRaw(Session remoteEnd, byte[] bytes) throws Exception { final Field secureSocket = Session.class.getDeclaredField("secureSocket"); secureSocket.setAccessible(true); final OutputStream output = ((SSLSocket) secureSocket.get(remoteEnd)).getOutputStream(); output.write(bytes); output.flush(); } private static void assertTooLargeFrameIsAnError(List<String> records, Session session, LocalizableMessage disconnected) { final String record = recordOf(records, PACKET_TOO_LARGE); assertThat(record) .as("a frame too large to allocate is an error") .contains("severity=ERROR"); assertThat(record) .as("the record of a frame too large to allocate names the peer which sent it") .contains("Peer: " + session.getReadableRemoteAddress()); assertThat(countRecordsOf(records, disconnected.toString())) .as("a frame too large to allocate is not the peer going away") .isZero(); } /** * Asserts that the handshake of a data server ended where it was aborted: only * {@code finalizeStart()} starts the thread of the session, once the handler is registered * with the domain. Read off the thread rather than off the domain, which the reader of a * handler started on a closed session may have unregistered it from already. */ private static void assertAbortedHandshakeWentNoFurther(Session session) { assertThat(session.getState()) .as("a handshake which was aborted starts no session thread") .isEqualTo(Thread.State.NEW); } private ReplicationServer newReplicationServer(String dbName, int rsId) throws Exception { return new ReplicationServer(new ReplServerFakeConfiguration( TestCaseUtils.findFreePort(), dbName, 0, rsId, 0, 100, new TreeSet<String>())); } private ServerStartMsg serverStartMsg(DN baseDN) { return new ServerStartMsg(REMOTE_DS_ID, "127.0.0.1:1389", baseDN, 100, 0, new ServerState(), -1, true, (byte) 1); } private ReplServerStartMsg replServerStartMsg(DN baseDN) { return replServerStartMsg(baseDN, REMOTE_RS_URL); } /** * Returns the start message of a fake peer replication server. * <p> * A generation id of -1 leaves the one of the domain alone, and the session stays * encrypted, so that neither end has to leave the SSL session for the handshake to go on. */ private ReplServerStartMsg replServerStartMsg(DN baseDN, String serverURL) { return new ReplServerStartMsg(REMOTE_RS_ID, serverURL, baseDN, 100, new ServerState(), -1, true, (byte) 1, 5000); } /** * Publishes the provided start message from the remote end and returns it as the local * end reads it, which is the message the listen thread hands to the handler: it carries * the protocol version of the session, which a message built here does not. */ private ReplicationMsg sendThrough(Session remoteEnd, Session session, ReplicationMsg startMsg) throws Exception { remoteEnd.publish(startMsg); return session.receive(); } /** Teardown must never mask the primary assertion failure. */ private void removeQuietly(ReplicationServer replicationServer) { try { remove(replicationServer); } catch (Exception ignored) { } } /** * Establishes a connected session pair over the given listen socket, as a * remote server connecting to the RS would. The TLS negotiation performed by * the session factories needs both ends handshaking at the same time, so the * client end runs on its own thread. * * @return the two sessions: the remote (client) end first, then the local * (server) end to hand to the handler under test */ private Session[] connectSessionPair(ServerSocket listenSocket, final ReplSessionSecurity security) throws Exception { final Socket clientSocket = new Socket("127.0.0.1", listenSocket.getLocalPort()); clientSocket.setTcpNoDelay(true); final ExecutorService executor = Executors.newSingleThreadExecutor(); try { final Future<Session> clientEnd = executor.submit( () -> security.createClientSession(clientSocket, SOCKET_TIMEOUT_MS)); final Socket serverSocket = listenSocket.accept(); serverSocket.setTcpNoDelay(true); final Session serverEnd = security.createServerSession(serverSocket, SOCKET_TIMEOUT_MS); assertNotNull(serverEnd, "could not create a session for the handler under test"); return new Session[] { clientEnd.get(SOCKET_TIMEOUT_MS, TimeUnit.MILLISECONDS), serverEnd }; } finally { executor.shutdown(); } } }