From 1d16ad0682d04f1d3a295989daf6b3e2bcd08b30 Mon Sep 17 00:00:00 2001 From: obdev Date: Fri, 9 Feb 2024 22:27:14 +0000 Subject: [PATCH] fix an unexpected BUF_NOT_ENOUGH error of all_string_data_writer of cs_encoding --- .../cs_encoding/ob_string_stream_encoder.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/storage/blocksstable/cs_encoding/ob_string_stream_encoder.h b/src/storage/blocksstable/cs_encoding/ob_string_stream_encoder.h index 0b1bf8de4c..80bed54782 100644 --- a/src/storage/blocksstable/cs_encoding/ob_string_stream_encoder.h +++ b/src/storage/blocksstable/cs_encoding/ob_string_stream_encoder.h @@ -75,7 +75,19 @@ int ObStringStreamEncoder::do_convert_datum_to_stream_(ObIDatumIter &iter) if (!is_fixed_len) { offset_arr_count_ = (uint32_t)(iter.size()); int64_t offset_arr_len = offset_arr_count_ * sizeof(T); - if (OB_FAIL(all_string_writer_->ensure_space(umcompress_len + offset_arr_len))) { + if (umcompress_len + offset_arr_len > all_string_writer_->remain()) { + // remain size is not enough to hold umcompress_len and offset_array_len, which is possible + // if the fixed-length data use variable-length encoding due to existing many null values. + if (OB_FAIL(all_string_writer_->ensure_space(umcompress_len))) { + STORAGE_LOG(WARN, "fail to ensure space", K(ret), K(umcompress_len), K(offset_arr_len)); + } else { + byte_arr_ = all_string_writer_->current(); + if (OB_ISNULL(offset_arr_ = ctx_->info_.allocator_->alloc(offset_arr_len))) { + ret = OB_ALLOCATE_MEMORY_FAILED; + STORAGE_LOG(WARN, "fail to malloc", K(ret), K(umcompress_len), K(offset_arr_len)); + } + } + } else if (OB_FAIL(all_string_writer_->ensure_space(umcompress_len + offset_arr_len))) { STORAGE_LOG(WARN, "fail to ensure space", K(ret), K(umcompress_len), K(offset_arr_len)); } else { byte_arr_ = all_string_writer_->current();