risingwave_meta/hummock/manager/
utils.rs1macro_rules! commit_multi_var {
19 ($meta_store:expr, $($val_txn:expr),*) => {
20 {
21 async {
22 use crate::model::{MetadataModelError, InMemValTransaction, ValTransaction};
23 use sea_orm::TransactionTrait;
24 let mut txn = $meta_store.conn.begin().await.map_err(MetadataModelError::from)?;
25 $(
26 $val_txn.apply_to_txn(&mut txn).await?;
27 )*
28 txn.commit().await.map_err(MetadataModelError::from)?;
29 $(
30 $val_txn.commit();
31 )*
32 Result::Ok(())
33 }.await
34 }
35 };
36}
37
38macro_rules! commit_multi_var_with_provided_txn {
39 ($txn:expr, $($val_txn:expr),*) => {
40 {
41 async {
42 use crate::model::{InMemValTransaction, ValTransaction};
43 use crate::model::MetadataModelError;
44 $(
45 $val_txn.apply_to_txn(&mut $txn).await?;
46 )*
47 $txn.commit().await.map_err(MetadataModelError::from)?;
48 $(
49 $val_txn.commit();
50 )*
51 Result::Ok(())
52 }.await
53 }
54 };
55}
56
57use risingwave_hummock_sdk::SstObjectIdRange;
58pub(crate) use {commit_multi_var, commit_multi_var_with_provided_txn};
59
60use crate::hummock::HummockManager;
61use crate::hummock::error::Result;
62use crate::hummock::sequence::next_sstable_object_id;
63
64impl HummockManager {
65 #[cfg(test)]
66 pub(super) async fn check_state_consistency(&self) {
67 use crate::hummock::manager::compaction::Compaction;
68 use crate::hummock::manager::context::ContextInfo;
69 use crate::hummock::manager::versioning::Versioning;
70 let mut compaction_guard = self.compaction.write().await;
71 let mut versioning_guard = self.versioning.write().await;
72 let mut context_info_guard = self.context_info.write().await;
73 let get_state = |compaction_guard: &mut Compaction,
76 versioning_guard: &mut Versioning,
77 context_info_guard: &mut ContextInfo| {
78 let compact_statuses_copy = compaction_guard.compaction_statuses.clone();
79 let compact_task_assignment_copy = compaction_guard.compact_task_assignment.clone();
80 let pinned_versions_copy = context_info_guard.pinned_versions.clone();
81 let hummock_version_deltas_copy = versioning_guard.hummock_version_deltas.clone();
82 let version_stats_copy = versioning_guard.version_stats.clone();
83 ((
84 compact_statuses_copy,
85 compact_task_assignment_copy,
86 pinned_versions_copy,
87 hummock_version_deltas_copy,
88 version_stats_copy,
89 ),)
90 };
91 let mem_state = get_state(
92 &mut compaction_guard,
93 &mut versioning_guard,
94 &mut context_info_guard,
95 );
96 self.load_meta_store_state_impl(
97 &mut compaction_guard,
98 &mut versioning_guard,
99 &mut context_info_guard,
100 )
101 .await
102 .expect("Failed to load state from meta store");
103 let loaded_state = get_state(
104 &mut compaction_guard,
105 &mut versioning_guard,
106 &mut context_info_guard,
107 );
108 assert_eq!(
109 mem_state, loaded_state,
110 "hummock in-mem state is inconsistent with meta store state",
111 );
112 }
113
114 pub async fn get_new_sst_ids(&self, number: u32) -> Result<SstObjectIdRange> {
115 let start_id = next_sstable_object_id(&self.env, number).await?;
116 Ok(SstObjectIdRange::new(start_id, start_id + number as u64))
117 }
118}