Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDB$BLOB_UTIL system package. #281

Merged
merged 15 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions src/jrd/ExtEngineManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ using namespace Firebird;
using namespace Jrd;


static EngineCheckout::Type checkoutType(IExternalEngine* engine);


namespace
{
// Internal message node.
Expand Down Expand Up @@ -477,8 +480,6 @@ namespace
}


namespace Jrd {

template <typename T> class ExtEngineManager::ContextManager
{
public:
Expand Down Expand Up @@ -556,7 +557,7 @@ template <typename T> class ExtEngineManager::ContextManager
char charSetName[MAX_SQL_IDENTIFIER_SIZE];

{ // scope
EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));

FbLocalStatus status;
obj->getCharSet(&status, attInfo->context, charSetName, MAX_SQL_IDENTIFIER_LEN);
Expand Down Expand Up @@ -736,7 +737,7 @@ void ExtEngineManager::Function::execute(thread_db* tdbb, UCHAR* inMsg, UCHAR* o
CallerName(obj_udf, udf->getName().identifier, userName) :
CallerName(obj_package_header, udf->getName().package, userName)));

EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));

FbLocalStatus status;
function->execute(&status, attInfo->context, inMsg, outMsg);
Expand Down Expand Up @@ -792,7 +793,7 @@ ExtEngineManager::ResultSet::ResultSet(thread_db* tdbb, UCHAR* inMsg, UCHAR* out

charSet = attachment->att_charset;

EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));

FbLocalStatus status;
resultSet = procedure->procedure->open(&status, attInfo->context, inMsg, outMsg);
Expand All @@ -804,7 +805,7 @@ ExtEngineManager::ResultSet::~ResultSet()
{
if (resultSet)
{
EngineCheckout cout(JRD_get_thread_data(), FB_FUNCTION);
EngineCheckout cout(JRD_get_thread_data(), FB_FUNCTION, checkoutType(attInfo->engine));
resultSet->dispose();
}
}
Expand All @@ -824,7 +825,7 @@ bool ExtEngineManager::ResultSet::fetch(thread_db* tdbb)
CallerName(obj_procedure, procedure->prc->getName().identifier, userName) :
CallerName(obj_package_header, procedure->prc->getName().package, userName)));

EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));

FbLocalStatus status;
bool ret = resultSet->fetch(&status);
Expand Down Expand Up @@ -914,7 +915,7 @@ void ExtEngineManager::Trigger::execute(thread_db* tdbb, jrd_req* request, unsig
setValues(tdbb, request, newMsg, newRpb);

{ // scope
EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));

FbLocalStatus status;
trigger->execute(&status, attInfo->context, action,
Expand Down Expand Up @@ -1232,7 +1233,7 @@ void ExtEngineManager::closeAttachment(thread_db* tdbb, Attachment* attachment)
enginesCopy.put(accessor.current()->first, accessor.current()->second);
}

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);

EnginesMap::Accessor accessor(&enginesCopy);
for (bool found = accessor.getFirst(); found; found = accessor.getNext())
Expand All @@ -1247,7 +1248,7 @@ void ExtEngineManager::closeAttachment(thread_db* tdbb, Attachment* attachment)
FbLocalStatus status;
engine->closeAttachment(&status, attInfo->context); //// FIXME: log status

// Check whether the engine is used by other attachments.
// Check whether the engine is used by other attachments.
// If no one uses, release it.
bool close = true;
WriteLockGuard writeGuard(enginesLock, FB_FUNCTION);
Expand All @@ -1263,7 +1264,7 @@ void ExtEngineManager::closeAttachment(thread_db* tdbb, Attachment* attachment)
}

if (close)
{
{
if (engines.remove(accessor.current()->first)) // If engine has already been deleted - nothing to do
engine->release();
}
Expand Down Expand Up @@ -1311,7 +1312,7 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, CompilerScratch* csb, Jrd::
RefPtr<IMessageMetadata> extInputParameters, extOutputParameters;

{ // scope
EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));

externalFunction = attInfo->engine->makeFunction(&status, attInfo->context, metadata,
inBuilder, outBuilder);
Expand Down Expand Up @@ -1392,7 +1393,7 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, CompilerScratch* csb, Jrd::
}
catch (...)
{
EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));
externalFunction->dispose();
throw;
}
Expand Down Expand Up @@ -1435,7 +1436,7 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
RefPtr<IMessageMetadata> extInputParameters, extOutputParameters;

{ // scope
EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));

externalProcedure = attInfo->engine->makeProcedure(&status, attInfo->context, metadata,
inBuilder, outBuilder);
Expand Down Expand Up @@ -1523,7 +1524,7 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
}
catch (...)
{
EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));
externalProcedure->dispose();
throw;
}
Expand Down Expand Up @@ -1585,7 +1586,7 @@ void ExtEngineManager::makeTrigger(thread_db* tdbb, CompilerScratch* csb, Jrd::T
IExternalTrigger* externalTrigger;

{ // scope
EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));

FbLocalStatus status;
externalTrigger = attInfo->engine->makeTrigger(&status, attInfo->context, metadata,
Expand Down Expand Up @@ -1621,7 +1622,7 @@ void ExtEngineManager::makeTrigger(thread_db* tdbb, CompilerScratch* csb, Jrd::T
}
catch (...)
{
EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));
externalTrigger->dispose();
throw;
}
Expand Down Expand Up @@ -1730,7 +1731,7 @@ ExtEngineManager::EngineAttachmentInfo* ExtEngineManager::getEngineAttachment(
enginesAttachments.put(key, attInfo);

ContextManager<IExternalFunction> ctxManager(tdbb, attInfo, attInfo->adminCharSet);
EngineCheckout cout(tdbb, FB_FUNCTION);
EngineCheckout cout(tdbb, FB_FUNCTION, checkoutType(attInfo->engine));
FbLocalStatus status;
engine->openAttachment(&status, attInfo->context); //// FIXME: log status
}
Expand Down Expand Up @@ -1773,4 +1774,10 @@ void ExtEngineManager::setupAdminCharSet(thread_db* tdbb, IExternalEngine* engin
}


} // namespace Jrd
//---------------------


static EngineCheckout::Type checkoutType(IExternalEngine* engine)
{
return engine == SystemEngine::INSTANCE ? EngineCheckout::AVOID : EngineCheckout::REQUIRED;
}
8 changes: 4 additions & 4 deletions src/jrd/GlobalRWLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool GlobalRWLock::lockWrite(thread_db* tdbb, SSHORT wait)

while (readers > 0 )
{
EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);
noReaders.wait(counterMutex);
}

Expand All @@ -120,7 +120,7 @@ bool GlobalRWLock::lockWrite(thread_db* tdbb, SSHORT wait)

while (currentWriter || pendingLock)
{
EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);
writerFinished.wait(counterMutex);
}

Expand Down Expand Up @@ -237,7 +237,7 @@ bool GlobalRWLock::lockRead(thread_db* tdbb, SSHORT wait, const bool queueJump)

while (pendingWriters > 0 || currentWriter)
{
EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);
writerFinished.wait(counterMutex);
}

Expand All @@ -248,7 +248,7 @@ bool GlobalRWLock::lockRead(thread_db* tdbb, SSHORT wait, const bool queueJump)
break;

MutexUnlockGuard cout(counterMutex, FB_FUNCTION);
EngineCheckout cout2(tdbb, FB_FUNCTION, true);
EngineCheckout cout2(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);
Thread::yield();
}

Expand Down
28 changes: 19 additions & 9 deletions src/jrd/jrd.h
Original file line number Diff line number Diff line change
Expand Up @@ -1078,18 +1078,28 @@ namespace Jrd {
class EngineCheckout
{
public:
EngineCheckout(thread_db* tdbb, const char* from, bool optional = false)
enum Type
{
REQUIRED,
OPTIONAL,
asfernandes marked this conversation as resolved.
Show resolved Hide resolved
AVOID
};

EngineCheckout(thread_db* tdbb, const char* from, Type type = REQUIRED)
: m_tdbb(tdbb), m_from(from)
{
Attachment* const att = tdbb ? tdbb->getAttachment() : NULL;
if (type != AVOID)
{
Attachment* const att = tdbb ? tdbb->getAttachment() : NULL;

if (att)
m_ref = att->getStable();
if (att)
m_ref = att->getStable();

fb_assert(optional || m_ref.hasData());
fb_assert(type == OPTIONAL || m_ref.hasData());

if (m_ref.hasData())
m_ref->getMutex()->leave();
if (m_ref.hasData())
m_ref->getMutex()->leave();
}
}

~EngineCheckout()
Expand Down Expand Up @@ -1123,7 +1133,7 @@ namespace Jrd {
{
if (!m_mutex.tryEnter(from))
{
EngineCheckout cout(tdbb, from, optional);
EngineCheckout cout(tdbb, from, optional ? EngineCheckout::OPTIONAL : EngineCheckout::REQUIRED);
m_mutex.enter(from);
}
}
Expand Down Expand Up @@ -1151,7 +1161,7 @@ namespace Jrd {
{
if (!m_sync.lockConditional(type, from))
{
EngineCheckout cout(tdbb, from, optional);
EngineCheckout cout(tdbb, from, optional ? EngineCheckout::OPTIONAL : EngineCheckout::REQUIRED);
m_sync.lock(type);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/jrd/os/posix/unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void PIO_extend(thread_db* tdbb, jrd_file* main_file, const ULONG extPages, cons

#if defined(HAVE_LINUX_FALLOC_H) && defined(HAVE_FALLOCATE)

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);

ULONG leftPages = extPages;
for (jrd_file* file = main_file; file && leftPages; file = file->fil_next)
Expand Down Expand Up @@ -388,7 +388,7 @@ void PIO_flush(thread_db* tdbb, jrd_file* main_file)
// Since all SUPERSERVER_V2 database and shadow I/O is synchronous, this is a no-op.
#ifndef SUPERSERVER_V2

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);
MutexLockGuard guard(main_file->fil_mutex, FB_FUNCTION);

for (jrd_file* file = main_file; file; file = file->fil_next)
Expand Down Expand Up @@ -608,7 +608,7 @@ USHORT PIO_init_data(thread_db* tdbb, jrd_file* main_file, FbStatusVector* statu

FB_UINT64 offset;

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);

jrd_file* file = seek_file(main_file, &bdb, &offset, status_vector);

Expand Down Expand Up @@ -756,7 +756,7 @@ bool PIO_read(thread_db* tdbb, jrd_file* file, BufferDesc* bdb, Ods::pag* page,

Database* const dbb = tdbb->getDatabase();

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);

const SLONG size = dbb->dbb_page_size;

Expand Down Expand Up @@ -817,7 +817,7 @@ bool PIO_write(thread_db* tdbb, jrd_file* file, BufferDesc* bdb, Ods::pag* page,

Database* const dbb = tdbb->getDatabase();

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);

const SLONG size = dbb->dbb_page_size;

Expand Down
14 changes: 7 additions & 7 deletions src/jrd/os/win32/winnt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void PIO_extend(thread_db* tdbb, jrd_file* main_file, const ULONG extPages, cons
if (!main_file->fil_ext_lock)
return;

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);
FileExtendLockGuard extLock(main_file->fil_ext_lock, true);

ULONG leftPages = extPages;
Expand Down Expand Up @@ -314,7 +314,7 @@ void PIO_flush(thread_db* tdbb, jrd_file* main_file)
* Flush the operating system cache back to good, solid oxide.
*
**************************************/
EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);

for (jrd_file* file = main_file; file; file = file->fil_next)
FlushFileBuffers(file->fil_desc);
Expand Down Expand Up @@ -437,7 +437,7 @@ USHORT PIO_init_data(thread_db* tdbb, jrd_file* main_file, FbStatusVector* statu

Database* const dbb = tdbb->getDatabase();

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);
FileExtendLockGuard extLock(main_file->fil_ext_lock, false);

// Fake buffer, used in seek_file. Page space ID doesn't matter there
Expand Down Expand Up @@ -570,7 +570,7 @@ bool PIO_read(thread_db* tdbb, jrd_file* file, BufferDesc* bdb, Ods::pag* page,

const DWORD size = dbb->dbb_page_size;

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);
FileExtendLockGuard extLock(file->fil_ext_lock, false);

OVERLAPPED overlapped;
Expand Down Expand Up @@ -615,7 +615,7 @@ bool PIO_read_ahead(thread_db* tdbb,

Database* const dbb = tdbb->getDatabase();

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);

// If an I/O status block was passed the caller wants to queue an asynchronous I/O.

Expand Down Expand Up @@ -701,7 +701,7 @@ bool PIO_status(thread_db* tdbb, phys_io_blk* piob, FbStatusVector* status_vecto
* Check the status of an asynchronous I/O.
*
**************************************/
EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);

if (!(piob->piob_flags & PIOB_success))
{
Expand Down Expand Up @@ -744,7 +744,7 @@ bool PIO_write(thread_db* tdbb, jrd_file* file, BufferDesc* bdb, Ods::pag* page,

const DWORD size = dbb->dbb_page_size;

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);
FileExtendLockGuard extLock(file->fil_ext_lock, false);

OVERLAPPED overlapped;
Expand Down
2 changes: 1 addition & 1 deletion src/jrd/tra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ void TRA_invalidate(thread_db* tdbb, ULONG mask)

Database* const database = tdbb->getDatabase();

EngineCheckout cout(tdbb, FB_FUNCTION, true);
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::OPTIONAL);

SyncLockGuard dbbSync(&database->dbb_sync, SYNC_SHARED, "TRA_invalidate");

Expand Down
Loading