码迷,mamicode.com
首页 > 其他好文 > 详细

翻译:多版本并发控制

时间:2014-05-16 00:05:24      阅读:407      评论:0      收藏:0      [点我收藏+]

标签:des   class   c   http   int   strong   

Multiversion concurrency control

多版本并发控制

Multiversion concurrency control (MCC or MVCC), is a concurrency control method commonly used by database management systems to provide concurrent access to the database and in programming languages to implement transactional memory.[1]

多版本并发控制(简称MCC或者MVCC),是一种并发控制思想,通常被用于DBMS中去保证并发连接数据库,或者去实现事务内存编程。

If someone is reading from a database at the same time as someone else is writing to it, it is possible that the reader will see a half-written or inconsistentpiece of data. There are several ways of solving this problem, known as concurrency control methods. The simplest way is to make all readers wait until the writer is done, which is known as a lock. This can be very slow, so MVCC takes a different approach: each user connected to the database sees a snapshot of the database at a particular instant in time. Any changes made by a writer will not be seen by other users of the database until the changes have been completed (or, in database terms: until the transaction has been committed.)

如果在一个库中,有人读,同时也有人写,很可能读操作会获取到写入一部分的内容,或者不一致的数据片段。有好几种方法可以解决这个问题,都采用并发控制思想。最简单的方法是加锁,让读操作一直等待直到写入结束,但这会导致读写非常慢。MVCC采用另一种思路,访问数据库的每个用户都将看到一个特定时刻的数据库快照。写操作进行的修改,不会被其他用户看到,直至修改完成(在数据库中,直至事务被提交)

When an MVCC database needs to update an item of data, it will not overwrite the old data with new data, but instead mark the old data as obsolete and add the newer version elsewhere. Thus there are multiple versions stored, but only one is the latest. This allows readers to access the data that was there when they began reading, even if it was modified or deleted part way through by someone else. It also allows the database to avoid the overhead of filling in holes in memory or disk structures but requires (generally) the system to periodically sweep through and delete the old, obsolete data objects. For a document-oriented database it also allows the system to optimize documents by writing entire documents onto contiguous sections of disk—when updated, the entire document can be re-written rather than bits and pieces cut out or maintained in a linked, non-contiguous database structure.

一个支持MVCC的数据库更新某一项数据的时候,它不会直接用新数据去覆盖原数据,而是将原数据标记为废弃,并且把新数据写在其他地方,这样就有多版本的数据同时被存储,但是只有一个是最新的。MVCC允许一个读会话开启之后,连接依然可以查看数据,即使它被其他操作修改或者删除。MVCC让数据库避免直接填写内存的空洞,或磁盘的结构(即被标记为脏数据的部分),一般请求系统周期性换出将脏数据删除。对于一个文件类型的数据库来说,系统通过把整个文件写入相似的磁盘区,更新完成后,整个文件被重写的方式来修改磁盘结构,而非一点一点截取或被链接在一个完全不同的磁盘结构。

MVCC provides point in time consistent views. Read transactions under MVCC typically use a timestamp or transaction ID to determine what state of the DB to read, and read these versions of the data. This avoids managing locks for read transactions because writes can be isolated by virtue of the old versions being maintained, rather than through a process of locks or mutexes. Writes affect a future version but at the transaction ID that the read is working at, everything is guaranteed to be consistent because the writes are occurring at a later transaction ID.

MVCC提供时间一致性读。MVCC下的读事务一般用一个时间戳或者事务ID来决定读取什么样的数据状态,和哪个版本的数据。这避免了为读事务加锁,因为写操作被独立执行在老本本的数据上,而不是通过发起锁或者互斥进程。写影响一个将来版本的数据,而不是读操作正在进行的事务id版。任何数据都一致的,因为写影响下一个事务id。

 

翻译:多版本并发控制,布布扣,bubuko.com

翻译:多版本并发控制

标签:des   class   c   http   int   strong   

原文地址:http://www.cnblogs.com/wyeat/p/mvcc.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!