From 081903dfe9054f80f5f9b0f923d024475a503525 Mon Sep 17 00:00:00 2001 From: xzxiaoshan <365384722@qq.com> Date: Thu, 23 May 2024 14:29:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B9=E6=B3=95updateClientBinlogFilenameAnd?= =?UTF-8?q?Position=E5=92=8CupdateGtidSet=E7=AD=89=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=80=E6=A0=B7=EF=BC=8C=E5=8F=AF=E4=BB=A5=E8=A2=AB=E6=8C=89?= =?UTF-8?q?=E9=9C=80=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 方法updateClientBinlogFilenameAndPosition和updateGtidSet等方法一样,可以被按需重写。 例如,重写该方法并添加对 binlogFileName 和 position 进行持久化。当服务宕机重启后可以从持久化中读取并继续。 例如: ``` BinaryLogClient client = new BinaryLogClient(binLogProperties.getHost(), binLogProperties.getPort(), binLogProperties.getUsername(), binLogProperties.getPassword()) { @Override private void updateClientBinlogFilenameAndPosition(Event event) { super.updateClientBinlogFilenameAndPosition(event); // 将binlogFileName和position持久化记录,在服务宕机重启后读取并继续 // (略) } }; ``` --- .../java/com/github/shyiko/mysql/binlog/BinaryLogClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java b/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java index 9376a732..24b7404d 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java @@ -1124,7 +1124,7 @@ private byte[] readPacketSplitInChunks(ByteArrayInputStream inputStream, int pac return result; } - private void updateClientBinlogFilenameAndPosition(Event event) { + protected void updateClientBinlogFilenameAndPosition(Event event) { EventHeader eventHeader = event.getHeader(); EventType eventType = eventHeader.getEventType(); if (eventType == EventType.ROTATE) {