@@ -133,51 +133,47 @@ int TxReceiverHandler::getBatchSize() const
133133// reactor methods
134134
135135void TxReceiverHandler::on_session_open (session &s) {
136- logger (trace) << " [on_session_open] declare_txn started..." ;
137- s.transaction_declare (*this );
138- logger (trace) << " [on_session_open] declare_txn ended..." ;
139- logger (debug) << " [on_session_open] transaction batch size: " << batch_size;
136+ if (!s.transaction_is_declared ()) {
137+ logger (trace) << " [on_session_open] New session is open" ;
138+ s.transaction_declare (*this );
139+ } else {
140+ logger (trace) << " [on_session_open] Transaction is declared: " << s.transaction_id ();
141+ recv.add_credit (batch_size);
142+ logger (debug) << " [on_session_open] Receiver credit: " << recv.credit ();
143+ if (count != 0 && processed + batch_size > count) {
144+ batch_size = count % batch_size;
145+ }
146+ }
140147}
141148
142- void TxReceiverHandler::on_transaction_declare_failed (session) {}
143-
144- void TxReceiverHandler::on_transaction_commit_failed (session s) {
145- logger (debug) << " [on_transaction_commit_failed] Transaction Commit Failed" ;
149+ void TxReceiverHandler::on_session_transaction_commit_failed (session &s) {
150+ logger (debug) << " [on_session_transaction_commit_failed] Transaction Commit Failed" ;
146151 s.connection ().close ();
147152 exit (-1 );
148153}
149154
150- void TxReceiverHandler::on_transaction_declared (session s) {
151- // TODO python some weird magic around count 0, doesn't make much sense to me yet
152- // when fixes take care about all count checks ofr zero
153- if (count != 0 && processed + batch_size > count) {
154- batch_size = count % batch_size;
155- } else if (count != 0 ) {
156- batch_size = count;
157- }
158- logger (trace) << " [on_transaction_declared] txn called " << s.transaction_id ();
159- }
160-
161- void TxReceiverHandler::on_transaction_aborted (session s) {
155+ void TxReceiverHandler::on_session_transaction_aborted (session &s) {
162156 processed += current_batch;
163157 current_batch = 0 ;
164- logger (debug) << " [on_transaction_aborted ] messages aborted, processed: " << processed;
158+ logger (debug) << " [on_session_transaction_aborted ] messages aborted, processed: " << processed;
165159 if (count == 0 || processed < count) {
160+ logger (info) << " [on_session_transaction_aborted] re-declaring transaction" ;
166161 s.transaction_declare (*this );
167162 } else {
168- logger (info) << " [on_transaction_aborted ] All messages processed" ;
163+ logger (info) << " [on_session_transaction_aborted ] All messages processed" ;
169164 s.connection ().close ();
170165 }
171166}
172167
173- void TxReceiverHandler::on_transaction_committed (session s) {
168+ void TxReceiverHandler::on_session_transaction_committed (session & s) {
174169 processed += current_batch;
175170 current_batch = 0 ;
176- logger (debug) << " [on_transaction_committed ] messages committed, processed: " << processed;
171+ logger (debug) << " [on_session_transaction_committed ] messages committed, processed: " << processed;
177172 if (count == 0 || processed < count) {
173+ logger (info) << " [on_session_transaction_committed] re-declaring transaction" ;
178174 s.transaction_declare (*this );
179175 } else {
180- logger (info) << " [on_transaction_committed ] All messages processed" ;
176+ logger (info) << " [on_session_transaction_committed ] All messages processed" ;
181177 s.connection ().close ();
182178 }
183179}
@@ -367,14 +363,10 @@ void TxReceiverHandler::on_message(delivery &d, message &m)
367363{
368364 logger (debug) << " [on_message] Processing received message" ;
369365
370- // TODO legit?
371366 session s = d.session ();
372-
373367 d.accept ();
374368 current_batch += 1 ;
375369
376- logger (debug) << " [on_message] current batch: " << current_batch;
377-
378370 if (log_msgs == " dict" ) {
379371 logger (trace) << " [on_message] Decoding message" ;
380372 ReactorDecoder decoder = ReactorDecoder (m);
@@ -436,8 +428,10 @@ void TxReceiverHandler::on_message(delivery &d, message &m)
436428#endif
437429 }
438430
431+ logger (debug) << " [on_message] Receiver credit: " << recv.credit ();
432+ logger (debug) << " [on_message] Current batch: " << current_batch;
439433 if (current_batch == batch_size) {
440- logger (debug) << " [send ] Transaction attempt: " << tx_action;
434+ logger (debug) << " [on_message ] Transaction attempt: " << tx_action;
441435 if (tx_action == " commit" ) {
442436 s.transaction_commit ();
443437 } else if (tx_action == " rollback" ) {
@@ -459,7 +453,7 @@ void TxReceiverHandler::on_message(delivery &d, message &m)
459453 }
460454
461455 } else if (count != 0 && processed + current_batch == count) {
462- logger (debug) << " [send ] Transaction attempt (endloop): " << tx_endloop_action;
456+ logger (debug) << " [on_message ] Transaction attempt (endloop): " << tx_endloop_action;
463457 if (tx_endloop_action == " commit" ) {
464458 s.transaction_commit ();
465459 } else if (tx_endloop_action == " rollback" ) {
0 commit comments