[MOD-9023] Replacing freeFlag with a reference counter#5736
[MOD-9023] Replacing freeFlag with a reference counter#5736
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5736 +/- ##
==========================================
- Coverage 88.13% 88.11% -0.03%
==========================================
Files 198 200 +2
Lines 35999 36050 +51
==========================================
+ Hits 31727 31764 +37
- Misses 4272 4286 +14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/coord/dist_aggregate.c
Outdated
| if (timedout && !cmd->forCursor) { | ||
| newCmd = MR_NewCommand(4, "_FT.CURSOR", "DEL", idx, buf); | ||
| newCmd.depleted = true; | ||
| // newCmd.depleted = true; |
There was a problem hiding this comment.
This is wrong. Here the cmd is essentially not depleted as we are going to send the shard another request...
src/coord/rmr/rmr.c
Outdated
| RS_LOG_ASSERT_FMT(pending >= 0, "Pending (%d) should not reach a negative value. inproc: %d, freeflag: %d, channel size: %d, shard_slot: %d", | ||
| pending, ctx->it->ctx.inProcess, ctx->it->ctx.freeFlag, MRChannel_Size(ctx->it->ctx.chan), ctx->cmd.targetSlot); |
There was a problem hiding this comment.
Can we always print it in debug mode rather than only when the assertion fails? perhaps it can bring more information when time comes.
…e one side is changing it twice. The refcount is increased when a new job is pushed to the queue, and decreased when the coordinator doesn't need any replies, or when all readers have done executing the job. introduce logging capabilities when ENABLE_ASSERT=1 : RS_DEBUG_LOG and RS_DEBUG_LOG_FMT to log in debug level
GuyAv46
left a comment
There was a problem hiding this comment.
What a catch and what a solution 🎣 🥇
| #define RS_DEBUG_LOG_FMT(fmt, ...) // NOP | ||
| #define RS_DEBUG_LOG(str) // NOP |
There was a problem hiding this comment.
Why have the debug logs depend on ENABLE_ASSERT?
Since they are in debug level I think we should always have them
There was a problem hiding this comment.
Their purpose is to be used in a testing env, not in production (even if it's only enabled with debug loglevel)
There was a problem hiding this comment.
Yes, why not have it in production?
There was a problem hiding this comment.
We don't know the impact on performance of calling RedisModule_log (even if it's not the configured log level, it still executes some code), so i prefer not to compile it at all.
We can open a ticket to measure that
|
Only merged pull requests can be backported. |
|
/backport |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin 8.0
git worktree add -d .worktree/backport-5736-to-8.0 origin/8.0
cd .worktree/backport-5736-to-8.0
git switch --create backport-5736-to-8.0
git cherry-pick -x 3420e93a87a6fbd4b8880075b557cf8e5d4a4ab0 |
* add prints * fix * no depletion in getCursorCommand * add info to assert * free flag is now a ref counter to avoid potential race condition where one side is changing it twice. The refcount is increased when a new job is pushed to the queue, and decreased when the coordinator doesn't need any replies, or when all readers have done executing the job. introduce logging capabilities when ENABLE_ASSERT=1 : RS_DEBUG_LOG and RS_DEBUG_LOG_FMT to log in debug level * cleanups * cr (cherry picked from commit 3420e93)
[MOD-9023] Replacing freeFlag with a reference counter (#5736) * add prints * fix * no depletion in getCursorCommand * add info to assert * free flag is now a ref counter to avoid potential race condition where one side is changing it twice. The refcount is increased when a new job is pushed to the queue, and decreased when the coordinator doesn't need any replies, or when all readers have done executing the job. introduce logging capabilities when ENABLE_ASSERT=1 : RS_DEBUG_LOG and RS_DEBUG_LOG_FMT to log in debug level * cleanups * cr (cherry picked from commit 3420e93)
|
/backport |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin 2.10
git worktree add -d .worktree/backport-5736-to-2.10 origin/2.10
cd .worktree/backport-5736-to-2.10
git switch --create backport-5736-to-2.10
git cherry-pick -x 3420e93a87a6fbd4b8880075b557cf8e5d4a4ab0 |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin 8.0
git worktree add -d .worktree/backport-5736-to-8.0 origin/8.0
cd .worktree/backport-5736-to-8.0
git switch --create backport-5736-to-8.0
git cherry-pick -x 3420e93a87a6fbd4b8880075b557cf8e5d4a4ab0 |
Already backported |
* add prints * fix * no depletion in getCursorCommand * add info to assert * free flag is now a ref counter to avoid potential race condition where one side is changing it twice. The refcount is increased when a new job is pushed to the queue, and decreased when the coordinator doesn't need any replies, or when all readers have done executing the job. introduce logging capabilities when ENABLE_ASSERT=1 : RS_DEBUG_LOG and RS_DEBUG_LOG_FMT to log in debug level * cleanups * cr (cherry picked from commit 3420e93)
[MOD-9023] Replacing freeFlag with a reference counter (#5736) * add prints * fix * no depletion in getCursorCommand * add info to assert * free flag is now a ref counter to avoid potential race condition where one side is changing it twice. The refcount is increased when a new job is pushed to the queue, and decreased when the coordinator doesn't need any replies, or when all readers have done executing the job. introduce logging capabilities when ENABLE_ASSERT=1 : RS_DEBUG_LOG and RS_DEBUG_LOG_FMT to log in debug level * cleanups * cr (cherry picked from commit 3420e93)
[MOD-9023] Replacing freeFlag with a reference counter (#5736) * add prints * fix * no depletion in getCursorCommand * add info to assert * free flag is now a ref counter to avoid potential race condition where one side is changing it twice. The refcount is increased when a new job is pushed to the queue, and decreased when the coordinator doesn't need any replies, or when all readers have done executing the job. introduce logging capabilities when ENABLE_ASSERT=1 : RS_DEBUG_LOG and RS_DEBUG_LOG_FMT to log in debug level * cleanups * cr (cherry picked from commit 3420e93) (cherry picked from commit 607a118)
[MOD-9023] Replacing freeFlag with a reference counter (#5736) * add prints * fix * no depletion in getCursorCommand * add info to assert * free flag is now a ref counter to avoid potential race condition where one side is changing it twice. The refcount is increased when a new job is pushed to the queue, and decreased when the coordinator doesn't need any replies, or when all readers have done executing the job. introduce logging capabilities when ENABLE_ASSERT=1 : RS_DEBUG_LOG and RS_DEBUG_LOG_FMT to log in debug level * cleanups * cr (cherry picked from commit 3420e93) (cherry picked from commit 607a118)
[2.10] [MOD-9023] Replacing freeFlag with a reference counter (#5784) [MOD-9023] Replacing freeFlag with a reference counter (#5736) * add prints * fix * no depletion in getCursorCommand * add info to assert * free flag is now a ref counter to avoid potential race condition where one side is changing it twice. The refcount is increased when a new job is pushed to the queue, and decreased when the coordinator doesn't need any replies, or when all readers have done executing the job. introduce logging capabilities when ENABLE_ASSERT=1 : RS_DEBUG_LOG and RS_DEBUG_LOG_FMT to log in debug level * cleanups * cr (cherry picked from commit 3420e93) (cherry picked from commit 607a118)
[2.10] [MOD-9023] Replacing freeFlag with a reference counter (#5784) [MOD-9023] Replacing freeFlag with a reference counter (#5736) * add prints * fix * no depletion in getCursorCommand * add info to assert * free flag is now a ref counter to avoid potential race condition where one side is changing it twice. The refcount is increased when a new job is pushed to the queue, and decreased when the coordinator doesn't need any replies, or when all readers have done executing the job. introduce logging capabilities when ENABLE_ASSERT=1 : RS_DEBUG_LOG and RS_DEBUG_LOG_FMT to log in debug level * cleanups * cr (cherry picked from commit 3420e93) (cherry picked from commit 607a118) (cherry picked from commit d01e71d)
This PR fixes a race condition on
freeFlagin the coordinator mechanism.The issue occurred because
freeFlagwas expected to be reset by the uv thread when the coordinator reachedMRIterator_Releasebut since the flag is reset from the a BG thread, this was not always the case.This led to an incorrect sequence of operations, ultimately causing an assertion failure.
To resolve this, freeFlag has been replaced with a reference counter, which:
Logging improvements:
RS_DEBUG_LOG_FMTandRS_DEBUG_LOGmacros for debug logging indeps/rmutil/rm_assert.h.ENABLE_ASSERT=1it will callRedisModule_Logwith "debug" level