From 4a57f644d08b165f562307dd320b66cecf943881 Mon Sep 17 00:00:00 2001 From: qiye Date: Fri, 7 Jun 2024 10:46:35 +0800 Subject: [PATCH] =?UTF-8?q?[fix](inverted=20index)Delete=20tmp=20dirs=20wh?= =?UTF-8?q?en=20BE=20starts=20to=20avoid=20tmp=20file=E2=80=A6=20(#35951)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …s left by last crash When BE crashes, there may be tmp files left in the tmp dir, so we remove and rebuild the tmp dir every time we start BE to prevent rubbish data from occupying the disk. Co-authored-by: Luennng --- be/src/olap/compaction.cpp | 3 +-- be/src/olap/rowset/segment_v2/inverted_index_writer.h | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/be/src/olap/compaction.cpp b/be/src/olap/compaction.cpp index 3f1579ff276954..47be4e01e07c60 100644 --- a/be/src/olap/compaction.cpp +++ b/be/src/olap/compaction.cpp @@ -663,8 +663,7 @@ Status Compaction::do_inverted_index_compaction() { } } - // we choose the first destination segment name as the temporary index writer path - // Used to distinguish between different index compaction + // use tmp file dir to store index files auto tmp_file_dir = ExecEnv::GetInstance()->get_tmp_file_dirs()->get_tmp_file_dir(); auto index_tmp_path = tmp_file_dir / dest_rowset_id.to_string(); LOG(INFO) << "start index compaction" diff --git a/be/src/olap/rowset/segment_v2/inverted_index_writer.h b/be/src/olap/rowset/segment_v2/inverted_index_writer.h index 77873905af107f..06bc960bc330fe 100644 --- a/be/src/olap/rowset/segment_v2/inverted_index_writer.h +++ b/be/src/olap/rowset/segment_v2/inverted_index_writer.h @@ -106,11 +106,9 @@ class TmpFileDirs { Status init() { for (auto& tmp_file_dir : _tmp_file_dirs) { - bool exists = true; - RETURN_IF_ERROR(io::global_local_filesystem()->exists(tmp_file_dir, &exists)); - if (!exists) { - RETURN_IF_ERROR(io::global_local_filesystem()->create_directory(tmp_file_dir)); - } + // delete the tmp dir to avoid the tmp files left by last crash + RETURN_IF_ERROR(io::global_local_filesystem()->delete_directory(tmp_file_dir)); + RETURN_IF_ERROR(io::global_local_filesystem()->create_directory(tmp_file_dir)); } return Status::OK(); };