Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Add more metric for vacuum #56234

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sevev
Copy link
Contributor

@sevev sevev commented Feb 25, 2025

Why I'm doing:

What I'm doing:

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.4
    • 3.3
    • 3.2
    • 3.1
    • 3.0

Signed-off-by: sevev <[email protected]>
Signed-off-by: sevev <[email protected]>
Signed-off-by: sevev <[email protected]>
Signed-off-by: sevev <[email protected]>
@sevev sevev requested review from a team as code owners February 25, 2025 02:18
@github-actions github-actions bot added the 3.3 label Feb 25, 2025
@wanpengfei-git wanpengfei-git requested a review from a team February 25, 2025 02:18
@github-actions github-actions bot added the 3.4 label Feb 25, 2025
@wanpengfei-git wanpengfei-git requested a review from a team February 25, 2025 02:18
@mergify mergify bot assigned sevev Feb 25, 2025
@@ -406,6 +417,7 @@ private void waitResponse() {
LakeTablet tablet = (LakeTablet) tablets.get(stat.tabletId);
tablet.setDataSize(stat.dataSize);
tablet.setRowCount(stat.numRows);
tablet.setStorageSize(stat.storageSize);
tablet.setDataSizeUpdateTime(collectStatTime);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
Incorrect use of partition.getLastVacuumTime() when filtering tablets instead of using vacuumVersion

You can modify the code like this:

-                   lakeTablet.getDataSizeUpdateTime() >= partition.getLastVacuumTime();
+                   lakeTablet.getDataSizeUpdateTime() >= snapshot.vacuumVersion;

@@ -489,7 +497,8 @@ public String toString() {
buffer.append("versionEpoch: ").append(versionEpoch).append("; ");
buffer.append("versionTxnType: ").append(versionTxnType).append("; ");

buffer.append("storageDataSize: ").append(storageDataSize()).append("; ");
buffer.append("dataSize: ").append(dataSize()).append("; ");
buffer.append("storageSize: ").append(storageSize()).append("; ");
buffer.append("storageRowCount: ").append(storageRowCount()).append("; ");
buffer.append("storageReplicaCount: ").append(storageReplicaCount()).append("; ");

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
Renaming the method storageDataSize() to dataSize() without updating all references to it could cause issues if storageDataSize() is used elsewhere.

You can modify the code like this:

// Ensure that all references to storageDataSize() are updated, or retain the old method for backward compatibility.
public long getTabletMaxDataSize() {
    return maxDataSize;
}

public long dataSize() {  // formerly named storageDataSize
    long dataSize = 0;
    for (MaterializedIndex mIndex : getMaterializedIndices(IndexExtState.VISIBLE)) {
        dataSize += mIndex.getDataSize();
    }
    return dataSize;
}

// Optionally, retain the original method with a deprecated annotation if used elsewhere:
// @Deprecated
// public long storageDataSize() {
//     return dataSize();
// }

public long storageSize() {
    long storageSize = 0;
    for (MaterializedIndex mIndex : getMaterializedIndices(IndexExtState.VISIBLE)) {
        storageSize += mIndex.getStorageSize();
    }
    return storageSize;
}

public long storageRowCount() {
    long rowCount = 0;
    for (MaterializedIndex mIndex : getMaterializedIndices(IndexExtState.VISIBLE)) {
        rowCount += mIndex.getRowCount();
    }
    return rowCount;
}

public String toString() {
    buffer.append("versionEpoch: ").append(versionEpoch).append("; ");
    buffer.append("versionTxnType: ").append(versionTxnType).append("; ");

    buffer.append("dataSize: ").append(dataSize()).append("; ");
    buffer.append("storageSize: ").append(storageSize()).append("; ");
    buffer.append("storageRowCount: ").append(storageRowCount()).append("; ");
    buffer.append("storageReplicaCount: ").append(storageReplicaCount()).append("; ");
}

}
return total_size;
}

} // namespace starrocks::lake No newline at end of file
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
Potential infinite loop due to incorrect update condition for 'version'.

You can modify the code like this:

StatusOr<int64_t> TabletManager::collect_tablet_storage_size(int64_t tablet_id, int64_t curr_version,
                                                             int64_t vacuum_version) {
    auto root_dir = tablet_root_location(tablet_id);
    auto data_dir = join_path(root_dir, lake::kSegmentDirectoryName);
    auto version = curr_version;
    int64_t total_size = 0;
    ASSIGN_OR_RETURN(auto fs, FileSystem::CreateSharedFromString(root_dir));
    while (version >= vacuum_version) {
        auto res = get_tablet_metadata(tablet_id, version, false);
        if (res.status().is_not_found()) {
            break;
        } else if (!res.ok()) {
            return res.status();
        }
        auto metadata = std::move(res).value();

        if (version == curr_version) {
            for (const auto& rowset : metadata->rowsets()) {
                total_size += rowset.data_size();
            }
        }

        if (version > vacuum_version) {
            for (const auto& rowset : metadata->compaction_inputs()) {
                total_size += rowset.data_size();
            }

            for (const auto& file : metadata->orphan_files()) {
                total_size += file.size();
            }

            for (auto& [_, file_meta] : metadata->delvec_meta().version_to_file()) {
                total_size += file_meta.size();
            }

            for (const auto& sstable : metadata->sstable_meta().sstables()) {
                total_size += sstable.filesize();
            }
        }

        // Update 'version' correctly to avoid potential infinite loop
        int64_t new_version = metadata->prev_garbage_version();
        if (new_version >= version) {
            break; // Prevent infinite loop
        }
        version = new_version;
    }
    return total_size;
}

Signed-off-by: sevev <[email protected]>
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants