8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 17:23:03 +01:00

Add CachedRequestId mechanism for internal request cache.

This commit is contained in:
Adriano dos Santos Fernandes 2024-08-01 22:44:08 -03:00
parent 0cc8de396a
commit 2c48a4ed06
5 changed files with 61 additions and 4 deletions

View File

@ -265,6 +265,7 @@ Jrd::Attachment::Attachment(MemoryPool* pool, Database* dbb, JProvider* provider
att_generators(*pool),
att_internal(*pool),
att_dyn_req(*pool),
att_internal_cached_statements(*pool),
att_dec_status(DecimalStatus::DEFAULT),
att_charsets(*pool),
att_charset_ids(*pool),
@ -681,9 +682,15 @@ Request* Jrd::Attachment::findSystemRequest(thread_db* tdbb, USHORT id, USHORT w
//Database::CheckoutLockGuard guard(this, dbb_cmp_clone_mutex);
fb_assert(which == IRQ_REQUESTS || which == DYN_REQUESTS);
fb_assert(which == IRQ_REQUESTS || which == DYN_REQUESTS || which == CACHED_REQUESTS);
Statement* statement = (which == IRQ_REQUESTS ? att_internal[id] : att_dyn_req[id]);
if (which == CACHED_REQUESTS && id >= att_internal_cached_statements.getCount())
att_internal_cached_statements.grow(id + 1);
Statement* statement =
which == IRQ_REQUESTS ? att_internal[id] :
which == DYN_REQUESTS ? att_dyn_req[id] :
att_internal_cached_statements[id];
if (!statement)
return NULL;

View File

@ -666,6 +666,7 @@ public:
Firebird::Array<Statement*> att_internal; // internal statements
Firebird::Array<Statement*> att_dyn_req; // internal dyn statements
Firebird::Array<Statement*> att_internal_cached_statements; // internal cached statements
Firebird::ICryptKeyCallback* att_crypt_callback; // callback for DB crypt
Firebird::DecimalStatus att_dec_status; // error handling and rounding

View File

@ -1897,8 +1897,15 @@ void AutoCacheRequest::cacheRequest()
thread_db* tdbb = JRD_get_thread_data();
Attachment* att = tdbb->getAttachment();
Statement** stmt = which == IRQ_REQUESTS ? &att->att_internal[id] :
which == DYN_REQUESTS ? &att->att_dyn_req[id] : nullptr;
if (which == CACHED_REQUESTS && id >= att->att_internal_cached_statements.getCount())
att->att_internal_cached_statements.grow(id + 1);
Statement** stmt =
which == IRQ_REQUESTS ? &att->att_internal[id] :
which == DYN_REQUESTS ? &att->att_dyn_req[id] :
which == CACHED_REQUESTS ? &att->att_internal_cached_statements[id] :
nullptr;
if (!stmt)
{
fb_assert(false);

View File

@ -25,6 +25,7 @@
#define JRD_EXE_PROTO_H
#include "../jrd/cmp_proto.h"
#include <atomic>
namespace Jrd {
class Request;
@ -58,6 +59,29 @@ void EXE_unwind(Jrd::thread_db*, Jrd::Request*);
namespace Jrd
{
class CachedRequestId
{
public:
CachedRequestId()
: id(generator++)
{
fb_assert(id <= MAX_USHORT);
}
CachedRequestId(const CachedRequestId&) = delete;
CachedRequestId& operator=(const CachedRequestId&) = delete;
public:
USHORT getId() const
{
return id;
}
private:
unsigned id;
static inline std::atomic<unsigned> generator;
};
// ASF: To make this class MT-safe in SS for v3, it should be AutoCacheRequest::release job to
// inform CMP that the request is available for subsequent usage.
class AutoCacheRequest
@ -70,6 +94,13 @@ namespace Jrd
{
}
AutoCacheRequest(thread_db* tdbb, const CachedRequestId& cachedRequestId)
: id(cachedRequestId.getId()),
which(CACHED_REQUESTS),
request(tdbb->getAttachment()->findSystemRequest(tdbb, id, which))
{
}
AutoCacheRequest()
: id(0),
which(0),
@ -92,6 +123,15 @@ namespace Jrd
request = tdbb->getAttachment()->findSystemRequest(tdbb, id, which);
}
void reset(thread_db* tdbb, const CachedRequestId& cachedRequestId)
{
release();
id = cachedRequestId.getId();
which = CACHED_REQUESTS;
request = tdbb->getAttachment()->findSystemRequest(tdbb, id, which);
}
void compile(thread_db* tdbb, const UCHAR* blr, ULONG blrLength)
{
if (request)

View File

@ -205,8 +205,10 @@ private:
//
// Flags to indicate normal internal requests vs. dyn internal requests
//
// IRQ_REQUESTS and DYN_REQUESTS are deprecated
const int IRQ_REQUESTS = 1;
const int DYN_REQUESTS = 2;
const int CACHED_REQUESTS = 3;
// Procedure block