@@ -19,19 +19,63 @@ typedef enum
19
19
CLOSE_NO_RENAME
20
20
} WalCloseMethod ;
21
21
22
+ /*
23
+ * A WalWriteMethod structure represents the different methods used
24
+ * to write the streaming WAL as it's received.
25
+ *
26
+ * All methods that have a failure return indicator will set state
27
+ * allowing the getlasterror() method to return a suitable message.
28
+ * Commonly, errno is this state (or part of it); so callers must take
29
+ * care not to clobber errno between a failed method call and use of
30
+ * getlasterror() to retrieve the message.
31
+ */
22
32
typedef struct WalWriteMethod WalWriteMethod ;
23
33
struct WalWriteMethod
24
34
{
35
+ /*
36
+ * Open a target file. Returns Walfile, or NULL if open failed. If a temp
37
+ * suffix is specified, a file with that name will be opened, and then
38
+ * automatically renamed in close(). If pad_to_size is specified, the file
39
+ * will be padded with NUL up to that size, if supported by the Walmethod.
40
+ */
25
41
Walfile (* open_for_write ) (const char * pathname , const char * temp_suffix , size_t pad_to_size );
42
+
43
+ /*
44
+ * Close an open Walfile, using one or more methods for handling automatic
45
+ * unlinking etc. Returns 0 on success, other values for error.
46
+ */
26
47
int (* close ) (Walfile f , WalCloseMethod method );
48
+
49
+ /* Check if a file exist */
27
50
bool (* existsfile ) (const char * pathname );
51
+
52
+ /* Return the size of a file, or -1 on failure. */
28
53
ssize_t (* get_file_size ) (const char * pathname );
29
54
55
+ /*
56
+ * Write count number of bytes to the file, and return the number of bytes
57
+ * actually written or -1 for error.
58
+ */
30
59
ssize_t (* write ) (Walfile f , const void * buf , size_t count );
60
+
61
+ /* Return the current position in a file or -1 on error */
31
62
off_t (* get_current_pos ) (Walfile f );
63
+
64
+ /*
65
+ * fsync the contents of the specified file. Returns 0 on success.
66
+ */
32
67
int (* sync ) (Walfile f );
68
+
69
+ /*
70
+ * Clean up the Walmethod, closing any shared resources. For methods like
71
+ * tar, this includes writing updated headers. Returns true if the
72
+ * close/write/sync of shared resources succeeded, otherwise returns false
73
+ * (but the resources are still closed).
74
+ */
33
75
bool (* finish ) (void );
34
- char * (* getlasterror ) (void );
76
+
77
+ /* Return a text for the last error in this Walfile */
78
+ const char * (* getlasterror ) (void );
35
79
};
36
80
37
81
/*
0 commit comments