-
Notifications
You must be signed in to change notification settings - Fork 401
feat: code style for cache package #773
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
feat: code style for cache package #773
Conversation
Here is the save operation. Grouping is reasonable. After the previous function is executed immediately, there is a lock behind it. The save operation is likely to cause a longer lock waiting time.
…------------------ Original ------------------
From: liaochuntao ***@***.***>
Date: Thu,Oct 27,2022 11:28 PM
To: polarismesh/polaris ***@***.***>
Cc: heige ***@***.***>, Author ***@***.***>
Subject: Re: [polarismesh/polaris] feat: code style for cache package (PR#773)
@chuntaojun commented on this pull request.
In cache/config_file_bucket.go:
> @@ -66,19 +66,14 @@ func (b *configFileGroupBucket) saveGroupById(id uint64, item *model.ConfigFileG } func (b *configFileGroupBucket) saveGroup(namespace, group string, item *model.ConfigFileGroup) { -func() { -b.lock.Lock() -defer b.lock.Unlock() +b.lock.Lock() +defer b.lock.Unlock()
锁的持有时间变长了
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
lock 处理的是 map[namespace]bucket 中关于bucket 的插入,一旦 bucket 插入完成,lock 的写锁本身就应该立即释放,而不是不断持有写锁直到 bucket 的插入操作完成 |
Before this, a function was executed immediately, and whether there was an initialization operation was judged in the immediately executed function. If there was no initialization, a lock operation was performed here. Then another lock operation is performed, the write operation is performed, and the lock is released. I adjusted the code so that it only needs to lock, unlock, initialize and write again once. For locks, it actually reduces the time and granularity of locking and unlocking. I will add a unit test case later, and you will understand why I do this.
…------------------ Original ------------------
From: daheige ***@***.***>
Date: Thu,Oct 27,2022 11:31 PM
To: reply+ACMGV64GPTR7VPAGFD2LHNOBM7LDPEVBNHHFJ6LAVQ ***@***.***>, polarismesh/polaris ***@***.***>
Cc: daheige ***@***.***>, Author ***@***.***>
Subject: Re: [polarismesh/polaris] feat: code style for cache package (PR#773)
Here is the save operation. Grouping is reasonable. After the previous function is executed immediately, there is a lock behind it. The save operation is likely to cause a longer lock waiting time.
------------------ Original ------------------
From: liaochuntao ***@***.***>
Date: Thu,Oct 27,2022 11:28 PM
To: polarismesh/polaris ***@***.***>
Cc: heige ***@***.***>, Author ***@***.***>
Subject: Re: [polarismesh/polaris] feat: code style for cache package (PR#773)
@chuntaojun commented on this pull request.
In cache/config_file_bucket.go:
> @@ -66,19 +66,14 @@ func (b *configFileGroupBucket) saveGroupById(id uint64, item *model.ConfigFileG } func (b *configFileGroupBucket) saveGroup(namespace, group string, item *model.ConfigFileGroup) { -func() { -b.lock.Lock() -defer b.lock.Unlock() +b.lock.Lock() +defer b.lock.Unlock()
锁的持有时间变长了
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Codecov Report
@@ Coverage Diff @@
## main #773 +/- ##
==========================================
- Coverage 56.29% 56.28% -0.02%
==========================================
Files 159 159
Lines 28978 28958 -20
==========================================
- Hits 16313 16298 -15
+ Misses 10494 10492 -2
+ Partials 2171 2168 -3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Please provide issue(s) of this PR:
Fixes #774
code style for cache package