1,Database 的 Trasaction Log File 是用于记录Publication的modification log,在Transaction Replication中,Log Reader Agent 读取Publication的标记为Replcation 的 transaction log,传递到 Distributor 的distribution database中存储起来。
Transaction log files are used not only during the recovery of the database, but also by the Log Reader Agent, which uses the log to send the messages to the distribution database during transactional replication.
2,用于同步到 subscription 的Transaction都是commit的。
Modifying Data and the Log Reader Agent
The Log Reader Agent runs at the Distributor; it typically runs continuously, but can also run according to a schedule you establish. When executing, the Log Reader Agent first reads the publication transaction log (the same database log used for transaction tracking and recovery during regular SQL Server Database Engine operations) and identifies any INSERT, UPDATE, and DELETE statements, or other modifications made to the data in transactions that have been marked for replication. Next, the agent copies those transactions in batches to the distribution database at the Distributor. The Log Reader Agent uses the internal stored procedure sp_replcmds to get the next set of commands marked for replication from the log. The distribution database then becomes the store-and-forward queue from which changes are sent to Subscribers. Only committed transactions are sent to the distribution database.
After the entire batch of transactions has been written successfully to the distribution database, it is committed. Following the commit of each batch of commands to the Distributor, the Log Reader Agent calls sp_repldone to mark where replication was last completed. Finally, the agent marks the rows in the transaction log that are ready to be purged. Rows still waiting to be replicated are not purged.
Transaction commands are stored in the distribution database until they are propagated to all Subscribers or until the maximum distribution retention period has been reached. Subscribers receive transactions in the same order in which they were applied at the Publisher.
3,The Log Reader Agent
The Log Reader Agent is responsible for tracking the transaction log on the publication database for any changes marked for replication. It then pushes them to the distribution database, where the Distribution Agent then picks up the messages. As such, the Log Reader Agent is scheduled to run continuously. The transaction log is cleared by SQL Server only after all the messages have been delivered to the distribution database.
4,Transaction Log 在distribution db中存储的时间是有限制的,默认的maximum retention period 是72hours。如果在这个period中,Transaction 没有推送到subscription,Distribution cleanup job将会将这些Transaction 清理掉,subscription必须重新初始化(如果只是缺少部分数据,有workaround可以补救,手动同步数据,并重启Subscription)。
The Distribution Database
The Log Reader Agent acts as the facilitator in forwarding and storing messages from the publication to the distribution database.
The transactions are retained in both the MSrepl_commands and MSrepl_transactions tables for a period of up to 72 hours, by default. This means any transactions that have not been delivered to the subscriptions by that time will be cleaned up by the Distribution cleanup job, and the subscriptions will have to be reinitialized.
The publication retention period is 336 hours, by default, and the subscriptions will be deactivated by the Expired subscription cleanup job on the publishing server after that time. After the subscriptions are reactivated, the retention period will have to be re-created and reinitialized.
The history of the commands and the data is stored in the history tables for each of the agents, namely MSdistribution_history, MSlogreader_history, MSqreader_history (for publication with queued updates), and MSsnapshot_history. they are stored for 48 hours by default.
参考文档:
https://msdn.microsoft.com/en-us/library/ms151176(v=sql.110).aspx
Sujoy Paul-Pro SQL Server 2008 Replication-Apress