diff --git a/src/mito2/src/memtable/merge_tree/data.rs b/src/mito2/src/memtable/merge_tree/data.rs index cea4d9baccad..f414ca38f99a 100644 --- a/src/mito2/src/memtable/merge_tree/data.rs +++ b/src/mito2/src/memtable/merge_tree/data.rs @@ -678,6 +678,11 @@ impl DataParts { } } + pub(crate) fn with_frozen(mut self, frozen: Vec) -> Self { + self.frozen = frozen; + self + } + /// Writes a row into parts. pub fn write_row(&mut self, pk_index: PkIndex, kv: KeyValue) { self.active.write_row(pk_index, kv) diff --git a/src/mito2/src/memtable/merge_tree/partition.rs b/src/mito2/src/memtable/merge_tree/partition.rs index 3bb41b3e0cf9..dc817d134ded 100644 --- a/src/mito2/src/memtable/merge_tree/partition.rs +++ b/src/mito2/src/memtable/merge_tree/partition.rs @@ -26,7 +26,7 @@ use store_api::storage::ColumnId; use crate::error::Result; use crate::memtable::key_values::KeyValue; -use crate::memtable::merge_tree::data::{DataBuffer, DataParts, DATA_INIT_CAP}; +use crate::memtable::merge_tree::data::{DataParts, DATA_INIT_CAP}; use crate::memtable::merge_tree::metrics::WriteMetrics; use crate::memtable::merge_tree::shard::Shard; use crate::memtable::merge_tree::shard_builder::ShardBuilder; @@ -207,10 +207,7 @@ impl Inner { }; if inner.metadata.primary_key.is_empty() { - let data_parts = DataParts::new( - DataBuffer::with_capacity(inner.metadata.clone(), DATA_INIT_CAP), - Vec::new(), - ); + let data_parts = DataParts::new(inner.metadata.clone(), DATA_INIT_CAP); inner.shards.push(Shard::new(0, None, data_parts)); inner.active_shard_id = 1; } diff --git a/src/mito2/src/memtable/merge_tree/shard.rs b/src/mito2/src/memtable/merge_tree/shard.rs index 7299e160d508..86c5ea18f1a2 100644 --- a/src/mito2/src/memtable/merge_tree/shard.rs +++ b/src/mito2/src/memtable/merge_tree/shard.rs @@ -17,7 +17,7 @@ use store_api::metadata::RegionMetadataRef; use crate::memtable::key_values::KeyValue; -use crate::memtable::merge_tree::data::{DataBuffer, DataParts, DATA_INIT_CAP}; +use crate::memtable::merge_tree::data::{DataParts, DATA_INIT_CAP}; use crate::memtable::merge_tree::dict::KeyDictRef; use crate::memtable::merge_tree::{PkId, ShardId}; @@ -77,10 +77,7 @@ impl Shard { Shard { shard_id: self.shard_id, key_dict: self.key_dict.clone(), - data_parts: DataParts::new( - DataBuffer::with_capacity(metadata, DATA_INIT_CAP), - Vec::new(), - ), + data_parts: DataParts::new(metadata, DATA_INIT_CAP), } } } @@ -147,7 +144,7 @@ mod tests { } let dict = dict_builder.finish().unwrap(); - let data_parts = DataParts::new(DataBuffer::with_capacity(metadata, DATA_INIT_CAP), vec![]); + let data_parts = DataParts::new(metadata, DATA_INIT_CAP); Shard::new(shard_id, Some(Arc::new(dict)), data_parts) } diff --git a/src/mito2/src/memtable/merge_tree/shard_builder.rs b/src/mito2/src/memtable/merge_tree/shard_builder.rs index 9bf2c27ab5b3..f9a32a17a563 100644 --- a/src/mito2/src/memtable/merge_tree/shard_builder.rs +++ b/src/mito2/src/memtable/merge_tree/shard_builder.rs @@ -87,10 +87,7 @@ impl ShardBuilder { }; // build data parts. - let data_parts = DataParts::new( - DataBuffer::with_capacity(metadata, DATA_INIT_CAP), - vec![data_part], - ); + let data_parts = DataParts::new(metadata, DATA_INIT_CAP).with_frozen(vec![data_part]); let key_dict = key_dict.map(Arc::new); Ok(Some(Shard::new(shard_id, key_dict, data_parts))) @@ -168,7 +165,7 @@ mod tests { } let dict = dict_builder.finish().unwrap(); - let data_parts = DataParts::new(DataBuffer::with_capacity(metadata, DATA_INIT_CAP), vec![]); + let data_parts = DataParts::new(metadata, DATA_INIT_CAP); Shard::new(shard_id, Some(Arc::new(dict)), data_parts) }