您的位置:首页 > 运维架构 > 网站架构

关系型数据库和nosql数据库高可用性的思考

2012-09-16 23:37 381 查看
最近在看NOSQL。NOSQL和关系型数据库相比,一大优势就是高可用性。因此产生了一些疑问:

为什么nosql可以实现高可用性而关系型数据库在这方面却饱受诟病?

关系型数据库

首先Oracle, MySQL和SQL Server都属于分布式数据库。而实现分布式的方式,无非是两种:

1,多个数据库实例相连接,数据间是独立的,非冗余的。

2,多个数据库实例间数据是冗余的。

在Oracle11g中对分布式数据库的描述(从9i开始到11g,在分布式数据库方面,从文档来看没有什么变化):
http://docs.oracle.com/cd/B28359_01/server.111/b28310/ds_concepts001.htm
其中谈到了一个重点:在oracle的分布式数据库,是在网络中连接不同的数据库实例。实例和实例之间没有数据的复制和同步,所有数据都只有一份。也就是说,在分布式数据库中存储的是没有冗余的数据,对特定数据的读写只能发生在固定的节点。而这样的分布式数据库并不能提高可用性(availability),因为只有数据存在冗余时,才能将读写分散到不同的节点。

在Sql Server中的分布式数据库实现和上文中的oracle没有多少区别,对应的就是linked database和synonyms。

由于oracle和sqlserver高度一致性(不仅仅是分布式,而是方方面面的数据库的工作方式上),我认为,oracle和sqlserver在数据处理能力上不会有本质的区别。

这里提一下关系型数据库中复制的概念。因为我前面提到,制造冗余数据可以提高可用性。那么关系型数据库是如何制造冗余数据的,同时为什么关系型数据库中的冗余数据不能用来提高可用性。

下列语句引用了上面给出的oracle的官方文档的内容。

The term replication refers to the operation of copying and maintaining database objects in multiple databases belonging to a distributed system. While replication relies on distributed database technology,
database replication offers applications benefits that are not possible within a pure distributed database environment.

Most commonly, replication is used to improve local database performance and protect the availability of applications because alternate data access options exist. For example, an application may normally access a local database rather than a remote server
to minimize network traffic and achieve maximum performance. Furthermore, the application can continue to function if the local server experiences a failure, but other servers with replicated data remain accessible.

在关系型数据库中的复制主要用于容灾,而不是提高可用性。因为要实现数据冗余,就涉及同步问题,涉及事务问题。在强一致性的关系型数据库中,在multi-box中同步数据,处理事务可能会付出更多的代价,反而降低了可用性。

NOSQL

因此nosql能够使用数据冗余来提高可用性,根本原因就在于nosql数据库不是强一致的,而是最终一致的。

我们来看看MongoDB是怎么做的。

MongoDB supports asynchronous replication of data between servers for fail over and redundancy.Only one server (in the set/shard) is active for writes (the primary, or master) at a given time – this is to allow strong consistent (atomic)
operations. One can optionally send read operations to the secondaries when
eventual consistency
semantics are acceptable.

上文的重点是:只有当最终一致性是可接受的时,读操作才能被分散到不同的节点,从而实现高可用性。

如果要实现的还是强一致性,那么和关系型数据库就不会有本质的区别。

但是,一些NOSQL数据库,例如HBase声称自己实现了强一致性和高可用性。

还有听到有用NOSQL做强一致性项目的,具体怎么做还不得而知。有时间再研究。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: