-
Notifications
You must be signed in to change notification settings - Fork 580
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
RedisConnection#Connect(): get rid of spin lock #10265
Open
Al2Klimov
wants to merge
1
commit into
master
Choose a base branch
from
RedisConnection-spinlock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ RedisConnection::RedisConnection(boost::asio::io_context& io, String host, int p | |
m_DbIndex(db), m_CertPath(std::move(certPath)), m_KeyPath(std::move(keyPath)), m_Insecure(insecure), | ||
m_CaPath(std::move(caPath)), m_CrlPath(std::move(crlPath)), m_TlsProtocolmin(std::move(tlsProtocolmin)), | ||
m_CipherList(std::move(cipherList)), m_ConnectTimeout(connectTimeout), m_DebugInfo(std::move(di)), m_Connecting(false), m_Connected(false), | ||
m_Started(false), m_Strand(io), m_QueuedWrites(io), m_QueuedReads(io), m_LogStatsTimer(io), m_Parent(parent) | ||
m_Started(false), m_Strand(io), m_QueuedWrites(io), m_QueuedReads(io), m_NoQueuedReads(io, true), m_LogStatsTimer(io), m_Parent(parent) | ||
{ | ||
if (useTls && m_Path.IsEmpty()) { | ||
UpdateTLSContext(); | ||
|
@@ -302,12 +302,6 @@ void RedisConnection::Connect(asio::yield_context& yc) | |
|
||
boost::asio::deadline_timer timer (m_Strand.context()); | ||
|
||
auto waitForReadLoop ([this, &yc]() { | ||
while (!m_Queues.FutureResponseActions.empty()) { | ||
IoEngine::YieldCurrentCoroutine(yc); | ||
} | ||
}); | ||
|
||
for (;;) { | ||
try { | ||
if (m_Path.IsEmpty()) { | ||
|
@@ -340,7 +334,7 @@ void RedisConnection::Connect(asio::yield_context& yc) | |
} | ||
|
||
Handshake(conn, yc); | ||
waitForReadLoop(); | ||
m_NoQueuedReads.Wait(yc); | ||
m_TlsConn = std::move(conn); | ||
} else { | ||
Log(m_Parent ? LogNotice : LogInformation, "IcingaDB") | ||
|
@@ -352,7 +346,7 @@ void RedisConnection::Connect(asio::yield_context& yc) | |
|
||
icinga::Connect(conn->next_layer(), m_Host, Convert::ToString(m_Port), yc); | ||
Handshake(conn, yc); | ||
waitForReadLoop(); | ||
m_NoQueuedReads.Wait(yc); | ||
m_TcpConn = std::move(conn); | ||
} | ||
} else { | ||
|
@@ -365,7 +359,7 @@ void RedisConnection::Connect(asio::yield_context& yc) | |
|
||
conn->next_layer().async_connect(Unix::endpoint(m_Path.CStr()), yc); | ||
Handshake(conn, yc); | ||
waitForReadLoop(); | ||
m_NoQueuedReads.Wait(yc); | ||
m_UnixConn = std::move(conn); | ||
} | ||
|
||
|
@@ -477,6 +471,7 @@ void RedisConnection::ReadLoop(asio::yield_context& yc) | |
} | ||
|
||
m_QueuedReads.Clear(); | ||
m_NoQueuedReads.Set(); | ||
} | ||
} | ||
|
||
|
@@ -577,6 +572,7 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection: | |
} | ||
|
||
m_QueuedReads.Set(); | ||
m_NoQueuedReads.Clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not perform this within the |
||
} | ||
|
||
if (next.FireAndForgetQueries) { | ||
|
@@ -613,6 +609,7 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection: | |
} | ||
|
||
m_QueuedReads.Set(); | ||
m_NoQueuedReads.Clear(); | ||
} | ||
|
||
if (next.GetResultOfQuery) { | ||
|
@@ -638,6 +635,7 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection: | |
} | ||
|
||
m_QueuedReads.Set(); | ||
m_NoQueuedReads.Clear(); | ||
} | ||
|
||
if (next.GetResultsOfQueries) { | ||
|
@@ -660,6 +658,7 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection: | |
m_Queues.FutureResponseActions.emplace(FutureResponseAction{item.first.size(), ResponseAction::DeliverBulk}); | ||
|
||
m_QueuedReads.Set(); | ||
m_NoQueuedReads.Clear(); | ||
} | ||
|
||
if (next.Callback) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I often struggle to differentiate between the
AsioConditionVariable::Clear()
andAsioConditionVariable::Set()
methods since they seem to perform very similar functions, and neither of them includes a clear comment explaining their purpose. And yet, I had to trace on my own to understand why theinit
parameter is set for this in the constructor but not for the others. Could you please provide some comments explaining the scenarios in which this gets unblocked? Additionally, I would suggest naming that new property something likem_ReadLoopDone
to better reflect its original intentions.