This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c353098fb0 [enhance](FileWriter) Prevent multiple invocation to 
FileWriter's close function (#34890)
1c353098fb0 is described below

commit 1c353098fb0f1b5544f89017b26a57d12822569f
Author: AlexYue <yj976240...@gmail.com>
AuthorDate: Wed May 15 17:20:29 2024 +0800

    [enhance](FileWriter) Prevent multiple invocation to FileWriter's close 
function (#34890)
---
 be/src/io/cache/fs_file_cache_storage.cpp      | 4 +++-
 be/src/io/fs/benchmark/base_benchmark.h        | 2 +-
 be/src/olap/rowset/beta_rowset_writer.cpp      | 5 +++--
 be/src/olap/rowset/segcompaction.cpp           | 2 +-
 be/src/vec/core/block_spill_writer.h           | 6 +++++-
 be/src/vec/sink/writer/vfile_result_writer.cpp | 3 ++-
 6 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/be/src/io/cache/fs_file_cache_storage.cpp 
b/be/src/io/cache/fs_file_cache_storage.cpp
index 2b12abf48df..18c26fa05d4 100644
--- a/be/src/io/cache/fs_file_cache_storage.cpp
+++ b/be/src/io/cache/fs_file_cache_storage.cpp
@@ -144,7 +144,9 @@ Status FSFileCacheStorage::finalize(const FileCacheKey& 
key) {
         file_writer = std::move(iter->second);
         _key_to_writer.erase(iter);
     }
-    RETURN_IF_ERROR(file_writer->close());
+    if (file_writer->state() != FileWriter::State::CLOSED) {
+        RETURN_IF_ERROR(file_writer->close());
+    }
     std::string dir = get_path_in_local_cache(key.hash, 
key.meta.expiration_time);
     std::string true_file = get_path_in_local_cache(dir, key.offset, 
key.meta.type);
     return fs->rename(file_writer->path(), true_file);
diff --git a/be/src/io/fs/benchmark/base_benchmark.h 
b/be/src/io/fs/benchmark/base_benchmark.h
index 8f263b80d93..4c75b3ff9e8 100644
--- a/be/src/io/fs/benchmark/base_benchmark.h
+++ b/be/src/io/fs/benchmark/base_benchmark.h
@@ -177,7 +177,7 @@ public:
             }
             remaining_size -= size;
         }
-        if (status.ok() && writer != nullptr) {
+        if (status.ok() && writer != nullptr && writer->state() != 
FileWriter::State::CLOSED) {
             status = writer->close();
         }
 
diff --git a/be/src/olap/rowset/beta_rowset_writer.cpp 
b/be/src/olap/rowset/beta_rowset_writer.cpp
index f323441640d..5029a406b8a 100644
--- a/be/src/olap/rowset/beta_rowset_writer.cpp
+++ b/be/src/olap/rowset/beta_rowset_writer.cpp
@@ -854,7 +854,8 @@ Status 
BetaRowsetWriter::_create_segment_writer_for_segcompaction(
             file_writer.get(), _num_segcompacted, _context.tablet_schema, 
_context.tablet,
             _context.data_dir, _context.max_rows_per_segment, writer_options, 
_context.mow_context,
             _context.fs);
-    if (_segcompaction_worker->get_file_writer() != nullptr) {
+    if (auto& seg_writer = _segcompaction_worker->get_file_writer();
+        seg_writer != nullptr && seg_writer->state() != 
io::FileWriter::State::CLOSED) {
         RETURN_IF_ERROR(_segcompaction_worker->get_file_writer()->close());
     }
     _segcompaction_worker->get_file_writer().reset(file_writer.release());
@@ -921,7 +922,7 @@ Status BaseBetaRowsetWriter::add_segment(uint32_t 
segment_id, const SegmentStati
     if (_context.mow_context != nullptr) {
         // ensure that the segment file writing is complete
         auto* file_writer = _seg_files.get(segment_id);
-        if (file_writer) {
+        if (file_writer && file_writer->state() != 
io::FileWriter::State::CLOSED) {
             RETURN_IF_ERROR(file_writer->close());
         }
         RETURN_IF_ERROR(_generate_delete_bitmap(segment_id));
diff --git a/be/src/olap/rowset/segcompaction.cpp 
b/be/src/olap/rowset/segcompaction.cpp
index be19c74cf9c..fd45956d362 100644
--- a/be/src/olap/rowset/segcompaction.cpp
+++ b/be/src/olap/rowset/segcompaction.cpp
@@ -281,7 +281,7 @@ Status 
SegcompactionWorker::_do_compact_segments(SegCompactionCandidatesSharedPt
     RETURN_IF_ERROR(
             _writer->flush_segment_writer_for_segcompaction(&writer, 
total_index_size, key_bounds));
 
-    if (_file_writer != nullptr) {
+    if (_file_writer != nullptr && _file_writer->state() != 
io::FileWriter::State::CLOSED) {
         RETURN_IF_ERROR(_file_writer->close());
     }
 
diff --git a/be/src/vec/core/block_spill_writer.h 
b/be/src/vec/core/block_spill_writer.h
index 4785258c156..86533a99966 100644
--- a/be/src/vec/core/block_spill_writer.h
+++ b/be/src/vec/core/block_spill_writer.h
@@ -47,7 +47,11 @@ public:
         _init_profile();
     }
 
-    ~BlockSpillWriter() { static_cast<void>(close()); }
+    ~BlockSpillWriter() {
+        if (nullptr != file_writer_ && file_writer_->state() != 
io::FileWriter::State::CLOSED) {
+            std::ignore = file_writer_->close();
+        }
+    }
 
     Status open();
 
diff --git a/be/src/vec/sink/writer/vfile_result_writer.cpp 
b/be/src/vec/sink/writer/vfile_result_writer.cpp
index d8f6cfa5747..de916c4c2ea 100644
--- a/be/src/vec/sink/writer/vfile_result_writer.cpp
+++ b/be/src/vec/sink/writer/vfile_result_writer.cpp
@@ -32,6 +32,7 @@
 #include "io/file_factory.h"
 #include "io/fs/broker_file_system.h"
 #include "io/fs/file_system.h"
+#include "io/fs/file_writer.h"
 #include "io/fs/hdfs_file_system.h"
 #include "io/fs/local_file_system.h"
 #include "io/fs/s3_file_system.h"
@@ -239,7 +240,7 @@ Status VFileResultWriter::_close_file_writer(bool done) {
         // and _current_written_bytes will less than 
_vfile_writer->written_len()
         COUNTER_UPDATE(_written_data_bytes, _vfile_writer->written_len());
         _vfile_writer.reset(nullptr);
-    } else if (_file_writer_impl) {
+    } else if (_file_writer_impl && _file_writer_impl->state() != 
io::FileWriter::State::CLOSED) {
         RETURN_IF_ERROR(_file_writer_impl->close());
     }
 


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

Reply via email to