fix(crawler): realtime_table id bigint(시퀀스 오버플로) + HCX 폴링 비활성

운영 사고 재발 방지:
- realtime_table.id가 SERIAL(int4)이라 매 poll의 nextval 소비로 2^31 도달 →
  전체 realtime 업서트가 'reached maximum value of sequence'로 정지(현장에서 14h
  무갱신 발생, bigint ALTER로 라이브 복구 완료). 신규 배포: CREATE를 BIGSERIAL로,
  기존 배포: 기동 시 멱등 마이그레이션(integer일 때만 bigint+시퀀스 ALTER).
- gateway-config: HCX(IP·맵 없는 플레이스홀더)가 enabled=true라 50055 연결거부
  로그 양산 → enabled=false.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
windpacer
2026-06-19 05:44:11 +09:00
parent 017caaff3a
commit b3985d77fb
2 changed files with 17 additions and 2 deletions

View File

@@ -53,7 +53,7 @@
"grpcPort": 50055,
"pollIntervalMs": 1000,
"registerMapPath": "",
"enabled": true
"enabled": false
}
]
}

View File

@@ -705,7 +705,7 @@ public class Hc900DbService : IExperionDbService
// realtime_table 생성 (실시간 모니터링 포인트)
await _ctx.Database.ExecuteSqlRawAsync("""
CREATE TABLE IF NOT EXISTS realtime_table (
id SERIAL PRIMARY KEY,
id BIGSERIAL PRIMARY KEY,
tagname TEXT NOT NULL,
node_id TEXT NOT NULL,
livevalue TEXT,
@@ -772,6 +772,21 @@ public class Hc900DbService : IExperionDbService
ON event_history_table(tagname, event_type, event_time DESC);
""");
// ── realtime_table.id int4→bigint 마이그레이션 (멱등) ───────────────
// realtime_table은 upsert지만 매 poll마다 nextval을 소비 → SERIAL(int4)은
// 2^31에서 오버플로해 전체 업서트가 멈춘다(운영 사고). 이미 bigint면 no-op.
await _ctx.Database.ExecuteSqlRawAsync("""
DO $$
BEGIN
IF (SELECT data_type FROM information_schema.columns
WHERE table_schema = current_schema()
AND table_name = 'realtime_table' AND column_name = 'id') = 'integer' THEN
ALTER TABLE realtime_table ALTER COLUMN id TYPE bigint;
ALTER SEQUENCE realtime_table_id_seq AS bigint MAXVALUE 9223372036854775807;
END IF;
END $$;
""");
// ── Multi-Controller Migration (controller_id) ─────────────────────
// 기존 테이블에 controller_id 컬럼 추가 (멱등)
await _ctx.Database.ExecuteSqlRawAsync(