Skip to content

Commit

Permalink
close to finish full read and begin full write
Browse files Browse the repository at this point in the history
  • Loading branch information
sodaRyCN committed Jul 11, 2024
1 parent 7659e59 commit cd3575b
Show file tree
Hide file tree
Showing 15 changed files with 501 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.mysql.cj.MysqlType;

import java.sql.JDBCType;
import java.util.HashMap;
import java.util.Map;

public enum CanalMySQLType {
BIT("BIT"),
Expand All @@ -12,37 +13,38 @@ public enum CanalMySQLType {
INT("INT"),
BIGINT("BIGINT"),
DECIMAL("DECIMAL"),
FLOAT("FLOAT", JDBCType.REAL),
DOUBLE("DOUBLE", JDBCType.DOUBLE),
DATE("DATE", JDBCType.DATE),
DATETIME("DATETIME", JDBCType.TIMESTAMP),
TIMESTAMP("TIMESTAMP", JDBCType.TIMESTAMP),
TIME("TIME", JDBCType.TIME),
YEAR("YEAR", JDBCType.DATE),
CHAR("CHAR", JDBCType.CHAR),
VARCHAR("VARCHAR", JDBCType.VARCHAR),
BINARY("BINARY", JDBCType.BINARY),
VARBINARY("VARBINARY", JDBCType.VARBINARY),
TINYBLOB("TINYBLOB", JDBCType.VARBINARY),
BLOB("BLOB", JDBCType.LONGVARBINARY),
MEDIUMBLOB("MEDIUMBLOB", JDBCType.LONGVARBINARY),
LONGBLOB("LONGBLOB", JDBCType.LONGVARBINARY),
TINYTEXT("TINYTEXT", JDBCType.VARCHAR),
TEXT("TEXT", JDBCType.LONGVARCHAR),
MEDIUMTEXT("MEDIUMTEXT", JDBCType.LONGVARCHAR),
LONGTEXT("LONGTEXT", JDBCType.LONGVARCHAR),
ENUM("ENUM", JDBCType.CHAR),
SET("SET", JDBCType.CHAR),
JSON("JSON", JDBCType.LONGVARCHAR),
GEOMETRY("GEOMETRY", JDBCType.BINARY),
POINT("POINT", JDBCType.BINARY),
LINESTRING("LINESTRING", JDBCType.BINARY),
POLYGON("POLYGON", JDBCType.BINARY),
MULTIPOINT("MULTIPOINT", JDBCType.BINARY),
GEOMETRY_COLLECTION("GEOMETRYCOLLECTION", JDBCType.BINARY),
GEOM_COLLECTION("GEOMCOLLECTION", JDBCType.BINARY),
MULTILINESTRING("MULTILINESTRING", JDBCType.BINARY),
MULTIPOLYGON("MULTIPOLYGON", JDBCType.BINARY);
FLOAT("FLOAT"),
DOUBLE("DOUBLE"),
DATE("DATE"),
DATETIME("DATETIME"),
TIMESTAMP("TIMESTAMP"),
TIME("TIME"),
YEAR("YEAR"),
CHAR("CHAR"),
VARCHAR("VARCHAR"),
BINARY("BINARY"),
VARBINARY("VARBINARY"),
TINYBLOB("TINYBLOB"),
BLOB("BLOB"),
MEDIUMBLOB("MEDIUMBLOB"),
LONGBLOB("LONGBLOB"),
TINYTEXT("TINYTEXT"),
TEXT("TEXT"),
MEDIUMTEXT("MEDIUMTEXT"),
LONGTEXT("LONGTEXT"),
ENUM("ENUM"),
SET("SET"),
JSON("JSON"),
GEOMETRY("GEOMETRY"),
// MysqlType not include the following type
POINT("POINT"),
LINESTRING("LINESTRING"),
POLYGON("POLYGON"),
MULTIPOINT("MULTIPOINT"),
GEOMETRY_COLLECTION("GEOMETRYCOLLECTION"),
GEOM_COLLECTION("GEOMCOLLECTION"),
MULTILINESTRING("MULTILINESTRING"),
MULTIPOLYGON("MULTIPOLYGON");

private final String codeKey;
private final MysqlType mysqlType;
Expand All @@ -51,13 +53,18 @@ public enum CanalMySQLType {
this.codeKey = codeKey;
this.mysqlType = MysqlType.getByName(codeKey);
}

public static CanalMySQLType valueOfCode(String code) {
private static final Map<String, CanalMySQLType> TYPES = new HashMap<>();
static {
CanalMySQLType[] values = values();
for (CanalMySQLType tableType : values) {
if (tableType.codeKey.equalsIgnoreCase(code)) {
return tableType;
}
TYPES.put(tableType.codeKey, tableType);
}
}

public static CanalMySQLType valueOfCode(String code) {
CanalMySQLType type = TYPES.get(code.toUpperCase());
if (type != null) {
return type;
}
switch (MysqlType.getByName(code)) {
case BOOLEAN:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.apache.eventmesh.common.config.connector.rdb.canal;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.eventmesh.common.config.connector.SinkConfig;


@Data
@EqualsAndHashCode(callSuper = true)
public class CanalSinkFullConfig extends SinkConfig {

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class CanalSourceFullConfig extends SourceConfig {
private SourceConnectorConfig connectorConfig;
private List<RecordPosition> startPosition;
private int parallel;
private int flushSize;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package org.apache.eventmesh.common.config.connector.rdb.canal;

import lombok.Data;
import lombok.ToString;

import java.math.BigDecimal;

@Data
@ToString
public class JobRdbFullPosition {
private String jobId;
private String schema;
private String tableName;
private String curPrimaryKey;
private String primaryKeyRecords;
private long maxCount;
private boolean finished;
private BigDecimal percent;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.apache.eventmesh.common.remote.offset.canal;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.eventmesh.common.config.connector.rdb.canal.JobRdbFullPosition;
import org.apache.eventmesh.common.remote.offset.RecordOffset;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString
public class CanalFullRecordOffset extends RecordOffset {
private JobRdbFullPosition position;
@Override
public Class<? extends RecordOffset> getRecordOffsetClass() {
return CanalFullRecordOffset.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.common.remote.offset.canal;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.eventmesh.common.remote.offset.RecordPartition;


@Data
@ToString
@EqualsAndHashCode(callSuper = true)
public class CanalFullRecordPartition extends RecordPartition {
private String schema;
private String table;

@Override
public Class<? extends RecordPartition> getRecordPartitionClass() {
return CanalFullRecordPartition.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
package org.apache.eventmesh.connector.canal;


import com.alibaba.druid.pool.DruidDataSource;
import org.apache.eventmesh.common.config.connector.rdb.canal.CanalSinkConfig;
import org.apache.eventmesh.common.config.connector.rdb.canal.CanalSourceConfig;

import java.sql.Connection;
import java.sql.SQLException;

import com.alibaba.druid.pool.DruidDataSource;

public class DatabaseConnection {

public static DruidDataSource sourceDataSource;
Expand All @@ -42,6 +41,7 @@ public static DruidDataSource createDruidDataSource(String url, String UserName,
dataSource.setUsername(UserName);
dataSource.setPassword(passWord);
dataSource.setInitialSize(5);
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setMinIdle(5);
dataSource.setMaxActive(20);
dataSource.setMaxWait(60000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

package org.apache.eventmesh.connector.canal;

import static org.apache.eventmesh.connector.canal.ByteArrayConverter.SQL_BYTES;
import static org.apache.eventmesh.connector.canal.SqlTimestampConverter.SQL_TIMESTAMP;

import com.mysql.cj.MysqlType;
import org.apache.commons.beanutils.ConvertUtilsBean;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
Expand All @@ -42,8 +41,8 @@
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.eventmesh.connector.canal.ByteArrayConverter.SQL_BYTES;
import static org.apache.eventmesh.connector.canal.SqlTimestampConverter.SQL_TIMESTAMP;

public class SqlUtils {

Expand Down Expand Up @@ -127,8 +126,13 @@ public static String genPrepareSqlOfInClause(int size) {
}

public static void setInClauseParameters(PreparedStatement preparedStatement, List<String> params) throws SQLException {
setInClauseParameters(preparedStatement, 0, params);
}

public static void setInClauseParameters(PreparedStatement preparedStatement, int paramIndexStart,
List<String> params) throws SQLException {
for (int i = 0; i < params.size(); i++) {
preparedStatement.setString(i + 1, params.get(i));
preparedStatement.setString(paramIndexStart + i, params.get(i));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.apache.eventmesh.connector.canal.sink.connector;

import org.apache.eventmesh.common.config.connector.Config;
import org.apache.eventmesh.common.config.connector.rdb.canal.CanalSinkFullConfig;
import org.apache.eventmesh.openconnect.api.ConnectorCreateService;
import org.apache.eventmesh.openconnect.api.connector.ConnectorContext;
import org.apache.eventmesh.openconnect.api.connector.SinkConnectorContext;
import org.apache.eventmesh.openconnect.api.sink.Sink;
import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;

import java.util.List;

public class CanalSinkFullConnector implements Sink, ConnectorCreateService<Sink> {
private CanalSinkFullConfig config;
@Override
public void start() throws Exception {

}

@Override
public void stop() throws Exception {

}

@Override
public Sink create() {
return new CanalSinkFullConnector();
}

@Override
public Class<? extends Config> configClass() {
return CanalSinkFullConfig.class;
}

@Override
public void init(Config config) throws Exception {
this.config = (CanalSinkFullConfig) config;
}

@Override
public void init(ConnectorContext connectorContext) throws Exception {
this.config = (CanalSinkFullConfig)((SinkConnectorContext)connectorContext).getSinkConfig();
}

@Override
public void commit(ConnectRecord record) {

}

@Override
public String name() {
return null;
}

@Override
public void put(List<ConnectRecord> sinkRecords) {

}
}
Loading

0 comments on commit cd3575b

Please sign in to comment.