Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*-------------------------------------------------------------------------
 *
 * repack_internal.h
 *    header for REPACK internals
 *
 * Copyright (c) 2026, PostgreSQL Global Development Group
 *
 * src/include/commands/repack_internal.h
 *
 *-------------------------------------------------------------------------
 */
#ifndef REPACK_INTERNAL_H
#define REPACK_INTERNAL_H
 
#include "nodes/execnodes.h"
#include "replication/decode.h"
#include "postmaster/bgworker.h"
#include "replication/logical.h"
#include "storage/buffile.h"
#include "storage/sharedfileset.h"
#include "storage/shm_mq.h"
#include "utils/resowner.h"
 
/*
 * The type of a change stored in the output files.
 */
typedef char ConcurrentChangeKind;
 
#define     CHANGE_INSERT       'i'
#define     CHANGE_UPDATE_OLD   'u'
#define     CHANGE_UPDATE_NEW   'U'
#define     CHANGE_DELETE       'd'
 
/*
 * Logical decoding state.
 *
 * The output plugin uses it to store the data changes that it decodes from
 * WAL while the table contents is being copied to a new storage.
 */
typedef struct RepackDecodingState
{
    /* The relation whose changes we're decoding. */
    Oid         relid;
 
    /* Per-change memory context. */
    MemoryContext change_cxt;
 
    /* A tuple slot used to pass tuples back and forth */
    TupleTableSlot *slot;
 
    /*
     * Memory context and resource owner of the decoding worker's transaction.
     */
    MemoryContext worker_cxt;
    ResourceOwner worker_resowner;
 
    /* The current output file. */
    BufFile    *file;
} RepackDecodingState;
 
/*
 * Shared memory used for communication between the backend running REPACK and
 * the worker that performs logical decoding of data changes.
 */
typedef struct DecodingWorkerShared
{
    /* Is the decoding initialized? */
    bool        initialized;
 
    /*
     * Once the worker has reached this LSN, it should close the current
     * output file and either create a new one or exit, according to the field
     * 'done'. If the value is InvalidXLogRecPtr, the worker should decode all
     * the WAL available and keep checking this field. It is ok if the worker
     * had already decoded records whose LSN is >= lsn_upto before this field
     * has been set.
     */
    XLogRecPtr  lsn_upto;
 
    /* Exit after closing the current file? */
    bool        done;
 
    /* The output is stored here. */
    SharedFileSet sfs;
 
    /* Number of the last file exported by the worker. */
    int         last_exported;
 
    /* Synchronize access to the fields above. */
    slock_t     mutex;
 
    /* Database to connect to. */
    Oid         dbid;
 
    /* Role to connect as. */
    Oid         roleid;
 
    /* Settings to use in the worker */
    int         lock_timeout;
    int         transaction_timeout;
    int         temp_file_limit;
 
    /* Relation from which data changes to decode. */
    Oid         relid;
 
    /* CV the backend waits on */
    ConditionVariable cv;
 
    /* Info to signal the backend. */
    pid_t       backend_pid;
    ProcNumber  backend_proc_number;
 
    /*
     * Memory the queue is located in.
     *
     * For considerations on the value see the comments of
     * PARALLEL_ERROR_QUEUE_SIZE.
     */
#define REPACK_ERROR_QUEUE_SIZE         16384
    char        error_queue[FLEXIBLE_ARRAY_MEMBER];
} DecodingWorkerShared;
 
extern void DecodingWorkerFileName(char *fname, Oid relid, uint32 seq);
 
 
#endif                          /* REPACK_INTERNAL_H */