Skip to content

Commit

Permalink
Feature - deleting bloat files (#54)
Browse files Browse the repository at this point in the history
* yezzey_block_db_file_path Creates a string containing the prefix of files from a specific table

* New func yezzey_vacuum_relation Deletes bloat files from a specific table (sql interface by name). And c func for by Relation and by Oid.

* Vacuum cleans the data in s3 with a new function  by relation (does not work)
  • Loading branch information
visill authored Oct 28, 2024
1 parent 2c9e0f4 commit d4d48f9
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ std::string yezzey_block_file_path(const std::string &nspname,
relnodeCoord coords, int32_t segid);

std::string yezzey_block_namespace_path(int32_t segid);
std::string yezzey_block_db_file_path(const std::string &nspname,
const std::string &relname,
relnodeCoord coords, int32_t segid);

/* un-prefixed version of `craftStoragePrefixedPath` */
std::string craftStorageUnPrefixedPath(const std::shared_ptr<IOadv> &adv,
Expand Down
3 changes: 2 additions & 1 deletion include/xvacuum.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
EXTERNC int yezzey_delete_chunk_internal(const char *external_chunk_path);
EXTERNC int yezzey_vacuum_garbage_internal(int segindx, bool confirm,
bool crazyDrop);

EXTERNC int yezzey_vacuum_garbage_relation_internal(Oid reloid, int segindx, bool confirm,
bool crazyDrop);
#endif /* YEZZEY_XVACUUM_H */
9 changes: 9 additions & 0 deletions src/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ std::string yezzey_block_file_path(const std::string &nspname,

return url;
}
std::string yezzey_block_db_file_path(const std::string &nspname,
const std::string &relname,
relnodeCoord coords, int32_t segid){
std::string url = yezzey_block_namespace_path(segid);
url += std::to_string(coords.spcNode) + "_" + std::to_string(coords.dboid) + "_";

auto md = yezzey_fqrelname_md5(nspname, relname);
url += md;
return url;
}
/* prefix-independent WAL-G compatable path */
std::string craftStorageUnPrefixedPath(const std::shared_ptr<IOadv> &adv,
ssize_t segindx, ssize_t modcount,
Expand Down
48 changes: 48 additions & 0 deletions src/xvacuum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,51 @@ int yezzey_vacuum_garbage_internal(int segindx, bool confirm, bool crazyDrop) {
}
return 0;
}
int yezzey_vacuum_garbage_relation_internal(Relation rel,int segindx, bool confirm,bool crazyDrop){
try {
auto ioadv = std::make_shared<IOadv>(
std::string(gpg_engine_path), std::string(gpg_key_id),
std::string(storage_config), "", "", std::string(storage_host /*host*/),
std::string(storage_bucket /*bucket*/),
std::string(storage_prefix /*prefix*/),
std::string(storage_class /*storage_class*/), multipart_chunksize,
DEFAULTTABLESPACE_OID, "" /* coords */, InvalidOid /* reloid */,
std::string(walg_bin_path), std::string(walg_config_path),
use_gpg_crypto, yproxy_socket);

auto tp = SearchSysCache1(NAMESPACEOID,
ObjectIdGetDatum(RelationGetNamespace(rel)));

if (!HeapTupleIsValid(tp)) {
elog(ERROR, "yezzey: failed to get namescape name of relation %d",
RelationGetNamespace(rel));
}

relnodeCoord coords{1663,rel->rd_node.dbNode,rel->rd_node.relNode,segindx};
Form_pg_namespace nsptup = (Form_pg_namespace)GETSTRUCT(tp);
auto nspname = std::string(nsptup->nspname.data);
std::string relname = RelationGetRelationName(rel);

std::string storage_path(yezzey_block_db_file_path(nspname,relname,coords,segindx));

auto deleter =
std::make_shared<YProxyDeleter>(ioadv, ssize_t(segindx), confirm);
ReleaseSysCache(tp);

if (deleter->deleteChunk(storage_path)) {
return 0;
}

return -1;
} catch (...) {
elog(ERROR, "failed to prepare x-storage reader for chunk");
return 0;
}
return 0;
}
int yezzey_vacuum_garbage_relation_internal(Oid reloid,int segindx, bool confirm, bool crazyDrop) {
Relation rel = relation_open(reloid,NoLock);
int rc = yezzey_vacuum_garbage_relation_internal(rel,segindx,confirm,crazyDrop);
relation_close(rel,NoLock);
return rc;
}
9 changes: 7 additions & 2 deletions worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,17 @@ yezzey_ProcessUtility_hook(Node *parsetree,
#if IsGreenplum6
{
VacuumStmt *stmt = (VacuumStmt *) parsetree;
if (stmt->options & VACOPT_YEZZEY) {
if(!stmt->relation){
break;
}
Relation rel = relation_openrv(stmt->relation,NoLock);
if (stmt->options & VACOPT_YEZZEY & (rel->rd_node.spcNode == YEZZEYTABLESPACE_OID)) {
if (Gp_role == GP_ROLE_EXECUTE) {
Assert(GpIdentity.segindex != -1);
yezzey_vacuum_garbage_internal(GpIdentity.segindex, true, false);
yezzey_vacuum_garbage_relation_internal(rel, GpIdentity.segindex,true,false);
}
}
relation_close(rel,NoLock);
}
#endif
break;
Expand Down
52 changes: 51 additions & 1 deletion yezzey--1.8--1.8.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,54 @@ CREATE OR REPLACE FUNCTION yezzey_vacuum_garbage(
AS 'MODULE_PATHNAME'
VOLATILE
EXECUTE ON ALL SEGMENTS
LANGUAGE C STRICT;
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_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;
23 changes: 22 additions & 1 deletion yezzey.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ PG_FUNCTION_INFO_V1(yezzey_check_part_exr);

PG_FUNCTION_INFO_V1(yezzey_delete_chunk);
PG_FUNCTION_INFO_V1(yezzey_vacuum_garbage);
PG_FUNCTION_INFO_V1(yezzey_vacuum_relation);


/* Create yezzey metadata tables */
Expand All @@ -123,7 +124,7 @@ int yezzey_offload_relation_internal(Oid reloid, bool remove_locally,

int yezzey_delete_chunk_internal(const char *external_chunk_path);
int yezzey_vacuum_garbage_internal(int segindx, bool confirm, bool crazyDrop);

int yezzey_vacuum_garbage_relation_internal(Oid reloid,int segindx, bool confirm, bool crazyDrop);
/*
* yezzey_define_relation_offload_policy_internal:
* do all the work with initial relation offloading
Expand Down Expand Up @@ -430,6 +431,26 @@ Datum yezzey_vacuum_garbage(PG_FUNCTION_ARGS) {
PG_RETURN_VOID();
}

Datum yezzey_vacuum_relation(PG_FUNCTION_ARGS) {
Oid reloid = PG_GETARG_OID(0);
bool confirm;
bool crazyDrop;
int rc;
confirm = PG_GETARG_BOOL(1);
crazyDrop = PG_GETARG_BOOL(2);
if (GpIdentity.segindex == -1) {
elog(ERROR, "yezzey_vacuum_garbage_internal should be executed on SEGMENT");
}

if (crazyDrop && !superuser()) {
elog(ERROR, "crazyDrop forbidden for non-superuser");
}

rc = yezzey_vacuum_garbage_relation_internal(reloid,GpIdentity.segindex,confirm,crazyDrop);

PG_RETURN_VOID();

}
Datum yezzey_show_relation_external_path(PG_FUNCTION_ARGS) {
Oid reloid;
Relation aorel;
Expand Down

0 comments on commit d4d48f9

Please sign in to comment.