8000 [PG-1583, PG-1600] Do not unnecessarily try to fetch the principal key by AndersAstrand · Pull Request #330 · percona/postgres · GitHub
[go: up one dir, main page]

Skip to content

[PG-1583, PG-1600] Do not unnecessarily try to fetch the principal key #330

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

Merged
Changes from 1 commit
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
Next Next commit
Use an enum instead of bool for encryption status
Replace the boolean used in the smgr hooks. Currently we only have two
states still. This is in preparation for adding a third state to
indicate that the table is encrypted, but the key has not yet been
loaded.
  • Loading branch information
AndersAstrand committed May 13, 2025
commit a8f4a382004685efb067ef3cfd27e0e4f071e523
25 changes: 17 additions & 8 deletions contrib/pg_tde/src/smgr/pg_tde_smgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
#include "access/pg_tde_tdemap.h"
#include "pg_tde_event_capture.h"

typedef enum TDEMgrRelationDataEncryptionStatus
{
/* This is a plaintext relation */
RELATION_NOT_ENCRYPTED = 0,

/* This is an encrypted relation, and we have the key available. */
RELATION_KEY_AVAILABLE = 1,
} TDEMgrRelationDataEncryptionStatus;

typedef struct TDESMgrRelationData
{
/* parent data */
Expand All @@ -19,7 +28,7 @@ typedef struct TDESMgrRelationData
int md_num_open_segs[MAX_FORKNUM + 1];
struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1];

bool encrypted_relation;
TDEMgrRelationDataEncryptionStatus encryption_status;
InternalKey relKey;
} TDESMgrRelationData;

Expand Down Expand Up @@ -72,7 +81,7 @@ tde_mdwritev(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
TDESMgrRelation tdereln = (TDESMgrRelation) reln;
InternalKey *int_key = &tdereln->relKey;

if (!tdereln->encrypted_relation)
if (tdereln->encryption_status == RELATION_NOT_ENCRYPTED)
{
mdwritev(reln, forknum, blocknum, buffers, nblocks, skipFsync);
}
Expand Down Expand Up @@ -131,7 +140,7 @@ tde_mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
TDESMgrRelation tdereln = (TDESMgrRelation) reln;
InternalKey *int_key = &tdereln->relKey;

if (!tdereln->encrypted_relation)
if (tdereln->encryption_status == RELATION_NOT_ENCRYPTED)
{
mdextend(reln, forknum, blocknum, buffer, skipFsync);
}
Expand Down Expand Up @@ -160,7 +169,7 @@ tde_mdreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,

mdreadv(reln, forknum, blocknum, buffers, nblocks);

if (!tdereln->encrypted_relation)
if (tdereln->encryption_status == RELATION_NOT_ENCRYPTED)
return;

for (int i = 0; i < nblocks; ++i)
Expand Down Expand Up @@ -233,12 +242,12 @@ tde_mdcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool

if (key)
{
tdereln->encrypted_relation = true;
tdereln->encryption_status = RELATION_KEY_AVAILABLE;
tdereln->relKey = *key;
}
else
{
tdereln->encrypted_relation = false;
tdereln->encryption_status = RELATION_NOT_ENCRYPTED;
}
}
}
Expand All @@ -258,12 +267,12 @@ tde_mdopen(SMgrRelation reln)

5EE5 if (key)
{
tdereln->encrypted_relation = true;
tdereln->encryption_status = RELATION_KEY_AVAILABLE;
tdereln->relKey = *key;
}
else
{
tdereln->encrypted_relation = false;
tdereln->encryption_status = RELATION_NOT_ENCRYPTED;
}
}

Expand Down
0