feat: 将架构改成支持中间两个server
This commit is contained in:
@@ -219,6 +219,46 @@ clean_log_directories() {
|
||||
remove_remote_log_dir "$peerb_ssh" "$peerb_log_dir" "peer-b"
|
||||
}
|
||||
|
||||
truncate_local_file() {
|
||||
local path="$1"
|
||||
local dir=""
|
||||
|
||||
dir="$(dirname "$path")"
|
||||
mkdir -p "$dir"
|
||||
: > "$path"
|
||||
}
|
||||
|
||||
truncate_remote_file() {
|
||||
local target="$1"
|
||||
local path="$2"
|
||||
local script=""
|
||||
|
||||
script="$(cat <<'EOF'
|
||||
set -euo pipefail
|
||||
|
||||
mkdir -p "$(dirname "$FILE_PATH")"
|
||||
: > "$FILE_PATH"
|
||||
EOF
|
||||
)"
|
||||
|
||||
run_remote_script "$target" "$script" "FILE_PATH=$path"
|
||||
}
|
||||
|
||||
reset_logs_after_probe() {
|
||||
log "resetting peer logs after connectivity probe"
|
||||
|
||||
rm -f "$local_peer_a_messages_log"
|
||||
truncate_local_file "$local_peer_a_stdout_log"
|
||||
truncate_local_file "$local_peer_a_latency_log"
|
||||
truncate_local_file "$local_peer_a_ts_debug_log"
|
||||
truncate_local_file "$local_peer_a_session_stats_log"
|
||||
|
||||
truncate_remote_file "$peerb_ssh" "$peerb_stdout_log"
|
||||
truncate_remote_file "$peerb_ssh" "$peerb_latency_log"
|
||||
truncate_remote_file "$peerb_ssh" "$peerb_ts_debug_log"
|
||||
truncate_remote_file "$peerb_ssh" "$peerb_session_stats_log"
|
||||
}
|
||||
|
||||
fetch_remote_peer_b_logs() {
|
||||
log "copying peer-b logs from $peerb_ssh:$peerb_log_dir to $local_log_dir"
|
||||
copy_remote_file_to_local "$peerb_ssh:$peerb_stdout_log" "$local_peer_b_stdout_log"
|
||||
@@ -562,6 +602,49 @@ EOF
|
||||
return 1
|
||||
}
|
||||
|
||||
probe_peer_b_to_local_peer_a() {
|
||||
local marker=""
|
||||
local command_line=""
|
||||
local quoted_command=""
|
||||
local script=""
|
||||
local start_time="$SECONDS"
|
||||
|
||||
marker="probe-$(date +%s)-$$"
|
||||
printf -v command_line 'text peer-a %s' "$marker"
|
||||
printf -v quoted_command '%q' "$command_line"
|
||||
|
||||
script="$(cat <<EOF
|
||||
set -euo pipefail
|
||||
|
||||
printf '%s\n' ${quoted_command} >> "\$COMMAND_FILE"
|
||||
EOF
|
||||
)"
|
||||
|
||||
log "probing peer-b -> peer-a message delivery before batch"
|
||||
run_remote_script "$peerb_ssh" "$script" "COMMAND_FILE=$peerb_command_file"
|
||||
|
||||
while (( SECONDS - start_time < ready_timeout )); do
|
||||
if [[ -f "$local_peer_a_messages_log" ]] && grep -Fq -- "$marker" "$local_peer_a_messages_log"; then
|
||||
log "peer-b -> peer-a probe succeeded"
|
||||
reset_logs_after_probe
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -n "$peer_a_pid" ]] && ! kill -0 "$peer_a_pid" 2>/dev/null; then
|
||||
log "local peer-a exited during connectivity probe"
|
||||
dump_local_log_head "$local_peer_a_stdout_log"
|
||||
return 1
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
|
||||
log "timed out waiting for peer-b -> peer-a probe delivery after ${ready_timeout}s"
|
||||
dump_local_log_head "$local_peer_a_stdout_log"
|
||||
dump_remote_log_head "$peerb_ssh" "$peerb_stdout_log" "peer-b"
|
||||
return 1
|
||||
}
|
||||
|
||||
run_remote_peer_b_batch() {
|
||||
local script=""
|
||||
local batch_commands=""
|
||||
@@ -804,6 +887,7 @@ inbox_dir_name="${log_prefix}inbox"
|
||||
|
||||
local_log_dir="$(join_path "$local_workdir" "$log_dir_name")"
|
||||
local_peer_a_inbox="$(join_path "$local_workdir" "$inbox_dir_name/peer-a")"
|
||||
local_peer_a_messages_log="$(join_path "$local_peer_a_inbox" "messages.log")"
|
||||
local_peer_a_stdout_log="$(join_path "$local_log_dir" "peer-a.stdout.log")"
|
||||
local_peer_a_latency_log="$(join_path "$local_log_dir" "peer-a-kcp-latency.jsonl")"
|
||||
local_peer_a_ts_debug_log="$(join_path "$local_log_dir" "peer-a-kcp-packet-debug.jsonl")"
|
||||
@@ -846,6 +930,7 @@ start_local_peer_a
|
||||
start_remote_peer_b
|
||||
wait_for_local_peer_a_ready
|
||||
wait_for_remote_peer_b_ready
|
||||
probe_peer_b_to_local_peer_a
|
||||
run_remote_peer_b_batch
|
||||
|
||||
log "batch send completed"
|
||||
|
||||
Reference in New Issue
Block a user