|
@@ -1,12 +1,22 @@
|
|
|
-package org.dbsyncer.parser.flush;
|
|
|
+/**
|
|
|
+ * DBSyncer Copyright 2020-2023 All Rights Reserved.
|
|
|
+ */
|
|
|
+package org.dbsyncer.parser.flush.impl;
|
|
|
|
|
|
-import org.dbsyncer.common.config.StorageConfig;
|
|
|
import org.dbsyncer.common.model.Result;
|
|
|
import org.dbsyncer.common.util.CollectionUtils;
|
|
|
import org.dbsyncer.common.util.StringUtil;
|
|
|
import org.dbsyncer.parser.CacheService;
|
|
|
+import org.dbsyncer.parser.LogService;
|
|
|
+import org.dbsyncer.parser.LogType;
|
|
|
+import org.dbsyncer.parser.ProfileComponent;
|
|
|
+import org.dbsyncer.parser.flush.FlushService;
|
|
|
import org.dbsyncer.parser.model.Meta;
|
|
|
+import org.dbsyncer.parser.model.SystemConfig;
|
|
|
import org.dbsyncer.parser.strategy.FlushStrategy;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -17,7 +27,10 @@ import java.time.Instant;
|
|
|
* @version 1.0.0
|
|
|
* @date 2021/11/18 22:22
|
|
|
*/
|
|
|
-public abstract class AbstractFlushStrategy implements FlushStrategy {
|
|
|
+@Component
|
|
|
+public final class FlushStrategyImpl implements FlushStrategy {
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
@Resource
|
|
|
private FlushService flushService;
|
|
@@ -26,10 +39,26 @@ public abstract class AbstractFlushStrategy implements FlushStrategy {
|
|
|
private CacheService cacheService;
|
|
|
|
|
|
@Resource
|
|
|
- private StorageConfig storageConfig;
|
|
|
+ private ProfileComponent profileComponent;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private LogService logService;
|
|
|
|
|
|
@Override
|
|
|
public void flushFullData(String metaId, Result result, String event) {
|
|
|
+ // 不记录全量数据, 只记录增量同步数据, 将异常记录到系统日志中
|
|
|
+ if (!getSystemConfig().isEnableStorageWriteFull()) {
|
|
|
+ // 不记录全量数据,只统计成功失败总数
|
|
|
+ refreshTotal(metaId, result);
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(result.getFailData())) {
|
|
|
+ logger.error(result.getError().toString());
|
|
|
+ LogType logType = LogType.TableGroupLog.FULL_FAILED;
|
|
|
+ logService.log(logType, "%s:%s:%s", result.getTargetTableGroupName(), logType.getMessage(), result.getError().toString());
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
flush(metaId, result, event);
|
|
|
}
|
|
|
|
|
@@ -52,15 +81,24 @@ public abstract class AbstractFlushStrategy implements FlushStrategy {
|
|
|
refreshTotal(metaId, result);
|
|
|
|
|
|
// 是否写失败数据
|
|
|
- if (storageConfig.isWriteFail() && !CollectionUtils.isEmpty(result.getFailData())) {
|
|
|
- final String error = StringUtil.substring(result.getError().toString(), 0, storageConfig.getMaxErrorLength());
|
|
|
+ if (getSystemConfig().isEnableStorageWriteFail() && !CollectionUtils.isEmpty(result.getFailData())) {
|
|
|
+ final String error = StringUtil.substring(result.getError().toString(), 0, getSystemConfig().getMaxStorageErrorLength());
|
|
|
flushService.asyncWrite(metaId, result.getTableGroupId(), result.getTargetTableGroupName(), event, false, result.getFailData(), error);
|
|
|
}
|
|
|
|
|
|
// 是否写成功数据
|
|
|
- if (storageConfig.isWriteSuccess() && !CollectionUtils.isEmpty(result.getSuccessData())) {
|
|
|
+ if (getSystemConfig().isEnableStorageWriteSuccess() && !CollectionUtils.isEmpty(result.getSuccessData())) {
|
|
|
flushService.asyncWrite(metaId, result.getTableGroupId(), result.getTargetTableGroupName(), event, true, result.getSuccessData(), "");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * TODO 加缓存过期
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private SystemConfig getSystemConfig() {
|
|
|
+ return profileComponent.getSystemConfig();
|
|
|
+ }
|
|
|
+
|
|
|
}
|