Home Database Mysql Tutorial HBase、Redis中关于“长事务”(Long Transaction)的一点讨论

HBase、Redis中关于“长事务”(Long Transaction)的一点讨论

Jun 07, 2016 pm 04:30 PM
hbase long redis about

首先解释下标题,可能命名不是那么严谨吧,大致的定义如下:sometimes you are in a situation where you want to read a record, check what is in it, and depending on that update the record. The problem is that between the time you read a row and

首先解释下标题,可能命名不是那么严谨吧,大致的定义如下: sometimes you are in a situation where you want to read a record, check what is in it, and depending on that update the record. The problem is that between the time you read a row and perform the update, someone else might have updated the row, so your update might be based on outdated information. 摘要一下:进程A读取了某行R,进行时间较长的计算操作,在这个计算过程中B对行R进行了更改。A计算完毕后,若直接写入,会覆盖B的修改结果。此时应令A写入失败。 以下的讨论整理自下述两个页面,表示感谢! http://www.ngdata.com/hbase-row-locks/ http://redis.io/topics/transactions 一个最简单、直接的思路是:Transaction + Row Lock。类似于传统DBMS的思路:首先开启行锁,新建一个Transaction,随后进行各种操作,最后commit,最最后解除行锁。看似很简单,也没什么Bug,但注意,若计算时间较长,整个DB就挂起了,不能执行任何操作。 BigTable的Paper中,对这类问题进行了讨论。 总体来说解决思路有三: 1、Rowlock,但是对于HBase来说,RegionLock更成熟。因为RowLock会长时间(从Transction开始到更新)占用一个线程。当并发量很大的时候,系统会挂掉。。。 2、ICV即HBase的incrementColumnValue()方法。 3、CAS即HBase的checkAndPut方法:在Put之前,先检查某个cell的值是否和value一样,一样再Put。注意,这里检查条件的Cell和要Put的Cell可以是不同的column,甚至是不同的row。。。 综上在HBASE中,使用上述CAS方法是较好的解决方案。 上面说了HBase,再来看一个轻量级的Redis: Redis也支持事务,具体见:http://redis.io/topics/transactions 通过MULTI开始一个事务,EXEC执行一个事务。在两者之间可以“执行”多个命令,但并未被实际执行,而是被Queue起来,直到EXEC再一起执行。Redis保证:在一个事务EXEC的过程中,不会处理其他任何Client的请求(会被挂起)。注意这里是EXEC锁,而不是整个MULTI锁。所以并发性能还是有保障的。 为了支持Paper中CAS方案,Redis提供了WATCH命令: So what is WATCH really about? It is a command that will make the EXEC conditional: we are asking Redis to perform the transaction only if no other client modified any of the WATCHed keys. Otherwise the transaction is not entered at all. 已经很显然了,更多具体的,读上述网页的文档吧。    
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution to 0x80242008 error when installing Windows 11 10.0.22000.100 Solution to 0x80242008 error when installing Windows 11 10.0.22000.100 May 08, 2024 pm 03:50 PM

Solution to 0x80242008 error when installing Windows 11 10.0.22000.100

Analyze PHP function bottlenecks and improve execution efficiency Analyze PHP function bottlenecks and improve execution efficiency Apr 23, 2024 pm 03:42 PM

Analyze PHP function bottlenecks and improve execution efficiency

Golang API caching strategy and optimization Golang API caching strategy and optimization May 07, 2024 pm 02:12 PM

Golang API caching strategy and optimization

Is redis a memory cache? Is redis a memory cache? Apr 20, 2024 am 05:26 AM

Is redis a memory cache?

Is redis a non-relational database? Is redis a non-relational database? Apr 20, 2024 am 05:36 AM

Is redis a non-relational database?

Which one has better performance, erlang or golang? Which one has better performance, erlang or golang? Apr 21, 2024 am 03:24 AM

Which one has better performance, erlang or golang?

Caching mechanism and application practice in PHP development Caching mechanism and application practice in PHP development May 09, 2024 pm 01:30 PM

Caching mechanism and application practice in PHP development

How to use Redis cache in PHP array pagination? How to use Redis cache in PHP array pagination? May 01, 2024 am 10:48 AM

How to use Redis cache in PHP array pagination?

See all articles