@@ -524,37 +524,6 @@ pg_tde_perform_rotate_key(TDEPrincipalKey *principal_key, TDEPrincipalKey *new_p
524
524
}
525
525
}
526
526
527
- /*
528
- * Checks if the key map file for the given database has any non-empty entries.
529
- *
530
- * The caller must hold the lock on the files before calling this function.
531
- */
532
- bool
533
- pg_tde_is_key_map_empty (Oid dbOid )
534
- {
535
- char path [MAXPGPATH ];
536
- off_t pos ;
537
- int fd ;
538
- TDEMapEntry map_entry ;
539
-
540
- pg_tde_set_db_file_path (dbOid , path );
541
-
542
- fd = pg_tde_open_file_read (path , false, & pos );
543
-
544
- while (pg_tde_read_one_map_entry (fd , & map_entry , & pos ))
545
- {
546
- if (map_entry .type != MAP_ENTRY_EMPTY )
547
- {
548
- close (fd );
549
- return false;
550
- }
551
- }
552
-
553
- close (fd );
554
- return true;
555
- }
556
-
557
-
558
527
void
559
528
pg_tde_delete_principal_key_redo (Oid dbOid )
560
529
{
@@ -578,20 +547,10 @@ pg_tde_delete_principal_key(Oid dbOid, bool write_xlog)
578
547
char path [MAXPGPATH ];
579
548
580
549
Assert (LWLockHeldByMeInMode (tde_lwlock_enc_keys (), LW_EXCLUSIVE ));
550
+ Assert (pg_tde_count_relations (dbOid ) == 0 );
581
551
582
552
pg_tde_set_db_file_path (dbOid , path );
583
553
584
- /*
585
- * Check that there aro no local keys in the map file, i.e. nothing is
586
- * encrypted with the principal key.
587
- */
588
- if (!pg_tde_is_key_map_empty (dbOid ))
589
- {
590
- ereport (ERROR ,
591
- errcode (ERRCODE_INTERNAL_ERROR ),
592
- errmsg ("could not delete key, key map file is not empty" ));
593
- }
594
-
595
554
if (write_xlog )
596
555
{
597
556
XLogBeginInsert ();
@@ -742,20 +701,21 @@ pg_tde_find_map_entry(const RelFileLocator *rlocator, TDEMapEntryType key_type,
742
701
* positive is more harmful this might not be.
743
702
*
744
703
* Works even if the database has no map file.
704
+ * The caller must hold a shared or exclusive lock on the
705
+ * tde_lwlock_enc_keys() lock.
745
706
*/
746
707
int
747
708
pg_tde_count_relations (Oid dbOid )
748
709
{
749
710
char db_map_path [MAXPGPATH ];
750
- LWLock * lock_pk = tde_lwlock_enc_keys ();
751
711
File map_fd ;
752
712
off_t curr_pos = 0 ;
753
713
TDEMapEntry map_entry ;
754
714
int count = 0 ;
755
715
756
- pg_tde_set_db_file_path ( dbOid , db_map_path );
716
+ Assert ( LWLockHeldByMeInMode ( tde_lwlock_enc_keys (), LW_SHARED ) || LWLockHeldByMeInMode ( tde_lwlock_enc_keys (), LW_EXCLUSIVE ) );
757
717
758
- LWLockAcquire ( lock_pk , LW_SHARED );
718
+ pg_tde_set_db_file_path ( dbOid , db_map_path );
759
719
760
720
map_fd = pg_tde_open_file_read (db_map_path , true, & curr_pos );
761
721
if (map_fd < 0 )
@@ -769,8 +729,6 @@ pg_tde_count_relations(Oid dbOid)
769
729
770
730
close (map_fd );
771
731
772
- LWLockRelease (lock_pk );
<
8000
code>773
-
774
732
return count ;
775
733
}
776
734
0 commit comments