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 ----

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to