/**
   * @param ctx Transaction context.
   * @param key Key.
   * @throws GridException If failed.
   */
  private void unlock(TxContext ctx, Object key) throws GridException {
    if (ctx.unlocked(key)) { // Finish transaction if last key is unlocked.
      txCtx.remove();

      GridCacheTx tx = cache.tx();

      assert tx != null;

      try {
        tx.commit();
      } finally {
        tx.close();
      }

      assert cache.tx() == null;
    }
  }