gaodayue commented on a change in pull request #1413: Add short key index builder, decoder, iterator URL: https://github.com/apache/incubator-doris/pull/1413#discussion_r298914147
########## File path: be/src/olap/olap_index.cpp ########## @@ -50,41 +53,64 @@ MemIndex::~MemIndex() { for (vector<SegmentMetaInfo>::iterator it = _meta.begin(); it != _meta.end(); ++it) { free(it->buffer.data); it->buffer.data = NULL; - it->buffer.length = 0; + it->buffer.size = 0; } } OLAPStatus MemIndex::load_segment(const char* file, size_t *current_num_rows_per_row_block) { - OLAPStatus res = OLAP_SUCCESS; - - SegmentMetaInfo meta; - OLAPIndexHeaderMessage pb; - uint32_t adler_checksum = 0; - uint32_t num_entries = 0; - - if (file == NULL) { - res = OLAP_ERR_INPUT_PARAMETER_ERROR; - OLAP_LOG_WARNING("load segment for loading index error. [file=%s; res=%d]", file, res); - return res; - } - FileHandler file_handler; + OLAPStatus res = OLAP_SUCCESS; if ((res = file_handler.open_with_cache(file, O_RDONLY)) != OLAP_SUCCESS) { OLAP_LOG_WARNING("fail to open index file. [file='%s']", file); OLAP_LOG_WARNING("load segment for loading index error. [file=%s; res=%d]", file, res); return res; } + auto file_length = file_handler.length(); + std::string file_content; + file_content.resize(file_length); - if ((res = meta.file_header.unserialize(&file_handler)) != OLAP_SUCCESS) { - OLAP_LOG_WARNING("fail to read index file header. [file='%s']", file); - OLAP_LOG_WARNING("load segment for loading index error. [file=%s; res=%d]", file, res); - file_handler.close(); + res = file_handler.pread((char*)file_content.data(), file_content.size(), 0); + file_handler.close(); + if (res != OLAP_SUCCESS) { + char errmsg[64]; + LOG(WARNING) << "fail to read data from file. file=" + << file << ", err=" << strerror_r(errno, errmsg, 64); return res; } + ShortKeyIndexDecoder decoder(file_content); + auto st = decoder.parse(); + if (!st.ok()) { + LOG(WARNING) << "failed to parse index, file=" << file + << ", msg=" << st.to_string(); + return OLAP_ERR_INDEX_LOAD_ERROR; + } + st = load_segment(decoder.header(), decoder.index_data()); + if (!st.ok()) { + LOG(WARNING) << "Failed to load segment, file=" << file << ", msg=" << st.to_string(); + return OLAP_ERR_INDEX_LOAD_ERROR; + } + + (current_num_rows_per_row_block == NULL + || (*current_num_rows_per_row_block = decoder.header().message().num_rows_per_block())); + return OLAP_SUCCESS; +} + +Status MemIndex::load_segment( + const FileHeader<OLAPIndexHeaderMessage, OLAPIndexFixedHeader>& header, const Slice& data) { Review comment: How about typedef `FileHeader<OLAPIndexHeaderMessage, OLAPIndexFixedHeader>` to V1IndexFileHeader? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org For additional commands, e-mail: dev-h...@doris.apache.org