Concurrency question when performing REPLACE INTO / INSERT... ON DUPLICATE KEY UPDATE

48 views
Skip to first unread message

jer...@blumr.com

unread,
May 28, 2015, 7:23:22 AM5/28/15
to node-...@googlegroups.com
Hi all, 

I'm currently testing concurrency for node-mysql using three different connection instances using:

async's mapSeries([
{value: 'hello', instance: connectionInstanceOne}
{value: 'world', instance: connectionInstanceTwo}
{value: 'hi', instance: connectionInstanceThree}
]) 

...to provide values to a function with only a very simple: 

instanceConn.query() doing "REPLACE INTO ?? (`key` , value ) VALUES (?, ?) " (where instanceConn is connectionInstanceOne (for value 'hello'), connectionInstanceTwo (for value 'world'), or connectionInstanceThree (for value 'hi') from the object input in the map) 

...inside the function; however, during the insertion phase (and the callback phase), it seems that the REPLACE INTO... statement is inserting in a different sequence from the 'hello', 'world', 'hi' order, and instead of having 'hi' as the last value inserted, the last value inserted switches between 'world' and 'hi' alternately every time I complete a test cycle.

Could anyone kindly explain how this out of sequence insertion is happening?

Thanks in advance!

Craig Russell

unread,
Jun 2, 2015, 11:26:12 AM6/2/15
to node-...@googlegroups.com
Each of the connections is independent of the others, so the order of execution should appear to be random. The only surprise for me is that, from your description, the "hello" statement is always executed first. 

If you want to guarantee order of execution, you may have to use locking.
Reply all
Reply to author
Forward
0 new messages