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.
There is one synchronizer associated with each Reader and with each ReaderGroup. The synchronizer is instantiated with a segment and a revisioned stream client. The client can be numerous just like the synchronizer and the readergroups but the writes to the stream serialized and the revision is checked before the updates are made. The stream is internal and starts with a prefix that denotes it is part of the scope of streams for internal use and includes the name of the source stream for which the reader and the readerGroup were created.
Each Reader created by the application references a set of internal readers called waterMarkReaders which are capable of reading the revisions to each stream. There is a map of one such internal reader to a stream and keyed by stream name that is maintained in each reader from the application. Before each read event, the reader forwards the positions of these internal readers to the latest revision.
The synchronizer maintains revisions so it does not need to synchronize on the client. But the revisions should be handled consistently otherwise the reader created on one thread will not generate a revision for a readergroup created on another thread. Usually the reader group and readers are created in the same thread and the notifier is always created after both the reader and the readerGroup have been created.
No comments:
Post a Comment