Skip to content

Commit 2616e27

Browse files
committed
Clean up tdeheap_xlog_seg_read()
Several variables were at a too long scope or were initialized when they should not be. Plus convert a while loop to a for loop.
1 parent b11d51c commit 2616e27

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

contrib/pg_tde/src/access/pg_tde_xlog_encrypt.c

+6-13
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,7 @@ tdeheap_xlog_seg_read(int fd, void *buf, size_t count, off_t offset,
252252
{
253253
ssize_t readsz;
254254
WALKeyCacheRec *keys = pg_tde_get_wal_cache_keys();
255-
XLogRecPtr write_key_lsn = 0;
256-
WALKeyCacheRec *curr_key = NULL;
257-
off_t dec_off = 0;
258-
off_t dec_end = 0;
259-
size_t dec_sz = 0;
255+
XLogRecPtr write_key_lsn;
260256
XLogRecPtr data_start;
261257
XLogRecPtr data_end;
262258

@@ -278,7 +274,6 @@ tdeheap_xlog_seg_read(int fd, void *buf, size_t count, off_t offset,
278274

279275
#ifndef FRONTEND
280276
write_key_lsn = pg_atomic_read_u64(&EncryptionState->enc_key_lsn);
281-
#endif
282277

283278
if (write_key_lsn != 0)
284279
{
@@ -295,6 +290,7 @@ tdeheap_xlog_seg_read(int fd, void *buf, size_t count, off_t offset,
295290
keys = pg_tde_get_wal_cache_keys();
296291
}
297292
}
293+
#endif
298294

299295
XLogSegNoOffsetToRecPtr(segno, offset, segSize, data_start);
300296
XLogSegNoOffsetToRecPtr(segno, offset + count, segSize, data_end);
@@ -303,8 +299,7 @@ tdeheap_xlog_seg_read(int fd, void *buf, size_t count, off_t offset,
303299
* TODO: this is higly ineffective. We should get rid of linked list and
304300
* search from the last key as this is what the walsender is useing.
305301
*/
306-
curr_key = keys;
307-
while (curr_key)
302+
for (WALKeyCacheRec *curr_key = keys; curr_key != NULL; curr_key = curr_key->next)
308303
{
309304
#ifdef TDE_XLOG_DEBUG
310305
elog(DEBUG1, "WAL key %X/%X-%X/%X, encrypted: %s",
@@ -323,12 +318,12 @@ tdeheap_xlog_seg_read(int fd, void *buf, size_t count, off_t offset,
323318
if (data_start < curr_key->end_lsn && data_end > curr_key->start_lsn)
324319
{
325320
char iv_prefix[16];
321+
off_t dec_off = XLogSegmentOffset(Max(data_start, curr_key->start_lsn), segSize);
322+
off_t dec_end = XLogSegmentOffset(Min(data_end, curr_key->end_lsn), segSize);
323+
size_t dec_sz;
326324

327325
CalcXLogPageIVPrefix(tli, segno, curr_key->key->base_iv, iv_prefix);
328326

329-
dec_off = XLogSegmentOffset(Max(data_start, curr_key->start_lsn), segSize);
330-
dec_end = XLogSegmentOffset(Min(data_end, curr_key->end_lsn), segSize);
331-
332327
/* We have reached the end of the segment */
333328
if (dec_end == 0)
334329
{
@@ -352,8 +347,6 @@ tdeheap_xlog_seg_read(int fd, void *buf, size_t count, off_t offset,
352347
}
353348
}
354349
}
355-
356-
curr_key = curr_key->next;
357350
}
358351

359352
return readsz;

0 commit comments

Comments
 (0)