reghao 2 jaren geleden
bovenliggende
commit
be07bf86ee

+ 1 - 0
dfs-store/src/main/java/cn/reghao/dfs/store/db/mapper/DataBlockMapper.java

@@ -20,4 +20,5 @@ public interface DataBlockMapper extends BaseMapper<DataBlock> {
 
     List<DataBlock> findByObjectId(String objectId);
     List<DataBlock> findDataBlockByPage(Page page);
+    DataBlock findByPath(String absolutePath);
 }

+ 4 - 0
dfs-store/src/main/resources/mapper/DataBlockMapper.xml

@@ -52,4 +52,8 @@
         inner join file_meta
         on data_block.object_id=file_meta.object_id
     </select>
+    <select id="findByPath" resultType="cn.reghao.dfs.store.model.po.DataBlock">
+        select * from data_block
+        where absolute_path=#{absolutePath}
+    </select>
 </mapper>

+ 23 - 0
dfs-store/src/test/java/RedisTest.java

@@ -1,6 +1,9 @@
 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.model.po.DataBlock;
 import cn.reghao.dfs.store.model.po.FileMeta;
+import cn.reghao.jutil.jdk.security.DigestUtil;
 import cn.reghao.oss.api.dto.ObjectMeta;
 import cn.reghao.dfs.store.redis.ds.RedisStringObj;
 import cn.reghao.jutil.jdk.db.Page;
@@ -12,6 +15,9 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.io.File;
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
 
 /**
@@ -66,4 +72,21 @@ public class RedisTest {
             log.info("page -> {}", pageNumber);
         }
     }
+
+    @Autowired
+    DataBlockMapper dataBlockMapper;
+    private void checkLocalFile(File file) throws IOException, NoSuchAlgorithmException {
+        log.error("--------------------------------------");
+        String absolutePath = file.getAbsolutePath();
+        DataBlock dataBlock = dataBlockMapper.findByPath(absolutePath);
+        if (dataBlock == null) {
+            log.error("{} not exist in data_block", absolutePath);
+        }
+
+        String sha256sum = DigestUtil.sha256sum(absolutePath);
+        FileMeta fileMeta = fileMetaMapper.findBySha256sum(sha256sum);
+        if (fileMeta == null) {
+            log.error("{} not exist in file_meta", absolutePath);
+        }
+    }
 }