Thank you Jeremy! That works!
On Wednesday, April 16, 2014 8:43:30 PM UTC-7, Jeremy Evans wrote:
>
> On Wednesday, April 16, 2014 6:37:53 PM UTC-7, Zhannan Ge wrote:
>>
>> The cause of this issue is our server changes the shard of all models in
>> before filter for each request based on if the coming request method is
>> "GET" or non-"GET"(POST, PATCH, PUT)
>>
>> If it's a "GET" request, we do
>> ALL_MODELS.each { |model| model.dataset = model.dataset.server(:slave) }
>>
>> otherwise, we do
>> ALL_MODELS.each { |model| model.dataset = model.dataset.server(:master) }
>>
>> The idea behind this is that, we do not want to choose whether to use
>> master or slave based on if the query is a "SELECT", instead we want to
>> choose slave for "GET" requests, and master for non-"GET" requests.
>>
>> The problem can be reproduced by the following steps:
>> 1. start the server
>> 2. make as many "POST" requests as you want, and the the rollback works
>> fine
>> 3. make a "GET" request, which would change all the models to point to
>> :slave
>> 4. make a "POST" request, which would change all the models back to
>> :master, and the rollback starts to fail from now on just as Gabe
>> N describes.
>>
>> If you could let us know why is this causing the problem, if we are doing
>> something wrong and if you have any alternative suggestions to approach
>> this.
>>
>
> Changing all models' datasets per request is not how you want to handle
> this. Use the server_block extension in conjunction with a rack middleware
> to change the default server per request.
>
> I'm not sure what exactly is going wrong with the way you currently have
> things setup. I would need a self-contained reproducible example to debug
> something like that. However, it's pointless to expend that effort if the
> server_block approach will solve the problem.
>
> Thanks,
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.