mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
walmethods.c/h: Make Walfile a struct, rather than a void *
This makes the curent file position and pathname visible in a generic way, so we no longer need current_walfile_name global variable or the get_current_pos() method. Since that purported to be able to fail but never actually did, this also lets us get rid of some unnecessary error-handling code. One risk of this change is that the get_current_pos() method previously cleared the error indicator, and that will no longer happen with the new approach. I looked for a way that this could cause problems and did not find one. The previous code was confused about whether "Walfile" was the implementation-dependent structure representing a WAL file or whether it was a pointer to that stucture. Some of the code used it one way, and some in the other. The compiler tolerated that because void * is interchangeable with void **, but now that Walfile is a struct, it's necessary to be consistent. Hence, some references to "Walfile" have been converted to "Walfile *". Discussion: http://postgr.es/m/CA+TgmoZS0Kw98fOoAcGz8B9iDhdqB4Be4e=vDZaJZ5A-xMYBqA@mail.gmail.com
This commit is contained in:
@@ -11,7 +11,20 @@
|
||||
|
||||
#include "common/compression.h"
|
||||
|
||||
typedef void *Walfile;
|
||||
struct WalWriteMethod;
|
||||
typedef struct WalWriteMethod WalWriteMethod;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
off_t currpos;
|
||||
char *pathname;
|
||||
/*
|
||||
* MORE DATA FOLLOWS AT END OF STRUCT
|
||||
*
|
||||
* Each WalWriteMethod is expected to embed this as the first member of
|
||||
* a larger struct with method-specific fields following.
|
||||
*/
|
||||
} Walfile;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -30,7 +43,6 @@ typedef enum
|
||||
* care not to clobber errno between a failed method call and use of
|
||||
* getlasterror() to retrieve the message.
|
||||
*/
|
||||
typedef struct WalWriteMethod WalWriteMethod;
|
||||
struct WalWriteMethod
|
||||
{
|
||||
/*
|
||||
@@ -39,13 +51,13 @@ struct WalWriteMethod
|
||||
* automatically renamed in close(). If pad_to_size is specified, the file
|
||||
* will be padded with NUL up to that size, if supported by the Walmethod.
|
||||
*/
|
||||
Walfile (*open_for_write) (const char *pathname, const char *temp_suffix, size_t pad_to_size);
|
||||
Walfile *(*open_for_write) (const char *pathname, const char *temp_suffix, size_t pad_to_size);
|
||||
|
||||
/*
|
||||
* Close an open Walfile, using one or more methods for handling automatic
|
||||
* unlinking etc. Returns 0 on success, other values for error.
|
||||
*/
|
||||
int (*close) (Walfile f, WalCloseMethod method);
|
||||
int (*close) (Walfile *f, WalCloseMethod method);
|
||||
|
||||
/* Check if a file exist */
|
||||
bool (*existsfile) (const char *pathname);
|
||||
@@ -66,15 +78,12 @@ struct WalWriteMethod
|
||||
* Write count number of bytes to the file, and return the number of bytes
|
||||
* actually written or -1 for error.
|
||||
*/
|
||||
ssize_t (*write) (Walfile f, const void *buf, size_t count);
|
||||
|
||||
/* Return the current position in a file or -1 on error */
|
||||
off_t (*get_current_pos) (Walfile f);
|
||||
ssize_t (*write) (Walfile *f, const void *buf, size_t count);
|
||||
|
||||
/*
|
||||
* fsync the contents of the specified file. Returns 0 on success.
|
||||
*/
|
||||
int (*sync) (Walfile f);
|
||||
int (*sync) (Walfile *f);
|
||||
|
||||
/*
|
||||
* Clean up the Walmethod, closing any shared resources. For methods like
|
||||
|
||||
Reference in New Issue
Block a user