Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(mq) Add relation tracking between MQ messages for easier tracking an…
…d debugging. The change adds a new column to the MESSAGE_QUEUE table called AUDIT_RELATED_ID. This field is populated transparently, using a dictionary mapping Thread IDs to Message IDs, populated by the inbox handlers. The existing RELATED_ID field has too many semantics associated with them, among other things the FSM code uses them this field in tracking state changes. The change set also improves the consistency of inbox names. The IndexClient was buggy and populated its outbox with a UUID. This is fixed. All Service2Service outboxes are now prefixed with 'pp:' to make them even easier to differentiate.
- Loading branch information
Showing
14 changed files
with
105 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
code/common/db/src/main/resources/db/migration/V24_01_0_003__mqaudit.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE MESSAGE_QUEUE ADD COLUMN AUDIT_RELATED_ID LONG NOT NULL DEFAULT -1 COMMENT 'To be applied to any new messages created while handling a message'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...es/message-queue/src/main/java/nu/marginalia/mq/persistence/MqMessageHandlerRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package nu.marginalia.mq.persistence; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** Keeps track of which thread is handling a message, to be able to | ||
* paint outgoing messages with a AUDIT_RELATED_ID to relate the | ||
* outgoing message to the incoming message that triggered it. | ||
* <p></p> | ||
* This is a pure audit field, a weaker version of the RELATED_ID, | ||
* which is used by e.g. state machines to relate a series of messages to each other. | ||
* <p></p> | ||
* The class is thread-safe, and tracks the thread ID of the thread that | ||
* is currently handling a message. It can be cleaned up by calling | ||
* deregister() when the message has been handled. | ||
*/ | ||
public class MqMessageHandlerRegistry { | ||
// There is some small risk of a memory leak here, if the registry entries aren't cleaned up properly, | ||
// but due to the low volume of messages being sent, this is not a big concern. Since the average | ||
// message rate is less than 1 per second, even if the process ran for 60 years, and we leaked every ID | ||
// put in, the total amount of memory leaked would only be about of order 2 MB. | ||
|
||
private static final ConcurrentHashMap<Long, Long> handlerRegistry = new ConcurrentHashMap<>(); | ||
|
||
public static void register(long msgId) { | ||
handlerRegistry.put(Thread.currentThread().threadId(), msgId); | ||
} | ||
|
||
public static long getOriginMessage() { | ||
return handlerRegistry.getOrDefault(Thread.currentThread().threadId(), -1L); | ||
} | ||
|
||
public static void deregister() { | ||
handlerRegistry.remove(Thread.currentThread().threadId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters