Commit 8876e37d authored by Teodor Sigaev's avatar Teodor Sigaev

Reduce size of critial section during vacuum full, critical

sections now isn't nested. All user-defined functions now is
called outside critsections. Small improvements in WAL
protocol.

TODO: improve XLOG replay
parent 815f5840
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.134 2006/05/10 23:18:38 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.135 2006/05/17 16:34:59 teodor Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -347,7 +347,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate) ...@@ -347,7 +347,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
* Form index tuples vector to split: * Form index tuples vector to split:
* remove old tuple if t's needed and add new tuples to vector * remove old tuple if t's needed and add new tuples to vector
*/ */
itvec = gistextractbuffer(state->stack->buffer, &tlen); itvec = gistextractpage(state->stack->page, &tlen);
if ( !is_leaf ) { if ( !is_leaf ) {
/* on inner page we should remove old tuple */ /* on inner page we should remove old tuple */
int pos = state->stack->childoffnum - FirstOffsetNumber; int pos = state->stack->childoffnum - FirstOffsetNumber;
...@@ -501,7 +501,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate) ...@@ -501,7 +501,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
} }
rdata = formUpdateRdata(state->r->rd_node, state->stack->buffer, rdata = formUpdateRdata(state->r->rd_node, state->stack->buffer,
offs, noffs, false, offs, noffs,
state->itup, state->ituplen, state->itup, state->ituplen,
&(state->key)); &(state->key));
...@@ -1157,7 +1157,7 @@ gistnewroot(Relation r, Buffer buffer, IndexTuple *itup, int len, ItemPointer ke ...@@ -1157,7 +1157,7 @@ gistnewroot(Relation r, Buffer buffer, IndexTuple *itup, int len, ItemPointer ke
XLogRecData *rdata; XLogRecData *rdata;
rdata = formUpdateRdata(r->rd_node, buffer, rdata = formUpdateRdata(r->rd_node, buffer,
NULL, 0, false, NULL, 0,
itup, len, key); itup, len, key);
recptr = XLogInsert(RM_GIST_ID, XLOG_GIST_NEW_ROOT, rdata); recptr = XLogInsert(RM_GIST_ID, XLOG_GIST_NEW_ROOT, rdata);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.11 2006/05/10 09:19:54 teodor Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.12 2006/05/17 16:34:59 teodor Exp $
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -112,18 +112,17 @@ gistfitpage(IndexTuple *itvec, int len) { ...@@ -112,18 +112,17 @@ gistfitpage(IndexTuple *itvec, int len) {
* Read buffer into itup vector * Read buffer into itup vector
*/ */
IndexTuple * IndexTuple *
gistextractbuffer(Buffer buffer, int *len /* out */ ) gistextractpage(Page page, int *len /* out */ )
{ {
OffsetNumber i, OffsetNumber i,
maxoff; maxoff;
IndexTuple *itvec; IndexTuple *itvec;
Page p = (Page) BufferGetPage(buffer);
maxoff = PageGetMaxOffsetNumber(p); maxoff = PageGetMaxOffsetNumber(page);
*len = maxoff; *len = maxoff;
itvec = palloc(sizeof(IndexTuple) * maxoff); itvec = palloc(sizeof(IndexTuple) * maxoff);
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
itvec[i - FirstOffsetNumber] = (IndexTuple) PageGetItem(p, PageGetItemId(p, i)); itvec[i - FirstOffsetNumber] = (IndexTuple) PageGetItem(page, PageGetItemId(page, i));
return itvec; return itvec;
} }
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.16 2006/05/10 09:19:54 teodor Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.17 2006/05/17 16:34:59 teodor Exp $
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -209,41 +209,33 @@ gistRedoPageUpdateRecord(XLogRecPtr lsn, XLogRecord *record, bool isnewroot) ...@@ -209,41 +209,33 @@ gistRedoPageUpdateRecord(XLogRecPtr lsn, XLogRecord *record, bool isnewroot)
return; return;
} }
if (xlrec.data->isemptypage) if (isnewroot)
GISTInitBuffer(buffer, 0);
else if (xlrec.data->ntodelete)
{ {
while (!PageIsEmpty(page)) int i;
PageIndexTupleDelete(page, FirstOffsetNumber);
if (xlrec.data->blkno == GIST_ROOT_BLKNO) for (i = 0; i < xlrec.data->ntodelete; i++)
GistPageSetLeaf(page); PageIndexTupleDelete(page, xlrec.todelete[i]);
else if (GistPageIsLeaf(page))
GistPageSetDeleted(page); GistMarkTuplesDeleted(page);
} }
else
{
if (isnewroot)
GISTInitBuffer(buffer, 0);
else if (xlrec.data->ntodelete)
{
int i;
for (i = 0; i < xlrec.data->ntodelete; i++) /* add tuples */
PageIndexTupleDelete(page, xlrec.todelete[i]); if (xlrec.len > 0)
if (GistPageIsLeaf(page)) gistfillbuffer(reln, page, xlrec.itup, xlrec.len, InvalidOffsetNumber);
GistMarkTuplesDeleted(page);
}
/* add tuples */ /*
if (xlrec.len > 0) * special case: leafpage, nothing to insert, nothing to delete, then
gistfillbuffer(reln, page, xlrec.itup, xlrec.len, InvalidOffsetNumber); * vacuum marks page
*/
if (GistPageIsLeaf(page) && xlrec.len == 0 && xlrec.data->ntodelete == 0)
GistClearTuplesDeleted(page);
/* if ( !GistPageIsLeaf(page) && PageGetMaxOffsetNumber(page) == InvalidOffsetNumber && xldata->blkno == GIST_ROOT_BLKNO )
* special case: leafpage, nothing to insert, nothing to delete, then /* all links on non-leaf root page was deleted by vacuum full,
* vacuum marks page so root page becomes a leaf */
*/ GistPageSetLeaf(page);
if (GistPageIsLeaf(page) && xlrec.len == 0 && xlrec.data->ntodelete == 0)
GistClearTuplesDeleted(page);
}
GistPageGetOpaque(page)->rightlink = InvalidBlockNumber; GistPageGetOpaque(page)->rightlink = InvalidBlockNumber;
PageSetLSN(page, lsn); PageSetLSN(page, lsn);
...@@ -252,6 +244,29 @@ gistRedoPageUpdateRecord(XLogRecPtr lsn, XLogRecord *record, bool isnewroot) ...@@ -252,6 +244,29 @@ gistRedoPageUpdateRecord(XLogRecPtr lsn, XLogRecord *record, bool isnewroot)
UnlockReleaseBuffer(buffer); UnlockReleaseBuffer(buffer);
} }
static void
gistRedoPageDeleteRecord(XLogRecPtr lsn, XLogRecord *record)
{
gistxlogPageDelete *xldata = (gistxlogPageDelete *) XLogRecGetData(record);
Relation reln;
Buffer buffer;
Page page;
reln = XLogOpenRelation(xldata->node);
buffer = XLogReadBuffer(reln, xldata->blkno, false);
if (!BufferIsValid(buffer))
return;
GISTInitBuffer( buffer, 0 );
page = (Page) BufferGetPage(buffer);
GistPageSetDeleted(page);
PageSetLSN(page, lsn);
PageSetTLI(page, ThisTimeLineID);
MarkBufferDirty(buffer);
UnlockReleaseBuffer(buffer);
}
static void static void
decodePageSplitRecord(PageSplitRecord *decoded, XLogRecord *record) decodePageSplitRecord(PageSplitRecord *decoded, XLogRecord *record)
{ {
...@@ -382,6 +397,9 @@ gist_redo(XLogRecPtr lsn, XLogRecord *record) ...@@ -382,6 +397,9 @@ gist_redo(XLogRecPtr lsn, XLogRecord *record)
case XLOG_GIST_PAGE_UPDATE: case XLOG_GIST_PAGE_UPDATE:
gistRedoPageUpdateRecord(lsn, record, false); gistRedoPageUpdateRecord(lsn, record, false);
break; break;
case XLOG_GIST_PAGE_DELETE:
gistRedoPageDeleteRecord(lsn, record);
break;
case XLOG_GIST_NEW_ROOT: case XLOG_GIST_NEW_ROOT:
gistRedoPageUpdateRecord(lsn, record, true); gistRedoPageUpdateRecord(lsn, record, true);
break; break;
...@@ -405,8 +423,10 @@ gist_redo(XLogRecPtr lsn, XLogRecord *record) ...@@ -405,8 +423,10 @@ gist_redo(XLogRecPtr lsn, XLogRecord *record)
static void static void
out_target(StringInfo buf, RelFileNode node, ItemPointerData key) out_target(StringInfo buf, RelFileNode node, ItemPointerData key)
{ {
appendStringInfo(buf, "rel %u/%u/%u; tid %u/%u", appendStringInfo(buf, "rel %u/%u/%u",
node.spcNode, node.dbNode, node.relNode, node.spcNode, node.dbNode, node.relNode);
if ( ItemPointerIsValid( &key ) )
appendStringInfo(buf, "; tid %u/%u",
ItemPointerGetBlockNumber(&key), ItemPointerGetBlockNumber(&key),
ItemPointerGetOffsetNumber(&key)); ItemPointerGetOffsetNumber(&key));
} }
...@@ -418,6 +438,14 @@ out_gistxlogPageUpdate(StringInfo buf, gistxlogPageUpdate *xlrec) ...@@ -418,6 +438,14 @@ out_gistxlogPageUpdate(StringInfo buf, gistxlogPageUpdate *xlrec)
appendStringInfo(buf, "; block number %u", xlrec->blkno); appendStringInfo(buf, "; block number %u", xlrec->blkno);
} }
static void
out_gistxlogPageDelete(StringInfo buf, gistxlogPageDelete *xlrec)
{
appendStringInfo(buf, "page_delete: rel %u/%u/%u; blkno %u",
xlrec->node.spcNode, xlrec->node.dbNode, xlrec->node.relNode,
xlrec->blkno);
}
static void static void
out_gistxlogPageSplit(StringInfo buf, gistxlogPageSplit *xlrec) out_gistxlogPageSplit(StringInfo buf, gistxlogPageSplit *xlrec)
{ {
...@@ -438,6 +466,9 @@ gist_desc(StringInfo buf, uint8 xl_info, char *rec) ...@@ -438,6 +466,9 @@ gist_desc(StringInfo buf, uint8 xl_info, char *rec)
appendStringInfo(buf, "page_update: "); appendStringInfo(buf, "page_update: ");
out_gistxlogPageUpdate(buf, (gistxlogPageUpdate *) rec); out_gistxlogPageUpdate(buf, (gistxlogPageUpdate *) rec);
break; break;
case XLOG_GIST_PAGE_DELETE:
out_gistxlogPageDelete(buf, (gistxlogPageDelete *) rec);
break;
case XLOG_GIST_NEW_ROOT: case XLOG_GIST_NEW_ROOT:
appendStringInfo(buf, "new_root: "); appendStringInfo(buf, "new_root: ");
out_target(buf, ((gistxlogPageUpdate *) rec)->node, ((gistxlogPageUpdate *) rec)->key); out_target(buf, ((gistxlogPageUpdate *) rec)->node, ((gistxlogPageUpdate *) rec)->key);
...@@ -643,7 +674,7 @@ gistContinueInsert(gistIncompleteInsert *insert) ...@@ -643,7 +674,7 @@ gistContinueInsert(gistIncompleteInsert *insert)
* we split root, just copy tuples from old root to new * we split root, just copy tuples from old root to new
* page * page
*/ */
parentitup = gistextractbuffer(buffers[numbuffer - 1], parentitup = gistextractpage(pages[numbuffer - 1],
&pituplen); &pituplen);
/* sanity check */ /* sanity check */
...@@ -796,7 +827,7 @@ formSplitRdata(RelFileNode node, BlockNumber blkno, bool page_is_leaf, ...@@ -796,7 +827,7 @@ formSplitRdata(RelFileNode node, BlockNumber blkno, bool page_is_leaf,
*/ */
XLogRecData * XLogRecData *
formUpdateRdata(RelFileNode node, Buffer buffer, formUpdateRdata(RelFileNode node, Buffer buffer,
OffsetNumber *todelete, int ntodelete, bool emptypage, OffsetNumber *todelete, int ntodelete,
IndexTuple *itup, int ituplen, ItemPointer key) IndexTuple *itup, int ituplen, ItemPointer key)
{ {
XLogRecData *rdata; XLogRecData *rdata;
...@@ -804,35 +835,37 @@ formUpdateRdata(RelFileNode node, Buffer buffer, ...@@ -804,35 +835,37 @@ formUpdateRdata(RelFileNode node, Buffer buffer,
int cur, int cur,
i; i;
/* ugly wart in API: emptypage causes us to ignore other inputs */ rdata = (XLogRecData *) palloc(sizeof(XLogRecData) * (3 + ituplen));
if (emptypage)
ntodelete = ituplen = 0;
rdata = (XLogRecData *) palloc(sizeof(XLogRecData) * (2 + ituplen));
xlrec = (gistxlogPageUpdate *) palloc(sizeof(gistxlogPageUpdate)); xlrec = (gistxlogPageUpdate *) palloc(sizeof(gistxlogPageUpdate));
xlrec->node = node; xlrec->node = node;
xlrec->blkno = BufferGetBlockNumber(buffer); xlrec->blkno = BufferGetBlockNumber(buffer);
xlrec->ntodelete = ntodelete; xlrec->ntodelete = ntodelete;
xlrec->isemptypage = emptypage;
if (key) if (key)
xlrec->key = *key; xlrec->key = *key;
else else
ItemPointerSetInvalid(&(xlrec->key)); ItemPointerSetInvalid(&(xlrec->key));
rdata[0].data = (char *) xlrec; rdata[0].buffer = buffer;
rdata[0].len = sizeof(gistxlogPageUpdate); rdata[0].buffer_std = true;
rdata[0].buffer = InvalidBuffer; rdata[0].data = NULL;
rdata[0].len = 0;
rdata[0].next = &(rdata[1]); rdata[0].next = &(rdata[1]);
rdata[1].data = (char *) todelete; rdata[1].data = (char *) xlrec;
rdata[1].len = MAXALIGN(sizeof(OffsetNumber) * ntodelete); rdata[1].len = sizeof(gistxlogPageUpdate);
rdata[1].buffer = buffer; rdata[1].buffer = InvalidBuffer;
rdata[1].buffer_std = true; rdata[1].next = &(rdata[2]);
rdata[1].next = NULL;
rdata[2].data = (char *) todelete;
rdata[2].len = MAXALIGN(sizeof(OffsetNumber) * ntodelete);
rdata[2].buffer = buffer;
rdata[2].buffer_std = true;
rdata[2].next = NULL;
/* new tuples */ /* new tuples */
cur = 2; cur = 3;
for (i = 0; i < ituplen; i++) for (i = 0; i < ituplen; i++)
{ {
rdata[cur - 1].next = &(rdata[cur]); rdata[cur - 1].next = &(rdata[cur]);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.13 2006/05/10 09:19:54 teodor Exp $ * $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.14 2006/05/17 16:34:59 teodor Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -85,20 +85,21 @@ extern const XLogRecPtr XLogRecPtrForTemp; ...@@ -85,20 +85,21 @@ extern const XLogRecPtr XLogRecPtrForTemp;
#define XLOG_GIST_PAGE_SPLIT 0x30 #define XLOG_GIST_PAGE_SPLIT 0x30
#define XLOG_GIST_INSERT_COMPLETE 0x40 #define XLOG_GIST_INSERT_COMPLETE 0x40
#define XLOG_GIST_CREATE_INDEX 0x50 #define XLOG_GIST_CREATE_INDEX 0x50
#define XLOG_GIST_PAGE_DELETE 0x60
typedef struct gistxlogPageUpdate typedef struct gistxlogPageUpdate
{ {
RelFileNode node; RelFileNode node;
BlockNumber blkno; BlockNumber blkno;
uint16 ntodelete;
bool isemptypage;
/* /*
* It used to identify completeness of insert. Sets to leaf itup * It used to identify completeness of insert. Sets to leaf itup
*/ */
ItemPointerData key; ItemPointerData key;
/* number of deleted offsets */
uint16 ntodelete;
/* /*
* follow: 1. todelete OffsetNumbers 2. tuples to insert * follow: 1. todelete OffsetNumbers 2. tuples to insert
*/ */
...@@ -131,6 +132,11 @@ typedef struct gistxlogInsertComplete ...@@ -131,6 +132,11 @@ typedef struct gistxlogInsertComplete
/* follows ItemPointerData key to clean */ /* follows ItemPointerData key to clean */
} gistxlogInsertComplete; } gistxlogInsertComplete;
typedef struct gistxlogPageDelete
{
RelFileNode node;
BlockNumber blkno;
} gistxlogPageDelete;
/* SplitedPageLayout - gistSplit function result */ /* SplitedPageLayout - gistSplit function result */
typedef struct SplitedPageLayout typedef struct SplitedPageLayout
...@@ -249,7 +255,7 @@ extern void gist_xlog_cleanup(void); ...@@ -249,7 +255,7 @@ extern void gist_xlog_cleanup(void);
extern IndexTuple gist_form_invalid_tuple(BlockNumber blkno); extern IndexTuple gist_form_invalid_tuple(BlockNumber blkno);
extern XLogRecData *formUpdateRdata(RelFileNode node, Buffer buffer, extern XLogRecData *formUpdateRdata(RelFileNode node, Buffer buffer,
OffsetNumber *todelete, int ntodelete, bool emptypage, OffsetNumber *todelete, int ntodelete,
IndexTuple *itup, int ituplen, ItemPointer key); IndexTuple *itup, int ituplen, ItemPointer key);
extern XLogRecData *formSplitRdata(RelFileNode node, extern XLogRecData *formSplitRdata(RelFileNode node,
...@@ -273,7 +279,7 @@ extern void gistcheckpage(Relation rel, Buffer buf); ...@@ -273,7 +279,7 @@ extern void gistcheckpage(Relation rel, Buffer buf);
extern Buffer gistNewBuffer(Relation r); extern Buffer gistNewBuffer(Relation r);
extern OffsetNumber gistfillbuffer(Relation r, Page page, IndexTuple *itup, extern OffsetNumber gistfillbuffer(Relation r, Page page, IndexTuple *itup,
int len, OffsetNumber off); int len, OffsetNumber off);
extern IndexTuple *gistextractbuffer(Buffer buffer, int *len /* out */ ); extern IndexTuple *gistextractpage(Page page, int *len /* out */ );
extern IndexTuple *gistjoinvector( extern IndexTuple *gistjoinvector(
IndexTuple *itvec, int *len, IndexTuple *itvec, int *len,
IndexTuple *additvec, int addlen); IndexTuple *additvec, int addlen);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment