@@ -120,6 +120,9 @@ RelKeyCache tde_rel_key_cache = {
120
120
};
121
121
122
122
123
+ /*
124
+ * TODO: WAL should have its own RelKeyCache
125
+ */
123
126
static WALKeyCacheRec * tde_wal_key_cache = NULL ;
124
127
static WALKeyCacheRec * tde_wal_key_last_rec = NULL ;
125
128
@@ -147,6 +150,7 @@ static void pg_tde_write_keydata(char *db_keydata_path, TDEPrincipalKeyInfo *pri
147
150
static void pg_tde_write_one_keydata (int keydata_fd , int32 key_index , InternalKey * enc_rel_key_data );
148
151
static int keyrotation_init_file (TDEPrincipalKeyInfo * new_principal_key_info , char * rotated_filename , char * filename , bool * is_new_file , off_t * curr_pos );
149
152
static void finalize_key_rotation (char * m_path_old , char * k_path_old , char * m_path_new , char * k_path_new );
153
+ static void update_wal_keys_cache (void );
150
154
151
155
InternalKey *
152
156
pg_tde_create_smgr_key (const RelFileLocatorBackend * newrlocator )
@@ -1552,6 +1556,25 @@ pg_tde_get_wal_cache_keys(void)
1552
1556
return tde_wal_key_cache ;
1553
1557
}
1554
1558
1559
+ /* Updates WAL keys cache pointers */
1560
+ static void
1561
+ update_wal_keys_cache (void )
1562
+ {
1563
+ WALKeyCacheRec * wal_rec = tde_wal_key_cache ;
1564
+ RelFileLocator rlocator = GLOBAL_SPACE_RLOCATOR (XLOG_TDE_OID );
1565
+
1566
+ for (int i = 0 ; i < tde_rel_key_cache .len && wal_rec ; i ++ )
1567
+ {
1568
+ RelKeyCacheRec * rec = tde_rel_key_cache .data + i ;
1569
+
1570
+ if (RelFileLocatorEquals (rec -> locator , rlocator ))
1571
+ {
1572
+ wal_rec -> key = & rec -> key ;
1573
+ wal_rec = wal_rec -> next ;
1574
+ }
1575
+ }
1576
+ }
1577
+
1555
1578
InternalKey *
1556
1579
pg_tde_read_last_wal_key (void )
1557
1580
{
@@ -1789,6 +1812,9 @@ pg_tde_put_key_into_cache(const RelFileLocator *rlocator, InternalKey *key)
1789
1812
elog (WARNING , "could not mlock internal key cache pages: %m" );
1790
1813
1791
1814
tde_rel_key_cache .cap = (size - 1 ) / sizeof (RelKeyCacheRec );
1815
+
1816
+ /* update wal key pointers after moving the cache */
1817
+ update_wal_keys_cache ();
1792
1818
}
1793
1819
1794
1820
rec = tde_rel_key_cache .data + tde_rel_key_cache .len ;
0 commit comments