Switchbot: sbtest isolated test cluster scripts + live test results

tools/server/sbtest/{setup,restart,rollback}.sh build and manage the isolated
203 test cluster (db :15040, auth :11040, channel5 on *_sb schemas with the
unlocked AVA2 protos). Docs record the channel5/sbtest switchbot results:
weapon, ring, talisman, relog (cache + MySQL), same-core warp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-16 23:03:07 +09:00
co-authored by Claude Opus 5.5
parent 99cf5514c3
commit 657e49e52a
6 changed files with 163 additions and 3 deletions
+70
View File
@@ -0,0 +1,70 @@
#!/bin/sh
# Builds the isolated test cluster on 203 (README.md): sbtest db :15040 + auth :11040, and channel5 moved onto it,
# all on *_sb copies of the live schemas. Live db / auth / CH1-4 and the live schemas are only read.
# Usage (on the server): sh setup.sh <stage dir>; the stage dir holds items-server.tsv, mobs-server.tsv,
# install_items.py (../ava2-items) and refine.sql (../pendant). A rerun drops and recopies the *_sb schemas.
set -eu
STAGE=$(cd "$1" && pwd)
R=/usr/metin2/server
T=$R/sbtest
DEV=${DEV:-/root/metin2-features-dev}
C5=$R/channel5/first
for f in items-server.tsv mobs-server.tsv install_items.py refine.sql; do [ -f "$STAGE/$f" ] || { echo "missing $STAGE/$f" >&2; exit 1; }; done
[ -x $DEV/bin/db.switchbot ] && [ -x $DEV/bin/game.switchbot ] || { echo "build db.switchbot / game.switchbot in $DEV first" >&2; exit 1; }
stop() # <dir>: SIGHUP the process in <dir>/pid and wait for it
{
[ -f "$1/pid" ] || return 0
p=$(cat "$1/pid")
kill -0 "$p" 2>/dev/null || return 0
kill -1 "$p"
i=0; while kill -0 "$p" 2>/dev/null && [ $i -lt 40 ]; do sleep 1; i=$((i+1)); done
echo "$1 stopped after ${i}s"
}
# 1. stop channel5 and an earlier sbtest cluster; the live db flushes channel5's players on logout
stop $C5; stop $T/auth; stop $T/db
sleep 15
# 2. copy the schemas (the binary connection charset keeps the gb2312 name bytes untouched)
for s in player common account log; do
mysql -uroot -e "DROP DATABASE IF EXISTS ${s}_sb; CREATE DATABASE ${s}_sb"
mysqldump -uroot --default-character-set=binary --routines --triggers --single-transaction $s | mysql -uroot --default-character-set=binary ${s}_sb
echo "$s -> ${s}_sb: $(mysql -uroot -N -e "select count(*) from information_schema.tables where table_schema='${s}_sb'") tables"
done
mysql -uroot --default-character-set=binary player_sb < $STAGE/refine.sql
echo "talisman refine rows: $(mysql -uroot -N -e 'select count(*) from player_sb.refine_proto where id between 440 and 499 and cost=50000')"
# 3. protos: live copies + the unlocked AVA2 rows
mkdir -p $T/share/conf
for f in item_proto item_names mob_proto mob_names; do cp $R/share/conf/$f.txt $T/share/conf/$f.txt; done
rm -rf $T/backup-conf
/usr/local/bin/python3.9 $STAGE/install_items.py $T $STAGE/items-server.tsv $T/backup-conf $STAGE/mobs-server.tsv
# 4. db
mkdir -p $T/db/log $T/db/cores
cp $DEV/bin/db.switchbot $T/db/db
for f in item_proto item_names mob_proto mob_names; do ln -sf ../share/conf/$f.txt $T/db/$f.txt; done
sed -e 's/^BIND_PORT = .*/BIND_PORT = 15040/' \
-e 's/ account metin2/ account_sb metin2/' -e 's/ common metin2/ common_sb metin2/' -e 's/ player metin2/ player_sb metin2/' \
$R/db/conf.txt > $T/db/conf.txt
# 5. auth
mkdir -p $T/auth/log $T/auth/cores $T/auth/mark
cp $DEV/bin/game.switchbot $T/game.switchbot
ln -sf ../game.switchbot $T/auth/auth
for d in data locale package; do ln -sfn ../../share/$d $T/auth/$d; done
sed -e 's/^HOSTNAME: .*/HOSTNAME: sbauth/' -e 's/^PORT: .*/PORT: 11040/' -e 's/^P2P_PORT: .*/P2P_PORT: 12040/' -e 's/^DB_PORT: .*/DB_PORT: 15040/' \
-e 's/password account$/password account_sb/' -e 's/password common$/password common_sb/' -e 's/password log$/password log_sb/' \
$R/auth/CONFIG > $T/auth/CONFIG
# 6. channel5 -> sbtest db (CONFIG.livedb + game.livedb keep the old setup for rollback.sh)
[ -f $C5/CONFIG.livedb ] || cp $C5/CONFIG $C5/CONFIG.livedb
[ -e $C5/game.livedb ] || cp -P $C5/game $C5/game.livedb
sed -e 's/^DB_PORT: .*/DB_PORT: 15040/' \
-e 's/password player$/password player_sb/' -e 's/password common$/password common_sb/' -e 's/password log$/password log_sb/' \
$C5/CONFIG.livedb > $C5/CONFIG
ln -sfn $T/game.switchbot $C5/game
# 7. start db, auth, channel5
sh $(dirname "$0")/restart.sh