From: | Ben Grimm <bgrimm(at)zaeon(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, Vadim Mikheev <vmikheev(at)sectorbase(dot)com> |
Subject: | Re: Bug #613: Sequence values fall back to previously checkpointed |
Date: | 2002-03-13 16:28:11 |
Message-ID: | 20020313102811.A32611@zaeon.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Wed, 13 Mar 2002, Tom Lane wrote:
>
> Accordingly, I'm thinking that we must remove the SEQ_LOG_VALS
> functionality and force one-WAL-record-per-nextval operation.
>
> Vadim, do you see another way? This was a cool idea and I hate
> to throw it away...
>
It seems like you just need to ensure that when the sequence is loaded
from disk that log_cnt gets updated and written back to disk before the
sequence is used. I'm not sure of the impact, but I can't reproduce the
bugs after making these changes. I just added a flag to the SeqTableData
struct to say whether its been logged yet - this seems like overkill..
but it works for me :-) (at least in the scenarios I've tried)
-- Ben
*** src/backend/commands/sequence.c Wed Mar 13 11:14:42 2002
--- src/backend/commands/sequence.c.orig Tue Mar 12 18:58:55 2002
***************
*** 62,68 ****
int64 cached;
int64 last;
int64 increment;
- bool islogged;
struct SeqTableData *next;
} SeqTableData;
--- 62,67 ----
***************
*** 315,321 ****
PG_RETURN_INT64(elm->last);
}
! seq = read_info("nextval", elm, &buf); /* lock page' buffer and read tuple */
last = next = result = seq->last_value;
incby = seq->increment_by;
--- 314,321 ----
PG_RETURN_INT64(elm->last);
}
! seq = read_info("nextval", elm, &buf); /* lock page' buffer and
! * read tuple */
last = next = result = seq->last_value;
incby = seq->increment_by;
***************
*** 331,337 ****
log--;
}
! if (log < fetch || !elm->islogged)
{
fetch = log = fetch - log + SEQ_LOG_VALS;
logit = true;
--- 331,337 ----
log--;
}
! if (log < fetch)
{
fetch = log = fetch - log + SEQ_LOG_VALS;
logit = true;
***************
*** 405,411 ****
rdata[0].next = &(rdata[1]);
seq->last_value = next;
! elm->islogged = seq->is_called = true;
seq->log_cnt = 0;
rdata[1].buffer = InvalidBuffer;
rdata[1].data = (char *) page + ((PageHeader) page)->pd_upper;
--- 405,411 ----
rdata[0].next = &(rdata[1]);
seq->last_value = next;
! seq->is_called = true;
seq->log_cnt = 0;
rdata[1].buffer = InvalidBuffer;
rdata[1].data = (char *) page + ((PageHeader) page)->pd_upper;
***************
*** 417,424 ****
PageSetLSN(page, recptr);
PageSetSUI(page, ThisStartUpID);
! XLogFlush(recptr);
!
if (fetch) /* not all numbers were fetched */
log -= fetch;
}
--- 417,423 ----
PageSetLSN(page, recptr);
PageSetSUI(page, ThisStartUpID);
!
if (fetch) /* not all numbers were fetched */
log -= fetch;
}
***************
*** 729,735 ****
prev->next = elm;
}
- elm->islogged = false;
return elm;
}
--- 728,733 ----
From | Date | Subject | |
---|---|---|---|
Next Message | Ward Vandewege | 2002-03-13 16:47:22 | SERIAL silently trunctates sequence name to 31 characters |
Previous Message | Stephan Szabo | 2002-03-13 16:13:22 | Re: referential constraint bug |