Fix Stale Reads on MySQL in Event Notifications DAO - #142
Open
ThiwankaChanditha wants to merge 2 commits into
Open
Fix Stale Reads on MySQL in Event Notifications DAO#142ThiwankaChanditha wants to merge 2 commits into
ThiwankaChanditha wants to merge 2 commits into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: Comment |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In MySQL InnoDB (default
REPEATABLE READisolation level), read queries executed withautoCommit = falseestablish an MVCC transaction snapshot. Because read operations inevent.notifications.daodid not callcommitTransactionbefore returning connections to the Tomcat JDBC pool, connections remained active with uncommitted, frozen snapshots. When requests reused those connections after writes, newly committed records were invisible, causing{"items":[],"total":0}list responses andEN-4040: No subscription existserrors. Reference #107Scope of Changes
Per ownership boundaries, changes are strictly isolated to
org.wso2.dpdp.accelerator.event.notifications.dao:SubscriptionDAOImpl.java:
DatabaseUtils.commitTransaction(conn)on success andDatabaseUtils.rollbackTransaction(conn)on catch across:getSubscriptionById(String, String)listSubscriptions(...)getPurposesBySubscriptionId(String, String)countActiveSubscriptionsForTopic(String, String)getPurposesBySubscriptionIds(List<String>)hasPendingOrInFlightDeliveries(String, String)getPendingSubscriptionsForRecovery(Timestamp, int)Connection connremain untouched.TopicDAOImpl.java:
commitTransaction(conn)on success androllbackTransaction(conn)on catch across:getTopicById(String, String)getTopicByOrgAndName(String, String)listTopics(...)EventDAOImpl.java:
commitTransaction(conn)on success androllbackTransaction(conn)on catch across:getEventById(String, String)getEventPurposes(String)hasActiveEventsForTopic(String)searchEvents(...)DeliveryDAOImpl.java:
commitTransaction(conn)on success androllbackTransaction(conn)on catch across:getWebhookDeliveryById(String, String)loadDispatchContexts(String, int)loadDispatchContextsWithCutoff(String, int, Timestamp)getWebhookDeliveryAudits(String, String)getPollDeliveryById(String, String)getPendingPollDeliveries(...)listSubscriptionDeliveries(...)getSubscriptionDeliveryById(...)listOrgDeliveries(...)getOrgDeliveryById(...)listEventDeliveries(...)DeliveryAckDAOImpl.java:
commitTransaction(conn)on success androllbackTransaction(conn)on catch ingetDeliveryAckByDeliveryId(String).Verification & Testing
1. Automated Unit Tests
mvn test -pl dpdp-accelerator/components/org.wso2.dpdp.accelerator.event.notifications.daoTests run: 62, Failures: 0, Errors: 0, Skipped: 2BUILD SUCCESS2. Manual Testing & Verification
Manual end-to-end tests were performed against a live WSO2 IS instance with MySQL Community Server 8.0:
Pre-fix Reproduction Test:
GET /subscriptionsrequests.POST /subscriptions(15cb9fa6-8a98-4960-89b3-9d0e1bab554a).GET /subscriptionsrequests.total: 10) while only 2 returned the fresh count (total: 11), confirming that uncommitted pooled connections were serving frozen snapshots and omitting newly created records. Direct fetch on stale connections yieldedEN-4040: No subscription exists with the specified ID for this organization.(404 Not Found).Post-fix Verification Test:
GETrequests consistently returned the updated total count with 100% consistency, and individualGET /subscriptions/{id}calls consistently returned200 OKwith the active subscription details.