You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After I am doing using(:slave), if by mistake I am trying to write I am getting errors of read_only user is trying to write to DB...
Then the current_shard of the connection proxy is stuck on the :slave shard
I thought to add this initializer to rails:
module OctopusActiveRecordExtension
extend ActiveSupport::Concern
attr_accessor :octopus_shard
included do
after_initialize :remove_current_shard
before_save :raise_error_if_shard_is_slave
end
protected
def remove_current_shard
# we backup if the model was recieved from slave in order
# to throw error if someone will try to save it to master
self.octopus_shard = self.current_shard
self.current_shard = nil
end
def raise_error_if_shard_is_slave
if self.octopus_shard == :slave
raise "Trying to write to model created from slave"
end
end
end
# include the extension
ActiveRecord::Base.send(:include, OctopusActiveRecordExtension)
Does that make sense?
Is there any better way to achieve the reset of the current_shard to master after trying to write to slave?
Do you think I should add a middleware to rails that will reset the current_shard to master:
before each request and async job? For example:
I am using Octopus 0.8.0 with Rails 3
After I am doing using(:slave), if by mistake I am trying to write I am getting errors of read_only user is trying to write to DB...
Then the current_shard of the connection proxy is stuck on the :slave shard
I thought to add this initializer to rails:
Does that make sense?
Is there any better way to achieve the reset of the current_shard to master after trying to write to slave?
Do you think I should add a middleware to rails that will reset the current_shard to master:
before each request and async job? For example:
The text was updated successfully, but these errors were encountered: