Skip to content

Commit 88043fd

Browse files
committed
feat: show read locks in show locks
related to #3047
1 parent 77b681e commit 88043fd

File tree

7 files changed

+41
-19
lines changed

7 files changed

+41
-19
lines changed

src/coroutine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,11 @@ bool ReadTableLock_c::UnlockRead() noexcept
11671167
return true;
11681168
}
11691169

1170+
[[nodiscard]] DWORD ReadTableLock_c::GetReads() const noexcept
1171+
{
1172+
return m_uReads;
1173+
}
1174+
11701175
ScopedWriteTable_c::ScopedWriteTable_c ( ReadTableLock_c& tTableLock )
11711176
: m_tTableLock { tTableLock }
11721177
, m_bCanWrite { tTableLock.TryWrite() }

src/coroutine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ class ReadTableLock_c final
355355
void WaitRead() noexcept;
356356
void FinishWrite() noexcept;
357357
[[nodiscard]] bool UnlockRead() noexcept;
358+
[[nodiscard]] DWORD GetReads() const noexcept;
358359
};
359360

360361
class ScopedWriteTable_c final

src/searchd.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10842,32 +10842,32 @@ void HandleMysqlShowLocks ( RowBuffer_i & tOut )
1084210842
if ( !tOut.HeadEnd () )
1084310843
return;
1084410844

10845+
auto fnLine = [&tOut](const NamedIndexType_t& dPair, int iLocks, const char* szType ) noexcept -> bool
10846+
{
10847+
tOut.PutString ( GetIndexTypeName ( dPair.m_eType ) );
10848+
tOut.PutString ( dPair.m_sName );
10849+
tOut.PutString ( szType );
10850+
tOut.PutStringf ( "Count: %d", iLocks );
10851+
return tOut.Commit ();
10852+
};
1084510853

1084610854
// collect local, rt, percolate
1084710855
auto dIndexes = GetAllServedIndexes ();
1084810856
for ( auto & dPair: dIndexes )
1084910857
{
10850-
switch ( dPair.m_eType )
10858+
auto pIndex = GetServed ( dPair.m_sName );
10859+
if ( ServedDesc_t::IsMutable ( pIndex ) )
1085110860
{
10852-
case IndexType_e::RT:
10853-
case IndexType_e::PERCOLATE:
10854-
{
10855-
auto pIndex = GetServed ( dPair.m_sName );
10856-
assert ( ServedDesc_t::IsMutable ( pIndex ) );
1085710861
RIdx_T<RtIndex_i *> pRt { pIndex };
10858-
int iLocks = pRt->GetNumOfLocks ();
10859-
if ( iLocks>0 )
10860-
{
10861-
tOut.PutString ( GetIndexTypeName ( dPair.m_eType ) );
10862-
tOut.PutString ( dPair.m_sName );
10863-
tOut.PutString ( "freeze" );
10864-
tOut.PutStringf ( "Count: %d", iLocks );
10865-
if ( !tOut.Commit () )
10866-
return;
10867-
}
10862+
const int iLocks = pRt->GetNumOfLocks ();
10863+
if ( iLocks>0 && !fnLine ( dPair, iLocks, "freeze" ) )
10864+
return;
1086810865
}
10869-
default:
10870-
break;
10866+
if ( ServedDesc_t::IsLocal ( pIndex ) )
10867+
{
10868+
const int iRLocks = pIndex->GetReadLocks();
10869+
if ( iRLocks>0 && !fnLine ( dPair, iRLocks, "read" ) )
10870+
return;
1087110871
}
1087210872
}
1087310873

src/searchdaemon.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,11 @@ void ServedIndex_c::LockRead() const noexcept
12851285
return m_tTableLock.UnlockRead();
12861286
}
12871287

1288+
[[nodiscard]] DWORD ServedIndex_c::GetReadLocks() const noexcept
1289+
{
1290+
return m_tTableLock.GetReads();
1291+
}
1292+
12881293
[[nodiscard]] Threads::Coro::ReadTableLock_c& ServedIndex_c::Locker() const noexcept
12891294
{
12901295
return m_tTableLock;

src/searchdaemon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ class ServedIndex_c : public ServedDesc_t
741741

742742
void LockRead() const noexcept;
743743
[[nodiscard]] bool UnlockRead() const noexcept;
744+
[[nodiscard]] DWORD GetReadLocks() const noexcept;
744745
[[nodiscard]] Threads::Coro::ReadTableLock_c& Locker() const noexcept;
745746
};
746747

test/test_316/model.bin

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

test/test_316/test.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ searchd
5959
</sphinxql>
6060
<sphinxql conn="1">lock tables a read</sphinxql>
6161
<sphinxql>
62+
show locks;
6263
insert into a values (9, 1);
6364
insert into b values (9, 2);
6465
update a set iid=9 where id=1;
@@ -76,8 +77,10 @@ searchd
7677
select * from b order by id asc;
7778
lock tables a read, b write;
7879
show warnings;
80+
show locks;
7981
lock tables a read, b read;
8082
show warnings;
83+
show locks;
8184
insert into a values (6, 1);
8285
insert into b values (6, 2);
8386
update a set iid=6 where id=1;
@@ -89,6 +92,13 @@ searchd
8992
update b set iid=7 where id=1;
9093
select * from a order by id asc;
9194
select * from b order by id asc;
95+
show locks;
96+
create cluster c;
97+
alter cluster c add a;
98+
lock tables a read;
99+
lock tables c:a read;
100+
alter cluster c drop a;
101+
delete cluster c;
92102
drop table a;
93103
drop table b;
94104
</sphinxql>

0 commit comments

Comments
 (0)