Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Jan 9, 2025
1 parent bbf8a81 commit c58c86f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions be/src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,8 @@ DEFINE_mBool(enable_sleep_between_delete_cumu_compaction, "false");

DEFINE_mInt32(compaction_num_per_round, "1");

DEFINE_mBool(enable_remove_useless_delete_bitmaps, "true");

// clang-format off
#ifdef BE_TEST
// test s3
Expand Down
2 changes: 2 additions & 0 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,8 @@ DECLARE_mBool(enable_sleep_between_delete_cumu_compaction);

DECLARE_mInt32(compaction_num_per_round);

DECLARE_mBool(enable_remove_useless_delete_bitmaps);

#ifdef BE_TEST
// test s3
DECLARE_String(test_s3_resource);
Expand Down
24 changes: 24 additions & 0 deletions be/src/olap/tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,30 @@ void Tablet::_delete_stale_rowset_by_version(const Version& version) {
VLOG_NOTICE << "delete stale rowset. tablet=" << tablet_id() << ", version=" << version;
}

void Tablet::remove_useless_delete_bitmaps() {
std::vector<RowsetId> useless_rowsets;
{
// hold read lock to find out delete bitmaps to remove
std::shared_lock<std::shared_mutex> rlock {_meta_lock};
_tablet_meta->delete_bitmap().traverse_rowset_id_prefix([&](const RowsetId& rowset_id) {
if (!_contains_rowset(rowset_id)) {
// delete bitmaps on these rowsets will never be used
useless_rowsets.emplace_back(rowset_id);
}
});
}

{
// hold write lock to remove useless delete bitmaps
std::lock_guard<std::shared_mutex> wlock {_meta_lock};
for (const auto& rowset_id : useless_rowsets) {
_tablet_meta->delete_bitmap().remove_by_rowset_prefix(rowset_id);
}
}
LOG_WARNING("removed useless delete bitmaps on {} rowsets, tablet_id={}",
useless_rowsets.size(), tablet_id());
}

void Tablet::delete_expired_stale_rowset() {
int64_t now = UnixSeconds();
// hold write lock while processing stable rowset
Expand Down
2 changes: 2 additions & 0 deletions be/src/olap/tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ class Tablet final : public BaseTablet {
/// need to delete flag.
void delete_expired_stale_rowset();

void remove_useless_delete_bitmaps();

// Given spec_version, find a continuous version path and store it in version_path.
// If quiet is true, then only "does this path exist" is returned.
// If skip_missing_version is true, return ok even there are missing versions.
Expand Down
6 changes: 6 additions & 0 deletions be/src/olap/tablet_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,12 @@ Status TabletManager::start_trash_sweep() {
for_each_tablet([](const TabletSharedPtr& tablet) { tablet->delete_expired_stale_rowset(); },
filter_all_tablets);

if (config::enable_remove_useless_delete_bitmaps) {
for_each_tablet(
[](const TabletSharedPtr& tablet) { tablet->remove_useless_delete_bitmaps(); },
filter_all_tablets);
}

std::list<TabletSharedPtr>::iterator last_it;
{
std::shared_lock rdlock(_shutdown_tablets_lock);
Expand Down
20 changes: 20 additions & 0 deletions be/src/olap/tablet_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <time.h>

#include <cstdint>
#include <limits>
#include <set>
#include <utility>

Expand Down Expand Up @@ -1245,6 +1246,25 @@ uint64_t DeleteBitmap::get_delete_bitmap_count() {
return count;
}

void DeleteBitmap::traverse_rowset_id_prefix(
const std::function<void(const RowsetId& rowsetId)>& func) const {
auto it = delete_bitmap.cbegin();
while (it != delete_bitmap.cend()) {
RowsetId rowset_id = std::get<0>(it->first);
func(rowset_id);
// find next rowset id
it = delete_bitmap.upper_bound({rowset_id, std::numeric_limits<SegmentId>::max(),
std::numeric_limits<Version>::max()});
}
}

void DeleteBitmap::remove_by_rowset_prefix(const RowsetId& rowset_id) {
BitmapKey start {rowset_id, 0, 0};
BitmapKey end {rowset_id, std::numeric_limits<SegmentId>::max(),
std::numeric_limits<Version>::max()};
remove(start, end);
}

// We cannot just copy the underlying memory to construct a string
// due to equivalent objects may have different padding bytes.
// Reading padding bytes is undefined behavior, neither copy nor
Expand Down
4 changes: 4 additions & 0 deletions be/src/olap/tablet_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ class DeleteBitmap {

uint64_t get_delete_bitmap_count();

void traverse_rowset_id_prefix(const std::function<void(const RowsetId& rowsetId)>& func) const;

void remove_by_rowset_prefix(const RowsetId& rowset_id);

class AggCachePolicy : public LRUCachePolicy {
public:
AggCachePolicy(size_t capacity)
Expand Down

0 comments on commit c58c86f

Please sign in to comment.