-
Notifications
You must be signed in to change notification settings - Fork 15
/
spock_sync.h
95 lines (76 loc) · 3.06 KB
/
spock_sync.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*-------------------------------------------------------------------------
*
* spock_sync.h
* table synchronization functions
*
* Copyright (c) 2022-2023, pgEdge, Inc.
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, The Regents of the University of California
*
*-------------------------------------------------------------------------
*/
#ifndef SPOCK_SYNC_H
#define SPOCK_SYNC_H
#include "libpq-fe.h"
#include "nodes/primnodes.h"
#include "spock_node.h"
typedef struct SpockSyncStatus
{
char kind;
Oid subid;
NameData nspname;
NameData relname;
char status;
XLogRecPtr statuslsn; /* remote lsn of the state change used for
* synchronization coordination */
} SpockSyncStatus;
#define SYNC_KIND_INIT 'i'
#define SYNC_KIND_FULL 'f'
#define SYNC_KIND_STRUCTURE 's'
#define SYNC_KIND_DATA 'd'
#define SyncKindData(kind) \
(kind == SYNC_KIND_FULL || kind == SYNC_KIND_DATA)
#define SyncKindStructure(kind) \
(kind == SYNC_KIND_FULL || kind == SYNC_KIND_STRUCTURE)
#define SYNC_STATUS_NONE '\0' /* No sync. */
#define SYNC_STATUS_INIT 'i' /* Ask for sync. */
#define SYNC_STATUS_STRUCTURE 's' /* Sync structure */
#define SYNC_STATUS_DATA 'd' /* Data sync. */
#define SYNC_STATUS_CONSTRAINTS 'c' /* Constraint sync (post-data structure). */
#define SYNC_STATUS_SYNCWAIT 'w' /* Table sync is waiting to get OK from main thread. */
#define SYNC_STATUS_CATCHUP 'u' /* Catching up. */
#define SYNC_STATUS_SYNCDONE 'y' /* Synchronization finished (at lsn). */
#define SYNC_STATUS_READY 'r' /* Done. */
extern void spock_sync_worker_finish(void);
extern void spock_sync_subscription(SpockSubscription *sub);
extern char spock_sync_table(SpockSubscription *sub, RangeVar *table, XLogRecPtr *status_lsn);
extern void create_local_sync_status(SpockSyncStatus *sync);
extern void drop_subscription_sync_status(Oid subid);
extern SpockSyncStatus *get_subscription_sync_status(Oid subid,
bool missing_ok);
extern void set_subscription_sync_status(Oid subid, char status);
extern void drop_table_sync_status(const char *nspname, const char *relname);
extern void drop_table_sync_status_for_sub(Oid subid, const char *nspname,
const char *relname);
extern SpockSyncStatus *get_table_sync_status(Oid subid,
const char *schemaname,
const char *relname,
bool missing_ok);
extern void set_table_sync_status(Oid subid, const char *schemaname,
const char *relname, char status,
XLogRecPtr status_lsn);
extern List *get_unsynced_tables(Oid subid);
/* For interface compat with spk3 */
inline static void free_sync_status(SpockSyncStatus *sync)
{
pfree(sync);
}
extern bool wait_for_sync_status_change(Oid subid, const char *nspname,
const char *relname, char desired_state,
XLogRecPtr *status_lsn);
extern void truncate_table(char *nspname, char *relname);
extern List *get_subscription_tables(Oid subid);
#ifdef WIN32
extern void QuoteWindowsArgv(StringInfo cmdline, const char * argv[]);
#endif
#endif /* SPOCK_SYNC_H */