gohbase
gohbase copied to clipboard
findRegion should a lock to avoid cache avalanche
If there are a lot of RPC request to a same table, but the region information not in cache.
func (c *client) findRegion(ctx context.Context, table, key []byte) (hrpc.RegionInfo, error) {
//get or create table related lcck in hash
var tableName = string(table)
var iLock, _ = c.tMetaLockHash.LoadOrStore(tableName, &sync.Mutex{})
var lock = iLock.(*sync.Mutex)
locker.Lock()
defer locker.Unlock()
if reg := c.getRegionFromCache(table, key); reg != nil {
return reg, nil
}
.....