Skip to content

Commit 5cc76e5

Browse files
committed
Merge pull request #1 from postgres/master
Merge from master of PG
2 parents 4db0d2d + 0ab3595 commit 5cc76e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1973
-1358
lines changed

contrib/bloom/blinsert.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ blinsert(Relation index, Datum *values, bool *isnull,
204204
*/
205205
metaBuffer = ReadBuffer(index, BLOOM_METAPAGE_BLKNO);
206206
LockBuffer(metaBuffer, BUFFER_LOCK_SHARE);
207-
metaData = BloomPageGetMeta(BufferGetPage(metaBuffer, NULL, NULL,
208-
BGP_NO_SNAPSHOT_TEST));
207+
metaData = BloomPageGetMeta(BufferGetPage(metaBuffer));
209208

210209
if (metaData->nEnd > metaData->nStart)
211210
{

contrib/bloom/blscan.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
138138
blkno, RBM_NORMAL, bas);
139139

140140
LockBuffer(buffer, BUFFER_LOCK_SHARE);
141-
page = BufferGetPage(buffer, scan->xs_snapshot, scan->indexRelation,
142-
BGP_TEST_FOR_OLD_SNAPSHOT);
141+
page = BufferGetPage(buffer);
142+
TestForOldSnapshot(scan->xs_snapshot, scan->indexRelation, page);
143143

144144
if (!BloomPageIsDeleted(page))
145145
{

contrib/bloom/blutils.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,11 @@ initBloomState(BloomState *state, Relation index)
139139
buffer = ReadBuffer(index, BLOOM_METAPAGE_BLKNO);
140140
LockBuffer(buffer, BUFFER_LOCK_SHARE);
141141

142-
page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
142+
page = BufferGetPage(buffer);
143143

144144
if (!BloomPageIsMeta(page))
145145
elog(ERROR, "Relation is not a bloom index");
146-
meta = BloomPageGetMeta(BufferGetPage(buffer, NULL, NULL,
147-
BGP_NO_SNAPSHOT_TEST));
146+
meta = BloomPageGetMeta(BufferGetPage(buffer));
148147

149148
if (meta->magickNumber != BLOOM_MAGICK_NUMBER)
150149
elog(ERROR, "Relation is not a bloom index");
@@ -317,8 +316,7 @@ BloomNewBuffer(Relation index)
317316
*/
318317
if (ConditionalLockBuffer(buffer))
319318
{
320-
Page page = BufferGetPage(buffer, NULL, NULL,
321-
BGP_NO_SNAPSHOT_TEST);
319+
Page page = BufferGetPage(buffer);
322320

323321
if (PageIsNew(page))
324322
return buffer; /* OK to use, if never initialized */

contrib/bloom/blvacuum.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ blvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
194194
buffer = ReadBufferExtended(index, MAIN_FORKNUM, blkno,
195195
RBM_NORMAL, info->strategy);
196196
LockBuffer(buffer, BUFFER_LOCK_SHARE);
197-
page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
197+
page = (Page) BufferGetPage(buffer);
198198

199199
if (BloomPageIsDeleted(page))
200200
{

contrib/pageinspect/btreefuncs.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ typedef struct BTPageStat
9090
static void
9191
GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat *stat)
9292
{
93-
Page page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
93+
Page page = BufferGetPage(buffer);
9494
PageHeader phdr = (PageHeader) page;
9595
OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
9696
BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
@@ -317,9 +317,7 @@ bt_page_items(PG_FUNCTION_ARGS)
317317
uargs = palloc(sizeof(struct user_args));
318318

319319
uargs->page = palloc(BLCKSZ);
320-
memcpy(uargs->page,
321-
BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST),
322-
BLCKSZ);
320+
memcpy(uargs->page, BufferGetPage(buffer), BLCKSZ);
323321

324322
UnlockReleaseBuffer(buffer);
325323
relation_close(rel, AccessShareLock);
@@ -449,7 +447,7 @@ bt_metap(PG_FUNCTION_ARGS)
449447
buffer = ReadBuffer(rel, 0);
450448
LockBuffer(buffer, BUFFER_LOCK_SHARE);
451449

452-
page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
450+
page = BufferGetPage(buffer);
453451
metad = BTPageGetMeta(page);
454452

455453
/* Build a tuple descriptor for our result type */

contrib/pageinspect/rawpage.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
147147
buf = ReadBufferExtended(rel, forknum, blkno, RBM_NORMAL, NULL);
148148
LockBuffer(buf, BUFFER_LOCK_SHARE);
149149

150-
memcpy(raw_page_data,
151-
BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST),
152-
BLCKSZ);
150+
memcpy(raw_page_data, BufferGetPage(buf), BLCKSZ);
153151

154152
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
155153
ReleaseBuffer(buf);

contrib/pg_visibility/pg_visibility.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pg_visibility(PG_FUNCTION_ARGS)
107107
buffer = ReadBuffer(rel, blkno);
108108
LockBuffer(buffer, BUFFER_LOCK_SHARE);
109109

110-
page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
110+
page = BufferGetPage(buffer);
111111
values[2] = BoolGetDatum(PageIsAllVisible(page));
112112

113113
UnlockReleaseBuffer(buffer);
@@ -333,7 +333,7 @@ collect_visibility_data(Oid relid, bool include_pd)
333333
bstrategy);
334334
LockBuffer(buffer, BUFFER_LOCK_SHARE);
335335

336-
page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
336+
page = BufferGetPage(buffer);
337337
if (PageIsAllVisible(page))
338338
info->bits[blkno] |= (1 << 2);
339339

contrib/pgstattuple/pgstatapprox.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ statapprox_heap(Relation rel, output_type *stat)
100100

101101
LockBuffer(buf, BUFFER_LOCK_SHARE);
102102

103-
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
103+
page = BufferGetPage(buf);
104104

105105
/*
106106
* It's not safe to call PageGetHeapFreeSpace() on new pages, so we

contrib/pgstattuple/pgstatindex.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
173173
*/
174174
{
175175
Buffer buffer = ReadBufferExtended(rel, MAIN_FORKNUM, 0, RBM_NORMAL, bstrategy);
176-
Page page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
176+
Page page = BufferGetPage(buffer);
177177
BTMetaPageData *metad = BTPageGetMeta(page);
178178

179179
indexStat.version = metad->btm_version;
@@ -211,7 +211,7 @@ pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
211211
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
212212
LockBuffer(buffer, BUFFER_LOCK_SHARE);
213213

214-
page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
214+
page = BufferGetPage(buffer);
215215
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
216216

217217
/* Determine page type, and update totals */
@@ -399,7 +399,7 @@ pgstatginindex(PG_FUNCTION_ARGS)
399399
*/
400400
buffer = ReadBuffer(rel, GIN_METAPAGE_BLKNO);
401401
LockBuffer(buffer, GIN_SHARE);
402-
page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
402+
page = BufferGetPage(buffer);
403403
metadata = GinPageGetMeta(page);
404404

405405
stats.version = metadata->ginVersion;

contrib/pgstattuple/pgstattuple.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
320320
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
321321
RBM_NORMAL, scan->rs_strategy);
322322
LockBuffer(buffer, BUFFER_LOCK_SHARE);
323-
stat.free_space += PageGetHeapFreeSpace
324-
(BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST));
323+
stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
325324
UnlockReleaseBuffer(buffer);
326325
block++;
327326
}
@@ -334,8 +333,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
334333
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
335334
RBM_NORMAL, scan->rs_strategy);
336335
LockBuffer(buffer, BUFFER_LOCK_SHARE);
337-
stat.free_space += PageGetHeapFreeSpace
338-
(BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST));
336+
stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
339337
UnlockReleaseBuffer(buffer);
340338
block++;
341339
}
@@ -360,7 +358,7 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno,
360358

