Skip to content

Commit

Permalink
fix socket timewait for storage client (#607)
Browse files Browse the repository at this point in the history
* fix socket timewait for storage client

* update docker compose

* update docker compose

* update

* update

* update storage container name
  • Loading branch information
Nicole00 authored Oct 14, 2024
1 parent fa6bcf2 commit c3fa62a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public StorageConnPoolFactory(StoragePoolConfig config) {
@Override
public PooledObject<GraphStorageConnection> makeObject(HostAddress address) throws Exception {
GraphStorageConnection connection = new GraphStorageConnection();
connection.open(
address,
config.getTimeout(),
config.isEnableSSL(),
config.getSslParam());
return new DefaultPooledObject<>(connection);
}

Expand All @@ -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;
}
}
Expand All @@ -56,11 +61,12 @@ public boolean validateObject(HostAddress hostAndPort,
public void activateObject(HostAddress address,
PooledObject<GraphStorageConnection> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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<TagItem> tags = metaClient.getTags("testMetaCA");
Expand Down Expand Up @@ -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<TagItem> tags = metaClient.getTags("testMetaSelf");
Expand Down

0 comments on commit c3fa62a

Please sign in to comment.