Skip to content

Commit b9a6905

Browse files
MochalovAlexeyAlexeyMochalov
authored andcommitted
remove redundant plugin reload on super server, update it only on classic after stateLock ast (#8393)
Co-authored-by: aleksey.mochalov <[email protected]>
1 parent 121c542 commit b9a6905

File tree

2 files changed

+17
-48
lines changed

2 files changed

+17
-48
lines changed

src/jrd/CryptoManager.cpp

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ namespace Jrd {
376376
return;
377377

378378
fb_assert(tdbb);
379-
lockAndReadHeader(tdbb, CRYPT_HDR_NOWAIT);
379+
lockAndReadHeader(tdbb, CRYPT_HDR_NOWAIT | CRYPT_RELOAD_PLUGIN);
380380
}
381381

382382
void CryptoManager::lockAndReadHeader(thread_db* tdbb, unsigned flags)
@@ -415,9 +415,15 @@ namespace Jrd {
415415
crypt = hdr->hdr_flags & Ods::hdr_encrypted;
416416
process = hdr->hdr_flags & Ods::hdr_crypt_process;
417417

418+
if (flags & CRYPT_RELOAD_PLUGIN && cryptPlugin)
419+
{
420+
PluginManagerInterfacePtr()->releasePlugin(cryptPlugin);
421+
cryptPlugin = NULL;
422+
}
423+
418424
// tdbb w/o attachment comes when database is shutting down in the end of detachDatabase()
419425
// the only needed here page is header, i.e. we can live w/o cryptPlugin
420-
if ((crypt || process) && tdbb->getAttachment())
426+
if ((crypt || process) && !cryptPlugin && tdbb->getAttachment())
421427
{
422428
ClumpletWriter hc(ClumpletWriter::UnTagged, hdr->hdr_page_size);
423429
hdr.getClumplets(hc);
@@ -426,55 +432,17 @@ namespace Jrd {
426432
else
427433
keyName = "";
428434

429-
if (!cryptPlugin)
435+
loadPlugin(tdbb, hdr->hdr_crypt_plugin);
436+
string valid;
437+
calcValidation(valid, cryptPlugin);
438+
if (hc.find(Ods::HDR_crypt_hash))
430439
{
431-
loadPlugin(tdbb, hdr->hdr_crypt_plugin);
432-
string valid;
433-
calcValidation(valid, cryptPlugin);
434-
if (hc.find(Ods::HDR_crypt_hash))
435-
{
436-
hc.getString(hash);
437-
if (hash != valid)
438-
(Arg::Gds(isc_bad_crypt_key) << keyName).raise();
439-
}
440-
else
441-
hash = valid;
440+
hc.getString(hash);
441+
if (hash != valid)
442+
(Arg::Gds(isc_bad_crypt_key) << keyName).raise();
442443
}
443444
else
444-
{
445-
for (GetPlugins<IKeyHolderPlugin> keyControl(IPluginManager::TYPE_KEY_HOLDER, dbb.dbb_config);
446-
keyControl.hasData(); keyControl.next())
447-
{
448-
// check does keyHolder want to provide a key for us
449-
IKeyHolderPlugin* keyHolder = keyControl.plugin();
450-
451-
FbLocalStatus st;
452-
int keyCallbackRc = keyHolder->keyCallback(&st, tdbb->getAttachment()->att_crypt_callback);
453-
st.check();
454-
if (!keyCallbackRc)
455-
continue;
456-
457-
// validate a key
458-
AutoPlugin<IDbCryptPlugin> crypt(checkFactory->makeInstance());
459-
setDbInfo(crypt);
460-
crypt->setKey(&st, 1, &keyHolder, keyName.c_str());
461-
462-
463-
string valid;
464-
calcValidation(valid, crypt);
465-
if (hc.find(Ods::HDR_crypt_hash))
466-
{
467-
hc.getString(hash);
468-
if (hash == valid)
469-
{
470-
// unload old plugin and set new one
471-
PluginManagerInterfacePtr()->releasePlugin(cryptPlugin);
472-
cryptPlugin = NULL;
473-
cryptPlugin = crypt.release();
474-
}
475-
}
476-
}
477-
}
445+
hash = valid;
478446
}
479447

480448
if (cryptPlugin && (flags & CRYPT_HDR_INIT))

src/jrd/CryptoManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ class CryptoManager FB_FINAL : public Firebird::PermanentStorage, public BarSync
374374
void lockAndReadHeader(thread_db* tdbb, unsigned flags = 0);
375375
static const unsigned CRYPT_HDR_INIT = 0x01;
376376
static const unsigned CRYPT_HDR_NOWAIT = 0x02;
377+
static const unsigned CRYPT_RELOAD_PLUGIN = 0x04;
377378

378379
void addClumplet(Firebird::string& value, Firebird::ClumpletReader& block, UCHAR tag);
379380
void calcDigitalSignature(thread_db* tdbb, Firebird::string& signature, const class Header& hdr);

0 commit comments

Comments
 (0)