This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 422a92aa4cf [fix](fd) remove fd from cache when tablet is deleted
(#34004)
422a92aa4cf is described below
commit 422a92aa4cfd8079dee59b1853445a212340b601
Author: Yongqiang YANG <[email protected]>
AuthorDate: Thu Apr 25 10:55:45 2024 +0800
[fix](fd) remove fd from cache when tablet is deleted (#34004)
---
be/src/olap/merger.cpp | 5 +++++
be/src/olap/rowset/beta_rowset.cpp | 38 +++++++++++++++++++++++++++++-------
be/src/olap/rowset/beta_rowset.h | 4 ++++
be/src/olap/rowset/rowset.cpp | 2 ++
be/src/olap/rowset/rowset.h | 3 +++
be/src/olap/storage_engine.cpp | 1 +
be/src/olap/tablet.cpp | 13 +++++++++++++
be/src/olap/tablet.h | 4 ++++
be/src/olap/tablet_manager.cpp | 40 ++++++--------------------------------
9 files changed, 69 insertions(+), 41 deletions(-)
diff --git a/be/src/olap/merger.cpp b/be/src/olap/merger.cpp
index 62753c4710c..6bcdb2206c5 100644
--- a/be/src/olap/merger.cpp
+++ b/be/src/olap/merger.cpp
@@ -104,6 +104,11 @@ Status Merger::vmerge_rowsets(TabletSharedPtr tablet,
ReaderType reader_type,
size_t output_rows = 0;
bool eof = false;
while (!eof && !StorageEngine::instance()->stopped()) {
+ if (tablet->tablet_state() == TABLET_SHUTDOWN) {
+ return Status::Error<INTERNAL_ERROR>("tablet {} is not used any
more",
+ tablet->tablet_id());
+ }
+
// Read one block from block reader
RETURN_NOT_OK_STATUS_WITH_WARN(
reader.next_block_with_aggregation(&block, &eof),
diff --git a/be/src/olap/rowset/beta_rowset.cpp
b/be/src/olap/rowset/beta_rowset.cpp
index 176ff0d21b5..bf3cb1d1e74 100644
--- a/be/src/olap/rowset/beta_rowset.cpp
+++ b/be/src/olap/rowset/beta_rowset.cpp
@@ -120,6 +120,21 @@ Status BetaRowset::do_load(bool /*use_cache*/) {
return Status::OK();
}
+void BetaRowset::clear_inverted_index_cache() {
+ for (int i = 0; i < num_segments(); ++i) {
+ auto seg_path = segment_file_path(i);
+ for (auto& column : tablet_schema()->columns()) {
+ const TabletIndex* index_meta =
tablet_schema()->get_inverted_index(column.unique_id());
+ if (index_meta) {
+ std::string inverted_index_file =
InvertedIndexDescriptor::get_index_file_name(
+ seg_path, index_meta->index_id());
+
(void)segment_v2::InvertedIndexSearcherCache::instance()->erase(
+ inverted_index_file);
+ }
+ }
+ }
+}
+
Status BetaRowset::get_segments_size(std::vector<size_t>* segments_size) {
auto fs = _rowset_meta->fs();
if (!fs || _schema == nullptr) {
@@ -177,7 +192,7 @@ Status BetaRowset::remove() {
<< ", version:" << start_version() << "-" << end_version()
<< ", tabletid:" << _rowset_meta->tablet_id();
// If the rowset was removed, it need to remove the fds in segment cache
directly
-
SegmentLoader::instance()->erase_segments(SegmentCache::CacheKey(rowset_id()));
+ clear_cache();
auto fs = _rowset_meta->fs();
if (!fs) {
return Status::Error<INIT_FAILED>("get fs failed");
@@ -201,15 +216,9 @@ Status BetaRowset::remove() {
if (!st.ok()) {
LOG(WARNING) << st.to_string();
success = false;
- } else {
-
segment_v2::InvertedIndexSearcherCache::instance()->erase(inverted_index_file);
}
}
}
- if (fs->type() != io::FileSystemType::LOCAL) {
- auto cache_path = segment_cache_path(i);
- FileCacheManager::instance()->remove_file_cache(cache_path);
- }
}
if (!success) {
return Status::Error<ROWSET_DELETE_FILE_FAILED>("failed to remove
files in rowset {}",
@@ -479,4 +488,19 @@ Status BetaRowset::add_to_binlog() {
return Status::OK();
}
+void BetaRowset::clear_cache() {
+ SegmentCache::CacheKey cache_key(rowset_id());
+ SegmentLoader::instance()->erase_segments(cache_key);
+ clear_inverted_index_cache();
+
+ auto fs = _rowset_meta->fs();
+ for (int i = 0; i < num_segments(); ++i) {
+ auto seg_path = segment_file_path(i);
+ if (fs->type() != io::FileSystemType::LOCAL) {
+ auto cache_path = segment_cache_path(i);
+ FileCacheManager::instance()->remove_file_cache(cache_path);
+ }
+ }
+}
+
} // namespace doris
diff --git a/be/src/olap/rowset/beta_rowset.h b/be/src/olap/rowset/beta_rowset.h
index 064b8fcb6ef..f4496457183 100644
--- a/be/src/olap/rowset/beta_rowset.h
+++ b/be/src/olap/rowset/beta_rowset.h
@@ -94,8 +94,12 @@ public:
Status get_segments_size(std::vector<size_t>* segments_size);
+ void clear_inverted_index_cache() override;
+
[[nodiscard]] virtual Status add_to_binlog() override;
+ void clear_cache() override;
+
protected:
BetaRowset(const TabletSchemaSPtr& schema, const std::string& tablet_path,
const RowsetMetaSharedPtr& rowset_meta);
diff --git a/be/src/olap/rowset/rowset.cpp b/be/src/olap/rowset/rowset.cpp
index 3cf6d92a8fe..0872149a68f 100644
--- a/be/src/olap/rowset/rowset.cpp
+++ b/be/src/olap/rowset/rowset.cpp
@@ -19,7 +19,9 @@
#include <gen_cpp/olap_file.pb.h>
+#include "io/cache/file_cache_manager.h"
#include "olap/olap_define.h"
+#include "olap/segment_loader.h"
#include "olap/tablet_schema.h"
#include "util/time.h"
diff --git a/be/src/olap/rowset/rowset.h b/be/src/olap/rowset/rowset.h
index 7c932522006..c860cf6f646 100644
--- a/be/src/olap/rowset/rowset.h
+++ b/be/src/olap/rowset/rowset.h
@@ -312,6 +312,9 @@ public:
// set skip index compaction next time
void set_skip_index_compaction(int32_t column_id) {
skip_index_compaction.insert(column_id); }
+ virtual void clear_inverted_index_cache() { LOG(INFO) << "should not reach
here"; }
+ virtual void clear_cache() { LOG(INFO) << "should not reach here"; }
+
protected:
friend class RowsetFactory;
diff --git a/be/src/olap/storage_engine.cpp b/be/src/olap/storage_engine.cpp
index e48ecb56d05..2bd70b57730 100644
--- a/be/src/olap/storage_engine.cpp
+++ b/be/src/olap/storage_engine.cpp
@@ -1074,6 +1074,7 @@ void StorageEngine::start_delete_unused_rowset() {
}
// remote rowset data will be reclaimed by
`remove_unused_remote_files`
evict_querying_rowset(it->second->rowset_id());
+ it->second->clear_cache();
it = _unused_rowsets.erase(it);
} else {
++it;
diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp
index ab7653684e9..8cfc803ad27 100644
--- a/be/src/olap/tablet.cpp
+++ b/be/src/olap/tablet.cpp
@@ -837,6 +837,7 @@ void Tablet::delete_expired_stale_rowset() {
if (it->second->is_local()) {
StorageEngine::instance()->add_unused_rowset(it->second);
}
+ it->second->clear_cache();
_stale_rs_version_map.erase(it);
VLOG_NOTICE << "delete stale rowset tablet=" <<
full_name() << " version["
<< timestampedVersion->version().first << ","
@@ -3993,4 +3994,16 @@ Status
Tablet::check_delete_bitmap_correctness(DeleteBitmapPtr delete_bitmap, in
}
return Status::OK();
}
+
+void Tablet::clear_cache() {
+ std::shared_lock rlock(get_header_lock());
+ static auto recycle_segment_cache = [](const auto& rowset_map) {
+ for (auto& [_, rowset] : rowset_map) {
+ rowset->clear_cache();
+ }
+ };
+ recycle_segment_cache(rowset_map());
+ recycle_segment_cache(stale_rowset_map());
+}
+
} // namespace doris
diff --git a/be/src/olap/tablet.h b/be/src/olap/tablet.h
index b6c01e84d5c..f3ee91b9d1b 100644
--- a/be/src/olap/tablet.h
+++ b/be/src/olap/tablet.h
@@ -572,6 +572,8 @@ public:
void set_alter_failed(bool alter_failed) { _alter_failed = alter_failed; }
bool is_alter_failed() { return _alter_failed; }
+ void clear_cache();
+
private:
Status _init_once_action();
void _print_missed_versions(const std::vector<Version>& missed_versions)
const;
@@ -620,6 +622,8 @@ private:
void _remove_sentinel_mark_from_delete_bitmap(DeleteBitmapPtr
delete_bitmap);
std::string _get_rowset_info_str(RowsetSharedPtr rowset, bool delete_flag);
+ void _clear_cache_by_rowset(const BetaRowsetSharedPtr& rowset);
+
public:
static const int64_t K_INVALID_CUMULATIVE_POINT = -1;
diff --git a/be/src/olap/tablet_manager.cpp b/be/src/olap/tablet_manager.cpp
index 29b61ac8c53..f31cd422caf 100644
--- a/be/src/olap/tablet_manager.cpp
+++ b/be/src/olap/tablet_manager.cpp
@@ -553,40 +553,8 @@ Status TabletManager::_drop_tablet_unlocked(TTabletId
tablet_id, TReplicaId repl
_remove_tablet_from_partition(to_drop_tablet);
tablet_map_t& tablet_map = _get_tablet_map(tablet_id);
tablet_map.erase(tablet_id);
- {
- std::shared_lock rlock(to_drop_tablet->get_header_lock());
- static auto recycle_segment_cache = [](const auto& rowset_map) {
- for (auto& [_, rowset] : rowset_map) {
- // If the tablet was deleted, it need to remove all rowsets
fds directly
- SegmentLoader::instance()->erase_segments(
- SegmentCache::CacheKey(rowset->rowset_id()));
- }
- };
- recycle_segment_cache(to_drop_tablet->rowset_map());
- recycle_segment_cache(to_drop_tablet->stale_rowset_map());
- // recycle inverted index cache
- static auto recycle_inverted_index_cache = [](const auto& rowset_map) {
- for (auto& [_, rowset] : rowset_map) {
- auto rs = std::static_pointer_cast<BetaRowset>(rowset);
- for (int i = 0; i < rs->num_segments(); ++i) {
- auto seg_path = rs->segment_file_path(i);
- for (auto& column : rs->tablet_schema()->columns()) {
- const TabletIndex* index_meta =
-
rs->tablet_schema()->get_inverted_index(column.unique_id());
- if (index_meta) {
- std::string inverted_index_file =
-
InvertedIndexDescriptor::get_index_file_name(
- seg_path, index_meta->index_id());
-
(void)segment_v2::InvertedIndexSearcherCache::instance()->erase(
- inverted_index_file);
- }
- }
- }
- }
- };
- recycle_inverted_index_cache(to_drop_tablet->rowset_map());
- recycle_inverted_index_cache(to_drop_tablet->stale_rowset_map());
- }
+ to_drop_tablet->clear_cache();
+
if (!keep_files) {
// drop tablet will update tablet meta, should lock
std::lock_guard<std::shared_mutex>
wrlock(to_drop_tablet->get_header_lock());
@@ -1167,6 +1135,9 @@ bool TabletManager::_move_tablet_to_trash(const
TabletSharedPtr& tablet) {
<< " cur tablet_uid=" << tablet_meta->tablet_uid();
return true;
}
+
+ tablet->clear_cache();
+
// move data to trash
const auto& tablet_path = tablet->tablet_path();
bool exists = false;
@@ -1208,6 +1179,7 @@ bool TabletManager::_move_tablet_to_trash(const
TabletSharedPtr& tablet) {
<< ", schema_hash=" << tablet->schema_hash() << ",
tablet_path=" << tablet_path;
return true;
} else {
+ tablet->clear_cache();
// if could not find tablet info in meta store, then check if dir
existed
const auto& tablet_path = tablet->tablet_path();
bool exists = false;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]