From d154d71e4ad57a593c805a09c5edb56d746e291b Mon Sep 17 00:00:00 2001 From: Yutong Sean Date: Tue, 18 May 2021 10:28:57 +0800 Subject: [PATCH] Replace semaphore with mutex --- client.go | 18 ++---------------- rpc.go | 4 ++-- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/client.go b/client.go index 0d340561..af8553cf 100644 --- a/client.go +++ b/client.go @@ -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" @@ -29,7 +27,6 @@ const ( defaultZkRoot = "/hbase" defaultZkTimeout = 30 * time.Second defaultEffectiveUser = "root" - defaultMetaLimit = 50 ) // Client a regular HBase client @@ -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 @@ -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{}), @@ -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 } diff --git a/rpc.go b/rpc.go index ec33aedc..d47705a7 100644 --- a/rpc.go +++ b/rpc.go @@ -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 }