在两个不同系统之间同步对象,最佳方法? [英] Syncing objects between two disparate systems, best approach?

查看:209
本文介绍了在两个不同系统之间同步对象,最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于XML的有效载荷在iPhone和网站之间同步两个业务对象,并且希望征求一些最佳例程的想法。

I am working on syncing two business objects between an iPhone and a Web site using an XML-based payload and would love to solicit some ideas for an optimal routine.

这个问题的性质是相当通用的,我可以看到它适用于需要在Web实体和客户端之间同步业务对象的各种不同的系统(桌面,手机等)

The nature of this question is fairly generic though and I can see it being applicable to a variety of different systems that need to sync business objects between a web entity and a client (desktop, mobile phone, etc.)

业务对象可以在两边编辑,删除和更新。双方可以在本地存储对象,但同步仅在iPhone端启动,用于断开连接。所有对象都有一个updated_at和created_at时间戳,并由双方的RDBMS支持(在iPhone端的SQLite和Web上的MySQL ...再次我认为这不重要),手机记录最后一次尝试同步。

The business objects can be edited, deleted, and updated on both sides. Both sides can store the object locally but the sync is only initiated on the iPhone side for disconnected viewing. All objects have an updated_at and created_at timestamp and are backed by an RDBMS on both sides (SQLite on the iPhone side and MySQL on the web... again I don't think this matters much) and the phone does record the last time a sync was attempted. Otherwise, no other data is stored (at the moment).

您会使用什么算法来最小化系统之间的网络聊天以进行同步?如果软删除不是选项,您将如何处理删除?

What algorithm would you use to minimize network chatter between the systems for syncing? How would you handle deletes if "soft-deletes" are not an option? What data model changes would you add to facilite this?

推荐答案

最简单的方法:同步时,传输所有记录 where updated_at> = @last_sync_at 。下面:这种方法根本不能容忍时钟偏移。

The simplest approach: when syncing, transfer all records where updated_at >= @last_sync_at. Down side: this approach doesn't tolerate clock skew very well at all.

每次更新一行时,保存一个版本号列是更安全的(以便时钟偏移不会妨碍同步过程)和最后同步的版本号(以便可以识别潜在的冲突更改)。为了使这种带宽高效,在发送到每个复制对等体的最后版本的每个数据库中保持高速缓存,使得仅需要传输修改的行。如果这将是一个星形拓扑,叶子可以使用简化的模式,其中最后同步的版本存储在每个表中。

It is probably safer to keep a version number column that is incremented each time a row is updated (so that clock skew doesn't foul your sync process) and a last-synced version number (so that potentially conflicting changes can be identified). To make this bandwidth-efficient, keep a cache in each database of the last version sent to each replication peer so that only modified rows need to be transmitted. If this is going to be a star topology, the leaves can use a simplified schema where the last synced version is stored in each table.

某些形式的软删除需要为了支持删除的同步,然而这可以是墓碑记录的形式,其仅包含被删除的行的键。墓碑只能在您确定所有副本都处理完毕后才能安全删除,否则可能会出现一个复制副本以重新激活您认为已删除的记录。

Some form of soft-deletes are required in order to support sync of deletes, however this can be in the form of a "tombstone" record which contains only the key of the deleted row. Tombstones can only be safely deleted once you are sure that all replicas have processed them, otherwise it is possible for a straggling replica to resurrect a record you thought was deleted.

这篇关于在两个不同系统之间同步对象,最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