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

jiangtian pushed a commit to branch fix_insert_long_min_max
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/fix_insert_long_min_max by 
this push:
     new bffdbf235ba fix insert/load with Long.MIN/MAX
bffdbf235ba is described below

commit bffdbf235baf0a5dd2bdf95b3307489fec28ab6e
Author: Tian Jiang <[email protected]>
AuthorDate: Wed Dec 18 19:18:30 2024 +0800

    fix insert/load with Long.MIN/MAX
---
 .../iotdb/session/it/IoTDBSessionSimpleIT.java     | 78 ++++++++++++++++------
 .../org/apache/iotdb/db/conf/IoTDBDescriptor.java  |  9 +++
 .../queryengine/plan/analyze/AnalyzeVisitor.java   |  6 +-
 .../analyze/load/LoadTsFileTableSchemaCache.java   |  1 +
 .../analyze/load/LoadTsFileTreeSchemaCache.java    |  1 +
 .../db/queryengine/plan/parser/ASTVisitor.java     |  8 ++-
 .../estimator/AbstractCompactionEstimator.java     |  3 +
 .../dataregion/memtable/AbstractMemTable.java      |  4 +-
 .../dataregion/tsfile/TsFileResource.java          |  8 ++-
 .../tsfile/timeindex/ArrayDeviceTimeIndex.java     |  9 +--
 .../dataregion/utils/TsFileResourceUtils.java      | 18 -----
 .../load/splitter/AlignedChunkData.java            | 14 +++-
 .../splitter/BatchedAlignedValueChunkData.java     |  6 +-
 .../load/splitter/NonAlignedChunkData.java         |  8 ++-
 .../load/splitter/TsFileSplitter.java              |  7 ++
 .../iotdb/db/utils/TimestampPrecisionUtils.java    | 16 ++---
 .../resources/conf/iotdb-system.properties         | 16 +++++
 17 files changed, 146 insertions(+), 66 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
