Fix KV Stores for same message in multiple groups (#8737)

* Fix KV Stores for same message in multiple groups

If same message is stored into different groups with the same KV store,
the removal of one group would lead to removal the message for the other one.

* Improve KV Store to save message with the key including a group id
* Respectively, refine the removal API to include group id into keys
* Also change the `MESSAGE_GROUP_KEY_PREFIX` for group records to `GROUP_OF_MESSAGES_`
since the `MESSAGE_` prefix includes group records as well for various operations
based on key pattern

* * Use `[^GROUP_]` in the pattern for messages count

**Cherry-pick to `6.1.x`**

* * Fix MongoDB MS for message removal logic

* * Bring back `GROUP_OF_MESSAGES_` prefix
to avoid complex regexp and don't bother for edge cases,
where even that regexp may fail
This commit is contained in:
Artem Bilan
2023-09-19 14:13:05 -04:00
committed by GitHub
parent 9ad2b8a8e2
commit 64f8ed5bab
7 changed files with 165 additions and 75 deletions

View File

@@ -536,6 +536,28 @@ public abstract class AbstractMongoDbMessageGroupStoreTests implements MongoDbCo
.containsEntry("type", "channel");
}
@Test
public void removeMessageDoesntRemoveSameMessageInTheGroup() {
GenericMessage<String> testMessage = new GenericMessage<>("test data");
MessageGroupStore store = getMessageGroupStore();
store.addMessageToGroup("1", testMessage);
MessageStore messageStore = (MessageStore) store;
messageStore.removeMessage(testMessage.getHeaders().getId());
assertThat(messageStore.getMessageCount()).isEqualTo(0);
assertThat(store.getMessageCountForAllMessageGroups()).isEqualTo(1);
assertThat(store.messageGroupSize("1")).isEqualTo(1);
store.removeMessageGroup("1");
assertThat(store.getMessageCountForAllMessageGroups()).isEqualTo(0);
assertThat(store.messageGroupSize("1")).isEqualTo(0);
}
protected abstract MessageGroupStore getMessageGroupStore();
protected abstract MessageStore getMessageStore();