- 更新 heartbeatProcessor.js 以处理所有数字溢出类型(int16、int32、int64)并使用二进制补码。 - 防止仅与数据相关的 PostgreSQL 失败抛出个别回退错误。 - 在 databaseManager.js 中添加 insertHeartbeatEventsErrors 方法以存储被拒绝的记录。 - 更新 heartbeatProcessor.js 中的 _emitRejectedRecord 方法,直接将所有无法处理的心跳数据写入 heartbeat_events_errors 数据库。 - 更新 openspec 规范以支持新的溢出和验证回退状态。 - 添加测试文件以验证大整数处理。
1.3 KiB
1.3 KiB
Change: Handle integer overflows and persist unprocessable data
Why
Hardware devices occasionally report service_mask or other bitmasks and counters (like power_state) where their unsigned values exceed PostgreSQL's signed boundaries (e.g. uint64, uint32, uint16). This triggers out of range database insertion errors which causes batch failure and falls back to individual row insertions. Previously, rows that failed due to data range constraints directly crashed out or were only logged to Redis, meaning fully invalid data or boundary constraint violations were fundamentally lost from DB history.
What Changes
- Safely map completely oversized integers to signed
int64,int32,int162's complement equivalents natively in Javascript (e.g.(v << 16) >> 16forint2). - Refine the loop mechanism in
databaseManager.jsto avoid throwing errors exclusively built from data-level constraint mismatches when doing individual row fallback. - Extend
_emitRejectedRecordto persist any unprocessable, validation-failing, or insert-failing raw records directly into a dedicated error database table:heartbeat_events_errors.
Impact
- Affected specs:
processor - Affected code:
src/processor/heartbeatProcessor.jssrc/db/databaseManager.js