storage client 无法关闭


如图所示,storage client 调用close方法还是没有关闭?这是不是一个bug ?
我看了一个nebula-java里的代码,代码是这样退出的

System.exit(1);

在上线项目中这样做会被打死吧

为什么close() 要调用两次?

StorageMain 里面是不是有线程池呢?

没有线程池


public class StorageMain {
    public static void main(String[] args) {
        StorageParam storageParam = new StorageParam();
        storageParam.setSpaceName("testindex1");
        storageParam.setEdgeType("serve");

        List<String> edgeProperties = new ArrayList<>();
        edgeProperties.add("start_year");
        edgeProperties.add("end_year");
        storageParam.setEdgeProperties(edgeProperties);
//        StorageUtils.scanEdge(storageParam, new StorageEdgeFilter(){
//            @Override
//            public void filterEdge(EdgeTableRow edge) {
//              try {
//                  if (edge.getSrcId().asString().contains("100")) {
//                      //System.out.println(edge.getSrcId().asString());
//                  }
//              }catch (Exception e){
//                  e.printStackTrace();
//              }
//            }
//        });


        StorageParam vertexParam = new StorageParam();
        vertexParam.setTagName("player");
        vertexParam.setSpaceName("testindex1");
        List<String> props = new ArrayList<>();
        props.add("name");
        props.add("age");
        vertexParam.setTagPropertis(props);
        // 查询点
        StorageUtils.scanVertex(vertexParam, new StorageVertexFilter() {
            @Override
            public void fileterVertex(VertexTableRow vertex) {
                try {
                    vertex.getVid().asString().equals("player9101");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
        });

    }
}
public class StorageUtils {
    private static final Logger LOGGER = LoggerFactory.getLogger(StorageUtils.class);

    public static StorageClient client= new StorageClient("172.80.1.2", 9559);


//    public static void main1(String[] args) {
//        // input params are the metad's ip and port
//
//        try {
//            client.connect();
//        } catch (Exception e) {
//            LOGGER.error("storage client connect error, ", e);
//            System.exit(1);
//        }
//        scanVertex(client);
//        scanEdge(client);
//    }

    /**
     * Vertex Person's property in Nebula Graph:
     * first_name, last_name, gender, birthday
     * Tom          Li        男       2010
     */
    public static void scanVertex(StorageParam storageParam, StorageVertexFilter storageFilter) {
        try {
            client.connect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        ScanVertexResultIterator iterator = client.scanVertex(
                storageParam.getSpaceName(),
                storageParam.getTagName(),
                storageParam.getTagPropertis());

        while (iterator.hasNext()) {
            ScanVertexResult result = null;
            try {
                result = iterator.next();
            } catch (Exception e) {
                LOGGER.error("scan error, ", e);
                System.exit(1);
            }
            if (result.isEmpty()) {
                continue;
            }
            System.out.println(result.getPropNames());
            List<VertexRow> vertexRows = result.getVertices();
//            for (VertexRow row : vertexRows) {
//                if (result.getVertex(row.getVid()) != null) {
//                    System.out.println("vid : " + result.getVertex(row.getVid()));
//                }
//            }
            //System.out.println(result.getVidVertices());
            //System.out.println("result vertex table view:");
            List<VertexTableRow> vertexTableRows = result.getVertexTableRows();
            for (VertexTableRow vertex : vertexTableRows) {

                if(storageFilter != null){
                    storageFilter.fileterVertex(vertex);
                }
                else{
                    System.out.println(vertex.getValues());
                }

//                try {
//                    System.out.println("_vid: " + vertex.getVid().asString());
//                    System.out.println(vertex.getValues());
//                } catch (UnsupportedEncodingException e) {
//                    LOGGER.error("decode String error, ", e);
//                }
            }
            //System.out.println(result.getVertices());
        }
        close(client);
    }

    /**
     * Edge Friend's property in Nebula Graph:
     * degree
     * 1.0
     */
    public static void scanEdge(StorageParam storageParam, StorageEdgeFilter storageFilter) {
        try {
            client.connect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        ScanEdgeResultIterator iterator = client.scanEdge(
                storageParam.getSpaceName(),
                storageParam.getEdgeType(),
                storageParam.getEdgeProperties());

        while (iterator.hasNext()) {
            ScanEdgeResult result = null;
            try {
                result = iterator.next();
            } catch (Exception e) {
                LOGGER.error("scan error, ", e);
                System.exit(1);
            }
            if (result.isEmpty()) {
                continue;
            }
            System.out.println(result.getPropNames());
            //System.out.println(result.getEdges());

            System.out.println("result edge table view:");
            List<EdgeTableRow> edgeTableRows = result.getEdgeTableRows();
            for (EdgeTableRow edge : edgeTableRows) {
                storageFilter.filterEdge(edge);
                //try {
                   // System.out.println("_src:" + edge.getSrcId().asString());
                    //System.out.println("_dst:" + edge.getDstId().asString());
                //} catch (UnsupportedEncodingException e) {
                 //   LOGGER.error("decode String error, ", e);
                //}
                //System.out.println("_rank:" + edge.getRank());

                //过滤测试代码
                if(storageFilter!=null){

                }else{
                    System.out.println(edge.getValues());
                }

            }
        }
        close(client);
    }


    public  static void close(StorageClient client){
        if(client!=null){
            client.close();
          //  client.close();
           // System.out.println("end");
        }
    }
}

遇到了同样的问题,main函数里只有这几行代码,但client.close()后没有正常退出


image

这是example代码里面的吧,这里写的是有问题,应该是要先关闭再退出的。

如图所示,storage client 调用close方法还是没有关闭?这是不是一个bug ?

咋看出没关闭了

finally 里面 client close,整个main是不会结束的

应该是storageclient里面用到了线程池没有正常退出,你可以提供版本信息,数据集,我们复现下吗?

就是最新的 client 2.0

client的close方法需要把线程池 shutdown 吧


代码都执行到最后了,这个红色的四方快旧代码还在运行。

https://github.com/vesoft-inc/nebula-java/pull/311 修复

该主题在最后一个回复创建后30天后自动关闭。不再允许新的回复。

浙ICP备20010487号