-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from zendesk/ben/store_position_in_database
Store binlog position in database
- Loading branch information
Showing
8 changed files
with
104 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/zendesk/maxwell/schema/SchemaPosition.java
This file contains 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,39 @@ | ||
package com.zendesk.maxwell.schema; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import com.zendesk.maxwell.BinlogPosition; | ||
|
||
public class SchemaPosition { | ||
public static BinlogPosition get(Connection c, Long serverID) throws SQLException { | ||
PreparedStatement s = c.prepareStatement("SELECT * from `maxwell`.`positions` where server_id = ?"); | ||
s.setLong(1, serverID); | ||
|
||
ResultSet rs = s.executeQuery(); | ||
if ( !rs.next() ) | ||
return null; | ||
|
||
return new BinlogPosition(rs.getLong("binlog_position"), rs.getString("binlog_file")); | ||
} | ||
|
||
public static void set(Connection c, Long serverID, BinlogPosition p) throws SQLException { | ||
String sql = "INSERT INTO `maxwell`.`positions` set " | ||
+ "server_id = ?, " | ||
+ "binlog_file = ?, " | ||
+ "binlog_position = ? " | ||
+ "ON DUPLICATE KEY UPDATE binlog_file=?, binlog_position=?"; | ||
PreparedStatement s = c.prepareStatement(sql); | ||
|
||
s.setLong(1, serverID); | ||
s.setString(2, p.getFile()); | ||
s.setLong(3, p.getOffset()); | ||
s.setString(4, p.getFile()); | ||
s.setLong(5, p.getOffset()); | ||
|
||
s.execute(); | ||
} | ||
|
||
} |
This file contains 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 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 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