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

refactor(meta): break hummock manager Versioning into smaller structs #16710

Merged
merged 2 commits into from
May 16, 2024

Conversation

wenym1
Copy link
Contributor

@wenym1 wenym1 commented May 13, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Currently, we have a Versioning struct that holds many informations, and it is protected by a single rwlock. Every time we want to access the fields of it, we need to acquire the lock, which may have great lock contention. Besides, having such a large struct will bundle different functionality together, which increases the overall code readability and maintainability.

In this PR, we break the Versioning struct into some smaller structs, and each struct is protected by their individual lock. The struct is broken in the following way.

Current

struct Versioning {
    // Volatile states below
    pub disable_commit_epochs: bool,
    pub current_version: HummockVersion,
    pub objects_to_delete: HashSet<HummockSstableObjectId>,
    pub branched_ssts: BTreeMap<
        // SST object id
        HummockSstableObjectId,
        BranchedSstInfo,
    >,
    pub version_safe_points: Vec<HummockVersionId>,
    pub write_limit: HashMap<CompactionGroupId, WriteLimit>,

    // Persistent states below
    pub hummock_version_deltas: BTreeMap<HummockVersionId, HummockVersionDelta>,
    pub pinned_versions: BTreeMap<HummockContextId, HummockPinnedVersion>,
    pub pinned_snapshots: BTreeMap<HummockContextId, HummockPinnedSnapshot>,
    pub version_stats: HummockVersionStats,
    pub checkpoint: HummockVersionCheckpoint,
    pub local_metrics: HashMap<u32, LocalTableMetrics>,
}

struct DeleteObjectTracker {
    objects_to_delete: Mutex<HashSet<HummockSstableObjectId>>,
}

After this PR

struct Versioning {
    // Volatile states below
    pub disable_commit_epochs: bool,
    pub current_version: HummockVersion,
    // pub objects_to_delete: HashSet<HummockSstableObjectId>, moved to `DeleteObjectTracker`
    pub branched_ssts: BTreeMap<
        // SST object id
        HummockSstableObjectId,
        BranchedSstInfo,
    >,
    // pub version_safe_points: Vec<HummockVersionId>, moved to `ContextInfo`
    // pub write_limit: HashMap<CompactionGroupId, WriteLimit>, moved to `CompactionGroupManager`

    // Persistent states below
    pub hummock_version_deltas: BTreeMap<HummockVersionId, HummockVersionDelta>,
    // pub pinned_versions: BTreeMap<HummockContextId, HummockPinnedVersion>, moved to `ContextInfo`
    // pub pinned_snapshots: BTreeMap<HummockContextId, HummockPinnedSnapshot>, moved to `ContextInfo`
    pub version_stats: HummockVersionStats,
    pub checkpoint: HummockVersionCheckpoint,
    pub local_metrics: HashMap<u32, LocalTableMetrics>,
}

struct ContextInfo { // newly added struct
    pub pinned_versions: BTreeMap<HummockContextId, HummockPinnedVersion>,
    pub pinned_snapshots: BTreeMap<HummockContextId, HummockPinnedSnapshot>,
    /// `version_safe_points` is similar to `pinned_versions` expect for being a transient state.
    pub version_safe_points: Vec<HummockVersionId>,
}

struct DeleteObjectTracker { // newly added struct 
    objects_to_delete: Mutex<HashSet<HummockSstableObjectId>>,
}

struct CompactionGroupManager { // original struct
    compaction_groups: BTreeMap<CompactionGroupId, CompactionGroup>,
    default_config: CompactionConfig,
    /// Tables that write limit is trigger for.
    pub write_limit: HashMap<CompactionGroupId, WriteLimit>, // newly added field
    meta_store_impl: MetaStoreImpl,
}

The MonitoredRwlock is updated by the way. Previously we have a label func_name, which specify the name of the function that waits on acquiring the lock. However, this information is not important, because they are acquiring the same lock with same logic, and it makes no difference on whichever function is acquiring the lock. Therefore, in this PR, we remove the func_name label, and then we don't need the #[named] macro to get the function automatically. The read_lock! and write_lock! macro is removed accordingly. We can simply call read() and write().

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

Copy link
Contributor

@zwang28 zwang28 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Li0k Li0k left a comment

Choose a reason for hiding this comment

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

LGTM,thanks for the effort

use crate::model::{BTreeMapTransaction, BTreeMapTransactionWrapper, ValTransaction};
use crate::storage::MetaStore;

impl HummockManager {
#[derive(Default)]
pub(super) struct ContextInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

qq: what means "Context" ?

@wenym1 wenym1 enabled auto-merge May 16, 2024 09:41
@wenym1 wenym1 added this pull request to the merge queue May 16, 2024
Merged via the queue into main with commit 93c221d May 16, 2024
28 of 29 checks passed
@wenym1 wenym1 deleted the yiming/break-hummock-manager-versioning branch May 16, 2024 10:20
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.

3 participants