feat: add getMaxMessageId() and getAllMessageIdsWithSizes() to spoole… - #45
feat: add getMaxMessageId() and getAllMessageIdsWithSizes() to spoole…#45saranyailla wants to merge 2 commits into
Conversation
…r startup optimization
|
|
||
| @Override | ||
| protected PreparedStatement createStatement(Connection connection) throws SQLException { | ||
| return connection.prepareStatement(QUERY); |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
The code is not properly closing resources, which can lead to resource leaks. Unclosed resources may cause memory leaks or other system resource issues, potentially degrading application performance over time. If an exception occurs before the explicit close() call, the resource will not be closed, increasing the risk of leaks. To remediate this, use the try-with-resources statement to automatically close AutoCloseable resources.Alternatively, if try-with-resources cannot be used, ensure that close() is called in a finally block to guarantee proper resource cleanup even when exceptions occur.
|
|
||
| @Override | ||
| protected ResultSet doExecute(PreparedStatement statement) throws SQLException { | ||
| return statement.executeQuery(); |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
The code is not properly closing resources, which can lead to resource leaks. Unclosed resources may cause memory leaks or other system resource issues, potentially degrading application performance over time. If an exception occurs before the explicit close() call, the resource will not be closed, increasing the risk of leaks. To remediate this, use the try-with-resources statement to automatically close AutoCloseable resources.Alternatively, if try-with-resources cannot be used, ensure that close() is called in a finally block to guarantee proper resource cleanup even when exceptions occur.
|
|
||
| @Override | ||
| protected ResultSet doExecute(PreparedStatement statement) throws SQLException { | ||
| return statement.executeQuery(); |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
The code is not properly closing resources, which can lead to resource leaks. Unclosed resources may cause memory leaks or other system resource issues, potentially degrading application performance over time. If an exception occurs before the explicit close() call, the resource will not be closed, increasing the risk of leaks. To remediate this, use the try-with-resources statement to automatically close AutoCloseable resources.Alternatively, if try-with-resources cannot be used, ensure that close() is called in a finally block to guarantee proper resource cleanup even when exceptions occur.
|
|
||
| @Override | ||
| protected PreparedStatement createStatement(Connection connection) throws SQLException { | ||
| return connection.prepareStatement(QUERY); |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
The code is not properly closing resources, which can lead to resource leaks. Unclosed resources may cause memory leaks or other system resource issues, potentially degrading application performance over time. If an exception occurs before the explicit close() call, the resource will not be closed, increasing the risk of leaks. To remediate this, use the try-with-resources statement to automatically close AutoCloseable resources.Alternatively, if try-with-resources cannot be used, ensure that close() is called in a finally block to guarantee proper resource cleanup even when exceptions occur.
…r startup optimization
Implements
getMaxMessageId()andgetAllMessageIdsWithSizes()— default methods added to theCloudMessageSpoolinterface in Nucleus 2.18.3+ (aws-greengrass-nucleus#1834).Context
At boot, the Nucleus reloads persisted message IDs into its in-memory dispatch queue. Today this calls
getMessageById()per message — reading the full payload from SQLite — only to getpayload.lengthfor capacity tracking. On constrained hardware with ~26,500 queued messages, this blocks all component startup for ~5 minutes (nucleus #1832).These two queries eliminate the per-message payload reads entirely.
Queries
getMaxMessageId()O(1) —
message_idisINTEGER PRIMARY KEY, so SQLite resolvesMAX()directly from the B-tree index. Returns -1 when the table is empty. Lets the Nucleus set its next-ID counter instantly without iterating all rows.getAllMessageIdsWithPayloadSize()Single table scan.
LENGTH()on a BLOB reads the size from the SQLite row header — no payload bytes are loaded into memory.ORDER BY message_id ASCis free since the primary key is already ordered in the B-tree. Lets the Nucleus populate its dispatch queue and enforce capacity in milliseconds regardless of queue depth.Testing
Added 7 unit tests covering:
Compatibility
These methods are additive. On Nucleus versions older than 2.18.3 that don't call them, they exist on the class but are never invoked — no minimum Nucleus version required.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.