基於跨資料庫的事務的乙個討論,希望參考下大家的意見

2022-02-28 03:27:55 字數 1139 閱讀 5459

多個資料進行資料操作, 基於效能方面的考慮首先排除掉了分布式事務,

後來參考了 ebay 的  用訊息佇列和訊息應用狀態表來消除分布式事務 原文可以看這裡 

大致是這樣的乙個過程:

begin;

insert

into

transaction

values(xid, $seller_id, $buyer_id, $amount);

put_to_queue 「update

user(「seller」, $seller_id, amount);

put_to_queue 「update

user(「buyer」, $buyer_id, amount);

commit;

for each message in queue

begin;

select

0then

if message.type = 「seller」 then

update

user

set amt_sold = amt_sold + message.amount where id = message.user_id;

else

update

user

set amt_bought = amt_bought + message.amount where id = message.user_id;

endinsert

commit;

if 上述事務成功

dequeue message

delete

end但是這樣子搞 如果 操作a庫成功了 而操作b庫失敗了  我可以在很短時間內重試, 如果重試失敗了的話, 我必須對a 庫的資料進行手工回滾 , 但是隨後提出的另外的乙個意見 ,於其如此不如像這樣的乙個結構

boolean

flag = 

false

;trycatch(exception e)

if(flag)catch(exception e)

}後者似乎更加簡單 方便, 前者雖然可以讓資料最終達到一致,但是不可避免的是由於資料獲取其他的因素必須回滾 前者似乎並沒有達到預期的效果. 

系統大家討論下 兩種方式的利於弊.  同時也討論下誇庫事務是否有更好的辦法

乙個簡單的跨庫事務問題

來自 最近在做乙個專案,其中乙個方案涉及到跨庫事務一致性問題,是乙個簡單的場景。這個專案是對老的業務進行效能提公升,業務邏輯基本上保持不變。主要是在於新專案採用了分庫分表的設計,從而提公升了效能。考慮到專案發布之後可能存在風險,採取了新老系統的並行方案。這個系統的業務比較簡單 接收來自外部的資料,然...

基於FMDB資料庫事務的使用

18 void viewdidload 19 else 36 39 40 self.queue queue 42 44 void touchesbegan nsset touches withevent uievent event 45 50 51 查詢資料 52 self.queue indata...

資料庫 隨手寫了乙個 跨資料庫 資料遷移工具

隨手寫了乙個 跨資料庫 的 資料遷移工具 目前支援 sqlserver,mysql,sqlite 遷移工具 可以自動建表,且 保留 主鍵,自增列 遷移工具 基於 laura.source orm框架 開發 遷移工具 支援 崩潰恢復 重啟遷移工具,將會繼續 未完成的 資料遷移 每張表乙個事務 即使 表...