index f06bd2ba38f..2ae4498dd4b 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
@@ -79,6 +79,7 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+@SuppressWarnings("ThrowFromFinallyBlock")
 @RunWith(IoTDBTestRunner.class)
 public class IoTDBSessionSimpleIT {
 
@@ -1870,15 +1871,24 @@ public class IoTDBSessionSimpleIT {
   @Test
   @Category({LocalStandaloneIT.class, ClusterIT.class})
   public void insertMinMaxTimeTest() throws IoTDBConnectionException, 
StatementExecutionException {
-    EnvFactory.getEnv().cleanClusterEnvironment();
-    
EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(false);
-    EnvFactory.getEnv().initClusterEnvironment();
     try {
       try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+        try {
+          session.executeNonQueryStatement(
+              "SET CONFIGURATION 
\"timestamp_precision_check_enabled\"=\"false\"");
+        } catch (StatementExecutionException e) {
+          // run in IDE will trigger this, ignore it
+          if (!e.getMessage().contains("Unable to find the configuration 
file")) {
+            throw e;
+          }
+        }
+
         session.executeNonQueryStatement(
-            String.format("INSERT INTO root.test.d1(timestamp, s1) VALUES (%d, 
1)", Long.MIN_VALUE));
+            String.format(
+                "INSERT INTO root.test.d1(timestamp, s1) VALUES (%d, 1)", 
Long.MIN_VALUE));
         session.executeNonQueryStatement(
-            String.format("INSERT INTO root.test.d1(timestamp, s1) VALUES (%d, 
1)", Long.MAX_VALUE));
+            String.format(
+                "INSERT INTO root.test.d1(timestamp, s1) VALUES (%d, 1)", 
Long.MAX_VALUE));
 
         SessionDataSet dataSet = session.executeQueryStatement("SELECT * FROM 
root.test.d1");
         RowRecord record = dataSet.next();
@@ -1896,7 +1906,17 @@ public class IoTDBSessionSimpleIT {
         assertFalse(dataSet.hasNext());
       }
     } finally {
-      
EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(true);
+      try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+        try {
+          session.executeNonQueryStatement(
+              "SET CONFIGURATION 
\"timestamp_precision_check_enabled\"=\"true\"");
+        } catch (StatementExecutionException e) {
+          // run in IDE will trigger this, ignore it
+          if (!e.getMessage().contains("Unable to find the configuration 
file")) {
+            throw e;
+          }
+        }
+      }
     }
   }
 
@@ -1909,30 +1929,46 @@ public class IoTDBSessionSimpleIT {
           WriteProcessException {
     File file = new File("target", "test.tsfile");
     try (TsFileWriter writer = new TsFileWriter(file)) {
-      IDeviceID deviceID = Factory.DEFAULT_FACTORY.create(new String[] 
{"root", "test", "d1"});
+      IDeviceID deviceID = Factory.DEFAULT_FACTORY.create("root.test.d1");
       writer.registerTimeseries(deviceID, new MeasurementSchema("s1", 
TSDataType.INT32));
       TSRecord record = new TSRecord(deviceID, Long.MIN_VALUE);
       record.addPoint("s1", 1);
       writer.writeRecord(record);
       record.setTime(Long.MAX_VALUE);
+      writer.writeRecord(record);
     }
 
-    EnvFactory.getEnv().cleanClusterEnvironment();
-    
EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(false);
-    EnvFactory.getEnv().initClusterEnvironment();
-    try {
-      try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
-        session.executeNonQueryStatement("LOAD " + file.getAbsolutePath());
-
-        SessionDataSet dataSet = session.executeQueryStatement("SELECT * FROM 
root.test.d1");
-        RowRecord record = dataSet.next();
-        assertEquals(Long.MIN_VALUE, record.getTimestamp());
-        record = dataSet.next();
-        assertEquals(Long.MAX_VALUE, record.getTimestamp());
-        assertFalse(dataSet.hasNext());
+    try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+      try {
+        session.executeNonQueryStatement(
+            "SET CONFIGURATION 
\"timestamp_precision_check_enabled\"=\"false\"");
+      } catch (StatementExecutionException e) {
+        // run in IDE will trigger this, ignore it
+        if (!e.getMessage().contains("Unable to find the configuration file")) 
{
+          throw e;
+        }
       }
+      session.executeNonQueryStatement("LOAD \"" + file.getAbsolutePath() + 
"\"");
+
+      SessionDataSet dataSet = session.executeQueryStatement("SELECT * FROM 
root.test.d1");
+      RowRecord record = dataSet.next();
+      assertEquals(Long.MIN_VALUE, record.getTimestamp());
+      record = dataSet.next();
+      assertEquals(Long.MAX_VALUE, record.getTimestamp());
+      assertFalse(dataSet.hasNext());
     } finally {
-      
EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(true);
+      try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+        try {
+          session.executeNonQueryStatement(
+              "SET CONFIGURATION 
\"timestamp_precision_check_enabled\"=\"true\"");
+        } catch (StatementExecutionException e) {
+          // run in IDE will trigger this, ignore it
+          if (!e.getMessage().contains("Unable to find the configuration 
file")) {
+            throw e;
+          }
+        }
+      }
+      file.delete();
     }
   }
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
index fce4bb4e933..4d0705f108a 100755
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
@@ -2882,6 +2882,15 @@ public class IoTDBDescriptor {
         BinaryAllocator.getInstance().close(true);
       }
 
+      commonDescriptor
+          .getConfig()
+          .setTimestampPrecisionCheckEnabled(
+              Boolean.parseBoolean(
+                  properties.getProperty(
+                      "timestamp_precision_check_enabled",
+                      ConfigurationFileUtils.getConfigurationDefaultValue(
+                          "timestamp_precision_check_enabled"))));
+
       // update query_sample_throughput_bytes_per_sec
       loadQuerySampleThroughput(properties);
       // update trusted_uri_pattern
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
index 224d22520a0..7ca0b9279d1 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
@@ -2301,7 +2301,11 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
         result.add(timePartitionSlot);
         // next init
         timePartitionSlot = new TTimePartitionSlot(endTime);
-        endTime = endTime + TimePartitionUtils.getTimePartitionInterval();
+        // beware of overflow
+        endTime =
+            endTime + TimePartitionUtils.getTimePartitionInterval() > endTime
+                ? endTime + TimePartitionUtils.getTimePartitionInterval()
+                : Long.MAX_VALUE;
       } else {
         index++;
         if (index < size) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/load/LoadTsFileTableSchemaCache.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/load/LoadTsFileTableSchemaCache.java
index 127b619f06c..ac715923945 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/load/LoadTsFileTableSchemaCache.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/load/LoadTsFileTableSchemaCache.java
@@ -134,6 +134,7 @@ public class LoadTsFileTableSchemaCache {
 
   private boolean isDeviceDeletedByMods(IDeviceID device) throws 
IllegalPathException {
     return currentTimeIndex != null
+        && currentTimeIndex.checkDeviceIdExist(device)
         && ModificationUtils.isAllDeletedByMods(
             currentModifications,
             device,
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/load/LoadTsFileTreeSchemaCache.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/load/LoadTsFileTreeSchemaCache.java
index f982a03affd..c6e215e67bd 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/load/LoadTsFileTreeSchemaCache.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/load/LoadTsFileTreeSchemaCache.java
@@ -189,6 +189,7 @@ public class LoadTsFileTreeSchemaCache {
 
   public boolean isDeviceDeletedByMods(IDeviceID device) throws 
IllegalPathException {
     return currentTimeIndex != null
+        && currentTimeIndex.checkDeviceIdExist(device)
         && ModificationUtils.isAllDeletedByMods(
             currentModifications,
             device,
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
index ebc84c33a45..7a274b38046 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
@@ -2001,10 +2001,12 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
       } catch (NumberFormatException e) {
         throw new SemanticException(
             String.format(
-                "Failed to parse the timestamp: " + e.getMessage() +
-                "Current system timestamp precision is %s, "
+                "Failed to parse the timestamp: "
+                    + e.getMessage()
+                    + "Current system timestamp precision is %s, "
                     + "please check whether the timestamp %s is correct.",
-                TIMESTAMP_PRECISION, constant.INTEGER_LITERAL().getText()));
+                TIMESTAMP_PRECISION,
+                constant.INTEGER_LITERAL().getText()));
       }
     } else if (constant.dateExpression() != null) {
       return parseDateExpression(constant.dateExpression(), 
CommonDateTimeUtils.currentTime());
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/estimator/AbstractCompactionEstimator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/estimator/AbstractCompactionEstimator.java
index 4ec74c57d63..fb9d825a591 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/estimator/AbstractCompactionEstimator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/estimator/AbstractCompactionEstimator.java
@@ -140,6 +140,9 @@ public abstract class AbstractCompactionEstimator {
       long maxEndTimeOfCurrentDevice = Long.MIN_VALUE;
       int overlapFileNumOfCurrentDevice = 0;
       for (ArrayDeviceTimeIndex resource : resourcesContainsCurrentDevice) {
+        if (resource.definitelyNotContains(device)) {
+          continue;
+        }
         long deviceStartTimeInCurrentFile = resource.getStartTime(device);
         long deviceEndTimeInCurrentFile = resource.getEndTime(device);
         if (deviceStartTimeInCurrentFile <= maxEndTimeOfCurrentDevice) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractMemTable.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractMemTable.java
index 27f681663d5..eacdc7371e8 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractMemTable.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractMemTable.java
@@ -986,10 +986,8 @@ public abstract class AbstractMemTable implements 
IMemTable {
   public Map<IDeviceID, Long> getMaxTime() {
     Map<IDeviceID, Long> latestTimeForEachDevice = new HashMap<>();
     for (Entry<IDeviceID, IWritableMemChunkGroup> entry : 
memTableMap.entrySet()) {
-      // When insert null values in to IWritableMemChunkGroup, the maxTime 
will not be updated.
-      // In this scenario, the maxTime will be Long.MIN_VALUE. We shouldn't 
return this device.
       long maxTime = entry.getValue().getMaxTime();
-      if (maxTime != Long.MIN_VALUE) {
+      if (entry.getValue().count() > 0) {
         latestTimeForEachDevice.put(entry.getKey(), maxTime);
       }
     }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
index ed681abe8ad..366eeef0ee6 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
@@ -576,7 +576,9 @@ public class TsFileResource implements PersistentResource {
 
   public long getStartTime(IDeviceID deviceId) {
     try {
-      return deviceId == null ? getFileStartTime() : 
timeIndex.getStartTime(deviceId);
+      return deviceId == null || !timeIndex.checkDeviceIdExist(deviceId)
+          ? getFileStartTime()
+          : timeIndex.getStartTime(deviceId);
     } catch (Exception e) {
       LOGGER.error(
           "meet error when getStartTime of {} in file {}", deviceId, 
file.getAbsolutePath(), e);
@@ -590,7 +592,9 @@ public class TsFileResource implements PersistentResource {
   /** open file's end time is Long.MIN_VALUE */
   public long getEndTime(IDeviceID deviceId) {
     try {
-      return deviceId == null ? getFileEndTime() : 
timeIndex.getEndTime(deviceId);
+      return deviceId == null || !timeIndex.checkDeviceIdExist(deviceId)
+          ? getFileEndTime()
+          : timeIndex.getEndTime(deviceId);
     } catch (Exception e) {
       LOGGER.error(
           "meet error when getEndTime of {} in file {}", deviceId, 
file.getAbsolutePath(), e);
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/timeindex/ArrayDeviceTimeIndex.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/timeindex/ArrayDeviceTimeIndex.java
index 31fd9d385e6..8b99caca8c5 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/timeindex/ArrayDeviceTimeIndex.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/timeindex/ArrayDeviceTimeIndex.java
@@ -43,6 +43,7 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -318,9 +319,9 @@ public class ArrayDeviceTimeIndex implements ITimeIndex {
 
   @Override
   public void updateStartTime(IDeviceID deviceId, long time) {
+    int index = getDeviceIndex(deviceId);
     long startTime = getStartTime(deviceId);
     if (time < startTime) {
-      int index = getDeviceIndex(deviceId);
       startTimes[index] = time;
     }
     minStartTime = Math.min(minStartTime, time);
@@ -328,9 +329,9 @@ public class ArrayDeviceTimeIndex implements ITimeIndex {
 
   @Override
   public void updateEndTime(IDeviceID deviceId, long time) {
+    int index = getDeviceIndex(deviceId);
     long endTime = getEndTime(deviceId);
     if (time > endTime) {
-      int index = getDeviceIndex(deviceId);
       endTimes[index] = time;
     }
     maxEndTime = Math.max(maxEndTime, time);
@@ -353,7 +354,7 @@ public class ArrayDeviceTimeIndex implements ITimeIndex {
   @Override
   public long getStartTime(IDeviceID deviceId) {
     if (!deviceToIndex.containsKey(deviceId)) {
-      return Long.MAX_VALUE;
+      throw new NoSuchElementException(deviceId.toString());
     }
     return startTimes[deviceToIndex.get(deviceId)];
   }
@@ -361,7 +362,7 @@ public class ArrayDeviceTimeIndex implements ITimeIndex {
   @Override
   public long getEndTime(IDeviceID deviceId) {
     if (!deviceToIndex.containsKey(deviceId)) {
-      return Long.MIN_VALUE;
+      throw new NoSuchElementException(deviceId.toString());
     }
     return endTimes[deviceToIndex.get(deviceId)];
   }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/utils/TsFileResourceUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/utils/TsFileResourceUtils.java
index d8bc61db50a..679d5119b9e 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/utils/TsFileResourceUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/utils/TsFileResourceUtils.java
@@ -94,24 +94,6 @@ public class TsFileResourceUtils {
       for (IDeviceID device : devices) {
         long startTime = timeIndex.getStartTime(device);
         long endTime = timeIndex.getEndTime(device);
-        if (startTime == Long.MAX_VALUE) {
-          logger.error(
-              "{} {} the start time of {} is {}",
-              resource.getTsFilePath(),
-              VALIDATE_FAILED,
-              device,
-              Long.MAX_VALUE);
-          return false;
-        }
-        if (endTime == Long.MIN_VALUE) {
-          logger.error(
-              "{} {} the end time of {} is {}",
-              resource.getTsFilePath(),
-              VALIDATE_FAILED,
-              device,
-              Long.MIN_VALUE);
-          return false;
-        }
         if (startTime > endTime) {
           logger.error(
               "{} {} the start time of {} is greater than end time",
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/AlignedChunkData.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/AlignedChunkData.java
index 585421e3afe..225d87a86bc 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/AlignedChunkData.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/AlignedChunkData.java
@@ -215,13 +215,17 @@ public class AlignedChunkData implements ChunkData {
     pageNumbers.set(pageNumbers.size() - 1, pageNumbers.get(pageNumbers.size() 
- 1) + 1);
     satisfiedLengthQueue.offer(satisfiedLength);
     final long startTime = timePartitionSlot.getStartTime();
-    final long endTime = startTime + 
TimePartitionUtils.getTimePartitionInterval();
+    // beware of overflow
+    long endTime = startTime + TimePartitionUtils.getTimePartitionInterval() - 
1;
+    if (endTime <= startTime) {
+      endTime = Long.MAX_VALUE;
+    }
     // serialize needDecode==true
     dataSize += ReadWriteIOUtils.write(true, stream);
     dataSize += ReadWriteIOUtils.write(satisfiedLength, stream);
 
     for (final long time : times) {
-      if (time >= endTime) {
+      if (time > endTime) {
         break;
       }
       if (time >= startTime) {
@@ -235,7 +239,11 @@ public class AlignedChunkData implements ChunkData {
       throws IOException {
     pageNumbers.set(pageNumbers.size() - 1, pageNumbers.get(pageNumbers.size() 
- 1) + 1);
     final long startTime = timePartitionSlot.getStartTime();
-    final long endTime = startTime + 
TimePartitionUtils.getTimePartitionInterval();
+    // beware of overflow
+    long endTime = startTime + TimePartitionUtils.getTimePartitionInterval();
+    if (endTime <= startTime) {
+      endTime = Long.MAX_VALUE;
+    }
     final int satisfiedLength = satisfiedLengthQueue.poll();
     // serialize needDecode==true
     dataSize += ReadWriteIOUtils.write(true, stream);
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/BatchedAlignedValueChunkData.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/BatchedAlignedValueChunkData.java
index a7b5a840ba6..d79fdeb09e0 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/BatchedAlignedValueChunkData.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/BatchedAlignedValueChunkData.java
@@ -70,7 +70,11 @@ public class BatchedAlignedValueChunkData extends 
AlignedChunkData {
       throws IOException {
     pageNumbers.set(pageNumbers.size() - 1, pageNumbers.get(pageNumbers.size() 
- 1) + 1);
     final long startTime = timePartitionSlot.getStartTime();
-    final long endTime = startTime + 
TimePartitionUtils.getTimePartitionInterval();
+    // beware of overflow
+    long endTime = startTime + TimePartitionUtils.getTimePartitionInterval();
+    if (endTime <= startTime) {
+      endTime = Long.MAX_VALUE;
+    }
     final int satisfiedLength = satisfiedLengthQueue.poll();
     // serialize needDecode==true
     dataSize += ReadWriteIOUtils.write(true, stream);
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/NonAlignedChunkData.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/NonAlignedChunkData.java
index f2d17ab95fc..ccf7970a1db 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/NonAlignedChunkData.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/NonAlignedChunkData.java
@@ -163,12 +163,16 @@ public class NonAlignedChunkData implements ChunkData {
       throws IOException {
     pageNumber += 1;
     final long startTime = timePartitionSlot.getStartTime();
-    final long endTime = startTime + 
TimePartitionUtils.getTimePartitionInterval();
+    // beware of overflow
+    long endTime = startTime + TimePartitionUtils.getTimePartitionInterval() - 
1;
+    if (endTime <= startTime) {
+      endTime = Long.MAX_VALUE;
+    }
     dataSize += ReadWriteIOUtils.write(true, stream);
     dataSize += ReadWriteIOUtils.write(satisfiedLength, stream);
 
     for (int i = 0; i < times.length; i++) {
-      if (times[i] >= endTime) {
+      if (times[i] > endTime) {
         break;
       }
       if (times[i] >= startTime) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/TsFileSplitter.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/TsFileSplitter.java
index 5c86082ce8c..38700766143 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/TsFileSplitter.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/splitter/TsFileSplitter.java
@@ -249,6 +249,10 @@ public class TsFileSplitter {
         int satisfiedLength = 0;
         long endTime =
             timePartitionSlot.getStartTime() + 
TimePartitionUtils.getTimePartitionInterval();
+        // beware of overflow
+        if (endTime <= timePartitionSlot.getStartTime()) {
+          endTime = Long.MAX_VALUE;
+        }
         for (int i = 0; i < times.length; i++) {
           if (times[i] >= endTime) {
             chunkData.writeDecodePage(times, values, satisfiedLength);
@@ -264,6 +268,9 @@ public class TsFileSplitter {
             satisfiedLength = 0;
             endTime =
                 timePartitionSlot.getStartTime() + 
TimePartitionUtils.getTimePartitionInterval();
+            if (endTime <= timePartitionSlot.getStartTime()) {
+              endTime = Long.MAX_VALUE;
+            }
             chunkData = ChunkData.createChunkData(isAligned, curDevice, 
header, timePartitionSlot);
           }
           satisfiedLength += 1;
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimestampPrecisionUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimestampPrecisionUtils.java
index fb0604d0919..5b0a642a0eb 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimestampPrecisionUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimestampPrecisionUtils.java
@@ -73,10 +73,10 @@ public class TimestampPrecisionUtils {
         if (time > 10_000_000_000_000L) {
           throw new SemanticException(
               String.format(
-                  "The timestamp is unexpectedly large, you may forget to set 
the timestamp precision." +
-                  "Current system timestamp precision is %s, "
-                      + "please check whether the timestamp %s is correct." +
-                  "If you insist to insert this timestamp, please set 
timestamp_precision_check_enabled=false and restart the server.",
+                  "The timestamp is unexpectedly large, you may forget to set 
the timestamp precision."
+                      + "Current system timestamp precision is %s, "
+                      + "please check whether the timestamp %s is correct."
+                      + "If you insist to insert this timestamp, please set 
timestamp_precision_check_enabled=false and restart the server.",
                   TIMESTAMP_PRECISION, time));
         }
         break;
@@ -84,10 +84,10 @@ public class TimestampPrecisionUtils {
         if (time > 10_000_000_000_000_000L) {
           throw new SemanticException(
               String.format(
-                  "The timestamp is unexpectedly large, you may forget to set 
the timestamp precision." +
-                      "Current system timestamp precision is %s, "
-                      + "please check whether the timestamp %s is correct." +
-                      "If you insist to insert this timestamp, please set 
timestamp_precision_check_enabled=false and restart the server.",
+                  "The timestamp is unexpectedly large, you may forget to set 
the timestamp precision."
+                      + "Current system timestamp precision is %s, "
+                      + "please check whether the timestamp %s is correct."
+                      + "If you insist to insert this timestamp, please set 
timestamp_precision_check_enabled=false and restart the server.",
                   TIMESTAMP_PRECISION, time));
         }
         break;
diff --git 
a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties 
b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties
index c51f948ad25..db2835acfc5 100644
--- 
a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties
+++ 
b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties
@@ -70,3 +70,19 @@ cn_metric_prometheus_reporter_port=9091
 
 # dn_metric_reporter_list=
 dn_metric_prometheus_reporter_port=9092
+#Wed Dec 18 17:50:40 HKT 2024
+#timestamp_precision_check_enabled=false
+#Wed Dec 18 18:05:55 HKT 2024
+#timestamp_precision_check_enabled=true
+#Wed Dec 18 18:17:25 HKT 2024
+#timestamp_precision_check_enabled=false
+#Wed Dec 18 18:17:25 HKT 2024
+#timestamp_precision_check_enabled=true
+#Wed Dec 18 18:18:03 HKT 2024
+#timestamp_precision_check_enabled=false
+#Wed Dec 18 18:19:27 HKT 2024
+#timestamp_precision_check_enabled=true
+#Wed Dec 18 18:19:55 HKT 2024
+#timestamp_precision_check_enabled=false
+#Wed Dec 18 18:55:14 HKT 2024
+timestamp_precision_check_enabled=true

Reply via email to