|
21 | 21 |
|
22 | 22 | import org.apache.iotdb.db.i18n.DataNodePipeMessages; |
23 | 23 |
|
| 24 | +import org.apache.tsfile.common.constant.TsFileConstant; |
24 | 25 | import org.apache.tsfile.compress.IUnCompressor; |
25 | 26 | import org.apache.tsfile.encoding.decoder.Decoder; |
26 | 27 | import org.apache.tsfile.encrypt.EncryptParameter; |
@@ -169,22 +170,49 @@ static List<Long> toSuffixMaxList(final List<Long> pageEstimatedMemoryUsageInByt |
169 | 170 | static long estimatePageMemoryUsageInBytesWithBatchData( |
170 | 171 | final PageHeader timePageHeader, |
171 | 172 | final Chunk timeChunk, |
172 | | - final List<TSDataType> valueDataTypeList) { |
| 173 | + final List<TSDataType> valueDataTypeList) |
| 174 | + throws IOException { |
173 | 175 | return estimatePageMemoryUsageInBytesWithBatchData( |
174 | 176 | timePageHeader.getUncompressedSize(), |
175 | 177 | getPageRowCount(timePageHeader, timeChunk), |
176 | 178 | valueDataTypeList); |
177 | 179 | } |
178 | 180 |
|
179 | | - static int getPageRowCount(final PageHeader pageHeader, final Chunk chunk) { |
| 181 | + static int getPageRowCount(final PageHeader pageHeader, final Chunk chunk) throws IOException { |
180 | 182 | if (isSinglePageChunk(chunk.getHeader())) { |
181 | | - return Objects.isNull(chunk.getChunkStatistic()) |
182 | | - ? 0 |
183 | | - : saturateToInt(chunk.getChunkStatistic().getCount()); |
| 183 | + if (Objects.nonNull(chunk.getChunkStatistic())) { |
| 184 | + return saturateToInt(chunk.getChunkStatistic().getCount()); |
| 185 | + } |
| 186 | + return isTimeChunk(chunk.getHeader()) ? countSinglePageTimeValues(chunk) : 0; |
184 | 187 | } |
185 | 188 | return saturateToInt(pageHeader.getNumOfValues()); |
186 | 189 | } |
187 | 190 |
|
| 191 | + private static int countSinglePageTimeValues(final Chunk chunk) throws IOException { |
| 192 | + final ByteBuffer chunkDataBuffer = chunk.getData().duplicate(); |
| 193 | + final PageHeader pageHeader = deserializePageHeader(chunkDataBuffer, chunk.getHeader()); |
| 194 | + final ByteBuffer pageData = |
| 195 | + deserializePageData( |
| 196 | + pageHeader, |
| 197 | + chunkDataBuffer, |
| 198 | + chunk.getHeader(), |
| 199 | + IDecryptor.getDecryptor(chunk.getEncryptParam())); |
| 200 | + final Decoder decoder = |
| 201 | + Decoder.getDecoderByType(chunk.getHeader().getEncodingType(), TSDataType.INT64); |
| 202 | + |
| 203 | + int rowCount = 0; |
| 204 | + while (decoder.hasNext(pageData)) { |
| 205 | + decoder.readLong(pageData); |
| 206 | + ++rowCount; |
| 207 | + } |
| 208 | + return rowCount; |
| 209 | + } |
| 210 | + |
| 211 | + private static boolean isTimeChunk(final ChunkHeader chunkHeader) { |
| 212 | + return (chunkHeader.getChunkType() & TsFileConstant.TIME_COLUMN_MASK) |
| 213 | + == TsFileConstant.TIME_COLUMN_MASK; |
| 214 | + } |
| 215 | + |
188 | 216 | private static int saturateToInt(final long value) { |
189 | 217 | return (int) Math.min(Integer.MAX_VALUE, value); |
190 | 218 | } |
|
0 commit comments