调整代码
This commit is contained in:
		
							parent
							
								
									23490f8993
								
							
						
					
					
						commit
						9f1f634095
					
				| 
						 | 
				
			
			@ -68,15 +68,8 @@ public class GraphCommonService {
 | 
			
		|||
        try {
 | 
			
		||||
            return new SessionPool(nebulaGraphProperties.getMaxConnSize(), nebulaGraphProperties.getMinConnsSize(), nebulaGraphProperties.getHostAddresses(),
 | 
			
		||||
                    nebulaGraphProperties.getUserName(), nebulaGraphProperties.getPassword());
 | 
			
		||||
        } catch (UnknownHostException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        } catch (IOErrorException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        } catch (AuthFailedException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        } catch (ClientServerIncompatibleException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        } catch (NotValidConnectionException e) {
 | 
			
		||||
        } catch (UnknownHostException | IOErrorException | ClientServerIncompatibleException | AuthFailedException |
 | 
			
		||||
                 NotValidConnectionException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,26 +82,18 @@ public class RelationCompletion {
 | 
			
		|||
 | 
			
		||||
        while (true) {
 | 
			
		||||
            for (TagEnum tagEnum : TagEnum.values()) {
 | 
			
		||||
 | 
			
		||||
                Object allGetNum = redisClient.get(ALLNUM);
 | 
			
		||||
                if (allGetNum != null && (Integer) allGetNum >= 5) {
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                String tag = tagEnum.getTag();
 | 
			
		||||
 | 
			
		||||
                Object num = redisClient.get(tag + "_num");
 | 
			
		||||
 | 
			
		||||
                Integer skip = (Integer) (num == null ? 0 : num);
 | 
			
		||||
 | 
			
		||||
                if (tagNumsMap.get(tag) < skip) {
 | 
			
		||||
                    redisClient.increment(ALLNUM);
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                log.info("开启{}类型的点为起始节点的第{}条数据到第{}条数据反向关系补全", tag, skip, skip + this.limitNum);
 | 
			
		||||
 | 
			
		||||
                List<NebulaMultiMatchJsonResult> idJsonResults =
 | 
			
		||||
                        graphCommonService.executeJson(NebulaUtil.getTagIdsWithLimit(spaceName, tag, skip, this.limitNum),
 | 
			
		||||
                                NebulaMultiMatchJsonResult.class);
 | 
			
		||||
| 
						 | 
				
			
			@ -109,9 +101,10 @@ public class RelationCompletion {
 | 
			
		|||
                if (CollectionUtils.isEmpty(idJsonResults)) {
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                List<String> idLists = NebulaMultiMatchJsonResult.getIdLists(idJsonResults.get(0));
 | 
			
		||||
 | 
			
		||||
                if (CollectionUtils.isEmpty(idLists)) {
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                List<CompletableFuture<?>> futures = new ArrayList<>();
 | 
			
		||||
                // 遍历边
 | 
			
		||||
                EdgeEnum[] edgeEnums = EdgeEnum.values();
 | 
			
		||||
| 
						 | 
				
			
			@ -119,15 +112,10 @@ public class RelationCompletion {
 | 
			
		|||
                    Integer finalSkip = skip;
 | 
			
		||||
                    CompletableFuture<Void> setVertexAndEdgeTotalsMap = CompletableFuture.supplyAsync(() -> {
 | 
			
		||||
                        try {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                            String srcTag = edgeEnum.getSrcTag();
 | 
			
		||||
                            String edgeType = edgeEnum.getEdgeType();
 | 
			
		||||
                            String reverseRelation = edgeEnum.getReverseRelation();
 | 
			
		||||
 | 
			
		||||
                            Instant now = Instant.now();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                            List<NebulaVertexJsonResult> vertexJsonResults = graphCommonService.executeJsonWithoutLogs(
 | 
			
		||||
                                    NebulaUtil.getDstVerticesById(spaceName, srcTag, idLists, edgeType),
 | 
			
		||||
                                    NebulaVertexJsonResult.class,
 | 
			
		||||
| 
						 | 
				
			
			@ -153,7 +141,6 @@ public class RelationCompletion {
 | 
			
		|||
                }
 | 
			
		||||
 | 
			
		||||
                CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
 | 
			
		||||
 | 
			
		||||
                skip = skip + this.limitNum;
 | 
			
		||||
                redisClient.set(tag + "_num", skip);
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@ package com.idata.tools.relationcompletion.util;
 | 
			
		|||
 | 
			
		||||
import com.idata.tools.relationcompletion.dto.NebulaVertexJsonResult;
 | 
			
		||||
import com.idata.tools.relationcompletion.vo.SearchSubgraphVo;
 | 
			
		||||
import com.vesoft.nebula.Edge;
 | 
			
		||||
import org.apache.commons.collections4.CollectionUtils;
 | 
			
		||||
import org.apache.commons.lang3.StringUtils;
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
| 
						 | 
				
			
			@ -54,7 +53,7 @@ public class NebulaUtil {
 | 
			
		|||
                .map(id -> "'" + id + "'")
 | 
			
		||||
                .collect(Collectors.joining(", "));
 | 
			
		||||
 | 
			
		||||
        String format = String.format("USE %s; MATCH (v:%s)-[:%s]->(v2) WHERE id(v) IN [%s] RETURN v2",
 | 
			
		||||
        String format = String.format("USE %s; MATCH (v:%s)-[e:%s]->(v2) WHERE id(v) IN [%s] RETURN v2",
 | 
			
		||||
                spaceName, tag, edgeType, idList);
 | 
			
		||||
        return format;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,15 +1,15 @@
 | 
			
		|||
nebula:
 | 
			
		||||
  userName: root
 | 
			
		||||
  password: nebula
 | 
			
		||||
  hostAddresses: 172.16.20.2:9669,172.16.20.4:9669,172.16.20.5:9669
 | 
			
		||||
  hostAddresses: 192.168.7.32:9669,192.168.7.153:9669
 | 
			
		||||
  minConnsSize: 20
 | 
			
		||||
  maxConnSize: 100
 | 
			
		||||
  maxConnSize: 50
 | 
			
		||||
  timeout: 600000
 | 
			
		||||
  idleTime: 180000
 | 
			
		||||
  spaceName: Y24_1206
 | 
			
		||||
  limitNum: 10000  #
 | 
			
		||||
 | 
			
		||||
redis:
 | 
			
		||||
  host: 172.16.20.1
 | 
			
		||||
  host: 192.168.7.32
 | 
			
		||||
  port: 6379
 | 
			
		||||
  password: 123456
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user