2。hbase CRUD--Lease in hbase

本文深入探讨了HBase中Lease机制的工作原理及其优势。详细解释了Lease如何通过减少资源开销提高系统的稳定性和可用性,并对比了Lease与Heartbeat的不同之处。此外,还分析了Lease在Mutation、Get及Scan操作中的使用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

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

OPuse leasethrough bytime to gettime to releasefeature
Mutationyesrow 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

ScanyesscannerId

 client:openScanner

(transparent to client)

 client:

scanner#close

server:

ScannerListener#leaseExpired

 same as above
Getsno    
      

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值