gavinchou commented on code in PR #35338:
URL: https://github.com/apache/doris/pull/35338#discussion_r1613337511


##########
be/src/util/block_compression.cpp:
##########
@@ -140,37 +140,45 @@ class Lz4BlockCompression : public BlockCompressionCodec {
                 _release_compression_ctx(std::move(context));
             }
         }};
-        Slice compressed_buf;
-        size_t max_len = max_compressed_len(input.size);
-        if (max_len > MAX_COMPRESSION_BUFFER_SIZE_FOR_REUSE) {
-            // use output directly
-            output->resize(max_len);
-            compressed_buf.data = reinterpret_cast<char*>(output->data());
-            compressed_buf.size = max_len;
-        } else {
-            // reuse context buffer if max_len <= 
MAX_COMPRESSION_BUFFER_FOR_REUSE
-            {
-                // context->buffer is resuable between queries, should 
accouting to
-                // global tracker.
-                SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(
-                        
ExecEnv::GetInstance()->block_compression_mem_tracker());
-                context->buffer->resize(max_len);
+
+        try {
+            Slice compressed_buf;
+            size_t max_len = max_compressed_len(input.size);
+            if (max_len > MAX_COMPRESSION_BUFFER_SIZE_FOR_REUSE) {
+                // use output directly
+                output->resize(max_len);
+                compressed_buf.data = reinterpret_cast<char*>(output->data());
+                compressed_buf.size = max_len;
+            } else {
+                // reuse context buffer if max_len <= 
MAX_COMPRESSION_BUFFER_FOR_REUSE
+                {
+                    // context->buffer is resuable between queries, should 
accouting to
+                    // global tracker.
+                    SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(
+                            
ExecEnv::GetInstance()->block_compression_mem_tracker());
+                    context->buffer->resize(max_len);
+                }
+                compressed_buf.data = 
reinterpret_cast<char*>(context->buffer->data());
+                compressed_buf.size = max_len;
             }
-            compressed_buf.data = 
reinterpret_cast<char*>(context->buffer->data());
-            compressed_buf.size = max_len;
-        }
 
-        size_t compressed_len =
-                LZ4_compress_fast_continue(context->ctx, input.data, 
compressed_buf.data,
-                                           input.size, compressed_buf.size, 
ACCELARATION);
-        if (compressed_len == 0) {
-            compress_failed = true;
-            return Status::InvalidArgument("Output buffer's capacity is not 
enough, size={}",
-                                           compressed_buf.size);
-        }
-        output->resize(compressed_len);
-        if (max_len <= MAX_COMPRESSION_BUFFER_SIZE_FOR_REUSE) {
-            
output->assign_copy(reinterpret_cast<uint8_t*>(compressed_buf.data), 
compressed_len);
+            size_t compressed_len =
+                    LZ4_compress_fast_continue(context->ctx, input.data, 
compressed_buf.data,
+                                               input.size, 
compressed_buf.size, ACCELARATION);
+            if (compressed_len == 0) {
+                compress_failed = true;
+                return Status::InvalidArgument("Output buffer's capacity is 
not enough, size={}",
+                                               compressed_buf.size);
+            }
+            output->resize(compressed_len);
+            if (max_len <= MAX_COMPRESSION_BUFFER_SIZE_FOR_REUSE) {
+                
output->assign_copy(reinterpret_cast<uint8_t*>(compressed_buf.data),
+                                    compressed_len);
+            }
+        } catch (...) {
+            // Do not set compress_failed to release context
+            DCHECK(!compress_failed);
+            return Status::InternalError("Fail to do LZ4Block compress due to 
exception");

Review Comment:
   also + e.what()? 



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to