未验证 提交 84046cdb 编写于 作者: H huolibo 提交者: GitHub

fix multi call close error (#10412)

上级 d36d0dd0
...@@ -65,8 +65,7 @@ public class RestfulDriver extends AbstractDriver { ...@@ -65,8 +65,7 @@ public class RestfulDriver extends AbstractDriver {
} }
String loginUrl; String loginUrl;
String batchLoad = info.getProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD); String batchLoad = info.getProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD);
// if (Boolean.parseBoolean(batchLoad)) { if (Boolean.parseBoolean(batchLoad)) {
if (false) {
loginUrl = "ws://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST) loginUrl = "ws://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST)
+ ":" + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/ws"; + ":" + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/ws";
WSClient client; WSClient client;
......
...@@ -25,7 +25,7 @@ public abstract class AbstractWSResultSet extends AbstractResultSet { ...@@ -25,7 +25,7 @@ public abstract class AbstractWSResultSet extends AbstractResultSet {
protected final RequestFactory factory; protected final RequestFactory factory;
protected final long queryId; protected final long queryId;
protected boolean isClosed; protected volatile boolean isClosed;
// meta // meta
protected final ResultSetMetaData metaData; protected final ResultSetMetaData metaData;
protected final List<RestfulResultSet.Field> fields = new ArrayList<>(); protected final List<RestfulResultSet.Field> fields = new ArrayList<>();
...@@ -105,10 +105,14 @@ public abstract class AbstractWSResultSet extends AbstractResultSet { ...@@ -105,10 +105,14 @@ public abstract class AbstractWSResultSet extends AbstractResultSet {
@Override @Override
public void close() throws SQLException { public void close() throws SQLException {
this.isClosed = true; synchronized (this) {
if (result != null && !result.isEmpty() && !isCompleted) { if (!this.isClosed) {
FetchReq fetchReq = new FetchReq(queryId, queryId); this.isClosed = true;
transport.sendWithoutRep(new Request(Action.FREE_RESULT.getAction(), fetchReq)); if (result != null && !result.isEmpty() && !isCompleted) {
FetchReq fetchReq = new FetchReq(queryId, queryId);
transport.sendWithoutRep(new Request(Action.FREE_RESULT.getAction(), fetchReq));
}
}
} }
} }
......
...@@ -95,7 +95,6 @@ public class WSClient extends WebSocketClient implements AutoCloseable { ...@@ -95,7 +95,6 @@ public class WSClient extends WebSocketClient implements AutoCloseable {
long id = bytes.getLong(); long id = bytes.getLong();
ResponseFuture remove = inFlightRequest.remove(Action.FETCH_BLOCK.getAction(), id); ResponseFuture remove = inFlightRequest.remove(Action.FETCH_BLOCK.getAction(), id);
if (null != remove) { if (null != remove) {
// FetchBlockResp fetchBlockResp = new FetchBlockResp(id, bytes.slice());
FetchBlockResp fetchBlockResp = new FetchBlockResp(id, bytes); FetchBlockResp fetchBlockResp = new FetchBlockResp(id, bytes);
remove.getFuture().complete(fetchBlockResp); remove.getFuture().complete(fetchBlockResp);
} }
......
...@@ -53,8 +53,12 @@ public class WSStatement extends AbstractStatement { ...@@ -53,8 +53,12 @@ public class WSStatement extends AbstractStatement {
@Override @Override
public void close() throws SQLException { public void close() throws SQLException {
if (!isClosed()) if (!isClosed()) {
this.closed = true; this.closed = true;
if (resultSet != null && !resultSet.isClosed()) {
resultSet.close();
}
}
} }
@Override @Override
......
...@@ -15,6 +15,7 @@ public class RestfulDatabaseMetaDataTest { ...@@ -15,6 +15,7 @@ public class RestfulDatabaseMetaDataTest {
private static final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; private static final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
private static Connection connection; private static Connection connection;
private static RestfulDatabaseMetaData metaData; private static RestfulDatabaseMetaData metaData;
private static final String dbName = "test";
@Test @Test
public void unwrap() throws SQLException { public void unwrap() throws SQLException {
...@@ -1092,9 +1093,9 @@ public class RestfulDatabaseMetaDataTest { ...@@ -1092,9 +1093,9 @@ public class RestfulDatabaseMetaDataTest {
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection(url, properties); connection = DriverManager.getConnection(url, properties);
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
stmt.execute("drop database if exists log"); stmt.execute("drop database if exists " + dbName);
stmt.execute("create database if not exists log precision 'us'"); stmt.execute("create database if not exists " + dbName + " precision 'us'");
stmt.execute("use log"); stmt.execute("use " + dbName);
stmt.execute("create table `dn` (ts TIMESTAMP,cpu_taosd FLOAT,cpu_system FLOAT,cpu_cores INT,mem_taosd FLOAT,mem_system FLOAT,mem_total INT,disk_used FLOAT,disk_total INT,band_speed FLOAT,io_read FLOAT,io_write FLOAT,req_http INT,req_select INT,req_insert INT) TAGS (dnodeid INT,fqdn BINARY(128))"); stmt.execute("create table `dn` (ts TIMESTAMP,cpu_taosd FLOAT,cpu_system FLOAT,cpu_cores INT,mem_taosd FLOAT,mem_system FLOAT,mem_total INT,disk_used FLOAT,disk_total INT,band_speed FLOAT,io_read FLOAT,io_write FLOAT,req_http INT,req_select INT,req_insert INT) TAGS (dnodeid INT,fqdn BINARY(128))");
stmt.execute("insert into dn1 using dn tags(1,'a') (ts) values(now)"); stmt.execute("insert into dn1 using dn tags(1,'a') (ts) values(now)");
......
...@@ -32,9 +32,7 @@ public class WSQueryTest { ...@@ -32,9 +32,7 @@ public class WSQueryTest {
public void queryBlock() throws InterruptedException { public void queryBlock() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1000); CountDownLatch latch = new CountDownLatch(1000);
IntStream.range(1, 10000).limit(1000).parallel().forEach(x -> { IntStream.range(1, 10000).limit(1000).parallel().forEach(x -> {
try { try (Statement statement = connection.createStatement()) {
Statement statement = connection.createStatement();
statement.execute("insert into " + databaseName + "." + tableName + " values(now+100s, 100)"); statement.execute("insert into " + databaseName + "." + tableName + " values(now+100s, 100)");
ResultSet resultSet = statement.executeQuery("select * from " + databaseName + "." + tableName); ResultSet resultSet = statement.executeQuery("select * from " + databaseName + "." + tableName);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册