You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "shanhe72101 (via GitHub)" <gi...@apache.org> on 2025/07/31 09:29:03 UTC
[PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
shanhe72101 opened a new pull request, #3053:
URL: https://github.com/apache/brpc/pull/3053
### What problem does this PR solve?
Issue Number:#3051
Problem Summary:
### What is changed and the side effects?
Changed:
Side effects:
- Performance effects:
- Breaking backward compatibility:
---
### Check List:
- Please make sure your changes are compilable.
- When providing us with a new feature, it is best to add related tests.
- Please follow [Contributor Covenant Code of Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "lorinlee (via GitHub)" <gi...@apache.org>.
lorinlee commented on code in PR #3053:
URL: https://github.com/apache/brpc/pull/3053#discussion_r2255760385
##########
test/BUILD.bazel:
##########
@@ -238,7 +238,7 @@ cc_test(
# glog CHECK die with a fatal error
"bthread_key_unittest.cpp",
"bthread_butex_multi_tag_unittest.cpp",
- "bthread_rwlock_unittest.cpp",
+ #"bthread_rwlock_unittest.cpp",
Review Comment:
@shanhe72101 It appears that the bthread_rwlock_unittest.cpp file originally existed here, but your PR has commented out this test file. Is this as expected?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "zyearn (via GitHub)" <gi...@apache.org>.
zyearn commented on code in PR #3053:
URL: https://github.com/apache/brpc/pull/3053#discussion_r2250041048
##########
test/BUILD.bazel:
##########
@@ -238,7 +238,7 @@ cc_test(
# glog CHECK die with a fatal error
"bthread_key_unittest.cpp",
"bthread_butex_multi_tag_unittest.cpp",
- "bthread_rwlock_unittest.cpp",
+ #"bthread_rwlock_unittest.cpp",
Review Comment:
Is there any specific reason why this line is commented out?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on PR #3053:
URL: https://github.com/apache/brpc/pull/3053#issuecomment-3182592138
```shell
bthread1 bthread2
bthread_sem_timedwait
rwlock->reader_count->fetch_add(RWLockMaxReaders);
bthread_sem_post_n
bthread_mutex_unlock
rwlock->reader_count->fetch_add
```
In this case, `reader_sema` has been posted. Subsequently, there may be a problem where the write lock and read lock enter the critical section at the same time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "shanhe72101 (via GitHub)" <gi...@apache.org>.
shanhe72101 commented on PR #3053:
URL: https://github.com/apache/brpc/pull/3053#issuecomment-3173780136
> 1. `reader_sema` should also be restored.
> 2. The same problem exists with `wlock`.
In case of timeout, reader_sema will not be modified and does not require restoration. The same applies to rwlock->writer_sema.
Perhaps I haven't uncovered the truth. Please point out the specific errors, thank you
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on PR #3053:
URL: https://github.com/apache/brpc/pull/3053#issuecomment-3146285763
Please add a UT.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "shanhe72101 (via GitHub)" <gi...@apache.org>.
shanhe72101 commented on PR #3053:
URL: https://github.com/apache/brpc/pull/3053#issuecomment-3162200452
@chenBright please review,thank you
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "shanhe72101 (via GitHub)" <gi...@apache.org>.
shanhe72101 commented on PR #3053:
URL: https://github.com/apache/brpc/pull/3053#issuecomment-3146488597
> Please add a UT.
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on PR #3053:
URL: https://github.com/apache/brpc/pull/3053#issuecomment-3144536796
LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "shanhe72101 (via GitHub)" <gi...@apache.org>.
shanhe72101 commented on code in PR #3053:
URL: https://github.com/apache/brpc/pull/3053#discussion_r2250277277
##########
test/BUILD.bazel:
##########
@@ -238,7 +238,7 @@ cc_test(
# glog CHECK die with a fatal error
"bthread_key_unittest.cpp",
"bthread_butex_multi_tag_unittest.cpp",
- "bthread_rwlock_unittest.cpp",
+ #"bthread_rwlock_unittest.cpp",
Review Comment:
The unit test for rwlock is located in bthread_rwlock_unittest.cpp. I need to compile and run this test. In fact, I don't understand why bthread_rwlock_unittest.cpp was excluded.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "shanhe72101 (via GitHub)" <gi...@apache.org>.
shanhe72101 commented on code in PR #3053:
URL: https://github.com/apache/brpc/pull/3053#discussion_r2255824608
##########
test/BUILD.bazel:
##########
@@ -238,7 +238,7 @@ cc_test(
# glog CHECK die with a fatal error
"bthread_key_unittest.cpp",
"bthread_butex_multi_tag_unittest.cpp",
- "bthread_rwlock_unittest.cpp",
+ #"bthread_rwlock_unittest.cpp",
Review Comment:
@lorinlee "bthread_rwlock_unittest.cpp" is in the exclude list; you'll understand by checking the full configuration of the build target "bthread_test".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on PR #3053:
URL: https://github.com/apache/brpc/pull/3053#issuecomment-3173106379
1. `reader_sema` should also be restored.
2. The same problem exists with `wlock`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3053:
URL: https://github.com/apache/brpc/pull/3053#discussion_r2249128687
##########
src/bthread/rwlock.cpp:
##########
@@ -53,18 +53,29 @@ static int rwlock_rdlock_impl(bthread_rwlock_t* __restrict rwlock,
// Don't sample when contention profiler is off.
if (NULL == bthread::g_cp) {
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
Review Comment:
[nitpick] Missing space before opening brace. Should be 'if (rc != 0) {' to follow consistent formatting style.
```suggestion
if (rc != 0) {
```
##########
src/bthread/rwlock.cpp:
##########
@@ -53,18 +53,29 @@ static int rwlock_rdlock_impl(bthread_rwlock_t* __restrict rwlock,
// Don't sample when contention profiler is off.
if (NULL == bthread::g_cp) {
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
+ ((butil::atomic<int>*)&rwlock->reader_count)->fetch_add(-1, butil::memory_order_relaxed);
+ }
+ return rc;
}
// Ask Collector if this (contended) locking should be sampled.
const size_t sampling_range = bvar::is_collectable(&bthread::g_cp_sl);
if (!bvar::is_sampling_range_valid(sampling_range)) { // Don't sample.
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
+ ((butil::atomic<int>*)&rwlock->reader_count)->fetch_add(-1, butil::memory_order_relaxed);
+ }
+ return rc;
}
// Sample.
const int64_t start_ns = butil::cpuwide_time_ns();
int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
const int64_t end_ns = butil::cpuwide_time_ns();
+ if (rc != 0){
Review Comment:
[nitpick] Missing space before opening brace. Should be 'if (rc != 0) {' to follow consistent formatting style.
```suggestion
if (rc != 0) {
```
##########
src/bthread/rwlock.cpp:
##########
@@ -53,18 +53,29 @@ static int rwlock_rdlock_impl(bthread_rwlock_t* __restrict rwlock,
// Don't sample when contention profiler is off.
if (NULL == bthread::g_cp) {
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
+ ((butil::atomic<int>*)&rwlock->reader_count)->fetch_add(-1, butil::memory_order_relaxed);
+ }
+ return rc;
}
// Ask Collector if this (contended) locking should be sampled.
const size_t sampling_range = bvar::is_collectable(&bthread::g_cp_sl);
if (!bvar::is_sampling_range_valid(sampling_range)) { // Don't sample.
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
Review Comment:
[nitpick] Missing space before opening brace. Should be 'if (rc != 0) {' to follow consistent formatting style.
```suggestion
if (rc != 0) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright closed pull request #3053: Restore reader_count in case of failure in rwlock_rdlock_impl
URL: https://github.com/apache/brpc/pull/3053
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Restore reader_count in case of failure in rwlock_rdlock_impl (brpc)
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on PR #3053:
URL: https://github.com/apache/brpc/pull/3053#issuecomment-4486006109
Please use #3286 .
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org