Skip to content

Commit 00a0283

Browse files
committed
Feat: Vacuum all tablespaces
1 parent a573bb6 commit 00a0283

11 files changed

Lines changed: 1108 additions & 17 deletions

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ OBJS = \
4141
smgr.o yezzey.o
4242

4343
EXTENSION = yezzey
44-
DATA = yezzey--1.0.sql yezzey--1.8.8.sql \
44+
DATA = yezzey--1.0.sql yezzey--1.8.8.sql yezzey--1.8.9.sql \
4545
yezzey--1.0--1.8.sql \
4646
yezzey--1.8--1.8.1.sql \
4747
yezzey--1.8.1--1.8.2.sql \
@@ -50,7 +50,8 @@ DATA = yezzey--1.0.sql yezzey--1.8.8.sql \
5050
yezzey--1.8.4--1.8.5.sql \
5151
yezzey--1.8.5--1.8.6.sql \
5252
yezzey--1.8.6--1.8.7.sql \
53-
yezzey--1.8.7--1.8.8.sql
53+
yezzey--1.8.7--1.8.8.sql \
54+
yezzey--1.8.8--1.8.9.sql
5455

5556
PGFILEDESC = "yezzey - external storage tables offloading extension"
5657

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
CREATE EXTENSION yezzey VERSION '1.0';
2+
ALTER EXTENSION yezzey UPDATE TO '1.8.6';
3+
CREATE TABLE vacuum_garbage_aot(i INT) WITH (appendonly=true) DISTRIBUTED BY (i);
4+
SELECT yezzey_define_offload_policy('vacuum_garbage_aot');
5+
yezzey_define_offload_policy
6+
------------------------------
7+
8+
(1 row)
9+
10+
CREATE TABLE vacuum_garbage_aot_r(i INT) WITH (appendonly=true) DISTRIBUTED BY (i);
11+
SELECT yezzey_define_offload_policy('vacuum_garbage_aot_r');
12+
yezzey_define_offload_policy
13+
------------------------------
14+
15+
(1 row)
16+
17+
-- check how it work with ONLY given relation
18+
INSERT INTO vacuum_garbage_aot_r VALUES(1);
19+
DELETE FROM vacuum_garbage_aot_r;
20+
INSERT INTO vacuum_garbage_aot_r VALUES(1);
21+
VACUUM vacuum_garbage_aot_r;
22+
INSERT INTO vacuum_garbage_aot VALUES(1);
23+
DELETE FROM vacuum_garbage_aot;
24+
INSERT INTO vacuum_garbage_aot VALUES(1);
25+
VACUUM vacuum_garbage_aot;
26+
-- should be three files, old and new, and after vacuum
27+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot_r');
28+
count
29+
-------
30+
3
31+
(1 row)
32+
33+
-- should be three files, old and new, and after vacuum
34+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot');
35+
count
36+
-------
37+
3
38+
(1 row)
39+
40+
SELECT yezzey_vacuum_garbage_relation('vacuum_garbage_aot_r', true, true);
41+
yezzey_vacuum_garbage_relation
42+
--------------------------------
43+
44+
(1 row)
45+
46+
-- should single file.
47+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot_r');
48+
count
49+
-------
50+
1
51+
(1 row)
52+
53+
-- should not change
54+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot');
55+
count
56+
-------
57+
3
58+
(1 row)
59+
60+
-- should be one file in each relation
61+
SELECT yezzey_vacuum_garbage(true, true);
62+
yezzey_vacuum_garbage
63+
-----------------------
64+
65+
66+
67+
(3 rows)
68+
69+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot');
70+
count
71+
-------
72+
1
73+
(1 row)
74+
75+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot_r');
76+
count
77+
-------
78+
1
79+
(1 row)
80+
81+
DROP TABLE vacuum_garbage_aot;
82+
DROP TABLE vacuum_garbage_aot_r;
83+
-- should be zero
84+
SELECT yezzey_vacuum_garbage(true, true);
85+
yezzey_vacuum_garbage
86+
-----------------------
87+
88+
89+
90+
(3 rows)
91+
92+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot');
93+
count
94+
-------
95+
0
96+
(1 row)
97+
98+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot_r');
99+
count
100+
-------
101+
0
102+
(1 row)
103+
104+
DROP EXTENSION yezzey;
105+
CHECKPOINT;

