• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #9634

pending completion
#9634

push

travis_ci

web-flow
Add session interface of faster last query in one device

190 of 190 new or added lines in 5 files covered. (100.0%)

79025 of 165424 relevant lines covered (47.77%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.92
/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.iotdb.session;
21

22
import org.apache.iotdb.common.rpc.thrift.TAggregationType;
23
import org.apache.iotdb.common.rpc.thrift.TEndPoint;
24
import org.apache.iotdb.common.rpc.thrift.TSStatus;
25
import org.apache.iotdb.isession.SessionConfig;
26
import org.apache.iotdb.isession.SessionDataSet;
27
import org.apache.iotdb.rpc.IoTDBConnectionException;
28
import org.apache.iotdb.rpc.RedirectException;
29
import org.apache.iotdb.rpc.RpcTransportFactory;
30
import org.apache.iotdb.rpc.RpcUtils;
31
import org.apache.iotdb.rpc.StatementExecutionException;
32
import org.apache.iotdb.service.rpc.thrift.IClientRPCService;
33
import org.apache.iotdb.service.rpc.thrift.TCreateTimeseriesUsingSchemaTemplateReq;
34
import org.apache.iotdb.service.rpc.thrift.TSAggregationQueryReq;
35
import org.apache.iotdb.service.rpc.thrift.TSAppendSchemaTemplateReq;
36
import org.apache.iotdb.service.rpc.thrift.TSBackupConfigurationResp;
37
import org.apache.iotdb.service.rpc.thrift.TSCloseSessionReq;
38
import org.apache.iotdb.service.rpc.thrift.TSConnectionInfoResp;
39
import org.apache.iotdb.service.rpc.thrift.TSCreateAlignedTimeseriesReq;
40
import org.apache.iotdb.service.rpc.thrift.TSCreateMultiTimeseriesReq;
41
import org.apache.iotdb.service.rpc.thrift.TSCreateSchemaTemplateReq;
42
import org.apache.iotdb.service.rpc.thrift.TSCreateTimeseriesReq;
43
import org.apache.iotdb.service.rpc.thrift.TSDeleteDataReq;
44
import org.apache.iotdb.service.rpc.thrift.TSDropSchemaTemplateReq;
45
import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementReq;
46
import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp;
47
import org.apache.iotdb.service.rpc.thrift.TSFastLastDataQueryForOneDeviceReq;
48
import org.apache.iotdb.service.rpc.thrift.TSInsertRecordReq;
49
import org.apache.iotdb.service.rpc.thrift.TSInsertRecordsOfOneDeviceReq;
50
import org.apache.iotdb.service.rpc.thrift.TSInsertRecordsReq;
51
import org.apache.iotdb.service.rpc.thrift.TSInsertStringRecordReq;
52
import org.apache.iotdb.service.rpc.thrift.TSInsertStringRecordsOfOneDeviceReq;
53
import org.apache.iotdb.service.rpc.thrift.TSInsertStringRecordsReq;
54
import org.apache.iotdb.service.rpc.thrift.TSInsertTabletReq;
55
import org.apache.iotdb.service.rpc.thrift.TSInsertTabletsReq;
56
import org.apache.iotdb.service.rpc.thrift.TSLastDataQueryReq;
57
import org.apache.iotdb.service.rpc.thrift.TSOpenSessionReq;
58
import org.apache.iotdb.service.rpc.thrift.TSOpenSessionResp;
59
import org.apache.iotdb.service.rpc.thrift.TSPruneSchemaTemplateReq;
60
import org.apache.iotdb.service.rpc.thrift.TSQueryTemplateReq;
61
import org.apache.iotdb.service.rpc.thrift.TSQueryTemplateResp;
62
import org.apache.iotdb.service.rpc.thrift.TSRawDataQueryReq;
63
import org.apache.iotdb.service.rpc.thrift.TSSetSchemaTemplateReq;
64
import org.apache.iotdb.service.rpc.thrift.TSSetTimeZoneReq;
65
import org.apache.iotdb.service.rpc.thrift.TSUnsetSchemaTemplateReq;
66
import org.apache.iotdb.session.util.SessionUtils;
67
import org.apache.iotdb.tsfile.utils.Pair;
68

69
import org.apache.thrift.TException;
70
import org.apache.thrift.protocol.TBinaryProtocol;
71
import org.apache.thrift.protocol.TCompactProtocol;
72
import org.apache.thrift.transport.TTransport;
73
import org.apache.thrift.transport.TTransportException;
74
import org.slf4j.Logger;
75
import org.slf4j.LoggerFactory;
76

77
import java.security.SecureRandom;
78
import java.time.ZoneId;
79
import java.util.ArrayList;
80
import java.util.List;
81
import java.util.StringJoiner;
82

83
public class SessionConnection {
84

85
  private static final Logger logger = LoggerFactory.getLogger(SessionConnection.class);
1✔
86
  public static final String MSG_RECONNECTION_FAIL =
87
      "Fail to reconnect to server. Please check server status.";
88
  private Session session;
89
  private TTransport transport;
90
  private IClientRPCService.Iface client;
91
  private long sessionId;
92
  private long statementId;
93
  private ZoneId zoneId;
94
  private TEndPoint endPoint;
95
  private List<TEndPoint> endPointList = new ArrayList<>();
1✔
96
  private boolean enableRedirect = false;
1✔
97

98
  // TestOnly
99
  public SessionConnection() {}
1✔
100

101
  public SessionConnection(Session session, TEndPoint endPoint, ZoneId zoneId)
102
      throws IoTDBConnectionException {
×
103
    this.session = session;
×
104
    this.endPoint = endPoint;
×
105
    endPointList.add(endPoint);
×
106
    this.zoneId = zoneId == null ? ZoneId.systemDefault() : zoneId;
×
107
    try {
108
      init(endPoint);
×
109
    } catch (IoTDBConnectionException e) {
×
110
      throw new IoTDBConnectionException(logForReconnectionFailure());
×
111
    }
×
112
  }
×
113

114
  public SessionConnection(Session session, ZoneId zoneId) throws IoTDBConnectionException {
×
115
    this.session = session;
×
116
    this.zoneId = zoneId == null ? ZoneId.systemDefault() : zoneId;
×
117
    this.endPointList = SessionUtils.parseSeedNodeUrls(session.nodeUrls);
×
118
    initClusterConn();
×
119
  }
×
120

121
  private void init(TEndPoint endPoint) throws IoTDBConnectionException {
122
    RpcTransportFactory.setDefaultBufferCapacity(session.thriftDefaultBufferSize);
×
123
    RpcTransportFactory.setThriftMaxFrameSize(session.thriftMaxFrameSize);
×
124
    try {
125
      transport =
×
126
          RpcTransportFactory.INSTANCE.getTransport(
×
127
              // as there is a try-catch already, we do not need to use TSocket.wrap
128
              endPoint.getIp(), endPoint.getPort(), session.connectionTimeoutInMs);
×
129
      if (!transport.isOpen()) {
×
130
        transport.open();
×
131
      }
132
    } catch (TTransportException e) {
×
133
      throw new IoTDBConnectionException(e);
×
134
    }
×
135

136
    if (session.enableRPCCompression) {
×
137
      client = new IClientRPCService.Client(new TCompactProtocol(transport));
×
138
    } else {
139
      client = new IClientRPCService.Client(new TBinaryProtocol(transport));
×
140
    }
141
    client = RpcUtils.newSynchronizedClient(client);
×
142

143
    TSOpenSessionReq openReq = new TSOpenSessionReq();
×
144
    openReq.setUsername(session.username);
×
145
    openReq.setPassword(session.password);
×
146
    openReq.setZoneId(zoneId.toString());
×
147
    openReq.putToConfiguration("version", session.version.toString());
×
148

149
    try {
150
      TSOpenSessionResp openResp = client.openSession(openReq);
×
151

152
      RpcUtils.verifySuccess(openResp.getStatus());
×
153

154
      if (Session.protocolVersion.getValue() != openResp.getServerProtocolVersion().getValue()) {
×
155
        logger.warn(
×
156
            "Protocol differ, Client version is {}}, but Server version is {}",
157
            Session.protocolVersion.getValue(),
×
158
            openResp.getServerProtocolVersion().getValue());
×
159
        // less than 0.10
160
        if (openResp.getServerProtocolVersion().getValue() == 0) {
×
161
          throw new TException(
×
162
              String.format(
×
163
                  "Protocol not supported, Client version is %s, but Server version is %s",
164
                  Session.protocolVersion.getValue(),
×
165
                  openResp.getServerProtocolVersion().getValue()));
×
166
        }
167
      }
168

169
      sessionId = openResp.getSessionId();
×
170
      statementId = client.requestStatementId(sessionId);
×
171

172
    } catch (Exception e) {
×
173
      transport.close();
×
174
      throw new IoTDBConnectionException(e);
×
175
    }
×
176
  }
×
177

178
  @SuppressWarnings({"squid:S1751"}) // Loops with at most one iteration should be refactored
179
  private void initClusterConn() throws IoTDBConnectionException {
180
    for (TEndPoint tEndPoint : endPointList) {
×
181
      try {
182
        session.defaultEndPoint = tEndPoint;
×
183
        init(tEndPoint);
×
184
      } catch (IoTDBConnectionException e) {
×
185
        if (!reconnect()) {
×
186
          logger.error("Cluster has no nodes to connect");
×
187
          throw new IoTDBConnectionException(logForReconnectionFailure());
×
188
        }
189
      }
×
190
      break;
×
191
    }
192
  }
×
193

194
  public void close() throws IoTDBConnectionException {
195
    TSCloseSessionReq req = new TSCloseSessionReq(sessionId);
×
196
    try {
197
      client.closeSession(req);
×
198
    } catch (TException e) {
×
199
      throw new IoTDBConnectionException(
×
200
          "Error occurs when closing session at server. Maybe server is down.", e);
201
    } finally {
202
      if (transport != null) {
×
203
        transport.close();
×
204
      }
205
    }
206
  }
×
207

208
  protected IClientRPCService.Iface getClient() {
209
    return client;
×
210
  }
211

212
  protected void setTimeZone(String zoneId)
213
      throws StatementExecutionException, IoTDBConnectionException {
214
    TSSetTimeZoneReq req = new TSSetTimeZoneReq(sessionId, zoneId);
×
215
    TSStatus resp;
216
    try {
217
      resp = client.setTimeZone(req);
×
218
    } catch (TException e) {
×
219
      if (reconnect()) {
×
220
        try {
221
          req.setSessionId(sessionId);
×
222
          resp = client.setTimeZone(req);
×
223
        } catch (TException tException) {
×
224
          throw new IoTDBConnectionException(tException);
×
225
        }
×
226
      } else {
227
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
228
      }
229
    }
×
230
    RpcUtils.verifySuccess(resp);
×
231
    setTimeZoneOfSession(zoneId);
×
232
  }
×
233

234
  protected void setTimeZoneOfSession(String zoneId) {
235
    this.zoneId = ZoneId.of(zoneId);
×
236
  }
×
237

238
  protected String getTimeZone() {
239
    if (zoneId == null) {
×
240
      zoneId = ZoneId.systemDefault();
×
241
    }
242
    return zoneId.toString();
×
243
  }
244

245
  protected void setStorageGroup(String storageGroup)
246
      throws IoTDBConnectionException, StatementExecutionException {
247
    try {
248
      RpcUtils.verifySuccess(client.setStorageGroup(sessionId, storageGroup));
×
249
    } catch (TException e) {
×
250
      if (reconnect()) {
×
251
        try {
252
          RpcUtils.verifySuccess(client.setStorageGroup(sessionId, storageGroup));
×
253
        } catch (TException tException) {
×
254
          throw new IoTDBConnectionException(tException);
×
255
        }
×
256
      } else {
257
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
258
      }
259
    }
×
260
  }
×
261

262
  protected void deleteStorageGroups(List<String> storageGroups)
263
      throws IoTDBConnectionException, StatementExecutionException {
264
    try {
265
      RpcUtils.verifySuccess(client.deleteStorageGroups(sessionId, storageGroups));
×
266
    } catch (TException e) {
×
267
      if (reconnect()) {
×
268
        try {
269
          RpcUtils.verifySuccess(client.deleteStorageGroups(sessionId, storageGroups));
×
270
        } catch (TException tException) {
×
271
          throw new IoTDBConnectionException(tException);
×
272
        }
×
273
      } else {
274
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
275
      }
276
    }
×
277
  }
×
278

279
  protected void createTimeseries(TSCreateTimeseriesReq request)
280
      throws IoTDBConnectionException, StatementExecutionException {
281
    request.setSessionId(sessionId);
×
282
    try {
283
      RpcUtils.verifySuccess(client.createTimeseries(request));
×
284
    } catch (TException e) {
×
285
      if (reconnect()) {
×
286
        try {
287
          request.setSessionId(sessionId);
×
288
          RpcUtils.verifySuccess(client.createTimeseries(request));
×
289
        } catch (TException tException) {
×
290
          throw new IoTDBConnectionException(tException);
×
291
        }
×
292
      } else {
293
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
294
      }
295
    }
×
296
  }
×
297

298
  protected void createAlignedTimeseries(TSCreateAlignedTimeseriesReq request)
299
      throws IoTDBConnectionException, StatementExecutionException {
300
    request.setSessionId(sessionId);
×
301
    try {
302
      RpcUtils.verifySuccess(client.createAlignedTimeseries(request));
×
303
    } catch (TException e) {
×
304
      if (reconnect()) {
×
305
        try {
306
          request.setSessionId(sessionId);
×
307
          RpcUtils.verifySuccess(client.createAlignedTimeseries(request));
×
308
        } catch (TException tException) {
×
309
          throw new IoTDBConnectionException(tException);
×
310
        }
×
311
      } else {
312
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
313
      }
314
    }
×
315
  }
×
316

317
  protected void createMultiTimeseries(TSCreateMultiTimeseriesReq request)
318
      throws IoTDBConnectionException, StatementExecutionException {
319
    request.setSessionId(sessionId);
×
320
    try {
321
      RpcUtils.verifySuccess(client.createMultiTimeseries(request));
×
322
    } catch (TException e) {
×
323
      if (reconnect()) {
×
324
        try {
325
          request.setSessionId(sessionId);
×
326
          RpcUtils.verifySuccess(client.createMultiTimeseries(request));
×
327
        } catch (TException tException) {
×
328
          throw new IoTDBConnectionException(tException);
×
329
        }
×
330
      } else {
331
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
332
      }
333
    }
×
334
  }
×
335

336
  protected boolean checkTimeseriesExists(String path, long timeout)
337
      throws IoTDBConnectionException, StatementExecutionException {
338
    SessionDataSet dataSet = null;
×
339
    try {
340
      try {
341
        dataSet = executeQueryStatement(String.format("SHOW TIMESERIES %s", path), timeout);
×
342
      } catch (RedirectException e) {
×
343
        throw new StatementExecutionException("need to redirect query, should not see this.", e);
×
344
      }
×
345
      return dataSet.hasNext();
×
346
    } finally {
347
      if (dataSet != null) {
×
348
        dataSet.closeOperationHandle();
×
349
      }
350
    }
351
  }
352

353
  protected SessionDataSet executeQueryStatement(String sql, long timeout)
354
      throws StatementExecutionException, IoTDBConnectionException, RedirectException {
355
    TSExecuteStatementReq execReq = new TSExecuteStatementReq(sessionId, sql, statementId);
×
356
    execReq.setFetchSize(session.fetchSize);
×
357
    execReq.setTimeout(timeout);
×
358
    TSExecuteStatementResp execResp;
359
    try {
360
      execReq.setEnableRedirectQuery(enableRedirect);
×
361
      execResp = client.executeQueryStatementV2(execReq);
×
362
      RpcUtils.verifySuccessWithRedirection(execResp.getStatus());
×
363
    } catch (TException e) {
×
364
      if (reconnect()) {
×
365
        try {
366
          execReq.setSessionId(sessionId);
×
367
          execReq.setStatementId(statementId);
×
368
          execResp = client.executeQueryStatementV2(execReq);
×
369
        } catch (TException tException) {
×
370
          throw new IoTDBConnectionException(tException);
×
371
        }
×
372
      } else {
373
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
374
      }
375
    }
×
376

377
    RpcUtils.verifySuccess(execResp.getStatus());
×
378
    return new SessionDataSet(
×
379
        sql,
380
        execResp.getColumns(),
×
381
        execResp.getDataTypeList(),
×
382
        execResp.columnNameIndexMap,
383
        execResp.getQueryId(),
×
384
        statementId,
385
        client,
386
        sessionId,
387
        execResp.queryResult,
388
        execResp.isIgnoreTimeStamp(),
×
389
        timeout,
390
        execResp.moreData,
391
        session.fetchSize);
392
  }
393

394
  protected void executeNonQueryStatement(String sql)
395
      throws IoTDBConnectionException, StatementExecutionException {
396
    TSExecuteStatementReq execReq = new TSExecuteStatementReq(sessionId, sql, statementId);
×
397
    try {
398
      execReq.setEnableRedirectQuery(enableRedirect);
×
399
      TSExecuteStatementResp execResp = client.executeUpdateStatementV2(execReq);
×
400
      RpcUtils.verifySuccess(execResp.getStatus());
×
401
    } catch (TException e) {
×
402
      if (reconnect()) {
×
403
        try {
404
          execReq.setSessionId(sessionId);
×
405
          execReq.setStatementId(statementId);
×
406
          RpcUtils.verifySuccess(client.executeUpdateStatementV2(execReq).status);
×
407
        } catch (TException tException) {
×
408
          throw new IoTDBConnectionException(tException);
×
409
        }
×
410
      } else {
411
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
412
      }
413
    }
×
414
  }
×
415

416
  protected SessionDataSet executeRawDataQuery(
417
      List<String> paths, long startTime, long endTime, long timeOut)
418
      throws StatementExecutionException, IoTDBConnectionException, RedirectException {
419
    TSRawDataQueryReq execReq =
×
420
        new TSRawDataQueryReq(sessionId, paths, startTime, endTime, statementId);
421
    execReq.setFetchSize(session.fetchSize);
×
422
    execReq.setTimeout(timeOut);
×
423
    TSExecuteStatementResp execResp;
424
    try {
425
      execReq.setEnableRedirectQuery(enableRedirect);
×
426
      execResp = client.executeRawDataQueryV2(execReq);
×
427
      RpcUtils.verifySuccessWithRedirection(execResp.getStatus());
×
428
    } catch (TException e) {
×
429
      if (reconnect()) {
×
430
        try {
431
          execReq.setSessionId(sessionId);
×
432
          execReq.setStatementId(statementId);
×
433
          execResp = client.executeRawDataQueryV2(execReq);
×
434
        } catch (TException tException) {
×
435
          throw new IoTDBConnectionException(tException);
×
436
        }
×
437
      } else {
438
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
439
      }
440
    }
×
441

442
    RpcUtils.verifySuccess(execResp.getStatus());
×
443
    return new SessionDataSet(
×
444
        "",
445
        execResp.getColumns(),
×
446
        execResp.getDataTypeList(),
×
447
        execResp.columnNameIndexMap,
448
        execResp.getQueryId(),
×
449
        statementId,
450
        client,
451
        sessionId,
452
        execResp.queryResult,
453
        execResp.isIgnoreTimeStamp(),
×
454
        execResp.moreData);
455
  }
456

457
  protected Pair<SessionDataSet, TEndPoint> executeLastDataQueryForOneDevice(
458
      String db, String device, List<String> sensors, boolean isLegalPathNodes, long timeOut)
459
      throws StatementExecutionException, IoTDBConnectionException {
460
    TSFastLastDataQueryForOneDeviceReq req =
×
461
        new TSFastLastDataQueryForOneDeviceReq(sessionId, db, device, sensors, statementId);
462
    req.setFetchSize(session.fetchSize);
×
463
    req.setEnableRedirectQuery(enableRedirect);
×
464
    req.setLegalPathNodes(isLegalPathNodes);
×
465
    req.setTimeout(timeOut);
×
466
    TSExecuteStatementResp tsExecuteStatementResp = null;
×
467
    TEndPoint redirectedEndPoint = null;
×
468
    try {
469
      tsExecuteStatementResp = client.executeFastLastDataQueryForOneDeviceV2(req);
×
470
      RpcUtils.verifySuccessWithRedirection(tsExecuteStatementResp.getStatus());
×
471
    } catch (RedirectException e) {
×
472
      redirectedEndPoint = e.getEndPoint();
×
473
    } catch (TException e) {
×
474
      if (reconnect()) {
×
475
        try {
476
          req.setSessionId(sessionId);
×
477
          req.setStatementId(statementId);
×
478
          tsExecuteStatementResp = client.executeFastLastDataQueryForOneDeviceV2(req);
×
479
        } catch (TException tException) {
×
480
          throw new IoTDBConnectionException(tException);
×
481
        }
×
482
      } else {
483
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
484
      }
485
    }
×
486

487
    RpcUtils.verifySuccess(tsExecuteStatementResp.getStatus());
×
488
    return new Pair<>(
×
489
        new SessionDataSet(
490
            "",
491
            tsExecuteStatementResp.getColumns(),
×
492
            tsExecuteStatementResp.getDataTypeList(),
×
493
            tsExecuteStatementResp.columnNameIndexMap,
494
            tsExecuteStatementResp.getQueryId(),
×
495
            statementId,
496
            client,
497
            sessionId,
498
            tsExecuteStatementResp.queryResult,
499
            tsExecuteStatementResp.isIgnoreTimeStamp(),
×
500
            tsExecuteStatementResp.moreData),
501
        redirectedEndPoint);
502
  }
503

504
  protected SessionDataSet executeLastDataQuery(List<String> paths, long time, long timeOut)
505
      throws StatementExecutionException, IoTDBConnectionException, RedirectException {
506
    TSLastDataQueryReq tsLastDataQueryReq =
×
507
        new TSLastDataQueryReq(sessionId, paths, time, statementId);
508
    tsLastDataQueryReq.setFetchSize(session.fetchSize);
×
509
    tsLastDataQueryReq.setEnableRedirectQuery(enableRedirect);
×
510
    tsLastDataQueryReq.setTimeout(timeOut);
×
511
    TSExecuteStatementResp tsExecuteStatementResp;
512
    try {
513
      tsExecuteStatementResp = client.executeLastDataQueryV2(tsLastDataQueryReq);
×
514
      RpcUtils.verifySuccessWithRedirection(tsExecuteStatementResp.getStatus());
×
515
    } catch (TException e) {
×
516
      if (reconnect()) {
×
517
        try {
518
          tsLastDataQueryReq.setSessionId(sessionId);
×
519
          tsLastDataQueryReq.setStatementId(statementId);
×
520
          tsExecuteStatementResp = client.executeLastDataQueryV2(tsLastDataQueryReq);
×
521
        } catch (TException tException) {
×
522
          throw new IoTDBConnectionException(tException);
×
523
        }
×
524
      } else {
525
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
526
      }
527
    }
×
528

529
    RpcUtils.verifySuccess(tsExecuteStatementResp.getStatus());
×
530
    return new SessionDataSet(
×
531
        "",
532
        tsExecuteStatementResp.getColumns(),
×
533
        tsExecuteStatementResp.getDataTypeList(),
×
534
        tsExecuteStatementResp.columnNameIndexMap,
535
        tsExecuteStatementResp.getQueryId(),
×
536
        statementId,
537
        client,
538
        sessionId,
539
        tsExecuteStatementResp.queryResult,
540
        tsExecuteStatementResp.isIgnoreTimeStamp(),
×
541
        tsExecuteStatementResp.moreData);
542
  }
543

544
  protected SessionDataSet executeAggregationQuery(
545
      List<String> paths, List<TAggregationType> aggregations)
546
      throws StatementExecutionException, IoTDBConnectionException, RedirectException {
547
    TSAggregationQueryReq req = createAggregationQueryReq(paths, aggregations);
×
548
    return executeAggregationQuery(req);
×
549
  }
550

551
  protected SessionDataSet executeAggregationQuery(
552
      List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime)
553
      throws StatementExecutionException, IoTDBConnectionException, RedirectException {
554
    TSAggregationQueryReq req = createAggregationQueryReq(paths, aggregations);
×
555
    req.setStartTime(startTime);
×
556
    req.setEndTime(endTime);
×
557
    return executeAggregationQuery(req);
×
558
  }
559

560
  protected SessionDataSet executeAggregationQuery(
561
      List<String> paths,
562
      List<TAggregationType> aggregations,
563
      long startTime,
564
      long endTime,
565
      long interval)
566
      throws StatementExecutionException, IoTDBConnectionException, RedirectException {
567
    TSAggregationQueryReq req = createAggregationQueryReq(paths, aggregations);
×
568
    req.setStartTime(startTime);
×
569
    req.setEndTime(endTime);
×
570
    req.setInterval(interval);
×
571
    return executeAggregationQuery(req);
×
572
  }
573

574
  protected SessionDataSet executeAggregationQuery(
575
      List<String> paths,
576
      List<TAggregationType> aggregations,
577
      long startTime,
578
      long endTime,
579
      long interval,
580
      long slidingStep)
581
      throws StatementExecutionException, IoTDBConnectionException, RedirectException {
582
    TSAggregationQueryReq req = createAggregationQueryReq(paths, aggregations);
×
583
    req.setStartTime(startTime);
×
584
    req.setEndTime(endTime);
×
585
    req.setInterval(interval);
×
586
    req.setSlidingStep(slidingStep);
×
587
    return executeAggregationQuery(req);
×
588
  }
589

590
  private SessionDataSet executeAggregationQuery(TSAggregationQueryReq tsAggregationQueryReq)
591
      throws StatementExecutionException, IoTDBConnectionException, RedirectException {
592
    TSExecuteStatementResp tsExecuteStatementResp;
593
    try {
594
      tsExecuteStatementResp = client.executeAggregationQueryV2(tsAggregationQueryReq);
×
595
      RpcUtils.verifySuccessWithRedirection(tsExecuteStatementResp.getStatus());
×
596
    } catch (TException e) {
×
597
      if (reconnect()) {
×
598
        try {
599
          tsAggregationQueryReq.setSessionId(sessionId);
×
600
          tsAggregationQueryReq.setStatementId(statementId);
×
601
          tsExecuteStatementResp = client.executeAggregationQuery(tsAggregationQueryReq);
×
602
        } catch (TException tException) {
×
603
          throw new IoTDBConnectionException(tException);
×
604
        }
×
605
      } else {
606
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
607
      }
608
    }
×
609

610
    RpcUtils.verifySuccess(tsExecuteStatementResp.getStatus());
×
611
    return new SessionDataSet(
×
612
        "",
613
        tsExecuteStatementResp.getColumns(),
×
614
        tsExecuteStatementResp.getDataTypeList(),
×
615
        tsExecuteStatementResp.columnNameIndexMap,
616
        tsExecuteStatementResp.getQueryId(),
×
617
        statementId,
618
        client,
619
        sessionId,
620
        tsExecuteStatementResp.queryResult,
621
        tsExecuteStatementResp.isIgnoreTimeStamp(),
×
622
        tsExecuteStatementResp.moreData);
623
  }
624

625
  private TSAggregationQueryReq createAggregationQueryReq(
626
      List<String> paths, List<TAggregationType> aggregations) {
627
    TSAggregationQueryReq req =
×
628
        new TSAggregationQueryReq(sessionId, statementId, paths, aggregations);
629
    req.setFetchSize(session.getFetchSize());
×
630
    req.setTimeout(session.getQueryTimeout());
×
631
    return req;
×
632
  }
633

634
  protected void insertRecord(TSInsertRecordReq request)
635
      throws IoTDBConnectionException, StatementExecutionException, RedirectException {
636
    request.setSessionId(sessionId);
×
637
    try {
638
      RpcUtils.verifySuccessWithRedirection(client.insertRecord(request));
×
639
    } catch (TException e) {
×
640
      if (reconnect()) {
×
641
        try {
642
          request.setSessionId(sessionId);
×
643
          RpcUtils.verifySuccess(client.insertRecord(request));
×
644
        } catch (TException tException) {
×
645
          throw new IoTDBConnectionException(tException);
×
646
        }
×
647
      } else {
648
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
649
      }
650
    }
×
651
  }
×
652

653
  protected void insertRecord(TSInsertStringRecordReq request)
654
      throws IoTDBConnectionException, StatementExecutionException, RedirectException {
655
    request.setSessionId(sessionId);
×
656
    try {
657
      RpcUtils.verifySuccessWithRedirection(client.insertStringRecord(request));
×
658
    } catch (TException e) {
×
659
      if (reconnect()) {
×
660
        try {
661
          request.setSessionId(sessionId);
×
662
          RpcUtils.verifySuccess(client.insertStringRecord(request));
×
663
        } catch (TException tException) {
×
664
          throw new IoTDBConnectionException(tException);
×
665
        }
×
666
      } else {
667
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
668
      }
669
    }
×
670
  }
×
671

672
  protected void insertRecords(TSInsertRecordsReq request)
673
      throws IoTDBConnectionException, StatementExecutionException, RedirectException {
674
    request.setSessionId(sessionId);
×
675
    try {
676
      RpcUtils.verifySuccessWithRedirectionForMultiDevices(
×
677
          client.insertRecords(request), request.getPrefixPaths());
×
678
    } catch (TException e) {
×
679
      if (reconnect()) {
×
680
        try {
681
          request.setSessionId(sessionId);
×
682
          RpcUtils.verifySuccess(client.insertRecords(request));
×
683
        } catch (TException tException) {
×
684
          throw new IoTDBConnectionException(tException);
×
685
        }
×
686
      } else {
687
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
688
      }
689
    }
×
690
  }
×
691

692
  protected void insertRecords(TSInsertStringRecordsReq request)
693
      throws IoTDBConnectionException, StatementExecutionException, RedirectException {
694
    request.setSessionId(sessionId);
×
695
    try {
696
      RpcUtils.verifySuccessWithRedirectionForMultiDevices(
×
697
          client.insertStringRecords(request), request.getPrefixPaths());
×
698
    } catch (TException e) {
×
699
      if (reconnect()) {
×
700
        try {
701
          request.setSessionId(sessionId);
×
702
          RpcUtils.verifySuccess(client.insertStringRecords(request));
×
703
        } catch (TException tException) {
×
704
          throw new IoTDBConnectionException(tException);
×
705
        }
×
706
      } else {
707
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
708
      }
709
    }
×
710
  }
×
711

712
  protected void insertRecordsOfOneDevice(TSInsertRecordsOfOneDeviceReq request)
713
      throws IoTDBConnectionException, StatementExecutionException, RedirectException {
714
    request.setSessionId(sessionId);
×
715
    try {
716
      RpcUtils.verifySuccessWithRedirection(client.insertRecordsOfOneDevice(request));
×
717
    } catch (TException e) {
×
718
      if (reconnect()) {
×
719
        try {
720
          request.setSessionId(sessionId);
×
721
          RpcUtils.verifySuccess(client.insertRecordsOfOneDevice(request));
×
722
        } catch (TException tException) {
×
723
          throw new IoTDBConnectionException(tException);
×
724
        }
×
725
      } else {
726
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
727
      }
728
    }
×
729
  }
×
730

731
  protected void insertStringRecordsOfOneDevice(TSInsertStringRecordsOfOneDeviceReq request)
732
      throws IoTDBConnectionException, StatementExecutionException, RedirectException {
733
    request.setSessionId(sessionId);
×
734
    try {
735
      RpcUtils.verifySuccessWithRedirection(client.insertStringRecordsOfOneDevice(request));
×
736
    } catch (TException e) {
×
737
      if (reconnect()) {
×
738
        try {
739
          request.setSessionId(sessionId);
×
740
          RpcUtils.verifySuccess(client.insertStringRecordsOfOneDevice(request));
×
741
        } catch (TException tException) {
×
742
          throw new IoTDBConnectionException(tException);
×
743
        }
×
744
      } else {
745
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
746
      }
747
    }
×
748
  }
×
749

750
  protected void insertTablet(TSInsertTabletReq request)
751
      throws IoTDBConnectionException, StatementExecutionException, RedirectException {
752
    request.setSessionId(sessionId);
×
753
    try {
754
      RpcUtils.verifySuccessWithRedirection(client.insertTablet(request));
×
755
    } catch (TException e) {
×
756
      if (reconnect()) {
×
757
        try {
758
          request.setSessionId(sessionId);
×
759
          RpcUtils.verifySuccess(client.insertTablet(request));
×
760
        } catch (TException tException) {
×
761
          throw new IoTDBConnectionException(tException);
×
762
        }
×
763
      } else {
764
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
765
      }
766
    }
×
767
  }
×
768

769
  protected void insertTablets(TSInsertTabletsReq request)
770
      throws IoTDBConnectionException, StatementExecutionException, RedirectException {
771
    request.setSessionId(sessionId);
×
772
    try {
773
      RpcUtils.verifySuccessWithRedirectionForMultiDevices(
×
774
          client.insertTablets(request), request.getPrefixPaths());
×
775
    } catch (TException e) {
×
776
      if (reconnect()) {
×
777
        try {
778
          request.setSessionId(sessionId);
×
779
          RpcUtils.verifySuccess(client.insertTablets(request));
×
780
        } catch (TException tException) {
×
781
          throw new IoTDBConnectionException(tException);
×
782
        }
×
783
      } else {
784
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
785
      }
786
    }
×
787
  }
×
788

789
  protected void deleteTimeseries(List<String> paths)
790
      throws IoTDBConnectionException, StatementExecutionException {
791
    try {
792
      RpcUtils.verifySuccess(client.deleteTimeseries(sessionId, paths));
×
793
    } catch (TException e) {
×
794
      if (reconnect()) {
×
795
        try {
796
          RpcUtils.verifySuccess(client.deleteTimeseries(sessionId, paths));
×
797
        } catch (TException tException) {
×
798
          throw new IoTDBConnectionException(tException);
×
799
        }
×
800
      } else {
801
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
802
      }
803
    }
×
804
  }
×
805

806
  public void deleteData(TSDeleteDataReq request)
807
      throws IoTDBConnectionException, StatementExecutionException {
808
    request.setSessionId(sessionId);
×
809
    try {
810
      RpcUtils.verifySuccess(client.deleteData(request));
×
811
    } catch (TException e) {
×
812
      if (reconnect()) {
×
813
        try {
814
          request.setSessionId(sessionId);
×
815
          RpcUtils.verifySuccess(client.deleteData(request));
×
816
        } catch (TException tException) {
×
817
          throw new IoTDBConnectionException(tException);
×
818
        }
×
819
      } else {
820
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
821
      }
822
    }
×
823
  }
×
824

825
  protected void testInsertRecord(TSInsertStringRecordReq request)
826
      throws IoTDBConnectionException, StatementExecutionException {
827
    request.setSessionId(sessionId);
×
828
    try {
829
      RpcUtils.verifySuccess(client.testInsertStringRecord(request));
×
830
    } catch (TException e) {
×
831
      if (reconnect()) {
×
832
        try {
833
          request.setSessionId(sessionId);
×
834
          RpcUtils.verifySuccess(client.testInsertStringRecord(request));
×
835
        } catch (TException tException) {
×
836
          throw new IoTDBConnectionException(tException);
×
837
        }
×
838
      } else {
839
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
840
      }
841
    }
×
842
  }
×
843

844
  protected void testInsertRecord(TSInsertRecordReq request)
845
      throws IoTDBConnectionException, StatementExecutionException {
846
    request.setSessionId(sessionId);
×
847
    try {
848
      RpcUtils.verifySuccess(client.testInsertRecord(request));
×
849
    } catch (TException e) {
×
850
      if (reconnect()) {
×
851
        try {
852
          request.setSessionId(sessionId);
×
853
          RpcUtils.verifySuccess(client.testInsertRecord(request));
×
854
        } catch (TException tException) {
×
855
          throw new IoTDBConnectionException(tException);
×
856
        }
×
857
      } else {
858
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
859
      }
860
    }
×
861
  }
×
862

863
  public void testInsertRecords(TSInsertStringRecordsReq request)
864
      throws IoTDBConnectionException, StatementExecutionException {
865
    request.setSessionId(sessionId);
×
866
    try {
867
      RpcUtils.verifySuccess(client.testInsertStringRecords(request));
×
868
    } catch (TException e) {
×
869
      if (reconnect()) {
×
870
        try {
871
          request.setSessionId(sessionId);
×
872
          RpcUtils.verifySuccess(client.testInsertStringRecords(request));
×
873
        } catch (TException tException) {
×
874
          throw new IoTDBConnectionException(tException);
×
875
        }
×
876
      } else {
877
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
878
      }
879
    }
×
880
  }
×
881

882
  public void testInsertRecords(TSInsertRecordsReq request)
883
      throws IoTDBConnectionException, StatementExecutionException {
884
    request.setSessionId(sessionId);
×
885
    try {
886
      RpcUtils.verifySuccess(client.testInsertRecords(request));
×
887
    } catch (TException e) {
×
888
      if (reconnect()) {
×
889
        try {
890
          request.setSessionId(sessionId);
×
891
          RpcUtils.verifySuccess(client.testInsertRecords(request));
×
892
        } catch (TException tException) {
×
893
          throw new IoTDBConnectionException(tException);
×
894
        }
×
895
      } else {
896
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
897
      }
898
    }
×
899
  }
×
900

901
  protected void testInsertTablet(TSInsertTabletReq request)
902
      throws IoTDBConnectionException, StatementExecutionException {
903
    request.setSessionId(sessionId);
×
904
    try {
905
      RpcUtils.verifySuccess(client.testInsertTablet(request));
×
906
    } catch (TException e) {
×
907
      if (reconnect()) {
×
908
        try {
909
          request.setSessionId(sessionId);
×
910
          RpcUtils.verifySuccess(client.testInsertTablet(request));
×
911
        } catch (TException tException) {
×
912
          throw new IoTDBConnectionException(tException);
×
913
        }
×
914
      } else {
915
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
916
      }
917
    }
×
918
  }
×
919

920
  protected void testInsertTablets(TSInsertTabletsReq request)
921
      throws IoTDBConnectionException, StatementExecutionException {
922
    request.setSessionId(sessionId);
×
923
    try {
924
      RpcUtils.verifySuccess(client.testInsertTablets(request));
×
925
    } catch (TException e) {
×
926
      if (reconnect()) {
×
927
        try {
928
          request.setSessionId(sessionId);
×
929
          RpcUtils.verifySuccess(client.testInsertTablets(request));
×
930
        } catch (TException tException) {
×
931
          throw new IoTDBConnectionException(tException);
×
932
        }
×
933
      } else {
934
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
935
      }
936
    }
×
937
  }
×
938

939
  @SuppressWarnings({
940
    "squid:S3776"
941
  }) // ignore Cognitive Complexity of methods should not be too high
942
  private boolean reconnect() {
943
    boolean connectedSuccess = false;
×
944
    SecureRandom random = new SecureRandom();
×
945
    for (int i = 1; i <= SessionConfig.RETRY_NUM; i++) {
×
946
      if (transport != null) {
×
947
        transport.close();
×
948
        int currHostIndex = random.nextInt(endPointList.size());
×
949
        int tryHostNum = 0;
×
950
        for (int j = currHostIndex; j < endPointList.size(); j++) {
×
951
          if (tryHostNum == endPointList.size()) {
×
952
            break;
×
953
          }
954
          session.defaultEndPoint = endPointList.get(j);
×
955
          this.endPoint = endPointList.get(j);
×
956
          if (j == endPointList.size() - 1) {
×
957
            j = -1;
×
958
          }
959
          tryHostNum++;
×
960
          try {
961
            init(endPoint);
×
962
            connectedSuccess = true;
×
963
          } catch (IoTDBConnectionException e) {
×
964
            logger.error("The current node may have been down {},try next node", endPoint);
×
965
            continue;
×
966
          }
×
967
          break;
968
        }
969
      }
970
      if (connectedSuccess) {
×
971
        break;
×
972
      }
973
    }
974
    return connectedSuccess;
×
975
  }
976

977
  protected void createSchemaTemplate(TSCreateSchemaTemplateReq request)
978
      throws IoTDBConnectionException, StatementExecutionException {
979
    request.setSessionId(sessionId);
×
980
    try {
981
      RpcUtils.verifySuccess(client.createSchemaTemplate(request));
×
982
    } catch (TException e) {
×
983
      if (reconnect()) {
×
984
        try {
985
          request.setSessionId(sessionId);
×
986
          RpcUtils.verifySuccess(client.createSchemaTemplate(request));
×
987
        } catch (TException tException) {
×
988
          throw new IoTDBConnectionException(tException);
×
989
        }
×
990
      } else {
991
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
992
      }
993
    }
×
994
  }
×
995

996
  protected void appendSchemaTemplate(TSAppendSchemaTemplateReq request)
997
      throws IoTDBConnectionException, StatementExecutionException {
998
    request.setSessionId(sessionId);
×
999
    try {
1000
      RpcUtils.verifySuccess(client.appendSchemaTemplate(request));
×
1001
    } catch (TException e) {
×
1002
      if (reconnect()) {
×
1003
        try {
1004
          request.setSessionId(sessionId);
×
1005
          RpcUtils.verifySuccess(client.appendSchemaTemplate(request));
×
1006
        } catch (TException tException) {
×
1007
          throw new IoTDBConnectionException(tException);
×
1008
        }
×
1009
      } else {
1010
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
1011
      }
1012
    }
×
1013
  }
×
1014

1015
  protected void pruneSchemaTemplate(TSPruneSchemaTemplateReq request)
1016
      throws IoTDBConnectionException, StatementExecutionException {
1017
    request.setSessionId(sessionId);
×
1018
    try {
1019
      RpcUtils.verifySuccess(client.pruneSchemaTemplate(request));
×
1020
    } catch (TException e) {
×
1021
      if (reconnect()) {
×
1022
        try {
1023
          request.setSessionId(sessionId);
×
1024
          RpcUtils.verifySuccess(client.pruneSchemaTemplate(request));
×
1025
        } catch (TException tException) {
×
1026
          throw new IoTDBConnectionException(tException);
×
1027
        }
×
1028
      } else {
1029
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
1030
      }
1031
    }
×
1032
  }
×
1033

1034
  protected TSQueryTemplateResp querySchemaTemplate(TSQueryTemplateReq req)
1035
      throws StatementExecutionException, IoTDBConnectionException {
1036
    TSQueryTemplateResp execResp;
1037
    req.setSessionId(sessionId);
×
1038
    try {
1039
      execResp = client.querySchemaTemplate(req);
×
1040
      RpcUtils.verifySuccess(execResp.getStatus());
×
1041
    } catch (TException e) {
×
1042
      if (reconnect()) {
×
1043
        try {
1044
          execResp = client.querySchemaTemplate(req);
×
1045
        } catch (TException tException) {
×
1046
          throw new IoTDBConnectionException(tException);
×
1047
        }
×
1048
      } else {
1049
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
1050
      }
1051
    }
×
1052

1053
    RpcUtils.verifySuccess(execResp.getStatus());
×
1054
    return execResp;
×
1055
  }
1056

1057
  protected void setSchemaTemplate(TSSetSchemaTemplateReq request)
1058
      throws IoTDBConnectionException, StatementExecutionException {
1059
    request.setSessionId(sessionId);
×
1060
    try {
1061
      RpcUtils.verifySuccess(client.setSchemaTemplate(request));
×
1062
    } catch (TException e) {
×
1063
      if (reconnect()) {
×
1064
        try {
1065
          request.setSessionId(sessionId);
×
1066
          RpcUtils.verifySuccess(client.setSchemaTemplate(request));
×
1067
        } catch (TException tException) {
×
1068
          throw new IoTDBConnectionException(tException);
×
1069
        }
×
1070
      } else {
1071
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
1072
      }
1073
    }
×
1074
  }
×
1075

1076
  protected void unsetSchemaTemplate(TSUnsetSchemaTemplateReq request)
1077
      throws IoTDBConnectionException, StatementExecutionException {
1078
    request.setSessionId(sessionId);
×
1079
    try {
1080
      RpcUtils.verifySuccess(client.unsetSchemaTemplate(request));
×
1081
    } catch (TException e) {
×
1082
      if (reconnect()) {
×
1083
        try {
1084
          request.setSessionId(sessionId);
×
1085
          RpcUtils.verifySuccess(client.unsetSchemaTemplate(request));
×
1086
        } catch (TException tException) {
×
1087
          throw new IoTDBConnectionException(tException);
×
1088
        }
×
1089
      } else {
1090
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
1091
      }
1092
    }
×
1093
  }
×
1094

1095
  protected void dropSchemaTemplate(TSDropSchemaTemplateReq request)
1096
      throws IoTDBConnectionException, StatementExecutionException {
1097
    request.setSessionId(sessionId);
×
1098
    try {
1099
      RpcUtils.verifySuccess(client.dropSchemaTemplate(request));
×
1100
    } catch (TException e) {
×
1101
      if (reconnect()) {
×
1102
        try {
1103
          request.setSessionId(sessionId);
×
1104
          RpcUtils.verifySuccess(client.dropSchemaTemplate(request));
×
1105
        } catch (TException tException) {
×
1106
          throw new IoTDBConnectionException(tException);
×
1107
        }
×
1108
      } else {
1109
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
1110
      }
1111
    }
×
1112
  }
×
1113

1114
  protected void createTimeseriesUsingSchemaTemplate(
1115
      TCreateTimeseriesUsingSchemaTemplateReq request)
1116
      throws IoTDBConnectionException, StatementExecutionException {
1117
    request.setSessionId(sessionId);
×
1118
    try {
1119
      RpcUtils.verifySuccess(client.createTimeseriesUsingSchemaTemplate(request));
×
1120
    } catch (TException e) {
×
1121
      if (reconnect()) {
×
1122
        try {
1123
          request.setSessionId(sessionId);
×
1124
          RpcUtils.verifySuccess(client.createTimeseriesUsingSchemaTemplate(request));
×
1125
        } catch (TException tException) {
×
1126
          throw new IoTDBConnectionException(tException);
×
1127
        }
×
1128
      } else {
1129
        throw new IoTDBConnectionException(MSG_RECONNECTION_FAIL);
×
1130
      }
1131
    }
×
1132
  }
×
1133

1134
  protected TSBackupConfigurationResp getBackupConfiguration()
1135
      throws IoTDBConnectionException, StatementExecutionException {
1136
    TSBackupConfigurationResp execResp;
1137
    try {
1138
      execResp = client.getBackupConfiguration();
×
1139
      RpcUtils.verifySuccess(execResp.getStatus());
×
1140
    } catch (TException e) {
×
1141
      if (reconnect()) {
×
1142
        try {
1143
          execResp = client.getBackupConfiguration();
×
1144
          RpcUtils.verifySuccess(execResp.getStatus());
×
1145
        } catch (TException tException) {
×
1146
          throw new IoTDBConnectionException(tException);
×
1147
        }
×
1148
      } else {
1149
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
1150
      }
1151
    }
×
1152
    return execResp;
×
1153
  }
1154

1155
  public TSConnectionInfoResp fetchAllConnections() throws IoTDBConnectionException {
1156
    try {
1157
      return client.fetchAllConnectionsInfo();
×
1158
    } catch (TException e) {
×
1159
      if (reconnect()) {
×
1160
        try {
1161
          return client.fetchAllConnectionsInfo();
×
1162
        } catch (TException tException) {
×
1163
          throw new IoTDBConnectionException(tException);
×
1164
        }
1165
      } else {
1166
        throw new IoTDBConnectionException(logForReconnectionFailure());
×
1167
      }
1168
    }
1169
  }
1170

1171
  public boolean isEnableRedirect() {
1172
    return enableRedirect;
×
1173
  }
1174

1175
  public void setEnableRedirect(boolean enableRedirect) {
1176
    this.enableRedirect = enableRedirect;
1✔
1177
  }
1✔
1178

1179
  public TEndPoint getEndPoint() {
1180
    return endPoint;
×
1181
  }
1182

1183
  public void setEndPoint(TEndPoint endPoint) {
1184
    this.endPoint = endPoint;
×
1185
  }
×
1186

1187
  // error log for connection failure
1188
  private String logForReconnectionFailure() {
1189
    if (endPointList == null) {
×
1190
      return MSG_RECONNECTION_FAIL;
×
1191
    }
1192
    StringJoiner urls = new StringJoiner(",");
×
1193
    for (TEndPoint end : endPointList) {
×
1194
      StringJoiner url = new StringJoiner(":");
×
1195
      url.add(end.getIp());
×
1196
      url.add(String.valueOf(end.getPort()));
×
1197
      urls.add(url.toString());
×
1198
    }
×
1199
    return MSG_RECONNECTION_FAIL.concat(urls.toString());
×
1200
  }
1201

1202
  @Override
1203
  public String toString() {
1204
    return "SessionConnection{" + " endPoint=" + endPoint + "}";
×
1205
  }
1206
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc