-
Notifications
You must be signed in to change notification settings - Fork 3
/
yezzey--1.8--1.8.1.sql
143 lines (118 loc) · 3.71 KB
/
yezzey--1.8--1.8.1.sql
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
-- New utilities & functions
CREATE OR REPLACE FUNCTION yezzey_vacuum_garbage(
confirm BOOLEAN DEFAULT FALSE,
crazyDrop BOOLEAN DEFAULT FALSE
) RETURNS void
AS 'MODULE_PATHNAME'
VOLATILE
EXECUTE ON ALL SEGMENTS
LANGUAGE C STRICT;
CREATE OR REPLACE FUNCTION yezzey_vacuum_relation(
reloid OID,
confirm BOOLEAN DEFAULT FALSE,
crazyDrop BOOLEAN DEFAULT FALSE
) RETURNS void
AS 'MODULE_PATHNAME'
VOLATILE
EXECUTE ON ALL SEGMENTS
LANGUAGE C STRICT;
CREATE OR REPLACE FUNCTION yezzey_vacuum_relation(
relname TEXT,
confirm BOOLEAN DEFAULT FALSE,
crazyDrop BOOLEAN DEFAULT FALSE
) RETURNS void
AS $$ SELECT yezzey_vacuum_relation(relname::regclass::oid, confirm, crazyDrop) $$
LANGUAGE SQL;
CREATE OR REPLACE FUNCTION yezzey.yezzey_binary_upgrade_1_8_to_1_8_1() RETURNS void
AS 'MODULE_PATHNAME'
VOLATILE
EXECUTE ON ALL SEGMENTS
LANGUAGE C STRICT;
CREATE OR REPLACE FUNCTION yezzey.yezzey_binary_upgrade_1_8_to_1_8_1_m() RETURNS void
AS 'MODULE_PATHNAME','yezzey_binary_upgrade_1_8_to_1_8_1'
VOLATILE
EXECUTE ON MASTER
LANGUAGE C STRICT;
CREATE OR REPLACE FUNCTION yezzey_vacuum_garbage_relation(
i_offload_nspname TEXT,
i_offload_relname TEXT,
confirm BOOLEAN DEFAULT FALSE,
crazyDrop BOOLEAN DEFAULT FALSE
) RETURNS void
AS $$
DECLARE
v_reloid OID;
BEGIN
SELECT
oid
FROM
pg_catalog.pg_class
INTO v_reloid
WHERE
relname = i_offload_relname AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = i_offload_nspname);
PERFORM yezzey_vacuum_relation(
v_reloid,confirm,crazyDrop
);
END;
$$
LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION
yezzey_vacuum_garbage_relation(
i_offload_relname TEXT,
confirm BOOLEAN DEFAULT FALSE,
crazyDrop BOOLEAN DEFAULT FALSE)
RETURNS VOID
AS $$
BEGIN
PERFORM yezzey_vacuum_garbage_relation('public', i_offload_relname, confirm, crazyDrop);
END;
$$
LANGUAGE PLPGSQL;
-- will preserve NULL distrib policy
CREATE TABLE yezzey.yezzey_virtual_index_stale AS select * from yezzey.yezzey_virtual_index limit 0;
CREATE TABLE yezzey.offload_metadata_stale AS select * from yezzey.offload_metadata limit 0;
CREATE OR REPLACE FUNCTION
yezzey.fixup_stale_data() RETURNS VOID
AS
$$
WITH stale_data AS (
SELECT * FROM
yezzey.yezzey_virtual_index vi
WHERE NOT EXISTS (SELECT 1 FROM pg_class WHERE relfilenode = vi.filenode)
)
INSERT INTO yezzey.yezzey_virtual_index_stale TABLE stale_data;
DELETE FROM
yezzey.yezzey_virtual_index vi
WHERE NOT EXISTS (SELECT 1 FROM pg_class WHERE relfilenode = vi.filenode);
WITH stale_offload_data AS (
SELECT * FROM
yezzey.offload_metadata op
WHERE NOT EXISTS (SELECT 1 FROM pg_class WHERE oid = op.reloid)
)
INSERT INTO yezzey.offload_metadata_stale TABLE stale_offload_data;
DELETE FROM
yezzey.offload_metadata op
WHERE NOT EXISTS (SELECT 1 FROM pg_class WHERE oid = op.reloid);
$$ LANGUAGE SQL
EXECUTE ON ALL SEGMENTS;
CREATE OR REPLACE FUNCTION yezzey.yezzey_binary_upgrade_1_8_to_1_8_1_seg()
RETURNS VOID AS
$$
SELECT yezzey.yezzey_binary_upgrade_1_8_to_1_8_1();
$$
LANGUAGE SQL
EXECUTE ON ALL SEGMENTS;
CREATE TABLE yezzey.yezzey_expire_hint
(
x_path TEXT PRIMARY KEY,
lsn pg_lsn
) WITH (appendonly=false);
SET allow_segment_dml TO ON;
SELECT yezzey.fixup_stale_data();
SELECT yezzey.yezzey_binary_upgrade_1_8_to_1_8_1_seg();
SELECT yezzey.yezzey_binary_upgrade_1_8_to_1_8_1_m();
RESET allow_segment_DML;
DROP FUNCTION yezzey.yezzey_binary_upgrade_1_8_to_1_8_1_seg();
DROP FUNCTION yezzey.yezzey_binary_upgrade_1_8_to_1_8_1_m();
DROP FUNCTION yezzey.fixup_stale_data();
CREATE INDEX yezzey_virtual_index_x_path ON yezzey.yezzey_virtual_index(x_path);