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

Major yezzey refactoring. Prepare for v1.9 & vacuum features. #55

Merged
merged 7 commits into from
Oct 29, 2024
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
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ OBJS = \
src/url.o \
src/io.o \
src/io_adv.o \
src/worker.o \
src/offload_tablespace_map.o \
src/offload_policy.o \
src/offload.o \
src/virtual_tablespace.o \
src/partition.o \
src/xvacuum.o \
src/yezzey_expire.o \
src/yproxy.o \
src/init.o \
src/meta.o \
smgr.o worker.o yezzey.o
smgr.o yezzey.o

EXTENSION = yezzey
DATA = yezzey--1.0.sql yezzey--1.0--1.8.sql yezzey--1.8--1.8.1.sql
Expand Down
5 changes: 0 additions & 5 deletions include/gucs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ extern int yezzey_ao_log_level;
extern bool use_gpg_crypto;

/* ----- STORAGE ----- */
extern char *storage_prefix;
extern char *storage_bucket;
extern char *backup_bucket;
extern char *storage_config;
extern char *storage_host;
extern char *storage_class;
extern int multipart_chunksize;
extern int multipart_threshold;
Expand Down
12 changes: 2 additions & 10 deletions include/io_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ struct IOadv {
const std::string nspname;
// relation name itself
const std::string relname;
// s3 host
const std::string host;
// s3 bucked
const std::string bucket;
// wal-g specific prefix
const std::string external_storage_prefix;

// s3 storage class
const std::string storage_class;
Expand All @@ -39,16 +33,14 @@ struct IOadv {
const std::string yproxy_socket;

IOadv(const std::string &nspname,
const std::string &relname, const std::string &host,
const std::string &bucket, const std::string &external_storage_prefix,
const std::string &relname,
const std::string &storage_class, const int &multipart_chunksize,
/*unparse coords*/ Oid spcNode, const std::string &fileName,
const Oid reloid, bool use_gpg_crypto,
const std::string &yproxy_socket);

IOadv(const std::string &nspname,
const std::string &relname, const std::string &host,
const std::string &bucket, const std::string &external_storage_prefix,
const std::string &relname,
const std::string &storage_class, const int &multipart_chunksize,
const relnodeCoord &coords, const Oid reloid,
bool use_gpg_crypto, const std::string &yproxy_socket);
Expand Down
7 changes: 0 additions & 7 deletions include/json.h

This file was deleted.

2 changes: 2 additions & 0 deletions include/offload_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ EXTERNC void YezzeyDefineOffloadPolicy(Oid reloid);

EXTERNC void YezzeyDefineOffloadPolicyPrepare(Oid reloid);

EXTERNC void FixupOffloadMetadata(Oid reloid);

/*
* YezzeyLoadRealtion:
* do all offload-metadata related work for relation loading:
Expand Down
1 change: 0 additions & 1 deletion include/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ std::string craftStorageUnPrefixedPath(const std::shared_ptr<IOadv> &adv,
std::string
getYezzeyRelationUrl_internal(const std::string &nspname,
const std::string &relname,
const std::string &external_storage_prefix,
relnodeCoord coords, int32_t segid);
6 changes: 1 addition & 5 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ int64_t yezzey_calc_virtual_relation_size(std::shared_ptr<IOadv> adv,
std::string storage_url_add_options(const std::string &s3path,
const char *config_path);

std::string getYezzeyExtrenalStorageBucket(const char *host,
const char *bucket);

std::string make_yezzey_url(const std::string &prefix, int64_t modcounts,
XLogRecPtr current_recptr);

Expand All @@ -49,8 +46,7 @@ std::vector<int64_t> parseModcounts(const std::string &prefix,
#endif

EXTERNC void getYezzeyExternalStoragePathByCoords(
const char *nspname, const char *relname, const char *host,
const char *bucket, const char *storage_prefix, Oid spcNode, Oid dbNode,
const char *nspname, const char *relname, Oid spcNode, Oid dbNode,
Oid relNode, int32_t segblockno /* segment no*/, int32_t segid,
char **dest);

Expand Down
5 changes: 5 additions & 0 deletions include/virtual_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef struct {
text x_path; /* external path */
} FormData_yezzey_virtual_index;

typedef FormData_yezzey_virtual_index* Form_yezzey_virtual_index;

#define Natts_yezzey_virtual_index 10
#define Anum_yezzey_virtual_index_reloid 1
#define Anum_yezzey_virtual_index_filenode 2
Expand All @@ -57,6 +59,9 @@ EXTERNC void emptyYezzeyIndex(Oid yezzey_index_oid, Oid relfilenode);
EXTERNC void emptyYezzeyIndexBlkno(Oid yezzey_index_oid, Oid relation,
Oid relfilenode, int blkno);

/* fixup virtual index entry for relation's relfilenode. */
EXTERNC void YezzeyFixupVirtualIndex(Relation rel);

#ifdef __cplusplus
void YezzeyVirtualIndexInsert(Oid yandexoid /*yezzey auxiliary index oid*/,
Oid reloid, Oid relfilenodeOid, int64_t blkno,
Expand Down
54 changes: 0 additions & 54 deletions include/yezzey_expire.h

This file was deleted.

1 change: 0 additions & 1 deletion include/yezzey_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "pg.h"
#include "url.h"
#include "virtual_index.h"
#include "yezzey_expire.h"

#ifdef __cplusplus
#define EXTERNC extern "C"
Expand Down
2 changes: 0 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#include "init.h"

#include "offload_policy.h"
#include "yezzey_expire.h"

void YezzeyInitMetadata(void) {
(void)YezzeyCreateOffloadPolicyRelation();
(void)YezzeyCreateRelationExpireIndex();
(void)YezzeyCreateVirtualIndex();
}
14 changes: 4 additions & 10 deletions src/io_adv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
#include "offload_tablespace_map.h"

IOadv::IOadv(const std::string &nspname,
const std::string &relname, const std::string &host,
const std::string &bucket,
const std::string &external_storage_prefix,
const std::string &relname,
const std::string &storage_class, const int &multipart_chunksize,
const Oid spcNode, const std::string &fileName, const Oid reloid,
bool use_gpg_crypto,
const std::string &yproxy_socket)
:
nspname(nspname), relname(relname), host(host),
bucket(bucket), external_storage_prefix(external_storage_prefix),
nspname(nspname), relname(relname),
storage_class(storage_class), multipart_chunksize(multipart_chunksize),
coords_(getRelnodeCoordinate(spcNode, fileName)), reloid(reloid),
tableSpace(reloid ? YezzeyGetRelationOriginTablespace(nspname.c_str(), relname.c_str(), reloid) : "none"),
Expand All @@ -21,14 +18,11 @@ IOadv::IOadv(const std::string &nspname,
}

IOadv::IOadv(const std::string &nspname,
const std::string &relname, const std::string &host,
const std::string &bucket,
const std::string &external_storage_prefix,
const std::string &relname,
const std::string &storage_class, const int &multipart_chunksize,
const relnodeCoord &coords, const Oid reloid,bool use_gpg_crypto,
const std::string &yproxy_socket)
: nspname(nspname), relname(relname), host(host),
bucket(bucket), external_storage_prefix(external_storage_prefix),
: nspname(nspname), relname(relname),
storage_class(storage_class), multipart_chunksize(multipart_chunksize),
coords_(coords), reloid(reloid),
tableSpace(reloid ? YezzeyGetRelationOriginTablespace(nspname.c_str(), relname.c_str(), reloid) : "none"),
Expand Down
2 changes: 1 addition & 1 deletion src/meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ void YezzeyUpdateMetadataRelations(
YezzeyVirtualIndexInsert(yandexoid, reloid, relfilenodeOid, blkno,
offset_start, offset_finish, encrypted, reused,
modcount, lsn, x_path);
YezzeyUpsertLastUseLsn(reloid, relfilenodeOid, md5, lsn);
/* TODO: update yezzey relfilemap */
}
34 changes: 34 additions & 0 deletions src/offload_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,38 @@ void YezzeyLoadRealtion(Oid i_reloid) {

/* make changes visible*/
CommandCounterIncrement();
}

void FixupOffloadMetadata(Oid i_reloid) {
/**/
ScanKeyData skey[1];

auto snap = RegisterSnapshot(GetTransactionSnapshot());

auto offrel = heap_open(YEZZEY_OFFLOAD_POLICY_RELATION, RowExclusiveLock);

/* INSERT INTO yezzey.offload_metadata VALUES(v_reloid, 1, NULL, NOW()); */

ScanKeyInit(&skey[0], Anum_offload_metadata_reloid, BTEqualStrategyNumber,
F_OIDEQ, ObjectIdGetDatum(i_reloid));

auto scan = yezzey_beginscan(offrel, snap, 1, skey);

auto oldtuple = heap_getnext(scan, ForwardScanDirection);

if (HeapTupleIsValid(oldtuple)) {
auto meta = (Form_yezzey_offload_metadata)GETSTRUCT(oldtuple);

Assert(meta->reloid == i_reloid);

simple_heap_delete(offrel, &oldtuple->t_self);
}

heap_close(offrel, RowExclusiveLock);

yezzey_endscan(scan);
UnregisterSnapshot(snap);

/* make changes visible */
CommandCounterIncrement();
}
3 changes: 0 additions & 3 deletions src/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ EXTERNC SMGRFile yezzey_AORelOpenSegFile(Oid reloid, char *nspname,
if (!RecoveryInProgress()) {
auto ioadv = std::make_shared<IOadv>(
yfd.nspname, yfd.relname,
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,
yfd.filepath /* coords */, reloid /* reloid */,
Expand Down
14 changes: 2 additions & 12 deletions src/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ int loadSegmentFromExternalStorage(Relation rel, const std::string &nspname,
/* FIXME */

auto ioadv = std::make_shared<IOadv>(
nspname, relname,
storage_host /* host */, storage_bucket /*bucket*/,
storage_prefix /*prefix*/, storage_class /* storage_class */,
nspname, relname, storage_class /* storage_class */,
multipart_chunksize, coords /* filename */, rel->rd_id /* reloid */,
use_gpg_crypto, yproxy_socket);

Expand Down Expand Up @@ -348,9 +346,7 @@ int offloadRelationSegment(Relation aorel, int segno, int64 modcount,
!external_storage_path ? "" : std::string(external_storage_path);
ReleaseSysCache(tp);

auto ioadv = std::make_shared<IOadv>(nspname, relname,
storage_host /* host */, storage_bucket /*bucket*/,
storage_prefix /*prefix*/, storage_class /* storage_class */,
auto ioadv = std::make_shared<IOadv>(nspname, relname, storage_class /* storage_class */,
multipart_chunksize, coords, aorel->rd_id /* reloid */, use_gpg_crypto, yproxy_socket);

try {
Expand Down Expand Up @@ -448,9 +444,6 @@ int statRelationSpaceUsage(Relation aorel, int segno, int64 modcount,
auto ioadv = std::make_shared<IOadv>(
nspname,
std::string(aorel->rd_rel->relname.data),
std::string(storage_host /*host*/),
std::string(storage_bucket /*bucket*/),
std::string(storage_prefix /*prefix*/),
std::string(storage_class /*storage_class*/), multipart_chunksize,
coords /* coords */, aorel->rd_id /* reloid */, use_gpg_crypto,
yproxy_socket);
Expand Down Expand Up @@ -512,9 +505,6 @@ int statRelationSpaceUsagePerExternalChunk(Relation aorel, int segno,
auto ioadv = std::make_shared<IOadv>(
nspname,
std::string(aorel->rd_rel->relname.data),
std::string(storage_host /*host*/),
std::string(storage_bucket /*bucket*/),
std::string(storage_prefix /*prefix*/),
std::string(storage_class /*storage_class*/), multipart_chunksize,
coords /* coords */, aorel->rd_id /* reloid */, use_gpg_crypto,
yproxy_socket);
Expand Down
4 changes: 1 addition & 3 deletions src/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ std::string craftStorageUnPrefixedPath(const std::shared_ptr<IOadv> &adv,
std::string
getYezzeyRelationUrl_internal(const std::string &nspname,
const std::string &relname,
const std::string &external_storage_prefix,
relnodeCoord coords, int32_t segid) {
return external_storage_prefix +
yezzey_block_file_path(nspname, relname, coords, segid);
return yezzey_block_file_path(nspname, relname, coords, segid);
}
25 changes: 3 additions & 22 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@

const char *baseYezzeyPath = "/basebackups_005/yezzey/";

std::string getYezzeyExtrenalStorageBucket(const char *host,
const char *bucket) {
std::string url = "s3://";
std::string toErase = "https://";
std::string hostStr = host;
size_t pos = hostStr.find(toErase);
if (pos != std::string::npos) {
hostStr.erase(pos, toErase.length());
}
url += hostStr;
url += "/";
url += bucket;
url += "/";

return url;
}

std::string storage_url_add_options(const std::string &s3path,
const char *config_path) {
auto ret = s3path;
Expand Down Expand Up @@ -87,18 +70,16 @@ relnodeCoord getRelnodeCoordinate(Oid spcNode, const std::string &fileName) {
}

void getYezzeyExternalStoragePathByCoords(const char *nspname,
const char *relname, const char *host,
const char *bucket,
const char *storage_prefix,
const char *relname,
Oid spcNode, Oid dbNode, Oid relNode,
int32_t segblockno /* segment no*/,
int32_t segid, char **dest) {

/* FIXME: Support for non-default table space? */
auto coords = relnodeCoord(spcNode, dbNode, relNode, segblockno);
auto prefix = getYezzeyRelationUrl_internal(nspname, relname, storage_prefix,
auto prefix = getYezzeyRelationUrl_internal(nspname, relname,
coords, segid);
auto path = getYezzeyExtrenalStorageBucket(host, bucket) + prefix;
auto path = prefix;

*dest = (char *)malloc(sizeof(char) * path.size());
strcpy(*dest, path.c_str());
Expand Down
Loading
Loading