From: Craig Ringer <craig@2ndquadrant.com>
To: Inoue, Hiroshi <inoue@tpf.co.jp>
Cc: pgsql-odbc@postgresql.org <pgsql-odbc@postgresql.org>
Subject: Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
Date: Thu, 26 Jun 2014 16:23:27 +0800
Message-ID: <53ABD87F.2030204@2ndquadrant.com> (raw)
In-Reply-To: <53AADC07.3090206@2ndquadrant.com>
References: <53A45B59.70303@2ndquadrant.com>
<53A4A8FE.6010901@tpf.co.jp>
<53A50F8E.3090109@2ndquadrant.com>
<53A53BF9.1020603@2ndquadrant.com>
<53A7762E.10705@tpf.co.jp>
<53A781AE.6020009@2ndquadrant.com>
<53A89AC5.4010004@tpf.co.jp>
<53A8EB74.5040806@2ndquadrant.com>
<53AADC07.3090206@2ndquadrant.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>
On 06/25/2014 10:26 PM, Craig Ringer wrote:
> On 06/24/2014 11:07 AM, Craig Ringer wrote:
>> On 06/24/2014 05:23 AM, Inoue, Hiroshi wrote:
>>>
>>> XARMCreate() triggers xa_open() ( and xa_close()) probably so as to
>>> check that the XADLL works. Currently xa_open() doesn't connect to
>>> the database and simply saves the connection information for subsequent
>>> xa_commit(), xa_rollback() or xa_recover() call. When original process
>>> finished COMMIT/ROLLBACK PREPARED properly, No database access occurs
>>> in msdtc process. We can change xa_open() so that it connects to the
>>> database immediately and causes an error to XARMCreate() when the
>>> connection fails.
>>
>> That's enlightening. Thankyou very much.
>>
>> I'll happily implement that and send in a patch. It may take a week or
>> two as I have some other projects on the boil, but hopefully it won't
>> take super long.
>
> ... and done.
>
> Please merge branch fix-syswow64-msdtc from my repo at
> https://github.com/ringerc/psqlODBC.git .
>
> see: https://github.com/ringerc/psqlODBC/pull/2
>
> Patch attached if you prefer that. See patch header and in-code comments
> for details.
Here's the revised patch. I've tested this against the customer's
original test case and it now runs properly. MSDTC correctly recovers
abandoned tx's in which Phase I commit succeeded then the app exited /
crashed before Phase II completed on one or both sessions.
Updated patch attached:
git am -s 0001-Fix-driver-name-mismatch-between-32-bit-ODBC-app-and.patch
or pull my branch, above.
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbcAttachments:0001-Fix-driver-name-mismatch-between-32-bit-ODBC-app-and.patch (text/x-patch, 4.4K) download
From 85e208db45cd675d69aad44a95f8c79854682f5f Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Wed, 25 Jun 2014 15:17:00 +0800
Subject: [PATCH] Fix driver name mismatch between 32-bit ODBC app and 64-bit
MSDTC host
If the 32-bit driver runs on a 64-bit host within a 32-bit app
running under SysWow64 then XA transactions will fail to recover.
That's because recovery is done by pgxalib.dll which runs within
MSDTC.exe - a 64-bit application. It connects to a DSN supplied
by psqlODBC in EnlistInDtc_1pipe during DTC enlistment by the
XA resource manager. This DSN uses the driver name of the client's
ODBC driver - which is fine so long as the client and MSDTC
architectures match. If they don't then MSDTC will fail to connect
to Pg, so it'll never resolve transactions.
Traces of MSDTC will show RM_COMMIT_DELIVERY_FAILED_DUE_TO_CONNECTION_DOWN
events.
Traces of pgxalib.dll will show xa_recover(..) being entered, followed by
"SQLDriverConnect return=-1".
To fix this, we detect if we're running under SysWow64 by examining the
PROCESSOR_ARCHITEW6432 environment variable and supply the 64-bit driver name
if so.
See mailing list thread:
http://www.postgresql.org/message-id/53A45B59.70303@2ndquadrant.com
for details.
Craig Ringer
---
connection.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
psqlodbc.h | 8 ++++++--
2 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/connection.c b/connection.cindex 794ddde..3aeb71a 100644--- a/connection.c+++ b/connection.c@@ -4362,10 +4362,52 @@ const char *CurrCatString(const ConnectionClass *conn)
DLL_DECLARE void PgDtc_create_connect_string(void *self, char *connstr, int strsize)
{
ConnectionClass *conn = (ConnectionClass *) self;
-+ SYSTEM_INFO si;
ConnInfo *ci = &(conn->connInfo);
+ const char *drivername = ci->drivername;++#if defined(_WIN32) && !defined(_WIN64)+ /*+ * If this is an x86 driver running on an x64 host then the driver name+ * passed to MSDTC must be the (x64) driver but the client app will be+ * using the 32-bit driver name. So MSDTC.exe will fail to find the driver+ * and we'll fail to recover XA transactions.+ *+ * IsWow64Process(...) would be the ideal function for this, but is only+ * available on Windows 6+ (Vista/2k8). We'd use GetNativeSystemInfo, which+ * is supported on XP and 2k3, instead, but that won't link with older+ * SDKs.+ *+ * It's impler to just test the PROCESSOR_ARCHITEW6432 environment+ * variable.+ *+ * See http://www.postgresql.org/message-id/53A45B59.70303@2ndquadrant.com+ * for details on this issue.+ */+ const char * const procenv = getenv("PROCESSOR_ARCHITEW6432");+ if (procenv != NULL && strcmp(procenv, "AMD64") == 0)+ {+ /*+ * We're a 32-bit binary running under SysWow64 on a 64-bit host and need+ * to pass a different driver name.+ *+ * To avoid playing memory management games, just return a different+ * string constant depending on the unicode-ness of the driver.+ *+ * It probably doesn't matter whether we use the Unicode or ANSI driver+ * for the XA transaction manager, but pick the same as the client driver+ * to keep things as similar as possible.+ */+#ifdef UNICODE_SUPPORT+ drivername = DBMS_NAME_UNICODE"(x64)";+#else+ drivername = DBMS_NAME_ANSI"(x64)";+#endif+ }+#endif // _WIN32 && !_WIN64+
snprintf(connstr, strsize, "DRIVER={%s};SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s;" ABBR_SSLMODE "=%s",
- ci->drivername, ci->server, ci->port, ci->database, ci->username, SAFE_NAME(ci->password), ci->sslmode);+ drivername, ci->server, ci->port, ci->database, ci->username, SAFE_NAME(ci->password), ci->sslmode);
}
DLL_DECLARE void PgDtc_set_async(void *self, void *async)
diff --git a/psqlodbc.h b/psqlodbc.hindex c0c895f..05dcc9e 100644--- a/psqlodbc.h+++ b/psqlodbc.h@@ -249,6 +249,10 @@ typedef double SDOUBLE;
/* Driver stuff */
#define DRIVERNAME "PostgreSQL ODBC"
++#define DBMS_NAME_UNICODE "PostgreSQL Unicode"+#define DBMS_NAME_ANSI "PostgreSQL ANSI"+
#if (ODBCVER >= 0x0300)
#if (ODBCVER >= 0x0351)
#define DRIVER_ODBC_VER "03.51"
@@ -257,9 +261,9 @@ typedef double SDOUBLE;
#endif /* ODBCVER 0x0351 */
#ifndef DBMS_NAME
#ifdef UNICODE_SUPPORT
-#define DBMS_NAME "PostgreSQL Unicode"+#define DBMS_NAME DBMS_NAME_UNICODE
#else
-#define DBMS_NAME "PostgreSQL ANSI"+#define DBMS_NAME DBMS_NAME_ANSI
#endif /* UNICODE_SUPPORT */
#endif /* DBMS_NAME */
#else
--
1.9.0
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: craig@2ndquadrant.com, inoue@tpf.co.jp
Subject: Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
In-Reply-To: <53ABD87F.2030204@2ndquadrant.com>
References: <53A45B59.70303@2ndquadrant.com> <53A4A8FE.6010901@tpf.co.jp> <53A50F8E.3090109@2ndquadrant.com> <53A53BF9.1020603@2ndquadrant.com> <53A7762E.10705@tpf.co.jp> <53A781AE.6020009@2ndquadrant.com> <53A89AC5.4010004@tpf.co.jp> <53A8EB74.5040806@2ndquadrant.com> <53AADC07.3090206@2ndquadrant.com> <53ABD87F.2030204@2ndquadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox