feat: 实现GUID主键与service_mask索引改造
- 将主键从自增id改为GUID格式并添加格式校验 - 为service_mask添加表达式索引优化首位查询性能 - 更新相关文档说明改造方案与验证步骤 - 添加统计模块记录数据库写入与Kafka消费量 - 重构Redis心跳协议改用LIST类型存储项目状态 - 修复部署脚本中的服务名称不一致问题
This commit is contained in:
17
src/index.js
17
src/index.js
@@ -4,6 +4,7 @@ import { KafkaConsumer } from './kafka/consumer.js';
|
||||
import { HeartbeatProcessor } from './processor/heartbeatProcessor.js';
|
||||
import { DatabaseManager } from './db/databaseManager.js';
|
||||
import { RedisIntegration } from './redis/redisIntegration.js';
|
||||
import { StatsCounters, StatsReporter } from './stats/statsManager.js';
|
||||
|
||||
class WebBLSHeartbeatServer {
|
||||
constructor() {
|
||||
@@ -13,6 +14,8 @@ class WebBLSHeartbeatServer {
|
||||
this.databaseManager = null;
|
||||
this.redis = null;
|
||||
this.consumers = null;
|
||||
this.stats = new StatsCounters();
|
||||
this.statsReporter = null;
|
||||
}
|
||||
|
||||
async start() {
|
||||
@@ -21,6 +24,8 @@ class WebBLSHeartbeatServer {
|
||||
this.redis = new RedisIntegration(this.config.redis);
|
||||
await this.redis.connect();
|
||||
this.redis.startHeartbeat();
|
||||
this.statsReporter = new StatsReporter({ redis: this.redis, stats: this.stats });
|
||||
this.statsReporter.start();
|
||||
|
||||
// 初始化数据库连接
|
||||
this.databaseManager = new DatabaseManager({ ...this.config.db, maxConnections: 1 });
|
||||
@@ -36,11 +41,14 @@ class WebBLSHeartbeatServer {
|
||||
groupId: this.config.kafka?.groupId,
|
||||
fromOffset: this.config.kafka?.fromOffset ?? 'latest',
|
||||
ssl: !!this.config.kafka?.sslEnabled,
|
||||
sasl: !!this.config.kafka?.saslEnabled ? `enabled (mechanism: ${this.config.kafka?.saslMechanism})` : 'disabled'
|
||||
sasl: this.config.kafka?.saslEnabled ? `enabled (mechanism: ${this.config.kafka?.saslMechanism})` : 'disabled'
|
||||
});
|
||||
|
||||
// 初始化处理器(共享批处理队列)
|
||||
this.heartbeatProcessor = new HeartbeatProcessor(this.config.processor, this.databaseManager);
|
||||
this.heartbeatProcessor = new HeartbeatProcessor(this.config.processor, this.databaseManager, {
|
||||
redis: this.redis,
|
||||
stats: this.stats,
|
||||
});
|
||||
|
||||
// 在单进程内启动 N 个消费者实例(与分区数匹配)
|
||||
const instances = Math.max(1, Number(this.config.kafka?.consumerInstances ?? 1));
|
||||
@@ -69,6 +77,11 @@ class WebBLSHeartbeatServer {
|
||||
|
||||
async stop() {
|
||||
try {
|
||||
if (this.statsReporter) {
|
||||
this.statsReporter.stop();
|
||||
this.statsReporter = null;
|
||||
}
|
||||
|
||||
if (this.consumers && Array.isArray(this.consumers)) {
|
||||
for (const { consumer } of this.consumers) {
|
||||
await consumer.stopConsuming();
|
||||
|
||||
Reference in New Issue
Block a user