diff --git a/be/src/olap/rowset/column_data_writer.cpp b/be/src/olap/rowset/column_data_writer.cpp index b90926d5944ef1..bc25a168379fd1 100644 --- a/be/src/olap/rowset/column_data_writer.cpp +++ b/be/src/olap/rowset/column_data_writer.cpp @@ -186,6 +186,21 @@ OLAPStatus ColumnDataWriter::finalize() { _segment_group->set_empty(true); return OLAP_SUCCESS; } + + // Segment which size reaches OLAP_MAX_COLUMN_SEGMENT_FILE_SIZE + // will be flushed into disk. If the previous segment reach + // the threshold just right, and been flushed into disk. + // The following finalize() when closing ColumnDataWriter + // will generate a non-sense segment. + // In this scenario, undefined behavior will happens. + if (_num_rows == 0 && _row_index == 0) { + // If the two conditions are all satisfied, + // it dedicates that there is no necessity + // to generate segment object and file. + // Return OLAP_SUCCESS is OK. + return OLAP_SUCCESS; + } + OLAPStatus res = _flush_row_block(true); if (OLAP_SUCCESS != res) { OLAP_LOG_WARNING("failed to flush data while attaching row cursor.[res=%d]", res); @@ -194,7 +209,9 @@ OLAPStatus ColumnDataWriter::finalize() { res = _finalize_segment(); if (OLAP_SUCCESS != res) { - OLAP_LOG_WARNING("fail to finalize segment.[res=%d]", res); + LOG(WARNING) << "fail to finalize segment. res=" << res + << ", _row_index=" << _row_index + << ", _all_num_rows=" << _all_num_rows; return res; } diff --git a/be/src/olap/rowset/segment_group.cpp b/be/src/olap/rowset/segment_group.cpp index cecd83ed8585c8..5d9473833a4497 100644 --- a/be/src/olap/rowset/segment_group.cpp +++ b/be/src/olap/rowset/segment_group.cpp @@ -573,8 +573,8 @@ OLAPStatus SegmentGroup::add_short_key(const RowCursor& short_key, const uint32_ file_path.c_str(), O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR); if (res != OLAP_SUCCESS) { char errmsg[64]; - LOG(WARNING) << "can not create file. [file_path='" << file_path - << "' err='" << strerror_r(errno, errmsg, 64) << "']"; + LOG(WARNING) << "can not create file. file_path=" << file_path + << ", err='" << strerror_r(errno, errmsg, 64); return res; } _new_segment_created = true; @@ -629,8 +629,8 @@ OLAPStatus SegmentGroup::finalize_segment(uint32_t data_segment_size, int64_t nu int file_length = _current_file_handler.tell(); if (file_length == -1) { - OLAP_LOG_WARNING("get file_length error. [err=%m]"); - + LOG(WARNING) << "get file_length error. err=" << Errno::no() + << ", _new_segment_created=" << _new_segment_created; return OLAP_ERR_IO_ERROR; }