PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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
23typedef struct rewind_source
24{
25 /*
26 * Traverse all files in the source data directory, and call 'callback' on
27 * each file.
28 */
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 * Like queue_fetch_range(), but requests replacing the whole local file
52 * from the source system. 'len' is the expected length of the file,
53 * although when the source is a live server, the file may change
54 * concurrently. The implementation is not obliged to copy more than 'len'
55 * bytes, even if the file is larger. However, to avoid copying a
56 * truncated version of the file, which can cause trouble if e.g. a
57 * configuration file is modified concurrently, the implementation should
58 * try to copy the whole file, even if it's larger than expected.
59 */
60 void (*queue_fetch_file) (struct rewind_source *, const char *path,
61 size_t len);
62
63 /*
64 * Execute all requests queued up with queue_fetch_range().
65 */
67
68 /*
69 * Get the current WAL insert position in the source system.
70 */
72
73 /*
74 * Free this rewind_source object.
75 */
76 void (*destroy) (struct rewind_source *);
77
79
80/* in libpq_source.c */
82
83/* in local_source.c */
84extern rewind_source *init_local_source(const char *datadir);
85
86#endif /* REWIND_SOURCE_H */
void(* process_file_callback_t)(const char *path, file_type_t type, size_t size, const char *link_target)
Definition file_ops.h:26
const void size_t len
char * datadir
static int fb(int x)
rewind_source * init_local_source(const char *datadir)
rewind_source * init_libpq_source(PGconn *conn)
PGconn * conn
Definition streamutil.c:52
void(* queue_fetch_file)(struct rewind_source *, const char *path, size_t len)
void(* traverse_files)(struct rewind_source *, process_file_callback_t callback)
void(* finish_fetch)(struct rewind_source *)
XLogRecPtr(* get_current_wal_insert_lsn)(struct rewind_source *)
void(* queue_fetch_range)(struct rewind_source *, const char *path, off_t offset, size_t len)
void(* destroy)(struct rewind_source *)
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
uint64 XLogRecPtr
Definition xlogdefs.h:21