Skip to content

Commit

Permalink
Cherry-pick bugfix to V2.0.1 branch (#334)
Browse files Browse the repository at this point in the history
* Fix reconnect failed when all connections are idle status (#303)

* fix reconnect failed when all connection are broken idle

* add test

* fix null object (#301)

* fix thread pool while iterate result (#311)

* fix thread pool while iterate result

* add close for example

* 这里由于getIdleConnNum()被调用了两次, (#319)

fix getConnection() under the high concurrency return the wrong result

Co-authored-by: laura-ding <[email protected]>

* fix the toString of path (#327)

* Add SessionsManager and test (#330)

* add session manager

* Add comments

* modify get index

* Added reconnection handling for all service exceptions

* fix encoder without string col (#290)

* fix encoder with chinese value (#308)

Co-authored-by: Anqi <[email protected]>

* delete SessionManager and fix confilct

* filter online storaged hosts & add test (#326)

* filter the online hosts for storaged

* add test for listHosts

* add expired_time_factor config

* extract printProcessStatus function as util

* fix comments

* get the latest schema & add test (#316)

* get the latest schema

* add test for multi version schema

* add vid type for CREATE SPACE NGQL

* add vid type

* update vid length

Co-authored-by: laura-ding <[email protected]>

* modify the config of the pom to auto deploy (#329)

* cherry-pick bugfix

* modify the version

* modify version

* fix metaclient test

* fix timeout problem

* modify the waittime

Co-authored-by: Anqi <[email protected]>
Co-authored-by: Zhang Binbin <[email protected]>
  • Loading branch information
3 people authored Aug 10, 2021
1 parent 923bc04 commit 1e88e0f
Show file tree
Hide file tree
Showing 35 changed files with 814 additions and 178 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/deploy_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy release to the Maven Central Repository

on:
release:
types:
- published

jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- name: Check out Git repository
uses: actions/checkout@v2

- name: Install Java and Maven
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Install nebula-graph
run: |
mkdir tmp
pushd tmp
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
sleep 10
popd
popd
- name: Deploy Release to Maven package
uses: samuelmeuli/action-maven-publish@v1
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
nexus_username: ${{ secrets.OSSRH_USERNAME }}
nexus_password: ${{ secrets.OSSRH_TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/deploy_snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy snapshot to the Maven Central Repository

on:
push:
branches: [ master ]
schedule:
- cron: '0 6 * * *'

jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- name: Check out Git repository
uses: actions/checkout@v2

- name: Install Java and Maven
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Install nebula-graph
run: |
mkdir tmp
pushd tmp
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
sleep 10
popd
popd
- name: Deploy Snapshot to Maven package
uses: samuelmeuli/action-maven-publish@v1
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
nexus_username: ${{ secrets.OSSRH_USERNAME }}
nexus_password: ${{ secrets.OSSRH_TOKEN }}
5 changes: 4 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches:
- master
- 'v[0-9]+.*'


jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ There are the version correspondence between client and Nebula:
| 1.1.0 | 1.1.0,1.2.0 |
| 2.0.0-beta | 2.0.0-beta |
| 2.0.0-rc1 | 2.0.0-rc1 |
| 2.0.0 | 2.0.0 |
| 2.0.0/2.0.1 | 2.0.0/2.0.1 |
| 2.0.0-SNAPSHOT| 2.0.0-nightly |

## Graph client example
Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.vesoft</groupId>
<artifactId>nebula</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class PathWrapper {
private List<Segment> segments = new ArrayList<>();
private List<Node> nodes = new ArrayList<>();
private List<Relationship> relationships = new ArrayList<>();
private Path path = null;

public static class Segment {
Node startNode;
Expand Down Expand Up @@ -144,6 +145,7 @@ public PathWrapper(Path path) throws InvalidValueException, UnsupportedEncodingE
this.segments = new ArrayList<>();
return;
}
this.path = path;
nodes.add(new Node(path.src));
List<Value> vids = new ArrayList<>();
vids.add(path.src.vid);
Expand Down Expand Up @@ -190,48 +192,28 @@ public PathWrapper(Path path) throws InvalidValueException, UnsupportedEncodingE
@Override
public String toString() {
try {
Node startNode = getStartNode();
List<String> edgeStrs = new ArrayList<>();
if (segments.size() >= 1) {
for (int i = 0; i < relationships.size(); i++) {
Relationship relationship = relationships.get(i);
List<String> propStrs = new ArrayList<>();
Map<String, ValueWrapper> props = segments.get(0).getRelationShip().properties();
Map<String, ValueWrapper> props = relationship.properties();
for (String key : props.keySet()) {
propStrs.add(key + ":" + props.get(key).toString());
propStrs.add(key + ": " + props.get(key).toString());
}
if (segments.get(0).getStartNode() == startNode) {
Step step = path.steps.get(i);
Node node = new Node(step.dst);
if (step.type > 0) {
edgeStrs.add(String.format("-[:%s@%d{%s}]->%s",
segments.get(0).getRelationShip().edgeName(),
segments.get(0).getRelationShip().ranking(),
relationship.edgeName(),
relationship.ranking(),
String.join(", ", propStrs),
segments.get(0).getEndNode().toString()));
node.toString()));
} else {
edgeStrs.add(String.format("<-[:%s@%d{%s}]-%s",
segments.get(0).getRelationShip().edgeName(),
segments.get(0).getRelationShip().ranking(),
relationship.edgeName(),
relationship.ranking(),
String.join(", ", propStrs),
segments.get(0).getStartNode().toString()));
}

}

for (int i = 1; i < segments.size(); i++) {
List<String> propStrs = new ArrayList<>();
Map<String, ValueWrapper> props = segments.get(0).getRelationShip().properties();
for (String key : props.keySet()) {
propStrs.add(key + ":" + props.get(key).toString());
}
if (segments.get(i).getStartNode() == segments.get(i - 1).getStartNode()) {
edgeStrs.add(String.format("-[:%s@%d{%s}]->%s",
segments.get(i).getRelationShip().edgeName(),
segments.get(i).getRelationShip().ranking(),
String.join(", ", propStrs),
segments.get(i).getEndNode().toString()));
} else {
edgeStrs.add(String.format("<-[:%s@%d{%s}]-%s",
segments.get(i).getRelationShip().edgeName(),
segments.get(i).getRelationShip().ranking(),
String.join(", ", propStrs),
segments.get(i).getStartNode().toString()));
node.toString()));
}
}
return String.format("%s%s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class ResultSet {
private final ExecutionResponse response;
private List<String> columnNames;
private List<String> columnNames = new ArrayList<>();
private final String decodeType = "utf-8";

public static class Record implements Iterable<ValueWrapper> {
Expand Down Expand Up @@ -131,7 +131,6 @@ public ResultSet(ExecutionResponse resp) {
}
this.response = resp;
if (resp.data != null) {
this.columnNames = Lists.newArrayListWithCapacity(resp.data.column_names.size());
// space name's charset is 'utf-8'
for (byte[] column : resp.data.column_names) {
this.columnNames.add(new String(column));
Expand Down Expand Up @@ -290,6 +289,10 @@ public List<Row> getRows() {

@Override
public String toString() {
// When error, print the raw data directly
if (!isSucceeded()) {
return response.toString();
}
int i = 0;
List<String> rowStrs = new ArrayList<>();
while (i < rowsSize()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class IOErrorException extends java.lang.Exception {

public static final int E_CONNECT_BROKEN = 2;

public static final int E_TIME_OUT = 4;

public static final int E_NO_OPEN = 5;

private int type = E_UNKNOWN;

public IOErrorException(int errorType, String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

package com.vesoft.nebula.client.graph.exception;

public class InvalidSessionException extends RuntimeException {
public InvalidSessionException() {
super("The session was released, could not use again.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ public boolean validateObject(PooledObject<SyncConnection> p) {
return true;
}

@Override
public void activateObject(PooledObject<SyncConnection> p) throws Exception {
if (p.getObject() == null) {
throw new RuntimeException("The connection is null.");
}
if (!p.getObject().ping()) {
throw new RuntimeException("The connection is broken.");
}
super.activateObject(p);
}

public boolean init() {
return loadBalancer.isServersOK();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public HostAddress getServerAddress() {

public abstract void open(HostAddress address, int timeout) throws IOErrorException;

protected abstract void reopen() throws IOErrorException;

public abstract void close();

public abstract boolean ping();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class NebulaPool {
private LoadBalancer loadBalancer;
private final Logger log = LoggerFactory.getLogger(this.getClass());
// the wait time to get idle connection, unit ms
private final int waitTime = 60 * 1000;
private final int waitTime = 0;

private List<HostAddress> hostToIp(List<HostAddress> addresses)
throws UnknownHostException {
Expand Down Expand Up @@ -62,7 +62,7 @@ private void checkConfig(NebulaPoolConfig config) {
}

public boolean init(List<HostAddress> addresses, NebulaPoolConfig config)
throws UnknownHostException, InvalidConfigException {
throws UnknownHostException, InvalidConfigException {
checkConfig(config);
List<HostAddress> newAddrs = hostToIp(addresses);
this.loadBalancer = new RoundRobinLoadBalancer(newAddrs, config.getTimeout());
Expand All @@ -88,31 +88,18 @@ public void close() {

public Session getSession(String userName, String password, boolean reconnect)
throws NotValidConnectionException, IOErrorException, AuthFailedException {
SyncConnection connection = null;
try {
// If no idle connection, try once
int retry = getIdleConnNum() == 0 ? 1 : getIdleConnNum();
SyncConnection connection = null;
while (retry-- > 0) {
connection = objectPool.borrowObject(waitTime);
if (connection == null || !connection.ping()) {
continue;
}
break;
}
if (connection == null) {
throw new NotValidConnectionException("Get connection object failed.");
}
log.info(String.format("Get connection to %s:%d",
connection.getServerAddress().getHost(),
connection.getServerAddress().getPort()));
connection = getConnection();
long sessionID = connection.authenticate(userName, password);
return new Session(connection, sessionID, this.objectPool, reconnect);
} catch (NotValidConnectionException | AuthFailedException | IOErrorException e) {
return new Session(connection, sessionID, this, reconnect);
} catch (AuthFailedException | IOErrorException e) {
// if get the connection succeeded, but authenticate failed,
// needs to return connection to pool
if (connection != null) {
setInvalidateConnection(connection);
}
throw e;
} catch (IllegalStateException e) {
throw new NotValidConnectionException(e.getMessage());
} catch (Exception e) {
throw new IOErrorException(IOErrorException.E_UNKNOWN, e.getMessage());
}
}

Expand All @@ -133,4 +120,24 @@ public void updateServerStatus() {
((ConnObjectPool)objectPool.getFactory()).updateServerStatus();
}
}

protected void setInvalidateConnection(SyncConnection connection) {
try {
objectPool.invalidateObject(connection);
} catch (Exception e) {
log.error("Set invalidate object failed");
}
}

protected void returnConnection(SyncConnection connection) {
objectPool.returnObject(connection);
}

protected SyncConnection getConnection() throws NotValidConnectionException {
try {
return objectPool.borrowObject(waitTime);
} catch (Exception e) {
throw new NotValidConnectionException(e.getMessage());
}
}
}
Loading

0 comments on commit 1e88e0f

Please sign in to comment.