什么是最聪明的和简单的方法来同步多个实体之间的数据? [英] What is the most clever and easy approach to sync data between multiple entities?

查看:121
本文介绍了什么是最聪明的和简单的方法来同步多个实体之间的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在今天的世界里,有很多电脑,移动设备或Web服务共享数据或行为类似集线器,同步变得更为重要。大家都知道,同步是不是最舒服的人的解决方案,它是最好不要同步的。

In today’s world where a lot of computers, mobile devices or web services share data or act like hubs, syncing gets more important. As we all know solutions that sync aren’t the most comfortable ones and it’s best not to sync at all.

我还是好奇,你将如何实现一个同步的解决方案多个实体之间的同步。目前已经有很多不同的方法,比较喜欢更改了日期的字段或哈希,并使用最新的数据或让用户选择,他希望在冲突的情况下使用什么。另一种方法是尝试自动合并冲突的数据(这在我看来是没有那么聪明,因为机器不能猜出用户的意思)。

I’m still curious how you would implement a syncing solution to sync between multiple entities. There are already a lot of different approaches, like comparing a changed date field or a hash and using the most recent data or letting the user chose what he wants to use in a case of a conflict. Another approach is to try to automatically merge conflicted data (which in my opinion isn’t so clever, because a machine can’t guess what the user meant).

总之,这里有一对夫妇的同步,我们应该开始实施同步之前回答相关的问题:

Anyway, here are a couple of questions related to sync that we should answer before starting to implement syncing:

  • 什么是最新的数据?我如何想重新present呢?
  • 我该怎么做,以防发生冲突?合并?难道我提示,询问用户该怎么办?
  • 在做什么,当我进入状态不一致怎么办?(例如断开由于古怪的移动网络连接)?
  • 在做什么我必须做的时候我并不想进入不一致的状态?
  • 如何恢复当前的同步即被中断?
  • 如何处理数据存储?(Web服务上,例如MySQL数据库,核心数据在iPhone上,以及如何合并/同步数据,而无需大量的胶水code)
  • 我应该如何处理从同步过程中所发生用户编辑(它在后台运行,因此用户界面不会被阻止)?
  • 如何在哪个方向我传播的变化(例如,一个用户创建自己的计算机上的富条目并不会同步;然后他在旅途中,并创建另一个富的条目;当他试图会发生什么同步两个设备)?将用户与不同的唯一ID两个富项目?将用户只有一个入口,但哪一个?
  • 我应该如何处理同步,当我有分层的数据?自顶向下?自下而上?难道我原子对待每一位入境,我只看到一个超级节点?有多大是过于简单化的东西,投入太多的时间到实现之间的权衡?
  • ...
  • What is the most recent data? How do I want to represent it?
  • What do I do in case of a conflict? Merge? Do I prompt and ask the user what to do?
  • What do I do when I get into an inconsistent state (e.g. a disconnect due to a flakey mobile network connection)?
  • What do I have to do when I don’t want to get into an inconsistent state?
  • How do I resume a current sync that got interrupted?
  • How do I handle data storage (e.g. MySQL database on a web service, Core Data on an iPhone; and how do I merge/sync the data without a lot of glue code)?
  • How should I handle edits from the user that happen during the sync (which runs in the background, so the UI isn’t blocked)?
  • How and in which direction do I propagate changes (e.g. a user creates a „Foo" entry on his computer and doesn’t sync; then he’s on the go and creates another „Foo" entry; what happens when he tries to sync both devices)? Will the user have two „Foo" entries with different unique IDs? Will the user have only one entry, but which one?
  • How should I handle sync when I have hierarchical data? Top-down? Bottom-up? Do I treat every entry atomically or do I only look at a supernode? How big is the trade-off between oversimplifying things and investing too much time into the implementation?

有很多其他的问题,我希望我能鼓舞你就够了。同步是一个相当普遍的问题。一旦一个良好的,通用的同步方法被发现,它应该是更容易将它应用到一个具体的应用程序,而不是从头开始思考。我意识到,目前已经有大量的应用程序,试图解决(或顺利解决)同步,但它们已经相当具体,不要在一般的同步方法给予足够的答案。

There are a lot of other questions and I hope that I could inspire you enough. Syncing is a fairly general problem. Once a good, versatile syncing approach is found, it should be easier to apply it to a concrete application, rather than start thinking from scratch. I realize that there are already a lot of applications that try to solve (or successfully solve) syncing, but they are already fairly specific and don’t give enough answers to syncing approaches in general.

推荐答案

我在哪里工作,我们已经开发了一个离线版本,我们主要的(网络)应用程序供用户能够在他们的位置上工作的笔记本电脑无法上网(我不知道有多少,这些地方实际存在的这些天,但我已经告诉他们这样做;))。当用户回来的主要网站,他们需要同步,他们与我们的主应用程序离线输入的数据。

Where I work we have developed an "offline" version of our main (web) application for users to be able to work on their laptops in locations where they do not have internet access (I'm not sure how many of these places actually exist these days, but I've been told they do ;)). When the user comes back to the main site they need to synchronise the data they entered offline with our main application.

因此​​,要回答你的问题:

So, to answer your questions:

      
  • 什么是最新的数据?我如何想重新present呢?
  •   

我们有充分的表的LAST_UPDATED_DATE列。服务器保留曲目时同步情况发生,所以当离线应用程序请求同步服务器说:嘿,只给我,因为这个日期更改的数据的。

