Repository navigation
Keep unsent messages when the session is reset by its schedule - #1345
aymenjamaaoui wants to merge 6 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1345 +/- ##
============================================
+ Coverage 71.73% 72.08% +0.35%
- Complexity 2306 2359 +53
============================================
Files 162 163 +1
Lines 9106 9264 +158
Branches 1193 1215 +22
============================================
+ Hits 6532 6678 +146
- Misses 2120 2127 +7
- Partials 454 459 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
aa3486c to
d41b8ac
Compare
|
I rebased the branch on the latest #1346 (fix for #327) is now in With I added a commit to fix it: the callback is now also called in this case, before the message store is reset. I also added a test for it. |
|
Sorry, am a little busy at the moment, but will review files one by one... thanks for your patience... |
| if (keepUnsentMessagesOnReset && num == 0 && !isLoggedOn()) { | ||
| markFirstUnsentMessage(header.getInt(MsgSeqNum.FIELD)); | ||
| } | ||
| messageString = message.toString(); | ||
| persist(message.getHeader(), messageString, num); | ||
| if (isLoggedOn()) { | ||
| result = send(messageString); | ||
| } |
There was a problem hiding this comment.
I think the result of send() should also be taken into account. If it returns false, the message was also not sent and should go through markFirstUnsentMessage()
There was a problem hiding this comment.
Good point, thanks. If send() returns false, the message is in the store but was not sent. I changed the code: the message is now marked as unsent in this case too, and I added a test (b34a856).
One limit: we only keep the first unsent sequence number. With SynchronousWrites=Y, send() can return false after a timeout while the session stays logged on. If later messages are sent and then the session is reset by its schedule, these later messages are kept too, so they can be sent two times. Also, with async writes (the default), send() returns true even if the write fails later. Is this OK for you?
| @@ -2731,8 +2752,11 @@ | |||
| } catch (final Throwable t) { | |||
There was a problem hiding this comment.
Throwing DoNotSend also means a message was not sent. See other comment below.
There was a problem hiding this comment.
When toApp() throws DoNotSend, sendRaw() returns before persist(). So the message is not in the store and the sequence number is not used. I think there is nothing to keep here, because the application decided not to send it. Or do you mean another case?
Before this change, some messages were lost. This happened when the app sent a message while the session was not logged on, for example outside the session time. The message was saved in the store, and then the scheduled reset deleted it. With KeepUnsentMessagesOnReset=Y, the message store keeps the sequence number of the first message that was not sent. When the session is reset by its schedule, the unsent application messages are copied to the new store with new sequence numbers. After the next logon, they are sent again when the counterparty asks for them. The value is saved in the store, so it works after a restart. It is supported by MemoryStore, FileStore and CachedFileStore. The default is N. So the reset works the same as before. Refs quickfix-j#463, quickfix-j#986
JdbcStore can now keep the first unsent sequence number. The value is saved in a new table, "unsent_seqnums". The name can be changed with JdbcStoreUnsentSeqNumsTableName. The table is optional. Without it, JdbcStore works as before and KeepUnsentMessagesOnReset has no effect. The SQL scripts for HSQLDB, MySQL, MSSQL, Oracle and PostgreSQL create the new table. Refs quickfix-j#463, quickfix-j#986
Add tests for several unsent messages, a scheduled reset without unsent messages, the warnings when the setting has no effect, and the update and custom table name in JdbcStore.
d41b8ac to
b34a856
Compare
Problem
When the app sends a message while the session is not logged on (for example outside the session time), the message is saved in the message store. Then the session is reset by its schedule, and the reset deletes the store. So the message is never sent.
This does not match the Javadoc of
Application.onCreate(): "If no one is logged on, the messages will be sent at the time a connection is established with the counterparty."Closes #986
Refs #463
Solution
This PR adds a new session setting:
KeepUnsentMessagesOnReset(defaultN).With
KeepUnsentMessagesOnReset=Y:PossDupFlag=Ywhen the counterparty asks for them (ResendRequest).The value is saved in the store, so it works after a restart.
As discussed in #986:
MessageStorehas two newdefaultmethods:getFirstUnsentSenderMsgSeqNum()andsetFirstUnsentSenderMsgSeqNum(int). By default they do nothing (get returns-1), so custom stores still compile and work as before.MemoryStore: in memory.FileStoreandCachedFileStore: new file<session>.firstunsentseqnum.JdbcStore: new tableunsent_seqnums. The name can be changed withJdbcStoreUnsentSeqNumsTableName. The table is optional. Without it,JdbcStoreworks as before.If the store does not support it, or if
PersistMessages=N, the session logs a warning and works as before.Messages are still lost with
ResetOnLogon,ResetOnLogout,ResetOnDisconnect, a Logon withResetSeqNumFlag=Y, or a call toSession.reset(). These resets are asked by the user or by the counterparty, so this PR does not change them.Open question
The default is
N, so nothing changes for current users. In #986 we did not decide if it should beYby default. I am happy to change it.Tests
SessionTest: unsent messages are kept after a scheduled reset, resent after logon, and kept after a restart; messages that were already sent are not kept; no change when the setting is off.DefaultSessionFactoryTest: the new setting is read.AbstractMessageStoreTest: get, set, refresh and reset of the new value. It runs forMemoryStore,FileStore,CachedFileStoreandJdbcStore(also the legacy table layout).JdbcStoreTest:JdbcStoreworks without the new table.