feat: 添加 G5 独立写入功能
- 新增 G5 数据库连接配置与可关闭的写入开关 - 在现有 legacy/G4 写入成功路径后,追加独立的 G5 写入流程 - G5 使用与 G4 相同的数据结构映射,但不写入 guid,由数据库自生成 int4 guid - room_status 新增 G5 独立 upsert 写入路径,并保留旧表与 G5 表的独立开关 - 新增 G5 写入统计与启动摘要输出 - 更新 StatsCounters 和 StatsReporter 以支持 G5 统计 - 增加测试覆盖,确保 G5 写入逻辑与 room_status 的独立执行 - 新增 G5 相关数据库表结构 SQL 文件
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
class StatsCounters {
|
||||
constructor() {
|
||||
// 原有 4 槽 + 新增 7 槽 = 11 槽
|
||||
// [0] dbWritten, [1] filtered, [2] kafkaPulled, [3] dbWriteFailed,
|
||||
// [4] g4HotWritten, [5] g4HotWriteFailed, [6] roomStatusWritten,
|
||||
// [7] roomStatusFailed, [8] g4HotErrorTableInserted,
|
||||
// [9] g5Written, [10] g5WriteFailed
|
||||
// [0] dbWritten, [1] filtered, [2] kafkaPulled, [3] dbWriteFailed,
|
||||
// [4] g4HotWritten, [5] g4HotWriteFailed, [6] roomStatusWritten,
|
||||
// [7] roomStatusFailed, [8] g4HotErrorTableInserted
|
||||
this._minuteBuf = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 9);
|
||||
this._minuteBuf = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 11);
|
||||
this._minute = new BigInt64Array(this._minuteBuf);
|
||||
}
|
||||
|
||||
@@ -23,6 +26,8 @@ class StatsCounters {
|
||||
incRoomStatusWritten(n = 1) { this._inc(6, n); }
|
||||
incRoomStatusFailed(n = 1) { this._inc(7, n); }
|
||||
incG4HotErrorTableInserted(n = 1) { this._inc(8, n); }
|
||||
incG5Written(n = 1) { this._inc(9, n); }
|
||||
incG5WriteFailed(n = 1) { this._inc(10, n); }
|
||||
|
||||
snapshotAndResetMinute() {
|
||||
const dbWritten = Atomics.exchange(this._minute, 0, 0n);
|
||||
@@ -34,7 +39,9 @@ class StatsCounters {
|
||||
const roomStatusWritten = Atomics.exchange(this._minute, 6, 0n);
|
||||
const roomStatusFailed = Atomics.exchange(this._minute, 7, 0n);
|
||||
const g4HotErrorTableInserted = Atomics.exchange(this._minute, 8, 0n);
|
||||
return { dbWritten, filtered, kafkaPulled, dbWriteFailed, g4HotWritten, g4HotWriteFailed, roomStatusWritten, roomStatusFailed, g4HotErrorTableInserted };
|
||||
const g5Written = Atomics.exchange(this._minute, 9, 0n);
|
||||
const g5WriteFailed = Atomics.exchange(this._minute, 10, 0n);
|
||||
return { dbWritten, filtered, kafkaPulled, dbWriteFailed, g4HotWritten, g4HotWriteFailed, roomStatusWritten, roomStatusFailed, g4HotErrorTableInserted, g5Written, g5WriteFailed };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,13 +89,15 @@ class StatsReporter {
|
||||
if (this._lastFlushMinute === minuteKey) {
|
||||
return;
|
||||
}
|
||||
const { dbWritten, filtered, kafkaPulled, dbWriteFailed, g4HotWritten, g4HotWriteFailed, roomStatusWritten, roomStatusFailed, g4HotErrorTableInserted } = this.stats.snapshotAndResetMinute();
|
||||
const { dbWritten, filtered, kafkaPulled, dbWriteFailed, g4HotWritten, g4HotWriteFailed, roomStatusWritten, roomStatusFailed, g4HotErrorTableInserted, g5Written, g5WriteFailed } = this.stats.snapshotAndResetMinute();
|
||||
this._lastFlushMinute = minuteKey;
|
||||
const ts = formatTimestamp(new Date());
|
||||
this.redis.pushConsoleLog?.({ level: 'info', message: `[STATS] ${ts} Legacy写入量: ${dbWritten}条`, metadata: { module: 'stats' } });
|
||||
this.redis.pushConsoleLog?.({ level: 'info', message: `[STATS] ${ts} Legacy写入失败量: ${dbWriteFailed}条`, metadata: { module: 'stats' } });
|
||||
this.redis.pushConsoleLog?.({ level: 'info', message: `[STATS] ${ts} G4Hot写入量: ${g4HotWritten}条`, metadata: { module: 'stats' } });
|
||||
this.redis.pushConsoleLog?.({ level: 'info', message: `[STATS] ${ts} G4Hot写入失败量: ${g4HotWriteFailed}条`, metadata: { module: 'stats' } });
|
||||
this.redis.pushConsoleLog?.({ level: 'info', message: `[STATS] ${ts} G5写入量: ${g5Written}条`, metadata: { module: 'stats' } });
|
||||
this.redis.pushConsoleLog?.({ level: 'info', message: `[STATS] ${ts} G5写入失败量: ${g5WriteFailed}条`, metadata: { module: 'stats' } });
|
||||
this.redis.pushConsoleLog?.({ level: 'info', message: `[STATS] ${ts} RoomStatus写入量: ${roomStatusWritten}条`, metadata: { module: 'stats' } });
|
||||
this.redis.pushConsoleLog?.({ level: 'info', message: `[STATS] ${ts} RoomStatus失败量: ${roomStatusFailed}条`, metadata: { module: 'stats' } });
|
||||
this.redis.pushConsoleLog?.({ level: 'info', message: `[STATS] ${ts} G4Hot错误表插入量: ${g4HotErrorTableInserted}条`, metadata: { module: 'stats' } });
|
||||
|
||||
Reference in New Issue
Block a user