|
@@ -1,11 +1,20 @@
|
|
|
|
|
+import cn.reghao.jutil.jdk.converter.ByteConverter;
|
|
|
import cn.reghao.oss.mgr.OssMgrApplication;
|
|
import cn.reghao.oss.mgr.OssMgrApplication;
|
|
|
|
|
+import cn.reghao.oss.mgr.db.mapper.DataBlockMapper;
|
|
|
|
|
+import cn.reghao.oss.mgr.db.mapper.FileMetaMapper;
|
|
|
import cn.reghao.oss.mgr.db.mapper.UserKeyMapper;
|
|
import cn.reghao.oss.mgr.db.mapper.UserKeyMapper;
|
|
|
|
|
+import cn.reghao.oss.mgr.model.po.DataBlock;
|
|
|
|
|
+import cn.reghao.oss.mgr.model.po.FileMeta;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @author reghao
|
|
* @author reghao
|
|
|
* @date 2026-02-18 17:04:30
|
|
* @date 2026-02-18 17:04:30
|
|
@@ -17,8 +26,59 @@ public class FileMetaTest {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
UserKeyMapper userKeyMapper;
|
|
UserKeyMapper userKeyMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ FileMetaMapper fileMetaMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ DataBlockMapper dataBlockMapper;
|
|
|
@Test
|
|
@Test
|
|
|
public void test() {
|
|
public void test() {
|
|
|
//userKeyMapper.findByAccessKeyId();
|
|
//userKeyMapper.findByAccessKeyId();
|
|
|
|
|
+ findAllById();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void findBySha256List() {
|
|
|
|
|
+ ByteConverter byteConverter = new ByteConverter();
|
|
|
|
|
+ List<DataBlock> dataBlocks = dataBlockMapper.findAll();
|
|
|
|
|
+ long total = dataBlocks.stream().mapToLong(DataBlock::getSize).sum();
|
|
|
|
|
+ String result = byteConverter.convert(total);
|
|
|
|
|
+ String max = byteConverter.convert(dataBlocks.getFirst().getSize());
|
|
|
|
|
+ String min = byteConverter.convert(dataBlocks.getLast().getSize());
|
|
|
|
|
+ log.info("总大小: {} {} {}", result, max, min);
|
|
|
|
|
+
|
|
|
|
|
+ List<String> list = dataBlocks.stream().map(DataBlock::getSha256sum).collect(Collectors.toList());
|
|
|
|
|
+ List<FileMeta> list1 = fileMetaMapper.findBySha256List(list);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, List<FileMeta>> groupMap = list1.stream().collect(Collectors.groupingBy(FileMeta::getSha256sum));
|
|
|
|
|
+ for (Map.Entry<String, List<FileMeta>> entry : groupMap.entrySet()) {
|
|
|
|
|
+ String sha256sum = entry.getKey();
|
|
|
|
|
+ List<FileMeta> list2 = entry.getValue();
|
|
|
|
|
+
|
|
|
|
|
+ FileMeta fileMeta = list2.getFirst();
|
|
|
|
|
+ if (!fileMeta.getObjectName().startsWith("video/playback")) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String sizeStr = byteConverter.convert(fileMeta.getSize());
|
|
|
|
|
+ log.info("file_list: {} -> {} - {}", list2.size(), sizeStr, fileMeta.getFilename());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void findAllById() {
|
|
|
|
|
+ int pageSize = 10000;
|
|
|
|
|
+ int nextId = 0;
|
|
|
|
|
+ List<DataBlock> dataBlocks = dataBlockMapper.findAllById(pageSize, nextId);
|
|
|
|
|
+ while (!dataBlocks.isEmpty()) {
|
|
|
|
|
+ dataBlocks.forEach(this::process);
|
|
|
|
|
+
|
|
|
|
|
+ nextId = dataBlocks.get(dataBlocks.size()-1).getId();
|
|
|
|
|
+ dataBlocks = dataBlockMapper.findAllById(pageSize, nextId);
|
|
|
|
|
+ log.info("start nextId {} with size {}", nextId, dataBlocks.size());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void process(DataBlock dataBlock) {
|
|
|
|
|
+ String hostPort = "192.168.0.10:8020";
|
|
|
|
|
+ int id = dataBlock.getId();
|
|
|
|
|
+ dataBlockMapper.updateDataBlock(id, hostPort);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|