[Cppcms-users] Bug about transaction in cppdb
Brought to you by:
artyom-beilis
From: 陈抒 <csf...@gm...> - 2011-10-30 12:04:54
|
Hello,Artyom: I run into one problem,I try to update one record in one MySQL table using transaction like so: static shared_ptr<prize> award(shared_ptr<prize> p,shared_ptr<user> user, int promo_id){ my_application & app = app_singleton_holder::Instance(); cppdb::session session(app.config().master_mysql_uri); cppdb::statement stat; cppdb::transaction guard(session); cppdb::result res = session <<"select account_id from event_prize where prizeId = ? and account_id is NULL"<< p->id(); unsigned int account_id; if(res.next() ){ stat = session << "update event_prize set account_id=? ,award_time=now() where prizeId=?" << user->account_id() << p->id(); stat.exec(); guard.commit(); //发送站内短信 send_message(p , user , promo_id); BOOSTER_NOTICE("award") << "obtain a real prize, the account_id is:" << user->account_id() << ".the prize_id is:" << p->id(); return p; }else{ guard.rollback(); BOOSTER_NOTICE("award") << "already have got a prize, the account_id is:"<< user->account_id() << ".the prize_id is:" << p->id(); return create_default_prize(user,promo_id); } } Then I write a Java test application using TestNG to test my service with 50 threads.But the service updates one record twice.Here is my log: 20071:2011-10-30 11:48:37 GMT; award, notice: obtain a real prize, the account_id is:2011.the prize_id is:906326 (default_prize_policy.h:196) 20074:2011-10-30 11:48:37 GMT; award, notice: already have got a prize, the account_id is:2011.the prize_id is:906326 (default_prize_policy.h:200) 20121:2011-10-30 11:48:37 GMT; award, notice: obtain a real prize, the account_id is:2011.the prize_id is:906326 (default_prize_policy.h:196) Maybe it's a bug.Another question,How to change the transaction isolation level for MySQL? 陈抒 Best regards http://blog.csdn.net/sheismylife |