diff --git a/session/src/main/java/org/apache/iotdb/session/Session.java b/session/src/main/java/org/apache/iotdb/session/Session.java index fc3be40079029e00d2ffd44435eeef6d5fbb2c5e..4c1eb92a79f6e72feb8d5499444769b18a091c58 100644 --- a/session/src/main/java/org/apache/iotdb/session/Session.java +++ b/session/src/main/java/org/apache/iotdb/session/Session.java @@ -32,8 +32,6 @@ import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TCompactProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransportException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.time.ZoneId; @@ -44,7 +42,7 @@ public class Session { private String username; private String password; private final TSProtocolVersion protocolVersion = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1; - public TSIService.Iface client = null; + private TSIService.Iface client = null; private TS_SessionHandle sessionHandle = null; private TSocket transport; private boolean isClosed = true; @@ -65,11 +63,11 @@ public class Session { this.password = password; } - public void open() throws IoTDBSessionException { + public synchronized void open() throws IoTDBSessionException { open(false, 0); } - public void open(boolean enableRPCCompression, int connectionTimeoutInMs) + public synchronized void open(boolean enableRPCCompression, int connectionTimeoutInMs) throws IoTDBSessionException { if (!isClosed) { return; @@ -125,7 +123,7 @@ public class Session { } - public void close() throws IoTDBSessionException { + public synchronized void close() throws IoTDBSessionException { if (isClosed) { return; } @@ -142,7 +140,7 @@ public class Session { } } - public TSExecuteBatchStatementResp insertBatch(RowBatch rowBatch) throws IoTDBSessionException { + public synchronized TSExecuteBatchStatementResp insertBatch(RowBatch rowBatch) throws IoTDBSessionException { TSBatchInsertionReq request = new TSBatchInsertionReq(); request.deviceId = rowBatch.deviceId; for (MeasurementSchema measurementSchema: rowBatch.measurements) { @@ -160,7 +158,7 @@ public class Session { } } - public TSRPCResp insert(String deviceId, long time, List measurements, List values) + public synchronized TSRPCResp insert(String deviceId, long time, List measurements, List values) throws IoTDBSessionException { TSInsertReq request = new TSInsertReq(); request.setDeviceId(deviceId); @@ -175,7 +173,7 @@ public class Session { } } - public TSRPCResp setStorageGroup(String storageGroupId) throws IoTDBSessionException { + public synchronized TSRPCResp setStorageGroup(String storageGroupId) throws IoTDBSessionException { TSSetStorageGroupReq request = new TSSetStorageGroupReq(); request.setStorageGroupId(storageGroupId); @@ -186,7 +184,7 @@ public class Session { } } - public TSRPCResp createTimeseries(String path, TSDataType dataType, TSEncoding encoding, CompressionType compressor) throws IoTDBSessionException { + public synchronized TSRPCResp createTimeseries(String path, TSDataType dataType, TSEncoding encoding, CompressionType compressor) throws IoTDBSessionException { TSCreateTimeseriesReq request = new TSCreateTimeseriesReq(); request.setPath(path); request.setDataType(dataType.ordinal()); @@ -200,7 +198,7 @@ public class Session { } } - public String getTimeZone() throws TException, IoTDBRPCException { + public synchronized String getTimeZone() throws TException, IoTDBRPCException { if (zoneId != null) { return zoneId.toString(); } @@ -210,7 +208,7 @@ public class Session { return resp.getTimeZone(); } - public void setTimeZone(String zoneId) throws TException, IoTDBRPCException { + public synchronized void setTimeZone(String zoneId) throws TException, IoTDBRPCException { TSSetTimeZoneReq req = new TSSetTimeZoneReq(zoneId); TSRPCResp resp = client.setTimeZone(req); RpcUtils.verifySuccess(resp.getStatus());