This is an automated email from the ASF dual-hosted git repository.
apitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 6657a920a4 GH-48799: [C++] Improve SharedExclusiveChecker error
messages (#48800)
6657a920a4 is described below
commit 6657a920a4e4d0f0b3be20183b30157099132239
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Tue Jan 13 02:06:14 2026 +0900
GH-48799: [C++] Improve SharedExclusiveChecker error messages (#48800)
### Rationale for this change
The XXX comment in `SharedExclusiveChecker` noted that error messages were
too generic and didn't describe the actual operations involved.
**Shared lock:**
`ReadAt()`:
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L210-L212
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L215-L217
`GetSize()`:
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L199-L201
**Exclusive lock:**
`Read()`:
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L109-L111
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L114-L116
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L179-L181
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L184-L186
`Seek()`:
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L194-L196
`Tell()`:
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L104-L106
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L174-L176
`Peek()`:
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L119-L121
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L189-L191
`Close()`:
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L94-L96
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L164-L166
`Abort()`:
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L99-L101
https://github.com/apache/arrow/blob/7be5a89ef083f38317fd94330127be5b5df648d8/cpp/src/arrow/io/concurrency.h#L169-L171
### What changes are included in this PR?
Improved three error messages in `SharedExclusiveChecker` to explicitly
list the I/O operations involved:
- Shared lock operations: `ReadAt`, `GetSize`
- Exclusive lock operations: `Read`, `Seek`, `Tell`, `Peek`, `Close`,
`Abort`
### Are these changes tested?
I manually tested all of combinations.
### Are there any user-facing changes?
No.
* GitHub Issue: #48799
Authored-by: Hyukjin Kwon <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
---
cpp/src/arrow/io/interfaces.cc | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/cpp/src/arrow/io/interfaces.cc b/cpp/src/arrow/io/interfaces.cc
index 75f3d71ae8..12c124ce21 100644
--- a/cpp/src/arrow/io/interfaces.cc
+++ b/cpp/src/arrow/io/interfaces.cc
@@ -338,10 +338,9 @@ SharedExclusiveChecker::SharedExclusiveChecker() :
impl_(new Impl) {}
void SharedExclusiveChecker::LockShared() {
std::lock_guard<std::mutex> lock(impl_->mutex);
- // XXX The error message doesn't really describe the actual situation
- // (e.g. ReadAt() called while Read() call in progress)
ARROW_CHECK_EQ(impl_->n_exclusive, 0)
- << "Attempted to take shared lock while locked exclusive";
+ << "Cannot perform position-independent I/O (ReadAt/GetSize) while an "
+ "exclusive operation (Read/Seek/Tell/Peek/Close/Abort) is in
progress";
++impl_->n_shared;
}
@@ -354,9 +353,11 @@ void SharedExclusiveChecker::UnlockShared() {
void SharedExclusiveChecker::LockExclusive() {
std::lock_guard<std::mutex> lock(impl_->mutex);
ARROW_CHECK_EQ(impl_->n_shared, 0)
- << "Attempted to take exclusive lock while locked shared";
+ << "Cannot perform exclusive I/O operation
(Read/Seek/Tell/Peek/Close/Abort) while "
+ "position-independent operations (ReadAt/GetSize) are in progress";
ARROW_CHECK_EQ(impl_->n_exclusive, 0)
- << "Attempted to take exclusive lock while already locked exclusive";
+ << "Cannot perform exclusive I/O operation
(Read/Seek/Tell/Peek/Close/Abort) while "
+ "another exclusive operation is already in progress";
++impl_->n_exclusive;
}