Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid cache avalanche #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ type client struct {
string, time.Duration, compression.Codec) hrpc.RegionClient

compressionCodec compression.Codec


// region looker lock container
regionLookerMap sync.Map
}

// NewClient creates a new HBase client.
Expand Down
12 changes: 12 additions & 0 deletions rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"io"
"strconv"
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -54,6 +55,17 @@ const (
)

func (c *client) getRegionForRpc(rpc hrpc.Call) (hrpc.RegionInfo, error) {
// Check the cache for a region that can handle this request
// if in cache, return quickly
if reg := c.getRegionFromCache(rpc.Table(), rpc.Key()); reg != nil {
return reg, nil
}

il, _ := c.regionLookerMap.LoadOrStore(string(rpc.Table()), &sync.Mutex{})
lo := il.(*sync.Mutex)
lo.Lock()
defer lo.Unlock()

for i := 0; i < maxFindRegionTries; i++ {
// Check the cache for a region that can handle this request
if reg := c.getRegionFromCache(rpc.Table(), rpc.Key()); reg != nil {
Expand Down