title: Updating column in large Spanner table with concurrent writes
body: <p>I want to update a column in a large table (tens of millions of rows), without bringing our application down; i.e. there will be concurrent writes to the table. I want to do this in code (Java) since the update is non-trivial, and am wondering what the best way to do it is.</p>
  
  <p>An efficient approach is to open a read transaction querying all rows, then loop over all these rows (<code>resultSet.next()</code>) while at the same time creating a series of read/write transactions with, say, 10,000 <code>INSERT_OR_UPDATE</code> mutations buffered in each transaction, containing the desired updates.</p>
  
  <p>The problem is that this doesn't handle concurrent writes, since these steps can happen:</p>
  
  <ol>
  <li>The read transaction mentioned above reads row X</li>
  <li>Some separate transaction updates row X</li>
  <li>The read/write transaction mentioned above uses data from step 1 and overwrites the update from step 2</li>
  </ol>
  
  <p>To fix this, I can read the value back during the read/write transaction and verify that it hasn't changed, similar to <a href="https://cloud.google.com/spanner/docs/transactions#rw_transaction_example" rel="nofollow noreferrer">this example here</a>, however this seems very slow (~50 ms per call, which translates to several weeks to update the whole table).</p>
  
  <p>So how can I do this more efficiently? Thanks!</p>