我工作的公司有一个网络系统,一些模块将在工作中使用,这些模块并不总是连接到互联网。在构建中部署系统的web模块的最佳解决方案是什么?系统无法在数据库中进行读/写。
发布于 2013-04-25 04:53:52
您可以拥有一个在can服务器上运行的本地数据库。每隔15分钟,您会检查是否存在连接,并将更改从本地数据库传输到您的“真正”数据库。
发布于 2013-05-21 15:01:02
由于CAP theorem的存在,这个问题没有完美的解决方案。但是,如果有的话,分布式系统会容易得多:)
在我看来,你有几个选择。所有选项都需要数据客户端的副本,以便客户端至少可以在断开连接时读取数据。
- 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.
- 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).
https://stackoverflow.com/questions/16201865
复制相似问题