expected/yezzey-vacuum-garbage.out

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
CREATE EXTENSION yezzey VERSION '1.0';
2-
ALTER EXTENSION yezzey UPDATE TO '1.8.6';
2+
ALTER EXTENSION yezzey UPDATE TO '1.8.9';
3+
\! rm -fr /tmp/test_spc_vacuum_garbage_tab1 && mkdir -p /tmp/test_spc_vacuum_garbage_tab1
4+
CREATE TABLESPACE vacuum_garbage_tab1 LOCATION '/tmp/test_spc_vacuum_garbage_tab1';
5+
\! rm -fr /tmp/test_spc_vacuum_garbage_tab2 && mkdir -p /tmp/test_spc_vacuum_garbage_tab2
6+
CREATE TABLESPACE vacuum_garbage_tab2 LOCATION '/tmp/test_spc_vacuum_garbage_tab2';
37
CREATE TABLE vacuum_garbage_aot(i INT) WITH (appendonly=true) DISTRIBUTED BY (i);
48
SELECT yezzey_define_offload_policy('vacuum_garbage_aot');
59
yezzey_define_offload_policy
@@ -14,6 +18,20 @@ SELECT yezzey_define_offload_policy('vacuum_garbage_aot_r');
1418

1519
(1 row)
1620

21+
CREATE TABLE vacuum_garbage_ts1(i INT) WITH (appendonly=true) TABLESPACE vacuum_garbage_tab1 DISTRIBUTED BY (i);
22+
SELECT yezzey_define_offload_policy('vacuum_garbage_ts1');
23+
yezzey_define_offload_policy
24+
------------------------------
25+
26+
(1 row)
27+
28+
CREATE TABLE vacuum_garbage_ts2(i INT) WITH (appendonly=true) TABLESPACE vacuum_garbage_tab2 DISTRIBUTED BY (i);
29+
SELECT yezzey_define_offload_policy('vacuum_garbage_ts2');
30+
yezzey_define_offload_policy
31+
------------------------------
32+
33+
(1 row)
34+
1735
-- check how it work with ONLY given relation
1836
INSERT INTO vacuum_garbage_aot_r VALUES(1);
1937
DELETE FROM vacuum_garbage_aot_r;
@@ -23,6 +41,14 @@ INSERT INTO vacuum_garbage_aot VALUES(1);
2341
DELETE FROM vacuum_garbage_aot;
2442
INSERT INTO vacuum_garbage_aot VALUES(1);
2543
VACUUM vacuum_garbage_aot;
44+
INSERT INTO vacuum_garbage_ts1 VALUES(1);
45+
DELETE FROM vacuum_garbage_ts1;
46+
INSERT INTO vacuum_garbage_ts1 VALUES(1);
47+
VACUUM vacuum_garbage_ts1;
48+
INSERT INTO vacuum_garbage_ts2 VALUES(1);
49+
DELETE FROM vacuum_garbage_ts2;
50+
INSERT INTO vacuum_garbage_ts2 VALUES(1);
51+
VACUUM vacuum_garbage_ts2;
2652
-- should be three files, old and new, and after vacuum
2753
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot_r');
2854
count
@@ -37,6 +63,19 @@ SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum
3763
3
3864
(1 row)
3965

66+
-- should be three files, old and new, and after vacuum in custom tablespaces
67+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts1');
68+
count
69+
-------
70+
3
71+
(1 row)
72+
73+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts2');
74+
count
75+
-------
76+
3
77+
(1 row)
78+
4079
SELECT yezzey_vacuum_garbage_relation('vacuum_garbage_aot_r', true, true);
4180
yezzey_vacuum_garbage_relation
4281
--------------------------------
@@ -57,9 +96,50 @@ SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum
5796
3
5897
(1 row)
5998

99+
-- should not change custom tablespace relations before tablespace vacuum
100+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts1');
101+
count
102+
-------
103+
3
104+
(1 row)
105+
106+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts2');
107+
count
108+
-------
109+
3
110+
(1 row)
111+
112+
-- should vacuum garbage only in requested tablespace
113+
SELECT yezzey_vacuum_garbage_tablespace((SELECT oid FROM pg_tablespace WHERE spcname = 'vacuum_garbage_tab1'), true, true);
114+
yezzey_vacuum_garbage_tablespace
115+
----------------------------------
116+
117+
118+
119+
(3 rows)
120+
121+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts1');
122+
count
123+
-------
124+
1
125+
(1 row)
126+
127+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts2');
128+
count
129+
-------
130+
3
131+
(1 row)
132+
133+
-- default tablespace relation should not change after custom tablespace vacuum
134+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot');
135+
count
136+
-------
137+
3
138+
(1 row)
139+
60140
-- should be one file in each relation
61141
SELECT yezzey_vacuum_garbage(true, true);
62-
yezzey_vacuum_garbage
142+
yezzey_vacuum_garbage
63143
-----------------------
64144

