Member-only story

今翅仆街鳥:DB爆咗Integer

10+年前我寫落一個software,喺5+年前已經移交咗俾其他人打理,然後呢幾年一直都冇乜加過核心功能、DB Schema更加完全冇變過,所以我都逐漸遺忘開發方法,接手嘅同事亦對最core嘅logic唔係咁熟,畢竟日常更主要係做好DB maintainence同確保infra層面穩穩陣陣居多,另外小修小補business logic為輔。

不過公司依然有幾個重要scenario用得著佢而目前又四平八穩好哋哋,基於if it ain’t broke don’t fix it,所以未有任何計劃做大修。

今日lunch time同事拎住laptop衝過來,話個system爆咗炸,error message報DBD::Pg::db selectrow_array failed: ERROR: integer out of range. CONTEXT: PL/pgSQL get_event_log_log_id(integer,integer,integer) while casting return value to function’s return type
(註:無錯,backend係Perl)

「仆街囉」係我心入面嗰句,但冇講出口。

「個倉停哂呀」佢話…意味著啲貨會出唔到。

thenib.com/this-is-not-fine/

「你拎get_event_log_log_id個definition出來睇下先…喺source code入面應該有」令佢有啲嘢做同時等我消化下件事先。

而我腦入面一堆走馬燈。

表面上係get_event_log_log_id()呢個function嘅return type係integer所以出問題,話換咗佢做bigint當然簡單,但連帶會有咩影響呢?如果underlying嘅data structure (event_loglog_id)就係integer而唔係bigint呢?我知道呢個table係勁大 (亦因為噉所以會爆),雖然個名係叫log但實質係同business logic相關、並唔係話清就清。噉如果alter table又會block幾耐?code又使唔使改?

「可唔可以拎staging個DB變做production用住先?」我問。因為staging資料量一定少好多,而最主要嘅場景個logic應該係通嘅唔使改。

「得係得,但今日in-flight未走哂成個flow嘅order會有問題」佢話。即若switch over過去之後,要scrub啲data執屎都執死。

搵到source code,一如所料get_event_log_log_id係return integer。裡面有call到event_log table相關嘅primary key同sequence。

--

--

I.T. 9 遊戲日誌
I.T. 9 遊戲日誌

Written by I.T. 9 遊戲日誌

「IT9,你的資訊真的很有用」 你好 我就係IT9 Trust me I am IT9 // fb@it9gamelog, youtube@it9gamelog

No responses yet