Commit 2f8c2e99 authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

Fix deleted tuples re-incarnation possible when vacuum transaction

start time equal to tuple->t_tmax.

Privent shrinking if there are tuples modifyed by running transactions
(it concerns system relations only, currently).
parent 234776db
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.32 1997/05/05 10:01:02 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.33 1997/06/03 01:29:26 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -627,8 +627,6 @@ vc_scanheap (VRelStats *vacrelstats, Relation onerel, ...@@ -627,8 +627,6 @@ vc_scanheap (VRelStats *vacrelstats, Relation onerel,
Page page, tempPage = NULL; Page page, tempPage = NULL;
OffsetNumber offnum, maxoff; OffsetNumber offnum, maxoff;
bool pgchanged, tupgone, dobufrel, notup; bool pgchanged, tupgone, dobufrel, notup;
AbsoluteTime purgetime, expiretime;
RelativeTime preservetime;
char *relname; char *relname;
VPageDescr vpc, vp; VPageDescr vpc, vp;
uint32 nvac, ntups, nunused, ncrash, nempg, nnepg, nchpg, nemend; uint32 nvac, ntups, nunused, ncrash, nempg, nnepg, nchpg, nemend;
...@@ -637,6 +635,7 @@ vc_scanheap (VRelStats *vacrelstats, Relation onerel, ...@@ -637,6 +635,7 @@ vc_scanheap (VRelStats *vacrelstats, Relation onerel,
Size max_tlen = 0; Size max_tlen = 0;
int32 i/*, attr_cnt*/; int32 i/*, attr_cnt*/;
struct rusage ru0, ru1; struct rusage ru0, ru1;
bool do_shrinking = true;
getrusage(RUSAGE_SELF, &ru0); getrusage(RUSAGE_SELF, &ru0);
...@@ -647,22 +646,6 @@ vc_scanheap (VRelStats *vacrelstats, Relation onerel, ...@@ -647,22 +646,6 @@ vc_scanheap (VRelStats *vacrelstats, Relation onerel,
nblocks = RelationGetNumberOfBlocks(onerel); nblocks = RelationGetNumberOfBlocks(onerel);
/* calculate the purge time: tuples that expired before this time
will be archived or deleted */
purgetime = GetCurrentTransactionStartTime();
expiretime = (AbsoluteTime)onerel->rd_rel->relexpires;
preservetime = (RelativeTime)onerel->rd_rel->relpreserved;
if (RelativeTimeIsValid(preservetime) && (preservetime)) {
purgetime -= preservetime;
if (AbsoluteTimeIsBackwardCompatiblyValid(expiretime) &&
expiretime > purgetime)
purgetime = expiretime;
}
else if (AbsoluteTimeIsBackwardCompatiblyValid(expiretime))
purgetime = expiretime;
vpc = (VPageDescr) palloc (sizeof(VPageDescrData) + MaxOffsetNumber*sizeof(OffsetNumber)); vpc = (VPageDescr) palloc (sizeof(VPageDescrData) + MaxOffsetNumber*sizeof(OffsetNumber));
vpc->vpd_nusd = 0; vpc->vpd_nusd = 0;
...@@ -732,31 +715,36 @@ vc_scanheap (VRelStats *vacrelstats, Relation onerel, ...@@ -732,31 +715,36 @@ vc_scanheap (VRelStats *vacrelstats, Relation onerel,
ncrash++; ncrash++;
tupgone = true; tupgone = true;
} }
else { else
elog (MESSAGE_LEVEL, "Rel %.*s: TID %u/%u: InsertTransactionInProgress %u", {
elog (NOTICE, "Rel %.*s: TID %u/%u: InsertTransactionInProgress %u - can't shrink relation",
NAMEDATALEN, relname, blkno, offnum, htup->t_xmin); NAMEDATALEN, relname, blkno, offnum, htup->t_xmin);
do_shrinking = false;
} }
} }
if (TransactionIdIsValid((TransactionId)htup->t_xmax)) { if (TransactionIdIsValid((TransactionId)htup->t_xmax))
if (TransactionIdDidAbort(htup->t_xmax)) { {
if (TransactionIdDidAbort(htup->t_xmax))
{
StoreInvalidTransactionId(&(htup->t_xmax)); StoreInvalidTransactionId(&(htup->t_xmax));
pgchanged = true; pgchanged = true;
} else if (TransactionIdDidCommit(htup->t_xmax)) { }
if (!AbsoluteTimeIsBackwardCompatiblyReal(htup->t_tmax)) { else if (TransactionIdDidCommit(htup->t_xmax))
tupgone = true;
htup->t_tmax = TransactionIdGetCommitTime(htup->t_xmax); else if ( !TransactionIdIsInProgress (htup->t_xmax) ) {
pgchanged = true; /*
} * Not Aborted, Not Committed, Not in Progress -
* so it from crashed process. - vadim 06/02/97
/*
* Reap the dead tuple if its expiration time is
* before purgetime.
*/ */
StoreInvalidTransactionId(&(htup->t_xmax));
if (htup->t_tmax < purgetime) { pgchanged = true;
tupgone = true; }
} else
{
elog (NOTICE, "Rel %.*s: TID %u/%u: DeleteTransactionInProgress %u - can't shrink relation",
NAMEDATALEN, relname, blkno, offnum, htup->t_xmax);
do_shrinking = false;
} }
} }
...@@ -880,7 +868,7 @@ DELETE_TRANSACTION_ID_VALID %d, TUPGONE %d.", ...@@ -880,7 +868,7 @@ DELETE_TRANSACTION_ID_VALID %d, TUPGONE %d.",
* Try to make Fvpl keeping in mind that we can't use free space * Try to make Fvpl keeping in mind that we can't use free space
* of "empty" end-pages and last page if it reapped. * of "empty" end-pages and last page if it reapped.
*/ */
if ( Vvpl->vpl_npages - nemend > 0 ) if ( do_shrinking && Vvpl->vpl_npages - nemend > 0 )
{ {
int nusf; /* blocks usefull for re-using */ int nusf; /* blocks usefull for re-using */
......
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