diff --git a/tsfile/src/main/java/org/apache/tsfile/exception/StopReadTsFileByInterruptException.java b/tsfile/src/main/java/org/apache/tsfile/exception/StopReadTsFileByInterruptException.java new file mode 100644 index 000000000..6af4aad87 --- /dev/null +++ b/tsfile/src/main/java/org/apache/tsfile/exception/StopReadTsFileByInterruptException.java @@ -0,0 +1,24 @@ +/* + * 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.tsfile.exception; + +import java.io.IOException; + +public class StopReadTsFileByInterruptException extends IOException {} diff --git a/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java b/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java index 5a934a609..707954697 100644 --- a/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java +++ b/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java @@ -25,6 +25,7 @@ import org.apache.tsfile.compress.IUnCompressor; import org.apache.tsfile.encoding.decoder.Decoder; import org.apache.tsfile.enums.TSDataType; +import org.apache.tsfile.exception.StopReadTsFileByInterruptException; import org.apache.tsfile.exception.TsFileRuntimeException; import org.apache.tsfile.exception.TsFileStatisticsMistakesException; import org.apache.tsfile.file.MetaMarker; @@ -298,6 +299,8 @@ public TsFileMetadata readFileMetadata() throws IOException { } } } + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Exception e) { logger.error("Something error happened while reading file metadata of file {}", file); throw e; @@ -523,6 +526,8 @@ public List readTimeseriesMetadata( TimeseriesMetadata timeseriesMetadata; try { timeseriesMetadata = TimeseriesMetadata.deserializeFrom(tsFileInput, true); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Exception e1) { logger.error( "Something error happened while deserializing TimeseriesMetadata of file {}", file); @@ -728,6 +733,8 @@ public void getDevicesAndEntriesOfOneLeafNode( ByteBuffer nextBuffer = readData(startOffset, endOffset); MetadataIndexNode deviceLeafNode = MetadataIndexNode.deserializeFrom(nextBuffer); getDevicesOfLeafNode(deviceLeafNode, measurementNodeOffsetQueue); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Exception e) { logger.error("Something error happened while getting all devices of file {}", file); throw e; @@ -795,6 +802,8 @@ private void getAllDeviceLeafNodeOffset( getAllDeviceLeafNodeOffset( MetadataIndexNode.deserializeFrom(nextBuffer), leafDeviceNodeOffsets); } + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Exception e) { logger.error("Something error happened while getting all devices of file {}", file); throw e; @@ -926,6 +935,8 @@ private void getAllPaths( metadataIndexNode.getNodeType(), queue); } + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Exception e) { logger.error("Something error happened while getting all paths of file {}", file); throw e; @@ -1144,6 +1155,8 @@ private void generateMetadataIndex( } } } + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Exception e) { logger.error("Something error happened while generating MetadataIndex of file {}", file); throw e; @@ -1193,6 +1206,8 @@ private void generateMetadataIndexUsingTsFileInput( needChunkMetadata); } } + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Exception e) { logger.error("Something error happened while generating MetadataIndex of file {}", file); throw e; @@ -1314,6 +1329,8 @@ protected Pair getMetadataAndEndOffset( return getMetadataAndEndOffset( MetadataIndexNode.deserializeFrom(buffer), name, isDeviceLevel, exactSearch); } + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Exception e) { logger.error("Something error happened while deserializing MetadataIndex of file {}", file); throw e; @@ -1369,6 +1386,8 @@ public void readPlanIndex() throws IOException { public ChunkHeader readChunkHeader(byte chunkType) throws IOException { try { return ChunkHeader.deserializeFrom(tsFileInput.wrapAsInputStream(), chunkType); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Throwable t) { logger.warn("Exception {} happened while reading chunk header of {}", t.getMessage(), file); throw t; @@ -1383,6 +1402,8 @@ public ChunkHeader readChunkHeader(byte chunkType) throws IOException { private ChunkHeader readChunkHeader(long position) throws IOException { try { return ChunkHeader.deserializeFrom(tsFileInput, position); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Throwable t) { logger.warn("Exception {} happened while reading chunk header of {}", t.getMessage(), file); throw t; @@ -1399,6 +1420,8 @@ private ChunkHeader readChunkHeader(long position) throws IOException { public ByteBuffer readChunk(long position, int dataSize) throws IOException { try { return readData(position, dataSize); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Throwable t) { logger.warn("Exception {} happened while reading chunk of {}", t.getMessage(), file); throw t; @@ -1415,6 +1438,8 @@ public Chunk readMemChunk(long offset) throws IOException { ChunkHeader header = readChunkHeader(offset); ByteBuffer buffer = readChunk(offset + header.getSerializedSize(), header.getDataSize()); return new Chunk(header, buffer); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Throwable t) { logger.warn("Exception {} happened while reading chunk of {}", t.getMessage(), file); throw t; @@ -1434,6 +1459,8 @@ public Chunk readMemChunk(ChunkMetadata metaData) throws IOException { readChunk( metaData.getOffsetOfChunkHeader() + header.getSerializedSize(), header.getDataSize()); return new Chunk(header, buffer, metaData.getDeleteIntervalList(), metaData.getStatistics()); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Throwable t) { logger.warn("Exception {} happened while reading chunk of {}", t.getMessage(), file); throw t; @@ -1500,6 +1527,8 @@ public MeasurementSchema getMeasurementSchema(List chunkMetadata public PageHeader readPageHeader(TSDataType type, boolean hasStatistic) throws IOException { try { return PageHeader.deserializeFrom(tsFileInput.wrapAsInputStream(), type, hasStatistic); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Throwable t) { logger.warn("Exception {} happened while reading page header of {}", t.getMessage(), file); throw t; @@ -1618,6 +1647,8 @@ protected ByteBuffer readData(long position, int totalSize) throws IOException { protected ByteBuffer readData(long start, long end) throws IOException { try { return readData(start, (int) (end - start)); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Throwable t) { logger.warn("Exception {} happened while reading data of {}", t.getMessage(), file); throw t; @@ -1947,6 +1978,8 @@ public long selfCheckWithInfo( return TsFileCheckStatus.COMPLETE_FILE; } } + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (IOException e) { logger.error("Error occurred while fast checking TsFile."); throw e; @@ -1960,6 +1993,8 @@ public long selfCheckWithInfo( long tscheckStatus = TsFileCheckStatus.COMPLETE_FILE; try { tscheckStatus = checkChunkAndPagesStatistics(chunkMetadata); + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (IOException e) { logger.error("Error occurred while checking the statistics of chunk and its pages"); throw e; @@ -2392,6 +2427,8 @@ private void collectEachLeafMeasurementNodeOffsetRange( } collectEachLeafMeasurementNodeOffsetRange(readData(startOffset, endOffset), queue); } + } catch (StopReadTsFileByInterruptException e) { + throw e; } catch (Exception e) { logger.error( "Error occurred while collecting offset ranges of measurement nodes of file {}", file); diff --git a/tsfile/src/main/java/org/apache/tsfile/read/reader/LocalTsFileInput.java b/tsfile/src/main/java/org/apache/tsfile/read/reader/LocalTsFileInput.java index a7769c0d0..0ee73bd5d 100644 --- a/tsfile/src/main/java/org/apache/tsfile/read/reader/LocalTsFileInput.java +++ b/tsfile/src/main/java/org/apache/tsfile/read/reader/LocalTsFileInput.java @@ -48,7 +48,7 @@ public long size() throws IOException { try { return channel.size(); } catch (IOException e) { - logger.error("Error happened while getting {} size", filePath); + logger.warn("Error happened while getting {} size", filePath); throw e; } } @@ -58,7 +58,7 @@ public long position() throws IOException { try { return channel.position(); } catch (IOException e) { - logger.error("Error happened while getting {} current position", filePath); + logger.warn("Error happened while getting {} current position", filePath); throw e; } } @@ -69,7 +69,7 @@ public TsFileInput position(long newPosition) throws IOException { channel.position(newPosition); return this; } catch (IOException e) { - logger.error("Error happened while changing {} position to {}", filePath, newPosition); + logger.warn("Error happened while changing {} position to {}", filePath, newPosition); throw e; } }