不同時區對 Merge Replication 的影響

由於 Merge Replication 會對每筆記錄變更後,在 MSmerge_contents 系統資料表的 Generation 欄位記載著該筆記錄是在第幾次同步後更新,是同步前的舊值加一,若有衝突,大家彼此比 Generation,就知是否為最新的更新,還是太久沒上來同步的舊記錄。因此不憑更動的時間,也就沒有 UTC 時區對時的需求。你可以透過以下的語法觀察:

SELECT TOP 1000 *   FROM [dbo].[MSmerge_contents]

image

我實際透過兩台 VM 設定不同的時區模擬測試,也的確沒有問題。

image

參照 http://msdn.microsoft.com/en-gb/library/aa256294(SQL.80).aspx

SQL Server then adds several system tables to the database to support data tracking, efficient synchronization, and conflict detection, resolution and reporting. For every changed or created row, the table MSmerge_contents contains the generation in which the most recent modification occurred. It also contains the version of the row as a whole and every attribute of the row. MSmerge_tombstone stores DELETEs to the data within a publication. These tables use the rowguid column to join to the publishing table.

The generation column in these tables acts as a logical clock indicating when a row was last updated at a given site. Actual datetime values are not used for marking when changes occur, or deciding conflicts, and there is no dependence on synchronized clocks between sites. This makes the conflict detection and resolution algorithms more resilient to time zone differences and differences between physical clocks on multiple servers. At a given site, the generation numbers correspond to the order in which changes were performed by the Merge Agent or by a user at that site.

MSmerge_genhistory and MSmerge_replinfo allow SQL Server to determine the generations that need to be sent with each merge.

 

但若要以時間因素判斷衝突解決,可能會有問題,因為既有的 COM 衝突解決模組都並未支援 DatetimeOffset 類型的資料欄位,參照:http://msdn.microsoft.com/en-us/library/ms152573.aspx

若使用 DatetimeOffset 欄位當作判斷條件:

image

會有以下的錯誤:

image

因為衝突解決取決於你自行維護的欄位,所以,或許在更新用來評斷的欄位時,全部要換算成一特定地點的時間。

雖然 Merge 機制本身不會被跨時區干擾,但你的資料時間內容會錯,可能需要採 DatetimeOffset 資料類型儲存時間資訊

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: