Skip to content

Commit d80ee5c

Browse files
author
Petr Matousek
committed
align with python
1 parent ce7f96a commit d80ee5c

File tree

4 files changed

+60
-38
lines changed

4 files changed

+60
-38
lines changed

src/api/qpid-proton/reactor/TxReceivingClient.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ int TxReceivingClient::run(int argc, char **argv) const
393393
handler.setSelector(selector);
394394
}
395395

396+
// TODO python defaults to 10
397+
// int tx_size = 10;
396398
int tx_size = 0;
397399
if (options.is_set("tx-size")) {
398400
tx_size = static_cast<int> (options.get("tx-size"));

src/api/qpid-proton/reactor/handler/TxReceiverHandler.cpp

+57-36
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ TxReceiverHandler::TxReceiverHandler(
110110
recv_listen_port,
111111
recv_credit_window,
112112
recv_drain_after_credit_window
113-
),
113+
),
114114
tx_action(tx_action),
115115
tx_endloop_action(tx_endloop_action)
116116
{
@@ -149,33 +149,39 @@ void TxReceiverHandler::on_transaction_commit_failed(transaction t) {
149149
}
150150

151151
void TxReceiverHandler::on_transaction_declared(transaction t) {
152+
// TODO python some weird magic around count 0, doesn't make much sense to me yet
153+
// when fixes take care about all count checks ofr zero
154+
if (count != 0 && processed + batch_size > count) {
155+
batch_size = count % batch_size;
156+
} else if (count != 0) {
157+
batch_size = count;
158+
}
152159
logger(trace) << "[on_transaction_declared] txn called " << (&t);
153160
logger(debug) << "[on_transaction_declared] txn is_empty " << (t.is_empty());
154161
tx = t;
155162
}
156163

157164
void TxReceiverHandler::on_transaction_aborted(transaction t) {
158-
confirmed += current_batch;
159-
logger(debug) << "[on_transaction_aborted] messages aborted, confirmed: " << confirmed;
160-
if(confirmed == count) {
161-
logger(info) << "[on_transaction_committed] All messages proccessed";
162-
t.connection().close();
163-
}
164-
else {
165+
processed += current_batch;
166+
current_batch = 0;
167+
logger(debug) << "[on_transaction_aborted] messages aborted, processed: " << processed;
168+
if (count == 0 || processed < count) {
165169
sess.declare_transaction(*this);
170+
} else {
171+
logger(info) << "[on_transaction_committed] All messages processed";
172+
t.connection().close();
166173
}
167174
}
168175

169176
void TxReceiverHandler::on_transaction_committed(transaction t) {
170-
confirmed += current_batch;
177+
processed += current_batch;
171178
current_batch = 0;
172-
logger(debug) << "[on_transaction_aborted] messages committed, confirmed: " << confirmed;
173-
if(confirmed == count) {
174-
logger(info) << "[on_transaction_committed] All messages proccessed";
175-
t.connection().close();
176-
}
177-
else {
179+
logger(debug) << "[on_transaction_aborted] messages committed, processed: " << processed;
180+
if (count == 0 || processed < count) {
178181
sess.declare_transaction(*this);
182+
} else {
183+
logger(info) << "[on_transaction_committed] All messages processed";
184+
t.connection().close();
179185
}
180186
}
181187

@@ -192,7 +198,7 @@ void TxReceiverHandler::on_container_start(container &c)
192198
logger(debug) << "[on_container_start] Transaction action: " << tx_action;
193199
logger(debug) << "[on_container_start] Transaction endloop action: " << tx_endloop_action;
194200
logger(trace) << "[on_container_start] Messages count: " << count;
195-
logger(debug) << "[on_container_start] Messages confirmed: " << confirmed;
201+
logger(debug) << "[on_container_start] Messages processed: " << processed;
196202
logger(debug) << "[on_container_start] Peer to Peer: " << recv_listen;
197203

198204
if (recv_listen == "true") {
@@ -364,6 +370,11 @@ void TxReceiverHandler::on_message(delivery &d, message &m)
364370
{
365371
logger(debug) << "[on_message] Processing received message";
366372

373+
tx.accept(d);
374+
current_batch += 1;
375+
376+
logger(debug) << "[on_message] current batch: " << current_batch;
377+
367378
if (log_msgs == "dict") {
368379
logger(trace) << "[on_message] Decoding message";
369380
ReactorDecoder decoder = ReactorDecoder(m);
@@ -384,19 +395,15 @@ void TxReceiverHandler::on_message(delivery &d, message &m)
384395

385396
if (duration_time > 0 && duration_mode == "after-receive") {
386397
logger(debug) << "[on_message] Waiting...";
387-
sleep4next(ts, count, duration_time, confirmed);
398+
sleep4next(ts, count, duration_time, processed + current_batch);
388399
}
389400

390-
if((confirmed % msg_action_size) == 0) {
401+
if(((processed + current_batch) % msg_action_size) == 0) {
391402
do_message_action(d);
392403
}
393404

394405
if (duration_time > 0 && duration_mode == "after-receive-action") {
395-
sleep4next(ts, count, duration_time, confirmed);
396-
}
397-
398-
if (duration_time > 0 && duration_mode == "after-receive-action-tx-action") {
399-
// TODO: not implemented yet
406+
sleep4next(ts, count, duration_time, processed + current_batch);
400407
}
401408

402409
logger(debug) << "[on_message] Process-reply-to: " << process_reply_to;
@@ -411,12 +418,12 @@ void TxReceiverHandler::on_message(delivery &d, message &m)
411418
}
412419
}
413420

414-
if (recv_drain_after_credit_window && confirmed== recv_credit_window) {
421+
if (recv_drain_after_credit_window && processed + current_batch == recv_credit_window) {
415422
logger(debug) << "[on_message] Scheduling drain";
416423
d.receiver().work_queue().add(make_work(&TxReceiverHandler::drain, this));
417424
}
418425

419-
if (!process_reply_to && confirmed == count) {
426+
if (!process_reply_to && processed + current_batch == count) {
420427
if (durable_subscriber) {
421428
d.receiver().detach();
422429
} else {
@@ -429,32 +436,46 @@ void TxReceiverHandler::on_message(delivery &d, message &m)
429436
#endif
430437
}
431438

432-
tx.accept(d);
433-
current_batch += 1;
434-
logger(debug) << "[on_message] current batch: " << current_batch;
435-
if (confirmed + current_batch == count) {
436-
logger(debug) << "[on_message] Transaction attempt (endloop): " << tx_endloop_action;
437-
if (tx_endloop_action == "commit") {
439+
if(current_batch == batch_size) {
440+
logger(debug) << "[send] Transaction attempt: " << tx_action;
441+
if (tx_action == "commit") {
438442
tx.commit();
439-
} else if (tx_endloop_action == "rollback") {
443+
} else if (tx_action == "rollback") {
440444
tx.abort();
441445
}
442-
} else if(current_batch == batch_size) {
443-
logger(debug) << "[on_message] messages commited: " << current_batch;
446+
447+
if (tx_action == "none") {
448+
if (processed + current_batch == count) {
449+
recv.connection().close();
450+
} else {
451+
processed += current_batch;
452+
current_batch = 0;
453+
sess.declare_transaction(*this);
454+
}
455+
}
456+
457+
if (duration_time > 0 && duration_mode == "after-receive-action-tx-action") {
458+
// TODO: not implemented yet
459+
}
460+
461+
} else if (count != 0 && processed + current_batch == count) {
462+
logger(debug) << "[send] Transaction attempt (endloop): " << tx_endloop_action;
444463
if (tx_endloop_action == "commit") {
445464
tx.commit();
446465
} else if (tx_endloop_action == "rollback") {
447466
tx.abort();
467+
} else {
468+
recv.connection().close();
448469
}
449470
}
450471
}
451472

452473
void TxReceiverHandler::on_transport_close(transport &t) {
453474
logger(debug) << "[on_transport_close] Closing the transport";
454-
475+
current_batch = 0;
455476
if (conn_reconnect == "false") {
456477
exit(1);
457-
} else if (confirmed == count) {
478+
} else if (processed == count) {
458479
exit(0);
459480
}
460481
}

src/api/qpid-proton/reactor/handler/TxReceiverHandler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class TxReceiverHandler : public ReceiverHandler, transaction_handler {
161161

162162
int batch_size = 0;
163163
int current_batch = 0;
164-
int confirmed = 0;
164+
int processed = 0;
165165
string tx_action = "commit";
166166
string tx_endloop_action = "commit";
167167
transaction tx;

src/api/qpid-proton/reactor/handler/TxSenderHandler.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ void TxSenderHandler::send()
151151

152152

153153
logger(trace) << "[send] Transaction is empty: " << tx.is_empty();
154-
logger(trace) << "[send] Current_batch: " << sndr.credit();
155154
logger(debug) << "[send] Messages processed: " << processed;
156155
logger(trace) << "[send] Current batch: " << current_batch;
157156
while (!tx.is_empty() && sndr.credit() && (processed + current_batch) < count)

0 commit comments

Comments
 (0)