首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >系统在线或离线解决方案

系统在线或离线解决方案
EN

Stack Overflow用户
提问于 2013-04-25 04:47:48
回答 2查看 511关注 0票数 3

我工作的公司有一个网络系统,一些模块将在工作中使用,这些模块并不总是连接到互联网。在构建中部署系统的web模块的最佳解决方案是什么?系统无法在数据库中进行读/写。

EN

回答 2

Stack Overflow用户

发布于 2013-04-25 04:53:52

您可以拥有一个在can服务器上运行的本地数据库。每隔15分钟,您会检查是否存在连接,并将更改从本地数据库传输到您的“真正”数据库。

票数 0
EN

Stack Overflow用户

发布于 2013-05-21 15:01:02

由于CAP theorem的存在,这个问题没有完美的解决方案。但是,如果有的话,分布式系统会容易得多:)

在我看来,你有几个选择。所有选项都需要数据客户端的副本,以便客户端至少可以在断开连接时读取数据。

  1. 不允许不一致的写入,只允许不一致的读取。

代码语言:javascript
运行
复制
- Either the client or the server would take write-ownership of the data whenever the client is off the network. Whichever side owns the data is allowed to write, and the other side must read a potentially-stale local copy of the data (or it could generate errors if that's preferable, or at least tell the user that the data is stale). This is more difficult if you have multiple clients running at the same time.
- A similar approach is to run all server-side write operations when you know no clients will be at work (i.e. run all your jobs at midnight). It's simple, but it works for many applications.

  1. 允许不一致,并在以后处理它们。当您必须能够同时写入断开连接的网络的两端时,这是唯一的方法。但是,有几种方法可以缓解不一致问题,具体取决于您的设计:

代码语言:javascript
运行
复制
- If you can make all transformations commutative (you can change the order of the transformations and the outcome will be the same), you could store the transformations performed on the client and the server and then apply any cached ones from the client when the it reconnects to the server. This makes dealing with inconsistencies very simple. This is what ATMs do when they are disconnected from the banking network - their commutative transformations are similar to, "Deduct $50 from acct #12345." Note that this can still cause invalid state - the user could deduct more than they had in their account by visiting multiple ATMs which are disconnected from the banking network. However, the bank makes up for this by charging overdraft fees when the ATMs reconnect to the network, and so they don't typically lose any money as a result.
- If conflicts are rare, you could just tell a user of the client, "Hey, you wrote this while you were offline, but the value changed on the server - which copy should I keep?" This has the issue that you might have to ask it multiple times, since the user has to perform an atomic [CAS operation](http://en.wikipedia.org/wiki/Compare-and-swap) on the value being changed and it's possible that multiple clients might be reconnecting at the same time. This approach can also suffer from the [ABA problem](http://en.wikipedia.org/wiki/ABA_problem) if you're not careful (but that depends what you're doing).

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16201865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档