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

fix multi call close error (#10412)

上级 d36d0dd0
......@@ -65,8 +65,7 @@ public class RestfulDriver extends AbstractDriver {
}
String loginUrl;
String batchLoad = info.getProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD);
// if (Boolean.parseBoolean(batchLoad)) {
if (false) {
if (Boolean.parseBoolean(batchLoad)) {
loginUrl = "ws://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST)
+ ":" + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/ws";
WSClient client;
......
......@@ -25,7 +25,7 @@ public abstract class AbstractWSResultSet extends AbstractResultSet {
protected final RequestFactory factory;
protected final long queryId;
protected boolean isClosed;
protected volatile boolean isClosed;
// meta
protected final ResultSetMetaData metaData;
protected final List<RestfulResultSet.Field> fields = new ArrayList<>();
......@@ -105,10 +105,14 @@ public abstract class AbstractWSResultSet extends AbstractResultSet {
@Override
public void close() throws SQLException {
this.isClosed = true;
if (result != null && !result.isEmpty() && !isCompleted) {
FetchReq fetchReq = new FetchReq(queryId, queryId);
transport.sendWithoutRep(new Request(Action.FREE_RESULT.getAction(), fetchReq));
synchronized (this) {
if (!this.isClosed) {
this.isClosed = true;
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 {
long id = bytes.getLong();
ResponseFuture remove = inFlightRequest.remove(Action.FETCH_BLOCK.getAction(), id);
if (null != remove) {
// FetchBlockResp fetchBlockResp = new FetchBlockResp(id, bytes.slice());
FetchBlockResp fetchBlockResp = new FetchBlockResp(id, bytes);
remove.getFuture().complete(fetchBlockResp);
}
......
......@@ -53,8 +53,12 @@ public class WSStatement extends AbstractStatement {
@Override
public void close() throws SQLException {
if (!isClosed())
if (!isClosed()) {
this.closed = true;
if (resultSet != null && !resultSet.isClosed()) {
resultSet.close();
}
}
}
@Override
......
......@@ -15,6 +15,7 @@ public class RestfulDatabaseMetaDataTest {
private static final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
private static Connection connection;
private static RestfulDatabaseMetaData metaData;
private static final String dbName = "test";
@Test
public void unwrap() throws SQLException {
......@@ -1092,9 +1093,9 @@ public class RestfulDatabaseMetaDataTest {
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection(url, properties);
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists log");
stmt.execute("create database if not exists log precision 'us'");
stmt.execute("use log");
stmt.execute("drop database if exists " + dbName);
stmt.execute("create database if not exists " + dbName + " precision 'us'");
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("insert into dn1 using dn tags(1,'a') (ts) values(now)");
......
......@@ -32,9 +32,7 @@ public class WSQueryTest {
public void queryBlock() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1000);
IntStream.range(1, 10000).limit(1000).parallel().forEach(x -> {
try {
Statement statement = connection.createStatement();
try (Statement statement = connection.createStatement()) {
statement.execute("insert into " + databaseName + "." + tableName + " values(now+100s, 100)");
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.
先完成此消息的编辑!
想要评论请 注册