mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-02-02 10:00:38 +01:00
Add CachedRequestId mechanism for internal request cache.
This commit is contained in:
parent
0cc8de396a
commit
2c48a4ed06
@ -265,6 +265,7 @@ Jrd::Attachment::Attachment(MemoryPool* pool, Database* dbb, JProvider* provider
|
|||||||
att_generators(*pool),
|
att_generators(*pool),
|
||||||
att_internal(*pool),
|
att_internal(*pool),
|
||||||
att_dyn_req(*pool),
|
att_dyn_req(*pool),
|
||||||
|
att_internal_cached_statements(*pool),
|
||||||
att_dec_status(DecimalStatus::DEFAULT),
|
att_dec_status(DecimalStatus::DEFAULT),
|
||||||
att_charsets(*pool),
|
att_charsets(*pool),
|
||||||
att_charset_ids(*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);
|
//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)
|
if (!statement)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -666,6 +666,7 @@ public:
|
|||||||
|
|
||||||
Firebird::Array<Statement*> att_internal; // internal statements
|
Firebird::Array<Statement*> att_internal; // internal statements
|
||||||
Firebird::Array<Statement*> att_dyn_req; // internal dyn 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::ICryptKeyCallback* att_crypt_callback; // callback for DB crypt
|
||||||
Firebird::DecimalStatus att_dec_status; // error handling and rounding
|
Firebird::DecimalStatus att_dec_status; // error handling and rounding
|
||||||
|
|
||||||
|
@ -1897,8 +1897,15 @@ void AutoCacheRequest::cacheRequest()
|
|||||||
thread_db* tdbb = JRD_get_thread_data();
|
thread_db* tdbb = JRD_get_thread_data();
|
||||||
Attachment* att = tdbb->getAttachment();
|
Attachment* att = tdbb->getAttachment();
|
||||||
|
|
||||||
Statement** stmt = which == IRQ_REQUESTS ? &att->att_internal[id] :
|
if (which == CACHED_REQUESTS && id >= att->att_internal_cached_statements.getCount())
|
||||||
which == DYN_REQUESTS ? &att->att_dyn_req[id] : nullptr;
|
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)
|
if (!stmt)
|
||||||
{
|
{
|
||||||
fb_assert(false);
|
fb_assert(false);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#define JRD_EXE_PROTO_H
|
#define JRD_EXE_PROTO_H
|
||||||
|
|
||||||
#include "../jrd/cmp_proto.h"
|
#include "../jrd/cmp_proto.h"
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
namespace Jrd {
|
namespace Jrd {
|
||||||
class Request;
|
class Request;
|
||||||
@ -58,6 +59,29 @@ void EXE_unwind(Jrd::thread_db*, Jrd::Request*);
|
|||||||
|
|
||||||
namespace Jrd
|
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
|
// 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.
|
// inform CMP that the request is available for subsequent usage.
|
||||||
class AutoCacheRequest
|
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()
|
AutoCacheRequest()
|
||||||
: id(0),
|
: id(0),
|
||||||
which(0),
|
which(0),
|
||||||
@ -92,6 +123,15 @@ namespace Jrd
|
|||||||
request = tdbb->getAttachment()->findSystemRequest(tdbb, id, which);
|
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)
|
void compile(thread_db* tdbb, const UCHAR* blr, ULONG blrLength)
|
||||||
{
|
{
|
||||||
if (request)
|
if (request)
|
||||||
|
@ -205,8 +205,10 @@ private:
|
|||||||
//
|
//
|
||||||
// Flags to indicate normal internal requests vs. dyn internal requests
|
// Flags to indicate normal internal requests vs. dyn internal requests
|
||||||
//
|
//
|
||||||
|
// IRQ_REQUESTS and DYN_REQUESTS are deprecated
|
||||||
const int IRQ_REQUESTS = 1;
|
const int IRQ_REQUESTS = 1;
|
||||||
const int DYN_REQUESTS = 2;
|
const int DYN_REQUESTS = 2;
|
||||||
|
const int CACHED_REQUESTS = 3;
|
||||||
|
|
||||||
|
|
||||||
// Procedure block
|
// Procedure block
|
||||||
|
Loading…
Reference in New Issue
Block a user