761417898 commented on code in PR #192: URL: https://github.com/apache/tsfile/pull/192#discussion_r1729781840
########## cpp/src/reader/aligned_chunk_reader.cc: ########## @@ -0,0 +1,623 @@ +/* + * 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. + */ + +#include "aligned_chunk_reader.h" + +#include "compress/compressor_factory.h" +#include "encoding/decoder_factory.h" + +using namespace common; +namespace storage { + +int AlignedChunkReader::init(ReadFile *read_file, String m_name, + TSDataType data_type, Filter *time_filter) { + read_file_ = read_file; + measurement_name_.shallow_copy_from(m_name); + time_decoder_ = DecoderFactory::alloc_time_decoder(); + value_decoder_ = nullptr; + compressor_ = nullptr; + time_filter_ = time_filter; + time_uncompressed_buf_ = nullptr; + value_uncompressed_buf_ = nullptr; + if (IS_NULL(time_decoder_)) { + return E_OOM; + } + return E_OK; +} + +void AlignedChunkReader::reset() { + time_chunk_meta_ = nullptr; + value_chunk_meta_ = nullptr; + time_chunk_header_.reset(); + value_chunk_header_.reset(); + cur_time_page_header_.reset(); + cur_value_page_header_.reset(); + + char *file_data_buf = time_in_stream_.get_wrapped_buf(); + if (file_data_buf != nullptr) { + mem_free(file_data_buf); + } + time_in_stream_.reset(); + file_data_buf = value_in_stream_.get_wrapped_buf(); + if (file_data_buf != nullptr) { + mem_free(file_data_buf); + } + value_in_stream_.reset(); + file_data_time_buf_size_ = 0; + file_data_value_buf_size_ = 0; + time_chunk_visit_offset_ = 0; + value_chunk_visit_offset_ = 0; +} + +void AlignedChunkReader::destroy() { + if (time_decoder_ != nullptr) { + time_decoder_->~Decoder(); + DecoderFactory::free(time_decoder_); + time_decoder_ = nullptr; + } + if (value_decoder_ != nullptr) { + value_decoder_->~Decoder(); + DecoderFactory::free(value_decoder_); + value_decoder_ = nullptr; + } + if (compressor_ != nullptr) { + compressor_->~Compressor(); + CompressorFactory::free(compressor_); + compressor_ = nullptr; + } + char *buf = time_in_stream_.get_wrapped_buf(); + if (buf != nullptr) { + mem_free(buf); + time_in_stream_.clear_wrapped_buf(); + } + cur_time_page_header_.reset(); + buf = value_in_stream_.get_wrapped_buf(); + if (buf != nullptr) { + mem_free(buf); + value_in_stream_.clear_wrapped_buf(); + } + cur_value_page_header_.reset(); +} + +int AlignedChunkReader::load_by_aligned_meta(ChunkMeta *time_chunk_meta, + ChunkMeta *value_chunk_meta) { + int ret = E_OK; + time_chunk_meta_ = time_chunk_meta; + value_chunk_meta_ = value_chunk_meta; +#if DEBUG_SE + std::cout << "AlignedChunkReader::load_by_meta, meta=" << *time_chunk_meta + << ", " << *value_chunk_meta << std::endl; +#endif + /* ================ deserialize time_chunk_header ================*/ + // at least, we can reader the chunk header and the first page header. + // TODO configurable + file_data_time_buf_size_ = 1024; + file_data_value_buf_size_ = 1024; Review Comment: When a buffer shortage occurs during the deserialization of `page_header.statistic_`, the program reads more data based on the current file offset. I'm not sure if this will resolve the issue. ``` // TODOļ¼ configurable int retry_read_want_size = 1024; do { in_stream.mark_read_pos(); cur_page_header.reset(); ret = cur_page_header.deserialize_from( in_stream, !chunk_has_only_one_page(chunk_header), chunk_header.data_type_); cur_page_header_serialized_size = in_stream.get_mark_len(); if (deserialize_buf_not_enough(ret) && retry) { retry = false; retry_read_want_size += 1024; int32_t file_data_buf_size = chunk_header.data_type_ == common::VECTOR ? file_data_time_buf_size_ : file_data_value_buf_size_; if (E_OK == read_from_file_and_rewrap(in_stream, chunk_meta, chunk_visit_offset, file_data_buf_size, retry_read_want_size)) { continue; } } break; } while (true); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
