-- update_node2.lua
-- Purpose: Execute concurrent updates on leaf tables to trigger Galera conflicts

sysbench.cmdline.options = {
   table_size = {"Number of rows in t1", 2000}
}

function thread_init()
   drv = sysbench.sql.driver()
   con = drv:connect()
end

function event()
   -- Pick a random parent ID from t1
   local id = sysbench.rand.default(1, sysbench.opt.table_size)

   -- Update t3 that belong to that t1 hierarchy
   -- This will conflict with a DELETE happening on Node 1 for the same ID
   con:query(string.format([[
      UPDATE t3 SET count = count + 1 
      WHERE t2_id IN (
          SELECT id FROM t2 WHERE t1_id = %d
      ) LIMIT 5
   ]], id))
end