`

2。hbase CRUD--Lease in hbase

 
阅读更多

 

1.What is Lease

in general,between the communication of client and Region Server,there are RPCs in there.Lease is a mechanism to hold a reference object updated each client rpc. so Lease is similar to Hearbeat for server to know that client is alive always!(of course that is in a certain period in fact)

 

2.Why use Lease

at a first communication ,e.g. a scan operation,the client will get by batch to limit to size returned,then the client issue the second request to retrieve later data.during these requests,region Server will know to these are a scan operaction in fact,so it is needless to renew or create some new objects/caches/handles to locate the nexxt batch data.that is using a Lease will decrease some resourcces overhead!

so all theese cases will provide more stable,avilable.

 

u will say:why not use hearbeat instead of it?yes this is a good question.but if  take a look carefully,the advantages are distingguished :

-Lease has NOT additional connection overhead,but Hearbeat does.in server,there are resouces created once per 'session',and ONLY 'update-on-requesting'

-easy to implement.the server can use some mechanism like lockid to archive Lease.and the client will only keep a lockid in mind for each request.also,the server will have a timeout strategy to cancel this Lease if over a time range that client has not requested something.

and if some exceptions occurs in server,the client will get them and use some utility methods(eg. scan#close() or htable#unlock() to release the lease immediately)

 

3.How to use Lease

as mentioned above ,there are two clients interacted with Lease:user client and server-side listener.

that is a 'double check ' for the lease in fact!



 

 

4.Compare:Mutation VS Get VS Scan

OP use lease through by time to get time to release feature
Mutation yes row lock id

client:lockRow()

server:internalObtainRowLock() if client not locked row before

client: htable#unlock

server:

RowLockListener#leaseExpired

 client:

manually to generate or remove lease

server:

automatically to generate or remove if timeout

Scan yes scannerId

 client:openScanner

(transparent to client)

 client:

scanner#close

server:

ScannerListener#leaseExpired

 same as above
Gets no        
           

 

Questions:

while lock id is unique BUT scanner id ?this will causes some odd issues when multi clients use same scanner id.

lock id generateion:(unique)

while (true) {
        Integer lockId = lockIdGenerator.incrementAndGet();
        HashedBytes existingRowKey = lockIds.putIfAbsent(lockId, rowKey);
        if (existingRowKey == null) {
          return lockId;
        } else {
          // lockId already in use, jump generator to a new spot
          lockIdGenerator.set(rand.nextInt());
        }
      }

 

 

scanner id :

protected long addScanner(RegionScanner s) throws LeaseStillHeldException {
    long scannerId = -1L;
    scannerId = rand.nextLong();
    String scannerName = String.valueOf(scannerId);
    scanners.put(scannerName, s);	//直接put不考虑存在问题? TBD
    this.leases.createLease(scannerName, new ScannerListener(scannerName));
    return scannerId;
  }

 

any clues for me is appreciated!

 

 Note

* invoke a scanner's close method will only remove the lease on region server,but NOT for connection to it.instead of Htable's close method does close all connections established to all servers!

 

Ref:

hbase源码学习.Lease

  • 大小: 20 KB
分享到:
评论
2 楼 leibnitz 2013-09-22  
also, there is a similar bug   .
HBASE-5329:duplicate row lock id
1 楼 leibnitz 2013-08-23  
after a googling,i have foud this a bug!yes this is first bug i found in hbase!
https://issues.apache.org/jira/browse/HBASE-6838

相关推荐

    ycsb-hbase14-binding-0.17.0

    ycsb-hbase14-binding-0.17.0

    HBase(hbase-2.4.9-bin.tar.gz)

    HBase(hbase-2.4.9-bin.tar.gz)是一个分布式的、面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统(File System...

    hbase的hbase-1.2.0-cdh5.14.2.tar.gz资源包

    hbase的hbase-1.2.0-cdh5.14.2.tar.gz资源包

    hbase-meta-repair-hbase-2.0.2.jar

    HBase 元数据修复工具包。 ①修改 jar 包中的application.properties,重点是 zookeeper.address、zookeeper.nodeParent、hdfs....③开始修复 `java -jar -Drepair.tableName=表名 hbase-meta-repair-hbase-2.0.2.jar`

    hbase-prefix-tree-1.4.3-API文档-中文版.zip

    赠送jar包:hbase-prefix-tree-1.4.3.jar; 赠送原API文档:hbase-prefix-tree-1.4.3-javadoc.jar; 赠送源代码:hbase-prefix-tree-1.4.3-sources.jar; 赠送Maven依赖信息文件:hbase-prefix-tree-1.4.3.pom; ...

    phoenix-hbase-2.2-5.1.2-bin.tar.gz

    phoenix-hbase-2.2-5.1.2-bin.tar.gz

    hive-hbase-handler-1.2.1.jar

    被编译的hive-hbase-handler-1.2.1.jar,用于在Hive中创建关联HBase表的jar,解决创建Hive关联HBase时报FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop....

    hbase-hadoop-compat-1.1.3-API文档-中文版.zip

    赠送jar包:hbase-hadoop-compat-1.1.3.jar; 赠送原API文档:hbase-hadoop-compat-1.1.3-javadoc.jar; 赠送源代码:hbase-hadoop-compat-1.1.3-sources.jar; 赠送Maven依赖信息文件:hbase-hadoop-compat-1.1.3....

    phoenix-client-hbase-2.2-5.1.2.jar

    phoenix-client-hbase-2.2-5.1.2.jar

    hbase-prefix-tree-1.1.3-API文档-中文版.zip

    赠送jar包:hbase-prefix-tree-1.1.3.jar; 赠送原API文档:hbase-prefix-tree-1.1.3-javadoc.jar; 赠送源代码:hbase-prefix-tree-1.1.3-sources.jar; 赠送Maven依赖信息文件:hbase-prefix-tree-1.1.3.pom; ...

    hbase-1.2.1-bin.tar.gz.zip

    hbase-1.2.1-bin.tar.gz.zip 提示:先解压再使用,最外层是zip压缩文件

    hbase-metrics-api-1.4.3-API文档-中文版.zip

    赠送jar包:hbase-metrics-api-1.4.3.jar; 赠送原API文档:hbase-metrics-api-1.4.3-javadoc.jar; 赠送源代码:hbase-metrics-api-1.4.3-sources.jar; 赠送Maven依赖信息文件:hbase-metrics-api-1.4.3.pom; ...

    hbase-client-2.1.0-cdh6.3.0.jar

    hbase-client-2.1.0-cdh6.3.0.jar

    hbase-hbck2-1.1.0-SNAPSHOT.jar

    hbase-hbck2-1.1.0-SNAPSHOT.jar

    hbase-hadoop2-compat-1.2.12-API文档-中文版.zip

    赠送jar包:hbase-hadoop2-compat-1.2.12.jar; 赠送原API文档:hbase-hadoop2-compat-1.2.12-javadoc.jar; 赠送源代码:hbase-hadoop2-compat-1.2.12-sources.jar; 赠送Maven依赖信息文件:hbase-hadoop2-compat-...

    hbase-hadoop-compat-1.1.3-API文档-中英对照版.zip

    赠送jar包:hbase-hadoop-compat-1.1.3.jar; 赠送原API文档:hbase-hadoop-compat-1.1.3-javadoc.jar; 赠送源代码:hbase-hadoop-compat-1.1.3-sources.jar; 赠送Maven依赖信息文件:hbase-hadoop-compat-1.1.3....

    hbase-common-1.4.3-API文档-中文版.zip

    赠送jar包:hbase-common-1.4.3.jar; 赠送原API文档:hbase-common-1.4.3-javadoc.jar; 赠送源代码:hbase-common-1.4.3-sources.jar; 赠送Maven依赖信息文件:hbase-common-1.4.3.pom; 包含翻译后的API文档:...

    hbase-2.2.6-bin.tar.gz

    hbase-2.2.6-bin.tar.gz HBase是一个分布式的、面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统(File System)所...

    hbase-hadoop2-compat-1.1.3-API文档-中文版.zip

    赠送jar包:hbase-hadoop2-compat-1.1.3.jar; 赠送原API文档:hbase-hadoop2-compat-1.1.3-javadoc.jar; 赠送源代码:hbase-hadoop2-compat-1.1.3-sources.jar; 赠送Maven依赖信息文件:hbase-hadoop2-compat-...

Global site tag (gtag.js) - Google Analytics