Skip to content

Commit 9980a3f

Browse files
committed
Batch interface in embedded mode appears to be working without BLOBs
1 parent 76eeac2 commit 9980a3f

File tree

10 files changed

+58
-54
lines changed

10 files changed

+58
-54
lines changed

src/dsql/DsqlBatch.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ namespace {
106106
{
107107
try
108108
{
109-
if (pos >= reccount)
110-
(Arg::Gds(isc_random) << "Position is out of range").raise();
111-
112109
ULONG index = find(pos);
113110
if (index < rare.getCount())
114111
return rare[index].first;
@@ -120,7 +117,7 @@ namespace {
120117
return NO_MORE_ERRORS;
121118
}
122119

123-
FB_BOOLEAN getStatus(CheckStatusWrapper* status, unsigned pos)
120+
void getStatus(CheckStatusWrapper* status, IStatus* to, unsigned pos)
124121
{
125122
try
126123
{
@@ -131,17 +128,18 @@ namespace {
131128
if (index < rare.getCount() && rare[index].first == pos)
132129
{
133130
if (rare[index].second)
134-
fb_utils::copyStatus(status, rare[index].second);
131+
{
132+
CheckStatusWrapper w(to);
133+
fb_utils::copyStatus(&w, rare[index].second);
134+
return;
135+
}
135136
(Arg::Gds(isc_random) << "Detailed error info is missing in batch").raise();
136137
}
137-
138-
return true;
139138
}
140139
catch (const Exception& ex)
141140
{
142141
ex.stuffException(status);
143142
}
144-
return false;
145143
}
146144

147145
void dispose()
@@ -210,7 +208,7 @@ DsqlBatch::DsqlBatch(dsql_req* req, const dsql_msg* /*message*/, IMessageMetadat
210208
case IBatch::MULTIERROR:
211209
case IBatch::RECORD_COUNTS:
212210
case IBatch::USER_BLOB_IDS:
213-
if (pb.getBoolean())
211+
if (pb.getInt())
214212
m_flags |= (1 << t);
215213
else
216214
m_flags &= ~(1 << t);
@@ -379,17 +377,14 @@ Firebird::IBatchCompletionState* DsqlBatch::execute(thread_db* tdbb)
379377
extern bool treePrt;
380378
treePrt = true;
381379

382-
fprintf(stderr, "\n\n+++ Unwind\n\n");
383-
EXE_unwind(tdbb, req);
384-
fprintf(stderr, "\n\n+++ Start\n\n");
385-
EXE_start(tdbb, req, transaction);
386380

387381
// prepare completion interface
388382
AutoPtr<BatchCompletionState, SimpleDispose<BatchCompletionState> > completionState
389383
(FB_NEW BatchCompletionState(m_flags & (1 << IBatch::RECORD_COUNTS), m_detailed));
390-
391384
AutoSetRestore<bool> batchFlag(&req->req_batch, true);
392385
const dsql_msg* message = m_request->getStatement()->getSendMsg();
386+
bool startRequest = true;
387+
393388
ULONG remains;
394389
const UCHAR* data;
395390
while ((remains = m_messages.get(&data)) > 0)
@@ -402,6 +397,15 @@ Firebird::IBatchCompletionState* DsqlBatch::execute(thread_db* tdbb)
402397

403398
while (remains >= m_messageSize)
404399
{
400+
if (startRequest)
401+
{
402+
DEB_BATCH(fprintf(stderr, "\n\n+++ Unwind\n\n"));
403+
EXE_unwind(tdbb, req);
404+
DEB_BATCH(fprintf(stderr, "\n\n+++ Start\n\n"));
405+
EXE_start(tdbb, req, transaction);
406+
startRequest = false;
407+
}
408+
405409
// todo - translate blob IDs here
406410

407411
m_request->mapInOut(tdbb, false, message, m_meta, NULL, data);
@@ -412,7 +416,7 @@ Firebird::IBatchCompletionState* DsqlBatch::execute(thread_db* tdbb)
412416
// req->req_batch = false;
413417

414418
UCHAR* msgBuffer = m_request->req_msg_buffers[message->msg_buffer_number];
415-
fprintf(stderr, "\n\n+++ Send\n\n");
419+
DEB_BATCH(fprintf(stderr, "\n\n+++ Send\n\n"));
416420
try
417421
{
418422
ULONG before = req->req_records_inserted + req->req_records_updated +
@@ -426,9 +430,16 @@ Firebird::IBatchCompletionState* DsqlBatch::execute(thread_db* tdbb)
426430
{
427431
FbLocalStatus status;
428432
ex.stuffException(&status);
433+
tdbb->tdbb_status_vector->init();
434+
429435
completionState->regError(tdbb, &status);
430436
if (!(m_flags & (1 << IBatch::MULTIERROR)))
437+
{
438+
cancel(tdbb);
439+
remains = 0;
431440
break;
441+
}
442+
startRequest = true;
432443
}
433444
}
434445
m_messages.remained(remains);
@@ -528,11 +539,12 @@ ULONG DsqlBatch::DataCache::get(const UCHAR** buffer)
528539
if (m_used > m_got)
529540
{
530541
// get data from tempspace
531-
ULONG delta = m_cache->getCapacity() - m_cache->getCount();
542+
ULONG dlen = m_cache->getCount();
543+
ULONG delta = m_cache->getCapacity() - dlen;
532544
if (delta > m_used - m_got)
533545
delta = m_used - m_got;
534-
UCHAR* buf = m_cache->getBuffer(m_cache->getCount() + delta);
535-
buf += m_cache->getCount();
546+
UCHAR* buf = m_cache->getBuffer(dlen + delta);
547+
buf += dlen;
536548
const FB_UINT64 readBytes = m_space->read(m_got, buf, delta);
537549
fb_assert(readBytes == delta);
538550
m_got += delta;
@@ -570,7 +582,7 @@ ULONG DsqlBatch::DataCache::left(ULONG size)
570582
void DsqlBatch::DataCache::clear()
571583
{
572584
m_cache->clear();
573-
if (m_space)
585+
if (m_space && m_used)
574586
m_space->releaseSpace(0, m_used);
575587
m_used = m_got = 0;
576588
}

src/dsql/DsqlBatch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "../common/classes/RefCounted.h"
2929
#include "../common/classes/vector.h"
3030

31+
#define DEB_BATCH(x)
32+
3133

3234
namespace Firebird {
3335

src/dsql/StmtNodes.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6350,14 +6350,16 @@ const StmtNode* PostEventNode::execute(thread_db* tdbb, jrd_req* request, ExeSta
63506350

63516351

63526352
static RegisterNode<ReceiveNode> regReceiveNode(blr_receive);
6353+
static RegisterNode<ReceiveNode> regReceiveNodeBatch(blr_receive_batch);
63536354

6354-
DmlNode* ReceiveNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb, const UCHAR /*blrOp*/)
6355+
DmlNode* ReceiveNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb, const UCHAR blrOp)
63556356
{
63566357
ReceiveNode* node = FB_NEW_POOL(pool) ReceiveNode(pool);
63576358

63586359
USHORT n = csb->csb_blr_reader.getByte();
63596360
node->message = csb->csb_rpt[n].csb_message;
63606361
node->statement = PAR_parse_stmt(tdbb, csb);
6362+
node->batchFlag = (blrOp == blr_receive_batch);
63616363

63626364
return node;
63636365
}
@@ -6373,6 +6375,7 @@ string ReceiveNode::internalPrint(NodePrinter& printer) const
63736375

63746376
NODE_PRINT(printer, statement);
63756377
NODE_PRINT(printer, message);
6378+
NODE_PRINT(printer, batchFlag);
63766379

63776380
return "ReceiveNode";
63786381
}
@@ -6403,7 +6406,7 @@ const StmtNode* ReceiveNode::execute(thread_db* /*tdbb*/, jrd_req* request, ExeS
64036406
switch (request->req_operation)
64046407
{
64056408
case jrd_req::req_return:
6406-
if (!request->req_batch)
6409+
if (!(request->req_batch && batchFlag))
64076410
break;
64086411
// fall into
64096412

src/dsql/StmtNodes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,8 @@ class ReceiveNode : public TypedNode<StmtNode, StmtNode::TYPE_RECEIVE>
12111211
explicit ReceiveNode(MemoryPool& pool)
12121212
: TypedNode<StmtNode, StmtNode::TYPE_RECEIVE>(pool),
12131213
statement(NULL),
1214-
message(NULL)
1214+
message(NULL),
1215+
batchFlag(false)
12151216
{
12161217
}
12171218

@@ -1228,6 +1229,7 @@ class ReceiveNode : public TypedNode<StmtNode, StmtNode::TYPE_RECEIVE>
12281229
public:
12291230
NestConst<StmtNode> statement;
12301231
NestConst<MessageNode> message;
1232+
bool batchFlag;
12311233
};
12321234

12331235

src/dsql/gen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void GEN_request(DsqlCompilerScratch* scratch, DmlNode* node)
273273
else
274274
{
275275
GEN_port(scratch, message);
276-
scratch->appendUChar(blr_receive);
276+
scratch->appendUChar(blr_receive_batch);
277277
scratch->appendUChar(message->msg_number);
278278
}
279279
message = statement->getReceiveMsg();

src/include/firebird/FirebirdInterface.idl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ interface BatchCompletionState : Disposable
485485
// Depending upon returned value (true/false) status contains
486486
// an error which took place when processing record number 'pos' (when true)
487487
// or an error that was thrown during method execution (when false).
488-
boolean getStatus(Status status, uint pos);
488+
void getStatus(Status status, Status to, uint pos);
489489
}
490490
/*
491491
interface Pipe : ReferenceCounted
@@ -1054,6 +1054,7 @@ interface XpbBuilder : Disposable
10541054
const uint SPB_ATTACH = 2;
10551055
const uint SPB_START = 3;
10561056
const uint TPB = 4;
1057+
const uint BATCH = 5;
10571058

10581059
// removing data
10591060
void clear(Status status);

src/include/firebird/IdlFbInterfaces.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ namespace Firebird
18111811
unsigned (CLOOP_CARG *getSize)(IBatchCompletionState* self, IStatus* status) throw();
18121812
int (CLOOP_CARG *getState)(IBatchCompletionState* self, IStatus* status, unsigned pos) throw();
18131813
unsigned (CLOOP_CARG *findError)(IBatchCompletionState* self, IStatus* status, unsigned pos) throw();
1814-
FB_BOOLEAN (CLOOP_CARG *getStatus)(IBatchCompletionState* self, IStatus* status, unsigned pos) throw();
1814+
void (CLOOP_CARG *getStatus)(IBatchCompletionState* self, IStatus* status, IStatus* to, unsigned pos) throw();
18151815
};
18161816

18171817
protected:
@@ -1855,12 +1855,11 @@ namespace Firebird
18551855
return ret;
18561856
}
18571857

1858-
template <typename StatusType> FB_BOOLEAN getStatus(StatusType* status, unsigned pos)
1858+
template <typename StatusType> void getStatus(StatusType* status, IStatus* to, unsigned pos)
18591859
{
18601860
StatusType::clearException(status);
1861-
FB_BOOLEAN ret = static_cast<VTable*>(this->cloopVTable)->getStatus(this, status, pos);
1861+
static_cast<VTable*>(this->cloopVTable)->getStatus(this, status, to, pos);
18621862
StatusType::checkException(status);
1863-
return ret;
18641863
}
18651864
};
18661865

@@ -4063,6 +4062,7 @@ namespace Firebird
40634062
static const unsigned SPB_ATTACH = 2;
40644063
static const unsigned SPB_START = 3;
40654064
static const unsigned TPB = 4;
4065+
static const unsigned BATCH = 5;
40664066

40674067
template <typename StatusType> void clear(StatusType* status)
40684068
{
@@ -8963,18 +8963,17 @@ namespace Firebird
89638963
}
89648964
}
89658965

8966-
static FB_BOOLEAN CLOOP_CARG cloopgetStatusDispatcher(IBatchCompletionState* self, IStatus* status, unsigned pos) throw()
8966+
static void CLOOP_CARG cloopgetStatusDispatcher(IBatchCompletionState* self, IStatus* status, IStatus* to, unsigned pos) throw()
89678967
{
89688968
StatusType status2(status);
89698969

89708970
try
89718971
{
8972-
return static_cast<Name*>(self)->Name::getStatus(&status2, pos);
8972+
static_cast<Name*>(self)->Name::getStatus(&status2, to, pos);
89738973
}
89748974
catch (...)
89758975
{
89768976
StatusType::catchException(&status2);
8977-
return static_cast<FB_BOOLEAN>(0);
89788977
}
89798978
}
89808979

@@ -9007,7 +9006,7 @@ namespace Firebird
90079006
virtual unsigned getSize(StatusType* status) = 0;
90089007
virtual int getState(StatusType* status, unsigned pos) = 0;
90099008
virtual unsigned findError(StatusType* status, unsigned pos) = 0;
9010-
virtual FB_BOOLEAN getStatus(StatusType* status, unsigned pos) = 0;
9009+
virtual void getStatus(StatusType* status, IStatus* to, unsigned pos) = 0;
90119010
};
90129011

90139012
template <typename Name, typename StatusType, typename Base>

src/jrd/blr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@
126126
#define blr_maximum (unsigned char)29
127127
#define blr_minimum (unsigned char)30
128128
#define blr_total (unsigned char)31
129+
#define blr_receive_batch (unsigned char)32
129130

130-
// unused codes: 32..33
131+
// unused code: 33
131132

132133
#define blr_add (unsigned char)34
133134
#define blr_subtract (unsigned char)35

src/jrd/exe.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,21 +1274,6 @@ const StmtNode* EXE_looper(thread_db* tdbb, jrd_req* request, const StmtNode* no
12741274

12751275
const JrdStatement* statement = request->getStatement();
12761276

1277-
class StdErrPrn : public NodePrinter
1278-
{
1279-
public:
1280-
~StdErrPrn()
1281-
{
1282-
/* if (treePrt)
1283-
{
1284-
const string& t = getText();
1285-
fwrite(t.c_str(), 1, t.length(), stderr);
1286-
fflush(stderr);
1287-
}*/
1288-
}
1289-
};
1290-
StdErrPrn prn;
1291-
12921277
while (node && !(request->req_flags & req_stall))
12931278
{
12941279
try
@@ -1305,11 +1290,6 @@ const StmtNode* EXE_looper(thread_db* tdbb, jrd_req* request, const StmtNode* no
13051290
}
13061291
}
13071292

1308-
const char* nm = node->internalPrint(prn).c_str();
1309-
if (treePrt)
1310-
{
1311-
fprintf(stderr, "%p %1d %03x %d %s\n", node, request->req_operation, request->req_flags, request->req_batch, nm);
1312-
}
13131293
node = node->execute(tdbb, request, &exeState);
13141294

13151295
if (exeState.exit)

src/yvalve/utl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,12 @@ class XpbBuilder FB_FINAL : public DisposeIface<IXpbBuilderImpl<XpbBuilder, Chec
757757
k = ClumpletReader::Tpb;
758758
tag = isc_tpb_version3;
759759
break;
760+
case BATCH:
761+
k = ClumpletReader::WideTagged;
762+
tag = IBatch::CURRENT_VERSION;
763+
break;
760764
default:
761-
fatal_exception::raiseFmt("Wrong parameters block kind %d, should be from %d to %d", kind, DPB, TPB);
765+
fatal_exception::raiseFmt("Wrong parameters block kind %d, should be from %d to %d", kind, DPB, BATCH);
762766
break;
763767
}
764768

0 commit comments

Comments
 (0)