-
Notifications
You must be signed in to change notification settings - Fork 2.1k
perf(cubestore): reduce metastore RPC fan-out during partitioning #11095
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
Merged
+557
−73
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fff3f9d
perf(cubestore): make disk-space single-flight lock wait configurable
waralexrom 7b6c601
perf(cubestore): load the table once per partitioning job, not per chunk
waralexrom e41fe00
perf(cubestore): dedup the per-node disk-space check across a partiti…
waralexrom 5fd8f1a
perf(cubestore): batch active-partition fetch across indexes behind a…
waralexrom 358441b
perf(cubestore): batch child-partition creation in splits behind the …
waralexrom e4f0fac
perf(cubestore): batch child-chunk creation in range repartition behi…
waralexrom a024cfd
fix(cubestore): make batched active-partition fetch RPC-serializable
waralexrom 7cab940
perf(cubestore): skip disk-space dedup work when the limit is disabled
waralexrom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ use crate::metastore::wal::{WALIndexKey, WALRocksIndex}; | |
|
|
||
| use crate::table::{Row, TableValue}; | ||
|
|
||
| use crate::util::lock::acquire_lock; | ||
| use crate::util::lock::{acquire_lock, acquire_lock_duration}; | ||
| use crate::util::WorkerLoop; | ||
| use crate::{meta_store_table_impl, CubeError}; | ||
| use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; | ||
|
|
@@ -884,6 +884,10 @@ pub trait MetaStore: DIService + Send + Sync { | |
|
|
||
| fn partition_table(&self) -> PartitionMetaStoreTable; | ||
| async fn create_partition(&self, partition: Partition) -> Result<IdRow<Partition>, CubeError>; | ||
| async fn create_partitions( | ||
| &self, | ||
| partitions: Vec<Partition>, | ||
| ) -> Result<Vec<IdRow<Partition>>, CubeError>; | ||
| async fn get_partition(&self, partition_id: u64) -> Result<IdRow<Partition>, CubeError>; | ||
| async fn get_partition_out_of_queue( | ||
| &self, | ||
|
|
@@ -973,6 +977,13 @@ pub trait MetaStore: DIService + Send + Sync { | |
| &self, | ||
| index_id: u64, | ||
| ) -> Result<Vec<IdRow<Partition>>, CubeError>; | ||
| /// Active partitions for each index id, positionally aligned with `index_ids` | ||
| /// (result[i] corresponds to index_ids[i]). Returns a Vec rather than a map because the | ||
| /// metastore RPC serializes with flexbuffers, which rejects non-string map keys. | ||
| async fn get_active_partitions_for_indexes( | ||
| &self, | ||
| index_ids: Vec<u64>, | ||
| ) -> Result<Vec<Vec<IdRow<Partition>>>, CubeError>; | ||
| async fn get_index(&self, index_id: u64) -> Result<IdRow<Index>, CubeError>; | ||
|
|
||
| async fn get_index_with_active_partitions_out_of_queue( | ||
|
|
@@ -2760,6 +2771,21 @@ impl MetaStore for RocksMetaStore { | |
| .await | ||
| } | ||
|
|
||
| async fn create_partitions( | ||
| &self, | ||
| partitions: Vec<Partition>, | ||
| ) -> Result<Vec<IdRow<Partition>>, CubeError> { | ||
| self.write_operation("create_partitions", move |db_ref, batch_pipe| { | ||
| let table = PartitionRocksTable::new(db_ref.clone()); | ||
| let mut result = Vec::with_capacity(partitions.len()); | ||
| for partition in partitions { | ||
| result.push(table.insert(partition, batch_pipe)?); | ||
| } | ||
| Ok(result) | ||
| }) | ||
| .await | ||
| } | ||
|
Comment on lines
+2774
to
+2787
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding |
||
|
|
||
| #[tracing::instrument(level = "trace", skip(self))] | ||
| async fn get_partition(&self, partition_id: u64) -> Result<IdRow<Partition>, CubeError> { | ||
| self.read_operation("get_partition", move |db_ref| { | ||
|
|
@@ -2829,21 +2855,25 @@ impl MetaStore for RocksMetaStore { | |
| // Single-flight: serialize the scan so a burst of concurrent callers | ||
| // (e.g. many partition writes during an import/repartition) share one | ||
| // computation instead of each materializing a full metastore scan. | ||
| let _compute_guard = | ||
| match acquire_lock("disk space compute", self.disk_space_compute_lock.lock()).await | ||
| { | ||
| Ok(guard) => guard, | ||
| Err(e) => { | ||
| log::error!( | ||
| let _compute_guard = match acquire_lock_duration( | ||
| "disk space compute", | ||
| self.disk_space_compute_lock.lock(), | ||
| Duration::from_millis(self.store.config.disk_space_compute_lock_timeout_ms()), | ||
| ) | ||
| .await | ||
| { | ||
| Ok(guard) => guard, | ||
| Err(e) => { | ||
| log::error!( | ||
| "Timed out waiting for the disk space scan lock: {}. The single-flight \ | ||
| scan is stuck; reporting 0 used disk space so the disk-space check \ | ||
| passes. THE DISK-SPACE LIMIT IS NOT BEING ENFORCED until the scan \ | ||
| recovers.", | ||
| e | ||
| ); | ||
| return Ok(0); | ||
| } | ||
| }; | ||
| return Ok(0); | ||
| } | ||
| }; | ||
| if let Some(sizes) = self.disk_space_cached().await? { | ||
| sizes | ||
| } else { | ||
|
|
@@ -3598,6 +3628,29 @@ impl MetaStore for RocksMetaStore { | |
| .await | ||
| } | ||
|
|
||
| async fn get_active_partitions_for_indexes( | ||
| &self, | ||
| index_ids: Vec<u64>, | ||
| ) -> Result<Vec<Vec<IdRow<Partition>>>, CubeError> { | ||
| self.read_operation_out_of_queue("get_active_partitions_for_indexes", move |db_ref| { | ||
| let rocks_partition = PartitionRocksTable::new(db_ref); | ||
| let mut result = Vec::with_capacity(index_ids.len()); | ||
| for index_id in index_ids { | ||
| let partitions = rocks_partition | ||
| .get_rows_by_index( | ||
| &PartitionIndexKey::ByIndexId(index_id), | ||
| &PartitionRocksIndex::IndexId, | ||
| )? | ||
| .into_iter() | ||
| .filter(|r| r.get_row().active) | ||
| .collect::<Vec<_>>(); | ||
| result.push(partitions); | ||
| } | ||
| Ok(result) | ||
| }) | ||
| .await | ||
| } | ||
|
|
||
| #[tracing::instrument(level = "trace", skip(self))] | ||
| async fn get_index(&self, index_id: u64) -> Result<IdRow<Index>, CubeError> { | ||
| self.read_operation("get_index", move |db_ref| { | ||
|
|
@@ -5801,6 +5854,151 @@ mod tests { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn get_active_partitions_for_indexes_test() -> Result<(), CubeError> { | ||
| init_test_logger().await; | ||
|
|
||
| let (_remote_fs, meta_store) = | ||
| RocksMetaStore::prepare_test_metastore("get_active_partitions_for_indexes"); | ||
|
|
||
| meta_store.create_schema("foo".to_string(), false).await?; | ||
| let columns = vec![ | ||
| Column::new("col1".to_string(), ColumnType::Int, 0), | ||
| Column::new("col2".to_string(), ColumnType::String, 1), | ||
| ]; | ||
| // Two tables → two default indexes, each with its own initial active partition. | ||
| let table1 = meta_store | ||
| .create_table( | ||
| "foo".to_string(), | ||
| "t1".to_string(), | ||
| columns.clone(), | ||
| None, | ||
| None, | ||
| vec![], | ||
| true, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| false, | ||
| None, | ||
| ) | ||
| .await?; | ||
| let table2 = meta_store | ||
| .create_table( | ||
| "foo".to_string(), | ||
| "t2".to_string(), | ||
| columns.clone(), | ||
| None, | ||
| None, | ||
| vec![], | ||
| true, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| false, | ||
| None, | ||
| ) | ||
| .await?; | ||
|
|
||
| let index1 = meta_store.get_default_index(table1.get_id()).await?; | ||
| let index2 = meta_store.get_default_index(table2.get_id()).await?; | ||
|
|
||
| let single1 = meta_store | ||
| .get_active_partitions_by_index_id(index1.get_id()) | ||
| .await?; | ||
| let single2 = meta_store | ||
| .get_active_partitions_by_index_id(index2.get_id()) | ||
| .await?; | ||
|
|
||
| // Batch result is positionally aligned with the requested ids; it must match the | ||
| // per-index calls and return an empty vec (not an error) for the unknown index. | ||
| let unknown_index_id = index2.get_id() + 1000; | ||
| let batch = meta_store | ||
| .get_active_partitions_for_indexes(vec![ | ||
| index1.get_id(), | ||
| index2.get_id(), | ||
| unknown_index_id, | ||
| ]) | ||
| .await?; | ||
|
|
||
| let ids = |ps: &Vec<IdRow<Partition>>| ps.iter().map(|p| p.get_id()).collect::<Vec<_>>(); | ||
| assert_eq!(batch.len(), 3); | ||
| assert_eq!(ids(&batch[0]), ids(&single1)); | ||
| assert_eq!(ids(&batch[1]), ids(&single2)); | ||
| assert!(batch[2].is_empty()); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn create_partitions_test() -> Result<(), CubeError> { | ||
| init_test_logger().await; | ||
|
|
||
| let (_remote_fs, meta_store) = RocksMetaStore::prepare_test_metastore("create_partitions"); | ||
|
|
||
| meta_store.create_schema("foo".to_string(), false).await?; | ||
| let columns = vec![Column::new("col1".to_string(), ColumnType::Int, 0)]; | ||
| let table = meta_store | ||
| .create_table( | ||
| "foo".to_string(), | ||
| "t1".to_string(), | ||
| columns, | ||
| None, | ||
| None, | ||
| vec![], | ||
| true, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| None, | ||
| false, | ||
| None, | ||
| ) | ||
| .await?; | ||
| let index = meta_store.get_default_index(table.get_id()).await?; | ||
| let parent = meta_store | ||
| .get_active_partitions_by_index_id(index.get_id()) | ||
| .await?[0] | ||
| .clone(); | ||
|
|
||
| let created = meta_store | ||
| .create_partitions(vec![ | ||
| Partition::new_child(&parent, None), | ||
| Partition::new_child(&parent, None), | ||
| ]) | ||
| .await?; | ||
|
|
||
| assert_eq!(created.len(), 2); | ||
| assert_ne!(created[0].get_id(), created[1].get_id()); | ||
| // Both rows must be persisted and point at the same parent partition. | ||
| for child in &created { | ||
| let fetched = meta_store.get_partition(child.get_id()).await?; | ||
| assert_eq!( | ||
| fetched.get_row().parent_partition_id(), | ||
| &Some(parent.get_id()) | ||
| ); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn table_test() -> Result<(), CubeError> { | ||
| init_test_logger().await; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.