Skip to content

Commit fec34c4

Browse files
committed
Don't use pre-allocated static buffer for blobs (Rbl) to not waste a space in blobs cache by small blobs.
1 parent ff6849e commit fec34c4

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/remote/client/interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ IBlob* Attachment::createBlob(CheckStatusWrapper* status, ITransaction* apiTra,
18661866
p_blob->p_blob_bpb.cstr_length = 0;
18671867
p_blob->p_blob_bpb.cstr_address = NULL;
18681868

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

6012-
Rbl* blob = FB_NEW Rbl;
6012+
Rbl* blob = FB_NEW Rbl(BLOB_LENGTH);
60136013
blob->rbl_rdb = rdb;
60146014
blob->rbl_rtr = transaction;
60156015
blob->rbl_blob_id = *id;
@@ -9486,7 +9486,7 @@ static void release_blob( Rbl* blob)
94869486
if (blob->isCached())
94879487
{
94889488
// Assume buffer was not resized while blob was cached
9489-
rdb->decBlobCache(blob->rbl_data.getCapacity());
9489+
rdb->decBlobCache(blob->getCachedSize());
94909490
}
94919491
else
94929492
rdb->rdb_port->releaseObject(blob->rbl_id);

src/remote/protocol.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,16 +1167,15 @@ bool_t xdr_protocol(RemoteXdr* xdrs, PACKET* p)
11671167

11681168
MAP(xdr_response, p_blob->p_blob_info);
11691169

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

11731173
if (!xdr_blobBuffer(xdrs, p_blob->p_blob_data))
11741174
{
11751175
tran->rtr_inline_blob = nullptr;
1176-
delete blb;
1177-
11781176
return P_FALSE(xdrs, p);
11791177
}
1178+
blb.release();
11801179
}
11811180

11821181
return P_TRUE(xdrs, p);

src/remote/remote.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ Rbl* Rtr::createInlineBlob()
963963
{
964964
fb_assert(!rtr_inline_blob);
965965

966-
Rbl* blb = FB_NEW Rbl;
966+
Rbl* blb = FB_NEW Rbl(0);
967967

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

991991
blb->rbl_buffer_length = MIN(MAX_USHORT, blb->rbl_data.getCapacity());
992-
if (!rtr_rdb->incBlobCache(blb->rbl_data.getCapacity()))
992+
if (!rtr_rdb->incBlobCache(blb->getCachedSize()))
993993
{
994994
delete blb;
995995
return;
@@ -1005,7 +1005,7 @@ void Rtr::setupInlineBlob(P_INLINE_BLOB* p_blob)
10051005
fb_assert(blb != old);
10061006
delete blb;
10071007

1008-
rtr_rdb->decBlobCache(blb->rbl_data.getCapacity());
1008+
rtr_rdb->decBlobCache(blb->getCachedSize());
10091009
return;
10101010
}
10111011

src/remote/remote.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ struct RBlobInfo
283283
};
284284

285285
// Used in XDR
286-
class RemBlobBuffer : public Firebird::HalfStaticArray<UCHAR, BLOB_LENGTH>
286+
class RemBlobBuffer : public Firebird::Array<UCHAR>
287287
{
288-
using Firebird::HalfStaticArray<UCHAR, BLOB_LENGTH>::HalfStaticArray;
288+
using Firebird::Array<UCHAR>::Array;
289289
};
290290

291291
struct Rbl : public Firebird::GlobalStorage, public TypedHandle<rem_type_rbl>
@@ -319,11 +319,11 @@ struct Rbl : public Firebird::GlobalStorage, public TypedHandle<rem_type_rbl>
319319
};
320320

321321
public:
322-
Rbl() :
322+
Rbl(unsigned int initialSize) :
323323
rbl_data(getPool()), rbl_rdb(0), rbl_rtr(0),
324-
rbl_buffer(rbl_data.getBuffer(BLOB_LENGTH)), rbl_ptr(rbl_buffer), rbl_iface(NULL),
324+
rbl_buffer(rbl_data.getBuffer(initialSize)), rbl_ptr(rbl_buffer), rbl_iface(NULL),
325325
rbl_blob_id(NULL_BLOB), rbl_offset(0), rbl_id(0), rbl_flags(0),
326-
rbl_buffer_length(BLOB_LENGTH), rbl_length(0), rbl_fragment_length(0),
326+
rbl_buffer_length(initialSize), rbl_length(0), rbl_fragment_length(0),
327327
rbl_source_interp(0), rbl_target_interp(0), rbl_self(NULL)
328328
{ }
329329

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

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

343344
static const SQUAD& generate(const void*, const Rbl* item) { return item->rbl_blob_id; }
344345
};

src/remote/server/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4825,7 +4825,7 @@ ISC_STATUS rem_port::open_blob(P_OP op, P_BLOB* stuff, PACKET* sendL)
48254825
USHORT object = 0;
48264826
if (!(status_vector.getState() & IStatus::STATE_ERRORS))
48274827
{
4828-
Rbl* blob = FB_NEW Rbl;
4828+
Rbl* blob = FB_NEW Rbl(BLOB_LENGTH);
48294829
#ifdef DEBUG_REMOTE_MEMORY
48304830
printf("open_blob(server) allocate blob %x\n", blob);
48314831
#endif

0 commit comments

Comments
 (0)