critical sections of code.
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.98 2000/11/30 18:38:45 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.99 2000/12/03 10:27:25 vadim Exp $
*
*
* INTERFACE ROUTINES
buffer = RelationGetBufferForTuple(relation, tup->t_len);
/* NO ELOG(ERROR) from here till changes are logged */
+ START_CRIT_CODE;
RelationPutHeapTuple(relation, buffer, tup);
/* XLOG stuff */
PageSetLSN(BufferGetPage(buffer), recptr);
PageSetSUI(BufferGetPage(buffer), ThisStartUpID);
}
+ END_CRIT_CODE;
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
WriteBuffer(buffer);
}
/* XLOG stuff */
+ START_CRIT_CODE;
{
xl_heap_delete xlrec;
XLogRecPtr recptr;
tp.t_data->t_cmax = GetCurrentCommandId();
tp.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |
HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
+ END_CRIT_CODE;
#ifdef TUPLE_TOASTER_ACTIVE
/* ----------
}
/* NO ELOG(ERROR) from here till changes are logged */
+ START_CRIT_CODE;
- /* insert new tuple */
- RelationPutHeapTuple(relation, newbuf, newtup);
-
+ RelationPutHeapTuple(relation, newbuf, newtup); /* insert new tuple */
if (buffer == newbuf)
{
TransactionIdStore(GetCurrentTransactionId(), &(oldtup.t_data->t_xmax));
PageSetLSN(BufferGetPage(buffer), recptr);
PageSetSUI(BufferGetPage(buffer), ThisStartUpID);
}
+ END_CRIT_CODE;
if (newbuf != buffer)
{
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.69 2000/11/30 08:46:21 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.70 2000/12/03 10:27:26 vadim Exp $
*
*-------------------------------------------------------------------------
*/
* NO ELOG(ERROR) till right sibling is updated.
*
*/
+ START_CRIT_CODE;
{
char xlbuf[sizeof(xl_btree_split) +
sizeof(CommandId) + sizeof(RelFileNode) + BLCKSZ];
/* write and release the old right sibling */
_bt_wrtbuf(rel, sbuf);
}
+ END_CRIT_CODE;
/* split's done */
return rbuf;
metabuf = _bt_getbuf(rel, BTREE_METAPAGE,BT_WRITE);
/* NO ELOG(ERROR) from here till newroot op is logged */
+ START_CRIT_CODE;
/* set btree special data */
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
_bt_wrtbuf(rel, metabuf);
}
+ END_CRIT_CODE;
/* write and let go of the new root buffer */
_bt_wrtbuf(rel, rootbuf);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.42 2000/11/30 08:46:21 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.43 2000/12/03 10:27:26 vadim Exp $
*
* NOTES
* Postgres btree pages look like ordinary relation pages. The opaque
rootpage = BufferGetPage(rootbuf);
/* NO ELOG(ERROR) till meta is updated */
+ START_CRIT_CODE;
_bt_pageinit(rootpage, BufferGetPageSize(rootbuf));
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
PageSetLSN(metapg, recptr);
PageSetSUI(metapg, ThisStartUpID);
}
+ END_CRIT_CODE;
metad->btm_root = rootblkno;
metad->btm_level = 1;
page = BufferGetPage(buf);
/* XLOG stuff */
+ START_CRIT_CODE;
{
xl_btree_delete xlrec;
XLogRecPtr recptr;
}
PageIndexTupleDelete(page, offno);
+ END_CRIT_CODE;
/* write the buffer and release the lock */
_bt_wrtbuf(rel, buf);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.86 2000/11/30 08:46:22 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.87 2000/12/03 10:27:26 vadim Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
BufmgrCommit();
xlrec.xtime = time(NULL);
+ START_CRIT_CODE;
/*
* SHOULD SAVE ARRAY OF RELFILENODE-s TO DROP
*/
TransactionIdCommit(xid);
MyProc->logRec.xrecoff = 0;
+ END_CRIT_CODE;
}
if (leak)
XLogRecPtr recptr;
xlrec.xtime = time(NULL);
+ START_CRIT_CODE;
recptr = XLogInsert(RM_XACT_ID, XLOG_XACT_ABORT,
(char*) &xlrec, SizeOfXactAbort, NULL, 0);
TransactionIdAbort(xid);
MyProc->logRec.xrecoff = 0;
+ END_CRIT_CODE;
}
/*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.38 2000/11/30 08:46:22 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.39 2000/12/03 10:27:26 vadim Exp $
*
*-------------------------------------------------------------------------
*/
int XLOGbuffers = 8;
XLogRecPtr MyLastRecPtr = {0, 0};
-bool StopIfError = false;
+uint32 StopIfError = 0;
bool InRecovery = false;
StartUpID ThisStartUpID = 0;
return (RecPtr);
}
+ START_CRIT_CODE;
+
/* obtain xlog insert lock */
if (TAS(&(XLogCtl->insert_lck))) /* busy */
{
}
}
+ END_CRIT_CODE;
return (RecPtr);
}
return;
if (XLByteLE(record, LgwrResult.Flush))
return;
+
+ START_CRIT_CODE;
+
WriteRqst = LgwrRqst.Write;
for (;;)
{
if (XLByteLE(record, LgwrResult.Flush))
{
S_UNLOCK(&(XLogCtl->info_lck));
+ END_CRIT_CODE;
return;
}
if (XLByteLT(XLogCtl->LgwrRqst.Flush, record))
if (XLByteLE(record, LgwrResult.Flush))
{
S_UNLOCK(&(XLogCtl->lgwr_lck));
+ END_CRIT_CODE;
return;
}
if (XLByteLT(LgwrResult.Write, WriteRqst))
S_UNLOCK(&(XLogCtl->lgwr_lck));
if (XLByteLT(LgwrResult.Flush, record))
elog(STOP, "XLogFlush: request is not satisfied");
+ END_CRIT_CODE;
return;
}
break;
XLogCtl->Write.LgwrResult = LgwrResult;
S_UNLOCK(&(XLogCtl->lgwr_lck));
+
+ END_CRIT_CODE;
return;
}
LastRec;
XLogRecord *record;
char buffer[MAXLOGRECSZ + SizeOfXLogRecord];
- bool sie_saved = false;
elog(LOG, "starting up");
+ StopIfError++;
XLogCtl->xlblocks = (XLogRecPtr *) (((char *) XLogCtl) + sizeof(XLogCtlData));
XLogCtl->pages = ((char *) XLogCtl->xlblocks + sizeof(XLogRecPtr) * XLOGbuffers);
ControlFile->time = time(NULL);
UpdateControlFile();
- sie_saved = StopIfError;
- StopIfError = true;
-
XLogOpenLogRelation(); /* open pg_log */
XLogInitRelationCache();
if (InRecovery)
{
CreateCheckPoint(true);
- StopIfError = sie_saved;
XLogCloseRelationCache();
}
InRecovery = false;
XLogCtl->ThisStartUpID = ThisStartUpID;
elog(LOG, "database system is in production state");
+ StopIfError--;
return;
}
{
elog(LOG, "shutting down");
+ StopIfError++;
CreateDummyCaches();
CreateCheckPoint(true);
+ StopIfError--;
elog(LOG, "database system is shut down");
}
if (MyLastRecPtr.xrecoff != 0)
elog(ERROR, "CreateCheckPoint: cannot be called inside transaction block");
+ START_CRIT_CODE;
while (TAS(&(XLogCtl->chkp_lck)))
{
struct timeval delay = {2, 0};
S_UNLOCK(&(XLogCtl->chkp_lck));
MyLastRecPtr.xrecoff = 0; /* to avoid commit record */
+ END_CRIT_CODE;
return;
}
elm->last = result; /* last returned number */
elm->cached = last; /* last fetched number */
+ START_CRIT_CODE;
if (logit)
{
xl_seq_rec xlrec;
Assert(log >= 0);
seq->log_cnt = log; /* how much is logged */
seq->is_called = 't';
+ END_CRIT_CODE;
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
elm->cached = next; /* last cached number */
/* save info in sequence relation */
+ START_CRIT_CODE;
seq->last_value = next; /* last fetched number */
seq->is_called = iscalled ? 't' : 'f';
seq->log_cnt = (iscalled) ? 0 : 1;
PageSetLSN(BufferGetPage(buf), recptr);
PageSetSUI(BufferGetPage(buf), ThisStartUpID);
}
+ END_CRIT_CODE;
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.175 2000/12/02 19:38:34 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.176 2000/12/03 10:27:27 vadim Exp $
*
*-------------------------------------------------------------------------
*/
Cpage = BufferGetPage(Cbuf);
/* NO ELOG(ERROR) TILL CHANGES ARE LOGGED */
+ START_CRIT_CODE;
Citemid = PageGetItemId(Cpage,
ItemPointerGetOffsetNumber(&(tuple.t_self)));
PageSetLSN(ToPage, recptr);
PageSetSUI(ToPage, ThisStartUpID);
}
+ END_CRIT_CODE;
if (((int) destvacpage->blkno) > last_move_dest_block)
last_move_dest_block = destvacpage->blkno;
~(HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID | HEAP_MOVED_OFF);
newtup.t_data->t_infomask |= HEAP_MOVED_IN;
+ /* NO ELOG(ERROR) TILL CHANGES ARE LOGGED */
+ START_CRIT_CODE;
+
/* add tuple to the page */
newoff = PageAddItem(ToPage, (Item) newtup.t_data, tuple_len,
InvalidOffsetNumber, LP_USED);
if (newoff == InvalidOffsetNumber)
{
- elog(ERROR, "\
+ elog(STOP, "\
failed to add item with len = %lu to page %u (free space %lu, nusd %u, noff %u)",
(unsigned long)tuple_len, cur_page->blkno, (unsigned long)cur_page->free,
cur_page->offsets_used, cur_page->offsets_free);
PageSetLSN(ToPage, recptr);
PageSetSUI(ToPage, ThisStartUpID);
}
+ END_CRIT_CODE;
cur_page->offsets_used++;
num_moved++;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.193 2000/11/30 01:27:19 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.194 2000/12/03 10:27:27 vadim Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
void
handle_warn(SIGNAL_ARGS)
{
+ if (StopIfError)
+ {
+ QueryCancel = true;
+ return;
+ }
siglongjmp(Warn_restart, 1);
}
{
PG_SETMASK(&BlockSig);
- /*
- * If ERROR/FATAL is in progress...
- */
- if (InError)
+ ExitAfterAbort = true;
+ if (StopIfError)
{
- ExitAfterAbort = true;
+ QueryCancel = true;
return;
}
+ if (InError) /* If ERROR/FATAL is in progress... */
+ return;
elog(FATAL, "The system is shutting down");
}
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.193 $ $Date: 2000/11/30 01:27:19 $\n");
+ puts("$Revision: 1.194 $ $Date: 2000/12/03 10:27:27 $\n");
}
/*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.70 2000/12/01 19:52:04 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.71 2000/12/03 10:27:28 vadim Exp $
*
*-------------------------------------------------------------------------
*/
#include "commands/copy.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
-#include "miscadmin.h"
#include "storage/proc.h"
#include "tcop/tcopprot.h"
#include "utils/memutils.h"
/* this is probably redundant... */
if (IsInitProcessingMode())
lev = FATAL;
+ if (StopIfError)
+ lev = STOP;
}
/* choose message prefix and indent level */
*
* PostgreSQL transaction log manager
*
- * $Header: /cvsroot/pgsql/src/include/access/xlog.h,v 1.12 2000/11/30 01:47:32 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/include/access/xlog.h,v 1.13 2000/12/03 10:27:28 vadim Exp $
*/
#ifndef XLOG_H
#define XLOG_H
extern StartUpID ThisStartUpID; /* current SUI */
extern bool InRecovery;
extern XLogRecPtr MyLastRecPtr;
+extern uint32 StopIfError;
typedef struct RmgrData
{
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: tcopprot.h,v 1.35 2000/10/07 00:58:23 tgl Exp $
+ * $Id: tcopprot.h,v 1.36 2000/12/03 10:27:29 vadim Exp $
*
* OLD COMMENTS
* This file was created so that other c files could get the two
extern DLLIMPORT sigjmp_buf Warn_restart;
extern bool Warn_restart_ready;
extern bool InError;
-extern bool ExitAfterAbort;
extern bool HostnameLookup;
extern bool ShowPortNumber;
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: elog.h,v 1.18 2000/06/04 15:06:34 petere Exp $
+ * $Id: elog.h,v 1.19 2000/12/03 10:27:29 vadim Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef ELOG_H
#define ELOG_H
+#include "miscadmin.h"
+
#define NOTICE 0 /* random info - no special action */
#define ERROR (-1) /* user error - return to known state */
#define FATAL 1 /* fatal error - abort process */
extern int Use_syslog;
#endif
+/*
+ * If StopIfError > 0 signal handlers don't do
+ * elog(ERROR|FATAL) but remember what action was
+ * required with QueryCancel & ExitAfterAbort
+ */
+extern bool ExitAfterAbort;
+#define START_CRIT_CODE StopIfError++
+#define END_CRIT_CODE \
+ if (!StopIfError)\
+ elog(STOP, "Not in critical section");\
+ StopIfError--;\
+ if (!StopIfError && QueryCancel)\
+ {\
+ if (ExitAfterAbort)\
+ elog(FATAL, "The system is shutting down");\
+ else\
+ elog(ERROR, "Query was cancelled.");\
+ }
+
extern bool Log_timestamp;
extern bool Log_pid;