This is an automated email from the ASF dual-hosted git repository.

shuwenwei pushed a commit to branch fix/table-session-pool-lifecycle
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to 
refs/heads/fix/table-session-pool-lifecycle by this push:
     new 24f9af93129 Fix sortTablet session cleanup
24f9af93129 is described below

commit 24f9af93129de85b7810926ca420a6b970bfb1d4
Author: shuwenwei <[email protected]>
AuthorDate: Thu Nov 12 18:06:21 2026 +0800

    Fix sortTablet session cleanup
    
    Return the borrowed session when sortTablet succeeds or throws, and remove 
an unused connection-exception cleanup overload.
---
 .../org/apache/iotdb/session/pool/SessionPool.java | 13 ++++-------
 .../apache/iotdb/session/pool/SessionPoolTest.java | 27 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
index b5f9f8ea292..45d1392cd34 100644
--- 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
+++ 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/SessionPool.java
@@ -997,12 +997,6 @@ public class SessionPool implements ISessionPool {
     }
   }
 
-  protected void cleanSessionAndMayThrowConnectionException(ISession session) {
-    if (!releaseSession(session, false)) {
-      discardSession(session);
-    }
-  }
-
   /**
    * insert the data of a device. For each timestamp, the number of 
measurements is the same.
    *
@@ -3028,8 +3022,11 @@ public class SessionPool implements ISessionPool {
   @Override
   public void sortTablet(Tablet tablet) throws IoTDBConnectionException {
     ISession session = getSession();
-    session.sortTablet(tablet);
-    putBack(session);
+    try {
+      session.sortTablet(tablet);
+    } finally {
+      putBack(session);
+    }
   }
 
   @Override
diff --git 
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java
 
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java
index d08625cb978..60df47a1e86 100644
--- 
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java
+++ 
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java
@@ -1217,6 +1217,33 @@ public class SessionPoolTest {
         ((ConcurrentLinkedDeque<ISession>) 
Whitebox.getInternalState(sessionPool, "queue")).size());
   }
 
+  @Test
+  public void testSortTabletExceptionReturnsSessionToPool() throws 
IoTDBConnectionException {
+    List<IMeasurementSchema> schemas = new ArrayList<>();
+    MeasurementSchema schema = new MeasurementSchema();
+    schema.setMeasurementName("pressure");
+    schema.setDataType(TSDataType.BOOLEAN);
+    schema.setCompressionType(CompressionType.SNAPPY);
+    schema.setEncoding(TSEncoding.PLAIN);
+    schemas.add(schema);
+    long[] timestamp = new long[] {1L, 2L};
+    Object[] values = new Object[] {true, false};
+    BitMap[] partBitMap = new BitMap[2];
+    Tablet tablet = new Tablet("device", schemas, timestamp, values, 
partBitMap, 2);
+    Mockito.doThrow(new IllegalArgumentException("sort 
failed")).when(session).sortTablet(tablet);
+
+    try {
+      sessionPool.sortTablet(tablet);
+      fail("Expected sortTablet to throw");
+    } catch (IllegalArgumentException expected) {
+      // expected
+    }
+
+    assertEquals(
+        1,
+        ((ConcurrentLinkedDeque<ISession>) 
Whitebox.getInternalState(sessionPool, "queue")).size());
+  }
+
   @Test
   public void testSetSchemaTemplate() throws IoTDBConnectionException, 
StatementExecutionException {
     sessionPool.setSchemaTemplate("template2", "root.ut0.sensor2");

Reply via email to