diff options
author | Bruce Momjian | 2004-08-29 05:07:03 +0000 |
---|---|---|
committer | Bruce Momjian | 2004-08-29 05:07:03 +0000 |
commit | b6b71b85bc45b49005b5aec87cba2c33fc8baf49 (patch) | |
tree | c23dbd1dbc43972a8e48327c8a771baf36952f3d /src/backend/access | |
parent | 90cb9c305140684b2b00c739b724f67915e11404 (diff) |
Pgindent run for 8.0.
Diffstat (limited to 'src/backend/access')
31 files changed, 1094 insertions, 990 deletions
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index 97aa50855f1..c4bbd5923fa 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.93 2004/08/29 04:12:17 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.94 2004/08/29 05:06:39 momjian Exp $ * * NOTES * The old interface functions have been converted to macros @@ -468,17 +468,19 @@ heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull) break; /* - * If the attribute number is 0, then we are supposed to return - * the entire tuple as a row-type Datum. (Using zero for this - * purpose is unclean since it risks confusion with "invalid attr" - * result codes, but it's not worth changing now.) + * If the attribute number is 0, then we are supposed to + * return the entire tuple as a row-type Datum. (Using zero + * for this purpose is unclean since it risks confusion with + * "invalid attr" result codes, but it's not worth changing + * now.) * - * We have to make a copy of the tuple so we can safely insert the - * Datum overhead fields, which are not set in on-disk tuples. + * We have to make a copy of the tuple so we can safely insert + * the Datum overhead fields, which are not set in on-disk + * tuples. */ case InvalidAttrNumber: { - HeapTupleHeader dtup; + HeapTupleHeader dtup; dtup = (HeapTupleHeader) palloc(tup->t_len); memcpy((char *) dtup, (char *) tup->t_data, tup->t_len); @@ -555,7 +557,7 @@ heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest) * construct a tuple from the given values[] and nulls[] arrays * * Null attributes are indicated by a 'n' in the appropriate byte - * of nulls[]. Non-null attributes are indicated by a ' ' (space). + * of nulls[]. Non-null attributes are indicated by a ' ' (space). * ---------------- */ HeapTuple @@ -580,7 +582,7 @@ heap_formtuple(TupleDesc tupleDescriptor, /* * Check for nulls and embedded tuples; expand any toasted attributes - * in embedded tuples. This preserves the invariant that toasting can + * in embedded tuples. This preserves the invariant that toasting can * only go one level deep. * * We can skip calling toast_flatten_tuple_attribute() if the attribute @@ -620,7 +622,7 @@ heap_formtuple(TupleDesc tupleDescriptor, len += ComputeDataSize(tupleDescriptor, values, nulls); /* - * Allocate and zero the space needed. Note that the tuple body and + * Allocate and zero the space needed. Note that the tuple body and * HeapTupleData management structure are allocated in one chunk. */ tuple = (HeapTuple) palloc0(HEAPTUPLESIZE + len); @@ -683,9 +685,9 @@ heap_modifytuple(HeapTuple tuple, * allocate and fill values and nulls arrays from either the tuple or * the repl information, as appropriate. * - * NOTE: it's debatable whether to use heap_deformtuple() here or - * just heap_getattr() only the non-replaced colums. The latter could - * win if there are many replaced columns and few non-replaced ones. + * NOTE: it's debatable whether to use heap_deformtuple() here or just + * heap_getattr() only the non-replaced colums. The latter could win + * if there are many replaced columns and few non-replaced ones. * However, heap_deformtuple costs only O(N) while the heap_getattr * way would cost O(N^2) if there are many non-replaced columns, so it * seems better to err on the side of linear cost. @@ -763,10 +765,11 @@ heap_deformtuple(HeapTuple tuple, bool slow = false; /* can we use/set attcacheoff? */ natts = tup->t_natts; + /* - * In inheritance situations, it is possible that the given tuple actually - * has more fields than the caller is expecting. Don't run off the end - * of the caller's arrays. + * In inheritance situations, it is possible that the given tuple + * actually has more fields than the caller is expecting. Don't run + * off the end of the caller's arrays. */ natts = Min(natts, tdesc_natts); @@ -787,9 +790,7 @@ heap_deformtuple(HeapTuple tuple, nulls[attnum] = ' '; if (!slow && att[attnum]->attcacheoff >= 0) - { off = att[attnum]->attcacheoff; - } else { off = att_align(off, att[attnum]->attalign); @@ -807,8 +808,8 @@ heap_deformtuple(HeapTuple tuple, } /* - * If tuple doesn't have all the atts indicated by tupleDesc, read - * the rest as null + * If tuple doesn't have all the atts indicated by tupleDesc, read the + * rest as null */ for (; attnum < tdesc_natts; attnum++) { diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c index d6191a2cfe4..d305734c3e7 100644 --- a/src/backend/access/common/indextuple.c +++ b/src/backend/access/common/indextuple.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.70 2004/08/29 04:12:17 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.71 2004/08/29 05:06:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -162,9 +162,9 @@ index_formtuple(TupleDesc tupleDescriptor, if ((size & INDEX_SIZE_MASK) != size) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("index row requires %lu bytes, maximum size is %lu", - (unsigned long) size, - (unsigned long) INDEX_SIZE_MASK))); + errmsg("index row requires %lu bytes, maximum size is %lu", + (unsigned long) size, + (unsigned long) INDEX_SIZE_MASK))); infomask |= size; diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index 98dc37a76ea..4477a65bb2d 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.84 2004/08/29 04:12:17 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.85 2004/08/29 05:06:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -356,7 +356,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self) outputstr = DatumGetCString(FunctionCall3(&thisState->finfo, attr, - ObjectIdGetDatum(thisState->typioparam), + ObjectIdGetDatum(thisState->typioparam), Int32GetDatum(typeinfo->attrs[i]->atttypmod))); pq_sendcountedtext(&buf, outputstr, strlen(outputstr), false); pfree(outputstr); @@ -368,7 +368,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self) outputbytes = DatumGetByteaP(FunctionCall2(&thisState->finfo, attr, - ObjectIdGetDatum(thisState->typioparam))); + ObjectIdGetDatum(thisState->typioparam))); /* We assume the result will not have been toasted */ pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ, 4); pq_sendbytes(&buf, VARDATA(outputbytes), @@ -458,7 +458,7 @@ printtup_20(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self) outputstr = DatumGetCString(FunctionCall3(&thisState->finfo, attr, - ObjectIdGetDatum(thisState->typioparam), + ObjectIdGetDatum(thisState->typioparam), Int32GetDatum(typeinfo->attrs[i]->atttypmod))); pq_sendcountedtext(&buf, outputstr, strlen(outputstr), true); pfree(outputstr); @@ -579,7 +579,7 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self) value = DatumGetCString(OidFunctionCall3(typoutput, attr, - ObjectIdGetDatum(typioparam), + ObjectIdGetDatum(typioparam), Int32GetDatum(typeinfo->attrs[i]->atttypmod))); printatt((unsigned) i + 1, typeinfo->attrs[i], value); @@ -672,7 +672,7 @@ printtup_internal_20(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self) outputbytes = DatumGetByteaP(FunctionCall2(&thisState->finfo, attr, - ObjectIdGetDatum(thisState->typioparam))); + ObjectIdGetDatum(thisState->typioparam))); /* We assume the result will not have been toasted */ pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ, 4); pq_sendbytes(&buf, VARDATA(outputbytes), diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c index 66403a1b6b6..ed932d35ab6 100644 --- a/src/backend/access/common/tupdesc.c +++ b/src/backend/access/common/tupdesc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.105 2004/08/29 04:12:17 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.106 2004/08/29 05:06:39 momjian Exp $ * * NOTES * some of the executor utility code such as "ExecTypeFromTL" should be @@ -52,8 +52,8 @@ CreateTemplateTupleDesc(int natts, bool hasoid) /* * Allocate enough memory for the tuple descriptor, and zero the - * attrs[] array since TupleDescInitEntry assumes that the array - * is filled with NULL pointers. + * attrs[] array since TupleDescInitEntry assumes that the array is + * filled with NULL pointers. */ desc = (TupleDesc) palloc(sizeof(struct tupleDesc)); @@ -420,8 +420,8 @@ TupleDescInitEntry(TupleDesc desc, /* * Note: attributeName can be NULL, because the planner doesn't always - * fill in valid resname values in targetlists, particularly for resjunk - * attributes. + * fill in valid resname values in targetlists, particularly for + * resjunk attributes. */ if (attributeName != NULL) namestrcpy(&(att->attname), attributeName); @@ -464,7 +464,7 @@ TupleDescInitEntry(TupleDesc desc, * Given a relation schema (list of ColumnDef nodes), build a TupleDesc. * * Note: the default assumption is no OIDs; caller may modify the returned - * TupleDesc if it wants OIDs. Also, tdtypeid will need to be filled in + * TupleDesc if it wants OIDs. Also, tdtypeid will need to be filled in * later on. */ TupleDesc diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c index d3fde5fbc56..75e88002772 100644 --- a/src/backend/access/gist/gist.c +++ b/src/backend/access/gist/gist.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.110 2004/08/29 04:12:17 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.111 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -667,7 +667,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate) Datum attr[INDEX_MAX_KEYS]; bool whatfree[INDEX_MAX_KEYS]; char isnull[INDEX_MAX_KEYS]; - GistEntryVector *evec; + GistEntryVector *evec; Datum datum; int datumsize, i, @@ -715,8 +715,8 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate) { evec->n = 2; gistentryinit(evec->vector[1], - evec->vector[0].key, r, NULL, - (OffsetNumber) 0, evec->vector[0].bytes, FALSE); + evec->vector[0].key, r, NULL, + (OffsetNumber) 0, evec->vector[0].bytes, FALSE); } else @@ -763,7 +763,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate) static IndexTuple gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate) { - GistEntryVector *evec; + GistEntryVector *evec; Datum datum; int datumsize; bool result, @@ -879,7 +879,7 @@ gistunionsubkey(Relation r, GISTSTATE *giststate, IndexTuple *itvec, GIST_SPLITV int len, *attrsize; OffsetNumber *entries; - GistEntryVector *evec; + GistEntryVector *evec; Datum datum; int datumsize; int reallen; @@ -940,8 +940,8 @@ gistunionsubkey(Relation r, GISTSTATE *giststate, IndexTuple *itvec, GIST_SPLITV else { /* - * evec->vector[0].bytes may be not - * defined, so form union with itself + * evec->vector[0].bytes may be not defined, so form union + * with itself */ if (reallen == 1) { @@ -1056,7 +1056,7 @@ gistadjsubkey(Relation r, *ev1p; float lpenalty, rpenalty; - GistEntryVector *evec; + GistEntryVector *evec; int datumsize; bool isnull[INDEX_MAX_KEYS]; int i, @@ -1222,7 +1222,7 @@ gistSplit(Relation r, rbknum; GISTPageOpaque opaque; GIST_SPLITVEC v; - GistEntryVector *entryvec; + GistEntryVector *entryvec; bool *decompvec; int i, j, diff --git a/src/backend/access/gist/gistget.c b/src/backend/access/gist/gistget.c index e3a267ba67a..3580f1f3e60 100644 --- a/src/backend/access/gist/gistget.c +++ b/src/backend/access/gist/gistget.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.41 2004/08/29 04:12:17 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.42 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -250,9 +250,10 @@ gistindex_keytest(IndexTuple tuple, FALSE, isNull); /* - * Call the Consistent function to evaluate the test. The arguments - * are the index datum (as a GISTENTRY*), the comparison datum, and - * the comparison operator's strategy number and subtype from pg_amop. + * Call the Consistent function to evaluate the test. The + * arguments are the index datum (as a GISTENTRY*), the comparison + * datum, and the comparison operator's strategy number and + * subtype from pg_amop. * * (Presently there's no need to pass the subtype since it'll always * be zero, but might as well pass it for possible future use.) diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c index 02af1ef53ec..822b97e8e92 100644 --- a/src/backend/access/gist/gistscan.c +++ b/src/backend/access/gist/gistscan.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.54 2004/08/29 04:12:17 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.55 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -115,9 +115,7 @@ gistrescan(PG_FUNCTION_ARGS) * the sk_subtype field. */ for (i = 0; i < s->numberOfKeys; i++) - { s->keyData[i].sk_func = p->giststate->consistentFn[s->keyData[i].sk_attno - 1]; - } } PG_RETURN_VOID(); @@ -266,9 +264,9 @@ ReleaseResources_gist(void) GISTScanList next; /* - * Note: this should be a no-op during normal query shutdown. - * However, in an abort situation ExecutorEnd is not called and so - * there may be open index scans to clean up. + * Note: this should be a no-op during normal query shutdown. However, + * in an abort situation ExecutorEnd is not called and so there may be + * open index scans to clean up. */ prev = NULL; diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c index db00490e582..40b05720fb2 100644 --- a/src/backend/access/hash/hash.c +++ b/src/backend/access/hash/hash.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.72 2004/08/29 04:12:17 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.73 2004/08/29 05:06:40 momjian Exp $ * * NOTES * This file contains only the public interface routines. @@ -210,8 +210,8 @@ hashgettuple(PG_FUNCTION_ARGS) bool res; /* - * We hold pin but not lock on current buffer while outside the hash AM. - * Reacquire the read lock here. + * We hold pin but not lock on current buffer while outside the hash + * AM. Reacquire the read lock here. */ if (BufferIsValid(so->hashso_curbuf)) _hash_chgbufaccess(rel, so->hashso_curbuf, HASH_NOLOCK, HASH_READ); @@ -470,7 +470,7 @@ hashbulkdelete(PG_FUNCTION_ARGS) /* * Read the metapage to fetch original bucket and tuple counts. Also, * we keep a copy of the last-seen metapage so that we can use its - * hashm_spares[] values to compute bucket page addresses. This is a + * hashm_spares[] values to compute bucket page addresses. This is a * bit hokey but perfectly safe, since the interesting entries in the * spares array cannot change under us; and it beats rereading the * metapage for each bucket. @@ -532,7 +532,7 @@ loop_top: ItemPointer htup; hitem = (HashItem) PageGetItem(page, - PageGetItemId(page, offno)); + PageGetItemId(page, offno)); htup = &(hitem->hash_itup.t_tid); if (callback(htup, callback_state)) { @@ -595,8 +595,8 @@ loop_top: orig_ntuples == metap->hashm_ntuples) { /* - * No one has split or inserted anything since start of scan, - * so believe our count as gospel. + * No one has split or inserted anything since start of scan, so + * believe our count as gospel. */ metap->hashm_ntuples = num_index_tuples; } @@ -604,7 +604,7 @@ loop_top: { /* * Otherwise, our count is untrustworthy since we may have - * double-scanned tuples in split buckets. Proceed by + * double-scanned tuples in split buckets. Proceed by * dead-reckoning. */ if (metap->hashm_ntuples > tuples_removed) diff --git a/src/backend/access/hash/hashinsert.c b/src/backend/access/hash/hashinsert.c index b1c303f8d07..91ae559e3a6 100644 --- a/src/backend/access/hash/hashinsert.c +++ b/src/backend/access/hash/hashinsert.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/hash/hashinsert.c,v 1.33 2004/08/29 04:12:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/hash/hashinsert.c,v 1.34 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -20,7 +20,7 @@ static OffsetNumber _hash_pgaddtup(Relation rel, Buffer buf, - Size itemsize, HashItem hitem); + Size itemsize, HashItem hitem); /* @@ -81,7 +81,7 @@ _hash_doinsert(Relation rel, HashItem hitem) /* * Check whether the item can fit on a hash page at all. (Eventually, - * we ought to try to apply TOAST methods if not.) Note that at this + * we ought to try to apply TOAST methods if not.) Note that at this * point, itemsz doesn't include the ItemId. */ if (itemsz > HashMaxItemSize((Page) metap)) @@ -105,7 +105,8 @@ _hash_doinsert(Relation rel, HashItem hitem) _hash_chgbufaccess(rel, metabuf, HASH_READ, HASH_NOLOCK); /* - * Acquire share lock on target bucket; then we can release split lock. + * Acquire share lock on target bucket; then we can release split + * lock. */ _hash_getlock(rel, blkno, HASH_SHARE); @@ -124,7 +125,7 @@ _hash_doinsert(Relation rel, HashItem hitem) /* * no space on this page; check for an overflow page */ - BlockNumber nextblkno = pageopaque->hasho_nextblkno; + BlockNumber nextblkno = pageopaque->hasho_nextblkno; if (BlockNumberIsValid(nextblkno)) { @@ -169,8 +170,8 @@ _hash_doinsert(Relation rel, HashItem hitem) _hash_droplock(rel, blkno, HASH_SHARE); /* - * Write-lock the metapage so we can increment the tuple count. - * After incrementing it, check to see if it's time for a split. + * Write-lock the metapage so we can increment the tuple count. After + * incrementing it, check to see if it's time for a split. */ _hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE); diff --git a/src/backend/access/hash/hashovfl.c b/src/backend/access/hash/hashovfl.c index 740f119bc7a..c02da93dc1e 100644 --- a/src/backend/access/hash/hashovfl.c +++ b/src/backend/access/hash/hashovfl.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/hash/hashovfl.c,v 1.43 2004/08/29 04:12:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/hash/hashovfl.c,v 1.44 2004/08/29 05:06:40 momjian Exp $ * * NOTES * Overflow pages look like ordinary relation pages. @@ -41,11 +41,11 @@ bitno_to_blkno(HashMetaPage metap, uint32 ovflbitnum) for (i = 1; i < splitnum && ovflbitnum > metap->hashm_spares[i]; i++) - /* loop */ ; + /* loop */ ; /* - * Convert to absolute page number by adding the number of bucket pages - * that exist before this split point. + * Convert to absolute page number by adding the number of bucket + * pages that exist before this split point. */ return (BlockNumber) ((1 << i) + ovflbitnum); } @@ -79,7 +79,7 @@ blkno_to_bitno(HashMetaPage metap, BlockNumber ovflblkno) * * Add an overflow page to the bucket whose last page is pointed to by 'buf'. * - * On entry, the caller must hold a pin but no lock on 'buf'. The pin is + * On entry, the caller must hold a pin but no lock on 'buf'. The pin is * dropped before exiting (we assume the caller is not interested in 'buf' * anymore). The returned overflow page will be pinned and write-locked; * it is guaranteed to be empty. @@ -88,12 +88,12 @@ blkno_to_bitno(HashMetaPage metap, BlockNumber ovflblkno) * That buffer is returned in the same state. * * The caller must hold at least share lock on the bucket, to ensure that - * no one else tries to compact the bucket meanwhile. This guarantees that + * no one else tries to compact the bucket meanwhile. This guarantees that * 'buf' won't stop being part of the bucket while it's unlocked. * * NB: since this could be executed concurrently by multiple processes, * one should not assume that the returned overflow page will be the - * immediate successor of the originally passed 'buf'. Additional overflow + * immediate successor of the originally passed 'buf'. Additional overflow * pages might have been added to the bucket chain in between. */ Buffer @@ -197,7 +197,7 @@ _hash_getovflpage(Relation rel, Buffer metabuf) /* outer loop iterates once per bitmap page */ for (;;) { - BlockNumber mapblkno; + BlockNumber mapblkno; Page mappage; uint32 last_inpage; @@ -274,9 +274,9 @@ _hash_getovflpage(Relation rel, Buffer metabuf) blkno = bitno_to_blkno(metap, bit); /* - * Adjust hashm_firstfree to avoid redundant searches. But don't - * risk changing it if someone moved it while we were searching - * bitmap pages. + * Adjust hashm_firstfree to avoid redundant searches. But don't risk + * changing it if someone moved it while we were searching bitmap + * pages. */ if (metap->hashm_firstfree == orig_firstfree) metap->hashm_firstfree = bit + 1; @@ -304,9 +304,9 @@ found: blkno = bitno_to_blkno(metap, bit); /* - * Adjust hashm_firstfree to avoid redundant searches. But don't - * risk changing it if someone moved it while we were searching - * bitmap pages. + * Adjust hashm_firstfree to avoid redundant searches. But don't risk + * changing it if someone moved it while we were searching bitmap + * pages. */ if (metap->hashm_firstfree == orig_firstfree) { @@ -381,7 +381,7 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf) Bucket bucket; /* Get information from the doomed page */ - ovflblkno = BufferGetBlockNumber(ovflbuf); + ovflblkno = BufferGetBlockNumber(ovflbuf); ovflpage = BufferGetPage(ovflbuf); _hash_checkpage(rel, ovflpage, LH_OVERFLOW_PAGE); ovflopaque = (HashPageOpaque) PageGetSpecialPointer(ovflpage); @@ -396,7 +396,7 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf) /* * Fix up the bucket chain. this is a doubly-linked list, so we must * fix up the bucket chain members behind and ahead of the overflow - * page being deleted. No concurrency issues since we hold exclusive + * page being deleted. No concurrency issues since we hold exclusive * lock on the entire bucket. */ if (BlockNumberIsValid(prevblkno)) @@ -488,7 +488,8 @@ _hash_initbitmap(Relation rel, HashMetaPage metap, BlockNumber blkno) /* * It is okay to write-lock the new bitmap page while holding metapage - * write lock, because no one else could be contending for the new page. + * write lock, because no one else could be contending for the new + * page. * * There is some loss of concurrency in possibly doing I/O for the new * page while holding the metapage lock, but this path is taken so @@ -654,8 +655,8 @@ _hash_squeezebucket(Relation rel, /* * delete the tuple from the "read" page. PageIndexTupleDelete - * repacks the ItemId array, so 'roffnum' will be "advanced" to - * the "next" ItemId. + * repacks the ItemId array, so 'roffnum' will be "advanced" + * to the "next" ItemId. */ PageIndexTupleDelete(rpage, roffnum); } @@ -667,8 +668,9 @@ _hash_squeezebucket(Relation rel, * Tricky point here: if our read and write pages are adjacent in the * bucket chain, our write lock on wbuf will conflict with * _hash_freeovflpage's attempt to update the sibling links of the - * removed page. However, in that case we are done anyway, so we can - * simply drop the write lock before calling _hash_freeovflpage. + * removed page. However, in that case we are done anyway, so we + * can simply drop the write lock before calling + * _hash_freeovflpage. */ if (PageIsEmpty(rpage)) { diff --git a/src/backend/access/hash/hashpage.c b/src/backend/access/hash/hashpage.c index 787bb9bf621..d3088f50cef 100644 --- a/src/backend/access/hash/hashpage.c +++ b/src/backend/access/hash/hashpage.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.45 2004/08/29 04:12:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.46 2004/08/29 05:06:40 momjian Exp $ * * NOTES * Postgres hash pages look like ordinary relation pages. The opaque @@ -35,11 +35,11 @@ static void _hash_splitbucket(Relation rel, Buffer metabuf, - Bucket obucket, Bucket nbucket, - BlockNumber start_oblkno, - BlockNumber start_nblkno, - uint32 maxbucket, - uint32 highmask, uint32 lowmask); + Bucket obucket, Bucket nbucket, + BlockNumber start_oblkno, + BlockNumber start_nblkno, + uint32 maxbucket, + uint32 highmask, uint32 lowmask); /* @@ -47,7 +47,7 @@ static void _hash_splitbucket(Relation rel, Buffer metabuf, * of the locking rules). However, we can skip taking lmgr locks when the * index is local to the current backend (ie, either temp or new in the * current transaction). No one else can see it, so there's no reason to - * take locks. We still take buffer-level locks, but not lmgr locks. + * take locks. We still take buffer-level locks, but not lmgr locks. */ #define USELOCKING(rel) (!RELATION_IS_LOCAL(rel)) @@ -239,13 +239,13 @@ _hash_metapinit(Relation rel) RelationGetRelationName(rel)); /* - * Determine the target fill factor (tuples per bucket) for this index. - * The idea is to make the fill factor correspond to pages about 3/4ths - * full. We can compute it exactly if the index datatype is fixed-width, - * but for var-width there's some guessing involved. + * Determine the target fill factor (tuples per bucket) for this + * index. The idea is to make the fill factor correspond to pages + * about 3/4ths full. We can compute it exactly if the index datatype + * is fixed-width, but for var-width there's some guessing involved. */ data_width = get_typavgwidth(RelationGetDescr(rel)->attrs[0]->atttypid, - RelationGetDescr(rel)->attrs[0]->atttypmod); + RelationGetDescr(rel)->attrs[0]->atttypmod); item_width = MAXALIGN(sizeof(HashItemData)) + MAXALIGN(data_width) + sizeof(ItemIdData); /* include the line pointer */ ffactor = (BLCKSZ * 3 / 4) / item_width; @@ -288,8 +288,9 @@ _hash_metapinit(Relation rel) metap->hashm_procid = index_getprocid(rel, 1, HASHPROC); /* - * We initialize the index with two buckets, 0 and 1, occupying physical - * blocks 1 and 2. The first freespace bitmap page is in block 3. + * We initialize the index with two buckets, 0 and 1, occupying + * physical blocks 1 and 2. The first freespace bitmap page is in + * block 3. */ metap->hashm_maxbucket = metap->hashm_lowmask = 1; /* nbuckets - 1 */ metap->hashm_highmask = 3; /* (nbuckets << 1) - 1 */ @@ -297,7 +298,7 @@ _hash_metapinit(Relation rel) MemSet((char *) metap->hashm_spares, 0, sizeof(metap->hashm_spares)); MemSet((char *) metap->hashm_mapp, 0, sizeof(metap->hashm_mapp)); - metap->hashm_spares[1] = 1; /* the first bitmap page is only spare */ + metap->hashm_spares[1] = 1; /* the first bitmap page is only spare */ metap->hashm_ovflpoint = 1; metap->hashm_firstfree = 0; @@ -319,8 +320,8 @@ _hash_metapinit(Relation rel) } /* - * Initialize first bitmap page. Can't do this until we - * create the first two buckets, else smgr will complain. + * Initialize first bitmap page. Can't do this until we create the + * first two buckets, else smgr will complain. */ _hash_initbitmap(rel, metap, 3); @@ -362,17 +363,18 @@ _hash_expandtable(Relation rel, Buffer metabuf) uint32 lowmask; /* - * Obtain the page-zero lock to assert the right to begin a split - * (see README). + * Obtain the page-zero lock to assert the right to begin a split (see + * README). * * Note: deadlock should be impossible here. Our own backend could only - * be holding bucket sharelocks due to stopped indexscans; those will not - * block other holders of the page-zero lock, who are only interested in - * acquiring bucket sharelocks themselves. Exclusive bucket locks are - * only taken here and in hashbulkdelete, and neither of these operations - * needs any additional locks to complete. (If, due to some flaw in this - * reasoning, we manage to deadlock anyway, it's okay to error out; the - * index will be left in a consistent state.) + * be holding bucket sharelocks due to stopped indexscans; those will + * not block other holders of the page-zero lock, who are only + * interested in acquiring bucket sharelocks themselves. Exclusive + * bucket locks are only taken here and in hashbulkdelete, and neither + * of these operations needs any additional locks to complete. (If, + * due to some flaw in this reasoning, we manage to deadlock anyway, + * it's okay to error out; the index will be left in a consistent + * state.) */ _hash_getlock(rel, 0, HASH_EXCLUSIVE); @@ -383,8 +385,8 @@ _hash_expandtable(Relation rel, Buffer metabuf) _hash_checkpage(rel, (Page) metap, LH_META_PAGE); /* - * Check to see if split is still needed; someone else might have already - * done one while we waited for the lock. + * Check to see if split is still needed; someone else might have + * already done one while we waited for the lock. * * Make sure this stays in sync with_hash_doinsert() */ @@ -394,16 +396,16 @@ _hash_expandtable(Relation rel, Buffer metabuf) /* * Determine which bucket is to be split, and attempt to lock the old - * bucket. If we can't get the lock, give up. + * bucket. If we can't get the lock, give up. * * The lock protects us against other backends, but not against our own * backend. Must check for active scans separately. * - * Ideally we would lock the new bucket too before proceeding, but if - * we are about to cross a splitpoint then the BUCKET_TO_BLKNO mapping + * Ideally we would lock the new bucket too before proceeding, but if we + * are about to cross a splitpoint then the BUCKET_TO_BLKNO mapping * isn't correct yet. For simplicity we update the metapage first and - * then lock. This should be okay because no one else should be trying - * to lock the new bucket yet... + * then lock. This should be okay because no one else should be + * trying to lock the new bucket yet... */ new_bucket = metap->hashm_maxbucket + 1; old_bucket = (new_bucket & metap->hashm_lowmask); @@ -417,7 +419,8 @@ _hash_expandtable(Relation rel, Buffer metabuf) goto fail; /* - * Okay to proceed with split. Update the metapage bucket mapping info. + * Okay to proceed with split. Update the metapage bucket mapping + * info. */ metap->hashm_maxbucket = new_bucket; @@ -431,11 +434,11 @@ _hash_expandtable(Relation rel, Buffer metabuf) /* * If the split point is increasing (hashm_maxbucket's log base 2 * increases), we need to adjust the hashm_spares[] array and - * hashm_ovflpoint so that future overflow pages will be created beyond - * this new batch of bucket pages. + * hashm_ovflpoint so that future overflow pages will be created + * beyond this new batch of bucket pages. * - * XXX should initialize new bucket pages to prevent out-of-order - * page creation? Don't wanna do it right here though. + * XXX should initialize new bucket pages to prevent out-of-order page + * creation? Don't wanna do it right here though. */ spare_ndx = _hash_log2(metap->hashm_maxbucket + 1); if (spare_ndx > metap->hashm_ovflpoint) @@ -456,9 +459,10 @@ _hash_expandtable(Relation rel, Buffer metabuf) /* * Copy bucket mapping info now; this saves re-accessing the meta page * inside _hash_splitbucket's inner loop. Note that once we drop the - * split lock, other splits could begin, so these values might be out of - * date before _hash_splitbucket finishes. That's okay, since all it - * needs is to tell which of these two buckets to map hashkeys into. + * split lock, other splits could begin, so these values might be out + * of date before _hash_splitbucket finishes. That's okay, since all + * it needs is to tell which of these two buckets to map hashkeys + * into. */ maxbucket = metap->hashm_maxbucket; highmask = metap->hashm_highmask; @@ -539,8 +543,8 @@ _hash_splitbucket(Relation rel, /* * It should be okay to simultaneously write-lock pages from each - * bucket, since no one else can be trying to acquire buffer lock - * on pages of either bucket. + * bucket, since no one else can be trying to acquire buffer lock on + * pages of either bucket. */ oblkno = start_oblkno; nblkno = start_nblkno; @@ -562,9 +566,9 @@ _hash_splitbucket(Relation rel, nopaque->hasho_filler = HASHO_FILL; /* - * Partition the tuples in the old bucket between the old bucket and the - * new bucket, advancing along the old bucket's overflow bucket chain - * and adding overflow pages to the new bucket as needed. + * Partition the tuples in the old bucket between the old bucket and + * the new bucket, advancing along the old bucket's overflow bucket + * chain and adding overflow pages to the new bucket as needed. */ ooffnum = FirstOffsetNumber; omaxoffnum = PageGetMaxOffsetNumber(opage); @@ -582,9 +586,10 @@ _hash_splitbucket(Relation rel, oblkno = oopaque->hasho_nextblkno; if (!BlockNumberIsValid(oblkno)) break; + /* - * we ran out of tuples on this particular page, but we - * have more overflow pages; advance to next page. + * we ran out of tuples on this particular page, but we have + * more overflow pages; advance to next page. */ _hash_wrtbuf(rel, obuf); @@ -600,8 +605,8 @@ _hash_splitbucket(Relation rel, /* * Re-hash the tuple to determine which bucket it now belongs in. * - * It is annoying to call the hash function while holding locks, - * but releasing and relocking the page for each tuple is unappealing + * It is annoying to call the hash function while holding locks, but + * releasing and relocking the page for each tuple is unappealing * too. */ hitem = (HashItem) PageGetItem(opage, PageGetItemId(opage, ooffnum)); @@ -666,10 +671,11 @@ _hash_splitbucket(Relation rel, } /* - * We're at the end of the old bucket chain, so we're done partitioning - * the tuples. Before quitting, call _hash_squeezebucket to ensure the - * tuples remaining in the old bucket (including the overflow pages) are - * packed as tightly as possible. The new bucket is already tight. + * We're at the end of the old bucket chain, so we're done + * partitioning the tuples. Before quitting, call _hash_squeezebucket + * to ensure the tuples remaining in the old bucket (including the + * overflow pages) are packed as tightly as possible. The new bucket + * is already tight. */ _hash_wrtbuf(rel, obuf); _hash_wrtbuf(rel, nbuf); diff --git a/src/backend/access/hash/hashscan.c b/src/backend/access/hash/hashscan.c index 2fc24dd9e12..16d2a77d49b 100644 --- a/src/backend/access/hash/hashscan.c +++ b/src/backend/access/hash/hashscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/hash/hashscan.c,v 1.36 2004/08/29 04:12:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/hash/hashscan.c,v 1.37 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -44,9 +44,9 @@ ReleaseResources_hash(void) HashScanList next; /* - * Note: this should be a no-op during normal query shutdown. - * However, in an abort situation ExecutorEnd is not called and so - * there may be open index scans to clean up. + * Note: this should be a no-op during normal query shutdown. However, + * in an abort situation ExecutorEnd is not called and so there may be + * open index scans to clean up. */ prev = NULL; diff --git a/src/backend/access/hash/hashsearch.c b/src/backend/access/hash/hashsearch.c index 76ad5d31849..daaff4adc50 100644 --- a/src/backend/access/hash/hashsearch.c +++ b/src/backend/access/hash/hashsearch.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.36 2004/08/29 04:12:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.37 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -137,12 +137,13 @@ _hash_first(IndexScanDesc scan, ScanDirection dir) * We do not support hash scans with no index qualification, because * we would have to read the whole index rather than just one bucket. * That creates a whole raft of problems, since we haven't got a - * practical way to lock all the buckets against splits or compactions. + * practical way to lock all the buckets against splits or + * compactions. */ if (scan->numberOfKeys < 1) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("hash indexes do not support whole-index scans"))); + errmsg("hash indexes do not support whole-index scans"))); /* * If the constant in the index qual is NULL, assume it cannot match @@ -182,7 +183,8 @@ _hash_first(IndexScanDesc scan, ScanDirection dir) _hash_relbuf(rel, metabuf); /* - * Acquire share lock on target bucket; then we can release split lock. + * Acquire share lock on target bucket; then we can release split + * lock. */ _hash_getlock(rel, blkno, HASH_SHARE); @@ -287,9 +289,8 @@ _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir) while (offnum > maxoff) { /* - * either this page is empty - * (maxoff == InvalidOffsetNumber) - * or we ran off the end. + * either this page is empty (maxoff == + * InvalidOffsetNumber) or we ran off the end. */ _hash_readnext(rel, &buf, &page, &opaque); if (BufferIsValid(buf)) @@ -315,15 +316,12 @@ _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir) while (offnum < FirstOffsetNumber) { /* - * either this page is empty - * (offnum == InvalidOffsetNumber) - * or we ran off the end. + * either this page is empty (offnum == + * InvalidOffsetNumber) or we ran off the end. */ _hash_readprev(rel, &buf, &page, &opaque); if (BufferIsValid(buf)) - { maxoff = offnum = PageGetMaxOffsetNumber(page); - } else { /* end of bucket */ diff --git a/src/backend/access/hash/hashutil.c b/src/backend/access/hash/hashutil.c index 3fb04e77d86..bf9999dc92b 100644 --- a/src/backend/access/hash/hashutil.c +++ b/src/backend/access/hash/hashutil.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/hash/hashutil.c,v 1.39 2004/08/29 04:12:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/hash/hashutil.c,v 1.40 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -113,6 +113,7 @@ void _hash_checkpage(Relation rel, Page page, int flags) { Assert(page); + /* * When checking the metapage, always verify magic number and version. */ diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 4f965eb2bf5..6dd0c357fbb 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.172 2004/08/29 04:12:20 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.173 2004/08/29 05:06:40 momjian Exp $ * * * INTERFACE ROUTINES @@ -75,9 +75,9 @@ initscan(HeapScanDesc scan, ScanKey key) /* * Determine the number of blocks we have to scan. * - * It is sufficient to do this once at scan start, since any tuples - * added while the scan is in progress will be invisible to my - * transaction anyway... + * It is sufficient to do this once at scan start, since any tuples added + * while the scan is in progress will be invisible to my transaction + * anyway... */ scan->rs_nblocks = RelationGetNumberOfBlocks(scan->rs_rd); @@ -1141,12 +1141,13 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid) tup->t_data->t_infomask |= HEAP_XMAX_INVALID; HeapTupleHeaderSetXmin(tup->t_data, GetCurrentTransactionId()); HeapTupleHeaderSetCmin(tup->t_data, cid); - HeapTupleHeaderSetCmax(tup->t_data, 0); /* zero out Datum fields */ + HeapTupleHeaderSetCmax(tup->t_data, 0); /* zero out Datum fields */ tup->t_tableOid = relation->rd_id; /* * If the new tuple is too big for storage or contains already toasted - * out-of-line attributes from some other relation, invoke the toaster. + * out-of-line attributes from some other relation, invoke the + * toaster. */ if (HeapTupleHasExternal(tup) || (MAXALIGN(tup->t_len) > TOAST_TUPLE_THRESHOLD)) @@ -1273,7 +1274,7 @@ simple_heap_insert(Relation relation, HeapTuple tup) */ int heap_delete(Relation relation, ItemPointer tid, - ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait) + ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait) { ItemId lp; HeapTupleData tp; @@ -1404,9 +1405,9 @@ l1: /* * If the tuple has toasted out-of-line attributes, we need to delete - * those items too. We have to do this before WriteBuffer because we need - * to look at the contents of the tuple, but it's OK to release the - * context lock on the buffer first. + * those items too. We have to do this before WriteBuffer because we + * need to look at the contents of the tuple, but it's OK to release + * the context lock on the buffer first. */ if (HeapTupleHasExternal(&tp)) heap_tuple_toast_attrs(relation, NULL, &tp); @@ -1443,7 +1444,7 @@ simple_heap_delete(Relation relation, ItemPointer tid) result = heap_delete(relation, tid, &ctid, GetCurrentCommandId(), SnapshotAny, - true /* wait for commit */); + true /* wait for commit */ ); switch (result) { case HeapTupleSelfUpdated: @@ -1490,7 +1491,7 @@ simple_heap_delete(Relation relation, ItemPointer tid) */ int heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, - ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait) + ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait) { ItemId lp; HeapTupleData oldtup; @@ -1804,7 +1805,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup) result = heap_update(relation, otid, tup, &ctid, GetCurrentCommandId(), SnapshotAny, - true /* wait for commit */); + true /* wait for commit */ ); switch (result) { case HeapTupleSelfUpdated: @@ -2198,8 +2199,8 @@ heap_xlog_newpage(bool redo, XLogRecPtr lsn, XLogRecord *record) Page page; /* - * Note: the NEWPAGE log record is used for both heaps and indexes, - * so do not do anything that assumes we are touching a heap. + * Note: the NEWPAGE log record is used for both heaps and indexes, so + * do not do anything that assumes we are touching a heap. */ if (!redo || (record->xl_info & XLR_BKP_BLOCK_1)) @@ -2668,7 +2669,7 @@ static void out_target(char *buf, xl_heaptid *target) { sprintf(buf + strlen(buf), "rel %u/%u/%u; tid %u/%u", - target->node.spcNode, target->node.dbNode, target->node.relNode, + target->node.spcNode, target->node.dbNode, target->node.relNode, ItemPointerGetBlockNumber(&(target->tid)), ItemPointerGetOffsetNumber(&(target->tid))); } diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index 1a3b4ef896a..fe389991415 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.44 2004/08/29 04:12:20 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.45 2004/08/29 05:06:40 momjian Exp $ * * * INTERFACE ROUTINES @@ -288,13 +288,13 @@ toast_delete(Relation rel, HeapTuple oldtup) /* * Get the tuple descriptor and break down the tuple into fields. * - * NOTE: it's debatable whether to use heap_deformtuple() here or - * just heap_getattr() only the varlena columns. The latter could - * win if there are few varlena columns and many non-varlena ones. - * However, heap_deformtuple costs only O(N) while the heap_getattr - * way would cost O(N^2) if there are many varlena columns, so it - * seems better to err on the side of linear cost. (We won't even - * be here unless there's at least one varlena column, by the way.) + * NOTE: it's debatable whether to use heap_deformtuple() here or just + * heap_getattr() only the varlena columns. The latter could win if + * there are few varlena columns and many non-varlena ones. However, + * heap_deformtuple costs only O(N) while the heap_getattr way would + * cost O(N^2) if there are many varlena columns, so it seems better + * to err on the side of linear cost. (We won't even be here unless + * there's at least one varlena column, by the way.) */ tupleDesc = rel->rd_att; att = tupleDesc->attrs; @@ -311,7 +311,7 @@ toast_delete(Relation rel, HeapTuple oldtup) { if (att[i]->attlen == -1) { - Datum value = toast_values[i]; + Datum value = toast_values[i]; if (toast_nulls[i] != 'n' && VARATT_IS_EXTERNAL(value)) toast_delete_datum(rel, value); @@ -791,7 +791,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup) * * If a Datum is of composite type, "flatten" it to contain no toasted fields. * This must be invoked on any potentially-composite field that is to be - * inserted into a tuple. Doing this preserves the invariant that toasting + * inserted into a tuple. Doing this preserves the invariant that toasting * goes only one level deep in a tuple. * ---------- */ @@ -1105,7 +1105,7 @@ toast_delete_datum(Relation rel, Datum value) ScanKeyInit(&toastkey, (AttrNumber) 1, BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(attr->va_content.va_external.va_valueid)); + ObjectIdGetDatum(attr->va_content.va_external.va_valueid)); /* * Find the chunks by index @@ -1176,7 +1176,7 @@ toast_fetch_datum(varattrib *attr) ScanKeyInit(&toastkey, (AttrNumber) 1, BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(attr->va_content.va_external.va_valueid)); + ObjectIdGetDatum(attr->va_content.va_external.va_valueid)); /* * Read the chunks by index @@ -1330,7 +1330,7 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length) ScanKeyInit(&toastkey[0], (AttrNumber) 1, BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(attr->va_content.va_external.va_valueid)); + ObjectIdGetDatum(attr->va_content.va_external.va_valueid)); /* * Use equality condition for one chunk, a range condition otherwise: diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index 71266a5bfb0..815e207fb2f 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.115 2004/08/29 04:12:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.116 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -200,26 +200,26 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel, * We can skip items that are marked killed. * * Formerly, we applied _bt_isequal() before checking the kill - * flag, so as to fall out of the item loop as soon as possible. - * However, in the presence of heavy update activity an index - * may contain many killed items with the same key; running - * _bt_isequal() on each killed item gets expensive. Furthermore - * it is likely that the non-killed version of each key appears - * first, so that we didn't actually get to exit any sooner anyway. - * So now we just advance over killed items as quickly as we can. - * We only apply _bt_isequal() when we get to a non-killed item or - * the end of the page. + * flag, so as to fall out of the item loop as soon as + * possible. However, in the presence of heavy update activity + * an index may contain many killed items with the same key; + * running _bt_isequal() on each killed item gets expensive. + * Furthermore it is likely that the non-killed version of + * each key appears first, so that we didn't actually get to + * exit any sooner anyway. So now we just advance over killed + * items as quickly as we can. We only apply _bt_isequal() + * when we get to a non-killed item or the end of the page. */ if (!ItemIdDeleted(curitemid)) { /* - * _bt_compare returns 0 for (1,NULL) and (1,NULL) - this's - * how we handling NULLs - and so we must not use _bt_compare - * in real comparison, but only for ordering/finding items on - * pages. - vadim 03/24/97 + * _bt_compare returns 0 for (1,NULL) and (1,NULL) - + * this's how we handling NULLs - and so we must not use + * _bt_compare in real comparison, but only for + * ordering/finding items on pages. - vadim 03/24/97 */ if (!_bt_isequal(itupdesc, page, offset, natts, itup_scankey)) - break; /* we're past all the equal tuples */ + break; /* we're past all the equal tuples */ /* okay, we gotta fetch the heap tuple ... */ cbti = (BTItem) PageGetItem(page, curitemid); diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c index 7175fd5b2c3..fcdb45d952f 100644 --- a/src/backend/access/nbtree/nbtpage.c +++ b/src/backend/access/nbtree/nbtpage.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.79 2004/08/29 04:12:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.80 2004/08/29 05:06:40 momjian Exp $ * * NOTES * Postgres btree pages look like ordinary relation pages. The opaque @@ -276,8 +276,8 @@ _bt_getroot(Relation rel, int access) rootlevel = metad->btm_fastlevel; /* - * We are done with the metapage; arrange to release it via - * first _bt_relandgetbuf call + * We are done with the metapage; arrange to release it via first + * _bt_relandgetbuf call */ rootbuf = metabuf; @@ -368,8 +368,8 @@ _bt_gettrueroot(Relation rel) rootlevel = metad->btm_level; /* - * We are done with the metapage; arrange to release it via - * first _bt_relandgetbuf call + * We are done with the metapage; arrange to release it via first + * _bt_relandgetbuf call */ rootbuf = metabuf; @@ -433,21 +433,22 @@ _bt_getbuf(Relation rel, BlockNumber blkno, int access) * page could have been re-used between the time the last VACUUM * scanned it and the time the VACUUM made its FSM updates.) * - * In fact, it's worse than that: we can't even assume that it's - * safe to take a lock on the reported page. If somebody else - * has a lock on it, or even worse our own caller does, we could + * In fact, it's worse than that: we can't even assume that it's safe + * to take a lock on the reported page. If somebody else has a + * lock on it, or even worse our own caller does, we could * deadlock. (The own-caller scenario is actually not improbable. * Consider an index on a serial or timestamp column. Nearly all * splits will be at the rightmost page, so it's entirely likely - * that _bt_split will call us while holding a lock on the page most - * recently acquired from FSM. A VACUUM running concurrently with - * the previous split could well have placed that page back in FSM.) + * that _bt_split will call us while holding a lock on the page + * most recently acquired from FSM. A VACUUM running concurrently + * with the previous split could well have placed that page back + * in FSM.) * * To get around that, we ask for only a conditional lock on the - * reported page. If we fail, then someone else is using the page, - * and we may reasonably assume it's not free. (If we happen to be - * wrong, the worst consequence is the page will be lost to use till - * the next VACUUM, which is no big problem.) + * reported page. If we fail, then someone else is using the + * page, and we may reasonably assume it's not free. (If we + * happen to be wrong, the worst consequence is the page will be + * lost to use till the next VACUUM, which is no big problem.) */ for (;;) { diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index 15dc433d112..f75fde4c9f4 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.88 2004/08/29 04:12:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.89 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -155,15 +155,16 @@ _bt_moveright(Relation rel, opaque = (BTPageOpaque) PageGetSpecialPointer(page); /* - * When nextkey = false (normal case): if the scan key that brought us to - * this page is > the high key stored on the page, then the page has split - * and we need to move right. (If the scan key is equal to the high key, - * we might or might not need to move right; have to scan the page first - * anyway.) + * When nextkey = false (normal case): if the scan key that brought us + * to this page is > the high key stored on the page, then the page + * has split and we need to move right. (If the scan key is equal to + * the high key, we might or might not need to move right; have to + * scan the page first anyway.) * * When nextkey = true: move right if the scan key is >= page's high key. * - * The page could even have split more than once, so scan as far as needed. + * The page could even have split more than once, so scan as far as + * needed. * * We also have to move right if we followed a link that brought us to a * dead page. @@ -253,13 +254,11 @@ _bt_binsrch(Relation rel, * Binary search to find the first key on the page >= scan key, or * first key > scankey when nextkey is true. * - * For nextkey=false (cmpval=1), the loop invariant is: all slots - * before 'low' are < scan key, all slots at or after 'high' - * are >= scan key. + * For nextkey=false (cmpval=1), the loop invariant is: all slots before + * 'low' are < scan key, all slots at or after 'high' are >= scan key. * - * For nextkey=true (cmpval=0), the loop invariant is: all slots - * before 'low' are <= scan key, all slots at or after 'high' - * are > scan key. + * For nextkey=true (cmpval=0), the loop invariant is: all slots before + * 'low' are <= scan key, all slots at or after 'high' are > scan key. * * We can fall out when high == low. */ @@ -285,15 +284,15 @@ _bt_binsrch(Relation rel, * At this point we have high == low, but be careful: they could point * past the last slot on the page. * - * On a leaf page, we always return the first key >= scan key (resp. - * > scan key), which could be the last slot + 1. + * On a leaf page, we always return the first key >= scan key (resp. > + * scan key), which could be the last slot + 1. */ if (P_ISLEAF(opaque)) return low; /* - * On a non-leaf page, return the last key < scan key (resp. <= scan key). - * There must be one if _bt_compare() is playing by the rules. + * On a non-leaf page, return the last key < scan key (resp. <= scan + * key). There must be one if _bt_compare() is playing by the rules. */ Assert(low > P_FIRSTDATAKEY(opaque)); @@ -382,10 +381,10 @@ _bt_compare(Relation rel, { /* * The sk_func needs to be passed the index value as left arg - * and the sk_argument as right arg (they might be of different - * types). Since it is convenient for callers to think of - * _bt_compare as comparing the scankey to the index item, - * we have to flip the sign of the comparison result. + * and the sk_argument as right arg (they might be of + * different types). Since it is convenient for callers to + * think of _bt_compare as comparing the scankey to the index + * item, we have to flip the sign of the comparison result. * * Note: curious-looking coding is to avoid overflow if * comparison function returns INT_MIN. There is no risk of @@ -497,7 +496,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) bool goback; bool continuescan; ScanKey scankeys; - ScanKey *startKeys = NULL; + ScanKey *startKeys = NULL; int keysCount = 0; int i; StrategyNumber strat_total; @@ -521,7 +520,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) * We want to identify the keys that can be used as starting boundaries; * these are =, >, or >= keys for a forward scan or =, <, <= keys for * a backwards scan. We can use keys for multiple attributes so long as - * the prior attributes had only =, >= (resp. =, <=) keys. Once we accept + * the prior attributes had only =, >= (resp. =, <=) keys. Once we accept * a > or < boundary or find an attribute with no boundary (which can be * thought of as the same as "> -infinity"), we can't use keys for any * attributes to its right, because it would break our simplistic notion @@ -554,13 +553,15 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) ScanKey cur; startKeys = (ScanKey *) palloc(so->numberOfKeys * sizeof(ScanKey)); + /* - * chosen is the so-far-chosen key for the current attribute, if any. - * We don't cast the decision in stone until we reach keys for the - * next attribute. + * chosen is the so-far-chosen key for the current attribute, if + * any. We don't cast the decision in stone until we reach keys + * for the next attribute. */ curattr = 1; chosen = NULL; + /* * Loop iterates from 0 to numberOfKeys inclusive; we use the last * pass to handle after-last-key processing. Actual exit from the @@ -578,8 +579,10 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) if (chosen == NULL) break; startKeys[keysCount++] = chosen; + /* - * Adjust strat_total, and quit if we have stored a > or < key. + * Adjust strat_total, and quit if we have stored a > or < + * key. */ strat = chosen->sk_strategy; if (strat != BTEqualStrategyNumber) @@ -589,11 +592,13 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) strat == BTLessStrategyNumber) break; } + /* * Done if that was the last attribute. */ if (i >= so->numberOfKeys) break; + /* * Reset for next attr, which should be in sequence. */ @@ -646,8 +651,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) ScanKey cur = startKeys[i]; /* - * _bt_preprocess_keys disallows it, but it's place to add some code - * later + * _bt_preprocess_keys disallows it, but it's place to add some + * code later */ if (cur->sk_flags & SK_ISNULL) { @@ -656,10 +661,11 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) elog(ERROR, "btree doesn't support is(not)null, yet"); return false; } + /* * If scankey operator is of default subtype, we can use the - * cached comparison procedure; otherwise gotta look it up in - * the catalogs. + * cached comparison procedure; otherwise gotta look it up in the + * catalogs. */ if (cur->sk_subtype == InvalidOid) { @@ -695,43 +701,46 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) /* * Examine the selected initial-positioning strategy to determine - * exactly where we need to start the scan, and set flag variables - * to control the code below. + * exactly where we need to start the scan, and set flag variables to + * control the code below. * - * If nextkey = false, _bt_search and _bt_binsrch will locate the - * first item >= scan key. If nextkey = true, they will locate the - * first item > scan key. + * If nextkey = false, _bt_search and _bt_binsrch will locate the first + * item >= scan key. If nextkey = true, they will locate the first + * item > scan key. * - * If goback = true, we will then step back one item, while if - * goback = false, we will start the scan on the located item. + * If goback = true, we will then step back one item, while if goback = + * false, we will start the scan on the located item. * * it's yet other place to add some code later for is(not)null ... */ switch (strat_total) { case BTLessStrategyNumber: + /* - * Find first item >= scankey, then back up one to arrive at last - * item < scankey. (Note: this positioning strategy is only used - * for a backward scan, so that is always the correct starting - * position.) + * Find first item >= scankey, then back up one to arrive at + * last item < scankey. (Note: this positioning strategy is + * only used for a backward scan, so that is always the + * correct starting position.) */ nextkey = false; goback = true; break; case BTLessEqualStrategyNumber: + /* - * Find first item > scankey, then back up one to arrive at last - * item <= scankey. (Note: this positioning strategy is only used - * for a backward scan, so that is always the correct starting - * position.) + * Find first item > scankey, then back up one to arrive at + * last item <= scankey. (Note: this positioning strategy is + * only used for a backward scan, so that is always the + * correct starting position.) */ nextkey = true; goback = true; break; case BTEqualStrategyNumber: + /* * If a backward scan was specified, need to start with last * equal item not first one. @@ -739,8 +748,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) if (ScanDirectionIsBackward(dir)) { /* - * This is the same as the <= strategy. We will check - * at the end whether the found item is actually =. + * This is the same as the <= strategy. We will check at + * the end whether the found item is actually =. */ nextkey = true; goback = true; @@ -748,8 +757,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) else { /* - * This is the same as the >= strategy. We will check - * at the end whether the found item is actually =. + * This is the same as the >= strategy. We will check at + * the end whether the found item is actually =. */ nextkey = false; goback = false; @@ -757,18 +766,20 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) break; case BTGreaterEqualStrategyNumber: + /* - * Find first item >= scankey. (This is only used for - * forward scans.) + * Find first item >= scankey. (This is only used for forward + * scans.) */ nextkey = false; goback = false; break; case BTGreaterStrategyNumber: + /* - * Find first item > scankey. (This is only used for - * forward scans.) + * Find first item > scankey. (This is only used for forward + * scans.) */ nextkey = true; goback = false; @@ -814,23 +825,23 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) pfree(scankeys); /* - * If nextkey = false, we are positioned at the first item >= scan key, - * or possibly at the end of a page on which all the existing items are - * less than the scan key and we know that everything on later pages - * is greater than or equal to scan key. + * If nextkey = false, we are positioned at the first item >= scan + * key, or possibly at the end of a page on which all the existing + * items are less than the scan key and we know that everything on + * later pages is greater than or equal to scan key. * - * If nextkey = true, we are positioned at the first item > scan key, - * or possibly at the end of a page on which all the existing items are + * If nextkey = true, we are positioned at the first item > scan key, or + * possibly at the end of a page on which all the existing items are * less than or equal to the scan key and we know that everything on * later pages is greater than scan key. * * The actually desired starting point is either this item or the prior - * one, or in the end-of-page case it's the first item on the next page - * or the last item on this page. We apply _bt_step if needed to get to - * the right place. + * one, or in the end-of-page case it's the first item on the next + * page or the last item on this page. We apply _bt_step if needed to + * get to the right place. * - * If _bt_step fails (meaning we fell off the end of the index in - * one direction or the other), then there are no matches so we just + * If _bt_step fails (meaning we fell off the end of the index in one + * direction or the other), then there are no matches so we just * return false. */ if (goback) @@ -1292,7 +1303,8 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) itup = &(btitem->bti_itup); /* - * Okay, we are on the first or last tuple. Does it pass all the quals? + * Okay, we are on the first or last tuple. Does it pass all the + * quals? */ if (_bt_checkkeys(scan, itup, dir, &continuescan)) { diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c index ac251a4ee4e..98cdccb3bac 100644 --- a/src/backend/access/nbtree/nbtsort.c +++ b/src/backend/access/nbtree/nbtsort.c @@ -41,11 +41,11 @@ * * Since the index will never be used unless it is completely built, * from a crash-recovery point of view there is no need to WAL-log the - * steps of the build. After completing the index build, we can just sync + * steps of the build. After completing the index build, we can just sync * the whole file to disk using smgrimmedsync() before exiting this module. * This can be seen to be sufficient for crash recovery by considering that * it's effectively equivalent to what would happen if a CHECKPOINT occurred - * just after the index build. However, it is clearly not sufficient if the + * just after the index build. However, it is clearly not sufficient if the * DBA is using the WAL log for PITR or replication purposes, since another * machine would not be able to reconstruct the index from WAL. Therefore, * we log the completed index pages to WAL if and only if WAL archiving is @@ -56,7 +56,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.87 2004/08/29 04:12:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.88 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -98,7 +98,7 @@ struct BTSpool typedef struct BTPageState { Page btps_page; /* workspace for page building */ - BlockNumber btps_blkno; /* block # to write this page at */ + BlockNumber btps_blkno; /* block # to write this page at */ BTItem btps_minkey; /* copy of minimum key (first item) on * page */ OffsetNumber btps_lastoff; /* last item offset loaded */ @@ -114,10 +114,10 @@ typedef struct BTPageState typedef struct BTWriteState { Relation index; - bool btws_use_wal; /* dump pages to WAL? */ - BlockNumber btws_pages_alloced; /* # pages allocated */ - BlockNumber btws_pages_written; /* # pages written out */ - Page btws_zeropage; /* workspace for filling zeroes */ + bool btws_use_wal; /* dump pages to WAL? */ + BlockNumber btws_pages_alloced; /* # pages allocated */ + BlockNumber btws_pages_written; /* # pages written out */ + Page btws_zeropage; /* workspace for filling zeroes */ } BTWriteState; @@ -136,7 +136,7 @@ static void _bt_sortaddtup(Page page, Size itemsize, static void _bt_buildadd(BTWriteState *wstate, BTPageState *state, BTItem bti); static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state); static void _bt_load(BTWriteState *wstate, - BTSpool *btspool, BTSpool *btspool2); + BTSpool *btspool, BTSpool *btspool2); /* @@ -157,12 +157,12 @@ _bt_spoolinit(Relation index, bool isunique, bool isdead) btspool->isunique = isunique; /* - * We size the sort area as maintenance_work_mem rather than work_mem to - * speed index creation. This should be OK since a single backend can't - * run multiple index creations in parallel. Note that creation of a - * unique index actually requires two BTSpool objects. We expect that the - * second one (for dead tuples) won't get very full, so we give it only - * work_mem. + * We size the sort area as maintenance_work_mem rather than work_mem + * to speed index creation. This should be OK since a single backend + * can't run multiple index creations in parallel. Note that creation + * of a unique index actually requires two BTSpool objects. We expect + * that the second one (for dead tuples) won't get very full, so we + * give it only work_mem. */ btKbytes = isdead ? work_mem : maintenance_work_mem; btspool->sortstate = tuplesort_begin_index(index, isunique, @@ -205,7 +205,7 @@ _bt_spool(BTItem btitem, BTSpool *btspool) void _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2) { - BTWriteState wstate; + BTWriteState wstate; #ifdef BTREE_BUILD_STATS if (log_btree_build_stats) @@ -220,6 +220,7 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2) tuplesort_performsort(btspool2->sortstate); wstate.index = btspool->index; + /* * We need to log index creation in WAL iff WAL archiving is enabled * AND it's not a temp index. @@ -229,7 +230,7 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2) /* reserve the metapage */ wstate.btws_pages_alloced = BTREE_METAPAGE + 1; wstate.btws_pages_written = 0; - wstate.btws_zeropage = NULL; /* until needed */ + wstate.btws_zeropage = NULL; /* until needed */ _bt_load(&wstate, btspool, btspool2); } @@ -246,7 +247,7 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2) static Page _bt_blnewpage(uint32 level) { - Page page; + Page page; BTPageOpaque opaque; page = (Page) palloc(BLCKSZ); @@ -313,8 +314,8 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno) * If we have to write pages nonsequentially, fill in the space with * zeroes until we come back and overwrite. This is not logically * necessary on standard Unix filesystems (unwritten space will read - * as zeroes anyway), but it should help to avoid fragmentation. - * The dummy pages aren't WAL-logged though. + * as zeroes anyway), but it should help to avoid fragmentation. The + * dummy pages aren't WAL-logged though. */ while (blkno > wstate->btws_pages_written) { @@ -326,9 +327,9 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno) } /* - * Now write the page. We say isTemp = true even if it's not a - * temp index, because there's no need for smgr to schedule an fsync - * for this write; we'll do it ourselves before ending the build. + * Now write the page. We say isTemp = true even if it's not a temp + * index, because there's no need for smgr to schedule an fsync for + * this write; we'll do it ourselves before ending the build. */ smgrwrite(wstate->index->rd_smgr, blkno, (char *) page, true); @@ -468,7 +469,7 @@ static void _bt_buildadd(BTWriteState *wstate, BTPageState *state, BTItem bti) { Page npage; - BlockNumber nblkno; + BlockNumber nblkno; OffsetNumber last_off; Size pgspc; Size btisz; @@ -506,7 +507,7 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, BTItem bti) * already. Finish off the page and write it out. */ Page opage = npage; - BlockNumber oblkno = nblkno; + BlockNumber oblkno = nblkno; ItemId ii; ItemId hii; BTItem obti; @@ -539,8 +540,8 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, BTItem bti) ((PageHeader) opage)->pd_lower -= sizeof(ItemIdData); /* - * Link the old page into its parent, using its minimum key. If - * we don't have a parent, we have to create one; this adds a new + * Link the old page into its parent, using its minimum key. If we + * don't have a parent, we have to create one; this adds a new * btree level. */ if (state->btps_next == NULL) @@ -572,8 +573,8 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, BTItem bti) } /* - * Write out the old page. We never need to touch it again, - * so we can free the opage workspace too. + * Write out the old page. We never need to touch it again, so we + * can free the opage workspace too. */ _bt_blwritepage(wstate, opage, oblkno); @@ -613,7 +614,7 @@ static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state) { BTPageState *s; - BlockNumber rootblkno = P_NONE; + BlockNumber rootblkno = P_NONE; uint32 rootlevel = 0; Page metapage; @@ -663,9 +664,9 @@ _bt_uppershutdown(BTWriteState *wstate, BTPageState *state) /* * As the last step in the process, construct the metapage and make it - * point to the new root (unless we had no data at all, in which case it's - * set to point to "P_NONE"). This changes the index to the "valid" - * state by filling in a valid magic number in the metapage. + * point to the new root (unless we had no data at all, in which case + * it's set to point to "P_NONE"). This changes the index to the + * "valid" state by filling in a valid magic number in the metapage. */ metapage = (Page) palloc(BLCKSZ); _bt_initmetapage(metapage, rootblkno, rootlevel); @@ -744,7 +745,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2) compare = DatumGetInt32(FunctionCall2(&entry->sk_func, attrDatum1, - attrDatum2)); + attrDatum2)); if (compare > 0) { load1 = false; @@ -768,7 +769,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2) if (should_free) pfree((void *) bti); bti = (BTItem) tuplesort_getindextuple(btspool->sortstate, - true, &should_free); + true, &should_free); } else { @@ -776,7 +777,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2) if (should_free2) pfree((void *) bti2); bti2 = (BTItem) tuplesort_getindextuple(btspool2->sortstate, - true, &should_free2); + true, &should_free2); } } _bt_freeskey(indexScanKey); @@ -785,7 +786,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2) { /* merge is unnecessary */ while ((bti = (BTItem) tuplesort_getindextuple(btspool->sortstate, - true, &should_free)) != NULL) + true, &should_free)) != NULL) { /* When we see first tuple, create first index page */ if (state == NULL) @@ -802,18 +803,18 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2) /* * If the index isn't temp, we must fsync it down to disk before it's - * safe to commit the transaction. (For a temp index we don't care + * safe to commit the transaction. (For a temp index we don't care * since the index will be uninteresting after a crash anyway.) * - * It's obvious that we must do this when not WAL-logging the build. - * It's less obvious that we have to do it even if we did WAL-log the - * index pages. The reason is that since we're building outside - * shared buffers, a CHECKPOINT occurring during the build has no way - * to flush the previously written data to disk (indeed it won't know - * the index even exists). A crash later on would replay WAL from the + * It's obvious that we must do this when not WAL-logging the build. It's + * less obvious that we have to do it even if we did WAL-log the index + * pages. The reason is that since we're building outside shared + * buffers, a CHECKPOINT occurring during the build has no way to + * flush the previously written data to disk (indeed it won't know the + * index even exists). A crash later on would replay WAL from the * checkpoint, therefore it wouldn't replay our earlier WAL entries. - * If we do not fsync those pages here, they might still not be on disk - * when the crash occurs. + * If we do not fsync those pages here, they might still not be on + * disk when the crash occurs. */ if (!wstate->index->rd_istemp) smgrimmedsync(wstate->index->rd_smgr); diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c index 425e3b057e7..bd640f6f8b5 100644 --- a/src/backend/access/nbtree/nbtutils.c +++ b/src/backend/access/nbtree/nbtutils.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.59 2004/08/29 04:12:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.60 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -48,8 +48,8 @@ _bt_mkscankey(Relation rel, IndexTuple itup) bool null; /* - * We can use the cached (default) support procs since no cross-type - * comparison can be needed. + * We can use the cached (default) support procs since no + * cross-type comparison can be needed. */ procinfo = index_getprocinfo(rel, i + 1, BTORDER_PROC); arg = index_getattr(itup, i + 1, itupdesc, &null); @@ -68,7 +68,7 @@ _bt_mkscankey(Relation rel, IndexTuple itup) /* * _bt_mkscankey_nodata * Build a scan key that contains comparator routines appropriate to - * the key datatypes, but no comparison data. The comparison data + * the key datatypes, but no comparison data. The comparison data * ultimately used must match the key datatypes. * * The result cannot be used with _bt_compare(). Currently this @@ -93,8 +93,8 @@ _bt_mkscankey_nodata(Relation rel) FmgrInfo *procinfo; /* - * We can use the cached (default) support procs since no cross-type - * comparison can be needed. + * We can use the cached (default) support procs since no + * cross-type comparison can be needed. */ procinfo = index_getprocinfo(rel, i + 1, BTORDER_PROC); ScanKeyEntryInitializeWithInfo(&skey[i], @@ -163,12 +163,12 @@ _bt_formitem(IndexTuple itup) * _bt_preprocess_keys() -- Preprocess scan keys * * The caller-supplied keys (in scan->keyData[]) are copied to - * so->keyData[] with possible transformation. scan->numberOfKeys is + * so->keyData[] with possible transformation. scan->numberOfKeys is * the number of input keys, so->numberOfKeys gets the number of output * keys (possibly less, never greater). * * The primary purpose of this routine is to discover how many scan keys - * must be satisfied to continue the scan. It also attempts to eliminate + * must be satisfied to continue the scan. It also attempts to eliminate * redundant keys and detect contradictory keys. At present, redundant and * contradictory keys can only be detected for same-data-type comparisons, * but that's the usual case so it seems worth doing. @@ -198,7 +198,7 @@ _bt_formitem(IndexTuple itup) * or one or two boundary-condition keys for each attr.) However, we can * only detect redundant keys when the right-hand datatypes are all equal * to the index datatype, because we do not know suitable operators for - * comparing right-hand values of two different datatypes. (In theory + * comparing right-hand values of two different datatypes. (In theory * we could handle comparison of a RHS of the index datatype with a RHS of * another type, but that seems too much pain for too little gain.) So, * keys whose operator has a nondefault subtype (ie, its RHS is not of the @@ -285,9 +285,9 @@ _bt_preprocess_keys(IndexScanDesc scan) * * xform[i] points to the currently best scan key of strategy type i+1, * if any is found with a default operator subtype; it is NULL if we - * haven't yet found such a key for this attr. Scan keys of nondefault - * subtypes are transferred to the output with no processing except for - * noting if they are of "=" type. + * haven't yet found such a key for this attr. Scan keys of + * nondefault subtypes are transferred to the output with no + * processing except for noting if they are of "=" type. */ attno = 1; memset(xform, 0, sizeof(xform)); @@ -361,7 +361,7 @@ _bt_preprocess_keys(IndexScanDesc scan) /* * If no "=" for this key, we're done with required keys */ - if (! hasOtherTypeEqual) + if (!hasOtherTypeEqual) allEqualSoFar = false; } @@ -369,8 +369,8 @@ _bt_preprocess_keys(IndexScanDesc scan) if (xform[BTLessStrategyNumber - 1] && xform[BTLessEqualStrategyNumber - 1]) { - ScanKey lt = xform[BTLessStrategyNumber - 1]; - ScanKey le = xform[BTLessEqualStrategyNumber - 1]; + ScanKey lt = xform[BTLessStrategyNumber - 1]; + ScanKey le = xform[BTLessEqualStrategyNumber - 1]; test = FunctionCall2(&le->sk_func, lt->sk_argument, @@ -385,8 +385,8 @@ _bt_preprocess_keys(IndexScanDesc scan) if (xform[BTGreaterStrategyNumber - 1] && xform[BTGreaterEqualStrategyNumber - 1]) { - ScanKey gt = xform[BTGreaterStrategyNumber - 1]; - ScanKey ge = xform[BTGreaterEqualStrategyNumber - 1]; + ScanKey gt = xform[BTGreaterStrategyNumber - 1]; + ScanKey ge = xform[BTGreaterEqualStrategyNumber - 1]; test = FunctionCall2(&ge->sk_func, gt->sk_argument, @@ -545,21 +545,23 @@ _bt_checkkeys(IndexScanDesc scan, IndexTuple tuple, { /* * Tuple fails this qual. If it's a required qual, then we - * may be able to conclude no further tuples will pass, either. - * We have to look at the scan direction and the qual type. + * may be able to conclude no further tuples will pass, + * either. We have to look at the scan direction and the qual + * type. * * Note: the only case in which we would keep going after failing - * a required qual is if there are partially-redundant quals that - * _bt_preprocess_keys() was unable to eliminate. For example, - * given "x > 4 AND x > 10" where both are cross-type comparisons - * and so not removable, we might start the scan at the x = 4 - * boundary point. The "x > 10" condition will fail until we - * pass x = 10, but we must not stop the scan on its account. + * a required qual is if there are partially-redundant quals + * that _bt_preprocess_keys() was unable to eliminate. For + * example, given "x > 4 AND x > 10" where both are cross-type + * comparisons and so not removable, we might start the scan + * at the x = 4 boundary point. The "x > 10" condition will + * fail until we pass x = 10, but we must not stop the scan on + * its account. * - * Note: because we stop the scan as soon as any required equality - * qual fails, it is critical that equality quals be used for the - * initial positioning in _bt_first() when they are available. - * See comments in _bt_first(). + * Note: because we stop the scan as soon as any required + * equality qual fails, it is critical that equality quals be + * used for the initial positioning in _bt_first() when they + * are available. See comments in _bt_first(). */ if (ikey < so->numberOfRequiredKeys) { diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c index edb1ff8d9bb..03f09e3fa2c 100644 --- a/src/backend/access/nbtree/nbtxlog.c +++ b/src/backend/access/nbtree/nbtxlog.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.17 2004/08/29 04:12:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.18 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -770,7 +770,7 @@ static void out_target(char *buf, xl_btreetid *target) { sprintf(buf + strlen(buf), "rel %u/%u/%u; tid %u/%u", - target->node.spcNode, target->node.dbNode, target->node.relNode, + target->node.spcNode, target->node.dbNode, target->node.relNode, ItemPointerGetBlockNumber(&(target->tid)), ItemPointerGetOffsetNumber(&(target->tid))); } diff --git a/src/backend/access/rtree/rtscan.c b/src/backend/access/rtree/rtscan.c index 1765cef28d7..4ec3a5da631 100644 --- a/src/backend/access/rtree/rtscan.c +++ b/src/backend/access/rtree/rtscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/rtree/rtscan.c,v 1.54 2004/08/29 04:12:22 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/rtree/rtscan.c,v 1.55 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -123,7 +123,7 @@ rtrescan(PG_FUNCTION_ARGS) Oid int_oper; RegProcedure int_proc; - opclass = s->indexRelation->rd_index->indclass[attno-1]; + opclass = s->indexRelation->rd_index->indclass[attno - 1]; int_strategy = RTMapToInternalOperator(s->keyData[i].sk_strategy); int_oper = get_opclass_member(opclass, s->keyData[i].sk_subtype, @@ -280,14 +280,14 @@ rtdropscan(IndexScanDesc s) void ReleaseResources_rtree(void) { - RTScanList l; - RTScanList prev; - RTScanList next; + RTScanList l; + RTScanList prev; + RTScanList next; /* - * Note: this should be a no-op during normal query shutdown. - * However, in an abort situation ExecutorEnd is not called and so - * there may be open index scans to clean up. + * Note: this should be a no-op during normal query shutdown. However, + * in an abort situation ExecutorEnd is not called and so there may be + * open index scans to clean up. */ prev = NULL; diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c index b26807f9afb..fb490e4137a 100644 --- a/src/backend/access/transam/clog.c +++ b/src/backend/access/transam/clog.c @@ -24,7 +24,7 @@ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.24 2004/08/29 04:12:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.25 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -62,6 +62,7 @@ * Link to shared-memory data structures for CLOG control */ static SlruCtlData ClogCtlData; + #define ClogCtl (&ClogCtlData) diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c index c695013ed17..c87b38a7922 100644 --- a/src/backend/access/transam/slru.c +++ b/src/backend/access/transam/slru.c @@ -48,7 +48,7 @@ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.20 2004/08/29 04:12:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.21 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -79,7 +79,7 @@ * segment and page numbers in SimpleLruTruncate (see PagePrecedes()). * * Note: this file currently assumes that segment file names will be four - * hex digits. This sets a lower bound on the segment size (64K transactions + * hex digits. This sets a lower bound on the segment size (64K transactions * for 32-bit TransactionIds). */ #define SLRU_PAGES_PER_SEGMENT 32 @@ -96,9 +96,9 @@ */ typedef struct SlruFlushData { - int num_files; /* # files actually open */ - int fd[NUM_SLRU_BUFFERS]; /* their FD's */ - int segno[NUM_SLRU_BUFFERS]; /* their log seg#s */ + int num_files; /* # files actually open */ + int fd[NUM_SLRU_BUFFERS]; /* their FD's */ + int segno[NUM_SLRU_BUFFERS]; /* their log seg#s */ } SlruFlushData; /* @@ -132,7 +132,7 @@ static int slru_errno; static bool SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno); static bool SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, - SlruFlush fdata); + SlruFlush fdata); static void SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid); static int SlruSelectLRUPage(SlruCtl ctl, int pageno); @@ -385,7 +385,7 @@ SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata) /* If we failed, and we're in a flush, better close the files */ if (!ok && fdata) { - int i; + int i; for (i = 0; i < fdata->num_files; i++) close(fdata->fd[i]); @@ -511,7 +511,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata) */ if (fdata) { - int i; + int i; for (i = 0; i < fdata->num_files; i++) { @@ -527,16 +527,17 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata) { /* * If the file doesn't already exist, we should create it. It is - * possible for this to need to happen when writing a page that's not - * first in its segment; we assume the OS can cope with that. - * (Note: it might seem that it'd be okay to create files only when - * SimpleLruZeroPage is called for the first page of a segment. - * However, if after a crash and restart the REDO logic elects to - * replay the log from a checkpoint before the latest one, then it's - * possible that we will get commands to set transaction status of - * transactions that have already been truncated from the commit log. - * Easiest way to deal with that is to accept references to - * nonexistent files here and in SlruPhysicalReadPage.) + * possible for this to need to happen when writing a page that's + * not first in its segment; we assume the OS can cope with that. + * (Note: it might seem that it'd be okay to create files only + * when SimpleLruZeroPage is called for the first page of a + * segment. However, if after a crash and restart the REDO logic + * elects to replay the log from a checkpoint before the latest + * one, then it's possible that we will get commands to set + * transaction status of transactions that have already been + * truncated from the commit log. Easiest way to deal with that is + * to accept references to nonexistent files here and in + * SlruPhysicalReadPage.) */ SlruFileName(ctl, path, segno); fd = BasicOpenFile(path, O_RDWR | PG_BINARY, S_IRUSR | S_IWUSR); @@ -648,36 +649,36 @@ SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid) ereport(ERROR, (errcode_for_file_access(), errmsg("could not access status of transaction %u", xid), - errdetail("could not seek in file \"%s\" to offset %u: %m", - path, offset))); + errdetail("could not seek in file \"%s\" to offset %u: %m", + path, offset))); break; case SLRU_READ_FAILED: ereport(ERROR, (errcode_for_file_access(), errmsg("could not access status of transaction %u", xid), - errdetail("could not read from file \"%s\" at offset %u: %m", - path, offset))); + errdetail("could not read from file \"%s\" at offset %u: %m", + path, offset))); break; case SLRU_WRITE_FAILED: ereport(ERROR, (errcode_for_file_access(), errmsg("could not access status of transaction %u", xid), - errdetail("could not write to file \"%s\" at offset %u: %m", - path, offset))); + errdetail("could not write to file \"%s\" at offset %u: %m", + path, offset))); break; case SLRU_FSYNC_FAILED: ereport(ERROR, (errcode_for_file_access(), errmsg("could not access status of transaction %u", xid), - errdetail("could not fsync file \"%s\": %m", - path))); + errdetail("could not fsync file \"%s\": %m", + path))); break; case SLRU_CLOSE_FAILED: ereport(ERROR, (errcode_for_file_access(), errmsg("could not access status of transaction %u", xid), - errdetail("could not close file \"%s\": %m", - path))); + errdetail("could not close file \"%s\": %m", + path))); break; default: /* can't get here, we trust */ @@ -841,8 +842,8 @@ SimpleLruTruncate(SlruCtl ctl, int cutoffPage) /* * Scan shared memory and remove any pages preceding the cutoff page, * to ensure we won't rewrite them later. (Since this is normally - * called in or just after a checkpoint, any dirty pages should - * have been flushed already ... we're just being extra careful here.) + * called in or just after a checkpoint, any dirty pages should have + * been flushed already ... we're just being extra careful here.) */ LWLockAcquire(shared->ControlLock, LW_EXCLUSIVE); @@ -952,8 +953,11 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions) errno = 0; } #ifdef WIN32 - /* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but - not in released version */ + + /* + * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but + * not in released version + */ if (GetLastError() == ERROR_NO_MORE_FILES) errno = 0; #endif diff --git a/src/backend/access/transam/subtrans.c b/src/backend/access/transam/subtrans.c index 7976de2300c..93a586148be 100644 --- a/src/backend/access/transam/subtrans.c +++ b/src/backend/access/transam/subtrans.c @@ -5,7 +5,7 @@ * * The pg_subtrans manager is a pg_clog-like manager that stores the parent * transaction Id for each transaction. It is a fundamental part of the - * nested transactions implementation. A main transaction has a parent + * nested transactions implementation. A main transaction has a parent * of InvalidTransactionId, and each subtransaction has its immediate parent. * The tree can easily be walked from child to parent, but not in the * opposite direction. @@ -22,7 +22,7 @@ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.4 2004/08/29 04:12:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.5 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -57,6 +57,7 @@ * Link to shared-memory data structures for SUBTRANS control */ static SlruCtlData SubTransCtlData; + #define SubTransCtl (&SubTransCtlData) @@ -101,7 +102,7 @@ SubTransGetParent(TransactionId xid) int entryno = TransactionIdToEntry(xid); int slotno; TransactionId *ptr; - TransactionId parent; + TransactionId parent; /* Can't ask about stuff that might not be around anymore */ Assert(TransactionIdFollowsOrEquals(xid, RecentXmin)); @@ -139,7 +140,7 @@ TransactionId SubTransGetTopmostTransaction(TransactionId xid) { TransactionId parentXid = xid, - previousXid = xid; + previousXid = xid; /* Can't ask about stuff that might not be around anymore */ Assert(TransactionIdFollowsOrEquals(xid, RecentXmin)); @@ -185,7 +186,7 @@ SUBTRANSShmemInit(void) * must have been called already.) * * Note: it's not really necessary to create the initial segment now, - * since slru.c would create it on first write anyway. But we may as well + * since slru.c would create it on first write anyway. But we may as well * do it to be sure the directory is set up correctly. */ void @@ -229,10 +230,11 @@ StartupSUBTRANS(void) int startPage; /* - * Since we don't expect pg_subtrans to be valid across crashes, - * we initialize the currently-active page to zeroes during startup. + * Since we don't expect pg_subtrans to be valid across crashes, we + * initialize the currently-active page to zeroes during startup. * Whenever we advance into a new page, ExtendSUBTRANS will likewise - * zero the new page without regard to whatever was previously on disk. + * zero the new page without regard to whatever was previously on + * disk. */ LWLockAcquire(SubtransControlLock, LW_EXCLUSIVE); @@ -251,8 +253,8 @@ ShutdownSUBTRANS(void) /* * Flush dirty SUBTRANS pages to disk * - * This is not actually necessary from a correctness point of view. - * We do it merely as a debugging aid. + * This is not actually necessary from a correctness point of view. We do + * it merely as a debugging aid. */ SimpleLruFlush(SubTransCtl, false); } @@ -266,8 +268,8 @@ CheckPointSUBTRANS(void) /* * Flush dirty SUBTRANS pages to disk * - * This is not actually necessary from a correctness point of view. - * We do it merely to improve the odds that writing of dirty pages is done + * This is not actually necessary from a correctness point of view. We do + * it merely to improve the odds that writing of dirty pages is done * by the checkpoint process and not by backends. */ SimpleLruFlush(SubTransCtl, true); diff --git a/src/backend/access/transam/transam.c b/src/backend/access/transam/transam.c index fd5a1619a77..f82168be5b7 100644 --- a/src/backend/access/transam/transam.c +++ b/src/backend/access/transam/transam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/transam.c,v 1.60 2004/08/29 04:12:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/transam.c,v 1.61 2004/08/29 05:06:40 momjian Exp $ * * NOTES * This file contains the high level access-method interface to the @@ -126,7 +126,7 @@ TransactionLogUpdate(TransactionId transactionId, /* trans id to update */ static void TransactionLogMultiUpdate(int nxids, TransactionId *xids, XidStatus status) { - int i; + int i; Assert(nxids != 0); @@ -199,9 +199,10 @@ TransactionIdDidCommit(TransactionId transactionId) return true; /* - * If it's marked subcommitted, we have to check the parent recursively. - * However, if it's older than RecentXmin, we can't look at pg_subtrans; - * instead assume that the parent crashed without cleaning up its children. + * If it's marked subcommitted, we have to check the parent + * recursively. However, if it's older than RecentXmin, we can't look + * at pg_subtrans; instead assume that the parent crashed without + * cleaning up its children. */ if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED) { @@ -214,7 +215,7 @@ TransactionIdDidCommit(TransactionId transactionId) return TransactionIdDidCommit(parentXid); } - /* + /* * It's not committed. */ return false; @@ -247,9 +248,10 @@ TransactionIdDidAbort(TransactionId transactionId) return true; /* - * If it's marked subcommitted, we have to check the parent recursively. - * However, if it's older than RecentXmin, we can't look at pg_subtrans; - * instead assume that the parent crashed without cleaning up its children. + * If it's marked subcommitted, we have to check the parent + * recursively. However, if it's older than RecentXmin, we can't look + * at pg_subtrans; instead assume that the parent crashed without + * cleaning up its children. */ if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED) { diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index cfd78937428..84926ac415a 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -6,7 +6,7 @@ * Copyright (c) 2000-2004, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/varsup.c,v 1.58 2004/08/29 04:12:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/varsup.c,v 1.59 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,9 +47,9 @@ GetNewTransactionId(bool isSubXact) xid = ShmemVariableCache->nextXid; /* - * If we are allocating the first XID of a new page of the commit - * log, zero out that commit-log page before returning. We must do - * this while holding XidGenLock, else another xact could acquire and + * If we are allocating the first XID of a new page of the commit log, + * zero out that commit-log page before returning. We must do this + * while holding XidGenLock, else another xact could acquire and * commit a later XID before we zero the page. Fortunately, a page of * the commit log holds 32K or more transactions, so we don't have to * do this very often. @@ -61,17 +61,18 @@ GetNewTransactionId(bool isSubXact) /* * Now advance the nextXid counter. This must not happen until after - * we have successfully completed ExtendCLOG() --- if that routine fails, - * we want the next incoming transaction to try it again. We cannot - * assign more XIDs until there is CLOG space for them. + * we have successfully completed ExtendCLOG() --- if that routine + * fails, we want the next incoming transaction to try it again. We + * cannot assign more XIDs until there is CLOG space for them. */ TransactionIdAdvance(ShmemVariableCache->nextXid); /* - * We must store the new XID into the shared PGPROC array before releasing - * XidGenLock. This ensures that when GetSnapshotData calls + * We must store the new XID into the shared PGPROC array before + * releasing XidGenLock. This ensures that when GetSnapshotData calls * ReadNewTransactionId, all active XIDs before the returned value of - * nextXid are already present in PGPROC. Else we have a race condition. + * nextXid are already present in PGPROC. Else we have a race + * condition. * * XXX by storing xid into MyProc without acquiring SInvalLock, we are * relying on fetch/store of an xid to be atomic, else other backends @@ -86,19 +87,19 @@ GetNewTransactionId(bool isSubXact) * * A solution to the atomic-store problem would be to give each PGPROC * its own spinlock used only for fetching/storing that PGPROC's xid - * and related fields. (SInvalLock would then mean primarily that + * and related fields. (SInvalLock would then mean primarily that * PGPROCs couldn't be added/removed while holding the lock.) * * If there's no room to fit a subtransaction XID into PGPROC, set the * cache-overflowed flag instead. This forces readers to look in - * pg_subtrans to map subtransaction XIDs up to top-level XIDs. - * There is a race-condition window, in that the new XID will not - * appear as running until its parent link has been placed into - * pg_subtrans. However, that will happen before anyone could possibly - * have a reason to inquire about the status of the XID, so it seems - * OK. (Snapshots taken during this window *will* include the parent - * XID, so they will deliver the correct answer later on when someone - * does have a reason to inquire.) + * pg_subtrans to map subtransaction XIDs up to top-level XIDs. There + * is a race-condition window, in that the new XID will not appear as + * running until its parent link has been placed into pg_subtrans. + * However, that will happen before anyone could possibly have a + * reason to inquire about the status of the XID, so it seems OK. + * (Snapshots taken during this window *will* include the parent XID, + * so they will deliver the correct answer later on when someone does + * have a reason to inquire.) */ if (MyProc != NULL) { @@ -112,9 +113,7 @@ GetNewTransactionId(bool isSubXact) MyProc->subxids.nxids++; } else - { MyProc->subxids.overflowed = true; - } } } diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index fd5d6b51682..3bb38e4227f 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.182 2004/08/29 04:12:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.183 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -89,19 +89,20 @@ typedef enum TBlockState */ typedef struct TransactionStateData { - TransactionId transactionIdData; /* my XID */ - char *name; /* savepoint name, if any */ - int savepointLevel; /* savepoint level */ - CommandId commandId; /* current CID */ - TransState state; /* low-level state */ - TBlockState blockState; /* high-level state */ - int nestingLevel; /* nest depth */ - MemoryContext curTransactionContext; /* my xact-lifetime context */ - ResourceOwner curTransactionOwner; /* my query resources */ - List *childXids; /* subcommitted child XIDs */ - AclId currentUser; /* subxact start current_user */ - bool prevXactReadOnly; /* entry-time xact r/o state */ - struct TransactionStateData *parent; /* back link to parent */ + TransactionId transactionIdData; /* my XID */ + char *name; /* savepoint name, if any */ + int savepointLevel; /* savepoint level */ + CommandId commandId; /* current CID */ + TransState state; /* low-level state */ + TBlockState blockState; /* high-level state */ + int nestingLevel; /* nest depth */ + MemoryContext curTransactionContext; /* my xact-lifetime + * context */ + ResourceOwner curTransactionOwner; /* my query resources */ + List *childXids; /* subcommitted child XIDs */ + AclId currentUser; /* subxact start current_user */ + bool prevXactReadOnly; /* entry-time xact r/o state */ + struct TransactionStateData *parent; /* back link to parent */ } TransactionStateData; typedef TransactionStateData *TransactionState; @@ -180,8 +181,8 @@ static TransactionState CurrentTransactionState = &TopTransactionStateData; * This does not change as we enter and exit subtransactions, so we don't * keep it inside the TransactionState stack. */ -static AbsoluteTime xactStartTime; /* integer part */ -static int xactStartTimeUsec; /* microsecond part */ +static AbsoluteTime xactStartTime; /* integer part */ +static int xactStartTimeUsec; /* microsecond part */ /* @@ -261,7 +262,7 @@ IsAbortedTransactionBlockState(void) { TransactionState s = CurrentTransactionState; - if (s->blockState == TBLOCK_ABORT || + if (s->blockState == TBLOCK_ABORT || s->blockState == TBLOCK_SUBABORT) return true; @@ -362,15 +363,15 @@ TransactionIdIsCurrentTransactionId(TransactionId xid) } /* - * We will return true for the Xid of the current subtransaction, - * any of its subcommitted children, any of its parents, or any of - * their previously subcommitted children. However, a transaction - * being aborted is no longer "current", even though it may still - * have an entry on the state stack. + * We will return true for the Xid of the current subtransaction, any + * of its subcommitted children, any of its parents, or any of their + * previously subcommitted children. However, a transaction being + * aborted is no longer "current", even though it may still have an + * entry on the state stack. */ for (s = CurrentTransactionState; s != NULL; s = s->parent) { - ListCell *cell; + ListCell *cell; if (s->state == TRANS_ABORT) continue; @@ -502,15 +503,16 @@ AtSubStart_Memory(void) Assert(CurTransactionContext != NULL); /* - * Create a CurTransactionContext, which will be used to hold data that - * survives subtransaction commit but disappears on subtransaction abort. - * We make it a child of the immediate parent's CurTransactionContext. + * Create a CurTransactionContext, which will be used to hold data + * that survives subtransaction commit but disappears on + * subtransaction abort. We make it a child of the immediate parent's + * CurTransactionContext. */ CurTransactionContext = AllocSetContextCreate(CurTransactionContext, "CurTransactionContext", - ALLOCSET_DEFAULT_MINSIZE, - ALLOCSET_DEFAULT_INITSIZE, - ALLOCSET_DEFAULT_MAXSIZE); + ALLOCSET_DEFAULT_MINSIZE, + ALLOCSET_DEFAULT_INITSIZE, + ALLOCSET_DEFAULT_MAXSIZE); s->curTransactionContext = CurTransactionContext; /* Make the CurTransactionContext active. */ @@ -528,8 +530,8 @@ AtSubStart_ResourceOwner(void) Assert(s->parent != NULL); /* - * Create a resource owner for the subtransaction. We make it a - * child of the immediate parent's resource owner. + * Create a resource owner for the subtransaction. We make it a child + * of the immediate parent's resource owner. */ s->curTransactionOwner = ResourceOwnerCreate(s->parent->curTransactionOwner, @@ -560,10 +562,11 @@ RecordTransactionCommit(void) nchildren = xactGetCommittedChildren(&children); /* - * If we made neither any XLOG entries nor any temp-rel updates, - * and have no files to be deleted, we can omit recording the transaction + * If we made neither any XLOG entries nor any temp-rel updates, and + * have no files to be deleted, we can omit recording the transaction * commit at all. (This test includes the effects of subtransactions, - * so the presence of committed subxacts need not alone force a write.) + * so the presence of committed subxacts need not alone force a + * write.) */ if (MyXactMadeXLogEntry || MyXactMadeTempRelUpdate || nrels > 0) { @@ -577,17 +580,18 @@ RecordTransactionCommit(void) START_CRIT_SECTION(); /* - * If our transaction made any transaction-controlled XLOG entries, - * we need to lock out checkpoint start between writing our XLOG - * record and updating pg_clog. Otherwise it is possible for the - * checkpoint to set REDO after the XLOG record but fail to flush the - * pg_clog update to disk, leading to loss of the transaction commit - * if we crash a little later. Slightly klugy fix for problem - * discovered 2004-08-10. + * If our transaction made any transaction-controlled XLOG + * entries, we need to lock out checkpoint start between writing + * our XLOG record and updating pg_clog. Otherwise it is possible + * for the checkpoint to set REDO after the XLOG record but fail + * to flush the pg_clog update to disk, leading to loss of the + * transaction commit if we crash a little later. Slightly klugy + * fix for problem discovered 2004-08-10. * * (If it made no transaction-controlled XLOG entries, its XID - * appears nowhere in permanent storage, so no one else will ever care - * if it committed; so it doesn't matter if we lose the commit flag.) + * appears nowhere in permanent storage, so no one else will ever + * care if it committed; so it doesn't matter if we lose the + * commit flag.) * * Note we only need a shared lock. */ @@ -798,21 +802,21 @@ static void RecordSubTransactionCommit(void) { /* - * We do not log the subcommit in XLOG; it doesn't matter until - * the top-level transaction commits. + * We do not log the subcommit in XLOG; it doesn't matter until the + * top-level transaction commits. * * We must mark the subtransaction subcommitted in clog if its XID * appears either in permanent rels or in local temporary rels. We - * test this by seeing if we made transaction-controlled entries - * *OR* local-rel tuple updates. (The test here actually covers the - * entire transaction tree so far, so it may mark subtransactions that - * don't really need it, but it's probably not worth being tenser. - * Note that if a prior subtransaction dirtied these variables, then + * test this by seeing if we made transaction-controlled entries *OR* + * local-rel tuple updates. (The test here actually covers the entire + * transaction tree so far, so it may mark subtransactions that don't + * really need it, but it's probably not worth being tenser. Note that + * if a prior subtransaction dirtied these variables, then * RecordTransactionCommit will have to do the full pushup anyway...) */ if (MyLastRecPtr.xrecoff != 0 || MyXactMadeTempRelUpdate) { - TransactionId xid = GetCurrentTransactionId(); + TransactionId xid = GetCurrentTransactionId(); /* XXX does this really need to be a critical section? */ START_CRIT_SECTION(); @@ -837,8 +841,8 @@ RecordTransactionAbort(void) { int nrels; RelFileNode *rptr; - int nchildren; - TransactionId *children; + int nchildren; + TransactionId *children; /* Get data needed for abort record */ nrels = smgrGetPendingDeletes(false, &rptr); @@ -846,13 +850,13 @@ RecordTransactionAbort(void) /* * If we made neither any transaction-controlled XLOG entries nor any - * temp-rel updates, and are not going to delete any files, we can omit - * recording the transaction abort at all. No one will ever care that - * it aborted. (These tests cover our whole transaction tree.) + * temp-rel updates, and are not going to delete any files, we can + * omit recording the transaction abort at all. No one will ever care + * that it aborted. (These tests cover our whole transaction tree.) */ if (MyLastRecPtr.xrecoff != 0 || MyXactMadeTempRelUpdate || nrels > 0) { - TransactionId xid = GetCurrentTransactionId(); + TransactionId xid = GetCurrentTransactionId(); /* * Catch the scenario where we aborted partway through @@ -867,13 +871,13 @@ RecordTransactionAbort(void) * We only need to log the abort in XLOG if the transaction made * any transaction-controlled XLOG entries or will delete files. * (If it made no transaction-controlled XLOG entries, its XID - * appears nowhere in permanent storage, so no one else will ever care - * if it committed.) + * appears nowhere in permanent storage, so no one else will ever + * care if it committed.) * * We do not flush XLOG to disk unless deleting files, since the - * default assumption after a crash would be that we aborted, anyway. - * For the same reason, we don't need to worry about interlocking - * against checkpoint start. + * default assumption after a crash would be that we aborted, + * anyway. For the same reason, we don't need to worry about + * interlocking against checkpoint start. */ if (MyLastRecPtr.xrecoff != 0 || nrels > 0) { @@ -990,9 +994,9 @@ RecordSubTransactionAbort(void) { int nrels; RelFileNode *rptr; - TransactionId xid = GetCurrentTransactionId(); - int nchildren; - TransactionId *children; + TransactionId xid = GetCurrentTransactionId(); + int nchildren; + TransactionId *children; /* Get data needed for abort record */ nrels = smgrGetPendingDeletes(false, &rptr); @@ -1000,10 +1004,10 @@ RecordSubTransactionAbort(void) /* * If we made neither any transaction-controlled XLOG entries nor any - * temp-rel updates, and are not going to delete any files, we can omit - * recording the transaction abort at all. No one will ever care that - * it aborted. (These tests cover our whole transaction tree, and - * therefore may mark subxacts that don't really need it, but it's + * temp-rel updates, and are not going to delete any files, we can + * omit recording the transaction abort at all. No one will ever care + * that it aborted. (These tests cover our whole transaction tree, + * and therefore may mark subxacts that don't really need it, but it's * probably not worth being tenser.) * * In this case we needn't worry about marking subcommitted children as @@ -1021,9 +1025,9 @@ RecordSubTransactionAbort(void) if (MyLastRecPtr.xrecoff != 0 || nrels > 0) { XLogRecData rdata[3]; - int lastrdata = 0; + int lastrdata = 0; xl_xact_abort xlrec; - XLogRecPtr recptr; + XLogRecPtr recptr; xlrec.xtime = time(NULL); xlrec.nrels = nrels; @@ -1071,8 +1075,8 @@ RecordSubTransactionAbort(void) /* * We can immediately remove failed XIDs from PGPROC's cache of * running child XIDs. It's easiest to do it here while we have the - * child XID array at hand, even though in the main-transaction - * case the equivalent work happens just after return from + * child XID array at hand, even though in the main-transaction case + * the equivalent work happens just after return from * RecordTransactionAbort. */ XidCacheRemoveRunningXids(xid, nchildren, children); @@ -1169,7 +1173,8 @@ StartTransaction(void) s->state = TRANS_START; /* - * Make sure we've freed any old snapshot, and reset xact state variables + * Make sure we've freed any old snapshot, and reset xact state + * variables */ FreeXactSnapshot(); XactIsoLevel = DefaultXactIsoLevel; @@ -1323,9 +1328,9 @@ CommitTransaction(void) * want to release locks at the point where any backend waiting for us * will see our transaction as being fully cleaned up. * - * Resources that can be associated with individual queries are - * handled by the ResourceOwner mechanism. The other calls here - * are for backend-wide state. + * Resources that can be associated with individual queries are handled + * by the ResourceOwner mechanism. The other calls here are for + * backend-wide state. */ smgrDoPendingDeletes(true); @@ -1342,7 +1347,8 @@ CommitTransaction(void) * after relcache references are dropped (see comments for * AtEOXact_RelationCache), but before locks are released (if anyone * is waiting for lock on a relation we've modified, we want them to - * know about the catalog change before they start using the relation). + * know about the catalog change before they start using the + * relation). */ AtEOXact_Inval(true); @@ -1428,11 +1434,12 @@ AbortTransaction(void) /* * Reset user id which might have been changed transiently. We cannot - * use s->currentUser, but must get the session userid from miscinit.c. + * use s->currentUser, but must get the session userid from + * miscinit.c. * * (Note: it is not necessary to restore session authorization here * because that can only be changed via GUC, and GUC will take care of - * rolling it back if need be. However, an error within a SECURITY + * rolling it back if need be. However, an error within a SECURITY * DEFINER function could send control here with the wrong current * userid.) */ @@ -1443,7 +1450,7 @@ AbortTransaction(void) */ DeferredTriggerAbortXact(); AtAbort_Portals(); - AtEOXact_LargeObject(false); /* 'false' means it's abort */ + AtEOXact_LargeObject(false); /* 'false' means it's abort */ AtAbort_Notify(); AtEOXact_UpdatePasswordFile(false); @@ -1523,7 +1530,7 @@ CleanupTransaction(void) */ AtCleanup_Portals(); /* now safe to release portal memory */ - CurrentResourceOwner = NULL; /* and resource owner */ + CurrentResourceOwner = NULL; /* and resource owner */ ResourceOwnerDelete(TopTransactionResourceOwner); s->curTransactionOwner = NULL; CurTransactionResourceOwner = NULL; @@ -1561,9 +1568,10 @@ StartTransactionCommand(void) break; /* - * This is the case when we are somewhere in a transaction block - * and about to start a new command. For now we do nothing - * but someday we may do command-local resource initialization. + * This is the case when we are somewhere in a transaction + * block and about to start a new command. For now we do + * nothing but someday we may do command-local resource + * initialization. */ case TBLOCK_INPROGRESS: case TBLOCK_SUBINPROGRESS: @@ -1616,8 +1624,8 @@ CommitTransactionCommand(void) /* * This shouldn't happen, because it means the previous * StartTransactionCommand didn't set the STARTED state - * appropriately, or we didn't manage previous pending - * abort states. + * appropriately, or we didn't manage previous pending abort + * states. */ case TBLOCK_DEFAULT: case TBLOCK_SUBABORT_PENDING: @@ -1689,19 +1697,21 @@ CommitTransactionCommand(void) break; /* - * Ditto, but in a subtransaction. AbortOutOfAnyTransaction + * Ditto, but in a subtransaction. AbortOutOfAnyTransaction * will do the dirty work. */ case TBLOCK_SUBENDABORT_ALL: AbortOutOfAnyTransaction(); - s = CurrentTransactionState; /* changed by AbortOutOfAnyTransaction */ + s = CurrentTransactionState; /* changed by + * AbortOutOfAnyTransaction + * */ /* AbortOutOfAnyTransaction sets the blockState */ break; /* * We were just issued a SAVEPOINT inside a transaction block. - * Start a subtransaction. (DefineSavepoint already - * did PushTransaction, so as to have someplace to put the + * Start a subtransaction. (DefineSavepoint already did + * PushTransaction, so as to have someplace to put the * SUBBEGIN state.) */ case TBLOCK_SUBBEGIN: @@ -1720,14 +1730,15 @@ CommitTransactionCommand(void) * We were issued a RELEASE command, so we end the current * subtransaction and return to the parent transaction. * - * Since RELEASE can exit multiple levels of subtransaction, - * we must loop here until we get out of all SUBEND'ed levels. + * Since RELEASE can exit multiple levels of subtransaction, we + * must loop here until we get out of all SUBEND'ed levels. */ case TBLOCK_SUBEND: - do { + do + { CommitSubTransaction(); PopTransaction(); - s = CurrentTransactionState; /* changed by pop */ + s = CurrentTransactionState; /* changed by pop */ } while (s->blockState == TBLOCK_SUBEND); break; @@ -1738,25 +1749,26 @@ CommitTransactionCommand(void) break; /* - * The current subtransaction is ending. Do the equivalent - * of a ROLLBACK TO followed by a RELEASE command. + * The current subtransaction is ending. Do the equivalent of + * a ROLLBACK TO followed by a RELEASE command. */ case TBLOCK_SUBENDABORT_RELEASE: CleanupAbortedSubTransactions(false); break; /* - * The current subtransaction is ending due to a ROLLBACK - * TO command, so close all savepoints up to the target - * level. When finished, recreate the savepoint. + * The current subtransaction is ending due to a ROLLBACK TO + * command, so close all savepoints up to the target level. + * When finished, recreate the savepoint. */ case TBLOCK_SUBENDABORT: { - char *name = CleanupAbortedSubTransactions(true); + char *name = CleanupAbortedSubTransactions(true); Assert(PointerIsValid(name)); DefineSavepoint(name); - s = CurrentTransactionState; /* changed by DefineSavepoint */ + s = CurrentTransactionState; /* changed by + * DefineSavepoint */ pfree(name); /* This is the same as TBLOCK_SUBBEGIN case */ @@ -1780,8 +1792,8 @@ static char * CleanupAbortedSubTransactions(bool returnName) { TransactionState s = CurrentTransactionState; - char *name = NULL; - + char *name = NULL; + AssertState(PointerIsValid(s->parent)); Assert(s->parent->blockState == TBLOCK_SUBINPROGRESS || s->parent->blockState == TBLOCK_INPROGRESS || @@ -1798,7 +1810,7 @@ CleanupAbortedSubTransactions(bool returnName) CleanupSubTransaction(); PopTransaction(); - s = CurrentTransactionState; /* changed by pop */ + s = CurrentTransactionState; /* changed by pop */ while (s->blockState == TBLOCK_SUBABORT_PENDING) { @@ -1827,9 +1839,9 @@ AbortCurrentTransaction(void) switch (s->blockState) { - /* - * we aren't in a transaction, so we do nothing. - */ + /* + * we aren't in a transaction, so we do nothing. + */ case TBLOCK_DEFAULT: break; @@ -1856,10 +1868,10 @@ AbortCurrentTransaction(void) break; /* - * This is the case when we are somewhere in a transaction block - * and we've gotten a failure, so we abort the transaction and - * set up the persistent ABORT state. We will stay in ABORT - * until we get an "END TRANSACTION". + * This is the case when we are somewhere in a transaction + * block and we've gotten a failure, so we abort the + * transaction and set up the persistent ABORT state. We will + * stay in ABORT until we get an "END TRANSACTION". */ case TBLOCK_INPROGRESS: AbortTransaction(); @@ -1900,8 +1912,8 @@ AbortCurrentTransaction(void) break; /* - * If we are just starting a subtransaction, put it - * in aborted state. + * If we are just starting a subtransaction, put it in aborted + * state. */ case TBLOCK_SUBBEGIN: StartAbortedSubTransaction(); @@ -1914,8 +1926,8 @@ AbortCurrentTransaction(void) break; /* - * If we are aborting an ending transaction, - * we have to abort the parent transaction too. + * If we are aborting an ending transaction, we have to abort + * the parent transaction too. */ case TBLOCK_SUBEND: case TBLOCK_SUBABORT_PENDING: @@ -1924,7 +1936,7 @@ AbortCurrentTransaction(void) PopTransaction(); s = CurrentTransactionState; /* changed by pop */ Assert(s->blockState != TBLOCK_SUBEND && - s->blockState != TBLOCK_SUBENDABORT); + s->blockState != TBLOCK_SUBENDABORT); AbortCurrentTransaction(); break; @@ -1937,13 +1949,13 @@ AbortCurrentTransaction(void) PopTransaction(); s = CurrentTransactionState; /* changed by pop */ Assert(s->blockState != TBLOCK_SUBEND && - s->blockState != TBLOCK_SUBENDABORT); + s->blockState != TBLOCK_SUBENDABORT); AbortCurrentTransaction(); break; /* - * We are already aborting the whole transaction tree. - * Do nothing, CommitTransactionCommand will call + * We are already aborting the whole transaction tree. Do + * nothing, CommitTransactionCommand will call * AbortOutOfAnyTransaction and set things straight. */ case TBLOCK_SUBENDABORT_ALL: @@ -2068,8 +2080,8 @@ bool IsInTransactionChain(void *stmtNode) { /* - * Return true on same conditions that would make PreventTransactionChain - * error out + * Return true on same conditions that would make + * PreventTransactionChain error out */ if (IsTransactionBlock()) return true; @@ -2097,8 +2109,8 @@ IsInTransactionChain(void *stmtNode) * (mainly because it's easier to control the order that way, where needed). * * At transaction end, the callback occurs post-commit or post-abort, so the - * callback functions can only do noncritical cleanup. At subtransaction - * start, the callback is called when the subtransaction has finished + * callback functions can only do noncritical cleanup. At subtransaction + * start, the callback is called when the subtransaction has finished * initializing. */ void @@ -2141,9 +2153,7 @@ CallXactCallbacks(XactEvent event, TransactionId parentXid) XactCallbackItem *item; for (item = Xact_callbacks; item; item = item->next) - { (*item->callback) (event, parentXid, item->arg); - } } @@ -2164,8 +2174,8 @@ BeginTransactionBlock(void) switch (s->blockState) { /* - * We are not inside a transaction block, so allow one - * to begin. + * We are not inside a transaction block, so allow one to + * begin. */ case TBLOCK_STARTED: s->blockState = TBLOCK_BEGIN; @@ -2180,7 +2190,7 @@ BeginTransactionBlock(void) case TBLOCK_SUBABORT: ereport(WARNING, (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), - errmsg("there is already a transaction in progress"))); + errmsg("there is already a transaction in progress"))); break; /* These cases are invalid. Reject them altogether. */ @@ -2215,12 +2225,13 @@ EndTransactionBlock(void) switch (s->blockState) { - /* - * We are in a transaction block which should commit when we - * get to the upcoming CommitTransactionCommand() so we set the - * state to "END". CommitTransactionCommand() will recognize this - * and commit the transaction and return us to the default state. - */ + /* + * We are in a transaction block which should commit when we + * get to the upcoming CommitTransactionCommand() so we set + * the state to "END". CommitTransactionCommand() will + * recognize this and commit the transaction and return us to + * the default state. + */ case TBLOCK_INPROGRESS: case TBLOCK_SUBINPROGRESS: s->blockState = TBLOCK_END; @@ -2229,30 +2240,31 @@ EndTransactionBlock(void) /* * We are in a transaction block which aborted. Since the - * AbortTransaction() was already done, we need only - * change to the special "END ABORT" state. The upcoming - * CommitTransactionCommand() will recognise this and then put us - * back in the default state. + * AbortTransaction() was already done, we need only change to + * the special "END ABORT" state. The upcoming + * CommitTransactionCommand() will recognise this and then put + * us back in the default state. */ case TBLOCK_ABORT: s->blockState = TBLOCK_ENDABORT; break; /* - * Here we are inside an aborted subtransaction. Go to the "abort - * the whole tree" state so that CommitTransactionCommand() calls - * AbortOutOfAnyTransaction. + * Here we are inside an aborted subtransaction. Go to the + * "abort the whole tree" state so that + * CommitTransactionCommand() calls AbortOutOfAnyTransaction. */ case TBLOCK_SUBABORT: s->blockState = TBLOCK_SUBENDABORT_ALL; break; case TBLOCK_STARTED: + /* - * here, the user issued COMMIT when not inside a - * transaction. Issue a WARNING and go to abort state. The - * upcoming call to CommitTransactionCommand() will then put us - * back into the default state. + * here, the user issued COMMIT when not inside a transaction. + * Issue a WARNING and go to abort state. The upcoming call + * to CommitTransactionCommand() will then put us back into + * the default state. */ ereport(WARNING, (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), @@ -2303,11 +2315,10 @@ UserAbortTransactionBlock(void) break; /* - * We are inside a failed subtransaction and we got an - * abort command from the user. Abort processing is already - * done, so go to the "abort all" state and - * CommitTransactionCommand will call AbortOutOfAnyTransaction - * to set things straight. + * We are inside a failed subtransaction and we got an abort + * command from the user. Abort processing is already done, + * so go to the "abort all" state and CommitTransactionCommand + * will call AbortOutOfAnyTransaction to set things straight. */ case TBLOCK_SUBABORT: s->blockState = TBLOCK_SUBENDABORT_ALL; @@ -2325,7 +2336,7 @@ UserAbortTransactionBlock(void) break; /* - * We are inside a subtransaction. Abort the current + * We are inside a subtransaction. Abort the current * subtransaction and go to the "abort all" state, so * CommitTransactionCommand will call AbortOutOfAnyTransaction * to set things straight. @@ -2373,7 +2384,7 @@ UserAbortTransactionBlock(void) void DefineSavepoint(char *name) { - TransactionState s = CurrentTransactionState; + TransactionState s = CurrentTransactionState; switch (s->blockState) { @@ -2381,11 +2392,12 @@ DefineSavepoint(char *name) case TBLOCK_SUBINPROGRESS: /* Normal subtransaction start */ PushTransaction(); - s = CurrentTransactionState; /* changed by push */ + s = CurrentTransactionState; /* changed by push */ + /* * Note that we are allocating the savepoint name in the - * parent transaction's CurTransactionContext, since we - * don't yet have a transaction context for the new guy. + * parent transaction's CurTransactionContext, since we don't + * yet have a transaction context for the new guy. */ s->name = MemoryContextStrdup(CurTransactionContext, name); s->blockState = TBLOCK_SUBBEGIN; @@ -2413,16 +2425,16 @@ DefineSavepoint(char *name) /* * ReleaseSavepoint - * This executes a RELEASE command. + * This executes a RELEASE command. */ void ReleaseSavepoint(List *options) { - TransactionState s = CurrentTransactionState; + TransactionState s = CurrentTransactionState; TransactionState target, - xact; - ListCell *cell; - char *name = NULL; + xact; + ListCell *cell; + char *name = NULL; /* * Check valid block state transaction status. @@ -2437,8 +2449,8 @@ ReleaseSavepoint(List *options) break; /* - * We are in a non-aborted subtransaction. This is - * the only valid case. + * We are in a non-aborted subtransaction. This is the only + * valid case. */ case TBLOCK_SUBINPROGRESS: break; @@ -2461,9 +2473,9 @@ ReleaseSavepoint(List *options) break; } - foreach (cell, options) + foreach(cell, options) { - DefElem *elem = lfirst(cell); + DefElem *elem = lfirst(cell); if (strcmp(elem->defname, "savepoint_name") == 0) name = strVal(elem->arg); @@ -2490,8 +2502,8 @@ ReleaseSavepoint(List *options) /* * Mark "commit pending" all subtransactions up to the target - * subtransaction. The actual commits will happen when control - * gets to CommitTransactionCommand. + * subtransaction. The actual commits will happen when control gets + * to CommitTransactionCommand. */ xact = CurrentTransactionState; for (;;) @@ -2507,23 +2519,23 @@ ReleaseSavepoint(List *options) /* * RollbackToSavepoint - * This executes a ROLLBACK TO <savepoint> command. + * This executes a ROLLBACK TO <savepoint> command. */ void RollbackToSavepoint(List *options) { TransactionState s = CurrentTransactionState; TransactionState target, - xact; - ListCell *cell; - char *name = NULL; + xact; + ListCell *cell; + char *name = NULL; switch (s->blockState) { - /* - * We can't rollback to a savepoint if there is no saveopint - * defined. - */ + /* + * We can't rollback to a savepoint if there is no saveopint + * defined. + */ case TBLOCK_ABORT: case TBLOCK_INPROGRESS: ereport(ERROR, @@ -2536,9 +2548,10 @@ RollbackToSavepoint(List *options) */ case TBLOCK_SUBABORT: case TBLOCK_SUBINPROGRESS: + /* - * Have to do AbortSubTransaction, but first check - * if this is the right subtransaction + * Have to do AbortSubTransaction, but first check if this is + * the right subtransaction */ break; @@ -2559,9 +2572,9 @@ RollbackToSavepoint(List *options) break; } - foreach (cell, options) + foreach(cell, options) { - DefElem *elem = lfirst(cell); + DefElem *elem = lfirst(cell); if (strcmp(elem->defname, "savepoint_name") == 0) name = strVal(elem->arg); @@ -2597,7 +2610,7 @@ RollbackToSavepoint(List *options) /* * Mark "abort pending" all subtransactions up to the target - * subtransaction. (Except the current subtransaction!) + * subtransaction. (Except the current subtransaction!) */ xact = CurrentTransactionState; @@ -2623,7 +2636,7 @@ RollbackToSavepoint(List *options) void BeginInternalSubTransaction(char *name) { - TransactionState s = CurrentTransactionState; + TransactionState s = CurrentTransactionState; switch (s->blockState) { @@ -2632,11 +2645,12 @@ BeginInternalSubTransaction(char *name) case TBLOCK_SUBINPROGRESS: /* Normal subtransaction start */ PushTransaction(); - s = CurrentTransactionState; /* changed by push */ + s = CurrentTransactionState; /* changed by push */ + /* * Note that we are allocating the savepoint name in the - * parent transaction's CurTransactionContext, since we - * don't yet have a transaction context for the new guy. + * parent transaction's CurTransactionContext, since we don't + * yet have a transaction context for the new guy. */ if (name) s->name = MemoryContextStrdup(CurTransactionContext, name); @@ -2698,7 +2712,7 @@ RollbackAndReleaseCurrentSubTransaction(void) switch (s->blockState) { - /* Must be in a subtransaction */ + /* Must be in a subtransaction */ case TBLOCK_SUBABORT: case TBLOCK_SUBINPROGRESS: break; @@ -2748,7 +2762,8 @@ AbortOutOfAnyTransaction(void) /* * Get out of any transaction or nested transaction */ - do { + do + { switch (s->blockState) { case TBLOCK_DEFAULT: @@ -2770,21 +2785,26 @@ AbortOutOfAnyTransaction(void) s->blockState = TBLOCK_DEFAULT; break; case TBLOCK_SUBBEGIN: + /* - * We didn't get as far as starting the subxact, so there's - * nothing to abort. Just pop back to parent. + * We didn't get as far as starting the subxact, so + * there's nothing to abort. Just pop back to parent. */ PopTransaction(); - s = CurrentTransactionState; /* changed by pop */ + s = CurrentTransactionState; /* changed by pop */ break; case TBLOCK_SUBINPROGRESS: case TBLOCK_SUBEND: case TBLOCK_SUBABORT_PENDING: - /* In a subtransaction, so clean it up and abort parent too */ + + /* + * In a subtransaction, so clean it up and abort parent + * too + */ AbortSubTransaction(); CleanupSubTransaction(); PopTransaction(); - s = CurrentTransactionState; /* changed by pop */ + s = CurrentTransactionState; /* changed by pop */ break; case TBLOCK_SUBABORT: case TBLOCK_SUBENDABORT_ALL: @@ -2793,7 +2813,7 @@ AbortOutOfAnyTransaction(void) /* As above, but AbortSubTransaction already done */ CleanupSubTransaction(); PopTransaction(); - s = CurrentTransactionState; /* changed by pop */ + s = CurrentTransactionState; /* changed by pop */ break; } } while (s->blockState != TBLOCK_DEFAULT); @@ -2819,7 +2839,7 @@ CommitTransactionToLevel(int level) { CommitSubTransaction(); PopTransaction(); - s = CurrentTransactionState; /* changed by pop */ + s = CurrentTransactionState; /* changed by pop */ Assert(s->state == TRANS_INPROGRESS); } } @@ -2840,7 +2860,7 @@ IsTransactionBlock(void) /* * IsTransactionOrTransactionBlock --- are we within either a transaction - * or a transaction block? (The backend is only really "idle" when this + * or a transaction block? (The backend is only really "idle" when this * returns false.) * * This should match up with IsTransactionBlock and IsTransactionState. @@ -2928,9 +2948,10 @@ StartSubTransaction(void) /* * Generate a new Xid and record it in pg_subtrans. NB: we must make - * the subtrans entry BEFORE the Xid appears anywhere in shared storage, - * such as in the lock table; because until it's made the Xid may not - * appear to be "running" to other backends. See GetNewTransactionId. + * the subtrans entry BEFORE the Xid appears anywhere in shared + * storage, such as in the lock table; because until it's made the Xid + * may not appear to be "running" to other backends. See + * GetNewTransactionId. */ s->transactionIdData = GetNewTransactionId(true); @@ -2943,7 +2964,7 @@ StartSubTransaction(void) */ s->currentUser = GetUserId(); s->prevXactReadOnly = XactReadOnly; - + /* * Initialize other subsystems for new subtransaction */ @@ -2954,7 +2975,7 @@ StartSubTransaction(void) s->state = TRANS_INPROGRESS; /* - * Call start-of-subxact callbacks + * Call start-of-subxact callbacks */ CallXactCallbacks(XACT_EVENT_START_SUB, s->parent->transactionIdData); @@ -3020,9 +3041,9 @@ CommitSubTransaction(void) s->parent->transactionIdData); /* - * We need to restore the upper transaction's read-only state, - * in case the upper is read-write while the child is read-only; - * GUC will incorrectly think it should leave the child state in place. + * We need to restore the upper transaction's read-only state, in case + * the upper is read-write while the child is read-only; GUC will + * incorrectly think it should leave the child state in place. */ XactReadOnly = s->prevXactReadOnly; @@ -3117,14 +3138,16 @@ AbortSubTransaction(void) /* * Reset user id which might have been changed transiently. Here we * want to restore to the userid that was current at subxact entry. - * (As in AbortTransaction, we need not worry about the session userid.) + * (As in AbortTransaction, we need not worry about the session + * userid.) * * Must do this after AtEOXact_GUC to handle the case where we entered * the subxact inside a SECURITY DEFINER function (hence current and * session userids were different) and then session auth was changed - * inside the subxact. GUC will reset both current and session userids - * to the entry-time session userid. This is right in every other - * scenario so it seems simplest to let GUC do that and fix it here. + * inside the subxact. GUC will reset both current and session + * userids to the entry-time session userid. This is right in every + * other scenario so it seems simplest to let GUC do that and fix it + * here. */ SetUserId(s->currentUser); @@ -3168,11 +3191,11 @@ CleanupSubTransaction(void) * StartAbortedSubTransaction * * This function is used to start a subtransaction and put it immediately - * into aborted state. The end result should be equivalent to + * into aborted state. The end result should be equivalent to * StartSubTransaction immediately followed by AbortSubTransaction. * The reason we don't implement it just that way is that many of the backend * modules aren't designed to handle starting a subtransaction when not - * inside a valid transaction. Rather than making them all capable of + * inside a valid transaction. Rather than making them all capable of * doing that, we just omit the paired start and abort calls in this path. */ static void @@ -3195,9 +3218,10 @@ StartAbortedSubTransaction(void) /* Make sure currentUser is reasonably valid */ Assert(s->parent != NULL); s->currentUser = s->parent->currentUser; - + /* - * Initialize only what has to be there for CleanupSubTransaction to work. + * Initialize only what has to be there for CleanupSubTransaction to + * work. */ AtSubStart_Memory(); AtSubStart_ResourceOwner(); @@ -3219,8 +3243,8 @@ StartAbortedSubTransaction(void) static void PushTransaction(void) { - TransactionState p = CurrentTransactionState; - TransactionState s; + TransactionState p = CurrentTransactionState; + TransactionState s; /* * We keep subtransaction state nodes in TopTransactionContext. @@ -3315,7 +3339,7 @@ ShowTransactionStateRec(TransactionState s) /* use ereport to suppress computation if msg will not be printed */ ereport(DEBUG2, (errmsg_internal("name: %s; blockState: %13s; state: %7s, xid/cid: %u/%02u, nestlvl: %d, children: %s", - PointerIsValid(s->name) ? s->name : "unnamed", + PointerIsValid(s->name) ? s->name : "unnamed", BlockStateAsString(s->blockState), TransStateAsString(s->state), (unsigned int) s->transactionIdData, @@ -3393,7 +3417,7 @@ TransStateAsString(TransState state) /* * xactGetCommittedChildren * - * Gets the list of committed children of the current transaction. The return + * Gets the list of committed children of the current transaction. The return * value is the number of child transactions. *children is set to point to a * palloc'd array of TransactionIds. If there are no subxacts, *children is * set to NULL. @@ -3401,10 +3425,10 @@ TransStateAsString(TransState state) int xactGetCommittedChildren(TransactionId **ptr) { - TransactionState s = CurrentTransactionState; - int nchildren; - TransactionId *children; - ListCell *p; + TransactionState s = CurrentTransactionState; + int nchildren; + TransactionId *children; + ListCell *p; nchildren = list_length(s->childXids); if (nchildren == 0) @@ -3438,12 +3462,12 @@ xact_redo(XLogRecPtr lsn, XLogRecord *record) if (info == XLOG_XACT_COMMIT) { xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record); - int i; + int i; TransactionIdCommit(record->xl_xid); /* Mark committed subtransactions as committed */ TransactionIdCommitTree(xlrec->nsubxacts, - (TransactionId *) &(xlrec->xnodes[xlrec->nrels])); + (TransactionId *) &(xlrec->xnodes[xlrec->nrels])); /* Make sure files supposed to be dropped are dropped */ for (i = 0; i < xlrec->nrels; i++) { @@ -3454,12 +3478,12 @@ xact_redo(XLogRecPtr lsn, XLogRecord *record) else if (info == XLOG_XACT_ABORT) { xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record); - int i; + int i; TransactionIdAbort(record->xl_xid); /* mark subtransactions as aborted */ TransactionIdAbortTree(xlrec->nsubxacts, - (TransactionId *) &(xlrec->xnodes[xlrec->nrels])); + (TransactionId *) &(xlrec->xnodes[xlrec->nrels])); /* Make sure files supposed to be dropped are dropped */ for (i = 0; i < xlrec->nrels; i++) { @@ -3486,7 +3510,7 @@ void xact_desc(char *buf, uint8 xl_info, char *rec) { uint8 info = xl_info & ~XLR_INFO_MASK; - int i; + int i; if (info == XLOG_XACT_COMMIT) { @@ -3502,6 +3526,7 @@ xact_desc(char *buf, uint8 xl_info, char *rec) for (i = 0; i < xlrec->nrels; i++) { RelFileNode rnode = xlrec->xnodes[i]; + sprintf(buf + strlen(buf), " %u/%u/%u", rnode.spcNode, rnode.dbNode, rnode.relNode); } @@ -3509,7 +3534,7 @@ xact_desc(char *buf, uint8 xl_info, char *rec) if (xlrec->nsubxacts > 0) { TransactionId *xacts = (TransactionId *) - &xlrec->xnodes[xlrec->nrels]; + &xlrec->xnodes[xlrec->nrels]; sprintf(buf + strlen(buf), "; subxacts:"); for (i = 0; i < xlrec->nsubxacts; i++) @@ -3530,6 +3555,7 @@ xact_desc(char *buf, uint8 xl_info, char *rec) for (i = 0; i < xlrec->nrels; i++) { RelFileNode rnode = xlrec->xnodes[i]; + sprintf(buf + strlen(buf), " %u/%u/%u", rnode.spcNode, rnode.dbNode, rnode.relNode); } @@ -3537,7 +3563,7 @@ xact_desc(char *buf, uint8 xl_info, char *rec) if (xlrec->nsubxacts > 0) { TransactionId *xacts = (TransactionId *) - &xlrec->xnodes[xlrec->nrels]; + &xlrec->xnodes[xlrec->nrels]; sprintf(buf + strlen(buf), "; subxacts:"); for (i = 0; i < xlrec->nsubxacts; i++) @@ -3549,7 +3575,7 @@ xact_desc(char *buf, uint8 xl_info, char *rec) } void -XactPushRollback(void (*func) (void *), void *data) + XactPushRollback(void (*func) (void *), void *data) { #ifdef XLOG_II if (_RollbackFunc != NULL) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 309f17a83fc..e65c109f665 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.165 2004/08/29 04:12:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.166 2004/08/29 05:06:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -128,26 +128,28 @@ TimeLineID ThisTimeLineID = 0; /* Are we doing recovery from XLOG? */ bool InRecovery = false; + /* Are we recovering using offline XLOG archives? */ -static bool InArchiveRecovery = false; +static bool InArchiveRecovery = false; + /* Was the last xlog file restored from archive, or local? */ -static bool restoredFromArchive = false; +static bool restoredFromArchive = false; /* options taken from recovery.conf */ static char *recoveryRestoreCommand = NULL; static bool recoveryTarget = false; static bool recoveryTargetExact = false; static bool recoveryTargetInclusive = true; -static TransactionId recoveryTargetXid; -static time_t recoveryTargetTime; +static TransactionId recoveryTargetXid; +static time_t recoveryTargetTime; /* if recoveryStopsHere returns true, it saves actual stop xid/time here */ -static TransactionId recoveryStopXid; -static time_t recoveryStopTime; -static bool recoveryStopAfter; +static TransactionId recoveryStopXid; +static time_t recoveryStopTime; +static bool recoveryStopAfter; /* constraint set by read_backup_label */ -static XLogRecPtr recoveryMinXlogOffset = { 0, 0 }; +static XLogRecPtr recoveryMinXlogOffset = {0, 0}; /* * During normal operation, the only timeline we care about is ThisTimeLineID. @@ -161,7 +163,7 @@ static XLogRecPtr recoveryMinXlogOffset = { 0, 0 }; * * expectedTLIs: an integer list of recoveryTargetTLI and the TLIs of * its known parents, newest first (so recoveryTargetTLI is always the - * first list member). Only these TLIs are expected to be seen in the WAL + * first list member). Only these TLIs are expected to be seen in the WAL * segments we read, and indeed only these TLIs will be considered as * candidate WAL files to open at all. * @@ -171,9 +173,9 @@ static XLogRecPtr recoveryMinXlogOffset = { 0, 0 }; * file was created.) During a sequential scan we do not allow this value * to decrease. */ -static TimeLineID recoveryTargetTLI; -static List *expectedTLIs; -static TimeLineID curFileTLI; +static TimeLineID recoveryTargetTLI; +static List *expectedTLIs; +static TimeLineID curFileTLI; /* * MyLastRecPtr points to the start of the last XLOG record inserted by the @@ -373,7 +375,7 @@ static ControlFileData *ControlFile = NULL; /* File path names */ -char XLogDir[MAXPGPATH]; +char XLogDir[MAXPGPATH]; static char ControlFilePath[MAXPGPATH]; /* @@ -422,7 +424,7 @@ static bool XLogArchiveIsDone(const char *xlog); static void XLogArchiveCleanup(const char *xlog); static void readRecoveryCommandFile(void); static void exitArchiveRecovery(TimeLineID endTLI, - uint32 endLogId, uint32 endLogSeg); + uint32 endLogId, uint32 endLogSeg); static bool recoveryStopsHere(XLogRecord *record, bool *includeThis); static bool AdvanceXLInsertBuffer(void); @@ -435,7 +437,7 @@ static bool InstallXLogFileSegment(uint32 log, uint32 seg, char *tmppath, static int XLogFileOpen(uint32 log, uint32 seg); static int XLogFileRead(uint32 log, uint32 seg, int emode); static bool RestoreArchivedFile(char *path, const char *xlogfname, - const char *recovername, off_t expectedSize); + const char *recovername, off_t expectedSize); static void PreallocXlogFiles(XLogRecPtr endptr); static void MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr); static XLogRecord *ReadRecord(XLogRecPtr *RecPtr, int emode, char *buffer); @@ -447,12 +449,13 @@ static List *readTimeLineHistory(TimeLineID targetTLI); static bool existsTimeLineHistory(TimeLineID probeTLI); static TimeLineID findNewestTimeLine(TimeLineID startTLI); static void writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, - TimeLineID endTLI, - uint32 endLogId, uint32 endLogSeg); + TimeLineID endTLI, + uint32 endLogId, uint32 endLogSeg); static void WriteControlFile(void); static void ReadControlFile(void); static char *str_time(time_t tnow); static void issue_xlog_fsync(void); + #ifdef WAL_DEBUG static void xlog_outrec(char *buf, XLogRecord *record); #endif @@ -514,7 +517,8 @@ XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata) if (IsBootstrapProcessingMode() && rmid != RM_XLOG_ID) { RecPtr.xlogid = 0; - RecPtr.xrecoff = SizeOfXLogLongPHD; /* start of 1st chkpt record */ + RecPtr.xrecoff = SizeOfXLogLongPHD; /* start of 1st chkpt + * record */ return (RecPtr); } @@ -724,7 +728,8 @@ begin:; /* * If there isn't enough space on the current XLOG page for a record - * header, advance to the next page (leaving the unused space as zeroes). + * header, advance to the next page (leaving the unused space as + * zeroes). */ updrqst = false; freespace = INSERT_FREESPACE(Insert); @@ -895,19 +900,21 @@ static void XLogArchiveNotify(const char *xlog) { char archiveStatusPath[MAXPGPATH]; - FILE *fd; + FILE *fd; /* insert an otherwise empty file called <XLOG>.ready */ StatusFilePath(archiveStatusPath, xlog, ".ready"); fd = AllocateFile(archiveStatusPath, "w"); - if (fd == NULL) { + if (fd == NULL) + { ereport(LOG, (errcode_for_file_access(), errmsg("could not create archive status file \"%s\": %m", archiveStatusPath))); return; } - if (FreeFile(fd)) { + if (FreeFile(fd)) + { ereport(LOG, (errcode_for_file_access(), errmsg("could not write archive status file \"%s\": %m", @@ -935,7 +942,7 @@ XLogArchiveNotifySeg(uint32 log, uint32 seg) /* * XLogArchiveIsDone * - * Checks for a ".done" archive notification file. This is called when we + * Checks for a ".done" archive notification file. This is called when we * are ready to delete or recycle an old XLOG segment file. If it is okay * to delete it then return true. * @@ -958,7 +965,7 @@ XLogArchiveIsDone(const char *xlog) /* check for .ready --- this means archiver is still busy with it */ StatusFilePath(archiveStatusPath, xlog, ".ready"); if (stat(archiveStatusPath, &stat_buf) == 0) - return false; + return false; /* Race condition --- maybe archiver just finished, so recheck */ StatusFilePath(archiveStatusPath, xlog, ".done"); @@ -978,7 +985,7 @@ XLogArchiveIsDone(const char *xlog) static void XLogArchiveCleanup(const char *xlog) { - char archiveStatusPath[MAXPGPATH]; + char archiveStatusPath[MAXPGPATH]; /* Remove the .done file */ StatusFilePath(archiveStatusPath, xlog, ".done"); @@ -1267,8 +1274,8 @@ XLogWrite(XLogwrtRqst WriteRqst) issue_xlog_fsync(); LogwrtResult.Flush = LogwrtResult.Write; /* end of current page */ - if (XLogArchivingActive()) - XLogArchiveNotifySeg(openLogId, openLogSeg); + if (XLogArchivingActive()) + XLogArchiveNotifySeg(openLogId, openLogSeg); } if (ispartialpage) @@ -1552,7 +1559,7 @@ XLogFileInit(uint32 log, uint32 seg, ereport(PANIC, (errcode_for_file_access(), - errmsg("could not write to file \"%s\": %m", tmppath))); + errmsg("could not write to file \"%s\": %m", tmppath))); } } @@ -1591,8 +1598,8 @@ XLogFileInit(uint32 log, uint32 seg, if (fd < 0) ereport(PANIC, (errcode_for_file_access(), - errmsg("could not open file \"%s\" (log file %u, segment %u): %m", - path, log, seg))); + errmsg("could not open file \"%s\" (log file %u, segment %u): %m", + path, log, seg))); return (fd); } @@ -1606,7 +1613,7 @@ XLogFileInit(uint32 log, uint32 seg, * a different timeline) * * Currently this is only used during recovery, and so there are no locking - * considerations. But we should be just as tense as XLogFileInit to avoid + * considerations. But we should be just as tense as XLogFileInit to avoid * emplacing a bogus file. */ static void @@ -1660,7 +1667,7 @@ XLogFileCopy(uint32 log, uint32 seg, errmsg("could not read file \"%s\": %m", path))); else ereport(PANIC, - (errmsg("insufficient data in file \"%s\"", path))); + (errmsg("insufficient data in file \"%s\"", path))); } errno = 0; if ((int) write(fd, buffer, sizeof(buffer)) != (int) sizeof(buffer)) @@ -1677,7 +1684,7 @@ XLogFileCopy(uint32 log, uint32 seg, ereport(PANIC, (errcode_for_file_access(), - errmsg("could not write to file \"%s\": %m", tmppath))); + errmsg("could not write to file \"%s\": %m", tmppath))); } } @@ -1805,8 +1812,8 @@ XLogFileOpen(uint32 log, uint32 seg) if (fd < 0) ereport(PANIC, (errcode_for_file_access(), - errmsg("could not open file \"%s\" (log file %u, segment %u): %m", - path, log, seg))); + errmsg("could not open file \"%s\" (log file %u, segment %u): %m", + path, log, seg))); return fd; } @@ -1823,11 +1830,11 @@ XLogFileRead(uint32 log, uint32 seg, int emode) int fd; /* - * Loop looking for a suitable timeline ID: we might need to - * read any of the timelines listed in expectedTLIs. + * Loop looking for a suitable timeline ID: we might need to read any + * of the timelines listed in expectedTLIs. * - * We expect curFileTLI on entry to be the TLI of the preceding file - * in sequence, or 0 if there was no predecessor. We do not allow + * We expect curFileTLI on entry to be the TLI of the preceding file in + * sequence, or 0 if there was no predecessor. We do not allow * curFileTLI to go backwards; this prevents us from picking up the * wrong file when a parent timeline extends to higher segment numbers * than the child we want to read. @@ -1868,8 +1875,8 @@ XLogFileRead(uint32 log, uint32 seg, int emode) errno = ENOENT; ereport(emode, (errcode_for_file_access(), - errmsg("could not open file \"%s\" (log file %u, segment %u): %m", - path, log, seg))); + errmsg("could not open file \"%s\" (log file %u, segment %u): %m", + path, log, seg))); return -1; } @@ -1891,36 +1898,37 @@ static bool RestoreArchivedFile(char *path, const char *xlogfname, const char *recovername, off_t expectedSize) { - char xlogpath[MAXPGPATH]; - char xlogRestoreCmd[MAXPGPATH]; - char *dp; - char *endp; + char xlogpath[MAXPGPATH]; + char xlogRestoreCmd[MAXPGPATH]; + char *dp; + char *endp; const char *sp; - int rc; + int rc; struct stat stat_buf; /* * When doing archive recovery, we always prefer an archived log file * even if a file of the same name exists in XLogDir. The reason is - * that the file in XLogDir could be an old, un-filled or partly-filled - * version that was copied and restored as part of backing up $PGDATA. + * that the file in XLogDir could be an old, un-filled or + * partly-filled version that was copied and restored as part of + * backing up $PGDATA. * - * We could try to optimize this slightly by checking the local - * copy lastchange timestamp against the archived copy, - * but we have no API to do this, nor can we guarantee that the - * lastchange timestamp was preserved correctly when we copied - * to archive. Our aim is robustness, so we elect not to do this. + * We could try to optimize this slightly by checking the local copy + * lastchange timestamp against the archived copy, but we have no API + * to do this, nor can we guarantee that the lastchange timestamp was + * preserved correctly when we copied to archive. Our aim is + * robustness, so we elect not to do this. * - * If we cannot obtain the log file from the archive, however, we - * will try to use the XLogDir file if it exists. This is so that - * we can make use of log segments that weren't yet transferred to - * the archive. + * If we cannot obtain the log file from the archive, however, we will + * try to use the XLogDir file if it exists. This is so that we can + * make use of log segments that weren't yet transferred to the + * archive. * * Notice that we don't actually overwrite any files when we copy back * from archive because the recoveryRestoreCommand may inadvertently - * restore inappropriate xlogs, or they may be corrupt, so we may - * wish to fallback to the segments remaining in current XLogDir later. - * The copy-from-archive filename is always the same, ensuring that we + * restore inappropriate xlogs, or they may be corrupt, so we may wish + * to fallback to the segments remaining in current XLogDir later. The + * copy-from-archive filename is always the same, ensuring that we * don't run out of disk space on long recoveries. */ snprintf(xlogpath, MAXPGPATH, "%s/%s", XLogDir, recovername); @@ -1961,14 +1969,14 @@ RestoreArchivedFile(char *path, const char *xlogfname, case 'p': /* %p: full path of target file */ sp++; - StrNCpy(dp, xlogpath, endp-dp); + StrNCpy(dp, xlogpath, endp - dp); make_native_path(dp); dp += strlen(dp); break; case 'f': /* %f: filename of desired file */ sp++; - StrNCpy(dp, xlogfname, endp-dp); + StrNCpy(dp, xlogfname, endp - dp); dp += strlen(dp); break; case '%': @@ -1993,7 +2001,7 @@ RestoreArchivedFile(char *path, const char *xlogfname, *dp = '\0'; ereport(DEBUG3, - (errmsg_internal("executing restore command \"%s\"", + (errmsg_internal("executing restore command \"%s\"", xlogRestoreCmd))); /* @@ -2006,9 +2014,9 @@ RestoreArchivedFile(char *path, const char *xlogfname, * command apparently succeeded, but let's make sure the file is * really there now and has the correct size. * - * XXX I made wrong-size a fatal error to ensure the DBA would - * notice it, but is that too strong? We could try to plow ahead - * with a local copy of the file ... but the problem is that there + * XXX I made wrong-size a fatal error to ensure the DBA would notice + * it, but is that too strong? We could try to plow ahead with a + * local copy of the file ... but the problem is that there * probably isn't one, and we'd incorrectly conclude we've reached * the end of WAL and we're done recovering ... */ @@ -2041,23 +2049,23 @@ RestoreArchivedFile(char *path, const char *xlogfname, } /* - * remember, we rollforward UNTIL the restore fails - * so failure here is just part of the process... - * that makes it difficult to determine whether the restore - * failed because there isn't an archive to restore, or - * because the administrator has specified the restore + * remember, we rollforward UNTIL the restore fails so failure here is + * just part of the process... that makes it difficult to determine + * whether the restore failed because there isn't an archive to + * restore, or because the administrator has specified the restore * program incorrectly. We have to assume the former. */ ereport(DEBUG1, - (errmsg("could not restore \"%s\" from archive: return code %d", - xlogfname, rc))); + (errmsg("could not restore \"%s\" from archive: return code %d", + xlogfname, rc))); /* - * if an archived file is not available, there might still be a version - * of this file in XLogDir, so return that as the filename to open. + * if an archived file is not available, there might still be a + * version of this file in XLogDir, so return that as the filename to + * open. * - * In many recovery scenarios we expect this to fail also, but - * if so that just means we've reached the end of WAL. + * In many recovery scenarios we expect this to fail also, but if so that + * just means we've reached the end of WAL. */ snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlogfname); return false; @@ -2118,24 +2126,24 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr) { /* * We ignore the timeline part of the XLOG segment identifiers in - * deciding whether a segment is still needed. This ensures that + * deciding whether a segment is still needed. This ensures that * we won't prematurely remove a segment from a parent timeline. * We could probably be a little more proactive about removing * segments of non-parent timelines, but that would be a whole lot * more complicated. * - * We use the alphanumeric sorting property of the filenames to decide - * which ones are earlier than the lastoff segment. + * We use the alphanumeric sorting property of the filenames to + * decide which ones are earlier than the lastoff segment. */ if (strlen(xlde->d_name) == 24 && strspn(xlde->d_name, "0123456789ABCDEF") == 24 && strcmp(xlde->d_name + 8, lastoff + 8) <= 0) { - bool recycle; + bool recycle; if (XLogArchivingActive()) recycle = XLogArchiveIsDone(xlde->d_name); - else + else recycle = true; if (recycle) @@ -2160,8 +2168,8 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr) { /* No need for any more future segments... */ ereport(LOG, - (errmsg("removing transaction log file \"%s\"", - xlde->d_name))); + (errmsg("removing transaction log file \"%s\"", + xlde->d_name))); unlink(path); } @@ -2171,8 +2179,11 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr) errno = 0; } #ifdef WIN32 - /* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but - not in released version */ + + /* + * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but + * not in released version + */ if (GetLastError() == ERROR_NO_MORE_FILES) errno = 0; #endif @@ -2263,8 +2274,8 @@ RecordIsValid(XLogRecord *record, XLogRecPtr recptr, int emode) if (!EQ_CRC64(record->xl_crc, crc)) { ereport(emode, - (errmsg("incorrect resource manager data checksum in record at %X/%X", - recptr.xlogid, recptr.xrecoff))); + (errmsg("incorrect resource manager data checksum in record at %X/%X", + recptr.xlogid, recptr.xrecoff))); return (false); } @@ -2286,8 +2297,8 @@ RecordIsValid(XLogRecord *record, XLogRecPtr recptr, int emode) if (!EQ_CRC64(cbuf, crc)) { ereport(emode, - (errmsg("incorrect checksum of backup block %d in record at %X/%X", - i + 1, recptr.xlogid, recptr.xrecoff))); + (errmsg("incorrect checksum of backup block %d in record at %X/%X", + i + 1, recptr.xlogid, recptr.xrecoff))); return (false); } blk += sizeof(BkpBlock) + BLCKSZ; @@ -2361,12 +2372,13 @@ ReadRecord(XLogRecPtr *RecPtr, int emode, char *buffer) ereport(PANIC, (errmsg("invalid record offset at %X/%X", RecPtr->xlogid, RecPtr->xrecoff))); + /* * Since we are going to a random position in WAL, forget any - * prior state about what timeline we were in, and allow it - * to be any timeline in expectedTLIs. We also set a flag to - * allow curFileTLI to go backwards (but we can't reset that - * variable right here, since we might not change files at all). + * prior state about what timeline we were in, and allow it to be + * any timeline in expectedTLIs. We also set a flag to allow + * curFileTLI to go backwards (but we can't reset that variable + * right here, since we might not change files at all). */ lastPageTLI = 0; /* see comment in ValidXLOGHeader */ randAccess = true; /* allow curFileTLI to go backwards too */ @@ -2418,9 +2430,9 @@ ReadRecord(XLogRecPtr *RecPtr, int emode, char *buffer) if (targetRecOff == 0) { /* - * Can only get here in the continuing-from-prev-page case, because - * XRecOffIsValid eliminated the zero-page-offset case otherwise. - * Need to skip over the new page's header. + * Can only get here in the continuing-from-prev-page case, + * because XRecOffIsValid eliminated the zero-page-offset case + * otherwise. Need to skip over the new page's header. */ tmpRecPtr.xrecoff += pageHeaderSize; targetRecOff = pageHeaderSize; @@ -2631,15 +2643,15 @@ ValidXLOGHeader(XLogPageHeader hdr, int emode) ControlFile->system_identifier); ereport(emode, (errmsg("WAL file is from different system"), - errdetail("WAL file SYSID is %s, pg_control SYSID is %s", - fhdrident_str, sysident_str))); + errdetail("WAL file SYSID is %s, pg_control SYSID is %s", + fhdrident_str, sysident_str))); return false; } if (longhdr->xlp_seg_size != XLogSegSize) { ereport(emode, (errmsg("WAL file is from different system"), - errdetail("Incorrect XLOG_SEG_SIZE in page header."))); + errdetail("Incorrect XLOG_SEG_SIZE in page header."))); return false; } } @@ -2671,9 +2683,9 @@ ValidXLOGHeader(XLogPageHeader hdr, int emode) * immediate parent's TLI, we should never see TLI go backwards across * successive pages of a consistent WAL sequence. * - * Of course this check should only be applied when advancing sequentially - * across pages; therefore ReadRecord resets lastPageTLI to zero when - * going to a random page. + * Of course this check should only be applied when advancing + * sequentially across pages; therefore ReadRecord resets lastPageTLI + * to zero when going to a random page. */ if (hdr->xlp_tli < lastPageTLI) { @@ -2691,7 +2703,7 @@ ValidXLOGHeader(XLogPageHeader hdr, int emode) * Try to read a timeline's history file. * * If successful, return the list of component TLIs (the given TLI followed by - * its ancestor TLIs). If we can't find the history file, assume that the + * its ancestor TLIs). If we can't find the history file, assume that the * timeline has no parents, and return a list of just the specified timeline * ID. */ @@ -2702,7 +2714,7 @@ readTimeLineHistory(TimeLineID targetTLI) char path[MAXPGPATH]; char histfname[MAXFNAMELEN]; char fline[MAXPGPATH]; - FILE *fd; + FILE *fd; if (InArchiveRecovery) { @@ -2712,7 +2724,7 @@ readTimeLineHistory(TimeLineID targetTLI) else TLHistoryFilePath(path, targetTLI); - fd = AllocateFile(path, "r"); + fd = AllocateFile(path, "r"); if (fd == NULL) { if (errno != ENOENT) @@ -2725,15 +2737,15 @@ readTimeLineHistory(TimeLineID targetTLI) result = NIL; - /* - * Parse the file... - */ - while (fgets(fline, MAXPGPATH, fd) != NULL) + /* + * Parse the file... + */ + while (fgets(fline, MAXPGPATH, fd) != NULL) { /* skip leading whitespace and check for # comment */ - char *ptr; - char *endptr; - TimeLineID tli; + char *ptr; + char *endptr; + TimeLineID tli; for (ptr = fline; *ptr; ptr++) { @@ -2754,7 +2766,7 @@ readTimeLineHistory(TimeLineID targetTLI) tli <= (TimeLineID) linitial_int(result)) ereport(FATAL, (errmsg("invalid data in history file: %s", fline), - errhint("Timeline IDs must be in increasing sequence."))); + errhint("Timeline IDs must be in increasing sequence."))); /* Build list with newest item first */ result = lcons_int((int) tli, result); @@ -2768,7 +2780,7 @@ readTimeLineHistory(TimeLineID targetTLI) targetTLI <= (TimeLineID) linitial_int(result)) ereport(FATAL, (errmsg("invalid data in history file \"%s\"", path), - errhint("Timeline IDs must be less than child timeline's ID."))); + errhint("Timeline IDs must be less than child timeline's ID."))); result = lcons_int((int) targetTLI, result); @@ -2787,7 +2799,7 @@ existsTimeLineHistory(TimeLineID probeTLI) { char path[MAXPGPATH]; char histfname[MAXFNAMELEN]; - FILE *fd; + FILE *fd; if (InArchiveRecovery) { @@ -2827,12 +2839,12 @@ findNewestTimeLine(TimeLineID startTLI) TimeLineID probeTLI; /* - * The algorithm is just to probe for the existence of timeline history - * files. XXX is it useful to allow gaps in the sequence? + * The algorithm is just to probe for the existence of timeline + * history files. XXX is it useful to allow gaps in the sequence? */ newestTLI = startTLI; - for (probeTLI = startTLI + 1; ; probeTLI++) + for (probeTLI = startTLI + 1;; probeTLI++) { if (existsTimeLineHistory(probeTLI)) { @@ -2856,7 +2868,7 @@ findNewestTimeLine(TimeLineID startTLI) * endTLI et al: ID of the last used WAL file, for annotation purposes * * Currently this is only used during recovery, and so there are no locking - * considerations. But we should be just as tense as XLogFileInit to avoid + * considerations. But we should be just as tense as XLogFileInit to avoid * emplacing a bogus file. */ static void @@ -2872,7 +2884,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, int fd; int nbytes; - Assert(newTLI > parentTLI); /* else bad selection of newTLI */ + Assert(newTLI > parentTLI); /* else bad selection of newTLI */ /* * Write into a temp file name. @@ -2932,12 +2944,16 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, * space */ unlink(tmppath); - /* if write didn't set errno, assume problem is no disk space */ + + /* + * if write didn't set errno, assume problem is no disk + * space + */ errno = save_errno ? save_errno : ENOSPC; ereport(PANIC, (errcode_for_file_access(), - errmsg("could not write to file \"%s\": %m", tmppath))); + errmsg("could not write to file \"%s\": %m", tmppath))); } } close(srcfd); @@ -2946,8 +2962,8 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, /* * Append one line with the details of this timeline split. * - * If we did have a parent file, insert an extra newline just in case - * the parent file failed to end with one. + * If we did have a parent file, insert an extra newline just in case the + * parent file failed to end with one. */ XLogFileName(xlogfname, endTLI, endLogId, endLogSeg); @@ -2967,8 +2983,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, int save_errno = errno; /* - * If we fail to make the file, delete it to release disk - * space + * If we fail to make the file, delete it to release disk space */ unlink(tmppath); /* if write didn't set errno, assume problem is no disk space */ @@ -3215,7 +3230,7 @@ ReadControlFile(void) ereport(FATAL, (errmsg("database files are incompatible with server"), errdetail("The database cluster was initialized with XLOG_SEG_SIZE %d," - " but the server was compiled with XLOG_SEG_SIZE %d.", + " but the server was compiled with XLOG_SEG_SIZE %d.", ControlFile->xlog_seg_size, XLOG_SEG_SIZE), errhint("It looks like you need to recompile or initdb."))); if (ControlFile->nameDataLen != NAMEDATALEN) @@ -3336,7 +3351,8 @@ XLOGShmemSize(void) void XLOGShmemInit(void) { - bool foundXLog, foundCFile; + bool foundXLog, + foundCFile; /* this must agree with space requested by XLOGShmemSize() */ if (XLOGbuffers < MinXLOGbuffers) @@ -3414,16 +3430,17 @@ BootStrapXLOG(void) crc64 crc; /* - * Select a hopefully-unique system identifier code for this installation. - * We use the result of gettimeofday(), including the fractional seconds - * field, as being about as unique as we can easily get. (Think not to - * use random(), since it hasn't been seeded and there's no portable way - * to seed it other than the system clock value...) The upper half of the - * uint64 value is just the tv_sec part, while the lower half is the XOR - * of tv_sec and tv_usec. This is to ensure that we don't lose uniqueness - * unnecessarily if "uint64" is really only 32 bits wide. A person - * knowing this encoding can determine the initialization time of the - * installation, which could perhaps be useful sometimes. + * Select a hopefully-unique system identifier code for this + * installation. We use the result of gettimeofday(), including the + * fractional seconds field, as being about as unique as we can easily + * get. (Think not to use random(), since it hasn't been seeded and + * there's no portable way to seed it other than the system clock + * value...) The upper half of the uint64 value is just the tv_sec + * part, while the lower half is the XOR of tv_sec and tv_usec. This + * is to ensure that we don't lose uniqueness unnecessarily if + * "uint64" is really only 32 bits wide. A person knowing this + * encoding can determine the initialization time of the installation, + * which could perhaps be useful sometimes. */ gettimeofday(&tv, NULL); sysidentifier = ((uint64) tv.tv_sec) << 32; @@ -3492,18 +3509,18 @@ BootStrapXLOG(void) errno = ENOSPC; ereport(PANIC, (errcode_for_file_access(), - errmsg("could not write bootstrap transaction log file: %m"))); + errmsg("could not write bootstrap transaction log file: %m"))); } if (pg_fsync(openLogFile) != 0) ereport(PANIC, (errcode_for_file_access(), - errmsg("could not fsync bootstrap transaction log file: %m"))); + errmsg("could not fsync bootstrap transaction log file: %m"))); if (close(openLogFile)) ereport(PANIC, (errcode_for_file_access(), - errmsg("could not close bootstrap transaction log file: %m"))); + errmsg("could not close bootstrap transaction log file: %m"))); openLogFile = -1; @@ -3550,37 +3567,37 @@ str_time(time_t tnow) static void readRecoveryCommandFile(void) { - char recoveryCommandFile[MAXPGPATH]; - FILE *fd; - char cmdline[MAXPGPATH]; - TimeLineID rtli = 0; - bool rtliGiven = false; - bool syntaxError = false; - - snprintf(recoveryCommandFile, MAXPGPATH, "%s/recovery.conf", DataDir); - fd = AllocateFile(recoveryCommandFile, "r"); + char recoveryCommandFile[MAXPGPATH]; + FILE *fd; + char cmdline[MAXPGPATH]; + TimeLineID rtli = 0; + bool rtliGiven = false; + bool syntaxError = false; + + snprintf(recoveryCommandFile, MAXPGPATH, "%s/recovery.conf", DataDir); + fd = AllocateFile(recoveryCommandFile, "r"); if (fd == NULL) { if (errno == ENOENT) return; /* not there, so no archive recovery */ ereport(FATAL, - (errcode_for_file_access(), + (errcode_for_file_access(), errmsg("could not open recovery command file \"%s\": %m", recoveryCommandFile))); } ereport(LOG, - (errmsg("starting archive recovery"))); + (errmsg("starting archive recovery"))); - /* - * Parse the file... - */ - while (fgets(cmdline, MAXPGPATH, fd) != NULL) + /* + * Parse the file... + */ + while (fgets(cmdline, MAXPGPATH, fd) != NULL) { /* skip leading whitespace and check for # comment */ - char *ptr; - char *tok1; - char *tok2; + char *ptr; + char *tok1; + char *tok2; for (ptr = cmdline; *ptr; ptr++) { @@ -3591,13 +3608,13 @@ readRecoveryCommandFile(void) continue; /* identify the quoted parameter value */ - tok1 = strtok(ptr, "'"); + tok1 = strtok(ptr, "'"); if (!tok1) { syntaxError = true; break; } - tok2 = strtok(NULL, "'"); + tok2 = strtok(NULL, "'"); if (!tok2) { syntaxError = true; @@ -3611,13 +3628,15 @@ readRecoveryCommandFile(void) break; } - if (strcmp(tok1,"restore_command") == 0) { + if (strcmp(tok1, "restore_command") == 0) + { recoveryRestoreCommand = pstrdup(tok2); ereport(LOG, (errmsg("restore_command = \"%s\"", recoveryRestoreCommand))); } - else if (strcmp(tok1,"recovery_target_timeline") == 0) { + else if (strcmp(tok1, "recovery_target_timeline") == 0) + { rtliGiven = true; if (strcmp(tok2, "latest") == 0) rtli = 0; @@ -3637,7 +3656,8 @@ readRecoveryCommandFile(void) ereport(LOG, (errmsg("recovery_target_timeline = latest"))); } - else if (strcmp(tok1,"recovery_target_xid") == 0) { + else if (strcmp(tok1, "recovery_target_xid") == 0) + { errno = 0; recoveryTargetXid = (TransactionId) strtoul(tok2, NULL, 0); if (errno == EINVAL || errno == ERANGE) @@ -3650,7 +3670,8 @@ readRecoveryCommandFile(void) recoveryTarget = true; recoveryTargetExact = true; } - else if (strcmp(tok1,"recovery_target_time") == 0) { + else if (strcmp(tok1, "recovery_target_time") == 0) + { /* * if recovery_target_xid specified, then this overrides * recovery_target_time @@ -3659,20 +3680,22 @@ readRecoveryCommandFile(void) continue; recoveryTarget = true; recoveryTargetExact = false; + /* - * Convert the time string given by the user to the time_t format. - * We use type abstime's input converter because we know abstime - * has the same representation as time_t. + * Convert the time string given by the user to the time_t + * format. We use type abstime's input converter because we + * know abstime has the same representation as time_t. */ recoveryTargetTime = (time_t) DatumGetAbsoluteTime(DirectFunctionCall1(abstimein, - CStringGetDatum(tok2))); + CStringGetDatum(tok2))); ereport(LOG, (errmsg("recovery_target_time = %s", - DatumGetCString(DirectFunctionCall1(abstimeout, - AbsoluteTimeGetDatum((AbsoluteTime) recoveryTargetTime)))))); + DatumGetCString(DirectFunctionCall1(abstimeout, + AbsoluteTimeGetDatum((AbsoluteTime) recoveryTargetTime)))))); } - else if (strcmp(tok1,"recovery_target_inclusive") == 0) { + else if (strcmp(tok1, "recovery_target_inclusive") == 0) + { /* * does nothing if a recovery_target is not also set */ @@ -3694,11 +3717,11 @@ readRecoveryCommandFile(void) FreeFile(fd); - if (syntaxError) - ereport(FATAL, + if (syntaxError) + ereport(FATAL, (errmsg("syntax error in recovery command file: %s", cmdline), - errhint("Lines should have the format parameter = 'value'."))); + errhint("Lines should have the format parameter = 'value'."))); /* Check that required parameters were supplied */ if (recoveryRestoreCommand == NULL) @@ -3710,10 +3733,10 @@ readRecoveryCommandFile(void) InArchiveRecovery = true; /* - * If user specified recovery_target_timeline, validate it or compute the - * "latest" value. We can't do this until after we've gotten the restore - * command and set InArchiveRecovery, because we need to fetch timeline - * history files from the archive. + * If user specified recovery_target_timeline, validate it or compute + * the "latest" value. We can't do this until after we've gotten the + * restore command and set InArchiveRecovery, because we need to fetch + * timeline history files from the archive. */ if (rtliGiven) { @@ -3722,8 +3745,8 @@ readRecoveryCommandFile(void) /* Timeline 1 does not have a history file, all else should */ if (rtli != 1 && !existsTimeLineHistory(rtli)) ereport(FATAL, - (errmsg("recovery_target_timeline %u does not exist", - rtli))); + (errmsg("recovery_target_timeline %u does not exist", + rtli))); recoveryTargetTLI = rtli; } else @@ -3740,10 +3763,10 @@ readRecoveryCommandFile(void) static void exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg) { - char recoveryPath[MAXPGPATH]; - char xlogpath[MAXPGPATH]; - char recoveryCommandFile[MAXPGPATH]; - char recoveryCommandDone[MAXPGPATH]; + char recoveryPath[MAXPGPATH]; + char xlogpath[MAXPGPATH]; + char recoveryCommandFile[MAXPGPATH]; + char recoveryCommandDone[MAXPGPATH]; /* * We are no longer in archive recovery state. @@ -3751,9 +3774,9 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg) InArchiveRecovery = false; /* - * We should have the ending log segment currently open. Verify, - * and then close it (to avoid problems on Windows with trying to - * rename or delete an open file). + * We should have the ending log segment currently open. Verify, and + * then close it (to avoid problems on Windows with trying to rename + * or delete an open file). */ Assert(readFile >= 0); Assert(readId == endLogId); @@ -3763,17 +3786,17 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg) readFile = -1; /* - * If the segment was fetched from archival storage, we want to replace - * the existing xlog segment (if any) with the archival version. This - * is because whatever is in XLogDir is very possibly older than what - * we have from the archives, since it could have come from restoring - * a PGDATA backup. In any case, the archival version certainly is - * more descriptive of what our current database state is, because that - * is what we replayed from. + * If the segment was fetched from archival storage, we want to + * replace the existing xlog segment (if any) with the archival + * version. This is because whatever is in XLogDir is very possibly + * older than what we have from the archives, since it could have come + * from restoring a PGDATA backup. In any case, the archival version + * certainly is more descriptive of what our current database state + * is, because that is what we replayed from. * * Note that if we are establishing a new timeline, ThisTimeLineID is - * already set to the new value, and so we will create a new file instead - * of overwriting any existing file. + * already set to the new value, and so we will create a new file + * instead of overwriting any existing file. */ snprintf(recoveryPath, MAXPGPATH, "%s/RECOVERYXLOG", XLogDir); XLogFilePath(xlogpath, ThisTimeLineID, endLogId, endLogSeg); @@ -3798,6 +3821,7 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg) * RECOVERYXLOG laying about, get rid of it. */ unlink(recoveryPath); /* ignore any error */ + /* * If we are establishing a new timeline, we have to copy data * from the last WAL segment of the old timeline to create a @@ -3809,22 +3833,22 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg) } /* - * Let's just make real sure there are not .ready or .done flags posted - * for the new segment. + * Let's just make real sure there are not .ready or .done flags + * posted for the new segment. */ XLogFileName(xlogpath, ThisTimeLineID, endLogId, endLogSeg); XLogArchiveCleanup(xlogpath); /* Get rid of any remaining recovered timeline-history file, too */ snprintf(recoveryPath, MAXPGPATH, "%s/RECOVERYHISTORY", XLogDir); - unlink(recoveryPath); /* ignore any error */ + unlink(recoveryPath); /* ignore any error */ /* - * Rename the config file out of the way, so that we don't accidentally - * re-enter archive recovery mode in a subsequent crash. + * Rename the config file out of the way, so that we don't + * accidentally re-enter archive recovery mode in a subsequent crash. */ - snprintf(recoveryCommandFile, MAXPGPATH, "%s/recovery.conf", DataDir); - snprintf(recoveryCommandDone, MAXPGPATH, "%s/recovery.done", DataDir); + snprintf(recoveryCommandFile, MAXPGPATH, "%s/recovery.conf", DataDir); + snprintf(recoveryCommandDone, MAXPGPATH, "%s/recovery.done", DataDir); unlink(recoveryCommandDone); if (rename(recoveryCommandFile, recoveryCommandDone) != 0) ereport(FATAL, @@ -3849,8 +3873,8 @@ static bool recoveryStopsHere(XLogRecord *record, bool *includeThis) { bool stopsHere; - uint8 record_info; - time_t recordXtime; + uint8 record_info; + time_t recordXtime; /* Do we have a PITR target at all? */ if (!recoveryTarget) @@ -3862,14 +3886,14 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis) record_info = record->xl_info & ~XLR_INFO_MASK; if (record_info == XLOG_XACT_COMMIT) { - xl_xact_commit *recordXactCommitData; + xl_xact_commit *recordXactCommitData; recordXactCommitData = (xl_xact_commit *) XLogRecGetData(record); recordXtime = recordXactCommitData->xtime; } else if (record_info == XLOG_XACT_ABORT) { - xl_xact_abort *recordXactAbortData; + xl_xact_abort *recordXactAbortData; recordXactAbortData = (xl_xact_abort *) XLogRecGetData(record); recordXtime = recordXactAbortData->xtime; @@ -3880,14 +3904,13 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis) if (recoveryTargetExact) { /* - * there can be only one transaction end record - * with this exact transactionid + * there can be only one transaction end record with this exact + * transactionid * - * when testing for an xid, we MUST test for - * equality only, since transactions are numbered - * in the order they start, not the order they - * complete. A higher numbered xid will complete - * before you about 50% of the time... + * when testing for an xid, we MUST test for equality only, since + * transactions are numbered in the order they start, not the + * order they complete. A higher numbered xid will complete before + * you about 50% of the time... */ stopsHere = (record->xl_xid == recoveryTargetXid); if (stopsHere) @@ -3896,11 +3919,9 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis) else { /* - * there can be many transactions that - * share the same commit time, so - * we stop after the last one, if we are - * inclusive, or stop at the first one - * if we are exclusive + * there can be many transactions that share the same commit time, + * so we stop after the last one, if we are inclusive, or stop at + * the first one if we are exclusive */ if (recoveryTargetInclusive) stopsHere = (recordXtime > recoveryTargetTime); @@ -3921,22 +3942,22 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis) if (recoveryStopAfter) ereport(LOG, (errmsg("recovery stopping after commit of transaction %u, time %s", - recoveryStopXid, str_time(recoveryStopTime)))); + recoveryStopXid, str_time(recoveryStopTime)))); else ereport(LOG, (errmsg("recovery stopping before commit of transaction %u, time %s", - recoveryStopXid, str_time(recoveryStopTime)))); + recoveryStopXid, str_time(recoveryStopTime)))); } else { if (recoveryStopAfter) ereport(LOG, (errmsg("recovery stopping after abort of transaction %u, time %s", - recoveryStopXid, str_time(recoveryStopTime)))); + recoveryStopXid, str_time(recoveryStopTime)))); else ereport(LOG, (errmsg("recovery stopping before abort of transaction %u, time %s", - recoveryStopXid, str_time(recoveryStopTime)))); + recoveryStopXid, str_time(recoveryStopTime)))); } } @@ -4009,14 +4030,14 @@ StartupXLOG(void) #endif /* - * Initialize on the assumption we want to recover to the same timeline - * that's active according to pg_control. + * Initialize on the assumption we want to recover to the same + * timeline that's active according to pg_control. */ recoveryTargetTLI = ControlFile->checkPointCopy.ThisTimeLineID; /* - * Check for recovery control file, and if so set up state for - * offline recovery + * Check for recovery control file, and if so set up state for offline + * recovery */ readRecoveryCommandFile(); @@ -4029,7 +4050,7 @@ StartupXLOG(void) * timeline. */ if (!list_member_int(expectedTLIs, - (int) ControlFile->checkPointCopy.ThisTimeLineID)) + (int) ControlFile->checkPointCopy.ThisTimeLineID)) ereport(FATAL, (errmsg("requested timeline %u is not a child of database system timeline %u", recoveryTargetTLI, @@ -4038,29 +4059,30 @@ StartupXLOG(void) if (read_backup_label(&checkPointLoc)) { /* - * When a backup_label file is present, we want to roll forward from - * the checkpoint it identifies, rather than using pg_control. + * When a backup_label file is present, we want to roll forward + * from the checkpoint it identifies, rather than using + * pg_control. */ record = ReadCheckpointRecord(checkPointLoc, 0, buffer); if (record != NULL) { ereport(LOG, (errmsg("checkpoint record is at %X/%X", - checkPointLoc.xlogid, checkPointLoc.xrecoff))); + checkPointLoc.xlogid, checkPointLoc.xrecoff))); InRecovery = true; /* force recovery even if SHUTDOWNED */ } else { ereport(PANIC, - (errmsg("could not locate required checkpoint record"), - errhint("If you are not restoring from a backup, try removing $PGDATA/backup_label."))); + (errmsg("could not locate required checkpoint record"), + errhint("If you are not restoring from a backup, try removing $PGDATA/backup_label."))); } } else { /* - * Get the last valid checkpoint record. If the latest one according - * to pg_control is broken, try the next-to-last one. + * Get the last valid checkpoint record. If the latest one + * according to pg_control is broken, try the next-to-last one. */ checkPointLoc = ControlFile->checkPoint; record = ReadCheckpointRecord(checkPointLoc, 1, buffer); @@ -4068,7 +4090,7 @@ StartupXLOG(void) { ereport(LOG, (errmsg("checkpoint record is at %X/%X", - checkPointLoc.xlogid, checkPointLoc.xrecoff))); + checkPointLoc.xlogid, checkPointLoc.xrecoff))); } else { @@ -4077,13 +4099,14 @@ StartupXLOG(void) if (record != NULL) { ereport(LOG, - (errmsg("using previous checkpoint record at %X/%X", - checkPointLoc.xlogid, checkPointLoc.xrecoff))); - InRecovery = true; /* force recovery even if SHUTDOWNED */ + (errmsg("using previous checkpoint record at %X/%X", + checkPointLoc.xlogid, checkPointLoc.xrecoff))); + InRecovery = true; /* force recovery even if + * SHUTDOWNED */ } else ereport(PANIC, - (errmsg("could not locate a valid checkpoint record"))); + (errmsg("could not locate a valid checkpoint record"))); } } @@ -4108,9 +4131,9 @@ StartupXLOG(void) ShmemVariableCache->oidCount = 0; /* - * We must replay WAL entries using the same TimeLineID they were created - * under, so temporarily adopt the TLI indicated by the checkpoint (see - * also xlog_redo()). + * We must replay WAL entries using the same TimeLineID they were + * created under, so temporarily adopt the TLI indicated by the + * checkpoint (see also xlog_redo()). */ ThisTimeLineID = checkPoint.ThisTimeLineID; @@ -4123,8 +4146,8 @@ StartupXLOG(void) checkPoint.undo = RecPtr; /* - * Check whether we need to force recovery from WAL. If it appears - * to have been a clean shutdown and we did not have a recovery.conf + * Check whether we need to force recovery from WAL. If it appears to + * have been a clean shutdown and we did not have a recovery.conf * file, then assume no recovery needed. */ if (XLByteLT(checkPoint.undo, RecPtr) || @@ -4219,7 +4242,7 @@ StartupXLOG(void) */ if (recoveryStopsHere(record, &recoveryApply)) { - needNewTimeLine = true; /* see below */ + needNewTimeLine = true; /* see below */ recoveryContinue = false; if (!recoveryApply) break; @@ -4242,6 +4265,7 @@ StartupXLOG(void) record = ReadRecord(NULL, LOG, buffer); } while (record != NULL && recoveryContinue); + /* * end of main redo apply loop */ @@ -4276,7 +4300,8 @@ StartupXLOG(void) if (needNewTimeLine) /* stopped because of stop request */ ereport(FATAL, (errmsg("requested recovery stop point is before end time of backup dump"))); - else /* ran off end of WAL */ + else +/* ran off end of WAL */ ereport(FATAL, (errmsg("WAL ends before end time of backup dump"))); } @@ -4284,10 +4309,10 @@ StartupXLOG(void) /* * Consider whether we need to assign a new timeline ID. * - * If we stopped short of the end of WAL during recovery, then we - * are generating a new timeline and must assign it a unique new ID. - * Otherwise, we can just extend the timeline we were in when we - * ran out of WAL. + * If we stopped short of the end of WAL during recovery, then we are + * generating a new timeline and must assign it a unique new ID. + * Otherwise, we can just extend the timeline we were in when we ran + * out of WAL. */ if (needNewTimeLine) { @@ -4302,8 +4327,8 @@ StartupXLOG(void) XLogCtl->ThisTimeLineID = ThisTimeLineID; /* - * We are now done reading the old WAL. Turn off archive fetching - * if it was active, and make a writable copy of the last WAL segment. + * We are now done reading the old WAL. Turn off archive fetching if + * it was active, and make a writable copy of the last WAL segment. * (Note that we also have a copy of the last block of the old WAL in * readBuf; we will use that below.) */ @@ -4361,7 +4386,7 @@ StartupXLOG(void) * XLogWrite()). * * Note: it might seem we should do AdvanceXLInsertBuffer() here, but - * this is sufficient. The first actual attempt to insert a log + * this is sufficient. The first actual attempt to insert a log * record will advance the insert state. */ XLogCtl->Write.curridx = NextBufIdx(0); @@ -4434,8 +4459,8 @@ StartupXLOG(void) XLogCloseRelationCache(); /* - * Now that we've checkpointed the recovery, it's safe to - * flush old backup_label, if present. + * Now that we've checkpointed the recovery, it's safe to flush + * old backup_label, if present. */ remove_backup_label(); } @@ -4504,7 +4529,7 @@ ReadCheckpointRecord(XLogRecPtr RecPtr, break; default: ereport(LOG, - (errmsg("invalid checkpoint link in backup_label file"))); + (errmsg("invalid checkpoint link in backup_label file"))); break; } return NULL; @@ -4557,7 +4582,7 @@ ReadCheckpointRecord(XLogRecPtr RecPtr, { case 1: ereport(LOG, - (errmsg("invalid xl_info in primary checkpoint record"))); + (errmsg("invalid xl_info in primary checkpoint record"))); break; case 2: ereport(LOG, @@ -4576,7 +4601,7 @@ ReadCheckpointRecord(XLogRecPtr RecPtr, { case 1: ereport(LOG, - (errmsg("invalid length of primary checkpoint record"))); + (errmsg("invalid length of primary checkpoint record"))); break; case 2: ereport(LOG, @@ -4791,8 +4816,8 @@ CreateCheckPoint(bool shutdown, bool force) * so there's a risk of deadlock. Need to find a better solution. See * pgsql-hackers discussion of 17-Dec-01. * - * XXX actually, the whole UNDO code is dead code and unlikely to ever - * be revived, so the lack of a good solution here is not troubling. + * XXX actually, the whole UNDO code is dead code and unlikely to ever be + * revived, so the lack of a good solution here is not troubling. */ #ifdef NOT_USED checkPoint.undo = GetUndoRecPtr(); @@ -4919,11 +4944,11 @@ CreateCheckPoint(bool shutdown, bool force) PreallocXlogFiles(recptr); /* - * Truncate pg_subtrans if possible. We can throw away all data before - * the oldest XMIN of any running transaction. No future transaction will - * attempt to reference any pg_subtrans entry older than that (see Asserts - * in subtrans.c). During recovery, though, we mustn't do this because - * StartupSUBTRANS hasn't been called yet. + * Truncate pg_subtrans if possible. We can throw away all data + * before the oldest XMIN of any running transaction. No future + * transaction will attempt to reference any pg_subtrans entry older + * than that (see Asserts in subtrans.c). During recovery, though, we + * mustn't do this because StartupSUBTRANS hasn't been called yet. */ if (!InRecovery) TruncateSUBTRANS(GetOldestXmin(true)); @@ -4974,8 +4999,10 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record) ShmemVariableCache->nextXid = checkPoint.nextXid; ShmemVariableCache->nextOid = checkPoint.nextOid; ShmemVariableCache->oidCount = 0; + /* - * TLI may change in a shutdown checkpoint, but it shouldn't decrease + * TLI may change in a shutdown checkpoint, but it shouldn't + * decrease */ if (checkPoint.ThisTimeLineID != ThisTimeLineID) { @@ -4984,7 +5011,7 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record) (int) checkPoint.ThisTimeLineID)) ereport(PANIC, (errmsg("unexpected timeline ID %u (after %u) in checkpoint record", - checkPoint.ThisTimeLineID, ThisTimeLineID))); + checkPoint.ThisTimeLineID, ThisTimeLineID))); /* Following WAL records should be run with new TLI */ ThisTimeLineID = checkPoint.ThisTimeLineID; } @@ -5071,8 +5098,7 @@ xlog_outrec(char *buf, XLogRecord *record) sprintf(buf + strlen(buf), ": %s", RmgrTable[record->xl_rmid].rm_name); } - -#endif /* WAL_DEBUG */ +#endif /* WAL_DEBUG */ /* @@ -5200,7 +5226,7 @@ pg_start_backup(PG_FUNCTION_ARGS) char *backupidstr; XLogRecPtr checkpointloc; XLogRecPtr startpoint; - time_t stamp_time; + time_t stamp_time; char strfbuf[128]; char labelfilepath[MAXPGPATH]; char xlogfilename[MAXFNAMELEN]; @@ -5209,24 +5235,26 @@ pg_start_backup(PG_FUNCTION_ARGS) struct stat stat_buf; FILE *fp; - if (!superuser()) + if (!superuser()) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("must be superuser to run a backup")))); backupidstr = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(backupid))); + PointerGetDatum(backupid))); + /* - * Force a CHECKPOINT. This is not strictly necessary, but it seems - * like a good idea to minimize the amount of past WAL needed to use the - * backup. Also, this guarantees that two successive backup runs - * will have different checkpoint positions and hence different history - * file names, even if nothing happened in between. + * Force a CHECKPOINT. This is not strictly necessary, but it seems + * like a good idea to minimize the amount of past WAL needed to use + * the backup. Also, this guarantees that two successive backup runs + * will have different checkpoint positions and hence different + * history file names, even if nothing happened in between. */ RequestCheckpoint(true); + /* * Now we need to fetch the checkpoint record location, and also its - * REDO pointer. The oldest point in WAL that would be needed to restore - * starting from the checkpoint is precisely the REDO pointer. + * REDO pointer. The oldest point in WAL that would be needed to + * restore starting from the checkpoint is precisely the REDO pointer. */ LWLockAcquire(ControlFileLock, LW_EXCLUSIVE); checkpointloc = ControlFile->checkPoint; @@ -5235,18 +5263,21 @@ pg_start_backup(PG_FUNCTION_ARGS) XLByteToSeg(startpoint, _logId, _logSeg); XLogFileName(xlogfilename, ThisTimeLineID, _logId, _logSeg); + /* - * We deliberately use strftime/localtime not the src/timezone functions, - * so that backup labels will consistently be recorded in the same - * timezone regardless of TimeZone setting. This matches elog.c's - * practice. + * We deliberately use strftime/localtime not the src/timezone + * functions, so that backup labels will consistently be recorded in + * the same timezone regardless of TimeZone setting. This matches + * elog.c's practice. */ stamp_time = time(NULL); strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S %Z", localtime(&stamp_time)); + /* - * Check for existing backup label --- implies a backup is already running + * Check for existing backup label --- implies a backup is already + * running */ snprintf(labelfilepath, MAXPGPATH, "%s/backup_label", DataDir); if (stat(labelfilepath, &stat_buf) != 0) @@ -5263,6 +5294,7 @@ pg_start_backup(PG_FUNCTION_ARGS) errmsg("a backup is already in progress"), errhint("If you're sure there is no backup in progress, remove file \"%s\" and try again.", labelfilepath))); + /* * Okay, write the file */ @@ -5283,13 +5315,14 @@ pg_start_backup(PG_FUNCTION_ARGS) (errcode_for_file_access(), errmsg("could not write file \"%s\": %m", labelfilepath))); + /* * We're done. As a convenience, return the starting WAL offset. */ snprintf(xlogfilename, sizeof(xlogfilename), "%X/%X", startpoint.xlogid, startpoint.xrecoff); result = DatumGetTextP(DirectFunctionCall1(textin, - CStringGetDatum(xlogfilename))); + CStringGetDatum(xlogfilename))); PG_RETURN_TEXT_P(result); } @@ -5308,7 +5341,7 @@ pg_stop_backup(PG_FUNCTION_ARGS) XLogCtlInsert *Insert = &XLogCtl->Insert; XLogRecPtr startpoint; XLogRecPtr stoppoint; - time_t stamp_time; + time_t stamp_time; char strfbuf[128]; char labelfilepath[MAXPGPATH]; char histfilepath[MAXPGPATH]; @@ -5321,10 +5354,11 @@ pg_stop_backup(PG_FUNCTION_ARGS) char ch; int ich; - if (!superuser()) + if (!superuser()) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("must be superuser to run a backup")))); + /* * Get the current end-of-WAL position; it will be unsafe to use this * dump to restore to a point in advance of this time. @@ -5335,16 +5369,18 @@ pg_stop_backup(PG_FUNCTION_ARGS) XLByteToSeg(stoppoint, _logId, _logSeg); XLogFileName(stopxlogfilename, ThisTimeLineID, _logId, _logSeg); + /* - * We deliberately use strftime/localtime not the src/timezone functions, - * so that backup labels will consistently be recorded in the same - * timezone regardless of TimeZone setting. This matches elog.c's - * practice. + * We deliberately use strftime/localtime not the src/timezone + * functions, so that backup labels will consistently be recorded in + * the same timezone regardless of TimeZone setting. This matches + * elog.c's practice. */ stamp_time = time(NULL); strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S %Z", localtime(&stamp_time)); + /* * Open the existing label file */ @@ -5361,9 +5397,11 @@ pg_stop_backup(PG_FUNCTION_ARGS) (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("a backup is not in progress"))); } + /* * Read and parse the START WAL LOCATION line (this code is pretty - * crude, but we are not expecting any variability in the file format). + * crude, but we are not expecting any variability in the file + * format). */ if (fscanf(lfp, "START WAL LOCATION: %X/%X (file %24s)%c", &startpoint.xlogid, &startpoint.xrecoff, startxlogfilename, @@ -5371,6 +5409,7 @@ pg_stop_backup(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("invalid data in file \"%s\"", labelfilepath))); + /* * Write the backup history file */ @@ -5396,6 +5435,7 @@ pg_stop_backup(PG_FUNCTION_ARGS) (errcode_for_file_access(), errmsg("could not write file \"%s\": %m", histfilepath))); + /* * Close and remove the backup label file */ @@ -5409,6 +5449,7 @@ pg_stop_backup(PG_FUNCTION_ARGS) (errcode_for_file_access(), errmsg("could not remove file \"%s\": %m", labelfilepath))); + /* * Notify archiver that history file may be archived immediately */ @@ -5418,13 +5459,14 @@ pg_stop_backup(PG_FUNCTION_ARGS) startpoint.xrecoff % XLogSegSize); XLogArchiveNotify(histfilepath); } + /* * We're done. As a convenience, return the ending WAL offset. */ snprintf(stopxlogfilename, sizeof(stopxlogfilename), "%X/%X", stoppoint.xlogid, stoppoint.xrecoff); result = DatumGetTextP(DirectFunctionCall1(textin, - CStringGetDatum(stopxlogfilename))); + CStringGetDatum(stopxlogfilename))); PG_RETURN_TEXT_P(result); } @@ -5433,7 +5475,7 @@ pg_stop_backup(PG_FUNCTION_ARGS) * * If we see a backup_label during recovery, we assume that we are recovering * from a backup dump file, and we therefore roll forward from the checkpoint - * identified by the label file, NOT what pg_control says. This avoids the + * identified by the label file, NOT what pg_control says. This avoids the * problem that pg_control might have been archived one or more checkpoints * later than the start of the dump, and so if we rely on it as the start * point, we will fail to restore a consistent database state. @@ -5476,10 +5518,11 @@ read_backup_label(XLogRecPtr *checkPointLoc) labelfilepath))); return false; /* it's not there, all is fine */ } + /* - * Read and parse the START WAL LOCATION and CHECKPOINT lines (this code - * is pretty crude, but we are not expecting any variability in the file - * format). + * Read and parse the START WAL LOCATION and CHECKPOINT lines (this + * code is pretty crude, but we are not expecting any variability in + * the file format). */ if (fscanf(lfp, "START WAL LOCATION: %X/%X (file %08X%16s)%c", &startpoint.xlogid, &startpoint.xrecoff, &tli, @@ -5498,6 +5541,7 @@ read_backup_label(XLogRecPtr *checkPointLoc) (errcode_for_file_access(), errmsg("could not read file \"%s\": %m", labelfilepath))); + /* * Try to retrieve the backup history file (no error if we can't) */ @@ -5511,24 +5555,24 @@ read_backup_label(XLogRecPtr *checkPointLoc) BackupHistoryFilePath(histfilepath, tli, _logId, _logSeg, startpoint.xrecoff % XLogSegSize); - fp = AllocateFile(histfilepath, "r"); + fp = AllocateFile(histfilepath, "r"); if (fp) { /* * Parse history file to identify stop point. */ if (fscanf(fp, "START WAL LOCATION: %X/%X (file %24s)%c", - &startpoint.xlogid, &startpoint.xrecoff, startxlogfilename, + &startpoint.xlogid, &startpoint.xrecoff, startxlogfilename, &ch) != 4 || ch != '\n') ereport(FATAL, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("invalid data in file \"%s\"", histfilename))); + errmsg("invalid data in file \"%s\"", histfilename))); if (fscanf(fp, "STOP WAL LOCATION: %X/%X (file %24s)%c", - &stoppoint.xlogid, &stoppoint.xrecoff, stopxlogfilename, + &stoppoint.xlogid, &stoppoint.xrecoff, stopxlogfilename, &ch) != 4 || ch != '\n') ereport(FATAL, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("invalid data in file \"%s\"", histfilename))); + errmsg("invalid data in file \"%s\"", histfilename))); recoveryMinXlogOffset = stoppoint; if (ferror(fp) || FreeFile(fp)) ereport(FATAL, diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 1791068d7a5..4f1ac8dde58 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.33 2004/08/29 04:12:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.34 2004/08/29 05:06:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -212,11 +212,11 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode) res->reldata.rd_node = rnode; /* - * We set up the lockRelId in case anything tries to lock the dummy - * relation. Note that this is fairly bogus since relNode may be - * different from the relation's OID. It shouldn't really matter - * though, since we are presumably running by ourselves and can't - * have any lock conflicts ... + * We set up the lockRelId in case anything tries to lock the + * dummy relation. Note that this is fairly bogus since relNode + * may be different from the relation's OID. It shouldn't really + * matter though, since we are presumably running by ourselves and + * can't have any lock conflicts ... */ res->reldata.rd_lockInfo.lockRelId.dbId = rnode.dbNode; res->reldata.rd_lockInfo.lockRelId.relId = rnode.relNode; @@ -234,14 +234,15 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode) res->reldata.rd_targblock = InvalidBlockNumber; res->reldata.rd_smgr = smgropen(res->reldata.rd_node); + /* * Create the target file if it doesn't already exist. This lets * us cope if the replay sequence contains writes to a relation * that is later deleted. (The original coding of this routine * would instead return NULL, causing the writes to be suppressed. - * But that seems like it risks losing valuable data if the filesystem - * loses an inode during a crash. Better to write the data until we - * are actually told to delete the file.) + * But that seems like it risks losing valuable data if the + * filesystem loses an inode during a crash. Better to write the + * data until we are actually told to delete the file.) */ smgrcreate(res->reldata.rd_smgr, res->reldata.rd_istemp, true); } |