Skip to content

Commit

Permalink
Add some comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitlibar committed Dec 7, 2023
1 parent 366095a commit ec5348a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Common/RWLock.cpp
Expand Up @@ -177,6 +177,7 @@ RWLockImpl::getLock(RWLockImpl::Type type, const String & query_id, const std::c
/// Lock is free to acquire
if (rdlock_owner == readers_queue.end() && wrlock_owner == writers_queue.end())
{
/// Set `rdlock_owner` or `wrlock_owner` and make it owner.
(type == Read ? rdlock_owner : wrlock_owner) = it_group; /// SM2: nothrow
grantOwnership(it_group);
}
Expand Down Expand Up @@ -341,13 +342,21 @@ void RWLockImpl::grantOwnershipToAllReaders() noexcept
{
if (rdlock_owner != readers_queue.end())
{
size_t num_granted = 0;

for (;;)
{
if (!rdlock_owner->ownership)
++num_granted;
grantOwnership(rdlock_owner);
if (std::next(rdlock_owner) == readers_queue.end())
break;
++rdlock_owner;
}

/// There couldn't be more than one reader group which is not an owner.
/// (Because we add a new reader group only if the last reader group is an owner - see the `can_use_last_group` variable).
chassert(num_granted <= 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Common/tests/gtest_rw_lock.cpp
Expand Up @@ -37,7 +37,7 @@ namespace
if (timepoint.length() < 5)
timepoint.insert(0, 5 - timepoint.length(), ' ');
std::lock_guard lock{mutex};
std::cout << timepoint << " : " << event << std::endl;
//std::cout << timepoint << " : " << event << std::endl;
events.emplace_back(std::move(event));
}

Expand Down
Expand Up @@ -237,7 +237,8 @@ def truncate_tables():
while time.time() < end_time:
table_name = f"mydb.tbl{randint(1, num_nodes)}"
node = nodes[randint(0, num_nodes - 1)]
# "TRUNCATE TABLE IF EXISTS" still can throw some errors (e.g. "WRITE locking attempt on node0 has timed out!")
# "TRUNCATE TABLE IF EXISTS" still can throw some errors
# (e.g. "WRITE locking attempt on node0 has timed out!" if the table engine is "Log").
# So we use query_and_get_answer_with_error() to ignore any errors.
# `lock_acquire_timeout` is reduced because we don't wait our test to wait too long.
node.query_and_get_answer_with_error(
Expand Down

0 comments on commit ec5348a

Please sign in to comment.