Potential Inconsistency of Branch Existence Memoization in Multi-Replica Environments
Hello,
I have been studying the GitLab source code recently and came across a piece of code that I'm having some difficulty understanding. I apologize in advance if this is not the typical format for issues, but I could not find an appropriate issue template that matches my concern.
Here's the code in question, from https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/repository_cache_adapter.rb#L60
define_method("#{name}_include?") do |value|
ivar = "@#{name}_include"
memoized = instance_variable_get(ivar) || {}
lookup = proc { __send__(name).include?(value) } # rubocop:disable GitlabSecurity/PublicSend
next memoized[value] if memoized.key?(value)
memoized[value] =
if strong_memoized?(name)
lookup.call
else
result, exists = redis_set_cache.try_include?(name, value)
exists ? result : lookup.call
end
instance_variable_set(ivar, memoized)[value]
end
From what I understand, this code uses memoized[branch_name]
to record whether a branch exists, and this is held in memory.
My question is about the potential inconsistency of this approach in a multi-replica environment such as multiple Kubernetes pods. Could it occur that a new branch new_branch
is created in pod1
, but memoized[new_branch]
in pod2
's memory still returns false
?
I'm wondering if this could lead to potential issues and if there are any mechanisms in place to handle this kind of scenario.
Thanks for any help.