Try to avoid race condition by transaction.