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
+38
View File
@@ -0,0 +1,38 @@
# 203 隔离测试环境(sbtest)
在 203 上搭一套和线上分开的测试环境,用来联机测试还没部署的服务端功能,比如 feature/ava2-unlock 里的戒指、护符和自动洗练。线上的 db、auth、CH1–4 和线上库只读取,不会被修改。
| 进程 | 端口 | 目录 | 二进制 |
|---|---|---|---|
| db | 15040 | `/usr/metin2/server/sbtest/db` | `db.switchbot` 的副本 |
| auth | 11040(P2P 12040) | `/usr/metin2/server/sbtest/auth` | `sbtest/game.switchbot` |
| channel5 | 13040(P2P 14040),地图 1 21 41 | `/usr/metin2/server/channel5/first` | `sbtest/game.switchbot` |
- 数据库:`player_sb` / `common_sb` / `account_sb` / `log_sb`,从线上库复制(用 `--default-character-set=binary` 复制,gb2312 角色名不会乱码),并导入 `../pendant/refine.sql`。
- proto:先复制线上的 `share/conf`,再用 `../ava2-items/install_items.py` 装入解锁后的 AVA2 物品,放在 `sbtest/share/conf`。
- channel5 原来的配置保存为 `CONFIG.livedb`,原来的 game 链接保存为 `game.livedb`。
## 搭建
先在 `/root/metin2-features-dev` 编译出 `bin/db.switchbot` 和 `bin/game.switchbot`,再在本机生成中文客户端(会顺带生成 `build/zh-locale/ava2-items/*.tsv`),然后:
```sh
scp build/zh-locale/ava2-items/{items,mobs}-server.tsv tools/server/ava2-items/install_items.py \
tools/server/pendant/refine.sql root@192.168.21.203:/usr/metin2/server/sbtest/stage/
scp tools/server/sbtest/*.sh root@192.168.21.203:/usr/metin2/server/sbtest/tools/
ssh root@192.168.21.203 sh /usr/metin2/server/sbtest/tools/setup.sh /usr/metin2/server/sbtest/stage
```
重新运行会删除并重新复制 `*_sb` 库,测试数据会丢失。复制前脚本会先停掉 channel5 并等 15 秒,让线上 db 把 channel5 上的玩家写回 MySQL。还在线上 db 缓存里没写回的物品不会被复制过去。
## 日常
- `restart.sh`:按 db、auth、channel5 的顺序重启。重启会清空 db 缓存,下次登录全部从 MySQL 读取。
- `rollback.sh`:停掉测试环境,把 channel5 改回线上 db 和原来的二进制。`*_sb` 库和 `sbtest/` 目录会保留。
- Mac 客户端:`mt_native_render --live-client build/zh-locale/Client --live-server 192.168.21.203:11040:13040 --login-screen`。zh 客户端带 ava2items 包,能显示中文。
- GM 发物品:`/item <vnum> <数量>`,单堆最多 200 个。
## 注意
- db 下线后要过一段时间才写回(`g_iLogoutSeconds`),物品缓存每 5 分钟写一次。要确认数据已经进了 MySQL,就查 `player_sb.item`,或者跑一次 `restart.sh`。
- 只有一个核心,跨核心换线测不了。
+23
View File
@@ -0,0 +1,23 @@
#!/bin/sh
# (Re)starts the sbtest cluster in order db, auth, channel5 (README.md). Restarting empties the db cache,
# so the next login reads everything from MySQL.
set -eu
R=/usr/metin2/server
T=$R/sbtest
C5=$R/channel5/first
grep -q '^DB_PORT: 15040' $C5/CONFIG || { echo "channel5 is not on the sbtest db; run setup.sh" >&2; exit 1; }
for d in $C5 $T/auth $T/db; do
[ -f $d/pid ] || continue
p=$(cat $d/pid)
kill -0 "$p" 2>/dev/null || continue
kill -1 "$p"
i=0; while kill -0 "$p" 2>/dev/null && [ $i -lt 40 ]; do sleep 1; i=$((i+1)); done
echo "$d stopped after ${i}s"
done
daemon -f sh -c "cd $T/db && exec ./db > stdout 2>&1"; sleep 6
daemon -f sh -c "cd $T/auth && exec ./auth > stdout 2>&1"; sleep 4
daemon -f sh -c "cd $C5 && exec ./game > stdout 2>&1"; sleep 12
sockstat -l | grep -E ':(15040|11040|12040|13040|14040) '
echo "live db/auth listening: $(sockstat -l | grep -c -E ':(15000|11000) ') (expect 2)"
+23
View File
@@ -0,0 +1,23 @@
#!/bin/sh
# Stops the sbtest cluster and puts channel5 back on the live db with the binary it had before setup.sh
# (README.md). The *_sb schemas and /usr/metin2/server/sbtest stay; setup.sh rebuilds them.
set -eu
R=/usr/metin2/server
T=$R/sbtest
C5=$R/channel5/first
[ -f $C5/CONFIG.livedb ] || { echo "no $C5/CONFIG.livedb; channel5 was never moved" >&2; exit 1; }
for d in $C5 $T/auth $T/db; do
[ -f $d/pid ] || continue
p=$(cat $d/pid)
kill -0 "$p" 2>/dev/null || continue
kill -1 "$p"
i=0; while kill -0 "$p" 2>/dev/null && [ $i -lt 40 ]; do sleep 1; i=$((i+1)); done
echo "$d stopped after ${i}s"
done
cp $C5/CONFIG.livedb $C5/CONFIG
[ -e $C5/game.livedb ] && { rm -f $C5/game; mv $C5/game.livedb $C5/game; }
daemon -f sh -c "cd $C5 && exec ./game > stdout 2>&1"; sleep 12
grep -E '^DB_PORT' $C5/CONFIG; ls -l $C5/game
sockstat -l | grep -E ':(13040) '
+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