Thursday, July 9, 2020

Reader Group Notification explained

All notifications are based on a record that is called the ReaderGroupState. It contains useful information pertaining to segments and positions but the primary thing to note is that it uses a stream for its persistence and versions the changes. This in itself provides much of the desired serialization of the changes to the states and allows the manager to optimize updates if the revision is not exceeded.
The ReaderGroupStateManager is the one that handles the state update on every reader coming online or going offline. It does this with the help of StateSynchronizer for ReaderGroupState. Additionally, this manager knows how to handle a segment being completed or to release a segment on redistribution of segments to readers or to determine if a reader owns multiple segments. It fetches and applies updates as necessary and maintains timers to calculate most of the information associated with a ReaderGroupState.
The StateSynchronizer handles all the low-level operations associated with the state such as creating a new update, persisting and retrieving it.  The primary purpose of this synchronizer is to handle state updates across multiple processes. It needs to keep track of only the current state as opposed to others that may compare versions of the state. It knows the segment to be associate with that state. As usual, each segment points to a scoped stream that is unique by the scope-stream combination along with full qualification.
The ClientFactory that creates readers in the reader group creates both the reader group state manager and a state synchronizer. Additionally, it creates a revisioned stream client for watermarks. This is the main interface for all applications that want to create readers and writers. At the point of admission for a reader, all the associated data structures are initialized that enable the ReaderGroupState to be created and updated. The ReaderGroup data structure provides a notifier to the application.
The notifications are raised by the notifier such as the SegmentNotifier which polls and retrieves the state from the synchronizer. Only if the data has changed does the SegmentNotifier raise a notification to the listener registered with it by the application. The publishing of the notification is done with the help of a notification system.
The NotificationSystem has a notify method that invokes the listener with the corresponding notification. The application can then use the details in the notification with custom logic to scale readers up or down.  

No comments:

Post a Comment