数据同步框架MS Sync Framework [术语、例子、参考资料、Tips]

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介: 在现在的应用中,一些临时脱机(Offline)应用,需要和主数据库进行定期的数据同步,采用MS Sync Framework可以快速的实现一个解决方案,而且这个框架本身有很大的扩展性,可以用于数据库(ADO.net兼容的)、文件,Web Feed等同步。

在现在的应用中,一些临时脱机(Offline)应用,需要和主数据库进行定期的数据同步,采用MS Sync Framework可以快速的实现一个解决方案,而且这个框架本身有很大的扩展性,可以用于数据库(ADO.net兼容的)、文件,Web Feed等同步。

术语

[具体的翻译在MSDN]

synchronization scope

A synchronization scope is a logical grouping of objects that must be synchronized as a unit.

knowledge

The metadata that is maintained by each participant that describes all the changes it has seen. In its simplest form, known as a watermark, a knowledge item is a clock vector that consists of pairs of replica keys and replica tick counts.

provision

After you define the synchronization scope, you provision the database to create a change-tracking and metadata management infrastructure that consists of metadata tables, triggers, and stored procedures.

参考资料

http://msdn.microsoft.com/sync

http://msdn.microsoft.com/en-us/sync

官方博客 http://blogs.msdn.com/b/sync/

http://social.msdn.microsoft.com/Forums/en-US/synclab/threads

How To: Provision for Synchronization Using Snapshot Initialization

http://msdn.microsoft.com/en-us/library/gg294193(v=SQL.110).aspx

Sync Framework Tips and Troubleshooting

http://social.technet.microsoft.com/wiki/contents/articles/sync-framework-tips-and-troubleshooting.aspx

Database Synchronization

  • Use snapshot initialization to create and initialize multiple SQL Server Compact databases in your synchronization community. Snapshot initialization offers much faster performance for setting up multiple SQL Server Compact databases than provisioning each one individually. And the API is simple, too! Here's an article that tell you how to do this: http://msdn.microsoft.com/en-us/library/gg294193(v=SQL.110).aspx.
  • Use backup and restore (with post-restore fixup) to create and initialize multiple large SQL Server databases in your synchronization community. If you are setting up a synchronization community that contains copies of a large SQL Server database, performance will be better if you use backup and restore to create the database copies instead of an initial synchronization. Here's an article that tells you how to do this: http://msdn.microsoft.com/en-us/library/ee617375(v=SQL.110).aspx.
  • Don't use TRUNCATE TABLE to modify a table that is synchronized. This is because, while TRUNCATE TABLE is in effect a DELETE statement, it does not activate the trigger used to update the change tracking metadata, so the deletion is invisible to Sync Framework and will not be sent to other replicas.
  • To find a list of the scopes that are currently provisioned in a database, query the scope_info table. The scope_info table contains information about each scope, including the scope name.
  • When a table in a SQL Server Compact database is initialized through synchronization, the seed and increment of its identity columns are always set to 0 and 1, respectively, regardless of how they are set on the server database. If you need to insert rows locally in the client database you must first set the identity seed and increment to appropriate values or manually specify the identity column value, otherwise new rows will have duplicate identity values and row insertion will fail. The identity seed and increment can be set with the following query, which sets the seed value to 10 and the increment to 1: ALTER TABLE ExampleTable ALTER COLUMN idColIDENTITY(10,1)

Sync Framework 4.0

这个是目前的版本,现在是才CTP版本

如下是安装后其中的一个工具

C:\Program Files (x86)\Microsoft SDKs\Microsoft Sync Framework\4.0\bin

SyncSvcUtilHelper.exe

SyncSvcUtil.exe

image

可见常用的功能通过这些工具可以自动生成,更简化的处理的步骤。

其中例子目录iPhoneSample,是一个使用Odata协议的数据服务同步程序,很酷。

估计正式版本对开发更简化

例子

三种同步形式

Sync Framework provides snapshot, download-only, upload-only, and bidirectional synchronization for client and server scenarios:

