Prevent race condition on load balancer fix (final)
What does this MR do and why?
Replace redis set with a lua script to atomically update the LSN to prevent race conditions on the db load balancer. See issue below for important details.
References
https://gitlab.com/gitlab-org/gitlab/-/work_items/573726
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate the LUA script locally:
you can save the ATOMIC_STICKING_SCRIPT into a file (i.e. script.lua) and
go to the gkd/redis/ directory:
- Make sure redis is running (
gdk start redis) - Examples:
# First write (no existing key) — returns (integer) 1
redis-cli -s redis.socket --eval script.lua mylsnkey , 0/1000 30
# Higher LSN — returns (integer) 1, updates value
redis-cli -s redis.socket --eval script.lua mylsnkey , 0/2000 30
# Lower LSN — returns (integer) 0, keeps current, refreshes TTL
redis-cli -s redis.socket --eval script.lua mylsnkey , 0/1500 30
# Invalid LSN — returns (error) ERR ARGV[1] must be a valid LSN (e.g. 0/16B3A78)
redis-cli -s redis.socket --eval script.lua mylsnkey , 120 30
# Invalid TTL — returns (error) ERR ARGV[2] (TTL) must be a positive integer
redis-cli -s redis.socket --eval script.lua mylsnkey , 0/1000 0
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Irina Bronipolsky