Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yezzey: fix truncate metadata bug #112

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions expected/yezzey-trunc.out
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ SELECT count(1) FROM trunc_regaoty;
(1 row)

TRUNCATE trunc_regaoty;
SELECT count(1) from yezzey_dump_virtual_index('trunc_regaoty');
count
-------
0
(1 row)

SELECT count(1) FROM trunc_regaoty;
count
-------
Expand Down Expand Up @@ -183,6 +189,12 @@ SELECT count(1) FROM trunc_regaocsty;
(1 row)

TRUNCATE trunc_regaocsty;
SELECT count(1) from yezzey_dump_virtual_index('trunc_regaoty');
count
-------
0
(1 row)

SELECT count(1) FROM trunc_regaocsty;
count
-------
Expand Down
1 change: 1 addition & 0 deletions smgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void yezzey_unlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo,
#else
if (rnode.node.spcNode == YEZZEYTABLESPACE_OID) {
/*do nothing */

return;
}

Expand Down
2 changes: 2 additions & 0 deletions sql/yezzey-trunc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ INSERT INTO trunc_regaoty SELECT * FROM generate_series(1, 100000);
SELECT count(1) FROM trunc_regaoty;

TRUNCATE trunc_regaoty;
SELECT count(1) from yezzey_dump_virtual_index('trunc_regaoty');
SELECT count(1) FROM trunc_regaoty;

SELECT count() FROM yezzey_offload_relation_status('trunc_regaoty');
Expand Down Expand Up @@ -67,6 +68,7 @@ INSERT INTO trunc_regaocsty SELECT * FROM generate_series(1, 100000);
SELECT count(1) FROM trunc_regaocsty;

TRUNCATE trunc_regaocsty;
SELECT count(1) from yezzey_dump_virtual_index('trunc_regaoty');
SELECT count(1) FROM trunc_regaocsty;

SELECT count() FROM yezzey_offload_relation_status('trunc_regaocsty');
Expand Down
7 changes: 4 additions & 3 deletions src/virtual_tablespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ void YezzeyATExecSetTableSpace(Relation aorel, Oid reloid,
*/

/* drop old relation, and close new one */
RelationDropStorage(aorel);
if (desttablespace_oid == YEZZEYTABLESPACE_OID)
RelationDropStorage(aorel);

/* update the pg_class row */
if (desttablespace_oid != YEZZEYTABLESPACE_OID) {
if (desttablespace_oid != YEZZEYTABLESPACE_OID)
rd_rel->relfilenode = GetNewRelFileNode(desttablespace_oid, NULL,
aorel->rd_rel->relpersistence);
}

rd_rel->reltablespace = desttablespace_oid;

#if IsGreenplum6
Expand Down
10 changes: 9 additions & 1 deletion yezzey.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ int yezzey_load_relation_internal(Oid reloid, const char *dest_path) {
* Do not empty, just drop
* Dropping yezzey virtual index for loaded relation allow to
* remove extension dependecy on this object (relation)
* empty all track info **
* empty all track info
*/

(void)emptyYezzeyIndex(yandexoid, origrelfilenode);
Expand Down Expand Up @@ -1320,6 +1320,12 @@ static void yezzey_define_gucs() {
PGC_SUSET, 0, NULL, NULL, NULL);
}

void yezzey_TrackObjDrop (Relation rel)
{
if (rel->rd_node.spcNode == YEZZEYTABLESPACE_OID)
(void)emptyYezzeyIndex(YezzeyFindAuxIndex(RelationGetRelid(rel)), rel->rd_node.relNode);
}

void _PG_init(void) {
/* Allocate shared memory for yezzey workers */

Expand All @@ -1340,4 +1346,6 @@ void _PG_init(void) {

ExecutorStart_hook = yezzey_ExecuterStartHook;
ExecutorEnd_hook = yezzey_ExecuterEndHook;

TrackDropObject_hook = yezzey_TrackObjDrop;
}