|
@@ -1,11 +1,7 @@
|
|
|
import cn.reghao.dfs.store.DfsStoreApplication;
|
|
import cn.reghao.dfs.store.DfsStoreApplication;
|
|
|
-import cn.reghao.dfs.store.db.mapper.DataBlockMapper;
|
|
|
|
|
import cn.reghao.dfs.store.db.mapper.FileMetaMapper;
|
|
import cn.reghao.dfs.store.db.mapper.FileMetaMapper;
|
|
|
-import cn.reghao.dfs.store.model.po.DataBlock;
|
|
|
|
|
import cn.reghao.dfs.store.model.po.FileMeta;
|
|
import cn.reghao.dfs.store.model.po.FileMeta;
|
|
|
-import cn.reghao.dfs.api.dto.ObjectMeta;
|
|
|
|
|
import cn.reghao.jutil.jdk.db.Page;
|
|
import cn.reghao.jutil.jdk.db.Page;
|
|
|
-import cn.reghao.jutil.jdk.security.DigestUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
@@ -14,16 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
|
|
-import java.io.FileInputStream;
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.nio.file.FileVisitResult;
|
|
|
|
|
-import java.nio.file.FileVisitor;
|
|
|
|
|
-import java.nio.file.Files;
|
|
|
|
|
-import java.nio.file.Path;
|
|
|
|
|
-import java.nio.file.attribute.BasicFileAttributes;
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author reghao
|
|
* @author reghao
|
|
@@ -36,16 +23,8 @@ import java.util.UUID;
|
|
|
public class FileMetaTest {
|
|
public class FileMetaTest {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
FileMetaMapper fileMetaMapper;
|
|
FileMetaMapper fileMetaMapper;
|
|
|
- @Autowired
|
|
|
|
|
- DataBlockMapper dataBlockMapper;
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 正则表达式查询测试
|
|
|
|
|
- *
|
|
|
|
|
- * @param
|
|
|
|
|
- * @return
|
|
|
|
|
- * @date 2023-05-23 11:06:07
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // 正则表达式查询测试
|
|
|
public void regexpTest() {
|
|
public void regexpTest() {
|
|
|
String bucket = "";
|
|
String bucket = "";
|
|
|
String prefix = "abc/d/";
|
|
String prefix = "abc/d/";
|
|
@@ -61,105 +40,22 @@ public class FileMetaTest {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 分页处理
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @date 2023-05-30 00:26:07
|
|
|
|
|
+ */
|
|
|
@Test
|
|
@Test
|
|
|
- public void test2() {
|
|
|
|
|
- int pageSize = 10000;
|
|
|
|
|
- int pageNumber = 1;
|
|
|
|
|
- Page page = new Page(pageNumber, pageSize);
|
|
|
|
|
- List<DataBlock> dataBlocks = dataBlockMapper.findDataBlockByPage(page);
|
|
|
|
|
- List<FileMeta> fileMetas = new ArrayList<>();
|
|
|
|
|
- while (!dataBlocks.isEmpty()) {
|
|
|
|
|
- dataBlocks.forEach(dataBlock -> {
|
|
|
|
|
- String objectId = dataBlock.getObjectId();
|
|
|
|
|
- String contentId = UUID.randomUUID().toString().replace("-", "");
|
|
|
|
|
-
|
|
|
|
|
- FileMeta fileMeta = fileMetaMapper.findByObjectId(objectId);
|
|
|
|
|
- if (fileMeta == null) {
|
|
|
|
|
- log.error("{} 不存在", objectId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- fileMeta.setContentId(contentId);
|
|
|
|
|
- fileMetas.add(fileMeta);
|
|
|
|
|
- dataBlock.setContentId(contentId);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- long start = System.currentTimeMillis();
|
|
|
|
|
- if (!fileMetas.isEmpty()) {
|
|
|
|
|
- fileMetaMapper.updateBatch(fileMetas);
|
|
|
|
|
- fileMetas.clear();
|
|
|
|
|
- log.info("batch update FileMeta cost {}", System.currentTimeMillis()-start);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (!dataBlocks.isEmpty()) {
|
|
|
|
|
- dataBlockMapper.updateBatch(dataBlocks);
|
|
|
|
|
- log.info("batch update DataBlock cost {}", System.currentTimeMillis()-start);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- pageNumber++;
|
|
|
|
|
- page = new Page(pageNumber, pageSize);
|
|
|
|
|
- dataBlocks = dataBlockMapper.findDataBlockByPage(page);
|
|
|
|
|
- log.info("page -> {}", pageNumber);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void walkDir(Path path) throws IOException {
|
|
|
|
|
- Files.walkFileTree(path, new FileVisitor<>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
|
|
|
|
- return FileVisitResult.CONTINUE;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
|
|
|
|
- String absolutePath = file.toString();
|
|
|
|
|
- process(absolutePath);
|
|
|
|
|
- return FileVisitResult.CONTINUE;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
|
|
|
|
|
- return FileVisitResult.CONTINUE;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
|
|
|
|
- return FileVisitResult.CONTINUE;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void process(String absolutePath) {
|
|
|
|
|
- try {
|
|
|
|
|
- String sha256sum = DigestUtil.sha256sum(absolutePath);
|
|
|
|
|
- FileMeta fileMeta = fileMetaMapper.findBySha256sum(sha256sum);
|
|
|
|
|
- if (fileMeta == null) {
|
|
|
|
|
- log.error("{} 不存在", absolutePath);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception ignore) {
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- public void test22() throws IOException {
|
|
|
|
|
- String baseDir = "/home/reghao/mnt/zdata/porn/0.已完成/";
|
|
|
|
|
- Path path = Path.of(baseDir);
|
|
|
|
|
- walkDir(path);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- public void test11() {
|
|
|
|
|
|
|
+ public void processByPage() {
|
|
|
int pageSize = 10_000;
|
|
int pageSize = 10_000;
|
|
|
int pageNumber = 1;
|
|
int pageNumber = 1;
|
|
|
Page page = new Page(pageNumber, pageSize);
|
|
Page page = new Page(pageNumber, pageSize);
|
|
|
List<FileMeta> list = fileMetaMapper.findFileMetaByPage(page);
|
|
List<FileMeta> list = fileMetaMapper.findFileMetaByPage(page);
|
|
|
while (!list.isEmpty()) {
|
|
while (!list.isEmpty()) {
|
|
|
list.forEach(fileMeta -> {
|
|
list.forEach(fileMeta -> {
|
|
|
- String objectName = fileMeta.getObjectName();
|
|
|
|
|
- ObjectMeta objectMeta = fileMetaMapper.findObjectMeta(objectName);
|
|
|
|
|
- if (objectMeta == null) {
|
|
|
|
|
- log.error("{} 对应的文件不存在", objectName);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
pageNumber++;
|
|
pageNumber++;
|