title: Will Cloud Dataflow throw exceptions when performing autoscaling?
body: <p>We are currently using Dataflow to run a streaming job. In that job, we perform datastore transactions of the following form:</p>
  
  <pre class="lang-java prettyprint-override"><code>Entity task;
  Transaction txn = datastore.newTransaction();
  try {
    task = txn.get(taskKey);
    update(task);
    txn.put(task);
    txn.commit();
  } finally {
    if (txn.isActive()) {
      txn.rollback();
    }
  }
  </code></pre>
  
  <p>In the event of scaling up/down, we see a lot of exceptions that activate the <code>rollback</code>. This would mean that the transaction is still active and that the <code>commit</code> statement was never executed. We do not, however see datastore exceptions in this case.</p>
  
  <p>We suspect that Dataflow cancels the active processing of elements and retries them in the scaled pipeline. This would then throw an unhandled exception and execute the <code>finally</code> steps. For some elements this would be <em>before</em> the <code>commit</code>, which would explain the behaviour. </p>
  
  <p>Also, the exception is maybe not exposed by Dataflow as these are internal ones.</p>
  
  <p>If the above is not the case, it would seem that the transaction implementation is faulty, which we -of course- assume is correct.</p>
  
  <p>Is the reasoning correct? Or is there an other explanation?</p>