Sit合并到prod #111
@@ -0,0 +1,25 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
export async function verifyConfigReadback(url, expectedContent, expectExists, options = {}) {
|
||||
const request = options.request || fetch;
|
||||
const attempts = options.attempts || 3;
|
||||
const delayMs = options.delayMs ?? 1000;
|
||||
const expectedHash = expectExists ? sha256(expectedContent) : null;
|
||||
|
||||
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
||||
const response = await request(url);
|
||||
const actual = await response.text();
|
||||
const matches = expectExists
|
||||
? response.ok && sha256(actual) === expectedHash
|
||||
: response.status === 404;
|
||||
if (matches) return true;
|
||||
if (attempt + 1 < attempts && delayMs > 0) {
|
||||
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function sha256(value) {
|
||||
return createHash('sha256').update(value ?? '', 'utf8').digest('hex');
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { verifyConfigReadback } from './nacos-readback.mjs';
|
||||
|
||||
test('retries a stale read until the restored config is visible', async () => {
|
||||
const responses = [
|
||||
new Response('old config', { status: 200 }),
|
||||
new Response('restored config', { status: 200 })
|
||||
];
|
||||
let calls = 0;
|
||||
|
||||
const verified = await verifyConfigReadback('http://nacos/config', 'restored config', true, {
|
||||
request: async () => responses[calls++],
|
||||
attempts: 3,
|
||||
delayMs: 0
|
||||
});
|
||||
|
||||
assert.equal(verified, true);
|
||||
assert.equal(calls, 2);
|
||||
});
|
||||
|
||||
test('fails closed when the config does not match after bounded retries', async () => {
|
||||
let calls = 0;
|
||||
const verified = await verifyConfigReadback('http://nacos/config', 'restored config', true, {
|
||||
request: async () => {
|
||||
calls += 1;
|
||||
return new Response('different config', { status: 200 });
|
||||
},
|
||||
attempts: 3,
|
||||
delayMs: 0
|
||||
});
|
||||
|
||||
assert.equal(verified, false);
|
||||
assert.equal(calls, 3);
|
||||
});
|
||||
|
||||
test('confirms deletion only after the config is absent', async () => {
|
||||
const verified = await verifyConfigReadback('http://nacos/config', null, false, {
|
||||
request: async () => new Response(null, { status: 404 }),
|
||||
attempts: 1,
|
||||
delayMs: 0
|
||||
});
|
||||
|
||||
assert.equal(verified, true);
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import { createHash } from 'node:crypto';
|
||||
import { readFile, readdir, rm } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { envName, recordsRoot, snapshotRoot, writeJson } from './release-store.mjs';
|
||||
import { verifyConfigReadback } from './nacos-readback.mjs';
|
||||
|
||||
const environment = envName(process.env.NACOS_ENVIRONMENT);
|
||||
const group = 'DEFAULT_GROUP';
|
||||
@@ -40,9 +41,8 @@ for (const target of targets) {
|
||||
? await fetch(`${base}/nacos/v1/cs/configs?accessToken=${encodeURIComponent(target.token)}`, { method: 'POST', body: new URLSearchParams({ dataId: entry.dataId, group, tenant: entry.namespace, type: 'yaml', content }) })
|
||||
: await fetch(`${base}/nacos/v1/cs/configs?${query}`, { method: 'DELETE' });
|
||||
if (!response.ok || (exists && (await response.text()).trim() !== 'true')) throw new Error(`回退失败:${target.id}/${entry.namespace}/${entry.dataId}`);
|
||||
const check = await fetch(`${base}/nacos/v1/cs/configs?${new URLSearchParams({ dataId: entry.dataId, group, tenant: entry.namespace, accessToken: target.token })}`);
|
||||
const actual = await check.text();
|
||||
if (exists ? (!check.ok || sha256(actual) !== sha256(content)) : check.status !== 404) throw new Error(`回退摘要校验失败:${target.id}/${entry.namespace}/${entry.dataId}`);
|
||||
const checkUrl = `${base}/nacos/v1/cs/configs?${new URLSearchParams({ dataId: entry.dataId, group, tenant: entry.namespace, accessToken: target.token })}`;
|
||||
if (!(await verifyConfigReadback(checkUrl, content, exists))) throw new Error(`回退摘要校验失败:${target.id}/${entry.namespace}/${entry.dataId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public interface OrderArtistReviewMapper extends BaseMapper<OrderArtistReviewDO>
|
||||
+ "AND p.is_delete = 0 AND p.front_visible = 1 AND p.moderation_status = 'APPROVED' "
|
||||
+ "AND s.is_delete = 0 AND s.status = 1 AND s.moderation_status = 'APPROVED' "
|
||||
+ "AND FIND_IN_SET(#{fileId}, REPLACE(COALESCE(r.image_file_ids, ''), ' ', '')) > 0")
|
||||
Long countPublicImageReference(@Param("reviewId") Long reviewId, @Param("fileId") Long fileId);
|
||||
Long countPublicImageReferenceByReviewId(@Param("reviewId") Long reviewId, @Param("fileId") Long fileId);
|
||||
|
||||
@Select("SELECT COUNT(1) FROM t_order_artist_review r "
|
||||
+ "LEFT JOIN t_product p ON p.id = r.product_id "
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.order.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class OrderArtistReviewMapperMappingTest {
|
||||
@Test
|
||||
void registersReviewScopedAndGlobalImageReferenceStatementsSeparately() {
|
||||
MybatisConfiguration configuration = new MybatisConfiguration();
|
||||
configuration.addMapper(OrderArtistReviewMapper.class);
|
||||
|
||||
String mapperName = OrderArtistReviewMapper.class.getName();
|
||||
assertTrue(configuration.hasStatement(mapperName + ".countPublicImageReferenceByReviewId"));
|
||||
assertTrue(configuration.hasStatement(mapperName + ".countPublicImageReference"));
|
||||
}
|
||||
}
|
||||
@@ -44,3 +44,12 @@
|
||||
## 发布边界
|
||||
|
||||
本记录只说明当前 dev 工作区的代码整改和静态验证,不代表 SIT 已上线。合并、发布、数据库检查和外部依赖验收由负责人按现有 `dev -> sit -> prod` 流程执行。
|
||||
|
||||
## 2026-11-02 SIT 首次启动恢复
|
||||
|
||||
- 根因:SIT `jayucloud_salon` 已提前导入冻结初始化 SQL,但没有 Flyway 成功版本记录。Core 按空库首次启动执行 V1,在 `t_balance` 已存在时失败;MySQL DDL 部分提交,Flyway 记录 V1 失败,后续启动因验证失败而退出。
|
||||
- 只读核对确认:失败前所有业务表均为 0 行,仅有 4 条初始化权益种子;没有店铺、预约或用户数据。处理前将整个 schema 导出到 MySQL 主机 `/root/codex-backups/salon-sit-initialization-20261102T2255.sql.gz`,通过 gzip 完整性检查,SHA-256 `4298bdbe7b451739aafe5369e3558fe9cf210eec725d8ae79830cc4f4073044f`。
|
||||
- 在上述备份和空业务数据确认后,只重建 `jayucloud_salon` schema,保留 `utf8mb4` / `utf8mb4_0900_ai_ci`;随后由当前已部署 Core 自动执行 Flyway V1–V12。12 个版本全部 `success=1`,schema 共 64 张表,初始化管理员 1 个、门店 0 个。
|
||||
- Core 与 Gateway systemd 均为 active,重启计数为 0;Core `181/health/check`、Gateway `180/health/check`、`https://sit.salon.yunail.art/`、`/health/check`、`/api/shop/list` 和 `https://sit.minio.yunail.art/minio/health/live` 均返回 HTTP 200。
|
||||
- 在 `E:\sshkey` 创建独立的 `sitapp` 和 `sitmysql` 密钥,分别安装到对应主机的 root authorized_keys,并验证别名登录;不记录私钥或服务器密码。
|
||||
- 本次恢复的是 SIT 当前已部署包的数据库初始化和服务启动,不代表重新运行了 Gitea 发布流水线,也没有合并或推送 `dev` 的两个本地提交。前端入口可访问,但未由本次操作更新前端包。
|
||||
|
||||
@@ -70,6 +70,7 @@ Nacos 发布流程应先保存目标环境快照,再发布全部 YAML,并从
|
||||
```
|
||||
|
||||
缺少该挂载时,Prepare、Deploy 和 Rollback 任务之间无法共享发布记录、配置快照和应用包。
|
||||
Nacos 回退同样按快照恢复后校验配置摘要;考虑到集群读写传播延迟,读回校验最多重试 3 次、间隔 1 秒,仍不匹配时继续失败关闭,不记录回退成功。
|
||||
|
||||
Salon DEV/SIT/PROD 的 Nacos `core.yaml` 启用 Flyway,并固定目标 schema 为 `jayucloud_salon`、关闭自动建库。当前 Spring Boot 2.7.18 管理的 Flyway Community 8.5.13 要求目标数据库为 MySQL 8.0 或更高兼容版本;MySQL 5.7 会在迁移开始前导致 Core 启动失败。Gitea 现有 SIT/生产自动部署会构建并校验 Core JAR 中包含 V1 迁移;首个 Core 节点启动时由 Flyway 在已存在的空库中执行迁移,健康检查通过后才继续发布下一个 Core 节点。工作流不直接连接数据库或执行 SQL;迁移使用应用连接的 Nacos 数据源凭据,因此该账号必须具备建表、索引、数据初始化及初始化脚本所需存储过程的权限。Flyway 禁用自动 baseline、禁用 clean,并校验已应用迁移;schema 必须预先存在且为空,非空或迁移失败时 Core 启动失败并停止后续节点。升级数据库版本后不要先手动执行完整初始化 SQL,应由 Flyway 在空 schema 执行 V1。应用回退不会回滚数据库,后续修复只能追加新版本迁移。
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# 项目变更记录
|
||||
|
||||
## 2026-11-02 Salon SIT Core 启动故障与 Mapper 映射修复
|
||||
|
||||
- 检查 Gitea Actions 部署运行 #245:MyBatis-Plus 的 `OrderArtistReviewMapper.countPublicImageReference` 重复映射提示来自 Java Mapper 中两个同名重载方法;将按审核 ID 查询的方法改为独立名称,并新增 Mapper statement 注册测试,避免全局文件引用查询被忽略。
|
||||
- 部署真正阻塞点是 Core 启动时 Flyway 校验发现数据库中已存在失败的 V1 初始化迁移记录,健康检查因此端口拒绝连接并以退出码 43 失败;该 Flyway 状态不是上述 MyBatis 日志触发的。
|
||||
- 自动回退运行 #246 在恢复 Nacos 后单次读回校验失败;回退脚本增加有界重试,并通过模拟短暂读旧值后读到新值的测试覆盖。
|
||||
- 当前本机 SSH 凭据无法登录 SIT Core/数据库主机,本次没有修改 SIT 数据库。修复 V1 前必须先读取失败记录的 `error_message` 并核对 V1 部分执行的表、索引和种子数据;确认后再按项目 Flyway 规则处理,禁止直接清库、baseline 或自动 repair。
|
||||
- 调整 `.gitea/scripts/rollback-nacos.mjs` 并新增 `.gitea/scripts/nacos-readback.mjs`、`.gitea/scripts/nacos-readback.test.mjs`;同步更新 `docs/scripts/运行与发布配置总说明.md`。本次无 SQL 变更;Mapper 改名不影响 `FrontendFileController` 使用的单参数全局查询。
|
||||
|
||||
# 2026-11-02 Gitea 工作流仓库域名统一
|
||||
|
||||
- 将所有部署、Nacos 发布/回退工作流中的 Gitea API 与仓库检出地址统一为 `http://wcsrv.top:3000`。
|
||||
|
||||
Reference in New Issue
Block a user