-
Notifications
You must be signed in to change notification settings - Fork 1
Cursor catchup mechanism #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
999a7c1
Update README
p14n 31f875a
Update README
p14n 274573c
[cursor] Move messages table setup
p14n dd8339f
[cursor] create cathup server and test
p14n 52a5188
[cursor] correcting compile errors
p14n 68ea5df
[cursor] Catchup server tests pass
p14n 4878301
Merge branch 'main' of github.com:p14n/postevent into catchup-mechanism
p14n aee2c59
[cursor] Catchup service created
p14n 7219a13
[cursor] Compile errors fixed with 'quick fix'
p14n 203b7df
[cursor] Test added for catchup service, but it's testing the wrong t…
p14n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package com.p14n.postevent; | ||
|
|
||
| import javax.sql.DataSource; | ||
| import java.sql.Connection; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| public class CatchupServer { | ||
| private static final Logger LOGGER = Logger.getLogger(CatchupServer.class.getName()); | ||
| private final String topic; | ||
| private final DataSource dataSource; | ||
|
|
||
| public CatchupServer(String topic, DataSource dataSource) { | ||
| if (topic == null || topic.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("Topic name cannot be null or empty"); | ||
| } | ||
| this.topic = topic; | ||
| this.dataSource = dataSource; | ||
| } | ||
|
|
||
| public List<Event> fetchEvents(long start, long end, int maxResults) { | ||
| if (start > end) { | ||
| throw new IllegalArgumentException("Start value must be less than or equal to end value"); | ||
| } | ||
| if (maxResults <= 0) { | ||
| throw new IllegalArgumentException("Max results must be greater than zero"); | ||
| } | ||
|
|
||
| List<Event> events = new ArrayList<>(); | ||
| String sql = String.format( | ||
| "SELECT * FROM postevent.%s WHERE idn BETWEEN ? AND ? ORDER BY idn LIMIT ?", | ||
| topic); | ||
|
|
||
| try (Connection conn = dataSource.getConnection(); | ||
| PreparedStatement stmt = conn.prepareStatement(sql)) { | ||
|
|
||
| stmt.setLong(1, start); | ||
| stmt.setLong(2, end); | ||
| stmt.setInt(3, maxResults); | ||
|
|
||
| try (ResultSet rs = stmt.executeQuery()) { | ||
| while (rs.next()) { | ||
| Event event = new Event( | ||
| rs.getString("id"), | ||
| rs.getString("source"), | ||
| rs.getString("type"), | ||
| rs.getString("datacontenttype"), | ||
| rs.getString("dataschema"), | ||
| rs.getString("subject"), | ||
| rs.getBytes("data")); | ||
| events.add(event); | ||
| } | ||
| } | ||
|
|
||
| LOGGER.info(String.format("Fetched %d events from topic %s between %d and %d", | ||
| events.size(), topic, start, end)); | ||
|
|
||
| return events; | ||
|
|
||
| } catch (SQLException e) { | ||
| LOGGER.log(Level.SEVERE, "Error fetching events from database", e); | ||
| throw new RuntimeException("Failed to fetch events", e); | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Inaccurate description of catchup mechanism
The catchup mechanism writes messages to the database, not directly to the consumer. The consumer then reads from the database.