mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
format
This commit is contained in:
@@ -5,6 +5,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.ESAdapter;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.es6x.etl.ESEtlService;
|
||||
@@ -14,9 +18,6 @@ import com.alibaba.otter.canal.client.adapter.support.DatasourceConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.support.EtlResult;
|
||||
import com.alibaba.otter.canal.client.adapter.support.OuterAdapterConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.support.SPI;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* ES 6.x 外部适配器
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
@@ -118,8 +117,7 @@ public class ESEtlService extends AbstractEtlService {
|
||||
if (idVal != null) {
|
||||
String parentVal = (String) esFieldData.remove("$parent_routing");
|
||||
if (mapping.isUpsert()) {
|
||||
ESUpdateRequest esUpdateRequest = this.esConnection.new ES6xUpdateRequest(
|
||||
mapping.get_index(),
|
||||
ESUpdateRequest esUpdateRequest = this.esConnection.new ES6xUpdateRequest(mapping.get_index(),
|
||||
mapping.get_type(),
|
||||
idVal.toString()).setDoc(esFieldData).setDocAsUpsert(true);
|
||||
|
||||
@@ -129,8 +127,9 @@ public class ESEtlService extends AbstractEtlService {
|
||||
|
||||
esBulkRequest.add(esUpdateRequest);
|
||||
} else {
|
||||
ESIndexRequest esIndexRequest = this.esConnection.new ES6xIndexRequest(mapping
|
||||
.get_index(), mapping.get_type(), idVal.toString()).setSource(esFieldData);
|
||||
ESIndexRequest esIndexRequest = this.esConnection.new ES6xIndexRequest(mapping.get_index(),
|
||||
mapping.get_type(),
|
||||
idVal.toString()).setSource(esFieldData);
|
||||
if (StringUtils.isNotEmpty(parentVal)) {
|
||||
esIndexRequest.setRouting(parentVal);
|
||||
}
|
||||
@@ -139,18 +138,17 @@ public class ESEtlService extends AbstractEtlService {
|
||||
} else {
|
||||
idVal = esFieldData.get(mapping.getPk());
|
||||
ESSearchRequest esSearchRequest = this.esConnection.new ESSearchRequest(mapping.get_index(),
|
||||
mapping.get_type()).setQuery(QueryBuilders.termQuery(mapping.getPk(), idVal))
|
||||
.size(10000);
|
||||
mapping.get_type()).setQuery(QueryBuilders.termQuery(mapping.getPk(), idVal)).size(10000);
|
||||
SearchResponse response = esSearchRequest.getResponse();
|
||||
for (SearchHit hit : response.getHits()) {
|
||||
ESUpdateRequest esUpdateRequest = this.esConnection.new ES6xUpdateRequest(mapping
|
||||
.get_index(), mapping.get_type(), hit.getId()).setDoc(esFieldData);
|
||||
ESUpdateRequest esUpdateRequest = this.esConnection.new ES6xUpdateRequest(mapping.get_index(),
|
||||
mapping.get_type(),
|
||||
hit.getId()).setDoc(esFieldData);
|
||||
esBulkRequest.add(esUpdateRequest);
|
||||
}
|
||||
}
|
||||
|
||||
if (esBulkRequest.numberOfActions() % mapping.getCommitBatch() == 0
|
||||
&& esBulkRequest.numberOfActions() > 0) {
|
||||
if (esBulkRequest.numberOfActions() % mapping.getCommitBatch() == 0 && esBulkRequest.numberOfActions() > 0) {
|
||||
long esBatchBegin = System.currentTimeMillis();
|
||||
ESBulkResponse rp = esBulkRequest.bulk();
|
||||
if (rp.hasFailures()) {
|
||||
|
||||
@@ -2,7 +2,11 @@ package com.alibaba.otter.canal.client.adapter.es6x.support;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
@@ -20,8 +24,8 @@ import org.slf4j.LoggerFactory;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig.ESMapping;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.ColumnItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESBulkResponse;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESDeleteRequest;
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
@@ -27,7 +26,11 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.action.update.UpdateRequestBuilder;
|
||||
import org.elasticsearch.client.*;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.RestHighLevelClientExt;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
@@ -40,6 +43,8 @@ import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest;
|
||||
|
||||
/**
|
||||
* ES 连接器, Transport Rest 两种方式
|
||||
*
|
||||
@@ -86,10 +91,9 @@ public class ESConnection {
|
||||
if (StringUtils.isNotEmpty(nameAndPwd) && nameAndPwd.contains(":")) {
|
||||
String[] nameAndPwdArr = nameAndPwd.split(":");
|
||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
credentialsProvider.setCredentials(AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(nameAndPwdArr[0], nameAndPwdArr[1]));
|
||||
restClientBuilder.setHttpClientConfigCallback(
|
||||
httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
|
||||
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(nameAndPwdArr[0],
|
||||
nameAndPwdArr[1]));
|
||||
restClientBuilder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
|
||||
}
|
||||
restHighLevelClient = new RestHighLevelClient(restClientBuilder);
|
||||
}
|
||||
@@ -418,6 +422,7 @@ public class ESConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public ESBulkResponse bulk() {
|
||||
if (mode == ESClientMode.TRANSPORT) {
|
||||
BulkResponse responses = bulkRequestBuilder.execute().actionGet();
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.alibaba.otter.canal.client.adapter.es6x.test.sync;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.alibaba.otter.canal.client.adapter.es6x.test.sync;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.alibaba.otter.canal.client.adapter.es6x.test.sync;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.alibaba.otter.canal.client.adapter.es6x.test.sync;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.alibaba.otter.canal.client.adapter.es6x.test.sync;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.alibaba.otter.canal.client.adapter.es6x.test.sync;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.junit.Assert;
|
||||
|
||||
@@ -5,20 +5,20 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.es7x.etl.ESEtlService;
|
||||
import com.alibaba.otter.canal.client.adapter.support.DatasourceConfig;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.ESAdapter;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.es7x.etl.ESEtlService;
|
||||
import com.alibaba.otter.canal.client.adapter.es7x.support.ES7xTemplate;
|
||||
import com.alibaba.otter.canal.client.adapter.es7x.support.ESConnection;
|
||||
import com.alibaba.otter.canal.client.adapter.support.DatasourceConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.support.EtlResult;
|
||||
import com.alibaba.otter.canal.client.adapter.support.OuterAdapterConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.support.SPI;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* ES 7.x 外部适配器
|
||||
*
|
||||
|
||||
@@ -2,7 +2,11 @@ package com.alibaba.otter.canal.client.adapter.es7x.support;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ public class ESConnection {
|
||||
|
||||
private ESClientMode mode;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private TransportClient transportClient;
|
||||
|
||||
private RestHighLevelClient restHighLevelClient;
|
||||
@@ -89,10 +90,9 @@ public class ESConnection {
|
||||
if (StringUtils.isNotEmpty(nameAndPwd) && nameAndPwd.contains(":")) {
|
||||
String[] nameAndPwdArr = nameAndPwd.split(":");
|
||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
credentialsProvider.setCredentials(AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(nameAndPwdArr[0], nameAndPwdArr[1]));
|
||||
restClientBuilder.setHttpClientConfigCallback(
|
||||
httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
|
||||
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(nameAndPwdArr[0],
|
||||
nameAndPwdArr[1]));
|
||||
restClientBuilder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
|
||||
}
|
||||
restHighLevelClient = new RestHighLevelClient(restClientBuilder);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.junit.Test;
|
||||
@Ignore
|
||||
public class ES7xTest {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private TransportClient transportClient;
|
||||
|
||||
@Before
|
||||
@@ -65,8 +66,9 @@ public class ES7xTest {
|
||||
relations.put("parent", "2");
|
||||
|
||||
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
|
||||
bulkRequestBuilder
|
||||
.add(transportClient.prepareIndex("test", "osm", "2_4").setRouting("2").setSource(esFieldData));
|
||||
bulkRequestBuilder.add(transportClient.prepareIndex("test", "osm", "2_4")
|
||||
.setRouting("2")
|
||||
.setSource(esFieldData));
|
||||
commit(bulkRequestBuilder);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.es7x.support.ESConnection;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@Ignore
|
||||
public class ESConnectionTest {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.alibaba.otter.canal.client.adapter.es.core;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -8,7 +7,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.support.ESTemplate;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
@@ -19,6 +17,7 @@ import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SqlParser;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.monitor.ESConfigMonitor;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.service.ESSyncService;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.support.ESTemplate;
|
||||
import com.alibaba.otter.canal.client.adapter.support.DatasourceConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.support.Dml;
|
||||
import com.alibaba.otter.canal.client.adapter.support.EtlResult;
|
||||
@@ -63,8 +62,8 @@ public abstract class ESAdapter implements OuterAdapter {
|
||||
// 过滤不匹配的key的配置
|
||||
esSyncConfigTmp.forEach((key, config) -> {
|
||||
if ((config.getOuterAdapterKey() == null && configuration.getKey() == null)
|
||||
|| (config.getOuterAdapterKey() != null
|
||||
&& config.getOuterAdapterKey().equalsIgnoreCase(configuration.getKey()))) {
|
||||
|| (config.getOuterAdapterKey() != null && config.getOuterAdapterKey()
|
||||
.equalsIgnoreCase(configuration.getKey()))) {
|
||||
esSyncConfig.put(key, config);
|
||||
}
|
||||
});
|
||||
@@ -104,12 +103,12 @@ public abstract class ESAdapter implements OuterAdapter {
|
||||
String table = dml.getTable();
|
||||
Map<String, ESSyncConfig> configMap;
|
||||
if (envProperties != null && !"tcp".equalsIgnoreCase(envProperties.getProperty("canal.conf.mode"))) {
|
||||
configMap = dbTableEsSyncConfig
|
||||
.get(StringUtils.trimToEmpty(dml.getDestination()) + "-" + StringUtils.trimToEmpty(dml.getGroupId())
|
||||
+ "_" + database + "-" + table);
|
||||
configMap = dbTableEsSyncConfig.get(StringUtils.trimToEmpty(dml.getDestination()) + "-"
|
||||
+ StringUtils.trimToEmpty(dml.getGroupId()) + "_" + database + "-"
|
||||
+ table);
|
||||
} else {
|
||||
configMap = dbTableEsSyncConfig
|
||||
.get(StringUtils.trimToEmpty(dml.getDestination()) + "_" + database + "-" + table);
|
||||
configMap = dbTableEsSyncConfig.get(StringUtils.trimToEmpty(dml.getDestination()) + "_" + database + "-"
|
||||
+ table);
|
||||
}
|
||||
|
||||
if (configMap != null && !configMap.values().isEmpty()) {
|
||||
@@ -155,18 +154,24 @@ public abstract class ESAdapter implements OuterAdapter {
|
||||
}
|
||||
String schema = matcher.group(2);
|
||||
|
||||
schemaItem.getAliasTableItems().values().forEach(tableItem -> {
|
||||
schemaItem.getAliasTableItems()
|
||||
.values()
|
||||
.forEach(tableItem -> {
|
||||
Map<String, ESSyncConfig> esSyncConfigMap;
|
||||
if (envProperties != null
|
||||
&& !"tcp".equalsIgnoreCase(envProperties.getProperty("canal.conf.mode"))) {
|
||||
esSyncConfigMap = dbTableEsSyncConfig
|
||||
.computeIfAbsent(StringUtils.trimToEmpty(config.getDestination()) + "-"
|
||||
+ StringUtils.trimToEmpty(config.getGroupId()) + "_" + schema + "-"
|
||||
if (envProperties != null && !"tcp".equalsIgnoreCase(envProperties.getProperty("canal.conf.mode"))) {
|
||||
esSyncConfigMap = dbTableEsSyncConfig.computeIfAbsent(StringUtils.trimToEmpty(config.getDestination())
|
||||
+ "-"
|
||||
+ StringUtils.trimToEmpty(config.getGroupId())
|
||||
+ "_"
|
||||
+ schema
|
||||
+ "-"
|
||||
+ tableItem.getTableName(),
|
||||
k -> new ConcurrentHashMap<>());
|
||||
} else {
|
||||
esSyncConfigMap = dbTableEsSyncConfig
|
||||
.computeIfAbsent(StringUtils.trimToEmpty(config.getDestination()) + "_" + schema + "-"
|
||||
esSyncConfigMap = dbTableEsSyncConfig.computeIfAbsent(StringUtils.trimToEmpty(config.getDestination())
|
||||
+ "_"
|
||||
+ schema
|
||||
+ "-"
|
||||
+ tableItem.getTableName(),
|
||||
k -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
@@ -9,8 +9,19 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.alibaba.fastsql.sql.SQLUtils;
|
||||
import com.alibaba.fastsql.sql.ast.SQLExpr;
|
||||
import com.alibaba.fastsql.sql.ast.expr.*;
|
||||
import com.alibaba.fastsql.sql.ast.statement.*;
|
||||
import com.alibaba.fastsql.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.fastsql.sql.ast.expr.SQLCaseExpr;
|
||||
import com.alibaba.fastsql.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.fastsql.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.fastsql.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.fastsql.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.fastsql.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.fastsql.sql.ast.statement.SQLJoinTableSource;
|
||||
import com.alibaba.fastsql.sql.ast.statement.SQLSelectGroupByClause;
|
||||
import com.alibaba.fastsql.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.fastsql.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.fastsql.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.fastsql.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.fastsql.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
|
||||
import com.alibaba.fastsql.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.fastsql.sql.parser.ParserException;
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.alibaba.otter.canal.client.adapter.es.core.monitor;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.ESAdapter;
|
||||
import org.apache.commons.io.filefilter.FileFilterUtils;
|
||||
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
|
||||
import org.apache.commons.io.monitor.FileAlterationMonitor;
|
||||
@@ -15,12 +11,9 @@ import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.otter.canal.client.adapter.config.YmlConfigBinder;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.ESAdapter;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SqlParser;
|
||||
import com.alibaba.otter.canal.client.adapter.support.DatasourceConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.support.MappingConfigsLoader;
|
||||
import com.alibaba.otter.canal.client.adapter.support.Util;
|
||||
|
||||
@@ -70,8 +63,11 @@ public class ESConfigMonitor {
|
||||
try {
|
||||
// 加载新增的配置文件
|
||||
String configContent = MappingConfigsLoader.loadConfig(adapterName + File.separator + file.getName());
|
||||
ESSyncConfig config = YmlConfigBinder
|
||||
.bindYmlToObj(null, configContent, ESSyncConfig.class, null, envProperties);
|
||||
ESSyncConfig config = YmlConfigBinder.bindYmlToObj(null,
|
||||
configContent,
|
||||
ESSyncConfig.class,
|
||||
null,
|
||||
envProperties);
|
||||
if (config != null) {
|
||||
config.validate();
|
||||
addConfigToCache(file, config);
|
||||
@@ -89,14 +85,17 @@ public class ESConfigMonitor {
|
||||
try {
|
||||
if (esAdapter.getEsSyncConfig().containsKey(file.getName())) {
|
||||
// 加载配置文件
|
||||
String configContent = MappingConfigsLoader
|
||||
.loadConfig(adapterName + File.separator + file.getName());
|
||||
String configContent = MappingConfigsLoader.loadConfig(adapterName + File.separator
|
||||
+ file.getName());
|
||||
if (configContent == null) {
|
||||
onFileDelete(file);
|
||||
return;
|
||||
}
|
||||
ESSyncConfig config = YmlConfigBinder
|
||||
.bindYmlToObj(null, configContent, ESSyncConfig.class, null, envProperties);
|
||||
ESSyncConfig config = YmlConfigBinder.bindYmlToObj(null,
|
||||
configContent,
|
||||
ESSyncConfig.class,
|
||||
null,
|
||||
envProperties);
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
package com.alibaba.otter.canal.client.adapter.es.core.service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.alibaba.fastsql.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SqlParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastsql.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig.ESMapping;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.ColumnItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.TableItem;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.config.SqlParser;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.support.ESSyncUtil;
|
||||
import com.alibaba.otter.canal.client.adapter.es.core.support.ESTemplate;
|
||||
import com.alibaba.otter.canal.client.adapter.support.DatasourceConfig;
|
||||
|
||||
@@ -5,7 +5,13 @@ import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Blob;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
@@ -5,19 +5,24 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.support.*;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.hbase.config.MappingConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.hbase.support.*;
|
||||
import com.alibaba.otter.canal.client.adapter.hbase.support.HRow;
|
||||
import com.alibaba.otter.canal.client.adapter.hbase.support.HbaseTemplate;
|
||||
import com.alibaba.otter.canal.client.adapter.hbase.support.PhType;
|
||||
import com.alibaba.otter.canal.client.adapter.hbase.support.PhTypeUtil;
|
||||
import com.alibaba.otter.canal.client.adapter.hbase.support.Type;
|
||||
import com.alibaba.otter.canal.client.adapter.hbase.support.TypeUtil;
|
||||
import com.alibaba.otter.canal.client.adapter.support.AbstractEtlService;
|
||||
import com.alibaba.otter.canal.client.adapter.support.AdapterConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.support.EtlResult;
|
||||
import com.alibaba.otter.canal.client.adapter.support.JdbcTypeUtil;
|
||||
import com.alibaba.otter.canal.client.adapter.support.Util;
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
/**
|
||||
@@ -79,7 +84,8 @@ public class HbaseEtlService extends AbstractEtlService {
|
||||
createTable();
|
||||
|
||||
// 拼接sql
|
||||
String sql = "SELECT * FROM `" + config.getHbaseMapping().getDatabase() + "`.`" + hbaseMapping.getTable() + "`";
|
||||
String sql = "SELECT * FROM `" + config.getHbaseMapping().getDatabase() + "`.`" + hbaseMapping.getTable()
|
||||
+ "`";
|
||||
|
||||
return super.importData(sql, params);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.alibaba.otter.canal.adapter.launcher.config;
|
||||
|
||||
import com.alibaba.otter.canal.adapter.launcher.monitor.remote.ConfigItem;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.alibaba.otter.canal.adapter.launcher.monitor.remote.ConfigItem;
|
||||
|
||||
/**
|
||||
* @author L.J.R @ 2019-09-03
|
||||
* @version 1.1.4
|
||||
|
||||
@@ -8,20 +8,20 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import com.alibaba.otter.canal.adapter.launcher.config.SpringContext;
|
||||
import com.alibaba.otter.canal.client.adapter.support.Util;
|
||||
import com.alibaba.otter.canal.connector.core.config.CanalConstants;
|
||||
import com.alibaba.otter.canal.connector.core.spi.ExtensionLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.otter.canal.adapter.launcher.common.SyncSwitch;
|
||||
import com.alibaba.otter.canal.adapter.launcher.config.SpringContext;
|
||||
import com.alibaba.otter.canal.client.adapter.OuterAdapter;
|
||||
import com.alibaba.otter.canal.client.adapter.support.CanalClientConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.support.Dml;
|
||||
import com.alibaba.otter.canal.client.adapter.support.MessageUtil;
|
||||
import com.alibaba.otter.canal.client.adapter.support.Util;
|
||||
import com.alibaba.otter.canal.connector.core.config.CanalConstants;
|
||||
import com.alibaba.otter.canal.connector.core.consumer.CommonMessage;
|
||||
import com.alibaba.otter.canal.connector.core.spi.CanalMsgConsumer;
|
||||
import com.alibaba.otter.canal.connector.core.spi.ExtensionLoader;
|
||||
|
||||
/**
|
||||
* 适配处理器
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.alibaba.otter.canal.adapter.launcher.loader;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -60,22 +57,29 @@ public class CanalAdapterLoader {
|
||||
}
|
||||
canalOuterAdapterGroups.add(canalOuterAdapters);
|
||||
|
||||
AdapterProcessor adapterProcessor = canalAdapterProcessors.computeIfAbsent(canalAdapter.getInstance()+"|"+StringUtils.trimToEmpty(group.getGroupId()),
|
||||
f-> new AdapterProcessor(canalClientConfig,canalAdapter.getInstance(),
|
||||
group.getGroupId(), canalOuterAdapterGroups));
|
||||
AdapterProcessor adapterProcessor = canalAdapterProcessors.computeIfAbsent(canalAdapter.getInstance()
|
||||
+ "|"
|
||||
+ StringUtils.trimToEmpty(group.getGroupId()),
|
||||
f -> new AdapterProcessor(canalClientConfig,
|
||||
canalAdapter.getInstance(),
|
||||
group.getGroupId(),
|
||||
canalOuterAdapterGroups));
|
||||
adapterProcessor.start();
|
||||
|
||||
logger.info("Start adapter for canal-client mq topic: {} succeed",
|
||||
canalAdapter.getInstance() + "-" + group.getGroupId());
|
||||
logger.info("Start adapter for canal-client mq topic: {} succeed", canalAdapter.getInstance() + "-"
|
||||
+ group.getGroupId());
|
||||
}
|
||||
}
|
||||
|
||||
// if ("tcp".equalsIgnoreCase(canalClientConfig.getMode())) {
|
||||
// // 初始化canal-client的适配器
|
||||
// for (CanalClientConfig.CanalAdapter canalAdapter : canalClientConfig.getCanalAdapters()) {
|
||||
// List<List<OuterAdapter>> canalOuterAdapterGroups = new CopyOnWriteArrayList<>();
|
||||
// for (CanalClientConfig.CanalAdapter canalAdapter :
|
||||
// canalClientConfig.getCanalAdapters()) {
|
||||
// List<List<OuterAdapter>> canalOuterAdapterGroups = new
|
||||
// CopyOnWriteArrayList<>();
|
||||
//
|
||||
// for (CanalClientConfig.Group connectorGroup : canalAdapter.getGroups()) {
|
||||
// for (CanalClientConfig.Group connectorGroup :
|
||||
// canalAdapter.getGroups()) {
|
||||
// List<OuterAdapter> canalOutConnectors = new CopyOnWriteArrayList<>();
|
||||
// for (OuterAdapterConfig c : connectorGroup.getOuterAdapters()) {
|
||||
// loadAdapter(c, canalOutConnectors);
|
||||
@@ -99,42 +103,51 @@ public class CanalAdapterLoader {
|
||||
// }
|
||||
// canalWorkers.put(canalAdapter.getInstance(), worker);
|
||||
// worker.start();
|
||||
// logger.info("Start adapter for canal instance: {} succeed", canalAdapter.getInstance());
|
||||
// logger.info("Start adapter for canal instance: {} succeed",
|
||||
// canalAdapter.getInstance());
|
||||
// }
|
||||
// } else if ("kafka".equalsIgnoreCase(canalClientConfig.getMode())) {
|
||||
// // 初始化canal-client-kafka的适配器
|
||||
// for (CanalClientConfig.CanalAdapter canalAdapter : canalClientConfig.getCanalAdapters()) {
|
||||
// for (CanalClientConfig.CanalAdapter canalAdapter :
|
||||
// canalClientConfig.getCanalAdapters()) {
|
||||
// for (CanalClientConfig.Group group : canalAdapter.getGroups()) {
|
||||
// List<List<OuterAdapter>> canalOuterAdapterGroups = new CopyOnWriteArrayList<>();
|
||||
// List<List<OuterAdapter>> canalOuterAdapterGroups = new
|
||||
// CopyOnWriteArrayList<>();
|
||||
// List<OuterAdapter> canalOuterAdapters = new CopyOnWriteArrayList<>();
|
||||
// for (OuterAdapterConfig config : group.getOuterAdapters()) {
|
||||
// loadAdapter(config, canalOuterAdapters);
|
||||
// }
|
||||
// canalOuterAdapterGroups.add(canalOuterAdapters);
|
||||
//
|
||||
// CanalAdapterKafkaWorker canalKafkaWorker = new CanalAdapterKafkaWorker(canalClientConfig,
|
||||
// CanalAdapterKafkaWorker canalKafkaWorker = new
|
||||
// CanalAdapterKafkaWorker(canalClientConfig,
|
||||
// canalClientConfig.getMqServers(),
|
||||
// canalAdapter.getInstance(),
|
||||
// group.getGroupId(),
|
||||
// canalOuterAdapterGroups,
|
||||
// canalClientConfig.getFlatMessage());
|
||||
// canalMQWorker.put(canalAdapter.getInstance() + "-kafka-" + group.getGroupId(), canalKafkaWorker);
|
||||
// canalMQWorker.put(canalAdapter.getInstance() + "-kafka-" +
|
||||
// group.getGroupId(), canalKafkaWorker);
|
||||
// canalKafkaWorker.start();
|
||||
// logger.info("Start adapter for canal-client mq topic: {} succeed",
|
||||
// canalAdapter.getInstance() + "-" + group.getGroupId());
|
||||
// }
|
||||
// }
|
||||
// } else if ("rocketMQ".equalsIgnoreCase(canalClientConfig.getMode())) {
|
||||
// } else if ("rocketMQ".equalsIgnoreCase(canalClientConfig.getMode()))
|
||||
// {
|
||||
// // 初始化canal-client-rocketMQ的适配器
|
||||
// for (CanalClientConfig.CanalAdapter canalAdapter : canalClientConfig.getCanalAdapters()) {
|
||||
// for (CanalClientConfig.CanalAdapter canalAdapter :
|
||||
// canalClientConfig.getCanalAdapters()) {
|
||||
// for (CanalClientConfig.Group group : canalAdapter.getGroups()) {
|
||||
// List<List<OuterAdapter>> canalOuterAdapterGroups = new CopyOnWriteArrayList<>();
|
||||
// List<List<OuterAdapter>> canalOuterAdapterGroups = new
|
||||
// CopyOnWriteArrayList<>();
|
||||
// List<OuterAdapter> canalOuterAdapters = new CopyOnWriteArrayList<>();
|
||||
// for (OuterAdapterConfig config : group.getOuterAdapters()) {
|
||||
// loadAdapter(config, canalOuterAdapters);
|
||||
// }
|
||||
// canalOuterAdapterGroups.add(canalOuterAdapters);
|
||||
// CanalAdapterRocketMQWorker rocketMQWorker = new CanalAdapterRocketMQWorker(canalClientConfig,
|
||||
// CanalAdapterRocketMQWorker rocketMQWorker = new
|
||||
// CanalAdapterRocketMQWorker(canalClientConfig,
|
||||
// canalClientConfig.getMqServers(),
|
||||
// canalAdapter.getInstance(),
|
||||
// group.getGroupId(),
|
||||
@@ -146,29 +159,35 @@ public class CanalAdapterLoader {
|
||||
// canalClientConfig.getCustomizedTraceTopic(),
|
||||
// canalClientConfig.getAccessChannel(),
|
||||
// canalClientConfig.getNamespace());
|
||||
// canalMQWorker.put(canalAdapter.getInstance() + "-rocketmq-" + group.getGroupId(), rocketMQWorker);
|
||||
// canalMQWorker.put(canalAdapter.getInstance() + "-rocketmq-" +
|
||||
// group.getGroupId(), rocketMQWorker);
|
||||
// rocketMQWorker.start();
|
||||
//
|
||||
// logger.info("Start adapter for canal-client mq topic: {} succeed",
|
||||
// canalAdapter.getInstance() + "-" + group.getGroupId());
|
||||
// }
|
||||
// }
|
||||
// } else if ("rabbitMQ".equalsIgnoreCase(canalClientConfig.getMode())) {
|
||||
// } else if ("rabbitMQ".equalsIgnoreCase(canalClientConfig.getMode()))
|
||||
// {
|
||||
// // 初始化canal-client-rabbitMQ的适配器
|
||||
// for (CanalClientConfig.CanalAdapter canalAdapter : canalClientConfig.getCanalAdapters()) {
|
||||
// for (CanalClientConfig.CanalAdapter canalAdapter :
|
||||
// canalClientConfig.getCanalAdapters()) {
|
||||
// for (CanalClientConfig.Group group : canalAdapter.getGroups()) {
|
||||
// List<List<OuterAdapter>> canalOuterAdapterGroups = new CopyOnWriteArrayList<>();
|
||||
// List<List<OuterAdapter>> canalOuterAdapterGroups = new
|
||||
// CopyOnWriteArrayList<>();
|
||||
// List<OuterAdapter> canalOuterAdapters = new CopyOnWriteArrayList<>();
|
||||
// for (OuterAdapterConfig config : group.getOuterAdapters()) {
|
||||
// loadAdapter(config, canalOuterAdapters);
|
||||
// }
|
||||
// canalOuterAdapterGroups.add(canalOuterAdapters);
|
||||
// CanalAdapterRabbitMQWorker rabbitMQWork = new CanalAdapterRabbitMQWorker(canalClientConfig,
|
||||
// CanalAdapterRabbitMQWorker rabbitMQWork = new
|
||||
// CanalAdapterRabbitMQWorker(canalClientConfig,
|
||||
// canalOuterAdapterGroups,
|
||||
// canalAdapter.getInstance(),
|
||||
// group.getGroupId(),
|
||||
// canalClientConfig.getFlatMessage());
|
||||
// canalMQWorker.put(canalAdapter.getInstance() + "-rabbitmq-" + group.getGroupId(), rabbitMQWork);
|
||||
// canalMQWorker.put(canalAdapter.getInstance() + "-rabbitmq-" +
|
||||
// group.getGroupId(), rabbitMQWork);
|
||||
// rabbitMQWork.start();
|
||||
//
|
||||
// logger.info("Start adapter for canal-client mq topic: {} succeed",
|
||||
|
||||
@@ -15,14 +15,14 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.alibaba.otter.canal.common.utils.CommonUtils;
|
||||
import com.alibaba.otter.canal.common.utils.NamedThreadFactory;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.otter.canal.adapter.launcher.config.AdapterConfigHolder;
|
||||
import com.alibaba.otter.canal.common.utils.CommonUtils;
|
||||
import com.alibaba.otter.canal.common.utils.NamedThreadFactory;
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,10 +5,11 @@ import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import com.alibaba.otter.canal.common.utils.CommonUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.otter.canal.common.utils.CommonUtils;
|
||||
|
||||
/**
|
||||
* 远程配置监听器实现
|
||||
*
|
||||
|
||||
@@ -3,9 +3,10 @@ package com.alibaba.otter.canal.client.adapter.rdb.config;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.support.AdapterConfig;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.support.AdapterConfig;
|
||||
|
||||
/**
|
||||
* RDB表映射配置
|
||||
*
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.alibaba.otter.canal.client.adapter.rdb.service;
|
||||
|
||||
import java.sql.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -4,9 +4,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.support.Dml;
|
||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.support.Dml;
|
||||
|
||||
public class SingleDml {
|
||||
|
||||
private String destination;
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
@Ignore
|
||||
public class DBTest {
|
||||
|
||||
@@ -39,8 +40,7 @@ public class DBTest {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("insert into user (id,name,role_id,c_time,test1,test2) values (?,?,?,?,?,?)");
|
||||
PreparedStatement pstmt = conn.prepareStatement("insert into user (id,name,role_id,c_time,test1,test2) values (?,?,?,?,?,?)");
|
||||
|
||||
java.util.Date now = new java.util.Date();
|
||||
for (int i = 1; i <= 10000; i++) {
|
||||
@@ -67,14 +67,16 @@ public class DBTest {
|
||||
// ResultSetMetaData rsm = rs.getMetaData();
|
||||
// int cnt = rsm.getColumnCount();
|
||||
// for (int i = 1; i <= cnt; i++) {
|
||||
// System.out.println(rsm.getColumnName(i) + " " + rsm.getColumnType(i));
|
||||
// System.out.println(rsm.getColumnName(i) + " " +
|
||||
// rsm.getColumnType(i));
|
||||
// }
|
||||
|
||||
// rs.close();
|
||||
// stmt.close();
|
||||
|
||||
// PreparedStatement pstmt = conn
|
||||
// .prepareStatement("insert into tb_user (id,name,role_id,c_time,test1,test2)
|
||||
// .prepareStatement("insert into tb_user
|
||||
// (id,name,role_id,c_time,test1,test2)
|
||||
// values (?,?,?,?,?,?)");
|
||||
// pstmt.setBigDecimal(1, new BigDecimal("5"));
|
||||
// pstmt.setString(2, "test");
|
||||
@@ -91,6 +93,7 @@ public class DBTest {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String clob2Str(Clob clob) {
|
||||
String content = "";
|
||||
try (Reader is = clob.getCharacterStream(); BufferedReader buff = new BufferedReader(is)) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.alibaba.otter.canal.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.alibaba.otter.canal.protocol.Message;
|
||||
|
||||
@@ -12,21 +12,18 @@ public class CommonMessage implements Serializable {
|
||||
private String table; // 表名
|
||||
private List<String> pkNames;
|
||||
private Boolean isDdl;
|
||||
private String type; // 类型:
|
||||
// INSERT
|
||||
// UPDATE
|
||||
// DELETE
|
||||
// binlog executeTime
|
||||
private Long es; // 执行耗时
|
||||
// dml build timeStamp
|
||||
private Long ts; // 同步时间
|
||||
private String sql; // 执行的sql,
|
||||
// dml
|
||||
// sql为空
|
||||
private List<Map<String, Object>> data; // 数据列表
|
||||
private List<Map<String, Object>> old; // 旧数据列表,
|
||||
// 用于update,
|
||||
// size和data的size一一对应
|
||||
// 类型:INSERT/UPDATE/DELETE
|
||||
private String type;
|
||||
// binlog executeTime, 执行耗时
|
||||
private Long es;
|
||||
// dml build timeStamp, 同步时间
|
||||
private Long ts;
|
||||
// 执行的sql,dml sql为空
|
||||
private String sql;
|
||||
// 数据列表
|
||||
private List<Map<String, Object>> data;
|
||||
// 旧数据列表,用于update,size和data的size一一对应
|
||||
private List<Map<String, Object>> old;
|
||||
|
||||
public String getDatabase() {
|
||||
return database;
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.google.common.collect.MigrateMap;
|
||||
|
||||
public class PatternUtils {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Map<String, Pattern> patterns = MigrateMap.makeComputingMap(CacheBuilder.newBuilder().softValues(),
|
||||
pattern -> {
|
||||
try {
|
||||
|
||||
@@ -34,7 +34,6 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
||||
*/
|
||||
public class MQMessageUtils {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Map<String, List<PartitionData>> partitionDatas = MigrateMap.makeComputingMap(CacheBuilder.newBuilder()
|
||||
.softValues(),
|
||||
pkHashConfigs -> {
|
||||
@@ -74,7 +73,6 @@ public class MQMessageUtils {
|
||||
return datas;
|
||||
});
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Map<String, List<DynamicTopicData>> dynamicTopicDatas = MigrateMap.makeComputingMap(CacheBuilder.newBuilder()
|
||||
.softValues(),
|
||||
new Function<String, List<DynamicTopicData>>() {
|
||||
|
||||
@@ -409,7 +409,6 @@ public class ExtensionLoader<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static ClassLoader findClassLoader() {
|
||||
return ExtensionLoader.class.getClassLoader();
|
||||
}
|
||||
|
||||
@@ -27,12 +27,8 @@ import com.alibaba.otter.canal.protocol.Message;
|
||||
@SPI("tcp")
|
||||
public class CanalTCPConsumer implements CanalMsgConsumer {
|
||||
|
||||
private static final String PREFIX_TCP_CONFIG = "canal.tcp.";
|
||||
|
||||
private Long currentBatchId = null;
|
||||
|
||||
private CanalConnector canalConnector;
|
||||
|
||||
private int batchSize = 500;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package com.taobao.tddl.dbsync.binlog;
|
||||
|
||||
import com.taobao.tddl.dbsync.binlog.JsonConversion.Json_Value;
|
||||
import com.taobao.tddl.dbsync.binlog.JsonConversion.Json_enum_type;
|
||||
import com.taobao.tddl.dbsync.binlog.JsonConversion;
|
||||
import com.taobao.tddl.dbsync.binlog.LogBuffer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.Timeout;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import com.taobao.tddl.dbsync.binlog.JsonConversion.Json_Value;
|
||||
import com.taobao.tddl.dbsync.binlog.JsonConversion.Json_enum_type;
|
||||
|
||||
public class JsonConversion_Json_ValueTest {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule public final Timeout globalTimeout = new Timeout(10000);
|
||||
@SuppressWarnings("deprecation")
|
||||
@Rule
|
||||
public final Timeout globalTimeout = new Timeout(10000);
|
||||
|
||||
/* testedClasses: JsonConversion_Json_Value */
|
||||
// Test written by Diffblue Cover.
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package com.taobao.tddl.dbsync.binlog;
|
||||
|
||||
import com.taobao.tddl.dbsync.binlog.JsonDiffConversion;
|
||||
import com.taobao.tddl.dbsync.binlog.LogBuffer;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.Timeout;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class JsonDiffConversionTest {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule public final Timeout globalTimeout = new Timeout(10000);
|
||||
@SuppressWarnings("deprecation")
|
||||
@Rule
|
||||
public final Timeout globalTimeout = new Timeout(10000);
|
||||
|
||||
/* testedClasses: JsonDiffConversion */
|
||||
// Test written by Diffblue Cover.
|
||||
@@ -27,11 +27,10 @@ public class JsonDiffConversionTest {
|
||||
final LogBuffer buffer = new LogBuffer();
|
||||
buffer.position = 28;
|
||||
buffer.semival = 0;
|
||||
final byte[] myByteArray = {(byte)3, (byte)3, (byte)67, (byte)67, (byte)67, (byte)67,
|
||||
(byte)67, (byte)66, (byte)67, (byte)66, (byte)67, (byte)66,
|
||||
(byte)67, (byte)67, (byte)67, (byte)66, (byte)67, (byte)66,
|
||||
(byte)67, (byte)66, (byte)67, (byte)67, (byte)67, (byte)66,
|
||||
(byte)67, (byte)67, (byte)67, (byte)66, (byte)2, (byte)66};
|
||||
final byte[] myByteArray = { (byte) 3, (byte) 3, (byte) 67, (byte) 67, (byte) 67, (byte) 67, (byte) 67,
|
||||
(byte) 66, (byte) 67, (byte) 66, (byte) 67, (byte) 66, (byte) 67, (byte) 67, (byte) 67, (byte) 66,
|
||||
(byte) 67, (byte) 66, (byte) 67, (byte) 66, (byte) 67, (byte) 67, (byte) 67, (byte) 66, (byte) 67,
|
||||
(byte) 67, (byte) 67, (byte) 66, (byte) 2, (byte) 66 };
|
||||
buffer.buffer = myByteArray;
|
||||
buffer.limit = -1_000_000_065;
|
||||
buffer.origin = 1_000_000_096;
|
||||
@@ -50,13 +49,10 @@ public class JsonDiffConversionTest {
|
||||
Assert.assertNotNull(buffer);
|
||||
Assert.assertEquals(30, buffer.position);
|
||||
Assert.assertEquals(0, buffer.semival);
|
||||
Assert.assertArrayEquals(new byte[] {(byte)3, (byte)3, (byte)67, (byte)67, (byte)67,
|
||||
(byte)67, (byte)67, (byte)66, (byte)67, (byte)66,
|
||||
(byte)67, (byte)66, (byte)67, (byte)67, (byte)67,
|
||||
(byte)66, (byte)67, (byte)66, (byte)67, (byte)66,
|
||||
(byte)67, (byte)67, (byte)67, (byte)66, (byte)67,
|
||||
(byte)67, (byte)67, (byte)66, (byte)2, (byte)66},
|
||||
buffer.buffer);
|
||||
Assert.assertArrayEquals(new byte[] { (byte) 3, (byte) 3, (byte) 67, (byte) 67, (byte) 67, (byte) 67,
|
||||
(byte) 67, (byte) 66, (byte) 67, (byte) 66, (byte) 67, (byte) 66, (byte) 67, (byte) 67, (byte) 67,
|
||||
(byte) 66, (byte) 67, (byte) 66, (byte) 67, (byte) 66, (byte) 67, (byte) 67, (byte) 67, (byte) 66,
|
||||
(byte) 67, (byte) 67, (byte) 67, (byte) 66, (byte) 2, (byte) 66 }, buffer.buffer);
|
||||
Assert.assertEquals(-1_000_000_065, buffer.limit);
|
||||
Assert.assertEquals(1_000_000_096, buffer.origin);
|
||||
throw ex;
|
||||
@@ -72,10 +68,10 @@ public class JsonDiffConversionTest {
|
||||
final LogBuffer buffer = new LogBuffer();
|
||||
buffer.position = 28;
|
||||
buffer.semival = 0;
|
||||
final byte[] myByteArray = {
|
||||
final byte[] myByteArray = { (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2,
|
||||
(byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2,
|
||||
(byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2,
|
||||
(byte)2, (byte)2, (byte)2, (byte)2, (byte)2, (byte)2, (byte)2, (byte)2, (byte)3, (byte)2};
|
||||
(byte) 3, (byte) 2 };
|
||||
buffer.buffer = myByteArray;
|
||||
buffer.limit = 31;
|
||||
buffer.origin = 0;
|
||||
@@ -94,12 +90,10 @@ public class JsonDiffConversionTest {
|
||||
Assert.assertNotNull(buffer);
|
||||
Assert.assertEquals(29, buffer.position);
|
||||
Assert.assertEquals(0, buffer.semival);
|
||||
Assert.assertArrayEquals(new byte[] {(byte)2, (byte)2, (byte)2, (byte)2, (byte)2, (byte)2,
|
||||
(byte)2, (byte)2, (byte)2, (byte)2, (byte)2, (byte)2,
|
||||
(byte)2, (byte)2, (byte)2, (byte)2, (byte)2, (byte)2,
|
||||
(byte)2, (byte)2, (byte)2, (byte)2, (byte)2, (byte)2,
|
||||
(byte)2, (byte)2, (byte)2, (byte)2, (byte)3, (byte)2},
|
||||
buffer.buffer);
|
||||
Assert.assertArrayEquals(new byte[] { (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2,
|
||||
(byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2,
|
||||
(byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2, (byte) 2,
|
||||
(byte) 2, (byte) 3, (byte) 2 }, buffer.buffer);
|
||||
Assert.assertEquals(31, buffer.limit);
|
||||
Assert.assertEquals(0, buffer.origin);
|
||||
throw ex;
|
||||
@@ -115,10 +109,10 @@ public class JsonDiffConversionTest {
|
||||
final LogBuffer buffer = new LogBuffer();
|
||||
buffer.position = 15;
|
||||
buffer.semival = 0;
|
||||
final byte[] myByteArray = {
|
||||
(byte)1, (byte)1, (byte)0, (byte)0, (byte)1, (byte)1, (byte)1, (byte)1, (byte)1, (byte)1,
|
||||
(byte)0, (byte)1, (byte)1, (byte)1, (byte)1, (byte)0, (byte)1, (byte)1, (byte)0, (byte)0,
|
||||
(byte)1, (byte)1, (byte)1, (byte)1, (byte)1, (byte)1, (byte)1, (byte)0, (byte)1, (byte)1};
|
||||
final byte[] myByteArray = { (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 1, (byte) 1, (byte) 1, (byte) 1,
|
||||
(byte) 1, (byte) 1, (byte) 0, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 0, (byte) 1, (byte) 1,
|
||||
(byte) 0, (byte) 0, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 0,
|
||||
(byte) 1, (byte) 1 };
|
||||
buffer.buffer = myByteArray;
|
||||
buffer.limit = -1_215_751_986;
|
||||
buffer.origin = 1_215_752_002;
|
||||
@@ -137,12 +131,10 @@ public class JsonDiffConversionTest {
|
||||
Assert.assertNotNull(buffer);
|
||||
Assert.assertEquals(16, buffer.position);
|
||||
Assert.assertEquals(0, buffer.semival);
|
||||
Assert.assertArrayEquals(new byte[] {(byte)1, (byte)1, (byte)0, (byte)0, (byte)1, (byte)1,
|
||||
(byte)1, (byte)1, (byte)1, (byte)1, (byte)0, (byte)1,
|
||||
(byte)1, (byte)1, (byte)1, (byte)0, (byte)1, (byte)1,
|
||||
(byte)0, (byte)0, (byte)1, (byte)1, (byte)1, (byte)1,
|
||||
(byte)1, (byte)1, (byte)1, (byte)0, (byte)1, (byte)1},
|
||||
buffer.buffer);
|
||||
Assert.assertArrayEquals(new byte[] { (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 1, (byte) 1, (byte) 1,
|
||||
(byte) 1, (byte) 1, (byte) 1, (byte) 0, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 0, (byte) 1,
|
||||
(byte) 1, (byte) 0, (byte) 0, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1,
|
||||
(byte) 0, (byte) 1, (byte) 1 }, buffer.buffer);
|
||||
Assert.assertEquals(-1_215_751_986, buffer.limit);
|
||||
Assert.assertEquals(1_215_752_002, buffer.origin);
|
||||
throw ex;
|
||||
@@ -158,10 +150,10 @@ public class JsonDiffConversionTest {
|
||||
final LogBuffer buffer = new LogBuffer();
|
||||
buffer.position = 27;
|
||||
buffer.semival = 0;
|
||||
final byte[] myByteArray = {
|
||||
final byte[] myByteArray = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
|
||||
(byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
|
||||
(byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
|
||||
(byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1, (byte)0};
|
||||
(byte) 1, (byte) 0 };
|
||||
buffer.buffer = myByteArray;
|
||||
buffer.limit = 31;
|
||||
buffer.origin = -1;
|
||||
@@ -180,12 +172,10 @@ public class JsonDiffConversionTest {
|
||||
Assert.assertNotNull(buffer);
|
||||
Assert.assertEquals(29, buffer.position);
|
||||
Assert.assertEquals(0, buffer.semival);
|
||||
Assert.assertArrayEquals(new byte[] {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0,
|
||||
(byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0,
|
||||
(byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0,
|
||||
(byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0,
|
||||
(byte)0, (byte)0, (byte)0, (byte)0, (byte)1, (byte)0},
|
||||
buffer.buffer);
|
||||
Assert.assertArrayEquals(new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
|
||||
(byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
|
||||
(byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
|
||||
(byte) 0, (byte) 1, (byte) 0 }, buffer.buffer);
|
||||
Assert.assertEquals(31, buffer.limit);
|
||||
Assert.assertEquals(-1, buffer.origin);
|
||||
throw ex;
|
||||
@@ -204,8 +194,11 @@ public class JsonDiffConversionTest {
|
||||
final String charsetName = "1a 2b 3c";
|
||||
|
||||
// Act
|
||||
final StringBuilder actual =
|
||||
JsonDiffConversion.print_json_diff(buffer, len, columnName, columnIndex, charsetName);
|
||||
final StringBuilder actual = JsonDiffConversion.print_json_diff(buffer,
|
||||
len,
|
||||
columnName,
|
||||
columnIndex,
|
||||
charsetName);
|
||||
|
||||
// Assert result
|
||||
Assert.assertNotNull(actual);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.taobao.tddl.dbsync.binlog;
|
||||
|
||||
import com.taobao.tddl.dbsync.binlog.LogEvent;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -9,9 +8,12 @@ import org.junit.rules.Timeout;
|
||||
|
||||
public class LogEventTest {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule public final Timeout globalTimeout = new Timeout(10000);
|
||||
@SuppressWarnings("deprecation")
|
||||
@Rule
|
||||
public final Timeout globalTimeout = new Timeout(10000);
|
||||
|
||||
/* testedClasses: LogEvent */
|
||||
// Test written by Diffblue Cover.
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package com.taobao.tddl.dbsync.binlog.event;
|
||||
|
||||
import com.taobao.tddl.dbsync.binlog.event.LogHeader;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.Timeout;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LogHeaderTest {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule public final Timeout globalTimeout = new Timeout(10000);
|
||||
@SuppressWarnings("deprecation")
|
||||
@Rule
|
||||
public final Timeout globalTimeout = new Timeout(10000);
|
||||
|
||||
/* testedClasses: LogHeader */
|
||||
// Test written by Diffblue Cover.
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package com.alibaba.otter.canal.parse.driver.mysql.packets.client;
|
||||
|
||||
import com.alibaba.otter.canal.parse.driver.mysql.packets.client.RegisterSlaveCommandPacket;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.Timeout;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class RegisterSlaveCommandPacketTest {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule public final Timeout globalTimeout = new Timeout(10000);
|
||||
@SuppressWarnings("deprecation")
|
||||
@Rule
|
||||
public final Timeout globalTimeout = new Timeout(10000);
|
||||
|
||||
/* testedClasses: RegisterSlaveCommandPacket */
|
||||
// Test written by Diffblue Cover.
|
||||
@@ -35,12 +36,10 @@ public class RegisterSlaveCommandPacketTest {
|
||||
final byte[] actual = objectUnderTest.toBytes();
|
||||
|
||||
// Assert result
|
||||
Assert.assertArrayEquals(
|
||||
new byte[] {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)3, (byte)102,
|
||||
(byte)111, (byte)111, (byte)3, (byte)102, (byte)111, (byte)111, (byte)3,
|
||||
(byte)102, (byte)111, (byte)111, (byte)0, (byte)0, (byte)0, (byte)0,
|
||||
(byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0},
|
||||
actual);
|
||||
Assert.assertArrayEquals(new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 3, (byte) 102,
|
||||
(byte) 111, (byte) 111, (byte) 3, (byte) 102, (byte) 111, (byte) 111, (byte) 3, (byte) 102, (byte) 111,
|
||||
(byte) 111, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
|
||||
(byte) 0 }, actual);
|
||||
}
|
||||
|
||||
// Test written by Diffblue Cover.
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.alibaba.otter.canal.client.rocketmq.RocketMQCanalConnector;
|
||||
import com.alibaba.otter.canal.example.kafka.AbstractKafkaTest;
|
||||
import com.alibaba.otter.canal.protocol.FlatMessage;
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.google.common.collect.MigrateMap;
|
||||
|
||||
public class PatternUtils {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Map<String, Pattern> patterns = MigrateMap.makeComputingMap(CacheBuilder.newBuilder().softValues(),
|
||||
new Function<String, Pattern>() {
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ public class CanalInstanceWithManager extends AbstractCanalInstance {
|
||||
super.start();
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
protected void initAlarmHandler() {
|
||||
logger.info("init alarmHandler begin...");
|
||||
String alarmHandlerClass = parameters.getAlarmHandlerClass();
|
||||
|
||||
@@ -2,13 +2,12 @@ package com.alibaba.otter.canal.instance.spring;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.otter.canal.instance.core.CanalInstance;
|
||||
import com.alibaba.otter.canal.instance.core.CanalMQConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.otter.canal.common.alarm.CanalAlarmHandler;
|
||||
import com.alibaba.otter.canal.instance.core.AbstractCanalInstance;
|
||||
import com.alibaba.otter.canal.instance.core.CanalMQConfig;
|
||||
import com.alibaba.otter.canal.meta.CanalMetaManager;
|
||||
import com.alibaba.otter.canal.parse.CanalEventParser;
|
||||
import com.alibaba.otter.canal.protocol.CanalEntry;
|
||||
|
||||
@@ -665,6 +665,14 @@ public class DatabaseTableMeta implements TableMetaTSDB {
|
||||
this.fieldBlackFilterMap = fieldBlackFilterMap;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getFieldFilterMap() {
|
||||
return fieldFilterMap;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getFieldBlackFilterMap() {
|
||||
return fieldBlackFilterMap;
|
||||
}
|
||||
|
||||
public int getSnapshotInterval() {
|
||||
return snapshotInterval;
|
||||
}
|
||||
@@ -693,8 +701,4 @@ public class DatabaseTableMeta implements TableMetaTSDB {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str = StringUtils.substringBefore("int(11)", "(");
|
||||
System.out.println(str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
package com.alibaba.otter.canal.prometheus.impl;
|
||||
|
||||
import com.alibaba.otter.canal.instance.core.CanalInstance;
|
||||
import com.alibaba.otter.canal.prometheus.InstanceRegistry;
|
||||
import com.alibaba.otter.canal.sink.CanalEventSink;
|
||||
import com.alibaba.otter.canal.sink.entry.EntryEventSink;
|
||||
import com.google.common.base.Preconditions;
|
||||
import static com.alibaba.otter.canal.prometheus.CanalInstanceExports.DEST_LABELS_LIST;
|
||||
import io.prometheus.client.Collector;
|
||||
import io.prometheus.client.CounterMetricFamily;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -17,8 +11,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static com.alibaba.otter.canal.prometheus.CanalInstanceExports.DEST_LABELS_LIST;
|
||||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.otter.canal.instance.core.CanalInstance;
|
||||
import com.alibaba.otter.canal.prometheus.InstanceRegistry;
|
||||
import com.alibaba.otter.canal.sink.CanalEventSink;
|
||||
import com.alibaba.otter.canal.sink.entry.EntryEventSink;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* @author Chuanyi Li
|
||||
@@ -31,9 +31,11 @@ public class SinkCollector extends Collector implements InstanceRegistry {
|
||||
private static final String SINK_BLOCK_TIME_HELP = "Total sink blocking time in milliseconds";
|
||||
private final ConcurrentMap<String, SinkMetricsHolder> instances = new ConcurrentHashMap<String, SinkMetricsHolder>();
|
||||
|
||||
private SinkCollector() {}
|
||||
private SinkCollector(){
|
||||
}
|
||||
|
||||
private static class SingletonHolder {
|
||||
|
||||
private static final SinkCollector SINGLETON = new SinkCollector();
|
||||
}
|
||||
|
||||
@@ -45,7 +47,8 @@ public class SinkCollector extends Collector implements InstanceRegistry {
|
||||
public List<MetricFamilySamples> collect() {
|
||||
List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
|
||||
CounterMetricFamily blockingCounter = new CounterMetricFamily(SINK_BLOCKING_TIME,
|
||||
SINK_BLOCK_TIME_HELP, DEST_LABELS_LIST);
|
||||
SINK_BLOCK_TIME_HELP,
|
||||
DEST_LABELS_LIST);
|
||||
for (SinkMetricsHolder smh : instances.values()) {
|
||||
blockingCounter.addMetric(smh.destLabelValues, (smh.eventsSinkBlockingTime.doubleValue() / NANO_PER_MILLI));
|
||||
}
|
||||
@@ -78,6 +81,7 @@ public class SinkCollector extends Collector implements InstanceRegistry {
|
||||
}
|
||||
|
||||
private class SinkMetricsHolder {
|
||||
|
||||
private AtomicLong eventsSinkBlockingTime;
|
||||
private List<String> destLabelValues;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user