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

feat(meta): add CompactorManager #556

Merged
merged 5 commits into from
Mar 2, 2022
Merged

Conversation

zwang28
Copy link
Contributor

@zwang28 zwang28 commented Feb 25, 2022

What's changed and what's your intention?

This PR adds CompactorManager in meta node.

  • It maintains available compactors running in compute nodes.
  • It dispatches compact task to compactors via server-streaming RPC, in a round-robin approach.

Detailed in #546.

After this PR is merged, there will be no compaction at all temporarily, until compactor-node is integrated in next PR.

Checklist

  • I have written necessary docs and comments
  • I have added necessary unit tests

Refer to a related PR or issue link (optional)

#546

@zwang28 zwang28 force-pushed the wangzheng/refactor_compaction branch 2 times, most recently from 8c1134b to c15ff67 Compare February 25, 2022 07:50
@codecov
Copy link

codecov bot commented Feb 25, 2022

Codecov Report

Merging #556 (c56830e) into main (15da24f) will increase coverage by 0.01%.
The diff coverage is 69.44%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #556      +/-   ##
============================================
+ Coverage     71.35%   71.37%   +0.01%     
  Complexity     2683     2683              
============================================
  Files           883      886       +3     
  Lines         50561    50637      +76     
  Branches       1723     1723              
============================================
+ Hits          36079    36142      +63     
- Misses        13678    13691      +13     
  Partials        804      804              
Flag Coverage Δ
java 59.29% <ø> (ø)
rust 76.63% <69.44%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
rust/meta/src/hummock/compaction.rs 67.97% <0.00%> (-0.91%) ⬇️
rust/meta/src/hummock/mock_hummock_meta_client.rs 54.83% <0.00%> (-1.42%) ⬇️
rust/meta/src/rpc/service/mod.rs 0.00% <0.00%> (ø)
rust/storage/src/hummock/hummock_meta_client.rs 0.00% <0.00%> (ø)
rust/storage/src/hummock/shared_buffer.rs 87.02% <ø> (-0.16%) ⬇️
rust/meta/src/hummock/mod.rs 14.81% <14.81%> (ø)
rust/meta/src/rpc/service/hummock_service.rs 1.12% <16.66%> (-0.02%) ⬇️
rust/meta/src/hummock/hummock_manager.rs 68.94% <40.00%> (+0.34%) ⬆️
rust/meta/src/hummock/compactor_manager.rs 97.64% <97.64%> (ø)
rust/meta/src/hummock/hummock_manager_tests.rs 91.70% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 15da24f...c56830e. Read the comment docs.

@zwang28 zwang28 force-pushed the wangzheng/refactor_compaction branch from c15ff67 to 94793d9 Compare February 25, 2022 08:08
@zwang28 zwang28 marked this pull request as ready for review February 25, 2022 08:23
Copy link
Contributor

@soundOfDestiny soundOfDestiny left a comment

Choose a reason for hiding this comment

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

seems ok in first glance

const COMPACT_TASK_TIMEOUT: Duration = Duration::from_secs(60);

/// `CompactorManager` maintains compactors which can process compact task.
pub struct CompactorManager<E> {
Copy link
Member

Choose a reason for hiding this comment

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

There is a RwLock or Atomic for each field, which may cause non-atomic behaviors.

I think it's okay to simply create a struct CompactorManagerCore (or whatever) and protect it with a RwLock/Mutex<CompactorManagerCore>, which could make multi-threading easier, especially if more fields added in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

use crate::storage::MetaStore;

pub struct HummockServiceImpl<S>
where
S: MetaStore,
{
hummock_manager: Arc<HummockManager<S>>,
compaction_manager: Arc<CompactorManager<tonic::Status>>,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
compaction_manager: Arc<CompactorManager<tonic::Status>>,
compactor_manager: Arc<CompactorManager<tonic::Status>>,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. FIxed.

/// `CompactorManager` maintains compactors which can process compact task.
pub struct CompactorManager<E> {
/// Stores senders of stream to available compactors
compactors: RwLock<Vec<Sender<std::result::Result<CompactTasksResponse, E>>>>,
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to use generic (E) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried to not introduce tonic stuffs to CompactorManager.
But another NotificationManager actually uses tonic::Status already. So yes E may be removed to keep consistency.

Copy link
Member

Choose a reason for hiding this comment

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

recommend to avoid generics unless inevitable

Copy link
Contributor

Choose a reason for hiding this comment

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

Simply use RwError here, we can later convert it to tonic Status

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Add a wrapper struct RwReceiverStream to map Result<S, RwError> to Result<S, tonic::Status>.


type CompactTasksStream = ReceiverStream<Result<CompactTasksResponse, Status>>;

async fn compact_tasks(
Copy link
Member

Choose a reason for hiding this comment

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

get_compact_tasks ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would suggest to apply this renaming in next PR. Currently there is already a RPC named GetCompactionTasks, which is used by compactors to poll tasks. After we refactor the compactors in next PR, the legacy GetCompactionTasks can be removed.

}
}
Err(e) => {
error!("failed to try_assign_compact_task {}", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

(1) seems try_assign_compact_task will not return Err
(2) if try_assign_compact_task returns Err in the future, shall we call report_compact_task to report a compact failure here?

Copy link
Contributor Author

@zwang28 zwang28 Feb 28, 2022

Choose a reason for hiding this comment

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

You are right. try_assign_compact_task can simply return bool. And report_compact_task to cancel the task if false is returned.

Copy link
Contributor

@soundOfDestiny soundOfDestiny Feb 28, 2022

Choose a reason for hiding this comment

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

You are right. try_assign_compact_task can simply return bool. And report_compact_task to cancel the task if false is returned.

ok so we only need to remove this matching arm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


const COMPACT_TRIGGER_INTERVAL: Duration = Duration::from_secs(10);
/// Starts a worker to conditionally trigger compaction.
pub async fn start_compaction_loop<S, E>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all SSTable being compacted pinned? If not, should we pin them first?

Copy link
Contributor Author

@zwang28 zwang28 Feb 28, 2022

Choose a reason for hiding this comment

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

If a SST marked deletion by compation is being referenced by any pinned version, it won't be deleted at that time.
We don’t need to explictly pin when compaction, because the vacuum(WIP) knows when it's safe to delete a SST.

zwang28 and others added 2 commits February 28, 2022 22:39
Remove unnecessary Result wrapper in try_assign_compact_task.

Add CompactorManagerInner.
};
if !compactor_manager_ref
.try_assign_compact_task(compact_task.clone())
.await
Copy link
Contributor

Choose a reason for hiding this comment

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

latest change here seems that it has satisfied my need

# Conflicts:
#	rust/storage/src/hummock/hummock_meta_client.rs
#	rust/storage/src/hummock/mod.rs
@zwang28 zwang28 merged commit 7af70bc into main Mar 2, 2022
@zwang28 zwang28 deleted the wangzheng/refactor_compaction branch March 2, 2022 06:29
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.

5 participants