Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1098E200D21 for ; Mon, 16 Oct 2017 15:43:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0F0121609EF; Mon, 16 Oct 2017 13:43:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A09511609EC for ; Mon, 16 Oct 2017 15:43:12 +0200 (CEST) Received: (qmail 95397 invoked by uid 500); 16 Oct 2017 13:43:10 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 95386 invoked by uid 99); 16 Oct 2017 13:43:10 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Oct 2017 13:43:10 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 1AE101A28DC for ; Mon, 16 Oct 2017 13:43:10 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.121 X-Spam-Level: X-Spam-Status: No, score=-0.121 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id RlBqbd7cO6ni for ; Mon, 16 Oct 2017 13:43:08 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id B03265F239 for ; Mon, 16 Oct 2017 13:43:07 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id i124so3415934wmf.3 for ; Mon, 16 Oct 2017 06:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=O4BfVUX5kEglAOo/SSVYVdmEyG64gsScx9tQnN+z7GA=; b=P7STrVKI3riNLEYAMEwJZSQr3xXAvE8ssqUB/LnLNdYISj3qHfmBB11kAkA38VJgVW 8OrdJH1yhyEYBa7wB//g3hc45PQ30WCy14wR6S2yd9cXFkw4nG+GF3/MdS328FnpIQAV eyoiEBkzexhf1QkKLUD+Rv9xTQaJOVyQkWCgMdV+4mNvEsg3f//lObb9UVFTLkD/ZoiH NnyP0JZp0YjlREqI8JgCR2u4a/DcC59r8utfxCkLtnNZhL9qFdd4vQigGKoWoS0+Cfxx GJ+1xDlc9zXpUrYUCk+OrUFbKbTX3sR34LLp9LrKDIDwuXefds8/Hi4ysd3MdRfEKCE6 Q2iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=O4BfVUX5kEglAOo/SSVYVdmEyG64gsScx9tQnN+z7GA=; b=lORN3n7DKkzmmhy0di6jpWWcUl5zlmAXCsi3DX3mNZdc/AwfWDdPouj/thdXhbok66 vXfsUrre9R1SzSQ1uR+5F5vEWTMVSuP69uiuPSgKd3HJ3/FfI4hyo/kevwojgoH67oNU VQ/zYCogvQT5/Mad6ccenWIwrhoCm3G2scVyjuFUJpRnjatm116cOEDZVw4klag0dt6C Eo3ByP7HSgP8t35wQQuxvyzWv5K+b1zibn+hw+7f5HPvT8EzyFZmVPWTaeyDZRPrktGB 2DrjJjlqkHOiGwSDNNZLLAJHsp75HnXslmWkSdQkJwRc+qzQZnLWy6QnB6I0dd8YZ8dF /nvQ== X-Gm-Message-State: AMCzsaWNfY899SL95yNiRbqxhNMIyylgFq+VQtCu7cHr+HAA+C8cztDz LX9fFfmgMl7S9/mZCSJxfHCo6tuyBzdXqQLqo6J+NA== X-Google-Smtp-Source: ABhQp+ST9U2GnwTApjwgHHNszQms5vILoCxt4geOZ5au8Wl0msD9MQ70m99eCIN+UfOlIAZYYUDWiwbAnlqOS0g1ULo= X-Received: by 10.223.178.26 with SMTP id u26mr675460wra.239.1508161386481; Mon, 16 Oct 2017 06:43:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.145.139 with HTTP; Mon, 16 Oct 2017 06:43:05 -0700 (PDT) In-Reply-To: <87d4a07b-3c47-a0de-6311-0b236babbaab@christopherschultz.net> References: <87d4a07b-3c47-a0de-6311-0b236babbaab@christopherschultz.net> From: Chris Cheshire Date: Mon, 16 Oct 2017 09:43:05 -0400 Message-ID: Subject: Re: tomcat 8.5.23 dbcp not honoring autocommit = false? To: Tomcat Users List Content-Type: text/plain; charset="UTF-8" archived-at: Mon, 16 Oct 2017 13:43:14 -0000 On Fri, Oct 13, 2017 at 5:00 PM, Christopher Schultz wrote: > -----BEGIN PGP SIGNED MESSAGE----- > When you say you have "autocommit disabled in mysql config" what do > you mean? > /etc/my.cnf : [mysqld] autocommit=0 This turns off autocommit off as a default for all connections. I need this at a minimum for the mysql client, but in the absence of any other configuration it should be the default for a connection from any client. > On 10/13/17 10:17 AM, Chris Cheshire wrote: >> >> >> As a further test I just took out my explicit rollback in my >> DAOFactory close() method, and swapped back to commons dbcp. Added >> an update that wasn't explicitly committed, and it correctly did >> not get committed when the connection was closed. Swapped back to >> tomcat dbcp and repeated, it got committed without an explicit >> commit statement. >> >> I'm really puzzled as to why *I* have to explicitly rollback on >> close if autocommit is not enabled, instead of tomcat dbcp handling >> that when commons dbcp appears to do it. > > No connection pool can read your mind. If you begin a transaction (or > never start one), you must either commit or rollback. Merely calling > close() does not explicitly cause either of those to be called. > And that's just it. If I don't explicitly commit, then why are changes being committed when the connection is closed and returned back to the pool? >> If I do >> >> daoFactory = new MySQLDAOFactoryImpl(getDataSource()); >> >> // update #1 daoFactory.commit() >> >> // update #2 daoFactory.close(); >> >> then update #2 is being committed. > > I'm curious why you are doing "update #2" without either COMMIT or > ROLLBACK. That seems like ... a mistake. > Correct. This is an example to illustrate a mistake I found in my code. I found a servlet that actually wasn't explicitly committing when it should have been, yet everything it was doing was being committed to the database. > - From the Connection.close() javadoc: > > " > It is strongly recommended that an application explicitly commits or > rolls back an active transaction prior to calling the close method. If > the close method is called and there is an active transaction, the > results are implementation-defined. > " > If a commit is not being explicitly issued, then the commit behaviour should honor that of the connection, yes? > There *is* an implicit COMMIT executed if the autocommit flag is > flipped for any reason, either true->false or false->true. > > If you have autocommit=false in your configuration (which > you do), then calling setAutoCommit(false) shouldn't do anything. > >> If I put in this in the close() method of my DAO Factory >> >> if (!this.dbConn.getAutoCommit()) { this.dbConn.rollback(); } >> >> before the close() call, then update #2 is correctly not getting >> committed. > > This is probably the wrong approach: your close() method doesn't know > whether it's better to call commit() or rollback(), so it should do > neither. I realise this too, however I have to have it in otherwise if an exception is thrown, then work is being committed regardless of the fact that I have autocommit turned OFF in 3 levels, all the way back to the mysqld configuration. This behaviour does not happen with commons dbcp, only tomcat dbcp. There is a difference in default behaviour between the two pools when a transaction is not explicitly committed or rolled back when a connection is closed and returned to the pool. I use a try-with-resources/finally to open and close my database connections, thus short of a JVM crash, any exceptions thrown will always close the connections and return them to the pool. Thought: Perhaps the transaction marker is not being reset when a pooled connection is being handed out to a subsequent request for a connection, and that new servlet's work is committing the work from the first servlet that should not have been committed. Chris --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org