PostgreSQL Source Code  git master
rewind_source.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * rewind_source.h
4  * Abstraction for fetching from source server.
5  *
6  * The source server can be either a libpq connection to a live system,
7  * or a local data directory. The 'rewind_source' struct abstracts the
8  * operations to fetch data from the source system, so that the rest of
9  * the code doesn't need to care what kind of a source its dealing with.
10  *
11  * Copyright (c) 2013-2021, PostgreSQL Global Development Group
12  *
13  *-------------------------------------------------------------------------
14  */
15 #ifndef REWIND_SOURCE_H
16 #define REWIND_SOURCE_H
17 
18 #include "access/xlogdefs.h"
19 #include "file_ops.h"
20 #include "filemap.h"
21 #include "libpq-fe.h"
22 
23 typedef struct rewind_source
24 {
25  /*
26  * Traverse all files in the source data directory, and call 'callback' on
27  * each file.
28  */
29  void (*traverse_files) (struct rewind_source *,
31 
32  /*
33  * Fetch a single file into a malloc'd buffer. The file size is returned
34  * in *filesize. The returned buffer is always zero-terminated, which is
35  * handy for text files.
36  */
37  char *(*fetch_file) (struct rewind_source *, const char *path,
38  size_t *filesize);
39 
40  /*
41  * Request to fetch (part of) a file in the source system, specified by an
42  * offset and length, and write it to the same offset in the corresponding
43  * target file. The source implementation may queue up the request and
44  * execute it later when convenient. Call finish_fetch() to flush the
45  * queue and execute all requests.
46  */
47  void (*queue_fetch_range) (struct rewind_source *, const char *path,
48  off_t offset, size_t len);
49 
50  /*
51  * Execute all requests queued up with queue_fetch_range().
52  */
53  void (*finish_fetch) (struct rewind_source *);
54 
55  /*
56  * Get the current WAL insert position in the source system.
57  */
59 
60  /*
61  * Free this rewind_source object.
62  */
63  void (*destroy) (struct rewind_source *);
64 
66 
67 /* in libpq_source.c */
69 
70 /* in local_source.c */
71 extern rewind_source *init_local_source(const char *datadir);
72 
73 #endif /* FETCH_H */
void(* finish_fetch)(struct rewind_source *)
Definition: rewind_source.h:53
rewind_source * init_local_source(const char *datadir)
Definition: local_source.c:38
void(* process_file_callback_t)(const char *path, file_type_t type, size_t size, const char *link_target)
Definition: file_ops.h:26
struct rewind_source rewind_source
void(* traverse_files)(struct rewind_source *, process_file_callback_t callback)
Definition: rewind_source.h:29
rewind_source * init_libpq_source(PGconn *conn)
Definition: libpq_source.c:81
PGconn * conn
Definition: streamutil.c:54
XLogRecPtr(* get_current_wal_insert_lsn)(struct rewind_source *)
Definition: rewind_source.h:58
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
char * datadir
void(* queue_fetch_range)(struct rewind_source *, const char *path, off_t offset, size_t len)
Definition: rewind_source.h:47
void(* destroy)(struct rewind_source *)
Definition: rewind_source.h:63
uint64 XLogRecPtr
Definition: xlogdefs.h:21