diff --git a/contrib/pg_tde/src/catalog/tde_principal_key.c b/contrib/pg_tde/src/catalog/tde_principal_key.c index c8ae366101091..ab4516a8a6e2e 100644 --- a/contrib/pg_tde/src/catalog/tde_principal_key.c +++ b/contrib/pg_tde/src/catalog/tde_principal_key.c @@ -819,47 +819,40 @@ TDEPrincipalKey * GetPrincipalKey(Oid dbOid, LWLockMode lockMode) { TDEPrincipalKey *principalKey = GetPrincipalKeyNoDefault(dbOid, lockMode); -#ifndef FRONTEND - TDEPrincipalKey *newPrincipalKey = NULL; -#endif - - if (principalKey != NULL) - { - return principalKey; - } #ifndef FRONTEND - - /* - * If database doesn't have dedicated principal key we should try to - * fallback to default principal key. - */ - - /* Lock is already updated to exclusive at this point */ - principalKey = GetPrincipalKeyNoDefault(DEFAULT_DATA_TDE_OID, LW_EXCLUSIVE); - if (principalKey == NULL) { - return NULL; - } + /* + * If database doesn't have dedicated principal key we should try to + * fallback to default principal key. + */ + TDEPrincipalKey *newPrincipalKey; - newPrincipalKey = palloc_object(TDEPrincipalKey); - *newPrincipalKey = *principalKey; - newPrincipalKey->keyInfo.databaseId = dbOid; + /* Lock is already updated to exclusive at this point */ + principalKey = GetPrincipalKeyNoDefault(DEFAULT_DATA_TDE_OID, LW_EXCLUSIVE); - /* - * We have to write default principal key info to database keys file. - * However we cannot write XLOG records about this operation as current - * funcion may be invoked during server startup/recovery where WAL writes - * forbidden. - */ - pg_tde_save_principal_key(newPrincipalKey, false); + if (principalKey == NULL) + return NULL; - push_principal_key_to_cache(newPrincipalKey); + newPrincipalKey = palloc_object(TDEPrincipalKey); + *newPrincipalKey = *principalKey; + newPrincipalKey->keyInfo.databaseId = dbOid; - pfree(newPrincipalKey); + /* + * We have to write default principal key info to database keys file. + * However we cannot write XLOG records about this operation as + * current funcion may be invoked during server startup/recovery where + * WAL writes forbidden. + */ + pg_tde_save_principal_key(newPrincipalKey, false); + + push_principal_key_to_cache(newPrincipalKey); - principalKey = GetPrincipalKeyNoDefault(dbOid, LW_EXCLUSIVE); + pfree(newPrincipalKey); + + principalKey = GetPrincipalKeyNoDefault(dbOid, LW_EXCLUSIVE); + } #endif return principalKey;