Ø Snapshot and download-only synchronization are typically used to store and update reference data, such as a product list, on a client. Data changes that are made at the server are downloaded to the client database during synchronization. Snapshot synchronization completely refreshes data every time that the client is synchronized. This is appropriate when you do not want to track incremental changes or the server cannot do so. Download-only synchronization downloads only the incremental changes that have occurred since the previous synchronization.

Ø Upload-only synchronization is typically used to insert data, such as a sales order, on a client. Inserts and other changes to data that are made in the client database are uploaded to the server during synchronization.

Ø Bidirectional synchronization is typically used for data, such as customer contact information, that can be updated at the client and server. Any conflicting changes must be handled during synchronization.

SDK本身有例子,其他的比较好的参考资源

Additional samples are available in the Sync Framework SDK and on Code Gallery.

http://go.microsoft.com/fwlink/?LinkId=123328

这个地址上有Orcale ,SQL Express等的例子

http://archive.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sync&ReleaseId=3422

Database Sync - SQL Server and SQL Compact 2-Tier

http://archive.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=3761

Database Sync - Oracle and SQL Compact 2-Tier

下文我把根据SDK测试的几个例子分析一下,对这个框架有更详细的了解

相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情: https://www.aliyun.com/product/rds/sqlserver
相关文章
|
5月前
|
canal NoSQL 关系型数据库
淘东电商项目(22) -Canal数据同步框架
淘东电商项目(22) -Canal数据同步框架
60 0
|
canal SQL 消息中间件
阿里Canal框架(数据同步中间件)初步实践
阿里Canal框架(数据同步中间件)初步实践
783 0
阿里Canal框架(数据同步中间件)初步实践
|
Unix Linux 数据处理
LINUX进阶(基础篇)之数据同步写入磁盘:sync
LINUX进阶(基础篇)之数据同步写入磁盘:sync
691 0
|
canal 存储 NoSQL
【Canal】数据同步的终极解决方案,阿里巴巴开源的Canal框架当之无愧!!
在当今互联网行业,尤其是现在分布式、微服务开发环境下,为了提高搜索效率,以及搜索的精准度,会大量使用Redis、Memcached等NoSQL数据库,也会使用大量的Solr、Elasticsearch等全文检索服务。那么,这个时候,就会有一个问题需要我们来思考和解决:那就是数据同步的问题!如何将实时变化的数据库中的数据同步到Redis/Memcached或者Solr/Elasticsearch中呢?
697 0
【Canal】数据同步的终极解决方案,阿里巴巴开源的Canal框架当之无愧!!
|
SQL 数据库 开发工具
数据同步框架MS Sync Framework-不同场景使用例子和简要分析
上一篇http://www.cnblogs.com/2018/archive/2011/02/22/1961654.html 对这个框架一个总体介绍,这篇通过SDK内带的例子和一个综合的例子描述一下这个框架的使用 [例子基于SDK2.
1091 0
|
SQL IDE 数据库
数据同步框架MS Sync Framework - IDE快速开发支持Local Database Cache
数据同步框架MS Sync Framework [术语、例子、参考资料、Tips] http://www.cnblogs.com/2018/archive/2011/02/22/1961654.html  数据同步框架MS Sync Framework-不同场景使用例子和简要分析 http://www.cnblogs.com/2018/archive/2011/02/23/1961657.html 以上两篇文章对框架的基础有了描述,通过IDE的提供Local Database Cache可以快速的实现一个常用的同步应用。
943 0
|
20天前
|
canal 消息中间件 关系型数据库
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
66 0
|
1月前
|
canal 关系型数据库 MySQL
四种常用的 MySQL 数据同步 ES 的方法
【2月更文挑战第16天】
167 2
四种常用的 MySQL 数据同步 ES 的方法
|
6月前
|
关系型数据库 MySQL Java
对比下 datax 的 OceanBase/MYSQL 不同数据同步方案的效率差异 || 聊聊参数 rewriteBatchedStatements
对比下 datax 的 OceanBase/MYSQL 不同数据同步方案的效率差异 || 聊聊参数 rewriteBatchedStatements

热门文章

最新文章