Another question, since i wrapped my sql in a transaction, then it shoud
guarantee the feature transaction implies.
As mentioned above when didn't set default server, the select sql and sqls
other then select sql go different shards,
I use postgres with default isolation level, aka read commited:
> When a transaction uses this isolation level, a SELECT query (without a
> FOR UPDATE/SHARE clause) sees only data committed before the query began;
> it never sees either uncommitted data or changes committed during query
> execution by concurrent transactions. In effect, a SELECT query sees a
> snapshot of the database as of the instant the query begins to run.
> However, SELECT does see the effects of previous updates executed within
> its own transaction, even though they are not yet committed.
Dose sequel provides the above features across shards? if not, why? thanks!
在 2017年1月4日星期三 UTC+8上午1:19:00,Jeremy Evans写道:
>
> On Tuesday, January 3, 2017 at 8:46:26 AM UTC-8, melody wrote:
>>
>> I set up my postgresql database, master for write, the other for read
>> using the following:
>>
>> DB=Sequel.postgres('postgres://master_server/database',
>> :servers=>{:read_only=>{:host=>'slave_server'}})
>>
>> now when i execute sqls within a transaction, it didn't behave correct.
>>
>> DB.transaction do
>> DB["update XX set age = 22 where id = 3"].update
>> DB["select age from XX where id = 3"].first
>> end
>>
>> the second sql didn't return age: 22, So i guess the update sql and
>> select sql been executed on different databases, maybe update on master and
>> query on slave, is it possible?
>>
>
> This is not only possible, this is the expected behavior. SELECT queries
> go to read_only shard, other queries to the default shard. If you want to
> force the select query to the default shard:
>
> DB.transaction do
> DB["update XX set age = 22 where id = 3"].update
> DB["select age from XX where id = 3"].server(:default).first
> end
>
> Alternatively, you may want to look at the server_block extension, which
> allows setting a default shard for a given block.
>
> 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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.