Skip to content

Commit

Permalink
Don't use pre-allocated static buffer for blobs (Rbl) to not waste a …
Browse files Browse the repository at this point in the history
…space in blobs cache by small blobs.
  • Loading branch information
hvlad committed Jan 31, 2025
1 parent ff6849e commit fec34c4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/remote/client/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ IBlob* Attachment::createBlob(CheckStatusWrapper* status, ITransaction* apiTra,
p_blob->p_blob_bpb.cstr_length = 0;
p_blob->p_blob_bpb.cstr_address = NULL;

Rbl* blob = FB_NEW Rbl();
Rbl* blob = FB_NEW Rbl(BLOB_LENGTH);
blob->rbl_blob_id = *blob_id = packet->p_resp.p_resp_blob_id;
blob->rbl_rdb = rdb;
blob->rbl_rtr = transaction;
Expand Down Expand Up @@ -6009,7 +6009,7 @@ IBlob* Attachment::openBlob(CheckStatusWrapper* status, ITransaction* apiTra, IS
//p_blob->p_blob_bpb.cstr_length = 0;
//p_blob->p_blob_bpb.cstr_address = NULL;

Rbl* blob = FB_NEW Rbl;
Rbl* blob = FB_NEW Rbl(BLOB_LENGTH);
blob->rbl_rdb = rdb;
blob->rbl_rtr = transaction;
blob->rbl_blob_id = *id;
Expand Down Expand Up @@ -9486,7 +9486,7 @@ static void release_blob( Rbl* blob)
if (blob->isCached())
{
// Assume buffer was not resized while blob was cached
rdb->decBlobCache(blob->rbl_data.getCapacity());
rdb->decBlobCache(blob->getCachedSize());
}
else
rdb->rdb_port->releaseObject(blob->rbl_id);
Expand Down
5 changes: 2 additions & 3 deletions src/remote/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,16 +1167,15 @@ bool_t xdr_protocol(RemoteXdr* xdrs, PACKET* p)

MAP(xdr_response, p_blob->p_blob_info);

Rbl* blb = tran->createInlineBlob();
AutoPtr<Rbl> blb = tran->createInlineBlob();
p_blob->p_blob_data = &blb->rbl_data;

if (!xdr_blobBuffer(xdrs, p_blob->p_blob_data))
{
tran->rtr_inline_blob = nullptr;
delete blb;

return P_FALSE(xdrs, p);
}
blb.release();
}

return P_TRUE(xdrs, p);
Expand Down
6 changes: 3 additions & 3 deletions src/remote/remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ Rbl* Rtr::createInlineBlob()
{
fb_assert(!rtr_inline_blob);

Rbl* blb = FB_NEW Rbl;
Rbl* blb = FB_NEW Rbl(0);

blb->rbl_rdb = rtr_rdb;
blb->rbl_rtr = this;
Expand All @@ -989,7 +989,7 @@ void Rtr::setupInlineBlob(P_INLINE_BLOB* p_blob)
fb_assert(blb->rbl_data.getCount() <= MAX_USHORT);

blb->rbl_buffer_length = MIN(MAX_USHORT, blb->rbl_data.getCapacity());
if (!rtr_rdb->incBlobCache(blb->rbl_data.getCapacity()))
if (!rtr_rdb->incBlobCache(blb->getCachedSize()))
{
delete blb;
return;
Expand All @@ -1005,7 +1005,7 @@ void Rtr::setupInlineBlob(P_INLINE_BLOB* p_blob)
fb_assert(blb != old);
delete blb;

rtr_rdb->decBlobCache(blb->rbl_data.getCapacity());
rtr_rdb->decBlobCache(blb->getCachedSize());
return;
}

Expand Down
11 changes: 6 additions & 5 deletions src/remote/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ struct RBlobInfo
};

// Used in XDR
class RemBlobBuffer : public Firebird::HalfStaticArray<UCHAR, BLOB_LENGTH>
class RemBlobBuffer : public Firebird::Array<UCHAR>
{
using Firebird::HalfStaticArray<UCHAR, BLOB_LENGTH>::HalfStaticArray;
using Firebird::Array<UCHAR>::Array;
};

struct Rbl : public Firebird::GlobalStorage, public TypedHandle<rem_type_rbl>
Expand Down Expand Up @@ -319,11 +319,11 @@ struct Rbl : public Firebird::GlobalStorage, public TypedHandle<rem_type_rbl>
};

public:
Rbl() :
Rbl(unsigned int initialSize) :
rbl_data(getPool()), rbl_rdb(0), rbl_rtr(0),
rbl_buffer(rbl_data.getBuffer(BLOB_LENGTH)), rbl_ptr(rbl_buffer), rbl_iface(NULL),
rbl_buffer(rbl_data.getBuffer(initialSize)), rbl_ptr(rbl_buffer), rbl_iface(NULL),
rbl_blob_id(NULL_BLOB), rbl_offset(0), rbl_id(0), rbl_flags(0),
rbl_buffer_length(BLOB_LENGTH), rbl_length(0), rbl_fragment_length(0),
rbl_buffer_length(initialSize), rbl_length(0), rbl_fragment_length(0),
rbl_source_interp(0), rbl_target_interp(0), rbl_self(NULL)
{ }

Expand All @@ -339,6 +339,7 @@ struct Rbl : public Firebird::GlobalStorage, public TypedHandle<rem_type_rbl>
static ISC_STATUS badHandle() { return isc_bad_segstr_handle; }

bool isCached() const { return rbl_flags & CACHED; }
unsigned getCachedSize() const { return sizeof(Rbl) + rbl_data.getCapacity(); }

static const SQUAD& generate(const void*, const Rbl* item) { return item->rbl_blob_id; }
};
Expand Down
2 changes: 1 addition & 1 deletion src/remote/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4825,7 +4825,7 @@ ISC_STATUS rem_port::open_blob(P_OP op, P_BLOB* stuff, PACKET* sendL)
USHORT object = 0;
if (!(status_vector.getState() & IStatus::STATE_ERRORS))
{
Rbl* blob = FB_NEW Rbl;
Rbl* blob = FB_NEW Rbl(BLOB_LENGTH);
#ifdef DEBUG_REMOTE_MEMORY
printf("open_blob(server) allocate blob %x\n", blob);
#endif
Expand Down

0 comments on commit fec34c4

Please sign in to comment.