Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66ab937

Browse files
committed
dblink/isolationtester/fe_utils: Use new cancel API
Commit61461a3 introduced new functions to libpq for cancellingqueries. This replaces the usage of the old ones in parts of thecodebase with these newer ones. This specifically leaves out changes topsql and pgbench, as those would need a much larger refactor to be ableto call them due to the new functions not being signal-safe; and alsopostgres_fdw, because the original code there is not clear to me(Álvaro) and not fully tested.Author: Jelte Fennema-Nio <postgres@jeltef.nl>Discussion:https://postgr.es/m/CAGECzQT_VgOWWENUqvUV9xQmbaCyXjtRRAYO8W07oqashk_N+g@mail.gmail.com
1 parent61f352e commit66ab937

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

‎contrib/dblink/dblink.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,22 +1346,28 @@ PG_FUNCTION_INFO_V1(dblink_cancel_query);
13461346
Datum
13471347
dblink_cancel_query(PG_FUNCTION_ARGS)
13481348
{
1349-
intres;
13501349
PGconn*conn;
1351-
PGcancel*cancel;
1352-
charerrbuf[256];
1350+
PGcancelConn*cancelConn;
1351+
char*msg;
13531352

13541353
dblink_init();
13551354
conn=dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
1356-
cancel=PQgetCancel(conn);
1355+
cancelConn=PQcancelCreate(conn);
13571356

1358-
res=PQcancel(cancel,errbuf,256);
1359-
PQfreeCancel(cancel);
1357+
PG_TRY();
1358+
{
1359+
if (!PQcancelBlocking(cancelConn))
1360+
msg=pchomp(PQcancelErrorMessage(cancelConn));
1361+
else
1362+
msg="OK";
1363+
}
1364+
PG_FINALLY();
1365+
{
1366+
PQcancelFinish(cancelConn);
1367+
}
1368+
PG_END_TRY();
13601369

1361-
if (res==1)
1362-
PG_RETURN_TEXT_P(cstring_to_text("OK"));
1363-
else
1364-
PG_RETURN_TEXT_P(cstring_to_text(errbuf));
1370+
PG_RETURN_TEXT_P(cstring_to_text(msg));
13651371
}
13661372

13671373

‎src/fe_utils/connect_utils.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,14 @@ connectMaintenanceDatabase(ConnParams *cparams,
157157
void
158158
disconnectDatabase(PGconn*conn)
159159
{
160-
charerrbuf[256];
161-
162160
Assert(conn!=NULL);
163161

164162
if (PQtransactionStatus(conn)==PQTRANS_ACTIVE)
165163
{
166-
PGcancel*cancel;
164+
PGcancelConn*cancelConn=PQcancelCreate(conn);
167165

168-
if ((cancel=PQgetCancel(conn)))
169-
{
170-
(void)PQcancel(cancel,errbuf,sizeof(errbuf));
171-
PQfreeCancel(cancel);
172-
}
166+
(void)PQcancelBlocking(cancelConn);
167+
PQcancelFinish(cancelConn);
173168
}
174169

175170
PQfinish(conn);

‎src/test/isolation/isolationtester.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -946,26 +946,21 @@ try_complete_step(TestSpec *testspec, PermutationStep *pstep, int flags)
946946
*/
947947
if (td>max_step_wait&& !canceled)
948948
{
949-
PGcancel*cancel=PQgetCancel(conn);
949+
PGcancelConn*cancel_conn=PQcancelCreate(conn);
950950

951-
if (cancel!=NULL)
951+
if (PQcancelBlocking(cancel_conn))
952952
{
953-
charbuf[256];
954-
955-
if (PQcancel(cancel,buf,sizeof(buf)))
956-
{
957-
/*
958-
* print to stdout not stderr, as this should appear
959-
* in the test case's results
960-
*/
961-
printf("isolationtester: canceling step %s after %d seconds\n",
962-
step->name, (int) (td /USECS_PER_SEC));
963-
canceled= true;
964-
}
965-
else
966-
fprintf(stderr,"PQcancel failed: %s\n",buf);
967-
PQfreeCancel(cancel);
953+
/*
954+
* print to stdout not stderr, as this should appear in
955+
* the test case's results
956+
*/
957+
printf("isolationtester: canceling step %s after %d seconds\n",
958+
step->name, (int) (td /USECS_PER_SEC));
959+
canceled= true;
968960
}
961+
else
962+
fprintf(stderr,"PQcancel failed: %s\n",PQcancelErrorMessage(cancel_conn));
963+
PQcancelFinish(cancel_conn);
969964
}
970965

971966
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp