搜索

By Lars Hofhansl As we know, ACID stands for Atomicity, Consistency, Isolation, and Durability. HBase supports ACID in limited ways, namely Puts to the same row provide all ACID guarantees. (HBASE-3584 adds multi op transactions and HBASE-

By Lars Hofhansl

As we know, ACID stands for Atomicity, Consistency, Isolation, and Durability.

HBase supports ACID in limited ways, namely Puts to the same row provide all ACID guarantees. (HBASE-3584 adds multi op transactions and HBASE-5229 adds multi row transactions, but the principle remains the same)

So how does ACID work in HBase?

HBase employs a kind of MVCC. And HBase has no mixed read/write transactions.

The nomenclature in HBase is bit strange for historical reasons. In a nutshell each RegionServer maintains what I will call "strictly monotonically increasing transaction numbers".

When a write transaction (a set of puts or deletes) starts it retrieves the next highest transaction number. In HBase this is called a WriteNumber.
When a read transaction (a Scan or Get) starts it retrieves the transaction number of the last committed transaction. HBase calls this the ReadPoint.

Each created KeyValue is tagged with its transaction's WriteNumber (this tag, for historical reasons, is called the memstore timestamp in HBase. Note that this is separate from the application-visible timestamp.)

The highlevel flow of a write transaction in HBase looks like this:
  1. lock the row(s), to guard against concurrent writes to the same row(s)
  2. retrieve the current writenumber
  3. apply changes to the WAL (Write Ahead Log)
  4. apply the changes to the Memstore (using the acquired writenumber to tag the KeyValues)
  5. commit the transaction, i.e. attempt to roll the Readpoint forward to the acquired Writenumber.
  6. unlock the row(s)
The highlevel flow of a read transaction looks like this:
  1. open the scanner
  2. get the current readpoint
  3. filter all scanned KeyValues with memstore timestamp > the readpoint
  4. close the scanner (this is initiated by the client)
In reality it is a bit more complicated, but this is enough to illustrate the point. Note that a reader acquires no locks at all, but we still get all of ACID.

It is important to realize that this only works if transactions are committed strictly serially; otherwise an earlier uncommitted transaction could become visible when one that started later commits first. In HBase transaction are typically short, so this is not a problem.

HBase does exactly that: All transactions are committed serially.

Committing a transaction in HBase means settting the current ReadPoint to the transaction's WriteNumber, and hence make its changes visible to all new Scans.
HBase keeps a list of all unfinished transactions. A transaction's commit is delayed until all prior transactions committed. Note that HBase can still make all changes immediately and concurrently, only the commits are serial.

Since HBase does not guarantee any consistency between regions (and each region is hosted at exactly one RegionServer) all MVCC data structures only need to be kept in memory on every region server.

The next interesting question is what happens during compactions.

In HBase compactions are used to join multiple small store files (create by flushes of the MemStore to disk) into a larger ones and also to remove "garbage" in the process.
Garbage here are KeyValues that either expired due to a column family's TTL or VERSION settings or were marked for deletion. See here and here for more details.

Now imagine a compaction happening while a scanner is still scanning through the KeyValues. It would now be possible see a partial row (see here for how HBase defines a "row") - a row comprised of versions of KeyValues that do not reflect the outcome of any serializable transaction schedule.

The solution in HBase is to keep track of the earliest readpoint used by any open scanner and never collect any KeyValues with a memstore timestamp larger than that readpoint. That logic was - among other enhancements - added with HBASE-2856, which allowed HBase to support ACID guarantees even with concurrent flushes.
HBASE-5569 finally enables the same logic for the delete markers (and hence deleted KeyValues).

Lastly, note that a KeyValue's memstore timestamp can be cleared (set to 0) when it is older than the oldest scanner. I.e. it is known to be visible to every scanner, since all earlier scanner are finished.

Update Thursday, March 22: 
A couple of extra points:
  • The readpoint is rolled forward even if the transaction failed in order to not stall later transactions that waiting to be committed (since this is all in the same process, that just mean the roll forward happens in a Java finally block).
  • When updates are written to the WAL a single record is created for the all changes. There is no separate commit record.
  • When a RegionServer crashes, all in flight transaction are eventually replayed on another RegionServer if the WAL record was written completely or discarded otherwise.
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
在Beego中使用Hadoop和HBase进行大数据存储和查询在Beego中使用Hadoop和HBase进行大数据存储和查询Jun 22, 2023 am 10:21 AM

随着大数据时代的到来,数据处理和存储变得越来越重要,如何高效地管理和分析大量的数据也成为企业面临的挑战。Hadoop和HBase作为Apache基金会的两个项目,为大数据存储和分析提供了一种解决方案。本文将介绍如何在Beego中使用Hadoop和HBase进行大数据存储和查询。一、Hadoop和HBase简介Hadoop是一个开源的分布式存储和计算系统,它可

PHP编程中的数据严谨性设计(ACID)PHP编程中的数据严谨性设计(ACID)Jun 22, 2023 am 09:04 AM

PHP编程中的数据严谨性设计(ACID)在PHP编程中,数据的严谨性设计是非常重要的一个方面。一个可靠的应用程序不仅需要正确地处理数据,还需要保证数据的安全性和一致性。为此,开发人员需要使用ACID进行数据设计,以确保系统的稳定性和可靠性。ACID是指原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)和持久性(Dur

怎么在springboot中集成hbase怎么在springboot中集成hbaseMay 30, 2023 pm 04:31 PM

依赖:org.springframework.dataspring-data-hadoop-hbase2.5.0.RELEASEorg.apache.hbasehbase-client1.1.2org.springframework.dataspring-data-hadoop2.5.0.RELEASE增加配置官方提供的方式是通过xml方式,简单改写后如下:@ConfigurationpublicclassHBaseConfiguration{@Value("${hbase.zooke

如何使用Java开发一个基于HBase的NoSQL数据库应用如何使用Java开发一个基于HBase的NoSQL数据库应用Sep 20, 2023 am 08:39 AM

如何使用Java开发一个基于HBase的NoSQL数据库应用引言:随着大数据时代的到来,NoSQL数据库成为处理海量数据的重要工具之一。HBase作为一种开源的分布式NoSQL数据库系统,在大数据领域具有广泛的应用。本文将介绍如何使用Java来开发基于HBase的NoSQL数据库应用,并提供具体的代码示例。一、HBase介绍:HBase是基于Hadoop的分

PHP和Apache HBase集成实现NoSQL数据库和分布式存储PHP和Apache HBase集成实现NoSQL数据库和分布式存储Jun 25, 2023 pm 06:01 PM

随着互联网应用和数据量的不断增长,传统的关系型数据库已经不能满足存储和处理海量数据的需求。而NoSQL(NotOnlySQL)作为一种新型的数据库管理系统,其能够在海量数据存储和处理方面具有显著的优势,得到越来越多的关注和应用。在NoSQL数据库中,ApacheHBase是一个非常流行的开源分布式数据库,它基于Google的BigTable思想设计,具

在Go语言中使用HBase实现高效的NoSQL数据库应用在Go语言中使用HBase实现高效的NoSQL数据库应用Jun 15, 2023 pm 08:56 PM

随着大数据时代的到来,海量数据的存储和处理显得尤为重要。在NoSQL数据库方面,HBase是目前广泛应用的一种解决方案。Go语言作为一种静态强类型编程语言,由于其语法简单、性能优秀,被越来越多地应用于云计算、网站开发和数据科学等领域。本文将介绍如何在Go语言中使用HBase来实现高效的NoSQL数据库应用。HBase介绍HBase是一个高可扩展、高可靠性、基

在Beego中使用HBase进行数据存储和查询在Beego中使用HBase进行数据存储和查询Jun 22, 2023 am 11:58 AM

在Beego框架中使用HBase进行数据存储和查询随着互联网时代的不断发展,数据储存和查询变得越来越关键。大数据时代来临,各种数据源都在各自不同的领域占据着重要地位,其中非关系型数据库是一种在数据存储和查询方面优势明显的数据库,而HBase是一种基于Hadoop的分布式非关系型数据库。本文将介绍如何在Beego框架中使用HBase进行数据存储和查询。一、H

如何在Workerman中使用HBase进行数据存储与查询如何在Workerman中使用HBase进行数据存储与查询Nov 07, 2023 am 08:30 AM

Workerman是一款高性能的PHPsocket框架,它的特点是可以承载大量的并发连接。与传统的PHP框架不同的是,Workerman不依赖于Apache或Nginx等Web服务器,而是通过开启一个PHP进程,独自运行整个应用程序。Workerman具有极高的运行效率和更好的负载能力。与此同时,HBase是一个分布式的NoSQL数据库系统,广泛应用于大数

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具