We have a LAST_UPDATED_DATE column on every table. The server keeps a track of when synchronisations take place, so when the offline application requests a synchronisation the server says "hey, only give me data changed since this date".

      
  • 我该怎么做,以防发生冲突?合并?难道我提示和要求   用户该怎么办?
  •   
  • What do I do in case of a conflict? Merge? Do I prompt and ask the user what to do?

在我们的情况下,脱机应用程序仅能够更新所有的数据的相对小的子集。由于每个记录是同步的,我们检查它是否是其中一个案件,如果是的话,我们比较LAST_UPDATED_DATE备案在线和离线。如果这两个日期都不同,那么我们还检查值(因为它不是一个冲突,如果他们俩都更新为相同的值)。如果有我们记录的差的冲突,设置一个标志,表示有至少一个冲突,并进行检查的细节的其余部分。一旦该过程完成后,然后,如果isConflict标志被设置,用户能够进入到一个特殊的页面,其显示的差异,并决定哪些数据是正确的版本。该版本将保存在主机上的isConflict标志复位。

In our case the offline application is only able to update a relatively small subset of all the data. As each record is synchronised we check if it is one of these cases, and if so then we compare the LAST_UPDATED_DATE for the record both online and offline. If the dates are different then we also check the values (because it's not a conflict if they're both updated to the same value). If there is a conflict we record the difference, set a flag to say there is at least one conflict, and carry on checking the rest of the details. Once the process is finished then if the "isConflict" flag is set the user is able to go to a special page which displays the differences and decide which data is the "correct" version. This version is then saved on the host and the "isConflict" flag is reset.

      
  • 在做什么我必须做的时候我并不想进入不一致   状态?
  •   
  • 如何恢复当前的同步即被中断?
  •   
  • What do I have to do when I don’t want to get into an inconsistent state?
  • How do I resume a current sync that got interrupted?

好吧,我们尽量避免陷入不一致的状态摆在首位。如果synchronistaion由于某种原因中断,则该last_synchronisation_date不更新,因此同步启动下一次会在同一天的开始日期previous(interuppted)同步。

Well, we try to avoid getting into an inconsistent state in the first place. If a synchronistaion is interrupted for any reason then the last_synchronisation_date is not updated, and so the next time a synchronisation is started it will start from the same date as the start date for the previous (interuppted) synchronisation.

      
  • 如何处理的数据存储在一个Web服务(如MySQL数据库,核心   在iPhone上的数据;而我怎么   合并/同步数据没有很多   胶code)?
  •   
  • How do I handle data storage (e.g. MySQL database on a web service, Core Data on an iPhone; and how do I merge/sync the data without a lot of glue code)?

我们在这两个应用程序使用标准的数据库和Java对象之间。对象被序列化到XML(可和gzip压缩到加快转移),用于实际的同步过程,然后DECOM pressed / deserialised在每个末端

We use standard databases on both applications, and Java objects in between. The objects are serialised to XML (and gzipped to speed up the transfer) for the actual synchronisation process, then decompressed/deserialised at each end.

      
  • 我应该如何处理在同步过程中所发生的用户编辑   (它在后台运行,所以   UI不会被阻​​止)?
  •   
  • How should I handle edits from the user that happen during the sync (which runs in the background, so the UI isn’t blocked)?

这些修改将发生在同步开始日期之后,所以不会被拾起的另一侧,直到下一个同步

These edits would take place after the synchronisation start date, and so would not be picked up on the other side until the next synchronisation.

      
  • 如何在哪个方向我传播的变化(例如用户创建   他的计算机上的富条目,   不同步;然后他在旅途中和   创建另一个富项;什么   当他试图同步双方发生   装置)?将用户有两个富   与不同的唯一ID条目?   将用户只有一个条目,但   哪一个?
  •   
  • How and in which direction do I propagate changes (e.g. a user creates a „Foo" entry on his computer and doesn’t sync; then he’s on the go and creates another „Foo" entry; what happens when he tries to sync both devices)? Will the user have two „Foo" entries with different unique IDs? Will the user have only one entry, but which one?

这是由你来决定要如何处理这个特殊的富...即根据什么富的主键是,你如何确定一个富是否与另一个相同。

That's up to you to decide how you want to handle this particular Foo... i.e. depending on what the primary key of Foo is and how you determine whether one Foo is the same as another.

      
  • 我应该如何处理同步,当我有分层的数据?自顶向下?   自下而上?难道我对待每一个条目   原子或者我只是看一个   超级节点?
  •   
  • How should I handle sync when I have hierarchical data? Top-down? Bottom-up? Do I treat every entry atomically or do I only look at a supernode?

同步是原子,因此,如果一个记录失败,那么整个过程被标记为不完整的,类似于颠覆提交事务。

The synchronisation is atomic, so if one record fails then the whole process is marked as incomplete, similar to a subversion commit transaction.

      
  • 在多大的事情简单化和投资之间的权衡   太多的时间进入实施?
  •   
  • How big is the trade-off between oversimplifying things and investing too much time into the implementation?

我不知道到底是什么,你的意思,但我会说这一切都取决于你的情况和数据,要同步的类型/数量。这可能需要很长的时间来设计和实施的过程中,但它是可能的。

I'm not sure exactly what you mean, but I'd say it all depends on your situation and the type / quantity of data you want to sync. It might take a long time to design and implement the process, but it's possible.

希望帮助您,或者至少给你一些想法! :)

Hope that helps you or at least gives you a few ideas! :)

这篇关于什么是最聪明的和简单的方法来同步多个实体之间的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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