Skip to content

Commit

Permalink
Replace semaphore with mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
YutSean committed May 18, 2021
1 parent 5c2545c commit d154d71
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
18 changes: 2 additions & 16 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"sync"
"time"

"golang.org/x/sync/semaphore"

log "github.com/sirupsen/logrus"
"github.com/tsuna/gohbase/compression"
"github.com/tsuna/gohbase/hrpc"
Expand All @@ -29,7 +27,6 @@ const (
defaultZkRoot = "/hbase"
defaultZkTimeout = 30 * time.Second
defaultEffectiveUser = "root"
defaultMetaLimit = 50
)

// Client a regular HBase client
Expand Down Expand Up @@ -93,11 +90,8 @@ type client struct {
// regionReadTimeout is the maximum amount of time to wait for regionserver reply
regionReadTimeout time.Duration

// The max number of the goroutines that look up meta table simultaneously.
metaLimit int64

// The corresponding semaphore of metaLimit
sema *semaphore.Weighted
// The lock to control meta table lookup
lock sync.Mutex

done chan struct{}
closeOnce sync.Once
Expand Down Expand Up @@ -135,7 +129,6 @@ func newClient(zkquorum string, options ...Option) *client {
zkRoot: defaultZkRoot,
zkTimeout: defaultZkTimeout,
effectiveUser: defaultEffectiveUser,
metaLimit: defaultMetaLimit,
regionLookupTimeout: region.DefaultLookupTimeout,
regionReadTimeout: region.DefaultReadTimeout,
done: make(chan struct{}),
Expand All @@ -149,13 +142,6 @@ func newClient(zkquorum string, options ...Option) *client {
//since the zkTimeout could be changed as an option
c.zkClient = zk.NewClient(zkquorum, c.zkTimeout)

if c.metaLimit > 0 {
c.sema = semaphore.NewWeighted(c.metaLimit)
} else {
c.sema = semaphore.NewWeighted(defaultMetaLimit)
c.metaLimit = defaultMetaLimit
}

return c
}

Expand Down
4 changes: 2 additions & 2 deletions rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ func (c *client) metaLookup(ctx context.Context,
return nil, "", err
}

c.sema.Acquire(context.Background(), 1)
c.lock.Lock()
scanner := c.Scan(rpc)
resp, err := scanner.Next()
c.sema.Release(1)
c.lock.Unlock()
if err == io.EOF {
return nil, "", TableNotFound
}
Expand Down

0 comments on commit d154d71

Please sign in to comment.