feat(common): 完善基础设施封装(logger/redis/utils/etcd/channel/mysql/mail/mq/asr)#7
Open
ULookup wants to merge 2 commits into
Open
feat(common): 完善基础设施封装(logger/redis/utils/etcd/channel/mysql/mail/mq/asr)#7ULookup wants to merge 2 commits into
ULookup wants to merge 2 commits into
Conversation
…asr) 围绕 IM 高并发 / 高可用补齐,并修若干隐藏 bug。 logger.hpp - g_default_logger 改 inline 变量,避免多 TU include 重复定义链接错误 - 发布模式启用 async + rotating_file_sink(50MB×10 份),不阻塞业务线程 - flush 策略优化:warn 级以上即刷,其它级别 3 秒批量刷 - LOG_xxx 抽 basename 而非绝对路径,日志精简 data_redis.hpp - 工厂支持连接池(pool_size/wait_timeout/socket_timeout) - 用 key 前缀 namespace 隔离(im:sess:/im:status:/im:seq:...) - Session/Status/Codes 全部带 TTL 防 OOM - 新增 SeqGen:会话级/用户级单调递增 seq,IM 增量同步基石; 支持 backfill 修复 Redis 重启场景 - 新增 LastMessage:最近一条消息预览缓存,替代 chat_session.last_message_* - 新增 DeviceSet:用户在线设备集合,推送下发入口 - 新增 ReadAck:群已读暂存,配合后台批量刷库 utils.hpp - 修复 uuid() 递增计数器:原版每次调用都重置(局部 atomic 是 bug) - 新增 verify_code(n) 6 位默认;旧 4 位 verifyCode 标记为兼容 - 新增 single_session_id(a,b):双方 user_id 排序后哈希出确定性单聊 会话 ID,客户端可不查库直接推算 - 新增 ptime <-> ms/sec 时间戳互转工具 - 全部声明 inline,避免多 TU 重复定义 etcd.hpp - 修复 ~Registry 错调 Lease()(应为 Cancel + lease_revoke) - lease 30s,避免 3s 过短导致瞬时网络抖动节点掉线 - 新增 Registry::unregister() 优雅退出主动注销 - SPDLOG_xxx 全部改为 LOG_xxx 走统一格式 channel.hpp - _index 改为 std::atomic 防 RR 计数竞争 - ChannelOptions 改有限超时(1s 连接 / 3s RPC),旧版 -1 一直等待会拖垮线程 - ServiceChannel::size() 暴露节点数用于健康检查 - 容器/锁修整,注释加固 mysql.hpp - 工厂默认 charset utf8mb4(旧 utf8 存不下 emoji,与新 schema 不一致) - 新增 ping() 健康检查接口 - 新增 TxnGuard:事务感知 RAII,便于 DAO 嵌套外层事务 mail.hpp - 修复多个错误返回路径漏 cleanup curl handle / curl_slist 的资源泄漏 - 引入 RAII 包装(CurlHandle / SListHandle) - 新增 connect/total timeout,避免 SMTP 卡死调用线程 rabbitmq.hpp - 修复 DLX 命名 bug:dlx_xxx() 由 "exchange + dlx_" 改为 "dlx_ + exchange" - delayed_ttl 单位明确为毫秒(旧注释说秒,与 AMQP x-message-ttl 不一致) - 错误处理放松:库内不再 abort(),改返回失败让调用方决定 - consume() 增加 qos prefetch(默认 64),防止慢消费者内存堆积 - 析构改优雅关闭 channel/connection 后再销毁 ev_loop - PublishStatus 枚举注释明确 Lost vs Nack 区别 asr.hpp - 抽出 SpeechRecognizer 接口,便于后续替换 ASR 提供商 - 增加空结果防御 + 异常捕获
icsearch.hpp
- Serialize/UnSerialize 加 inline 防多 TU 重定义
- 移除调试遗留 std::cout
- 新增 ESUpdate:upsert 部分字段,IM 资料修改路径常用
- ESSearch:
· must + should 共存时强制 minimum_should_match=1,
避免 should 仅作打分加权不参与命中(旧版隐性 bug)
· 新增 page(from,size) / sort_by 接口
· 错误日志统一脱敏(body 仅 trace 输出)
data_es.hpp
- ESUser 增补 phone / status 字段,对齐新 schema
· search() 同时支持 mail / phone / user_id / nickname
- ESMessage 增补 seq_id / status 字段,写入与回查同步
· 仅 status=NORMAL 的文本消息进入索引
· search() 增加按时间倒序 + 分页
- ESChatSession 增补 update_time,按变更时间倒序
- 命名统一 create_index(保留 createIndex 兼容旧调用)
snowflake.hpp
- 仅做小幅注释完善与轻微 polish;逻辑保持不变
- WaitUntil sleep 1ms 起步策略保留
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
基于 #6(DAO 重构)继续完成基础设施层完善。
修复的真实 bug
高可用 / 高并发增强
data_redis.hpp(最大增量)
新增 IM 关键工具:
logger.hpp
utils.hpp
mysql.hpp
rabbitmq.hpp
Test plan