2000-10-13 14:06:40 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
2000-10-20 13:01:21 +02:00
|
|
|
* xlogutils.c
|
2000-10-13 14:06:40 +02:00
|
|
|
*
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-10-13 14:06:40 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2002-03-31 08:26:32 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlogutils.c,v 1.23 2002/03/31 06:26:29 tgl Exp $
|
XLOG (and related) changes:
* Store two past checkpoint locations, not just one, in pg_control.
On startup, we fall back to the older checkpoint if the newer one
is unreadable. Also, a physical copy of the newest checkpoint record
is kept in pg_control for possible use in disaster recovery (ie,
complete loss of pg_xlog). Also add a version number for pg_control
itself. Remove archdir from pg_control; it ought to be a GUC
parameter, not a special case (not that it's implemented yet anyway).
* Suppress successive checkpoint records when nothing has been entered
in the WAL log since the last one. This is not so much to avoid I/O
as to make it actually useful to keep track of the last two
checkpoints. If the things are right next to each other then there's
not a lot of redundancy gained...
* Change CRC scheme to a true 64-bit CRC, not a pair of 32-bit CRCs
on alternate bytes. Polynomial borrowed from ECMA DLT1 standard.
* Fix XLOG record length handling so that it will work at BLCKSZ = 32k.
* Change XID allocation to work more like OID allocation. (This is of
dubious necessity, but I think it's a good idea anyway.)
* Fix a number of minor bugs, such as off-by-one logic for XLOG file
wraparound at the 4 gig mark.
* Add documentation and clean up some coding infelicities; move file
format declarations out to include files where planned contrib
utilities can get at them.
* Checkpoint will now occur every CHECKPOINT_SEGMENTS log segments or
every CHECKPOINT_TIMEOUT seconds, whichever comes first. It is also
possible to force a checkpoint by sending SIGUSR1 to the postmaster
(undocumented feature...)
* Defend against kill -9 postmaster by storing shmem block's key and ID
in postmaster.pid lockfile, and checking at startup to ensure that no
processes are still connected to old shmem block (if it still exists).
* Switch backends to accept SIGQUIT rather than SIGUSR1 for emergency
stop, for symmetry with postmaster and xlog utilities. Clean up signal
handling in bootstrap.c so that xlog utilities launched by postmaster
will react to signals better.
* Standalone bootstrap now grabs lockfile in target directory, as added
insurance against running it in parallel with live postmaster.
2001-03-13 02:17:06 +01:00
|
|
|
*
|
2000-10-13 14:06:40 +02:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
XLOG (and related) changes:
* Store two past checkpoint locations, not just one, in pg_control.
On startup, we fall back to the older checkpoint if the newer one
is unreadable. Also, a physical copy of the newest checkpoint record
is kept in pg_control for possible use in disaster recovery (ie,
complete loss of pg_xlog). Also add a version number for pg_control
itself. Remove archdir from pg_control; it ought to be a GUC
parameter, not a special case (not that it's implemented yet anyway).
* Suppress successive checkpoint records when nothing has been entered
in the WAL log since the last one. This is not so much to avoid I/O
as to make it actually useful to keep track of the last two
checkpoints. If the things are right next to each other then there's
not a lot of redundancy gained...
* Change CRC scheme to a true 64-bit CRC, not a pair of 32-bit CRCs
on alternate bytes. Polynomial borrowed from ECMA DLT1 standard.
* Fix XLOG record length handling so that it will work at BLCKSZ = 32k.
* Change XID allocation to work more like OID allocation. (This is of
dubious necessity, but I think it's a good idea anyway.)
* Fix a number of minor bugs, such as off-by-one logic for XLOG file
wraparound at the 4 gig mark.
* Add documentation and clean up some coding infelicities; move file
format declarations out to include files where planned contrib
utilities can get at them.
* Checkpoint will now occur every CHECKPOINT_SEGMENTS log segments or
every CHECKPOINT_TIMEOUT seconds, whichever comes first. It is also
possible to force a checkpoint by sending SIGUSR1 to the postmaster
(undocumented feature...)
* Defend against kill -9 postmaster by storing shmem block's key and ID
in postmaster.pid lockfile, and checking at startup to ensure that no
processes are still connected to old shmem block (if it still exists).
* Switch backends to accept SIGQUIT rather than SIGUSR1 for emergency
stop, for symmetry with postmaster and xlog utilities. Clean up signal
handling in bootstrap.c so that xlog utilities launched by postmaster
will react to signals better.
* Standalone bootstrap now grabs lockfile in target directory, as added
insurance against running it in parallel with live postmaster.
2001-03-13 02:17:06 +01:00
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
#include "access/htup.h"
|
|
|
|
#include "access/xlogutils.h"
|
|
|
|
#include "catalog/pg_database.h"
|
2001-08-25 20:52:43 +02:00
|
|
|
#include "storage/bufpage.h"
|
|
|
|
#include "storage/smgr.h"
|
2001-10-05 19:28:13 +02:00
|
|
|
#include "utils/hsearch.h"
|
2000-11-21 22:16:06 +01:00
|
|
|
#include "utils/relcache.h"
|
2000-10-13 14:06:40 +02:00
|
|
|
|
2001-08-25 20:52:43 +02:00
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
/*
|
|
|
|
* ---------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Index support functions
|
|
|
|
*
|
|
|
|
*----------------------------------------------------------------
|
|
|
|
*/
|
2000-10-13 14:06:40 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if specified heap tuple was inserted by given
|
|
|
|
* xaction/command and return
|
|
|
|
*
|
|
|
|
* - -1 if not
|
2001-03-22 05:01:46 +01:00
|
|
|
* - 0 if there is no tuple at all
|
|
|
|
* - 1 if yes
|
2000-10-13 14:06:40 +02:00
|
|
|
*/
|
|
|
|
int
|
2001-03-22 05:01:46 +01:00
|
|
|
XLogIsOwnerOfTuple(RelFileNode hnode, ItemPointer iptr,
|
|
|
|
TransactionId xid, CommandId cid)
|
2000-10-13 14:06:40 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
Relation reln;
|
|
|
|
Buffer buffer;
|
|
|
|
Page page;
|
|
|
|
ItemId lp;
|
|
|
|
HeapTupleHeader htup;
|
2000-10-13 14:06:40 +02:00
|
|
|
|
|
|
|
reln = XLogOpenRelation(false, RM_HEAP_ID, hnode);
|
|
|
|
if (!RelationIsValid(reln))
|
2001-03-22 05:01:46 +01:00
|
|
|
return (0);
|
2000-10-13 14:06:40 +02:00
|
|
|
|
|
|
|
buffer = ReadBuffer(reln, ItemPointerGetBlockNumber(iptr));
|
|
|
|
if (!BufferIsValid(buffer))
|
2001-03-22 05:01:46 +01:00
|
|
|
return (0);
|
2000-10-13 14:06:40 +02:00
|
|
|
|
|
|
|
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
|
|
|
page = (Page) BufferGetPage(buffer);
|
|
|
|
if (PageIsNew((PageHeader) page) ||
|
|
|
|
ItemPointerGetOffsetNumber(iptr) > PageGetMaxOffsetNumber(page))
|
|
|
|
{
|
|
|
|
UnlockAndReleaseBuffer(buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (0);
|
2000-10-13 14:06:40 +02:00
|
|
|
}
|
|
|
|
lp = PageGetItemId(page, ItemPointerGetOffsetNumber(iptr));
|
|
|
|
if (!ItemIdIsUsed(lp) || ItemIdDeleted(lp))
|
|
|
|
{
|
|
|
|
UnlockAndReleaseBuffer(buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (0);
|
2000-10-13 14:06:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
htup = (HeapTupleHeader) PageGetItem(page, lp);
|
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
Assert(PageGetSUI(page) == ThisStartUpID);
|
2001-08-24 01:06:38 +02:00
|
|
|
if (!TransactionIdEquals(htup->t_xmin, xid) || htup->t_cmin != cid)
|
2000-10-13 14:06:40 +02:00
|
|
|
{
|
|
|
|
UnlockAndReleaseBuffer(buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (-1);
|
2000-10-13 14:06:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UnlockAndReleaseBuffer(buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (1);
|
2000-10-13 14:06:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-10-20 13:01:21 +02:00
|
|
|
* MUST BE CALLED ONLY ON RECOVERY.
|
|
|
|
*
|
2000-10-13 14:06:40 +02:00
|
|
|
* Check if exists valid (inserted by not aborted xaction) heap tuple
|
|
|
|
* for given item pointer
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
XLogIsValidTuple(RelFileNode hnode, ItemPointer iptr)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
Relation reln;
|
|
|
|
Buffer buffer;
|
|
|
|
Page page;
|
|
|
|
ItemId lp;
|
|
|
|
HeapTupleHeader htup;
|
2000-10-13 14:06:40 +02:00
|
|
|
|
|
|
|
reln = XLogOpenRelation(false, RM_HEAP_ID, hnode);
|
|
|
|
if (!RelationIsValid(reln))
|
2001-03-22 05:01:46 +01:00
|
|
|
return (false);
|
2000-10-13 14:06:40 +02:00
|
|
|
|
|
|
|
buffer = ReadBuffer(reln, ItemPointerGetBlockNumber(iptr));
|
|
|
|
if (!BufferIsValid(buffer))
|
2001-03-22 05:01:46 +01:00
|
|
|
return (false);
|
2000-10-13 14:06:40 +02:00
|
|
|
|
|
|
|
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
|
|
|
page = (Page) BufferGetPage(buffer);
|
|
|
|
if (PageIsNew((PageHeader) page) ||
|
|
|
|
ItemPointerGetOffsetNumber(iptr) > PageGetMaxOffsetNumber(page))
|
|
|
|
{
|
|
|
|
UnlockAndReleaseBuffer(buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (false);
|
2000-10-13 14:06:40 +02:00
|
|
|
}
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
if (PageGetSUI(page) != ThisStartUpID)
|
|
|
|
{
|
|
|
|
Assert(PageGetSUI(page) < ThisStartUpID);
|
|
|
|
UnlockAndReleaseBuffer(buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (true);
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
2000-10-13 14:06:40 +02:00
|
|
|
lp = PageGetItemId(page, ItemPointerGetOffsetNumber(iptr));
|
|
|
|
if (!ItemIdIsUsed(lp) || ItemIdDeleted(lp))
|
|
|
|
{
|
|
|
|
UnlockAndReleaseBuffer(buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (false);
|
2000-10-13 14:06:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
htup = (HeapTupleHeader) PageGetItem(page, lp);
|
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
/* MUST CHECK WASN'T TUPLE INSERTED IN PREV STARTUP */
|
|
|
|
|
2000-10-24 11:56:23 +02:00
|
|
|
if (!(htup->t_infomask & HEAP_XMIN_COMMITTED))
|
2000-10-13 14:06:40 +02:00
|
|
|
{
|
2000-10-24 11:56:23 +02:00
|
|
|
if (htup->t_infomask & HEAP_XMIN_INVALID ||
|
|
|
|
(htup->t_infomask & HEAP_MOVED_IN &&
|
2001-03-22 05:01:46 +01:00
|
|
|
TransactionIdDidAbort((TransactionId) htup->t_cmin)) ||
|
2000-10-24 11:56:23 +02:00
|
|
|
TransactionIdDidAbort(htup->t_xmin))
|
|
|
|
{
|
|
|
|
UnlockAndReleaseBuffer(buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (false);
|
2000-10-24 11:56:23 +02:00
|
|
|
}
|
2000-10-13 14:06:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UnlockAndReleaseBuffer(buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (true);
|
2000-10-13 14:06:40 +02:00
|
|
|
}
|
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
/*
|
|
|
|
* ---------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Storage related support functions
|
|
|
|
*
|
|
|
|
*----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
Buffer
|
|
|
|
XLogReadBuffer(bool extend, Relation reln, BlockNumber blkno)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
BlockNumber lastblock = RelationGetNumberOfBlocks(reln);
|
2000-10-20 13:01:21 +02:00
|
|
|
Buffer buffer;
|
|
|
|
|
|
|
|
if (blkno >= lastblock)
|
|
|
|
{
|
|
|
|
buffer = InvalidBuffer;
|
2001-03-22 05:01:46 +01:00
|
|
|
if (extend) /* we do this in recovery only - no locks */
|
2000-10-20 13:01:21 +02:00
|
|
|
{
|
|
|
|
Assert(InRecovery);
|
|
|
|
while (lastblock <= blkno)
|
|
|
|
{
|
2001-02-22 09:59:40 +01:00
|
|
|
if (buffer != InvalidBuffer)
|
2001-03-22 05:01:46 +01:00
|
|
|
ReleaseBuffer(buffer); /* must be WriteBuffer()? */
|
2000-10-20 13:01:21 +02:00
|
|
|
buffer = ReadBuffer(reln, P_NEW);
|
|
|
|
lastblock++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (buffer != InvalidBuffer)
|
|
|
|
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (buffer);
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer = ReadBuffer(reln, blkno);
|
|
|
|
if (buffer != InvalidBuffer)
|
|
|
|
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (buffer);
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "Relation" cache
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct XLogRelDesc
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
RelationData reldata;
|
|
|
|
struct XLogRelDesc *lessRecently;
|
|
|
|
struct XLogRelDesc *moreRecently;
|
2000-10-20 13:01:21 +02:00
|
|
|
} XLogRelDesc;
|
|
|
|
|
|
|
|
typedef struct XLogRelCacheEntry
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
RelFileNode rnode;
|
|
|
|
XLogRelDesc *rdesc;
|
2000-10-20 13:01:21 +02:00
|
|
|
} XLogRelCacheEntry;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
static HTAB *_xlrelcache;
|
|
|
|
static XLogRelDesc *_xlrelarr = NULL;
|
|
|
|
static Form_pg_class _xlpgcarr = NULL;
|
|
|
|
static int _xlast = 0;
|
|
|
|
static int _xlcnt = 0;
|
|
|
|
|
|
|
|
#define _XLOG_RELCACHESIZE 512
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
_xl_init_rel_cache(void)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
HASHCTL ctl;
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-11-01 00:56:36 +01:00
|
|
|
_xlcnt = _XLOG_RELCACHESIZE;
|
2000-10-20 13:01:21 +02:00
|
|
|
_xlast = 0;
|
2001-03-22 05:01:46 +01:00
|
|
|
_xlrelarr = (XLogRelDesc *) malloc(sizeof(XLogRelDesc) * _xlcnt);
|
2000-10-20 13:01:21 +02:00
|
|
|
memset(_xlrelarr, 0, sizeof(XLogRelDesc) * _xlcnt);
|
|
|
|
_xlpgcarr = (Form_pg_class) malloc(sizeof(FormData_pg_class) * _xlcnt);
|
2000-10-24 11:56:23 +02:00
|
|
|
memset(_xlpgcarr, 0, sizeof(FormData_pg_class) * _xlcnt);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-10-21 17:43:36 +02:00
|
|
|
_xlrelarr[0].moreRecently = &(_xlrelarr[0]);
|
|
|
|
_xlrelarr[0].lessRecently = &(_xlrelarr[0]);
|
|
|
|
|
2001-10-01 07:36:17 +02:00
|
|
|
memset(&ctl, 0, sizeof(ctl));
|
2000-10-20 13:01:21 +02:00
|
|
|
ctl.keysize = sizeof(RelFileNode);
|
2001-10-01 07:36:17 +02:00
|
|
|
ctl.entrysize = sizeof(XLogRelCacheEntry);
|
2000-10-20 13:01:21 +02:00
|
|
|
ctl.hash = tag_hash;
|
|
|
|
|
2001-10-05 19:28:13 +02:00
|
|
|
_xlrelcache = hash_create("XLOG relcache", _XLOG_RELCACHESIZE,
|
|
|
|
&ctl, HASH_ELEM | HASH_FUNCTION);
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
static void
|
2001-10-05 19:28:13 +02:00
|
|
|
_xl_remove_hash_entry(XLogRelDesc *rdesc)
|
2000-10-28 18:21:00 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
Form_pg_class tpgc = rdesc->reldata.rd_rel;
|
2001-10-05 19:28:13 +02:00
|
|
|
XLogRelCacheEntry *hentry;
|
2000-10-28 18:21:00 +02:00
|
|
|
|
|
|
|
rdesc->lessRecently->moreRecently = rdesc->moreRecently;
|
|
|
|
rdesc->moreRecently->lessRecently = rdesc->lessRecently;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
hentry = (XLogRelCacheEntry *) hash_search(_xlrelcache,
|
2001-10-25 07:50:21 +02:00
|
|
|
(void *) &(rdesc->reldata.rd_node), HASH_REMOVE, NULL);
|
2000-10-28 18:21:00 +02:00
|
|
|
if (hentry == NULL)
|
Commit to match discussed elog() changes. Only update is that LOG is
now just below FATAL in server_min_messages. Added more text to
highlight ordering difference between it and client_min_messages.
---------------------------------------------------------------------------
REALLYFATAL => PANIC
STOP => PANIC
New INFO level the prints to client by default
New LOG level the prints to server log by default
Cause VACUUM information to print only to the client
NOTICE => INFO where purely information messages are sent
DEBUG => LOG for purely server status messages
DEBUG removed, kept as backward compatible
DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1 added
DebugLvl removed in favor of new DEBUG[1-5] symbols
New server_min_messages GUC parameter with values:
DEBUG[5-1], INFO, NOTICE, ERROR, LOG, FATAL, PANIC
New client_min_messages GUC parameter with values:
DEBUG[5-1], LOG, INFO, NOTICE, ERROR, FATAL, PANIC
Server startup now logged with LOG instead of DEBUG
Remove debug_level GUC parameter
elog() numbers now start at 10
Add test to print error message if older elog() values are passed to elog()
Bootstrap mode now has a -d that requires an argument, like postmaster
2002-03-02 22:39:36 +01:00
|
|
|
elog(PANIC, "_xl_remove_hash_entry: file was not found in cache");
|
2000-10-28 18:21:00 +02:00
|
|
|
|
|
|
|
if (rdesc->reldata.rd_fd >= 0)
|
|
|
|
smgrclose(DEFAULT_SMGR, &(rdesc->reldata));
|
|
|
|
|
|
|
|
memset(rdesc, 0, sizeof(XLogRelDesc));
|
|
|
|
memset(tpgc, 0, sizeof(FormData_pg_class));
|
|
|
|
rdesc->reldata.rd_rel = tpgc;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
static XLogRelDesc *
|
2000-10-20 13:01:21 +02:00
|
|
|
_xl_new_reldesc(void)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
XLogRelDesc *res;
|
2000-11-01 00:56:36 +01:00
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
_xlast++;
|
|
|
|
if (_xlast < _xlcnt)
|
|
|
|
{
|
|
|
|
_xlrelarr[_xlast].reldata.rd_rel = &(_xlpgcarr[_xlast]);
|
2001-03-22 05:01:46 +01:00
|
|
|
return (&(_xlrelarr[_xlast]));
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
2000-11-01 00:56:36 +01:00
|
|
|
/* reuse */
|
|
|
|
res = _xlrelarr[0].moreRecently;
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2001-10-05 19:28:13 +02:00
|
|
|
_xl_remove_hash_entry(res);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-11-01 00:56:36 +01:00
|
|
|
_xlast--;
|
2001-03-22 05:01:46 +01:00
|
|
|
return (res);
|
2000-10-28 18:21:00 +02:00
|
|
|
}
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
void
|
|
|
|
XLogInitRelationCache(void)
|
|
|
|
{
|
|
|
|
CreateDummyCaches();
|
|
|
|
_xl_init_rel_cache();
|
|
|
|
}
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
void
|
|
|
|
XLogCloseRelationCache(void)
|
|
|
|
{
|
2001-10-05 19:28:13 +02:00
|
|
|
HASH_SEQ_STATUS status;
|
|
|
|
XLogRelCacheEntry *hentry;
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
DestroyDummyCaches();
|
|
|
|
|
|
|
|
if (!_xlrelarr)
|
|
|
|
return;
|
|
|
|
|
2001-10-05 19:28:13 +02:00
|
|
|
hash_seq_init(&status, _xlrelcache);
|
|
|
|
|
|
|
|
while ((hentry = (XLogRelCacheEntry *) hash_seq_search(&status)) != NULL)
|
|
|
|
_xl_remove_hash_entry(hentry->rdesc);
|
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
hash_destroy(_xlrelcache);
|
|
|
|
|
|
|
|
free(_xlrelarr);
|
|
|
|
free(_xlpgcarr);
|
|
|
|
|
|
|
|
_xlrelarr = NULL;
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Relation
|
|
|
|
XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
XLogRelDesc *res;
|
|
|
|
XLogRelCacheEntry *hentry;
|
|
|
|
bool found;
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
hentry = (XLogRelCacheEntry *)
|
2001-10-05 19:28:13 +02:00
|
|
|
hash_search(_xlrelcache, (void *) &rnode, HASH_FIND, NULL);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2001-10-05 19:28:13 +02:00
|
|
|
if (hentry)
|
2000-10-20 13:01:21 +02:00
|
|
|
{
|
|
|
|
res = hentry->rdesc;
|
|
|
|
|
|
|
|
res->lessRecently->moreRecently = res->moreRecently;
|
|
|
|
res->moreRecently->lessRecently = res->lessRecently;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = _xl_new_reldesc();
|
|
|
|
|
2002-03-31 08:26:32 +02:00
|
|
|
sprintf(RelationGetRelationName(&(res->reldata)), "%u", rnode.relNode);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
/* unexisting DB id */
|
|
|
|
res->reldata.rd_lockInfo.lockRelId.dbId = RecoveryDb;
|
|
|
|
res->reldata.rd_lockInfo.lockRelId.relId = rnode.relNode;
|
|
|
|
res->reldata.rd_node = rnode;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
hentry = (XLogRelCacheEntry *)
|
2001-10-01 07:36:17 +02:00
|
|
|
hash_search(_xlrelcache, (void *) &rnode, HASH_ENTER, &found);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
if (hentry == NULL)
|
Commit to match discussed elog() changes. Only update is that LOG is
now just below FATAL in server_min_messages. Added more text to
highlight ordering difference between it and client_min_messages.
---------------------------------------------------------------------------
REALLYFATAL => PANIC
STOP => PANIC
New INFO level the prints to client by default
New LOG level the prints to server log by default
Cause VACUUM information to print only to the client
NOTICE => INFO where purely information messages are sent
DEBUG => LOG for purely server status messages
DEBUG removed, kept as backward compatible
DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1 added
DebugLvl removed in favor of new DEBUG[1-5] symbols
New server_min_messages GUC parameter with values:
DEBUG[5-1], INFO, NOTICE, ERROR, LOG, FATAL, PANIC
New client_min_messages GUC parameter with values:
DEBUG[5-1], LOG, INFO, NOTICE, ERROR, FATAL, PANIC
Server startup now logged with LOG instead of DEBUG
Remove debug_level GUC parameter
elog() numbers now start at 10
Add test to print error message if older elog() values are passed to elog()
Bootstrap mode now has a -d that requires an argument, like postmaster
2002-03-02 22:39:36 +01:00
|
|
|
elog(PANIC, "XLogOpenRelation: out of memory for cache");
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
if (found)
|
Commit to match discussed elog() changes. Only update is that LOG is
now just below FATAL in server_min_messages. Added more text to
highlight ordering difference between it and client_min_messages.
---------------------------------------------------------------------------
REALLYFATAL => PANIC
STOP => PANIC
New INFO level the prints to client by default
New LOG level the prints to server log by default
Cause VACUUM information to print only to the client
NOTICE => INFO where purely information messages are sent
DEBUG => LOG for purely server status messages
DEBUG removed, kept as backward compatible
DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1 added
DebugLvl removed in favor of new DEBUG[1-5] symbols
New server_min_messages GUC parameter with values:
DEBUG[5-1], INFO, NOTICE, ERROR, LOG, FATAL, PANIC
New client_min_messages GUC parameter with values:
DEBUG[5-1], LOG, INFO, NOTICE, ERROR, FATAL, PANIC
Server startup now logged with LOG instead of DEBUG
Remove debug_level GUC parameter
elog() numbers now start at 10
Add test to print error message if older elog() values are passed to elog()
Bootstrap mode now has a -d that requires an argument, like postmaster
2002-03-02 22:39:36 +01:00
|
|
|
elog(PANIC, "XLogOpenRelation: file found on insert into cache");
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
hentry->rdesc = res;
|
|
|
|
|
2001-06-29 23:08:25 +02:00
|
|
|
res->reldata.rd_targblock = InvalidBlockNumber;
|
2000-10-21 17:43:36 +02:00
|
|
|
res->reldata.rd_fd = -1;
|
2000-11-08 23:10:03 +01:00
|
|
|
res->reldata.rd_fd = smgropen(DEFAULT_SMGR, &(res->reldata),
|
2001-03-22 05:01:46 +01:00
|
|
|
true /* allow failure */ );
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
res->moreRecently = &(_xlrelarr[0]);
|
|
|
|
res->lessRecently = _xlrelarr[0].lessRecently;
|
|
|
|
_xlrelarr[0].lessRecently = res;
|
|
|
|
res->lessRecently->moreRecently = res;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
if (res->reldata.rd_fd < 0) /* file doesn't exist */
|
|
|
|
return (NULL);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
return (&(res->reldata));
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|