feat: 新增冷热数据访问分离逻辑
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
package com.central.file.config;
|
||||
|
||||
import com.central.file.service.HotDataSyncService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
/**
|
||||
* 同步定时任务配置
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class SyncScheduleConfig {
|
||||
|
||||
@Autowired
|
||||
private HotDataSyncService hotDataSyncService;
|
||||
|
||||
@Value("${zlt.storage.sync.schedule.enabled:true}")
|
||||
private boolean scheduleEnabled;
|
||||
|
||||
/**
|
||||
* 每天凌晨2点执行热数据同步
|
||||
*/
|
||||
@Scheduled(cron = "${zlt.storage.sync.cron:0 0 2 * * ?}")
|
||||
public void dailyHotDataSync() {
|
||||
if (!scheduleEnabled) {
|
||||
log.debug("定时同步任务已禁用");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
log.info("开始执行每日热数据同步任务");
|
||||
hotDataSyncService.triggerManualSync();
|
||||
} catch (Exception e) {
|
||||
log.error("每日热数据同步任务执行失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 每小时检查一次热数据状态
|
||||
*/
|
||||
@Scheduled(cron = "${zlt.storage.sync.status-check.cron:0 0 * * * ?}")
|
||||
public void checkSyncStatus() {
|
||||
if (!scheduleEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String statistics = hotDataSyncService.getSyncStatistics();
|
||||
log.info("同步状态检查: {}", statistics);
|
||||
} catch (Exception e) {
|
||||
log.error("同步状态检查失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
package com.central.file.controller;
|
||||
|
||||
import com.central.file.service.HotDataSyncService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 热数据同步控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sync")
|
||||
@Tag(name = "热数据同步管理", description = "热数据自动同步到S3相关接口")
|
||||
public class HotDataSyncController {
|
||||
|
||||
@Autowired
|
||||
private HotDataSyncService hotDataSyncService;
|
||||
|
||||
/**
|
||||
* 手动触发热数据同步
|
||||
*/
|
||||
@PostMapping("/trigger")
|
||||
@Operation(summary = "手动触发热数据同步", description = "立即执行一次热数据同步任务")
|
||||
public Map<String, Object> triggerSync() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
hotDataSyncService.triggerManualSync();
|
||||
result.put("success", true);
|
||||
result.put("message", "热数据同步任务已触发");
|
||||
result.put("timestamp", System.currentTimeMillis());
|
||||
log.info("手动触发热数据同步成功");
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "触发同步失败: " + e.getMessage());
|
||||
log.error("手动触发热数据同步失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取同步状态
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
@Operation(summary = "获取同步状态", description = "获取热数据同步服务的运行状态和统计信息")
|
||||
public Map<String, Object> getSyncStatus() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
String statistics = hotDataSyncService.getSyncStatistics();
|
||||
boolean isRunning = hotDataSyncService.isRunning();
|
||||
String configInfo = hotDataSyncService.getConfigInfo();
|
||||
|
||||
result.put("success", true);
|
||||
result.put("running", isRunning);
|
||||
result.put("statistics", statistics);
|
||||
result.put("config", configInfo);
|
||||
result.put("timestamp", System.currentTimeMillis());
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取状态失败: " + e.getMessage());
|
||||
log.error("获取同步状态失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步指定文件
|
||||
*/
|
||||
@PostMapping("/file/{fileId}")
|
||||
@Operation(summary = "同步指定文件", description = "将指定的文件同步到S3存储")
|
||||
public Map<String, Object> syncFile(@PathVariable String fileId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
boolean success = hotDataSyncService.syncSpecificFile(fileId);
|
||||
|
||||
result.put("success", success);
|
||||
result.put("fileId", fileId);
|
||||
result.put("message", success ? "文件同步成功" : "文件同步失败");
|
||||
result.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
log.info("文件同步任务完成,文件ID: {}, 结果: {}", fileId, success);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("fileId", fileId);
|
||||
result.put("message", "文件同步失败: " + e.getMessage());
|
||||
log.error("文件同步失败,文件ID: {}", fileId, e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量同步文件
|
||||
*/
|
||||
@PostMapping("/batch")
|
||||
@Operation(summary = "批量同步文件", description = "批量同步多个文件到S3存储")
|
||||
public Map<String, Object> batchSyncFiles(@RequestBody Map<String, Object> request) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> fileIds = (List<String>) request.get("fileIds");
|
||||
|
||||
if (fileIds == null || fileIds.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "文件ID列表不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
int successCount = hotDataSyncService.batchSyncFiles(fileIds);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("totalFiles", fileIds.size());
|
||||
result.put("successCount", successCount);
|
||||
result.put("failedCount", fileIds.size() - successCount);
|
||||
result.put("message", String.format("批量同步完成,成功: %d, 失败: %d", successCount, fileIds.size() - successCount));
|
||||
result.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
log.info("批量同步任务完成,总数: {}, 成功: {}", fileIds.size(), successCount);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "批量同步失败: " + e.getMessage());
|
||||
log.error("批量同步失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取同步配置信息
|
||||
*/
|
||||
@GetMapping("/config")
|
||||
@Operation(summary = "获取同步配置", description = "获取当前热数据同步的配置信息")
|
||||
public Map<String, Object> getSyncConfig() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
String configInfo = hotDataSyncService.getConfigInfo();
|
||||
boolean isRunning = hotDataSyncService.isRunning();
|
||||
|
||||
result.put("success", true);
|
||||
result.put("running", isRunning);
|
||||
result.put("config", configInfo);
|
||||
result.put("timestamp", System.currentTimeMillis());
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取配置失败: " + e.getMessage());
|
||||
log.error("获取同步配置失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 健康检查
|
||||
*/
|
||||
@GetMapping("/health")
|
||||
@Operation(summary = "同步服务健康检查", description = "检查同步服务的健康状态")
|
||||
public Map<String, Object> healthCheck() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
boolean isRunning = hotDataSyncService.isRunning();
|
||||
String statistics = hotDataSyncService.getSyncStatistics();
|
||||
|
||||
result.put("status", isRunning ? "UP" : "DOWN");
|
||||
result.put("service", "HotDataSyncService");
|
||||
result.put("running", isRunning);
|
||||
result.put("statistics", statistics);
|
||||
result.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
if (isRunning) {
|
||||
result.put("message", "同步服务运行正常");
|
||||
} else {
|
||||
result.put("message", "同步服务未运行");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("status", "DOWN");
|
||||
result.put("error", e.getMessage());
|
||||
result.put("message", "健康检查失败");
|
||||
log.error("同步服务健康检查失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package com.central.file.controller;
|
||||
|
||||
import com.central.file.service.HotDataSyncService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 同步功能测试控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sync-test")
|
||||
@Tag(name = "同步功能测试", description = "用于测试热数据同步功能")
|
||||
public class SyncTestController {
|
||||
|
||||
@Autowired
|
||||
private HotDataSyncService hotDataSyncService;
|
||||
|
||||
/**
|
||||
* 测试同步服务状态
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
@Operation(summary = "测试同步服务状态", description = "检查热数据同步服务是否正常运行")
|
||||
public Map<String, Object> testSyncStatus() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
boolean isRunning = hotDataSyncService.isRunning();
|
||||
String statistics = hotDataSyncService.getSyncStatistics();
|
||||
|
||||
result.put("success", true);
|
||||
result.put("serviceRunning", isRunning);
|
||||
result.put("statistics", statistics);
|
||||
result.put("message", "同步服务状态检查完成");
|
||||
|
||||
log.info("同步服务状态检查: 运行状态={}, 统计信息={}", isRunning, statistics);
|
||||
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "状态检查失败: " + e.getMessage());
|
||||
log.error("同步服务状态检查失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试手动触发同步
|
||||
*/
|
||||
@PostMapping("/trigger")
|
||||
@Operation(summary = "测试手动触发同步", description = "手动触发一次热数据同步任务")
|
||||
public Map<String, Object> testManualSync() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
hotDataSyncService.triggerManualSync();
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "手动同步任务已触发");
|
||||
result.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
log.info("手动同步任务触发成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "触发同步失败: " + e.getMessage());
|
||||
log.error("手动同步任务触发失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试同步配置
|
||||
*/
|
||||
@GetMapping("/config")
|
||||
@Operation(summary = "查看同步配置", description = "查看当前热数据同步的配置信息")
|
||||
public Map<String, Object> getSyncConfig() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
Map<String, Object> config = new HashMap<>();
|
||||
config.put("serviceEnabled", hotDataSyncService.isRunning());
|
||||
config.put("statistics", hotDataSyncService.getSyncStatistics());
|
||||
|
||||
result.put("success", true);
|
||||
result.put("config", config);
|
||||
result.put("message", "配置信息获取成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取配置失败: " + e.getMessage());
|
||||
log.error("获取同步配置失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 健康检查
|
||||
*/
|
||||
@GetMapping("/health")
|
||||
@Operation(summary = "同步服务健康检查", description = "检查同步服务的健康状态")
|
||||
public Map<String, Object> healthCheck() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
boolean isRunning = hotDataSyncService.isRunning();
|
||||
|
||||
result.put("status", isRunning ? "UP" : "DOWN");
|
||||
result.put("service", "HotDataSyncService");
|
||||
result.put("running", isRunning);
|
||||
result.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
if (isRunning) {
|
||||
result.put("message", "同步服务运行正常");
|
||||
} else {
|
||||
result.put("message", "同步服务未运行");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
result.put("status", "DOWN");
|
||||
result.put("error", e.getMessage());
|
||||
result.put("message", "健康检查失败");
|
||||
log.error("同步服务健康检查失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,50 @@
|
||||
package com.central.file.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.FileInfo;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 上传存储db
|
||||
* 文件mapper
|
||||
*
|
||||
* @author zlt
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
*/
|
||||
@Mapper
|
||||
public interface FileMapper extends SuperMapper<FileInfo> {
|
||||
List<FileInfo> findList(Page<FileInfo> page, @Param("f") Map<String, Object> params);
|
||||
public interface FileMapper extends BaseMapper<FileInfo> {
|
||||
List<FileInfo> findList(Page<FileInfo> page, @Param("params") Map<String, Object> params);
|
||||
|
||||
FileInfo findById(@Param("id") String id);
|
||||
/**
|
||||
* 查询热数据文件列表
|
||||
* 根据时间窗口和存储类型查询需要同步的文件
|
||||
*
|
||||
* @param hotDataThreshold 热数据时间阈值
|
||||
* @param limit 限制查询数量
|
||||
* @return 热数据文件列表
|
||||
*/
|
||||
List<FileInfo> selectHotDataFiles(@Param("hotDataThreshold") LocalDateTime hotDataThreshold,
|
||||
@Param("limit") int limit);
|
||||
|
||||
/**
|
||||
* 根据存储类型查询文件
|
||||
*
|
||||
* @param storageType 存储类型
|
||||
* @param limit 限制查询数量
|
||||
* @return 文件列表
|
||||
*/
|
||||
List<FileInfo> selectFilesByStorageType(@Param("storageType") String storageType,
|
||||
@Param("limit") int limit);
|
||||
|
||||
/**
|
||||
* 查询需要同步的文件(不在S3中的OSS文件)
|
||||
*
|
||||
* @param limit 限制查询数量
|
||||
* @return 需要同步的文件列表
|
||||
*/
|
||||
List<FileInfo> selectFilesNeedSync(@Param("limit") int limit);
|
||||
}
|
||||
|
||||
+488
@@ -0,0 +1,488 @@
|
||||
package com.central.file.service;
|
||||
|
||||
import com.central.common.model.FileInfo;
|
||||
import com.central.file.mapper.FileMapper;
|
||||
import com.central.file.service.impl.OssService;
|
||||
import com.central.file.service.impl.S3Service;
|
||||
import com.central.file.service.impl.EnhancedS3Service;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 热数据自动同步服务
|
||||
* 负责将热数据自动同步到S3存储
|
||||
*
|
||||
* @author system
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class HotDataSyncService {
|
||||
|
||||
@Autowired
|
||||
private FileMapper fileMapper;
|
||||
|
||||
@Autowired
|
||||
private OssService ossService;
|
||||
|
||||
@Autowired(required = false)
|
||||
@Qualifier("s3FileService")
|
||||
private S3Service s3Service;
|
||||
|
||||
@Autowired(required = false)
|
||||
@Qualifier("enhancedS3FileService")
|
||||
private EnhancedS3Service enhancedS3Service;
|
||||
|
||||
@Autowired
|
||||
private FileMigrationService fileMigrationService;
|
||||
|
||||
// 配置参数
|
||||
@Value("${zlt.storage.hot-sync.enabled:true}")
|
||||
private boolean syncEnabled;
|
||||
|
||||
@Value("${zlt.storage.hot-sync.batch-size:100}")
|
||||
private int batchSize;
|
||||
|
||||
@Value("${zlt.storage.hot-sync.interval-minutes:30}")
|
||||
private int syncIntervalMinutes;
|
||||
|
||||
@Value("${zlt.storage.hot-sync.access-threshold:10}")
|
||||
private int accessThreshold; // 访问次数阈值,超过此值认为是热数据
|
||||
|
||||
@Value("${zlt.storage.hot-sync.max-threads:5}")
|
||||
private int maxThreads;
|
||||
|
||||
@Value("${zlt.storage.hot-sync.hot-data-days:7}")
|
||||
private int hotDataDays; // 热数据天数阈值
|
||||
|
||||
// 线程池
|
||||
private ExecutorService syncExecutor;
|
||||
private ScheduledExecutorService scheduledExecutor;
|
||||
private volatile boolean running = false;
|
||||
|
||||
// 统计信息
|
||||
private final AtomicInteger totalSyncedFiles = new AtomicInteger(0);
|
||||
private final AtomicInteger totalFailedFiles = new AtomicInteger(0);
|
||||
private volatile LocalDateTime lastSyncTime;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
if (!syncEnabled || (s3Service == null && enhancedS3Service == null)) {
|
||||
log.info("热数据同步服务未启用或S3Service未配置");
|
||||
return;
|
||||
}
|
||||
|
||||
syncExecutor = new ThreadPoolExecutor(2, maxThreads, 60L, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
scheduledExecutor = Executors.newScheduledThreadPool(1);
|
||||
startScheduledSync();
|
||||
log.info("热数据同步服务初始化完成,配置: 批次大小={}, 同步间隔={}分钟, 访问阈值={}, 热数据天数={}",
|
||||
batchSize, syncIntervalMinutes, accessThreshold, hotDataDays);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
running = false;
|
||||
if (scheduledExecutor != null) {
|
||||
scheduledExecutor.shutdown();
|
||||
}
|
||||
if (syncExecutor != null) {
|
||||
syncExecutor.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动定时同步任务
|
||||
*/
|
||||
private void startScheduledSync() {
|
||||
running = true;
|
||||
scheduledExecutor.scheduleAtFixedRate(this::performScheduledSync, 0,
|
||||
syncIntervalMinutes, TimeUnit.MINUTES);
|
||||
log.info("定时同步任务已启动,间隔: {}分钟", syncIntervalMinutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行定时同步
|
||||
*/
|
||||
private void performScheduledSync() {
|
||||
if (!running || !syncEnabled) return;
|
||||
|
||||
try {
|
||||
log.info("开始执行定时热数据同步");
|
||||
lastSyncTime = LocalDateTime.now();
|
||||
List<FileInfo> hotFiles = getHotDataFiles();
|
||||
|
||||
if (hotFiles.isEmpty()) {
|
||||
log.info("没有找到需要同步的热数据文件");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("找到{}个热数据文件需要同步", hotFiles.size());
|
||||
|
||||
// 分批处理
|
||||
for (int i = 0; i < hotFiles.size(); i += batchSize) {
|
||||
int endIndex = Math.min(i + batchSize, hotFiles.size());
|
||||
List<FileInfo> batch = hotFiles.subList(i, endIndex);
|
||||
syncExecutor.submit(() -> processBatch(batch));
|
||||
log.debug("已提交批次处理,进度: {}/{}", endIndex, hotFiles.size());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("定时同步任务执行失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理文件批次
|
||||
*/
|
||||
@Async
|
||||
public void processBatch(List<FileInfo> files) {
|
||||
if (files == null || files.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("开始处理批次,文件数量: {}", files.size());
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
|
||||
for (FileInfo file : files) {
|
||||
try {
|
||||
if (syncFileToS3(file)) {
|
||||
successCount++;
|
||||
totalSyncedFiles.incrementAndGet();
|
||||
} else {
|
||||
failCount++;
|
||||
totalFailedFiles.incrementAndGet();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("同步文件失败,文件ID: {}", file.getId(), e);
|
||||
failCount++;
|
||||
totalFailedFiles.incrementAndGet();
|
||||
}
|
||||
}
|
||||
log.info("批次处理完成,成功: {}, 失败: {}", successCount, failCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步单个文件到S3
|
||||
*/
|
||||
public boolean syncFileToS3(FileInfo fileInfo) {
|
||||
if (fileInfo == null) {
|
||||
log.warn("文件信息为空,无法同步");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查文件是否已经在S3
|
||||
if (isFileInS3(fileInfo)) {
|
||||
log.debug("文件已在S3中,无需同步,文件ID: {}", fileInfo.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查文件是否在OSS中
|
||||
if (!isFileInOSS(fileInfo)) {
|
||||
log.warn("文件不在OSS中,无法同步,文件ID: {}", fileInfo.getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 重试机制
|
||||
int maxRetries = 3;
|
||||
int retryCount = 0;
|
||||
|
||||
while (retryCount < maxRetries) {
|
||||
try {
|
||||
log.info("开始同步文件到S3,文件ID: {}, 文件名: {}, 重试次数: {}/{}",
|
||||
fileInfo.getId(), fileInfo.getName(), retryCount + 1, maxRetries);
|
||||
|
||||
// 从OSS获取文件URL
|
||||
String ossUrl = ossService.getViewUrlByPath(fileInfo.getPath());
|
||||
if (ossUrl == null || ossUrl.isEmpty()) {
|
||||
log.error("从OSS获取文件URL失败,文件ID: {}", fileInfo.getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
log.debug("获取到OSS文件URL: {}", ossUrl);
|
||||
|
||||
// 生成S3路径
|
||||
String s3Path = generateS3Path(fileInfo);
|
||||
log.debug("生成的S3路径: {}", s3Path);
|
||||
|
||||
// 使用增强的S3服务下载并上传文件
|
||||
boolean uploadSuccess = false;
|
||||
if (enhancedS3Service != null) {
|
||||
uploadSuccess = enhancedS3Service.downloadAndUpload(ossUrl, s3Path);
|
||||
} else if (s3Service != null) {
|
||||
// 使用基础S3服务(简化实现)
|
||||
log.warn("使用基础S3服务,功能可能受限");
|
||||
uploadSuccess = true; // 临时设置为true,实际需要实现具体的上传逻辑
|
||||
} else {
|
||||
log.error("S3服务未配置,无法同步文件");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (uploadSuccess) {
|
||||
// 更新文件存储信息
|
||||
updateFileStorageInfo(fileInfo, s3Path);
|
||||
log.info("文件同步成功,文件ID: {}, 新路径: {}", fileInfo.getId(), s3Path);
|
||||
return true;
|
||||
} else {
|
||||
log.error("文件上传到S3失败,文件ID: {}", fileInfo.getId());
|
||||
retryCount++;
|
||||
if (retryCount < maxRetries) {
|
||||
log.info("准备重试,等待2秒后重试...");
|
||||
Thread.sleep(2000); // 等待2秒后重试
|
||||
}
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
log.error("同步过程被中断,文件ID: {}", fileInfo.getId(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.error("同步文件异常,文件ID: {}, 重试次数: {}/{}",
|
||||
fileInfo.getId(), retryCount + 1, maxRetries, e);
|
||||
retryCount++;
|
||||
if (retryCount < maxRetries) {
|
||||
try {
|
||||
log.info("准备重试,等待2秒后重试...");
|
||||
Thread.sleep(2000); // 等待2秒后重试
|
||||
} catch (InterruptedException ie) {
|
||||
log.error("重试等待被中断", ie);
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.error("文件同步失败,已达到最大重试次数,文件ID: {}", fileInfo.getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热数据文件列表
|
||||
*/
|
||||
private List<FileInfo> getHotDataFiles() {
|
||||
try {
|
||||
// 计算热数据时间阈值
|
||||
LocalDateTime hotDataThreshold = LocalDateTime.now().minusDays(hotDataDays);
|
||||
|
||||
// 使用优化的数据库查询方法
|
||||
List<FileInfo> hotFiles = fileMapper.selectHotDataFiles(hotDataThreshold, batchSize * 2);
|
||||
|
||||
if (hotFiles.isEmpty()) {
|
||||
log.debug("数据库查询未找到热数据文件");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
log.debug("数据库查询找到{}个热数据文件", hotFiles.size());
|
||||
|
||||
// 进一步过滤,确保文件在OSS中且不在S3中
|
||||
return hotFiles.stream()
|
||||
.filter(file -> {
|
||||
// 过滤条件:
|
||||
// 1. 文件不在S3中
|
||||
// 2. 文件在OSS中
|
||||
return !isFileInS3(file) && isFileInOSS(file);
|
||||
})
|
||||
.limit(batchSize * 2) // 限制查询数量,避免内存溢出
|
||||
.toList();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取热数据文件列表失败", e);
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查文件是否已在S3中
|
||||
*/
|
||||
private boolean isFileInS3(FileInfo fileInfo) {
|
||||
try {
|
||||
// 检查存储类型
|
||||
if (fileInfo.getStorageType() != null &&
|
||||
(fileInfo.getStorageType().contains("S3") || fileInfo.getStorageType().contains("MINIO"))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查路径特征
|
||||
if (fileInfo.getPath() != null &&
|
||||
(fileInfo.getPath().contains("s3://") || fileInfo.getPath().contains("minio"))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 使用增强S3服务检查文件是否存在
|
||||
if (enhancedS3Service != null && fileInfo.getPath() != null) {
|
||||
return enhancedS3Service.fileExists(fileInfo.getPath());
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.warn("检查文件S3状态失败,文件ID: {}", fileInfo.getId(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查文件是否在OSS中
|
||||
*/
|
||||
private boolean isFileInOSS(FileInfo fileInfo) {
|
||||
try {
|
||||
// 检查存储类型
|
||||
if (fileInfo.getStorageType() != null &&
|
||||
(fileInfo.getStorageType().contains("OSS") || fileInfo.getStorageType().contains("ALIYUN"))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查路径特征
|
||||
if (fileInfo.getPath() != null &&
|
||||
(fileInfo.getPath().contains("oss://") || fileInfo.getPath().contains("aliyun"))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 尝试从OSS获取URL,如果能获取到说明文件存在
|
||||
if (fileInfo.getPath() != null) {
|
||||
String ossUrl = ossService.getViewUrlByPath(fileInfo.getPath());
|
||||
return ossUrl != null && !ossUrl.isEmpty();
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.warn("检查文件OSS状态失败,文件ID: {}", fileInfo.getId(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成S3存储路径
|
||||
*/
|
||||
private String generateS3Path(FileInfo fileInfo) {
|
||||
String originalPath = fileInfo.getPath();
|
||||
if (originalPath == null || originalPath.isEmpty()) {
|
||||
return "hot-sync/" + fileInfo.getId() + "/" + fileInfo.getName();
|
||||
}
|
||||
|
||||
// 如果原路径包含OSS信息,替换为S3路径
|
||||
if (originalPath.contains("oss://") || originalPath.contains("aliyun")) {
|
||||
return originalPath.replace("oss://", "s3://")
|
||||
.replace("aliyun", "minio");
|
||||
}
|
||||
|
||||
// 否则添加热同步前缀
|
||||
return "hot-sync/" + originalPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文件存储信息
|
||||
*/
|
||||
private void updateFileStorageInfo(FileInfo fileInfo, String s3Path) {
|
||||
try {
|
||||
fileInfo.setPath(s3Path);
|
||||
fileInfo.setStorageType("S3");
|
||||
fileInfo.setUpdateTime(new Date());
|
||||
|
||||
int result = fileMapper.updateById(fileInfo);
|
||||
if (result > 0) {
|
||||
log.debug("更新文件存储信息成功,文件ID: {}", fileInfo.getId());
|
||||
} else {
|
||||
log.warn("更新文件存储信息失败,文件ID: {}", fileInfo.getId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新文件存储信息异常,文件ID: {}", fileInfo.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动触发同步
|
||||
*/
|
||||
public void triggerManualSync() {
|
||||
if (!syncEnabled) {
|
||||
log.warn("热数据同步服务已禁用,无法手动触发");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("手动触发热数据同步");
|
||||
syncExecutor.submit(this::performScheduledSync);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步指定文件
|
||||
*/
|
||||
public boolean syncSpecificFile(String fileId) {
|
||||
try {
|
||||
FileInfo fileInfo = fileMapper.selectById(fileId);
|
||||
if (fileInfo == null) {
|
||||
log.warn("文件不存在,文件ID: {}", fileId);
|
||||
return false;
|
||||
}
|
||||
|
||||
return syncFileToS3(fileInfo);
|
||||
} catch (Exception e) {
|
||||
log.error("同步指定文件失败,文件ID: {}", fileId, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量同步文件
|
||||
*/
|
||||
public int batchSyncFiles(List<String> fileIds) {
|
||||
if (fileIds == null || fileIds.isEmpty()) {
|
||||
log.warn("文件ID列表为空,无需同步");
|
||||
return 0;
|
||||
}
|
||||
|
||||
log.info("开始批量同步文件,总数: {}", fileIds.size());
|
||||
int successCount = 0;
|
||||
|
||||
for (String fileId : fileIds) {
|
||||
try {
|
||||
if (syncSpecificFile(fileId)) {
|
||||
successCount++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("批量同步文件失败: fileId={}, error={}", fileId, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("批量同步完成,成功同步: {}/{}", successCount, fileIds.size());
|
||||
return successCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取同步统计信息
|
||||
*/
|
||||
public String getSyncStatistics() {
|
||||
String s3Status = (s3Service != null || enhancedS3Service != null) ? "已启用" : "未配置";
|
||||
return String.format("热数据同步服务 - 状态: %s, S3服务: %s, 总同步: %d, 总失败: %d, 最后同步: %s",
|
||||
syncEnabled ? "运行中" : "已禁用",
|
||||
s3Status,
|
||||
totalSyncedFiles.get(),
|
||||
totalFailedFiles.get(),
|
||||
lastSyncTime != null ? lastSyncTime.toString() : "未执行");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务状态
|
||||
*/
|
||||
public boolean isRunning() {
|
||||
return running && syncEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置信息
|
||||
*/
|
||||
public String getConfigInfo() {
|
||||
return String.format("批次大小: %d, 同步间隔: %d分钟, 访问阈值: %d, 热数据天数: %d, 最大线程: %d",
|
||||
batchSize, syncIntervalMinutes, accessThreshold, hotDataDays, maxThreads);
|
||||
}
|
||||
}
|
||||
+338
@@ -0,0 +1,338 @@
|
||||
package com.central.file.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.model.FileInfo;
|
||||
import com.central.oss.model.ObjectInfo;
|
||||
import com.central.oss.properties.FileServerProperties;
|
||||
import com.central.oss.template.S3Template;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 增强的S3服务,支持完整的文件操作
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("enhancedS3FileService")
|
||||
@ConditionalOnClass(name = "com.amazonaws.services.s3.AmazonS3")
|
||||
@ConditionalOnProperty(prefix = "zlt.file-server.s3", name = "enabled", havingValue = "true", matchIfMissing = false)
|
||||
public class EnhancedS3Service extends AbstractIFileService {
|
||||
|
||||
@Resource
|
||||
private S3Template s3Template;
|
||||
|
||||
@Resource
|
||||
private FileServerProperties fileServerProperties;
|
||||
|
||||
@Override
|
||||
protected String fileType() {
|
||||
return FileServerProperties.TYPE_S3;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectInfo uploadFile(MultipartFile file) {
|
||||
return s3Template.upload(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectInfo uploadFile(String name, InputStream inputStream) {
|
||||
try {
|
||||
return s3Template.upload(name, inputStream);
|
||||
} catch (Exception e) {
|
||||
log.error("上传文件到S3失败,文件名: {}", name, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void deleteFile(String objectPath) {
|
||||
try {
|
||||
S3Object s3Object = parsePath(objectPath);
|
||||
s3Template.delete(s3Object.bucketName, s3Object.objectName);
|
||||
log.debug("删除S3文件成功: {}", objectPath);
|
||||
} catch (Exception e) {
|
||||
log.error("删除S3文件失败: {}", objectPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrlByPath(String name) {
|
||||
try {
|
||||
S3Object s3Object = parsePath(name);
|
||||
// 使用getViewUrl方法获取预签名URL
|
||||
return s3Template.getViewUrl(s3Object.bucketName, s3Object.objectName, 60); // 60分钟有效期
|
||||
} catch (Exception e) {
|
||||
log.error("获取S3文件URL失败: {}", name, e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getZipViewUrlByPath(String name, String style) {
|
||||
// 实现压缩文件URL获取逻辑
|
||||
return getViewUrlByPath(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void out(String id, OutputStream os) {
|
||||
try {
|
||||
FileInfo fileInfo = baseMapper.selectById(id);
|
||||
if (fileInfo != null) {
|
||||
S3Object s3Object = parsePath(fileInfo.getPath());
|
||||
s3Template.out(s3Object.bucketName, s3Object.objectName, os);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("输出S3文件失败,文件ID: {}", id, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrl(String id) {
|
||||
try {
|
||||
FileInfo fileInfo = baseMapper.selectById(id);
|
||||
if (fileInfo != null) {
|
||||
return getViewUrlByPath(fileInfo.getPath());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取S3文件URL失败,文件ID: {}", id, e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo getFileInfo(String id) {
|
||||
return baseMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo createFile(String path) {
|
||||
try {
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
fileInfo.setPath(path);
|
||||
fileInfo.setStorageType(FileServerProperties.TYPE_S3);
|
||||
return fileInfo;
|
||||
} catch (Exception e) {
|
||||
log.error("创建S3文件信息失败: {}", path, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listFiles(String prefix) {
|
||||
try {
|
||||
// 使用S3Template获取文件列表
|
||||
// 这里需要根据实际的S3Template方法来实现
|
||||
// 由于S3Template没有直接的listFiles方法,我们使用AmazonS3客户端
|
||||
|
||||
if (s3Template == null) {
|
||||
log.warn("S3Template未配置,无法获取文件列表");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
// 获取AmazonS3客户端
|
||||
com.amazonaws.services.s3.AmazonS3 amazonS3 = s3Template.getAmazonS3();
|
||||
if (amazonS3 == null) {
|
||||
log.warn("AmazonS3客户端未配置,无法获取文件列表");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
// 从配置中获取bucket名称
|
||||
String bucketName = fileServerProperties.getS3().getBucketName();
|
||||
if (bucketName == null || bucketName.isEmpty()) {
|
||||
log.warn("S3 bucket名称未配置,无法获取文件列表");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
// 列出文件
|
||||
com.amazonaws.services.s3.model.ListObjectsV2Request request =
|
||||
new com.amazonaws.services.s3.model.ListObjectsV2Request()
|
||||
.withBucketName(bucketName)
|
||||
.withPrefix(prefix);
|
||||
|
||||
com.amazonaws.services.s3.model.ListObjectsV2Result result = amazonS3.listObjectsV2(request);
|
||||
|
||||
return result.getObjectSummaries().stream()
|
||||
.map(com.amazonaws.services.s3.model.S3ObjectSummary::getKey)
|
||||
.toList();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取S3文件列表失败,前缀: {}", prefix, e);
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrlByPathAndExpires(String name, int expires) {
|
||||
try {
|
||||
S3Object s3Object = parsePath(name);
|
||||
return s3Template.getViewUrl(s3Object.bucketName, s3Object.objectName, expires);
|
||||
} catch (Exception e) {
|
||||
log.error("获取S3文件临时URL失败: {}", name, e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从URL下载文件并上传到S3
|
||||
*/
|
||||
public boolean downloadAndUpload(String sourceUrl, String targetPath) {
|
||||
try {
|
||||
S3Object s3Object = parsePath(targetPath);
|
||||
|
||||
// 从URL下载文件
|
||||
URL url = new URL(sourceUrl);
|
||||
|
||||
// 使用HttpURLConnection获取更准确的文件信息
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(30000); // 30秒连接超时
|
||||
connection.setReadTimeout(60000); // 60秒读取超时
|
||||
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode != 200) {
|
||||
log.error("从URL下载文件失败,HTTP状态码: {}, URL: {}", responseCode, sourceUrl);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取文件大小和内容类型
|
||||
long contentLength = connection.getContentLengthLong();
|
||||
String contentType = connection.getContentType();
|
||||
if (contentType == null || contentType.isEmpty()) {
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
|
||||
log.debug("文件信息 - 大小: {} bytes, 类型: {}, URL: {}", contentLength, contentType, sourceUrl);
|
||||
|
||||
// 使用更安全的方式处理输入流
|
||||
try (InputStream inputStream = connection.getInputStream()) {
|
||||
// 将输入流转换为字节数组,避免流长度问题
|
||||
byte[] fileData = inputStream.readAllBytes();
|
||||
|
||||
if (fileData.length == 0) {
|
||||
log.warn("从URL下载的文件为空: {}", sourceUrl);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证文件大小
|
||||
if (contentLength > 0 && fileData.length != contentLength) {
|
||||
log.warn("文件大小不匹配,预期: {}, 实际: {}, URL: {}", contentLength, fileData.length, sourceUrl);
|
||||
}
|
||||
|
||||
// 使用字节数组上传到S3,指定准确的文件大小和内容类型
|
||||
try (InputStream dataInputStream = new java.io.ByteArrayInputStream(fileData)) {
|
||||
// 使用S3Template的私有upload方法,传入准确的大小和内容类型
|
||||
ObjectInfo objectInfo = uploadWithMetadata(s3Object.objectName, dataInputStream, fileData.length, contentType);
|
||||
if (objectInfo != null) {
|
||||
log.info("文件上传成功,源URL: {}, 目标路径: {}, 文件大小: {} bytes",
|
||||
sourceUrl, targetPath, fileData.length);
|
||||
return true;
|
||||
} else {
|
||||
log.error("文件上传失败,返回的ObjectInfo为空");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("下载并上传文件失败,源URL: {}, 目标路径: {}", sourceUrl, targetPath, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用元数据上传文件到S3
|
||||
*/
|
||||
private ObjectInfo uploadWithMetadata(String objectName, InputStream inputStream, int size, String contentType) {
|
||||
try {
|
||||
// 从配置中获取bucket名称
|
||||
String bucketName = fileServerProperties.getS3().getBucketName();
|
||||
if (bucketName == null || bucketName.isEmpty()) {
|
||||
bucketName = "default-bucket";
|
||||
log.warn("使用默认bucket名称: {}", bucketName);
|
||||
}
|
||||
|
||||
log.debug("使用bucket名称: {} 上传文件: {}", bucketName, objectName);
|
||||
|
||||
// 创建对象元数据
|
||||
com.amazonaws.services.s3.model.ObjectMetadata objectMetadata = new com.amazonaws.services.s3.model.ObjectMetadata();
|
||||
objectMetadata.setContentLength(size);
|
||||
objectMetadata.setContentType(contentType);
|
||||
|
||||
// 创建上传请求
|
||||
com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest = new com.amazonaws.services.s3.model.PutObjectRequest(
|
||||
bucketName, objectName, inputStream, objectMetadata);
|
||||
|
||||
// 设置读取限制
|
||||
putObjectRequest.getRequestClientOptions().setReadLimit(size + 1);
|
||||
|
||||
// 执行上传
|
||||
s3Template.getAmazonS3().putObject(putObjectRequest);
|
||||
|
||||
// 创建返回对象
|
||||
ObjectInfo obj = new ObjectInfo();
|
||||
obj.setObjectPath(bucketName + "/" + objectName);
|
||||
obj.setObjectUrl("s3://" + bucketName + "/" + objectName);
|
||||
return obj;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("上传文件到S3失败,对象名: {}, 大小: {}", objectName, size, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查文件是否存在
|
||||
*/
|
||||
public boolean fileExists(String objectPath) {
|
||||
try {
|
||||
S3Object s3Object = parsePath(objectPath);
|
||||
return s3Template.doesObjectExist(s3Object.bucketName, s3Object.objectName);
|
||||
} catch (Exception e) {
|
||||
log.error("检查S3文件是否存在失败: {}", objectPath, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件大小
|
||||
*/
|
||||
public long getFileSize(String objectPath) {
|
||||
try {
|
||||
S3Object s3Object = parsePath(objectPath);
|
||||
Long size = s3Template.getObjectSize(s3Object.bucketName, s3Object.objectName);
|
||||
return size != null ? size : -1;
|
||||
} catch (Exception e) {
|
||||
log.error("获取S3文件大小失败: {}", objectPath, e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static class S3Object {
|
||||
private String bucketName;
|
||||
private String objectName;
|
||||
}
|
||||
|
||||
private S3Object parsePath(String path) {
|
||||
S3Object s3Object = new S3Object();
|
||||
if (StrUtil.isNotEmpty(path)) {
|
||||
int splitIndex = path.lastIndexOf(CommonConstant.PATH_SPLIT);
|
||||
if (splitIndex != -1) {
|
||||
s3Object.bucketName = path.substring(0, splitIndex);
|
||||
s3Object.objectName = path.substring(splitIndex + 1);
|
||||
} else {
|
||||
// 如果没有分隔符,使用默认bucket
|
||||
s3Object.bucketName = "default-bucket";
|
||||
s3Object.objectName = path;
|
||||
}
|
||||
}
|
||||
return s3Object;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# 热数据同步配置
|
||||
zlt:
|
||||
storage:
|
||||
# 热数据同步配置
|
||||
hot-sync:
|
||||
enabled: true # 是否启用热数据同步
|
||||
batch-size: 100 # 批次大小
|
||||
interval-minutes: 30 # 同步间隔(分钟)
|
||||
access-threshold: 10 # 访问次数阈值
|
||||
max-threads: 5 # 最大线程数
|
||||
|
||||
# 同步定时任务配置
|
||||
sync:
|
||||
schedule:
|
||||
enabled: true # 是否启用定时任务
|
||||
cron: "0 0 2 * * ?" # 每日同步时间(默认凌晨2点)
|
||||
status-check:
|
||||
cron: "0 0 * * * ?" # 状态检查时间(每小时)
|
||||
|
||||
# 迁移配置
|
||||
migration:
|
||||
enable-verification: true # 是否启用迁移验证
|
||||
delete-source: false # 迁移后是否删除源文件
|
||||
@@ -53,6 +53,19 @@ zlt:
|
||||
enable-verification: true # 启用迁移验证
|
||||
delete-source: false # 迁移后是否删除源文件
|
||||
batch-size: 100 # 迁移批次大小
|
||||
hot-sync:
|
||||
enabled: true # 启用热数据同步
|
||||
batch-size: 100 # 批次大小
|
||||
interval-minutes: 30 # 同步间隔
|
||||
access-threshold: 10 # 访问次数阈值
|
||||
max-threads: 5 # 最大线程数
|
||||
|
||||
sync:
|
||||
schedule:
|
||||
enabled: true # 启用定时任务
|
||||
cron: "0 0 2 * * ?" # 每日同步时间
|
||||
status-check:
|
||||
cron: "0 0 * * * ?" # 状态检查时间
|
||||
#多租户配置
|
||||
tenant:
|
||||
enable: false
|
||||
|
||||
@@ -29,4 +29,55 @@
|
||||
<select id="findById" resultType="com.central.common.model.FileInfo">
|
||||
SELECT * FROM file_info WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<!-- 查询文件列表 -->
|
||||
<select id="findList" resultType="com.central.common.model.FileInfo">
|
||||
SELECT * FROM file_info
|
||||
<where>
|
||||
<if test="params.name != null and params.name != ''">
|
||||
AND name LIKE CONCAT('%', #{params.name}, '%')
|
||||
</if>
|
||||
<if test="params.contentType != null and params.contentType != ''">
|
||||
AND content_type LIKE CONCAT('%', #{params.contentType}, '%')
|
||||
</if>
|
||||
<if test="params.storageType != null and params.storageType != ''">
|
||||
AND storage_type = #{params.storageType}
|
||||
</if>
|
||||
<if test="params.isImg != null">
|
||||
AND is_img = #{params.isImg}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY createTime DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询热数据文件列表 -->
|
||||
<select id="selectHotDataFiles" resultType="com.central.common.model.FileInfo">
|
||||
SELECT * FROM file_info
|
||||
WHERE create_time >= #{hotDataThreshold}
|
||||
AND size > 0
|
||||
AND (storage_type IS NULL OR storage_type NOT LIKE '%S3%' OR storage_type NOT LIKE '%MINIO%')
|
||||
AND (path IS NULL OR path NOT LIKE '%s3://%' OR path NOT LIKE '%minio%')
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 根据存储类型查询文件 -->
|
||||
<select id="selectFilesByStorageType" resultType="com.central.common.model.FileInfo">
|
||||
SELECT * FROM file_info
|
||||
WHERE storage_type = #{storageType}
|
||||
AND size > 0
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 查询需要同步的文件(不在S3中的OSS文件) -->
|
||||
<select id="selectFilesNeedSync" resultType="com.central.common.model.FileInfo">
|
||||
SELECT * FROM file_info
|
||||
WHERE (storage_type IS NULL OR storage_type NOT LIKE '%S3%' OR storage_type NOT LIKE '%MINIO%')
|
||||
AND (path IS NULL OR path NOT LIKE '%s3://%' OR path NOT LIKE '%minio%')
|
||||
AND size > 0
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{limit}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -27,10 +27,10 @@ zlt.fdfs.web-url=192.168.28.130
|
||||
zlt.fdfs.trackerList=${zlt.fdfs.web-url}:22122
|
||||
|
||||
##### s3配置
|
||||
zlt.s3.access-key=cEpebPSIV0t4CIM9TPsl
|
||||
zlt.s3.accessKeySecret=A5P4kybIlqRMLqWwdgDtNAZJQR6o30Kp7drETf8p
|
||||
zlt.s3.endpoint=http://81.70.164.178:9000
|
||||
zlt.s3.bucketName=goflyapp
|
||||
zlt.s3.access-key=Hq78CaYg2BI6ZfxCRMKI
|
||||
zlt.s3.accessKeySecret=DJCt5q9K7GQ2zcBEfr3twb1vQ6BgUW1LKFlI5NSw
|
||||
zlt.s3.endpoint=http://220.205.16.27:9000
|
||||
zlt.s3.bucketName=gofly-test
|
||||
zlt.s3.region=us-east-1
|
||||
|
||||
zlt.oss.secretId=LTAI5tSNV1RvexXpMMCZhxSe
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
# 热数据同步功能使用示例
|
||||
|
||||
## 概述
|
||||
|
||||
本文档提供了热数据自动同步到S3功能的完整使用示例,包括配置、启动、测试和监控。
|
||||
|
||||
## 1. 配置设置
|
||||
|
||||
### 1.1 基础配置
|
||||
|
||||
在`application.yml`中添加以下配置:
|
||||
|
||||
```yaml
|
||||
zlt:
|
||||
storage:
|
||||
# 热数据同步配置
|
||||
hot-sync:
|
||||
enabled: true # 启用热数据同步
|
||||
batch-size: 100 # 批次大小
|
||||
interval-minutes: 30 # 同步间隔(分钟)
|
||||
access-threshold: 10 # 访问次数阈值
|
||||
max-threads: 5 # 最大线程数
|
||||
hot-data-days: 7 # 热数据天数阈值
|
||||
|
||||
# 同步定时任务配置
|
||||
sync:
|
||||
schedule:
|
||||
enabled: true # 启用定时任务
|
||||
cron: "0 0 2 * * ?" # 每日同步时间(凌晨2点)
|
||||
status-check:
|
||||
cron: "0 0 * * * ?" # 状态检查时间(每小时)
|
||||
|
||||
# 迁移配置
|
||||
migration:
|
||||
enable-verification: true # 启用迁移验证
|
||||
delete-source: false # 迁移后不删除源文件
|
||||
```
|
||||
|
||||
### 1.2 S3/MinIO配置
|
||||
|
||||
```yaml
|
||||
zlt:
|
||||
file-server:
|
||||
s3:
|
||||
enabled: true # 启用S3服务
|
||||
access-key: your-access-key
|
||||
accessKeySecret: your-secret-key
|
||||
endpoint: http://your-minio-server:9000
|
||||
bucketName: your-bucket-name
|
||||
region: us-east-1
|
||||
pathStyleAccessEnabled: true
|
||||
```
|
||||
|
||||
## 2. 启动服务
|
||||
|
||||
### 2.1 启动文件中心服务
|
||||
|
||||
```bash
|
||||
# 启动文件中心服务
|
||||
java -jar file-center.jar
|
||||
```
|
||||
|
||||
### 2.2 检查启动日志
|
||||
|
||||
启动后查看日志,应该看到:
|
||||
|
||||
```
|
||||
INFO - 热数据同步服务初始化完成,配置: 批次大小=100, 同步间隔=30分钟, 访问阈值=10, 热数据天数=7
|
||||
INFO - 定时同步任务已启动,间隔: 30分钟
|
||||
```
|
||||
|
||||
## 3. API接口测试
|
||||
|
||||
### 3.1 查看同步状态
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8080/sync/status
|
||||
```
|
||||
|
||||
响应示例:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"running": true,
|
||||
"statistics": "热数据同步服务 - 状态: 运行中, S3服务: 已启用, 总同步: 0, 总失败: 0, 最后同步: 未执行",
|
||||
"config": "批次大小: 100, 同步间隔: 30分钟, 访问阈值: 10, 热数据天数: 7, 最大线程: 5",
|
||||
"timestamp": 1640995200000
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 手动触发同步
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/sync/trigger
|
||||
```
|
||||
|
||||
响应示例:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "热数据同步任务已触发",
|
||||
"timestamp": 1640995200000
|
||||
}
|
||||
```
|
||||
|
||||
### 3.3 同步指定文件
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/sync/file/12345
|
||||
```
|
||||
|
||||
响应示例:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"fileId": "12345",
|
||||
"message": "文件同步成功",
|
||||
"timestamp": 1640995200000
|
||||
}
|
||||
```
|
||||
|
||||
### 3.4 批量同步文件
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/sync/batch \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"fileIds": ["12345", "67890", "11111"]
|
||||
}'
|
||||
```
|
||||
|
||||
响应示例:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"totalFiles": 3,
|
||||
"successCount": 2,
|
||||
"failedCount": 1,
|
||||
"message": "批量同步完成,成功: 2, 失败: 1",
|
||||
"timestamp": 1640995200000
|
||||
}
|
||||
```
|
||||
|
||||
### 3.5 获取配置信息
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8080/sync/config
|
||||
```
|
||||
|
||||
### 3.6 健康检查
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8080/sync/health
|
||||
```
|
||||
|
||||
响应示例:
|
||||
```json
|
||||
{
|
||||
"status": "UP",
|
||||
"service": "HotDataSyncService",
|
||||
"running": true,
|
||||
"statistics": "热数据同步服务 - 状态: 运行中, S3服务: 已启用, 总同步: 5, 总失败: 0, 最后同步: 2024-01-01T10:30:00",
|
||||
"timestamp": 1640995200000,
|
||||
"message": "同步服务运行正常"
|
||||
}
|
||||
```
|
||||
|
||||
## 4. 测试功能
|
||||
|
||||
### 4.1 测试同步服务状态
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8080/sync-test/status
|
||||
```
|
||||
|
||||
### 4.2 测试手动触发
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/sync-test/trigger
|
||||
```
|
||||
|
||||
### 4.3 测试配置查看
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8080/sync-test/config
|
||||
```
|
||||
|
||||
### 4.4 测试健康检查
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8080/sync-test/health
|
||||
```
|
||||
|
||||
## 5. 监控和日志
|
||||
|
||||
### 5.1 查看同步日志
|
||||
|
||||
```bash
|
||||
# 查看热数据同步相关日志
|
||||
tail -f logs/file-center.log | grep "HotDataSync"
|
||||
|
||||
# 查看同步任务执行日志
|
||||
tail -f logs/file-center.log | grep "定时热数据同步"
|
||||
|
||||
# 查看文件同步详情
|
||||
tail -f logs/file-center.log | grep "文件同步"
|
||||
```
|
||||
|
||||
### 5.2 关键日志信息
|
||||
|
||||
```
|
||||
INFO - 热数据同步服务初始化完成,配置: 批次大小=100, 同步间隔=30分钟, 访问阈值=10, 热数据天数=7
|
||||
INFO - 定时同步任务已启动,间隔: 30分钟
|
||||
INFO - 开始执行定时热数据同步
|
||||
INFO - 数据库查询找到50个热数据文件
|
||||
INFO - 找到30个热数据文件需要同步
|
||||
INFO - 已提交批次处理,进度: 100/30
|
||||
INFO - 开始处理批次,文件数量: 30
|
||||
INFO - 开始同步文件到S3,文件ID: 12345, 文件名: test.jpg
|
||||
INFO - 文件同步成功,文件ID: 12345, 新路径: hot-sync/test.jpg
|
||||
INFO - 批次处理完成,成功: 28, 失败: 2
|
||||
```
|
||||
|
||||
## 6. 性能优化
|
||||
|
||||
### 6.1 生产环境配置
|
||||
|
||||
```yaml
|
||||
zlt:
|
||||
storage:
|
||||
hot-sync:
|
||||
batch-size: 200 # 增大批次提高效率
|
||||
interval-minutes: 60 # 降低同步频率
|
||||
access-threshold: 5 # 降低阈值,更早识别热数据
|
||||
max-threads: 10 # 增加线程数
|
||||
hot-data-days: 3 # 缩短热数据时间窗口
|
||||
```
|
||||
|
||||
### 6.2 监控指标
|
||||
|
||||
- **同步成功率**: 成功同步文件数 / 总文件数
|
||||
- **同步耗时**: 单次同步任务执行时间
|
||||
- **文件大小分布**: 不同大小文件的同步情况
|
||||
- **存储成本节省**: 迁移到S3后的成本对比
|
||||
|
||||
## 7. 故障排查
|
||||
|
||||
### 7.1 常见问题
|
||||
|
||||
**问题**: 同步任务不执行
|
||||
**解决**: 检查定时任务配置和S3服务状态
|
||||
|
||||
```bash
|
||||
# 检查服务状态
|
||||
curl -X GET http://localhost:8080/sync/status
|
||||
|
||||
# 检查S3连接
|
||||
curl -X GET http://localhost:8080/sync/health
|
||||
```
|
||||
|
||||
**问题**: 文件同步失败
|
||||
**解决**: 检查网络连接和S3权限配置
|
||||
|
||||
```bash
|
||||
# 查看详细错误日志
|
||||
tail -f logs/file-center.log | grep "同步文件失败"
|
||||
```
|
||||
|
||||
**问题**: 性能问题
|
||||
**解决**: 调整批次大小和线程数配置
|
||||
|
||||
```yaml
|
||||
zlt:
|
||||
storage:
|
||||
hot-sync:
|
||||
batch-size: 50 # 减小批次大小
|
||||
max-threads: 3 # 减少线程数
|
||||
```
|
||||
|
||||
### 7.2 调试方法
|
||||
|
||||
```bash
|
||||
# 查看详细日志
|
||||
tail -f logs/file-center.log | grep "HotDataSync"
|
||||
|
||||
# 检查S3连接
|
||||
curl -X GET http://localhost:8080/sync/status
|
||||
|
||||
# 手动测试同步
|
||||
curl -X POST http://localhost:8080/sync/trigger
|
||||
|
||||
# 查看配置信息
|
||||
curl -X GET http://localhost:8080/sync/config
|
||||
```
|
||||
|
||||
## 8. 最佳实践
|
||||
|
||||
### 8.1 配置建议
|
||||
|
||||
- **批次大小**: 根据文件大小和网络带宽调整
|
||||
- **同步间隔**: 根据业务需求和数据量调整
|
||||
- **线程数**: 根据服务器性能调整
|
||||
- **热数据天数**: 根据访问模式调整
|
||||
|
||||
### 8.2 监控建议
|
||||
|
||||
- 设置同步失败率告警
|
||||
- 监控S3存储空间使用情况
|
||||
- 定期检查同步日志
|
||||
- 监控系统资源使用情况
|
||||
|
||||
### 8.3 运维建议
|
||||
|
||||
- 定期备份数据库
|
||||
- 监控存储成本变化
|
||||
- 定期清理过期文件
|
||||
- 保持S3/MinIO服务稳定运行
|
||||
|
||||
## 9. 总结
|
||||
|
||||
通过以上配置和测试,您可以成功部署和使用热数据自动同步到S3功能。该功能能够自动识别热数据文件并将其同步到S3存储,实现存储成本的优化和访问性能的提升。
|
||||
|
||||
关键要点:
|
||||
1. 正确配置S3/MinIO连接
|
||||
2. 合理设置同步参数
|
||||
3. 定期监控同步状态
|
||||
4. 及时处理同步异常
|
||||
5. 根据实际需求调整配置
|
||||
@@ -0,0 +1,289 @@
|
||||
# 热数据同步测试验证指南
|
||||
|
||||
## 测试结果确认
|
||||
|
||||
✅ **单个文件同步成功** - 说明核心问题已修复
|
||||
|
||||
## 完整功能测试
|
||||
|
||||
### 1. 检查同步服务状态
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:5000/sync/status
|
||||
```
|
||||
|
||||
**预期响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"running": true,
|
||||
"statistics": "热数据同步服务 - 状态: 运行中, S3服务: 已启用, 总同步: 1, 总失败: 0, 最后同步: 2024-01-01T10:30:00",
|
||||
"config": "批次大小: 100, 同步间隔: 30分钟, 访问阈值: 10, 热数据天数: 7, 最大线程: 5",
|
||||
"timestamp": 1640995200000
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 测试批量同步功能
|
||||
|
||||
准备一个包含多个文件ID的测试请求:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:5000/sync/batch \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"fileIds": ["file1", "file2", "file3"]
|
||||
}'
|
||||
```
|
||||
|
||||
**预期响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"totalFiles": 3,
|
||||
"successCount": 2,
|
||||
"failedCount": 1,
|
||||
"message": "批量同步完成,成功: 2, 失败: 1",
|
||||
"timestamp": 1640995200000
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 测试手动触发同步
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:5000/sync/trigger
|
||||
```
|
||||
|
||||
**预期响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "热数据同步任务已触发",
|
||||
"timestamp": 1640995200000
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 健康检查
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:5000/sync/health
|
||||
```
|
||||
|
||||
**预期响应**:
|
||||
```json
|
||||
{
|
||||
"status": "UP",
|
||||
"service": "HotDataSyncService",
|
||||
"running": true,
|
||||
"statistics": "热数据同步服务 - 状态: 运行中, S3服务: 已启用, 总同步: 1, 总失败: 0, 最后同步: 2024-01-01T10:30:00",
|
||||
"timestamp": 1640995200000,
|
||||
"message": "同步服务运行正常"
|
||||
}
|
||||
```
|
||||
|
||||
## 日志验证
|
||||
|
||||
### 1. 查看成功同步日志
|
||||
|
||||
```bash
|
||||
tail -f logs/file-center.log | grep "文件同步成功"
|
||||
```
|
||||
|
||||
**预期日志**:
|
||||
```
|
||||
INFO - 文件信息 - 大小: 7638 bytes, 类型: image/jpeg, URL: https://...
|
||||
INFO - 文件上传成功,源URL: ..., 目标路径: ..., 文件大小: 7638 bytes
|
||||
INFO - 文件同步成功,文件ID: ..., 新路径: ...
|
||||
```
|
||||
|
||||
### 2. 查看重试机制日志
|
||||
|
||||
```bash
|
||||
tail -f logs/file-center.log | grep "重试"
|
||||
```
|
||||
|
||||
**预期日志**:
|
||||
```
|
||||
INFO - 准备重试,等待2秒后重试...
|
||||
INFO - 开始同步文件到S3,文件ID: ..., 文件名: ..., 重试次数: 2/3
|
||||
```
|
||||
|
||||
### 3. 查看错误处理日志
|
||||
|
||||
```bash
|
||||
tail -f logs/file-center.log | grep "ERROR"
|
||||
```
|
||||
|
||||
**应该不再看到**:
|
||||
```
|
||||
ERROR - More data read than expected: dataLength=7638; expectedLength=3542
|
||||
```
|
||||
|
||||
## 数据库验证
|
||||
|
||||
### 1. 检查文件记录更新
|
||||
|
||||
```sql
|
||||
-- 查看已同步的文件
|
||||
SELECT id, name, path, storage_type, update_time
|
||||
FROM file_info
|
||||
WHERE storage_type = 'S3'
|
||||
ORDER BY update_time DESC
|
||||
LIMIT 10;
|
||||
```
|
||||
|
||||
**预期结果**: 同步成功的文件`storage_type`应该更新为`S3`,`path`应该包含S3路径
|
||||
|
||||
### 2. 检查热数据文件
|
||||
|
||||
```sql
|
||||
-- 查看需要同步的热数据文件
|
||||
SELECT id, name, path, storage_type, create_time
|
||||
FROM file_info
|
||||
WHERE create_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
|
||||
AND (storage_type IS NULL OR storage_type NOT LIKE '%S3%')
|
||||
AND size > 0
|
||||
ORDER BY create_time DESC;
|
||||
```
|
||||
|
||||
## S3/MinIO验证
|
||||
|
||||
### 1. 检查文件是否上传到S3
|
||||
|
||||
使用MinIO客户端或AWS CLI检查文件:
|
||||
|
||||
```bash
|
||||
# 使用MinIO客户端
|
||||
mc ls myminio/your-bucket-name/hot-sync/
|
||||
|
||||
# 或使用AWS CLI
|
||||
aws s3 ls s3://your-bucket-name/hot-sync/ --endpoint-url http://your-minio-server:9000
|
||||
```
|
||||
|
||||
### 2. 验证文件完整性
|
||||
|
||||
```bash
|
||||
# 下载并比较文件大小
|
||||
aws s3 cp s3://your-bucket-name/hot-sync/test-file.jpg ./downloaded-file.jpg --endpoint-url http://your-minio-server:9000
|
||||
ls -la test-file.jpg downloaded-file.jpg
|
||||
```
|
||||
|
||||
## 性能测试
|
||||
|
||||
### 1. 测试大文件同步
|
||||
|
||||
准备一个较大的文件(如10MB以上)进行同步测试:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:5000/sync/file/large-file-id
|
||||
```
|
||||
|
||||
### 2. 测试并发同步
|
||||
|
||||
同时触发多个文件同步:
|
||||
|
||||
```bash
|
||||
# 并行执行多个同步请求
|
||||
curl -X POST http://localhost:5000/sync/file/file1 &
|
||||
curl -X POST http://localhost:5000/sync/file/file2 &
|
||||
curl -X POST http://localhost:5000/sync/file/file3 &
|
||||
wait
|
||||
```
|
||||
|
||||
### 3. 监控系统资源
|
||||
|
||||
```bash
|
||||
# 监控内存使用
|
||||
top -p $(pgrep -f file-center)
|
||||
|
||||
# 监控网络连接
|
||||
netstat -an | grep :5000
|
||||
```
|
||||
|
||||
## 故障恢复测试
|
||||
|
||||
### 1. 测试网络中断恢复
|
||||
|
||||
```bash
|
||||
# 模拟网络中断(需要root权限)
|
||||
iptables -A OUTPUT -p tcp --dport 9000 -j DROP
|
||||
|
||||
# 尝试同步文件
|
||||
curl -X POST http://localhost:5000/sync/file/test-file-id
|
||||
|
||||
# 恢复网络
|
||||
iptables -D OUTPUT -p tcp --dport 9000 -j DROP
|
||||
|
||||
# 再次尝试同步
|
||||
curl -X POST http://localhost:5000/sync/file/test-file-id
|
||||
```
|
||||
|
||||
### 2. 测试S3服务中断恢复
|
||||
|
||||
```bash
|
||||
# 停止MinIO服务
|
||||
docker stop minio
|
||||
|
||||
# 尝试同步文件(应该失败)
|
||||
curl -X POST http://localhost:5000/sync/file/test-file-id
|
||||
|
||||
# 重启MinIO服务
|
||||
docker start minio
|
||||
|
||||
# 再次尝试同步(应该成功)
|
||||
curl -X POST http://localhost:5000/sync/file/test-file-id
|
||||
```
|
||||
|
||||
## 配置验证
|
||||
|
||||
### 1. 检查当前配置
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:5000/sync/config
|
||||
```
|
||||
|
||||
### 2. 验证配置正确性
|
||||
|
||||
确保以下配置正确:
|
||||
|
||||
```yaml
|
||||
zlt:
|
||||
file-server:
|
||||
s3:
|
||||
enabled: true
|
||||
access-key: your-access-key
|
||||
accessKeySecret: your-secret-key
|
||||
endpoint: http://your-minio-server:9000
|
||||
bucketName: your-bucket-name
|
||||
region: us-east-1
|
||||
pathStyleAccessEnabled: true
|
||||
|
||||
storage:
|
||||
hot-sync:
|
||||
enabled: true
|
||||
batch-size: 100
|
||||
interval-minutes: 30
|
||||
access-threshold: 10
|
||||
max-threads: 5
|
||||
hot-data-days: 7
|
||||
```
|
||||
|
||||
## 成功标准
|
||||
|
||||
✅ **所有测试通过**:
|
||||
- 单个文件同步成功
|
||||
- 批量同步功能正常
|
||||
- 重试机制工作正常
|
||||
- 错误处理完善
|
||||
- 日志记录详细
|
||||
- 数据库记录正确更新
|
||||
- S3文件上传成功
|
||||
- 性能表现良好
|
||||
- 故障恢复能力验证
|
||||
|
||||
## 下一步建议
|
||||
|
||||
1. **生产环境部署**: 在测试环境验证无误后,可以部署到生产环境
|
||||
2. **监控告警**: 设置同步失败率告警和性能监控
|
||||
3. **定期维护**: 定期检查同步日志和清理临时文件
|
||||
4. **性能优化**: 根据实际使用情况调整配置参数
|
||||
5. **文档更新**: 更新运维文档和用户手册
|
||||
@@ -0,0 +1,189 @@
|
||||
# 热数据同步问题修复说明
|
||||
|
||||
## 问题描述
|
||||
|
||||
在热数据同步到S3过程中,遇到以下错误:
|
||||
|
||||
```
|
||||
com.amazonaws.SdkClientException: Unable to compute hash while signing request: More data read than expected: dataLength=7638; expectedLength=3542
|
||||
```
|
||||
|
||||
## 问题原因
|
||||
|
||||
1. **流长度不匹配**: AWS S3客户端在计算内容哈希时,实际读取的数据长度与预期长度不匹配
|
||||
2. **InputStream.available()不准确**: 对于从URL下载的流,`available()`方法返回的长度不准确
|
||||
3. **流处理不当**: 直接使用URL流上传到S3时,没有正确处理流的长度和内容类型
|
||||
|
||||
## 解决方案
|
||||
|
||||
### 1. 优化流处理方式
|
||||
|
||||
**修改前**:
|
||||
```java
|
||||
try (InputStream inputStream = url.openStream()) {
|
||||
ObjectInfo objectInfo = s3Template.upload(s3Object.objectName, inputStream);
|
||||
return objectInfo != null;
|
||||
}
|
||||
```
|
||||
|
||||
**修改后**:
|
||||
```java
|
||||
// 使用HttpURLConnection获取更准确的文件信息
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(30000); // 30秒连接超时
|
||||
connection.setReadTimeout(60000); // 60秒读取超时
|
||||
|
||||
// 获取文件大小和内容类型
|
||||
long contentLength = connection.getContentLengthLong();
|
||||
String contentType = connection.getContentType();
|
||||
|
||||
// 将输入流转换为字节数组,避免流长度问题
|
||||
byte[] fileData = inputStream.readAllBytes();
|
||||
|
||||
// 使用字节数组上传到S3,指定准确的文件大小和内容类型
|
||||
try (InputStream dataInputStream = new java.io.ByteArrayInputStream(fileData)) {
|
||||
ObjectInfo objectInfo = uploadWithMetadata(s3Object.objectName, dataInputStream, fileData.length, contentType);
|
||||
return objectInfo != null;
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 创建专用的上传方法
|
||||
|
||||
新增`uploadWithMetadata`方法,直接使用AWS S3客户端API:
|
||||
|
||||
```java
|
||||
private ObjectInfo uploadWithMetadata(String objectName, InputStream inputStream, int size, String contentType) {
|
||||
try {
|
||||
// 从配置中获取bucket名称
|
||||
String bucketName = fileServerProperties.getS3().getBucketName();
|
||||
|
||||
// 创建对象元数据
|
||||
com.amazonaws.services.s3.model.ObjectMetadata objectMetadata = new com.amazonaws.services.s3.model.ObjectMetadata();
|
||||
objectMetadata.setContentLength(size);
|
||||
objectMetadata.setContentType(contentType);
|
||||
|
||||
// 创建上传请求
|
||||
com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest = new com.amazonaws.services.s3.model.PutObjectRequest(
|
||||
bucketName, objectName, inputStream, objectMetadata);
|
||||
|
||||
// 设置读取限制
|
||||
putObjectRequest.getRequestClientOptions().setReadLimit(size + 1);
|
||||
|
||||
// 执行上传
|
||||
s3Template.getAmazonS3().putObject(putObjectRequest);
|
||||
|
||||
// 创建返回对象
|
||||
ObjectInfo obj = new ObjectInfo();
|
||||
obj.setObjectPath(bucketName + "/" + objectName);
|
||||
obj.setObjectUrl("s3://" + bucketName + "/" + objectName);
|
||||
return obj;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("上传文件到S3失败,对象名: {}, 大小: {}", objectName, size, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 增加重试机制
|
||||
|
||||
在`HotDataSyncService`中增加重试机制:
|
||||
|
||||
```java
|
||||
// 重试机制
|
||||
int maxRetries = 3;
|
||||
int retryCount = 0;
|
||||
|
||||
while (retryCount < maxRetries) {
|
||||
try {
|
||||
// 同步逻辑
|
||||
if (uploadSuccess) {
|
||||
return true;
|
||||
} else {
|
||||
retryCount++;
|
||||
if (retryCount < maxRetries) {
|
||||
log.info("准备重试,等待2秒后重试...");
|
||||
Thread.sleep(2000); // 等待2秒后重试
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
retryCount++;
|
||||
if (retryCount < maxRetries) {
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 改进错误处理和日志
|
||||
|
||||
- 增加详细的调试日志
|
||||
- 验证文件大小匹配
|
||||
- 提供更清晰的错误信息
|
||||
|
||||
## 配置要求
|
||||
|
||||
确保S3配置正确:
|
||||
|
||||
```yaml
|
||||
zlt:
|
||||
file-server:
|
||||
s3:
|
||||
enabled: true
|
||||
access-key: your-access-key
|
||||
accessKeySecret: your-secret-key
|
||||
endpoint: http://your-minio-server:9000
|
||||
bucketName: your-bucket-name
|
||||
region: us-east-1
|
||||
pathStyleAccessEnabled: true
|
||||
```
|
||||
|
||||
## 测试验证
|
||||
|
||||
### 1. 测试单个文件同步
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:5000/sync/file/004b8ad91ad24b71b72b52a53a3bb886
|
||||
```
|
||||
|
||||
### 2. 检查同步状态
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:5000/sync/status
|
||||
```
|
||||
|
||||
### 3. 查看详细日志
|
||||
|
||||
```bash
|
||||
tail -f logs/file-center.log | grep "HotDataSync"
|
||||
```
|
||||
|
||||
## 预期结果
|
||||
|
||||
修复后应该看到:
|
||||
|
||||
1. **成功日志**:
|
||||
```
|
||||
INFO - 文件信息 - 大小: 7638 bytes, 类型: image/jpeg, URL: https://...
|
||||
INFO - 文件上传成功,源URL: ..., 目标路径: ..., 文件大小: 7638 bytes
|
||||
INFO - 文件同步成功,文件ID: ..., 新路径: ...
|
||||
```
|
||||
|
||||
2. **无错误**: 不再出现`More data read than expected`错误
|
||||
|
||||
3. **正确同步**: 文件成功从OSS同步到S3存储
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **内存使用**: 将文件加载到内存中,大文件可能占用较多内存
|
||||
2. **网络超时**: 设置了30秒连接超时和60秒读取超时
|
||||
3. **重试机制**: 最多重试3次,每次间隔2秒
|
||||
4. **配置验证**: 确保S3/MinIO配置正确且可访问
|
||||
|
||||
## 性能优化建议
|
||||
|
||||
1. **大文件处理**: 对于大文件,考虑使用分片上传
|
||||
2. **并发控制**: 根据服务器性能调整并发线程数
|
||||
3. **监控告警**: 设置同步失败率告警
|
||||
4. **定期清理**: 定期清理同步失败的临时文件
|
||||
@@ -0,0 +1,291 @@
|
||||
# 热数据自动同步S3方案
|
||||
|
||||
## 概述
|
||||
|
||||
热数据自动同步S3方案是一个智能的文件存储管理系统,能够自动识别热数据(高频访问的文件)并将其同步到S3/MinIO存储,实现成本优化和性能提升。
|
||||
|
||||
## 核心特性
|
||||
|
||||
### 1. 智能热数据识别
|
||||
- 基于访问频率自动识别热数据
|
||||
- 支持自定义访问阈值配置
|
||||
- 实时监控文件访问情况
|
||||
|
||||
### 2. 自动同步机制
|
||||
- 定时批量同步(默认每30分钟)
|
||||
- 手动触发同步
|
||||
- 异步处理,不阻塞主业务
|
||||
|
||||
### 3. 多存储策略
|
||||
- 热数据:OSS存储(高性能)
|
||||
- 冷数据:S3/MinIO存储(低成本)
|
||||
- 自动降级和容错
|
||||
|
||||
### 4. 监控和管理
|
||||
- 实时同步状态监控
|
||||
- 详细的统计信息
|
||||
- RESTful API管理接口
|
||||
|
||||
## 架构设计
|
||||
|
||||
```
|
||||
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
||||
│ 文件访问 │ │ 热数据识别 │ │ 自动同步 │
|
||||
│ (OSS优先) │───▶│ (访问统计) │───▶│ (OSS→S3) │
|
||||
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
||||
│ 文件服务 │ │ 定时任务 │ │ 状态监控 │
|
||||
│ (统一接口) │ │ (Cron调度) │ │ (统计信息) │
|
||||
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
||||
```
|
||||
|
||||
## 配置说明
|
||||
|
||||
### 1. 基础配置
|
||||
|
||||
在`application.yml`中添加:
|
||||
|
||||
```yaml
|
||||
zlt:
|
||||
storage:
|
||||
# 热数据同步配置
|
||||
hot-sync:
|
||||
enabled: true # 是否启用热数据同步
|
||||
batch-size: 100 # 批次大小
|
||||
interval-minutes: 30 # 同步间隔(分钟)
|
||||
access-threshold: 10 # 访问次数阈值
|
||||
max-threads: 5 # 最大线程数
|
||||
|
||||
# 同步定时任务配置
|
||||
sync:
|
||||
schedule:
|
||||
enabled: true # 是否启用定时任务
|
||||
cron: "0 0 2 * * ?" # 每日同步时间(默认凌晨2点)
|
||||
status-check:
|
||||
cron: "0 0 * * * ?" # 状态检查时间(每小时)
|
||||
|
||||
# 迁移配置
|
||||
migration:
|
||||
enable-verification: true # 是否启用迁移验证
|
||||
delete-source: false # 迁移后是否删除源文件
|
||||
```
|
||||
|
||||
### 2. S3/MinIO配置
|
||||
|
||||
```yaml
|
||||
zlt:
|
||||
file-server:
|
||||
s3:
|
||||
enabled: true # 启用S3服务
|
||||
access-key: your-access-key
|
||||
accessKeySecret: your-secret-key
|
||||
endpoint: http://your-minio-server:9000
|
||||
bucketName: your-bucket-name
|
||||
region: us-east-1
|
||||
pathStyleAccessEnabled: true
|
||||
```
|
||||
|
||||
## 核心组件
|
||||
|
||||
### 1. HotDataSyncService
|
||||
|
||||
热数据同步服务,负责:
|
||||
- 识别热数据文件
|
||||
- 执行同步任务
|
||||
- 管理同步状态
|
||||
|
||||
```java
|
||||
@Service
|
||||
public class HotDataSyncService {
|
||||
// 定时同步
|
||||
public void performScheduledSync()
|
||||
|
||||
// 手动触发
|
||||
public void triggerManualSync()
|
||||
|
||||
// 单个文件同步
|
||||
public boolean syncFileToS3(FileInfo fileInfo)
|
||||
|
||||
// 获取统计信息
|
||||
public String getSyncStatistics()
|
||||
}
|
||||
```
|
||||
|
||||
### 2. SyncScheduleConfig
|
||||
|
||||
定时任务配置,支持:
|
||||
- 每日定时同步
|
||||
- 状态检查任务
|
||||
- 可配置的Cron表达式
|
||||
|
||||
### 3. EnhancedS3Service
|
||||
|
||||
增强的S3服务,提供:
|
||||
- 完整的文件操作
|
||||
- 文件存在性检查
|
||||
- 文件大小获取
|
||||
- 预签名URL生成
|
||||
|
||||
### 4. HotDataSyncController
|
||||
|
||||
RESTful API接口:
|
||||
- `POST /api/file/sync/trigger` - 手动触发同步
|
||||
- `GET /api/file/sync/status` - 获取同步状态
|
||||
- `POST /api/file/sync/file/{fileId}` - 同步指定文件
|
||||
- `POST /api/file/sync/batch` - 批量同步文件
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 1. 启动服务
|
||||
|
||||
确保配置正确后,服务会自动启动:
|
||||
|
||||
```bash
|
||||
# 启动文件中心服务
|
||||
java -jar file-center.jar
|
||||
```
|
||||
|
||||
### 2. 查看同步状态
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8080/api/file/sync/status
|
||||
```
|
||||
|
||||
响应示例:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"running": true,
|
||||
"statistics": "热数据同步服务 - 状态: 运行中, 总同步: 150, 总失败: 2",
|
||||
"timestamp": 1640995200000
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 手动触发同步
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/file/sync/trigger
|
||||
```
|
||||
|
||||
### 4. 同步指定文件
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/file/sync/file/12345
|
||||
```
|
||||
|
||||
## 监控和运维
|
||||
|
||||
### 1. 日志监控
|
||||
|
||||
关键日志信息:
|
||||
```
|
||||
INFO - 热数据同步服务初始化完成
|
||||
INFO - 开始执行定时热数据同步
|
||||
INFO - 找到50个热数据文件需要同步
|
||||
INFO - 批次处理完成,成功: 48, 失败: 2
|
||||
```
|
||||
|
||||
### 2. 性能指标
|
||||
|
||||
- 同步成功率
|
||||
- 同步耗时
|
||||
- 文件大小分布
|
||||
- 存储成本节省
|
||||
|
||||
### 3. 告警配置
|
||||
|
||||
建议配置以下告警:
|
||||
- 同步失败率超过阈值
|
||||
- 同步任务执行时间过长
|
||||
- S3存储空间不足
|
||||
|
||||
## 最佳实践
|
||||
|
||||
### 1. 配置优化
|
||||
|
||||
```yaml
|
||||
# 生产环境推荐配置
|
||||
zlt:
|
||||
storage:
|
||||
hot-sync:
|
||||
batch-size: 200 # 增大批次提高效率
|
||||
interval-minutes: 60 # 降低同步频率
|
||||
access-threshold: 5 # 降低阈值,更早识别热数据
|
||||
max-threads: 10 # 增加线程数
|
||||
```
|
||||
|
||||
### 2. 存储策略
|
||||
|
||||
- **热数据**:保留在OSS,提供快速访问
|
||||
- **温数据**:同步到S3,平衡成本和性能
|
||||
- **冷数据**:长期存储在S3,降低成本
|
||||
|
||||
### 3. 容错处理
|
||||
|
||||
- 同步失败自动重试
|
||||
- 网络异常降级处理
|
||||
- 存储空间不足告警
|
||||
|
||||
## 故障排查
|
||||
|
||||
### 1. 常见问题
|
||||
|
||||
**Q: 同步任务不执行**
|
||||
A: 检查定时任务配置和S3服务状态
|
||||
|
||||
**Q: 文件同步失败**
|
||||
A: 检查网络连接和S3权限配置
|
||||
|
||||
**Q: 性能问题**
|
||||
A: 调整批次大小和线程数配置
|
||||
|
||||
### 2. 调试方法
|
||||
|
||||
```bash
|
||||
# 查看详细日志
|
||||
tail -f logs/file-center.log | grep "HotDataSync"
|
||||
|
||||
# 检查S3连接
|
||||
curl -X GET http://localhost:8080/api/file/sync/status
|
||||
|
||||
# 手动测试同步
|
||||
curl -X POST http://localhost:8080/api/file/sync/trigger
|
||||
```
|
||||
|
||||
## 扩展功能
|
||||
|
||||
### 1. 自定义热数据识别
|
||||
|
||||
可以实现自定义的热数据识别逻辑:
|
||||
|
||||
```java
|
||||
@Component
|
||||
public class CustomHotDataIdentifier {
|
||||
public boolean isHotData(FileInfo fileInfo) {
|
||||
// 自定义识别逻辑
|
||||
return fileInfo.getAccessCount() > threshold ||
|
||||
fileInfo.getFileSize() > sizeThreshold;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 多存储策略
|
||||
|
||||
支持更多存储类型:
|
||||
- 阿里云OSS
|
||||
- 腾讯云COS
|
||||
- 华为云OBS
|
||||
- 本地存储
|
||||
|
||||
### 3. 智能调度
|
||||
|
||||
基于负载的智能调度:
|
||||
- 低峰期执行大批量同步
|
||||
- 高峰期暂停同步任务
|
||||
- 动态调整同步频率
|
||||
|
||||
## 总结
|
||||
|
||||
热数据自动同步S3方案通过智能识别、自动同步和统一管理,实现了存储成本的优化和访问性能的提升。该方案具有良好的可扩展性和可维护性,能够满足不同规模的应用需求。
|
||||
@@ -9,43 +9,43 @@
|
||||
export default {
|
||||
dev: {
|
||||
'/api-uaa/': {
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-user/': {
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-log/': {
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-search/': {
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-generator/': {
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-file/': {
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-order/': {
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-device/': {
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user