Skip to content

Commit

Permalink
add comment in cluster_redis_lock,add currency of WorkPool verifying
Browse files Browse the repository at this point in the history
  • Loading branch information
WhaleSong committed Nov 5, 2021
1 parent 1cc4357 commit 7e09d80
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/lock/redis/cluster_redis_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (c *ClusterRedisLock) Features() []lock.Feature {
func (c *ClusterRedisLock) TryLock(req *lock.TryLockRequest) (*lock.TryLockResponse, error) {
//try to get lock on all redis nodes
intervalStart := utils.GetMiliTimestamp(time.Now().UnixNano())
//intervalLimit must be 1/10 of expire time to make sure time of lock far less than expire time
intervalLimit := int64(req.Expire) * 1000 / 10
wg := sync.WaitGroup{}
wg.Add(len(c.clients))
Expand Down Expand Up @@ -150,6 +151,10 @@ func (c *ClusterRedisLock) TryLock(req *lock.TryLockRequest) (*lock.TryLockRespo

func (c *ClusterRedisLock) Unlock(req *lock.UnlockRequest) (*lock.UnlockResponse, error) {
wg := sync.WaitGroup{}
//err means there were some internal errors,then the status must be INTERNAL_ERROR
//the LOCK_UNEXIST and LOCK_BELONG_TO_OTHERS status codes can be ignore
//becauce they means the lock of the current redis
//returned the status code don't need to be unlocked by current invoking
_, err := c.UnlockAllRedis(req, &wg)
if err != nil {
return newInternalErrorUnlockResponse(), err
Expand Down
3 changes: 3 additions & 0 deletions components/pkg/utils/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ func ParseRedisClusterMetadata(properties map[string]string) (RedisClusterMetada
if err != nil {
return m, fmt.Errorf("redis store error: can't parse concurrency field: %s", err)
}
if con <= 0{
con = runtime.NumCPU()
}
m.Concurrency = con
} else {
m.Concurrency = runtime.NumCPU()
Expand Down
1 change: 1 addition & 0 deletions configs/config_lock_redis_cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"lock": {
"redis_cluster": {
"metadata": {
"concurrency": "0",
"redisHosts": "localhost:6381,localhost:6382,localhost:6383,localhost:6384,localhost:6385",
"redisPassword": ""
}
Expand Down

0 comments on commit 7e09d80

Please sign in to comment.