整個系統的需求文檔為英文描述。
A Simple 2-Phase Commit SystemThis is a typical example of distributed transaction.
1. There is no direct communication among Bank of China (BoC), China Construction Bank (CCB), and CBRC's application server. They
only interact with ABC's transaction manager.
2. A wire transfer like this is a transaction (so ACID). All operations of the transaction (BoC substracts $1000 from John's account, CCB
adds $1000 to John's account, and CBRC records this transaction) must be all-done or none-done.
Please write 5 small programs:
1. A client program that can talk to ABC Transaction Manager to require a wire transfer. This is a command line program (e.g. cli john
1000 boc ccb 127.0.0.1 8888 means sending a wire transfer request to ABC transaction manager that runs on 127.0.0.1 and listens on
the port 8888. The request requires a wire transfer of $1000 from John's BoC account to John's CCB account)
2. ABC transaction manager - it waits for requests from the client, initiates the distributed transaction among Boc, CCB, and CBRC, then
send the client the wire transfer result (succeed or fail)
3. BoC Application Server - it uses a MySQL db to store account information, and waits for requests from ABC's transaction manager.
4.CCB Application Server - same as BoC Application Server (you can combine 3 and 4 as one program)
5.CBRC Application Server - it uses a MySQL db to store all transactions, and waits for requests from ABC's transaction manager.
Your system should be able to handle all kinds of failures that can be handled by the classical 2PC algorithm.
整個系統的company Transaction WEB Server面向所有用戶,實現高並發,Hold住用戶的連接,隔離後端數據系統,在這一部分,只是簡單的使用備份來實現HA。由company WEB Server來維護整個2PC協議。
後端的三個數據庫系統分別有一個高並發的服務器,雖然這些服務器不直接面向用戶,但並發量並一定小,因為他可能面向的不止一個Company server,而且異步的處理每個用戶連接。並發量並不小。
後端數據庫為mysql數據庫,為了實現數據的原子操作,使用行鎖的方式。
以下是整個系統的進程架構圖。
1.客戶端並發請求。解決辦法:使用一個WEB服務器Hold住所有連接,將所有請求構建成一個隊列,在後面使用多線程並發請求數據庫並返回所有回復到回復隊列。工作線程的數量不宜過多,避免後端數據庫服務器過於繁忙掛掉。
2.各個線程池中的線程在收到一個請求後,與後端進行2PC過程,每個階段在向後端發送阻塞式請求,使用poll方式來hold住三個連接, 如果超時,則進行超時處理。