From 54ba85a44c8d2bda417d5afd7256f13c5798cd42 Mon Sep 17 00:00:00 2001 From: szywilliam Date: Tue, 26 Nov 2024 22:21:56 +0800 Subject: [PATCH 1/4] refactor session connect to reduce redundency --- .../iotdb/session/SessionConnection.java | 169 +++++------------- .../iotdb/session/util/CheckedSupplier.java | 32 ++++ 2 files changed, 79 insertions(+), 122 deletions(-) create mode 100644 iotdb-client/session/src/main/java/org/apache/iotdb/session/util/CheckedSupplier.java diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java index e6f55f39286b..12c11f76ae2a 100644 --- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java +++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java @@ -63,6 +63,7 @@ import org.apache.iotdb.service.rpc.thrift.TSSetSchemaTemplateReq; import org.apache.iotdb.service.rpc.thrift.TSSetTimeZoneReq; import org.apache.iotdb.service.rpc.thrift.TSUnsetSchemaTemplateReq; +import org.apache.iotdb.session.util.CheckedSupplier; import org.apache.iotdb.session.util.SessionUtils; import org.apache.thrift.TException; @@ -1477,172 +1478,96 @@ private boolean reconnect() { protected void createSchemaTemplate(TSCreateSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.createSchemaTemplate(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createSchemaTemplate(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void appendSchemaTemplate(TSAppendSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.appendSchemaTemplate(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.appendSchemaTemplate(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void pruneSchemaTemplate(TSPruneSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.pruneSchemaTemplate(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.pruneSchemaTemplate(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected TSQueryTemplateResp querySchemaTemplate(TSQueryTemplateReq req) throws StatementExecutionException, IoTDBConnectionException { - TSQueryTemplateResp execResp; - req.setSessionId(sessionId); - try { - execResp = client.querySchemaTemplate(req); + return doOperation(() -> { + req.setSessionId(sessionId); + TSQueryTemplateResp execResp = client.querySchemaTemplate(req); RpcUtils.verifySuccess(execResp.getStatus()); - } catch (TException e) { - if (reconnect()) { - try { - execResp = client.querySchemaTemplate(req); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } - - RpcUtils.verifySuccess(execResp.getStatus()); - return execResp; + return execResp; + }); } protected void setSchemaTemplate(TSSetSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.setSchemaTemplate(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.setSchemaTemplate(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void unsetSchemaTemplate(TSUnsetSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.unsetSchemaTemplate(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.unsetSchemaTemplate(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void dropSchemaTemplate(TSDropSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.dropSchemaTemplate(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.dropSchemaTemplate(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void createTimeseriesUsingSchemaTemplate( TCreateTimeseriesUsingSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.createTimeseriesUsingSchemaTemplate(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createTimeseriesUsingSchemaTemplate(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(MSG_RECONNECTION_FAIL); - } - } + return null; + }); } protected TSBackupConfigurationResp getBackupConfiguration() throws IoTDBConnectionException, StatementExecutionException { - TSBackupConfigurationResp execResp; - try { - execResp = client.getBackupConfiguration(); + return doOperation(() -> { + TSBackupConfigurationResp execResp = client.getBackupConfiguration(); RpcUtils.verifySuccess(execResp.getStatus()); + return execResp; + }); + } + + private RETURN doOperation(CheckedSupplier supplier) + throws IoTDBConnectionException, StatementExecutionException { + RETURN ret; + try { + ret = supplier.get(); } catch (TException e) { if (reconnect()) { try { - execResp = client.getBackupConfiguration(); - RpcUtils.verifySuccess(execResp.getStatus()); + ret = supplier.get(); } catch (TException tException) { throw new IoTDBConnectionException(tException); } @@ -1650,7 +1575,7 @@ protected TSBackupConfigurationResp getBackupConfiguration() throw new IoTDBConnectionException(logForReconnectionFailure()); } } - return execResp; + return ret; } public TSConnectionInfoResp fetchAllConnections() throws IoTDBConnectionException { diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/util/CheckedSupplier.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/util/CheckedSupplier.java new file mode 100644 index 000000000000..c57e31ff0c1c --- /dev/null +++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/util/CheckedSupplier.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.session.util; + +import org.apache.iotdb.rpc.StatementExecutionException; + +/** Supplier with a throws-clause. */ +@FunctionalInterface +public interface CheckedSupplier { + /** + * The same as {@link java.util.function.Supplier#get()} + * except that this method is declared with a throws-clause. + */ + OUTPUT get() throws THROWABLE, StatementExecutionException; +} From 90cce528556615c5c05a77bcd1bd1e21d873b366 Mon Sep 17 00:00:00 2001 From: szywilliam Date: Thu, 28 Nov 2024 21:38:25 +0800 Subject: [PATCH 2/4] refactor session connect to reduce redundency --- .../iotdb/session/SessionConnection.java | 216 ++++-------------- 1 file changed, 48 insertions(+), 168 deletions(-) diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java index 12c11f76ae2a..0ba35706e5b6 100644 --- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java +++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java @@ -284,23 +284,11 @@ protected IClientRPCService.Iface getClient() { protected void setTimeZone(String zoneId) throws StatementExecutionException, IoTDBConnectionException { - TSSetTimeZoneReq req = new TSSetTimeZoneReq(sessionId, zoneId); - TSStatus resp; - try { - resp = client.setTimeZone(req); - } catch (TException e) { - if (reconnect()) { - try { - req.setSessionId(sessionId); - resp = client.setTimeZone(req); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } - RpcUtils.verifySuccess(resp); + doOperation(() -> { + TSSetTimeZoneReq req = new TSSetTimeZoneReq(sessionId, zoneId); + RpcUtils.verifySuccess(client.setTimeZone(req)); + return null; + }); setTimeZoneOfSession(zoneId); } @@ -317,93 +305,45 @@ protected String getTimeZone() { protected void setStorageGroup(String storageGroup) throws IoTDBConnectionException, StatementExecutionException { - try { + doOperation(() -> { RpcUtils.verifySuccess(client.setStorageGroup(sessionId, storageGroup)); - } catch (TException e) { - if (reconnect()) { - try { - RpcUtils.verifySuccess(client.setStorageGroup(sessionId, storageGroup)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void deleteStorageGroups(List storageGroups) throws IoTDBConnectionException, StatementExecutionException { - try { + doOperation(() -> { RpcUtils.verifySuccess(client.deleteStorageGroups(sessionId, storageGroups)); - } catch (TException e) { - if (reconnect()) { - try { - RpcUtils.verifySuccess(client.deleteStorageGroups(sessionId, storageGroups)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } - protected void createTimeseries(TSCreateTimeseriesReq request) + protected void createTimescreateTimeserieseries(TSCreateTimeseriesReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.createTimeseries(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createTimeseries(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void createAlignedTimeseries(TSCreateAlignedTimeseriesReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.createAlignedTimeseries(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createAlignedTimeseries(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void createMultiTimeseries(TSCreateMultiTimeseriesReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.createMultiTimeseries(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createMultiTimeseries(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected boolean checkTimeseriesExists(String path, long timeout) @@ -1316,116 +1256,56 @@ private TSStatus deleteDataInternal(TSDeleteDataReq request) throws TException { protected void testInsertRecord(TSInsertStringRecordReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.testInsertStringRecord(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertStringRecord(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void testInsertRecord(TSInsertRecordReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.testInsertRecord(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertRecord(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } public void testInsertRecords(TSInsertStringRecordsReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.testInsertStringRecords(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertStringRecords(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } public void testInsertRecords(TSInsertRecordsReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.testInsertRecords(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertRecords(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void testInsertTablet(TSInsertTabletReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.testInsertTablet(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertTablet(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } protected void testInsertTablets(TSInsertTabletsReq request) throws IoTDBConnectionException, StatementExecutionException { - request.setSessionId(sessionId); - try { + doOperation(() -> { + request.setSessionId(sessionId); RpcUtils.verifySuccess(client.testInsertTablets(request)); - } catch (TException e) { - if (reconnect()) { - try { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertTablets(request)); - } catch (TException tException) { - throw new IoTDBConnectionException(tException); - } - } else { - throw new IoTDBConnectionException(logForReconnectionFailure()); - } - } + return null; + }); } @SuppressWarnings({ From 99627e03ce4545480a52b454bfa6cb1f8d805000 Mon Sep 17 00:00:00 2001 From: szywilliam Date: Thu, 28 Nov 2024 21:44:53 +0800 Subject: [PATCH 3/4] mvn spotless --- .../iotdb/session/SessionConnection.java | 231 ++++++++++-------- .../iotdb/session/util/CheckedSupplier.java | 4 +- 2 files changed, 128 insertions(+), 107 deletions(-) diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java index 0ba35706e5b6..5f0635e23311 100644 --- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java +++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java @@ -284,11 +284,12 @@ protected IClientRPCService.Iface getClient() { protected void setTimeZone(String zoneId) throws StatementExecutionException, IoTDBConnectionException { - doOperation(() -> { - TSSetTimeZoneReq req = new TSSetTimeZoneReq(sessionId, zoneId); - RpcUtils.verifySuccess(client.setTimeZone(req)); - return null; - }); + doOperation( + () -> { + TSSetTimeZoneReq req = new TSSetTimeZoneReq(sessionId, zoneId); + RpcUtils.verifySuccess(client.setTimeZone(req)); + return null; + }); setTimeZoneOfSession(zoneId); } @@ -305,45 +306,50 @@ protected String getTimeZone() { protected void setStorageGroup(String storageGroup) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - RpcUtils.verifySuccess(client.setStorageGroup(sessionId, storageGroup)); - return null; - }); + doOperation( + () -> { + RpcUtils.verifySuccess(client.setStorageGroup(sessionId, storageGroup)); + return null; + }); } protected void deleteStorageGroups(List storageGroups) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - RpcUtils.verifySuccess(client.deleteStorageGroups(sessionId, storageGroups)); - return null; - }); + doOperation( + () -> { + RpcUtils.verifySuccess(client.deleteStorageGroups(sessionId, storageGroups)); + return null; + }); } protected void createTimescreateTimeserieseries(TSCreateTimeseriesReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createTimeseries(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.createTimeseries(request)); + return null; + }); } protected void createAlignedTimeseries(TSCreateAlignedTimeseriesReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createAlignedTimeseries(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.createAlignedTimeseries(request)); + return null; + }); } protected void createMultiTimeseries(TSCreateMultiTimeseriesReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createMultiTimeseries(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.createMultiTimeseries(request)); + return null; + }); } protected boolean checkTimeseriesExists(String path, long timeout) @@ -1256,56 +1262,62 @@ private TSStatus deleteDataInternal(TSDeleteDataReq request) throws TException { protected void testInsertRecord(TSInsertStringRecordReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertStringRecord(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.testInsertStringRecord(request)); + return null; + }); } protected void testInsertRecord(TSInsertRecordReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertRecord(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.testInsertRecord(request)); + return null; + }); } public void testInsertRecords(TSInsertStringRecordsReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertStringRecords(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.testInsertStringRecords(request)); + return null; + }); } public void testInsertRecords(TSInsertRecordsReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertRecords(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.testInsertRecords(request)); + return null; + }); } protected void testInsertTablet(TSInsertTabletReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertTablet(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.testInsertTablet(request)); + return null; + }); } protected void testInsertTablets(TSInsertTabletsReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.testInsertTablets(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.testInsertTablets(request)); + return null; + }); } @SuppressWarnings({ @@ -1358,89 +1370,98 @@ private boolean reconnect() { protected void createSchemaTemplate(TSCreateSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createSchemaTemplate(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.createSchemaTemplate(request)); + return null; + }); } protected void appendSchemaTemplate(TSAppendSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.appendSchemaTemplate(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.appendSchemaTemplate(request)); + return null; + }); } protected void pruneSchemaTemplate(TSPruneSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.pruneSchemaTemplate(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.pruneSchemaTemplate(request)); + return null; + }); } protected TSQueryTemplateResp querySchemaTemplate(TSQueryTemplateReq req) throws StatementExecutionException, IoTDBConnectionException { - return doOperation(() -> { - req.setSessionId(sessionId); - TSQueryTemplateResp execResp = client.querySchemaTemplate(req); - RpcUtils.verifySuccess(execResp.getStatus()); - return execResp; - }); + return doOperation( + () -> { + req.setSessionId(sessionId); + TSQueryTemplateResp execResp = client.querySchemaTemplate(req); + RpcUtils.verifySuccess(execResp.getStatus()); + return execResp; + }); } protected void setSchemaTemplate(TSSetSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.setSchemaTemplate(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.setSchemaTemplate(request)); + return null; + }); } protected void unsetSchemaTemplate(TSUnsetSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.unsetSchemaTemplate(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.unsetSchemaTemplate(request)); + return null; + }); } protected void dropSchemaTemplate(TSDropSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.dropSchemaTemplate(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.dropSchemaTemplate(request)); + return null; + }); } protected void createTimeseriesUsingSchemaTemplate( TCreateTimeseriesUsingSchemaTemplateReq request) throws IoTDBConnectionException, StatementExecutionException { - doOperation(() -> { - request.setSessionId(sessionId); - RpcUtils.verifySuccess(client.createTimeseriesUsingSchemaTemplate(request)); - return null; - }); + doOperation( + () -> { + request.setSessionId(sessionId); + RpcUtils.verifySuccess(client.createTimeseriesUsingSchemaTemplate(request)); + return null; + }); } protected TSBackupConfigurationResp getBackupConfiguration() throws IoTDBConnectionException, StatementExecutionException { - return doOperation(() -> { - TSBackupConfigurationResp execResp = client.getBackupConfiguration(); - RpcUtils.verifySuccess(execResp.getStatus()); - return execResp; - }); + return doOperation( + () -> { + TSBackupConfigurationResp execResp = client.getBackupConfiguration(); + RpcUtils.verifySuccess(execResp.getStatus()); + return execResp; + }); } private RETURN doOperation(CheckedSupplier supplier) - throws IoTDBConnectionException, StatementExecutionException { + throws IoTDBConnectionException, StatementExecutionException { RETURN ret; try { ret = supplier.get(); diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/util/CheckedSupplier.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/util/CheckedSupplier.java index c57e31ff0c1c..93949524afb6 100644 --- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/util/CheckedSupplier.java +++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/util/CheckedSupplier.java @@ -25,8 +25,8 @@ @FunctionalInterface public interface CheckedSupplier { /** - * The same as {@link java.util.function.Supplier#get()} - * except that this method is declared with a throws-clause. + * The same as {@link java.util.function.Supplier#get()} except that this method is declared with + * a throws-clause. */ OUTPUT get() throws THROWABLE, StatementExecutionException; } From ea78d9f63cc8e1996aeaf984162fc7fb81d98353 Mon Sep 17 00:00:00 2001 From: szywilliam Date: Thu, 28 Nov 2024 21:52:22 +0800 Subject: [PATCH 4/4] fix small error --- .../main/java/org/apache/iotdb/session/SessionConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java index 5f0635e23311..c0dc516ba114 100644 --- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java +++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java @@ -322,7 +322,7 @@ protected void deleteStorageGroups(List storageGroups) }); } - protected void createTimescreateTimeserieseries(TSCreateTimeseriesReq request) + protected void createTimeseries(TSCreateTimeseriesReq request) throws IoTDBConnectionException, StatementExecutionException { doOperation( () -> {