mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-06-06 06:03:12 +03:00
Keep the GIL while converting the xid into the PostgreSQL transaction id.
This commit is contained in:
parent
397eace051
commit
17d70babb1
|
@ -939,21 +939,30 @@ conn_tpc_command(connectionObject *self, const char *cmd, XidObject *xid)
|
||||||
{
|
{
|
||||||
PGresult *pgres = NULL;
|
PGresult *pgres = NULL;
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
int rv;
|
char *tid = NULL;
|
||||||
|
int rv = -1;
|
||||||
|
|
||||||
Dprintf("conn_tpc_command: %s", cmd);
|
Dprintf("conn_tpc_command: %s", cmd);
|
||||||
|
|
||||||
|
/* convert the xid into PostgreSQL transaction id while keeping the GIL */
|
||||||
|
if (!(tid = xid_get_tid(xid))) { goto exit; }
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS;
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
pthread_mutex_lock(&self->lock);
|
pthread_mutex_lock(&self->lock);
|
||||||
|
|
||||||
rv = pq_tpc_command_locked(self, cmd, xid, &pgres, &error, &_save);
|
if (0 > (rv = pq_tpc_command_locked(self, cmd, tid,
|
||||||
|
&pgres, &error, &_save))) {
|
||||||
|
pthread_mutex_unlock(&self->lock);
|
||||||
|
Py_BLOCK_THREADS;
|
||||||
|
pq_complete_error(self, &pgres, &error);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
if (rv < 0) {
|
exit:
|
||||||
pq_complete_error(self, &pgres, &error);
|
PyMem_Free(tid);
|
||||||
}
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -617,19 +617,17 @@ pq_reset(connectionObject *conn)
|
||||||
* holding the global interpreter lock. */
|
* holding the global interpreter lock. */
|
||||||
|
|
||||||
int
|
int
|
||||||
pq_tpc_command_locked(connectionObject *conn, const char *cmd, XidObject *xid,
|
pq_tpc_command_locked(connectionObject *conn, const char *cmd, const char *tid,
|
||||||
PGresult **pgres, char **error,
|
PGresult **pgres, char **error, PyThreadState **tstate)
|
||||||
PyThreadState **tstate)
|
|
||||||
{
|
{
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
char *tid = NULL, *etid = NULL, *buf = NULL;
|
char *etid = NULL, *buf = NULL;
|
||||||
Py_ssize_t buflen;
|
Py_ssize_t buflen;
|
||||||
|
|
||||||
Dprintf("_pq_tpc_command: pgconn = %p, command = %s",
|
Dprintf("_pq_tpc_command: pgconn = %p, command = %s",
|
||||||
conn->pgconn, cmd);
|
conn->pgconn, cmd);
|
||||||
|
|
||||||
/* convert the xid into the postgres transaction_id and quote it. */
|
/* convert the xid into the postgres transaction_id and quote it. */
|
||||||
if (!(tid = xid_get_tid(xid))) { goto exit; }
|
|
||||||
if (!(etid = psycopg_escape_string((PyObject *)conn, tid, 0, NULL, NULL)))
|
if (!(etid = psycopg_escape_string((PyObject *)conn, tid, 0, NULL, NULL)))
|
||||||
{ goto exit; }
|
{ goto exit; }
|
||||||
|
|
||||||
|
@ -647,7 +645,6 @@ pq_tpc_command_locked(connectionObject *conn, const char *cmd, XidObject *xid,
|
||||||
exit:
|
exit:
|
||||||
PyMem_Free(buf);
|
PyMem_Free(buf);
|
||||||
PyMem_Free(etid);
|
PyMem_Free(etid);
|
||||||
PyMem_Free(tid);
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres,
|
||||||
HIDDEN int pq_abort(connectionObject *conn);
|
HIDDEN int pq_abort(connectionObject *conn);
|
||||||
HIDDEN int pq_reset(connectionObject *conn);
|
HIDDEN int pq_reset(connectionObject *conn);
|
||||||
HIDDEN int pq_tpc_command_locked(connectionObject *conn,
|
HIDDEN int pq_tpc_command_locked(connectionObject *conn,
|
||||||
const char *cmd, XidObject *xid,
|
const char *cmd, const char *tid,
|
||||||
PGresult **pgres, char **error,
|
PGresult **pgres, char **error,
|
||||||
PyThreadState **tstate);
|
PyThreadState **tstate);
|
||||||
HIDDEN int pq_is_busy(connectionObject *conn);
|
HIDDEN int pq_is_busy(connectionObject *conn);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user