361359
buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
362360
LockBuffer(buf, BT_READ);
363-
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
361+
page = BufferGetPage(buf);
364362

365363
/* Page is valid, see what to do with it */
366364
if (PageIsNew(page))
@@ -404,7 +402,7 @@ pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno,
404402

405403
_hash_getlock(rel, blkno, HASH_SHARE);
406404
buf = _hash_getbuf_with_strategy(rel, blkno, HASH_READ, 0, bstrategy);
407-
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
405+
page = BufferGetPage(buf);
408406

409407
if (PageGetSpecialSize(page) == MAXALIGN(sizeof(HashPageOpaqueData)))
410408
{
@@ -449,7 +447,7 @@ pgstat_gist_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno,
449447
buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
450448
LockBuffer(buf, GIST_SHARE);
451449
gistcheckpage(rel, buf);
452-
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
450+
page = BufferGetPage(buf);
453451

454452
if (GistPageIsLeaf(page))
455453
{

contrib/postgres_fdw/connection.c

+99
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "access/xact.h"
1818
#include "mb/pg_wchar.h"
1919
#include "miscadmin.h"
20+
#include "storage/latch.h"
2021
#include "utils/hsearch.h"
2122
#include "utils/memutils.h"
2223

@@ -447,6 +448,78 @@ GetPrepStmtNumber(PGconn *conn)
447448
return ++prep_stmt_number;
448449
}
449450

451+
/*
452+
* Submit a query and wait for the result.
453+
*
454+
* This function is interruptible by signals.
455+
*
456+
* Caller is responsible for the error handling on the result.
457+
*/
458+
PGresult *
459+
pgfdw_exec_query(PGconn *conn, const char *query)
460+
{
461+
/*
462+
* Submit a query. Since we don't use non-blocking mode, this also can
463+
* block. But its risk is relatively small, so we ignore that for now.
464+
*/
465+
if (!PQsendQuery(conn, query))
466+
pgfdw_report_error(ERROR, NULL, conn, false, query);
467+
468+
/* Wait for the result. */
469+
return pgfdw_get_result(conn, query);
470+
}
471+
472+
/*
473+
* Wait for the result from a prior asynchronous execution function call.
474+
*
475+
* This function offers quick responsiveness by checking for any interruptions.
476+
*
477+
* This function emulates the PQexec()'s behavior of returning the last result
478+
* when there are many.
479+
*
480+
* Caller is responsible for the error handling on the result.
481+
*/
482+
PGresult *
483+
pgfdw_get_result(PGconn *conn, const char *query)
484+
{
485+
PGresult *last_res = NULL;
486+
487+
for (;;)
488+
{
489+
PGresult *res;
490+
491+
while (PQisBusy(conn))
492+
{
493+
int wc;
494+
495+
/* Sleep until there's something to do */
496+
wc = WaitLatchOrSocket(MyLatch,
497+
WL_LATCH_SET | WL_SOCKET_READABLE,
498+
PQsocket(conn),
499+
-1L);
500+
ResetLatch(MyLatch);
501+
502+
CHECK_FOR_INTERRUPTS();
503+
504+
/* Data available in socket */
505+
if (wc & WL_SOCKET_READABLE)
506+
{
507+
if (!PQconsumeInput(conn))
508+
pgfdw_report_error(ERROR, NULL, conn, false, query);
509+
}
510+
}
511+
512+
res = PQgetResult(conn);
513+
if (res == NULL)
514+
break; /* query is complete */
515+
516+
PQclear(last_res);
517+
last_res = res;
518+
}
519+
520+
return last_res;
521+
}
522+
450523
/*
451524
* Report an error we got from the remote server.
452525
*
@@ -598,6 +671,32 @@ pgfdw_xact_callback(XactEvent event, void *arg)
598671
case XACT_EVENT_ABORT:
599672
/* Assume we might have lost track of prepared statements */
600673
entry->have_error = true;
674+
675+
/*
676+
* If a command has been submitted to the remote server by
677+
* using an asynchronous execution function, the command
678+
* might not have yet completed. Check to see if a command
679+
* is still being processed by the remote server, and if so,
680+
* request cancellation of the command; if not, abort
681+
* gracefully.
682+
*/
683+
if (PQtransactionStatus(entry->conn) == PQTRANS_ACTIVE)
684+
{
685+
PGcancel *cancel;
686+
char errbuf[256];
687+
688+
if ((cancel = PQgetCancel(entry->conn)))
689+
{
690+
if (!PQcancel(cancel, errbuf, sizeof(errbuf)))
691+
ereport(WARNING,
692+
(errcode(ERRCODE_CONNECTION_FAILURE),
693+
errmsg("could not send cancel request: %s",
694+
errbuf)));
695+
PQfreeCancel(cancel);
696+
}
697+
break;
698+
}
699+
601700
/* If we're aborting, abort all remote transactions too */
602701
res = PQexec(entry->conn, "ABORT TRANSACTION");
603702
/* Note: can't throw ERROR, it would be infinite loop */

0 commit comments

Comments
 (0)