Skip to content

Commit

Permalink
Add KEK metadata to virtual index (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
EinKrebs authored Feb 18, 2025
1 parent 164600b commit 0c7eb84
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct YIO {
bool io_read(char *buffer, size_t *amount);
bool io_write(char *buffer, size_t *amount);
bool io_close();

bool use_kek();
};

#endif /* YEZZEY_IO_H */
3 changes: 3 additions & 0 deletions include/virtual_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#define YEZZEY_VIRTUAL_INDEX_RELATION 8500
#define YEZZEY_VIRTUAL_INDEX_IDX_RELATION 8501

#define YEZZEY_IS_ENC 0x1
#define YEZZEY_ENC_KEK 0x2

/* ----------------
* compiler constants for pg_database
* ----------------
Expand Down
2 changes: 1 addition & 1 deletion include/yezzey_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
EXTERNC void YezzeyUpdateMetadataRelations(
Oid yandexoid /*yezzey auxiliary index oid*/, Oid reloid,
Oid relfilenodeOid, int64_t blkno, int64_t offset_start,
int64_t offset_finish, int32_t encrypted, int32_t reused, int64_t modcount,
int64_t offset_finish, bool encrypted, bool kek, int32_t reused, int64_t modcount,
XLogRecPtr lsn, const char *x_path /* external path */, const char *md5);
2 changes: 2 additions & 0 deletions include/yproxy_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ class YProxyWriter : YProxyConnector {
std::string getExternalStoragePath() { return storage_path_; }

XLogRecPtr getInsertionStorageLsn() { return insertion_rec_ptr_; }

bool getUseKEK() { return key_version == 2; }
};
7 changes: 7 additions & 0 deletions src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@ YIO::~YIO() { io_close(); }

bool YIO::reader_empty() {
return reader_.get() == nullptr ? true : reader_->empty();
}

bool YIO::use_kek() {
if (writer_.get()) {
return writer_->getUseKEK();
}
return false;
}
9 changes: 7 additions & 2 deletions src/meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
void YezzeyUpdateMetadataRelations(
Oid yandexoid /*yezzey auxiliary index oid*/, Oid reloid,
Oid relfilenodeOid, int64_t blkno, int64_t offset_start,
int64_t offset_finish, int32_t encrypted, int32_t reused, int64_t modcount,
int64_t offset_finish, bool encrypted, bool kek, int32_t reused, int64_t modcount,
XLogRecPtr lsn, const char *x_path /* external path */, const char *md5) {
int32_t flags = 0;
if (encrypted)
flags |= YEZZEY_IS_ENC;
if (kek)
flags |= YEZZEY_ENC_KEK;
YezzeyVirtualIndexInsert(yandexoid, reloid, relfilenodeOid, blkno,
offset_start, offset_finish, encrypted, reused,
offset_start, offset_finish, flags, reused,
modcount, lsn, x_path);
/* TODO: update yezzey relfilemap */
}
2 changes: 1 addition & 1 deletion src/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void yezzey_FileClose(SMGRFile file) {
YezzeyFindAuxIndex(yfd.reloid), yfd.reloid, yfd.coord.filenode,
yfd.coord.blkno /* blkno*/, yfd.op_start_offset,
yfd.offset /* io operation finish offset */,
yfd.handler->adv_->use_gpg_crypto /* encrypted */, 0 /* reused */,
yfd.handler->adv_->use_gpg_crypto /* encrypted */, yfd.handler->use_kek(), 0 /* reused */,
yfd.modcount, yfd.handler->writer_->getInsertionStorageLsn(),
yfd.handler->writer_->getExternalStoragePath().c_str() /* path ? */,
yezzey_fqrelname_md5(yfd.nspname, yfd.relname).c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ int offloadRelationSegmentPath(Relation aorel, std::shared_ptr<IOadv> ioadv,
YezzeyUpdateMetadataRelations(
YezzeyFindAuxIndex(aorel->rd_id), ioadv->reloid, ioadv->coords_.filenode,
ioadv->coords_.blkno /* blkno*/, offset_start, offset_finish,
ioadv->use_gpg_crypto /* encrypted */, 0 /* reused */, modcount,
iohandler.adv_->use_gpg_crypto /* encrypted */, iohandler.use_kek(), 0 /* reused */, modcount,
iohandler.writer_->getInsertionStorageLsn(),
iohandler.writer_->getExternalStoragePath().c_str() /* path */,
yezzey_fqrelname_md5(ioadv->nspname, ioadv->relname).c_str());
Expand Down

0 comments on commit 0c7eb84

Please sign in to comment.