This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 1b80ba306d3 Refactor BinlogContext (#32539)
1b80ba306d3 is described below
commit 1b80ba306d38403905f1db5bcb1af849e33f777f
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 15 23:50:25 2024 +0800
Refactor BinlogContext (#32539)
* Refactor MySQLIncrementalDumper
* Refactor BinlogContext
* Refactor BinlogContext
---
.../mysql/ingest/binlog/BinlogContext.java | 40 +++-------------------
.../netty/MySQLBinlogEventPacketDecoder.java | 4 +--
.../mysql/ingest/binlog/BinlogContextTest.java | 25 --------------
3 files changed, 6 insertions(+), 63 deletions(-)
diff --git
a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/binlog/BinlogContext.java
b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/binlog/BinlogContext.java
index 854b35b53f5..cbf3b1a977a 100644
---
a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/binlog/BinlogContext.java
+++
b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/binlog/BinlogContext.java
@@ -21,25 +21,23 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import
org.apache.shardingsphere.db.protocol.mysql.packet.binlog.row.MySQLBinlogTableMapEventPacket;
-import
org.apache.shardingsphere.db.protocol.mysql.packet.binlog.row.column.MySQLBinlogColumnDef;
-import java.util.List;
import java.util.Map;
/**
* Binlog context.
*/
-@Getter
@RequiredArgsConstructor
+@Getter
+@Setter
public final class BinlogContext {
- @Setter
- private volatile String fileName;
-
private final int checksumLength;
private final Map<Long, MySQLBinlogTableMapEventPacket> tableMap;
+ private volatile String fileName;
+
/**
* Cache table map event.
*
@@ -59,34 +57,4 @@ public final class BinlogContext {
public MySQLBinlogTableMapEventPacket getTableMapEvent(final long tableId)
{
return tableMap.get(tableId);
}
-
- /**
- * Get table name by table id.
- *
- * @param tableId table id
- * @return table name
- */
- public String getTableName(final long tableId) {
- return tableMap.get(tableId).getTableName();
- }
-
- /**
- * Get database name by table id.
- *
- * @param tableId table id
- * @return database name
- */
- public String getDatabaseName(final long tableId) {
- return tableMap.get(tableId).getSchemaName();
- }
-
- /**
- * Get column defined by table id.
- *
- * @param tableId table id
- * @return MySQL binlog column definitions
- */
- public List<MySQLBinlogColumnDef> getColumnDefs(final long tableId) {
- return tableMap.get(tableId).getColumnDefs();
- }
}
diff --git
a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLBinlogEventPacketDecoder.java
b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLBinlogEventPacketDecoder.java
index 1d2984a3d77..c910e559e6d 100644
---
a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLBinlogEventPacketDecoder.java
+++
b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLBinlogEventPacketDecoder.java
@@ -226,8 +226,8 @@ public final class MySQLBinlogEventPacketDecoder extends
ByteToMessageDecoder {
}
private void initRowsEvent(final AbstractRowsEvent rowsEvent, final
MySQLBinlogEventHeader binlogEventHeader, final long tableId) {
- rowsEvent.setDatabaseName(binlogContext.getDatabaseName(tableId));
- rowsEvent.setTableName(binlogContext.getTableName(tableId));
+
rowsEvent.setDatabaseName(binlogContext.getTableMapEvent(tableId).getSchemaName());
+
rowsEvent.setTableName(binlogContext.getTableMapEvent(tableId).getTableName());
rowsEvent.setFileName(binlogContext.getFileName());
rowsEvent.setPosition(binlogEventHeader.getLogPos());
rowsEvent.setTimestamp(binlogEventHeader.getTimestamp());
diff --git
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/binlog/BinlogContextTest.java
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/binlog/BinlogContextTest.java
index 5a7409cef34..b4b6bd749ff 100644
---
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/binlog/BinlogContextTest.java
+++
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/binlog/BinlogContextTest.java
@@ -17,9 +17,7 @@
package org.apache.shardingsphere.data.pipeline.mysql.ingest.binlog;
-import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLBinaryColumnType;
import
org.apache.shardingsphere.db.protocol.mysql.packet.binlog.row.MySQLBinlogTableMapEventPacket;
-import
org.apache.shardingsphere.db.protocol.mysql.packet.binlog.row.column.MySQLBinlogColumnDef;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -28,9 +26,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -58,27 +54,6 @@ class BinlogContextTest {
when(tableMapEventPacket.getTableName()).thenReturn(TEST_TABLE);
}
- @Test
- void assertGetTableName() {
- binlogContext.putTableMapEvent(TEST_TABLE_ID, tableMapEventPacket);
- assertThat(binlogContext.getTableName(TEST_TABLE_ID), is(TEST_TABLE));
- }
-
- @Test
- void assertGetDatabaseName() {
- binlogContext.putTableMapEvent(TEST_TABLE_ID, tableMapEventPacket);
- assertThat(binlogContext.getDatabaseName(TEST_TABLE_ID),
is(TEST_SCHEMA));
- }
-
- @Test
- void assertGetColumnDefs() {
- binlogContext.putTableMapEvent(TEST_TABLE_ID, tableMapEventPacket);
- List<MySQLBinlogColumnDef> columnDefs = new ArrayList<>(1);
- columnDefs.add(new MySQLBinlogColumnDef(MySQLBinaryColumnType.LONG));
- when(tableMapEventPacket.getColumnDefs()).thenReturn(columnDefs);
- assertThat(binlogContext.getColumnDefs(TEST_TABLE_ID), is(columnDefs));
- }
-
@Test
void assertGetTableMapEvent() {
binlogContext.putTableMapEvent(TEST_TABLE_ID, tableMapEventPacket);