65145

@@ -78,11 +158,25 @@ SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum
78158
1
79159
(1 row)
80160

161+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts1');
162+
count
163+
-------
164+
1
165+
(1 row)
166+
167+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts2');
168+
count
169+
-------
170+
1
171+
(1 row)
172+
81173
DROP TABLE vacuum_garbage_aot;
82174
DROP TABLE vacuum_garbage_aot_r;
175+
DROP TABLE vacuum_garbage_ts1;
176+
DROP TABLE vacuum_garbage_ts2;
83177
-- should be zero
84178
SELECT yezzey_vacuum_garbage(true, true);
85-
yezzey_vacuum_garbage
179+
yezzey_vacuum_garbage
86180
-----------------------
87181

88182

@@ -101,5 +195,19 @@ SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum
101195
0
102196
(1 row)
103197

198+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts1');
199+
count
200+
-------
201+
0
202+
(1 row)
203+
204+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_ts2');
205+
count
206+
-------
207+
0
208+
(1 row)
209+
210+
DROP TABLESPACE vacuum_garbage_tab1;
211+
DROP TABLESPACE vacuum_garbage_tab2;
104212
DROP EXTENSION yezzey;
105213
CHECKPOINT;

include/xvacuum.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ EXTERNC void yezzey_delete_chunk_internal(const char *external_chunk_path);
1515
EXTERNC void yezzey_vacuum_garbage_internal(int segindx, bool confirm,
1616
bool crazyDrop);
1717

18+
EXTERNC void yezzey_vacuum_garbage_tablespace_internal(Oid tablespace,
19+
int segindx,
20+
bool confirm,
21+
bool crazyDrop);
22+
1823
EXTERNC void yezzey_vacuum_garbage_relation_internal(Relation rel, int segindx,
1924
bool confirm,
2025
bool crazyDrop);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
CREATE EXTENSION yezzey VERSION '1.0';
2+
ALTER EXTENSION yezzey UPDATE TO '1.8.6';
3+
4+
CREATE TABLE vacuum_garbage_aot(i INT) WITH (appendonly=true) DISTRIBUTED BY (i);
5+
SELECT yezzey_define_offload_policy('vacuum_garbage_aot');
6+
7+
CREATE TABLE vacuum_garbage_aot_r(i INT) WITH (appendonly=true) DISTRIBUTED BY (i);
8+
SELECT yezzey_define_offload_policy('vacuum_garbage_aot_r');
9+
10+
-- check how it work with ONLY given relation
11+
INSERT INTO vacuum_garbage_aot_r VALUES(1);
12+
DELETE FROM vacuum_garbage_aot_r;
13+
INSERT INTO vacuum_garbage_aot_r VALUES(1);
14+
VACUUM vacuum_garbage_aot_r;
15+
16+
INSERT INTO vacuum_garbage_aot VALUES(1);
17+
DELETE FROM vacuum_garbage_aot;
18+
INSERT INTO vacuum_garbage_aot VALUES(1);
19+
VACUUM vacuum_garbage_aot;
20+
21+
-- should be three files, old and new, and after vacuum
22+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot_r');
23+
24+
-- should be three files, old and new, and after vacuum
25+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot');
26+
27+
SELECT yezzey_vacuum_garbage_relation('vacuum_garbage_aot_r', true, true);
28+
29+
-- should single file.
30+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot_r');
31+
32+
-- should not change
33+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot');
34+
35+
-- should be one file in each relation
36+
SELECT yezzey_vacuum_garbage(true, true);
37+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot');
38+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot_r');
39+
40+
DROP TABLE vacuum_garbage_aot;
41+
DROP TABLE vacuum_garbage_aot_r;
42+
43+
-- should be zero
44+
SELECT yezzey_vacuum_garbage(true, true);
45+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot');
46+
SELECT count(1) FROM yezzey_relation_describe_external_storage_structure('vacuum_garbage_aot_r');
47+
48+
DROP EXTENSION yezzey;
49+
CHECKPOINT;

0 commit comments

Comments
 (0)