Skip to content

Commit

Permalink
PG-1095 More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov committed Oct 29, 2024
1 parent fcbfb27 commit e22c25f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/access/pg_tde_slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ tdeheap_slot_deform_heap_tuple(TupleTableSlot *slot, HeapTuple tuple, uint32 *of
bool *isnull = slot->tts_isnull;
HeapTupleHeader tup = tuple->t_data;
bool hasnulls = HeapTupleHasNulls(tuple);
int attnum;
int attnum;
char *tp; /* ptr to tuple data */
uint32 off; /* offset in tuple data */
bits8 *bp = tup->t_bits; /* ptr to null bitmap in tuple */
Expand Down
72 changes: 36 additions & 36 deletions src/access/pg_tde_tdemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ pg_tde_create_key_map_entry(const RelFileLocator *newrlocator, uint32 entry_type
RelKeyData *rel_key_data;
RelKeyData *enc_rel_key_data;
TDEPrincipalKey *principal_key;
XLogRelKey xlrec;
LWLock *lock_pk = tde_lwlock_enc_keys();
XLogRelKey xlrec;
LWLock *lock_pk = tde_lwlock_enc_keys();

LWLockAcquire(lock_pk, LW_EXCLUSIVE);
principal_key = GetPrincipalKey(newrlocator->dbOid, newrlocator->spcOid, LW_EXCLUSIVE);
Expand Down Expand Up @@ -215,7 +215,7 @@ const char *
tde_sprint_key(InternalKey *k)
{
static char buf[256];
int i;
int i;

for (i = 0; i < sizeof(k->key); i++)
sprintf(buf + i, "%02X", k->key[i]);
Expand All @@ -230,7 +230,7 @@ tde_sprint_key(InternalKey *k)
RelKeyData *
tde_create_rel_key(RelFileNumber rel_num, uint32 key_type, InternalKey *key, TDEPrincipalKeyInfo *principal_key_info)
{
RelKeyData rel_key_data;
RelKeyData rel_key_data;

memcpy(&rel_key_data.principal_key_id, &principal_key_info->keyId, sizeof(TDEPrincipalKeyId));
memcpy(&rel_key_data.internal_key, key, sizeof(InternalKey));
Expand Down Expand Up @@ -284,13 +284,13 @@ pg_tde_delete_tde_files(Oid dbOid, Oid spcOid)
bool
pg_tde_save_principal_key(TDEPrincipalKeyInfo *principal_key_info)
{
int ap_fd = -1;
int eydata_fd = -1;
off_t urr_pos = 0;
bool s_new_map = false;
bool s_new_key_data = false;
char b_map_path[MAXPGPATH] = {0};
char b_keydata_path[MAXPGPATH] = {0};
int map_fd = -1;
int keydata_fd = -1;
off_t curr_pos = 0;
bool is_new_map = false;
bool is_new_key_data = false;
char db_map_path[MAXPGPATH] = {0};
char db_keydata_path[MAXPGPATH] = {0};

/* Set the file paths */
pg_tde_set_db_file_paths(principal_key_info->databaseId,
Expand Down Expand Up @@ -361,7 +361,7 @@ pg_tde_file_header_write(char *tde_filename, int fd, TDEPrincipalKeyInfo *princi
static int32
pg_tde_write_map_entry(const RelFileLocator *rlocator, uint32 entry_type, char *db_map_path, TDEPrincipalKeyInfo *principal_key_info)
{
int map_fd = -1;
int map_fd = -1;
int32 key_index = 0;
TDEMapEntry map_entry;
bool is_new_file;
Expand Down Expand Up @@ -655,28 +655,28 @@ finalize_key_rotation(char *m_path_old, char *k_path_old, char *m_path_new, char
bool
pg_tde_perform_rotate_key(TDEPrincipalKey *principal_key, TDEPrincipalKey *new_principal_key)
{
#define OLD_PRINCIPAL_KEY 0
#define NEW_PRINCIPAL_KEY 1
#define OLD_PRINCIPAL_KEY 0
#define NEW_PRINCIPAL_KEY 1
#define PRINCIPAL_KEY_COUNT 2

off_t curr_pos[PRINCIPAL_KEY_COUNT] = {0};
off_t prev_pos[PRINCIPAL_KEY_COUNT] = {0};
int32 key_index[PRINCIPAL_KEY_COUNT] = {0};
off_t curr_pos[PRINCIPAL_KEY_COUNT] = {0};
off_t prev_pos[PRINCIPAL_KEY_COUNT] = {0};
int32 key_index[PRINCIPAL_KEY_COUNT] = {0};
RelKeyData *rel_key_data[PRINCIPAL_KEY_COUNT];
RelKeyData *enc_rel_key_data[PRINCIPAL_KEY_COUNT];
int m_fd[PRINCIPAL_KEY_COUNT] = {-1};
int k_fd[PRINCIPAL_KEY_COUNT] = {-1};
char m_path[PRINCIPAL_KEY_COUNT][MAXPGPATH];
char k_path[PRINCIPAL_KEY_COUNT][MAXPGPATH];
bool found = false;
off_t read_pos_tmp = 0;
bool is_new_file;
off_t map_size;
off_t keydata_size;
int m_fd[PRINCIPAL_KEY_COUNT] = {-1};
int k_fd[PRINCIPAL_KEY_COUNT] = {-1};
char m_path[PRINCIPAL_KEY_COUNT][MAXPGPATH];
char k_path[PRINCIPAL_KEY_COUNT][MAXPGPATH];
bool found = false;
off_t read_pos_tmp = 0;
bool is_new_file;
off_t map_size;
off_t keydata_size;
XLogPrincipalKeyRotate *xlrec;
off_t xlrec_size;
char db_map_path[MAXPGPATH] = {0};
char db_keydata_path[MAXPGPATH] = {0};
off_t xlrec_size;
char db_map_path[MAXPGPATH] = {0};
char db_keydata_path[MAXPGPATH] = {0};

/* Set the file paths */
pg_tde_set_db_file_paths(principal_key->keyInfo.databaseId,
Expand Down Expand Up @@ -795,8 +795,8 @@ pg_tde_write_map_keydata_files(off_t map_size, char *m_file_data, off_t keydata_
TDEFileHeader *fheader;
char m_path_new[MAXPGPATH];
char k_path_new[MAXPGPATH];
int m_fd_new;
int k_fd_new;
int m_fd_new;
int k_fd_new;
bool is_new_file;
off_t curr_pos = 0;
off_t read_pos_tmp = 0;
Expand Down Expand Up @@ -928,7 +928,7 @@ pg_tde_get_key_from_file(const RelFileLocator *rlocator, uint32 key_type)
inline void
pg_tde_set_db_file_paths(Oid dbOid, Oid spcOid, char *map_path, char *keydata_path)
{
char *db_path = pg_tde_get_tde_file_dir(dbOid, spcOid);
char *db_path = pg_tde_get_tde_file_dir(dbOid, spcOid);

if (map_path)
join_path_components(map_path, db_path, PG_TDE_MAP_FILENAME);
Expand Down Expand Up @@ -1087,7 +1087,7 @@ tde_decrypt_rel_key(TDEPrincipalKey *principal_key, RelKeyData *enc_rel_key_data
static int
pg_tde_open_file(char *tde_filename, TDEPrincipalKeyInfo *principal_key_info, bool should_fill_info, int fileFlags, bool *is_new_file, off_t *curr_pos)
{
int fd = -1;
int fd = -1;
TDEFileHeader fheader;
off_t bytes_read = 0;
off_t bytes_written = 0;
Expand Down Expand Up @@ -1120,7 +1120,7 @@ pg_tde_open_file(char *tde_filename, TDEPrincipalKeyInfo *principal_key_info, bo
static int
pg_tde_open_file_basic(char *tde_filename, int fileFlags, bool ignore_missing)
{
int fd = -1;
int fd = -1;

/*
* Ensuring that we always open the file in binary mode. The caller must
Expand Down Expand Up @@ -1229,7 +1229,7 @@ pg_tde_read_one_keydata(int keydata_fd, int32 key_index, TDEPrincipalKey *princi
/* Check if the file has a valid key */
if ((read_pos + INTERNAL_KEY_LEN) > lseek(keydata_fd, 0, SEEK_END))
{
char db_keydata_path[MAXPGPATH] = {0};
char db_keydata_path[MAXPGPATH] = {0};

pg_tde_set_db_file_paths(principal_key->keyInfo.databaseId, principal_key->keyInfo.tablespaceId, NULL, db_keydata_path);
ereport(FATAL,
Expand Down Expand Up @@ -1294,7 +1294,7 @@ pg_tde_get_principal_key_info(Oid dbOid, Oid spcOid)
*/
if (!is_new_file)
{
size_t sz = sizeof(TDEPrincipalKeyInfo);
size_t sz = sizeof(TDEPrincipalKeyInfo);

principal_key_info = (TDEPrincipalKeyInfo *) palloc(sz);
memcpy(principal_key_info, &fheader.principal_key_info, sz);
Expand Down
6 changes: 3 additions & 3 deletions src/access/pg_tde_xlog_encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static XLogPageHeaderData EncryptCurrentPageHrd;

static ssize_t TDEXLogWriteEncryptedPages(int fd, const void *buf, size_t count, off_t offset);
static char *TDEXLogEncryptBuf = NULL;
static int XLOGChooseNumBuffers(void);
static int XLOGChooseNumBuffers(void);

void
XLogInitGUC(void)
Expand All @@ -65,7 +65,7 @@ XLogInitGUC(void)
static int
XLOGChooseNumBuffers(void)
{
int xbuffers;
int xbuffers;

xbuffers = NBuffers / 32;
if (xbuffers > (wal_segment_size / XLOG_BLCKSZ))
Expand All @@ -81,7 +81,7 @@ XLOGChooseNumBuffers(void)
Size
TDEXLogEncryptBuffSize(void)
{
int xbuffers;
int xbuffers;

xbuffers = (XLOGbuffers == -1) ? XLOGChooseNumBuffers() : XLOGbuffers;
return (Size) XLOG_BLCKSZ * xbuffers;
Expand Down
28 changes: 14 additions & 14 deletions src/catalog/tde_keyring.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef enum ProviderScanType
PROVIDER_SCAN_BY_ID,
PROVIDER_SCAN_BY_TYPE,
PROVIDER_SCAN_ALL
} ProviderScanType;
} ProviderScanType;

#define PG_TDE_KEYRING_FILENAME "pg_tde_keyrings"

Expand All @@ -67,10 +67,10 @@ static void simple_list_free(SimplePtrList *list);
static List *scan_key_provider_file(ProviderScanType scanType, void *scanKey, Oid dbOid, Oid spcOid);

PG_FUNCTION_INFO_V1(pg_tde_add_key_provider_internal);
Datum pg_tde_add_key_provider_internal(PG_FUNCTION_ARGS);
Datum pg_tde_add_key_provider_internal(PG_FUNCTION_ARGS);

PG_FUNCTION_INFO_V1(pg_tde_list_all_key_providers);
Datum pg_tde_list_all_key_providers(PG_FUNCTION_ARGS);
Datum pg_tde_list_all_key_providers(PG_FUNCTION_ARGS);

#define PG_TDE_LIST_PROVIDERS_COLS 4

Expand Down Expand Up @@ -177,7 +177,7 @@ GenericKeyring *
GetKeyProviderByName(const char *provider_name, Oid dbOid, Oid spcOid)
{
GenericKeyring *keyring = NULL;
List *providers = scan_key_provider_file(PROVIDER_SCAN_BY_NAME, (void *) provider_name, dbOid, spcOid);
List *providers = scan_key_provider_file(PROVIDER_SCAN_BY_NAME, (void *) provider_name, dbOid, spcOid);

if (providers != NIL)
{
Expand All @@ -201,8 +201,8 @@ write_key_provider_info(KeyringProvideRecord *provider, Oid database_id,
{
off_t bytes_written = 0;
off_t curr_pos = 0;
int fd;
int max_provider_id = 0;
int fd;
int max_provider_id = 0;
char kp_info_path[MAXPGPATH] = {0};
KeyringProvideRecord existing_provider;

Expand Down Expand Up @@ -330,8 +330,8 @@ pg_tde_add_key_provider_internal(PG_FUNCTION_ARGS)
char *options = text_to_cstring(PG_GETARG_TEXT_PP(2));
bool is_global = PG_GETARG_BOOL(3);
KeyringProvideRecord provider;
Oid dbOid = MyDatabaseId;
Oid spcOid = MyDatabaseTableSpace;
Oid dbOid = MyDatabaseId;
Oid spcOid = MyDatabaseTableSpace;

if (is_global)
{
Expand Down Expand Up @@ -388,7 +388,7 @@ pg_tde_list_all_key_providers(PG_FUNCTION_ARGS)
Datum values[PG_TDE_LIST_PROVIDERS_COLS] = {0};
bool nulls[PG_TDE_LIST_PROVIDERS_COLS] = {0};
GenericKeyring *keyring = (GenericKeyring *) lfirst(lc);
int i = 0;
int i = 0;

values[i++] = Int32GetDatum(keyring->key_id);
values[i++] = CStringGetTextDatum(keyring->provider_name);
Expand All @@ -406,7 +406,7 @@ GenericKeyring *
GetKeyProviderByID(int provider_id, Oid dbOid, Oid spcOid)
{
GenericKeyring *keyring = NULL;
List *providers = scan_key_provider_file(PROVIDER_SCAN_BY_ID, &provider_id, dbOid, spcOid);
List *providers = scan_key_provider_file(PROVIDER_SCAN_BY_ID, &provider_id, dbOid, spcOid);

if (providers != NIL)
{
Expand All @@ -416,7 +416,7 @@ GetKeyProviderByID(int provider_id, Oid dbOid, Oid spcOid)
return keyring;
}

#endif /* !FRONTEND */
#endif /* !FRONTEND */

#ifdef FRONTEND
GenericKeyring *
Expand Down Expand Up @@ -448,7 +448,7 @@ simple_list_free(SimplePtrList *list)
cell = next;
}
}
#endif /* FRONTEND */
#endif /* FRONTEND */

/*
* Scan the key provider info file and can also apply filter based on scanType
Expand All @@ -461,7 +461,7 @@ static SimplePtrList *
scan_key_provider_file(ProviderScanType scanType, void *scanKey, Oid dbOid, Oid spcOid)
{
off_t curr_pos = 0;
int fd;
int fd;
char kp_info_path[MAXPGPATH] = {0};
KeyringProvideRecord provider;
#ifndef FRONTEND
Expand Down Expand Up @@ -662,7 +662,7 @@ get_keyring_infofile_path(char *resPath, Oid dbOid, Oid spcOid)
static bool
fetch_next_key_provider(int fd, off_t *curr_pos, KeyringProvideRecord *provider)
{
off_t bytes_read = 0;
off_t bytes_read = 0;

Assert(provider != NULL);
Assert(fd >= 0);
Expand Down
1 change: 1 addition & 0 deletions typedefs.list
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ LVSavedErrInfo
LogicalRewriteMappingData
LogicalRewriteMappingData
PendingMapEntryDelete
ProviderScanType
PruneFreezeResult
RelKeyCache
RelKeyCacheRec
Expand Down

0 comments on commit e22c25f

Please sign in to comment.