Allow Gitlab::Database::LoadBalancing::Session.without_sticky_writes to stick writes within the block
In !56849 (merged), we added Gitlab::Database::LoadBalancing::Session.without_sticky_writes
, which allows a block to perform writes without subsequent reads sticking to the primary.
@ayufan rightly pointed out (!56849 (comment 535895824)) that this would be surprising in the block itself, as reads in the block would also not stick to the primary:
runner = Ci::Runner.last
without_sticky_writes do
runner.update(aa: 10) # write will be performed on primary
runner.reset # read will be done on replica unless another write outside of section did happen
end
In the specific cases we're currently using this method for (see also !57328 (merged)), this behaviour is OK: we don't need to read anything in the block that would be affected by this. But it has the potential to cause problems if we use this method more widely in future, as a read could come from a model callback or similar without being explicit.