Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5713f03

Browse files
committed
Improve API of GenericXLogRegister().
Rename this function to GenericXLogRegisterBuffer() to make it clearer what it does, and leave room for other sorts of "register" actions in future. Also, replace its "bool isNew" argument with an integer flags argument, so as to allow adding more flags in future without an API break. Alexander Korotkov, adjusted slightly by me
1 parent bdf7db8 commit 5713f03

File tree

6 files changed

+41
-31
lines changed

6 files changed

+41
-31
lines changed

contrib/bloom/blinsert.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ flushCachedPage(Relation index, BloomBuildState *buildstate)
4949
GenericXLogState *state;
5050

5151
state = GenericXLogStart(index);
52-
page = GenericXLogRegister(state, buffer, true);
52+
page = GenericXLogRegisterBuffer(state, buffer, GENERIC_XLOG_FULL_IMAGE);
5353
memcpy(page, buildstate->data, BLCKSZ);
5454
GenericXLogFinish(state);
5555
UnlockReleaseBuffer(buffer);
@@ -221,7 +221,7 @@ blinsert(Relation index, Datum *values, bool *isnull,
221221
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
222222

223223
state = GenericXLogStart(index);
224-
page = GenericXLogRegister(state, buffer, false);
224+
page = GenericXLogRegisterBuffer(state, buffer, 0);
225225

226226
if (BloomPageAddItem(&blstate, page, itup))
227227
{
@@ -268,7 +268,7 @@ blinsert(Relation index, Datum *values, bool *isnull,
268268
state = GenericXLogStart(index);
269269

270270
/* get modifiable copy of metapage */
271-
metaPage = GenericXLogRegister(state, metaBuffer, false);
271+
metaPage = GenericXLogRegisterBuffer(state, metaBuffer, 0);
272272
metaData = BloomPageGetMeta(metaPage);
273273

274274
if (nStart >= metaData->nEnd)
@@ -279,7 +279,7 @@ blinsert(Relation index, Datum *values, bool *isnull,
279279

280280
buffer = ReadBuffer(index, blkno);
281281
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
282-
page = GenericXLogRegister(state, buffer, false);
282+
page = GenericXLogRegisterBuffer(state, buffer, 0);
283283

284284
if (BloomPageAddItem(&blstate, page, itup))
285285
{
@@ -305,7 +305,7 @@ blinsert(Relation index, Datum *values, bool *isnull,
305305
*/
306306
buffer = BloomNewBuffer(index);
307307

308-
page = GenericXLogRegister(state, buffer, true);
308+
page = GenericXLogRegisterBuffer(state, buffer, GENERIC_XLOG_FULL_IMAGE);
309309
BloomInitPage(page, 0);
310310

311311
if (!BloomPageAddItem(&blstate, page, itup))

contrib/bloom/blutils.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ PG_FUNCTION_INFO_V1(blhandler);
3939
/* Kind of relation optioms for bloom index */
4040
static relopt_kind bl_relopt_kind;
4141

42-
static int32 myRand();
42+
static int32 myRand(void);
4343
static void mySrand(uint32 seed);
4444

4545
/*
@@ -173,15 +173,16 @@ initBloomState(BloomState *state, Relation index)
173173
static int32 next;
174174

175175
static int32
176-
myRand()
176+
myRand(void)
177177
{
178-
/*
178+
/*----------
179179
* Compute x = (7^5 * x) mod (2^31 - 1)
180180
* without overflowing 31 bits:
181181
* (2^31 - 1) = 127773 * (7^5) + 2836
182182
* From "Random number generators: good ones are hard to find",
183183
* Park and Miller, Communications of the ACM, vol. 31, no. 10,
184184
* October 1988, p. 1195.
185+
*----------
185186
*/
186187
int32 hi, lo, x;
187188

@@ -418,7 +419,7 @@ BloomInitMetapage(Relation index)
418419

419420
/* Initialize contents of meta page */
420421
state = GenericXLogStart(index);
421-
metaPage = GenericXLogRegister(state, metaBuffer, true);
422+
metaPage = GenericXLogRegisterBuffer(state, metaBuffer, GENERIC_XLOG_FULL_IMAGE);
422423

423424
BloomInitPage(metaPage, BLOOM_META);
424425
metadata = BloomPageGetMeta(metaPage);

contrib/bloom/blvacuum.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
6565

6666
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
6767
gxlogState = GenericXLogStart(index);
68-
page = GenericXLogRegister(gxlogState, buffer, false);
68+
page = GenericXLogRegisterBuffer(gxlogState, buffer, 0);
6969

7070
if (BloomPageIsDeleted(page))
7171
{
@@ -145,7 +145,7 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
145145
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
146146

147147
gxlogState = GenericXLogStart(index);
148-
page = GenericXLogRegister(gxlogState, buffer, false);
148+
page = GenericXLogRegisterBuffer(gxlogState, buffer, 0);
149149

150150
metaData = BloomPageGetMeta(page);
151151
memcpy(metaData->notFullPage, notFullPage, sizeof(BlockNumber) * countPage);

doc/src/sgml/generic-wal.sgml

+18-14
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@
3131

3232
<listitem>
3333
<para>
34-
<function>page = GenericXLogRegister(state, buffer, isNew)</> &mdash;
35-
register a buffer to be modified within the current generic WAL
34+
<function>page = GenericXLogRegisterBuffer(state, buffer, flags)</>
35+
&mdash; register a buffer to be modified within the current generic WAL
3636
record. This function returns a pointer to a temporary copy of the
3737
buffer's page, where modifications should be made. (Do not modify the
38-
buffer's contents directly.) The third argument indicates if the page
39-
is new; if true, this will result in a full-page image rather than a
40-
delta update being included in the WAL record.
41-
<function>GenericXLogRegister</> can be repeated if the WAL-logged
42-
action needs to modify multiple pages.
38+
buffer's contents directly.) The third argument is a bitmask of flags
39+
applicable to the operation. Currently the only such flag is
40+
<literal>GENERIC_XLOG_FULL_IMAGE</>, which indicates that a full-page
41+
image rather than a delta update should be included in the WAL record.
42+
Typically this flag would be set if the page is new or has been
43+
rewritten completely.
44+
<function>GenericXLogRegisterBuffer</> can be repeated if the
45+
WAL-logged action needs to modify multiple pages.
4346
</para>
4447
</listitem>
4548

@@ -71,13 +74,13 @@
7174
<itemizedlist>
7275
<listitem>
7376
<para>
74-
No direct modifications of buffers are allowed! All modifications
75-
must be done in copies acquired from <function>GenericXLogRegister()</>.
77+
No direct modifications of buffers are allowed! All modifications must
78+
be done in copies acquired from <function>GenericXLogRegisterBuffer()</>.
7679
In other words, code that makes generic WAL records should never call
7780
<function>BufferGetPage()</> for itself. However, it remains the
7881
caller's responsibility to pin/unpin and lock/unlock the buffers at
7982
appropriate times. Exclusive lock must be held on each target buffer
80-
from before <function>GenericXLogRegister()</> until after
83+
from before <function>GenericXLogRegisterBuffer()</> until after
8184
<function>GenericXLogFinish()</>.
8285
</para>
8386
</listitem>
@@ -145,10 +148,11 @@
145148

146149
<listitem>
147150
<para>
148-
If a registered buffer is not new, the generic WAL record contains
149-
a delta between the old and the new page images. This delta is based
150-
on byte-by-byte comparison. This is not very compact for the case of
151-
moving data within a page, and might be improved in the future.
151+
If <literal>GENERIC_XLOG_FULL_IMAGE</> is not specified for a
152+
registered buffer, the generic WAL record contains a delta between
153+
the old and the new page images. This delta is based on byte-by-byte
154+
comparison. This is not very compact for the case of moving data
155+
within a page, and might be improved in the future.
152156
</para>
153157
</listitem>
154158
</itemizedlist>

src/backend/access/transam/generic_xlog.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
typedef struct
5151
{
5252
Buffer buffer; /* registered buffer */
53-
bool fullImage; /* are we taking a full image of this page? */
53+
int flags; /* flags for this buffer */
5454
int deltaLen; /* space consumed in delta field */
5555
char image[BLCKSZ]; /* copy of page image for modification */
5656
char delta[MAX_DELTA_SIZE]; /* delta between page images */
@@ -280,9 +280,11 @@ GenericXLogStart(Relation relation)
280280
* is what the caller should modify.
281281
*
282282
* If the buffer is already registered, just return its existing entry.
283+
* (It's not very clear what to do with the flags in such a case, but
284+
* for now we stay with the original flags.)
283285
*/
284286
Page
285-
GenericXLogRegister(GenericXLogState *state, Buffer buffer, bool isNew)
287+
GenericXLogRegisterBuffer(GenericXLogState *state, Buffer buffer, int flags)
286288
{
287289
int block_id;
288290

@@ -295,7 +297,7 @@ GenericXLogRegister(GenericXLogState *state, Buffer buffer, bool isNew)
295297
{
296298
/* Empty slot, so use it (there cannot be a match later) */
297299
page->buffer = buffer;
298-
page->fullImage = isNew;
300+
page->flags = flags;
299301
memcpy(page->image,
300302
BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST),
301303
BLCKSZ);
@@ -347,7 +349,7 @@ GenericXLogFinish(GenericXLogState *state)
347349
BGP_NO_SNAPSHOT_TEST);
348350
pageHeader = (PageHeader) pageData->image;
349351

350-
if (pageData->fullImage)
352+
if (pageData->flags & GENERIC_XLOG_FULL_IMAGE)
351353
{
352354
/*
353355
* A full-page image does not require us to supply any xlog

src/include/access/generic_xlog.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222

2323
#define MAX_GENERIC_XLOG_PAGES XLR_NORMAL_MAX_BLOCK_ID
2424

25+
/* Flag bits for GenericXLogRegisterBuffer */
26+
#define GENERIC_XLOG_FULL_IMAGE 0x0001 /* write full-page image */
27+
2528
/* state of generic xlog record construction */
2629
struct GenericXLogState;
2730
typedef struct GenericXLogState GenericXLogState;
2831

2932
/* API for construction of generic xlog records */
3033
extern GenericXLogState *GenericXLogStart(Relation relation);
31-
extern Page GenericXLogRegister(GenericXLogState *state, Buffer buffer,
32-
bool isNew);
34+
extern Page GenericXLogRegisterBuffer(GenericXLogState *state, Buffer buffer,
35+
int flags);
3336
extern XLogRecPtr GenericXLogFinish(GenericXLogState *state);
3437
extern void GenericXLogAbort(GenericXLogState *state);
3538

0 commit comments

Comments
 (0)