StorageClient scanVertex查询对结果进行迭遍历时子线程没有退出

Nebula v2.0ga

Java client是2.0.0

  • 部署方式分布式 :

测试执行的时候,发现使用main函数。主程序是不退出的,但是执行junit 是正常退出的(因为junit不支持多线程),估计是对scanVertex执行的结果ScanVertexResultIterator进行迭代遍历的时候,存在异步多线程执行没有退出

代码 / 终端输出 / 日志…
import com.vesoft.nebula.client.graph.data.HostAddress;
import com.vesoft.nebula.client.storage.StorageClient;
import com.vesoft.nebula.client.storage.data.VertexRow;
import com.vesoft.nebula.client.storage.data.VertexTableRow;
import com.vesoft.nebula.client.storage.scan.ScanVertexResult;
import com.vesoft.nebula.client.storage.scan.ScanVertexResultIterator;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: 01394612
 * @Date: 2021/3/25
 */
@Slf4j
public class StorageClientTest {
    public static void main(String[] args) {
        testScanVertexWithNoCol();
        log.info("end main");
    }

    @Test
    public void test() {
        testScanVertexWithNoCol();
        log.info("end junit test");
    }

    public static void testScanVertexWithNoCol() {
        List<HostAddress> addressList = Arrays.asList(
                new HostAddress("10.206.56.99", 45500)
                , new HostAddress("10.206.56.100", 45500)
                , new HostAddress("10.206.56.101", 45500));
        StorageClient client = new StorageClient(addressList);
        try {
            client.connect();
        } catch (Exception e) {
        }

        ScanVertexResultIterator resultIterator = client.scanVertex(
                "testStorage",
                "person");
        while (resultIterator.hasNext()) {
            ScanVertexResult result = null;
            try {
                result = resultIterator.next();
            } catch (Exception e) {
                e.printStackTrace();
            }

            List<VertexRow> rows = result.getVertices();
            for (VertexRow row : rows) {
                log.info("" + row.getVid());
            }

            List<VertexTableRow> tableRows = result.getVertexTableRows();
            for (VertexTableRow tableRow : tableRows) {
                log.info("" + tableRow.getVid());
            }
        }

        log.info("end");
    }
}

image

Nebula v2.0ga

Java client是2.0.0

com.vesoft
client
2.0.0

发现 如果最后加一行client.close(); 就可以正常退出了,但是这种情况下,main执行完毕了竟然不退出 :innocent:

那个测试代码里面缺少把连接池关闭,连接池有个线程没有退出,我fix后提pr,你再看下。

Add close in test by laura-ding · Pull Request #282 · vesoft-inc/nebula-java · GitHub 这个pr修了,你看下。

1赞

浙ICP备20010487号