Writing then immediately reading the same data (or reading then immediately writing) are both antipatterns in any eventually consistent system, Cassandra included.
You may need to investigate Compare and Set operations and see if they will work for your needs. Or else look into Serial consistency ( http://www.datastax.com/documentation/cassandra/2.0/cassandra/dml/dml_config_consistency_c.html) - but be aware that both of these have potentially significant performance implications. On Sun Dec 07 2014 at 10:34:25 PM 鄢来琼 <laiqiong....@gtafe.com> wrote: > Hi All, > > There is a practices for Cassandra UPDATE statement. Maybe is not the > best, but it is a reference for you to update a row in high frequency. > > > > The Cassandra will be failed if UPDATE statement is executed more than > once on the same row. > > In the end, I change the primary key to let Cassandra insert a new row > after executing UPDATE statement, then delete all the redundant rows. > > I also found that the UPDATE statement may be failed if it follows the > DELETE statement immediately. > > The SELECT statement is used to check the last UPDATE statement is > executed correctly. > > > > Peter > > *发件人:* 鄢来琼 [mailto:laiqiong....@gtafe.com] > *发送时间:* 2014年12月3日 13:08 > *收件人:* user@cassandra.apache.org > *主题:* re: UPDATE statement is failed > > > > The system setting is as the following: > > > > Cluster replication: > > replication = {'class': 'NetworkTopologyStrategy', 'GTA_SZ_DC1':2} > > > > Totally, 5 Nodes, > > OS of Nodes are windows. > > > > > > > > Thanks & Regards, > > *鄢来琼* */ Peter YAN,* Staff Software Engineer, > > A3 Dept., GTA Information Technology Co., Ltd. > > ========================================= > > Mobile: 18620306659 > > E-Mail: laiqiong....@gtafe.com > > Website: http://www.gtafe.com/ > > ========================================= > > > > *发件人:* 鄢来琼 [mailto:laiqiong....@gtafe.com] > *发送时间:* 2014年12月3日 11:49 > *收件人:* user@cassandra.apache.org > *主题:* UPDATE statement is failed > > > > Hi ALL, > > > > There is a grogram to consume messages from queue; according to the > message, the program will READ a row and then UPDATE the row; > > BUT, sometimes, the UPDATE statement is fail, the result of READ statement > is also the old content before UDPATE. > > Any suggestions from you are appreciated. > > The following are my program and the result. > > > > ---READ---- > > from cassandra.query import SimpleStatement > > from cassandra import ConsistencyLevel > > self.interval_data_get_simple = SimpleStatement("""SELECT > TRADETIME, OPENPRICE, HIGHPRICE, \ > > LOWPRICE, CLOSEPRICE, CHANGE, > CHANGERATIO, VOLUME, AMOUNT,SECURITYNAME, \ > > SECURITYID from {} WHERE SYMBOL = > '{}' AND TRADETIME = '{}';\ > > """.format(self.cassandra_table, > symbol, \ > > interval_trade_time.strftime(u'%Y-%m-%d > %H:%M:%S')), \ > > consistency_level= > ConsistencyLevel.ALL) > > > > cur_interval_future = self.cassandra_session. > execute_async(self.interval_data_get_simple) > > -----UPDATE-------- > > from cassandra.query import SimpleStatement > > from cassandra import ConsistencyLevel > > data_set_simple = SimpleStatement("""UPDATE {} SET OPENPRICE = {}, > HIGHPRICE = {}, LOWPRICE = {},\ > > CLOSEPRICE = {}, VOLUME = {}, AMOUNT = {}, MARKET = {}, > SECURITYID = {} WHERE \ > > SYMBOL = '{}' AND TRADETIME = > '{}';""".format(self.cassandra_table, > insert_data_list[0], \ > > insert_data_list[1], > insert_data_list[2], insert_data_list[3], \ > > insert_data_list[4], > insert_data_list[5], insert_data_list[6], \ > > insert_data_list[7], > insert_data_list[8], insert_data_list[9]), \ > > consistency_level= > ConsistencyLevel.ALL) > > > > update_future = self.cassandra_session.execute(data_set_simple) > > > > > > ------------test result---------- > > #CQL UPDATE statement > > UPDATE GTA_HFDCS_SSEL2.SSEL2_TRDMIN01_20141127 SET OPENPRICE = 8.460, > HIGHPRICE = 8.460, LOWPRICE = 8.460, CLOSEPRICE = 8.460, *VOLUME > = 1500*, AMOUNT = 12240.000, MARKET = 1, SECURITYID = 201000003592 > WHERE SYMBOL = '600256' AND TRADETIME = '2014-11-27 10:00:00'; > > #the result of READ > > [Row(tradetime=datetime.datetime(2014, 11, 27, 2, 0), > openprice=Decimal('8.460'), highprice=Decimal('8.460'), > lowprice=Decimal('8.460'), closeprice=Decimal('8.460'), change=None, > changeratio=None, *volume=1500*, amount=Decimal('12240.000'), > securityname=None, securityid=201000003592)] > > #CQL UPDATE statement > > UPDATE GTA_HFDCS_SSEL2.SSEL2_TRDMIN01_20141127 SET OPENPRICE = 8.460, > HIGHPRICE = 8.460, LOWPRICE = 8.160, CLOSEPRICE = 8.160, *VOLUME > = 3500*, AMOUNT = 28560.000, MARKET = 1, SECURITYID = 201000003592 > WHERE SYMBOL = '600256' AND TRADETIME = '2014-11-27 10:00:00'; > > #the result of READ > > [Row(tradetime=datetime.datetime(2014, 11, 27, 2, 0), > openprice=Decimal('8.460'), highprice=Decimal('8.460'), > lowprice=Decimal('8.460'), closeprice=Decimal('8.460'), change=None, > changeratio=None, *volume=1500*, amount=Decimal('12240.000'), > securityname=None, securityid=201000003592)] > > > > > > > > Thanks & Regards, > > *鄢来琼* */ Peter YAN,* Staff Software Engineer, > > A3 Dept., GTA Information Technology Co., Ltd. > > ========================================= > > Mobile: 18620306659 > > E-Mail: laiqiong....@gtafe.com > > Website: http://www.gtafe.com/ > > ========================================= > > >