From c3fa62ab859f2f11e7a9c2617f270b881d4e66dd Mon Sep 17 00:00:00 2001 From: Anqi <16240361+Nicole00@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:26:59 +0800 Subject: [PATCH] fix socket timewait for storage client (#607) * fix socket timewait for storage client * update docker compose * update docker compose * update * update * update storage container name --- .github/workflows/pull_request.yml | 12 ++++++------ .../client/storage/StorageConnPoolFactory.java | 18 ++++++++++++------ .../nebula/client/meta/TestMetaClient.java | 13 +++++++------ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 1ebd0bab2..2f8f9bf8f 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -38,9 +38,9 @@ jobs: git clone https://github.com/vesoft-inc/nebula-docker-compose.git pushd nebula-docker-compose/ cp ../../client/src/test/resources/docker-compose.yaml . - docker-compose up -d + docker compose up -d sleep 30 - docker-compose ps + docker compose ps popd popd @@ -51,9 +51,9 @@ jobs: pushd ca cp -r ../../client/src/test/resources/ssl . cp ../../client/src/test/resources/docker-compose-casigned.yaml . - docker-compose -f docker-compose-casigned.yaml up -d + docker compose -f docker-compose-casigned.yaml up -d sleep 30 - docker-compose -f docker-compose-casigned.yaml ps + docker compose -f docker-compose-casigned.yaml ps popd popd @@ -64,9 +64,9 @@ jobs: pushd self cp -r ../../client/src/test/resources/ssl . cp ../../client/src/test/resources/docker-compose-selfsigned.yaml . - docker-compose -f docker-compose-selfsigned.yaml up -d + docker compose -f docker-compose-selfsigned.yaml up -d sleep 30 - docker-compose -f docker-compose-selfsigned.yaml ps + docker compose -f docker-compose-selfsigned.yaml ps popd popd diff --git a/client/src/main/java/com/vesoft/nebula/client/storage/StorageConnPoolFactory.java b/client/src/main/java/com/vesoft/nebula/client/storage/StorageConnPoolFactory.java index 2136c2916..a88766c67 100644 --- a/client/src/main/java/com/vesoft/nebula/client/storage/StorageConnPoolFactory.java +++ b/client/src/main/java/com/vesoft/nebula/client/storage/StorageConnPoolFactory.java @@ -27,6 +27,11 @@ public StorageConnPoolFactory(StoragePoolConfig config) { @Override public PooledObject makeObject(HostAddress address) throws Exception { GraphStorageConnection connection = new GraphStorageConnection(); + connection.open( + address, + config.getTimeout(), + config.isEnableSSL(), + config.getSslParam()); return new DefaultPooledObject<>(connection); } @@ -47,7 +52,7 @@ public boolean validateObject(HostAddress hostAndPort, return connection.transport.isOpen(); } catch (Exception e) { LOGGER.warn(String.format("storage connection with %s:%d is not open", - hostAndPort.getHost(), hostAndPort.getPort()), e); + hostAndPort.getHost(), hostAndPort.getPort()), e); return false; } } @@ -56,11 +61,12 @@ public boolean validateObject(HostAddress hostAndPort, public void activateObject(HostAddress address, PooledObject pooledObject) throws Exception { - pooledObject.getObject().open( - address, - config.getTimeout(), - config.isEnableSSL(), - config.getSslParam()); + if (pooledObject.getObject() == null) { + throw new RuntimeException("The connection is null."); + } + if (!pooledObject.getObject().transport.isOpen()) { + throw new RuntimeException("The connection is broken."); + } } @Override diff --git a/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaClient.java b/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaClient.java index 6ca59aa7b..43ea1f25f 100644 --- a/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaClient.java +++ b/client/src/test/java/com/vesoft/nebula/client/meta/TestMetaClient.java @@ -30,7 +30,7 @@ public class TestMetaClient extends TestCase { private static final Logger LOGGER = LoggerFactory.getLogger(TestMetaClient.class); private final String address = "127.0.0.1"; - private final int port = 9559; + private final int port = 9559; private MetaClient metaClient; @@ -119,13 +119,13 @@ public void testListHosts() { public void testListOnlineHosts() { // stop one storage server - String cmd = "docker stop nebula-docker-compose_storaged0_1"; + String cmd = "docker stop nebula-docker-compose-storaged0-1"; Runtime runtime = Runtime.getRuntime(); try { Process p = runtime.exec(cmd); p.waitFor(5, TimeUnit.SECONDS); ProcessUtil.printProcessStatus(cmd, p); - Thread.sleep(5000); // wait to update the storaged's status to OFFLINE + Thread.sleep(10000); // wait to update the storaged's status to OFFLINE } catch (Exception e) { LOGGER.error("stop docker service error, ", e); assert (false); @@ -137,10 +137,11 @@ public void testListOnlineHosts() { assert (false); } } + System.out.println("listHosts size:" + metaClient.listHosts().size()); assert (metaClient.listHosts().size() == 2); try { - runtime.exec("docker start nebula-docker-compose_storaged0_1") + runtime.exec("docker start nebula-docker-compose-storaged0-1") .waitFor(5, TimeUnit.SECONDS); Thread.sleep(5000); } catch (Exception e) { @@ -162,7 +163,7 @@ public void testCASignedSSLMetaClient() { "src/test/resources/ssl/client.key"); metaClient = new MetaClient(Arrays.asList(new HostAddress(address, 8559)), - 3000, 1, 1, true, sslParam); + 3000, 1, 1, true, sslParam); metaClient.connect(); List tags = metaClient.getTags("testMetaCA"); @@ -190,7 +191,7 @@ public void testSelfSignedSSLMetaClient() { "src/test/resources/ssl/client.key", ""); metaClient = new MetaClient(Arrays.asList(new HostAddress(address, 7559)), - 3000, 1, 1, true, sslParam); + 3000, 1, 1, true, sslParam); metaClient.connect(); List tags = metaClient.getTags("testMetaSelf");