From d87dffa17712a7450e7872abd48a722c71403b78 Mon Sep 17 00:00:00 2001 From: Linwei Zhang Date: Thu, 15 Feb 2024 23:05:36 +0800 Subject: [PATCH] Improve code --- bustubx/src/execution/physical_plan/insert.rs | 3 +- bustubx/src/storage/codec/table_page.rs | 11 +- bustubx/src/storage/index.rs | 62 +++---- bustubx/src/storage/table_heap.rs | 138 +++++++-------- bustubx/src/storage/table_page.rs | 160 ++++++++++-------- 5 files changed, 189 insertions(+), 185 deletions(-) diff --git a/bustubx/src/execution/physical_plan/insert.rs b/bustubx/src/execution/physical_plan/insert.rs index f4975d0..e4cedd2 100644 --- a/bustubx/src/execution/physical_plan/insert.rs +++ b/bustubx/src/execution/physical_plan/insert.rs @@ -86,8 +86,7 @@ impl VolcanoExecutor for PhysicalInsert { delete_txn_id: 0, is_deleted: false, }; - // TODO check result - table_heap.insert_tuple(&tuple_meta, &tuple); + table_heap.insert_tuple(&tuple_meta, &tuple)?; self.insert_rows .fetch_add(1, std::sync::atomic::Ordering::SeqCst); } diff --git a/bustubx/src/storage/codec/table_page.rs b/bustubx/src/storage/codec/table_page.rs index 15a807c..06814b1 100644 --- a/bustubx/src/storage/codec/table_page.rs +++ b/bustubx/src/storage/codec/table_page.rs @@ -1,6 +1,7 @@ use crate::buffer::BUSTUBX_PAGE_SIZE; use crate::catalog::SchemaRef; use crate::common::rid::Rid; +use crate::common::util::page_bytes_to_array; use crate::storage::codec::{CommonCodec, DecodedData}; use crate::storage::table_page::{TablePageHeader, TupleInfo}; use crate::storage::{TablePage, TupleMeta}; @@ -24,14 +25,12 @@ impl TablePageCodec { bytes.len() ))); } - let (header, offset) = TablePageHeaderCodec::decode(bytes)?; - let mut data = [0u8; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&bytes[0..BUSTUBX_PAGE_SIZE]); + let (header, _) = TablePageHeaderCodec::decode(bytes)?; Ok(( TablePage { schema, header, - data, + data: page_bytes_to_array(&bytes[0..BUSTUBX_PAGE_SIZE]), }, BUSTUBX_PAGE_SIZE, )) @@ -175,8 +174,8 @@ mod tests { }; let mut table_page = TablePage::new(schema.clone(), INVALID_PAGE_ID); - table_page.insert_tuple(&tuple1_meta, &tuple1); - table_page.insert_tuple(&tuple2_meta, &tuple2); + table_page.insert_tuple(&tuple1_meta, &tuple1).unwrap(); + table_page.insert_tuple(&tuple2_meta, &tuple2).unwrap(); let (new_page, _) = TablePageCodec::decode(&TablePageCodec::encode(&table_page), schema.clone()).unwrap(); diff --git a/bustubx/src/storage/index.rs b/bustubx/src/storage/index.rs index 79808c9..0ec5d48 100644 --- a/bustubx/src/storage/index.rs +++ b/bustubx/src/storage/index.rs @@ -115,10 +115,10 @@ impl BPlusTreeIndex { // 向右分裂出一个新page let internalkv = self.split(&mut curr_page); - let mut data = [0; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&BPlusTreePageCodec::encode(&curr_page)); - - self.buffer_pool_manager.write_page(curr_page_id, data); + self.buffer_pool_manager.write_page( + curr_page_id, + page_bytes_to_array(&BPlusTreePageCodec::encode(&curr_page)), + ); self.buffer_pool_manager .unpin_page(curr_page_id, true) .unwrap(); @@ -177,10 +177,10 @@ impl BPlusTreeIndex { } } - let mut data = [0; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&BPlusTreePageCodec::encode(&curr_page)); - - self.buffer_pool_manager.write_page(curr_page_id, data); + self.buffer_pool_manager.write_page( + curr_page_id, + page_bytes_to_array(&BPlusTreePageCodec::encode(&curr_page)), + ); self.buffer_pool_manager .unpin_page(curr_page_id, true) .unwrap(); @@ -279,11 +279,12 @@ impl BPlusTreeIndex { } }; // 更新兄弟节点 - let mut data = [0; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&BPlusTreePageCodec::encode(&left_sibling_tree_page)); - - self.buffer_pool_manager - .write_page(left_sibling_page_id, data); + self.buffer_pool_manager.write_page( + left_sibling_page_id, + page_bytes_to_array(&BPlusTreePageCodec::encode( + &left_sibling_tree_page, + )), + ); self.buffer_pool_manager .unpin_page(left_sibling_page_id, true) .unwrap(); @@ -364,11 +365,12 @@ impl BPlusTreeIndex { } }; // 更新兄弟节点 - let mut data = [0; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&BPlusTreePageCodec::encode(&right_sibling_tree_page)); - - self.buffer_pool_manager - .write_page(right_sibling_page_id, data); + self.buffer_pool_manager.write_page( + right_sibling_page_id, + page_bytes_to_array(&BPlusTreePageCodec::encode( + &right_sibling_tree_page, + )), + ); self.buffer_pool_manager .unpin_page(right_sibling_page_id, true) .unwrap(); @@ -443,11 +445,11 @@ impl BPlusTreeIndex { } } }; - let mut data = [0; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&BPlusTreePageCodec::encode(&left_sibling_tree_page)); - self.buffer_pool_manager - .write_page(left_sibling_page_id, data); + self.buffer_pool_manager.write_page( + left_sibling_page_id, + page_bytes_to_array(&BPlusTreePageCodec::encode(&left_sibling_tree_page)), + ); // 删除当前页 let deleted_page_id = curr_page_id; @@ -539,10 +541,10 @@ impl BPlusTreeIndex { } }; - let mut data = [0; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&BPlusTreePageCodec::encode(&curr_page)); - - self.buffer_pool_manager.write_page(curr_page_id, data); + self.buffer_pool_manager.write_page( + curr_page_id, + page_bytes_to_array(&BPlusTreePageCodec::encode(&curr_page)), + ); // 删除右兄弟页 let deleted_page_id = right_sibling_page_id; @@ -591,10 +593,10 @@ impl BPlusTreeIndex { } } - let mut data = [0; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&BPlusTreePageCodec::encode(&curr_page)); - - self.buffer_pool_manager.write_page(curr_page_id, data); + self.buffer_pool_manager.write_page( + curr_page_id, + page_bytes_to_array(&BPlusTreePageCodec::encode(&curr_page)), + ); self.buffer_pool_manager .unpin_page(curr_page_id, true) .unwrap(); diff --git a/bustubx/src/storage/table_heap.rs b/bustubx/src/storage/table_heap.rs index f6e00fd..8cfccae 100644 --- a/bustubx/src/storage/table_heap.rs +++ b/bustubx/src/storage/table_heap.rs @@ -50,18 +50,15 @@ impl TableHeap { /// /// Returns: /// An `Option` containing the `Rid` of the inserted tuple if successful, otherwise `None`. - pub fn insert_tuple(&mut self, meta: &TupleMeta, tuple: &Tuple) -> Option { + pub fn insert_tuple(&mut self, meta: &TupleMeta, tuple: &Tuple) -> BustubxResult { let mut last_page_id = self.last_page_id; - let last_page = self - .buffer_pool_manager - .fetch_page(self.last_page_id) - .expect("Can not fetch last page"); + let last_page = self.buffer_pool_manager.fetch_page(self.last_page_id)?; // Loop until a suitable page is found for inserting the tuple let (mut last_table_page, _) = - TablePageCodec::decode(&last_page.read().unwrap().data, self.schema.clone()).unwrap(); + TablePageCodec::decode(&last_page.read().unwrap().data, self.schema.clone())?; loop { - if last_table_page.get_next_tuple_offset(meta, tuple).is_some() { + if last_table_page.next_tuple_offset(tuple).is_ok() { break; } @@ -73,10 +70,7 @@ impl TableHeap { ); // Allocate a new page if no more table pages are available. - let next_page = self - .buffer_pool_manager - .new_page() - .expect("cannot allocate page"); + let next_page = self.buffer_pool_manager.new_page()?; let next_page_id = next_page.read().unwrap().page_id; let next_table_page = TablePage::new(self.schema.clone(), INVALID_PAGE_ID); next_page.write().unwrap().data = @@ -85,13 +79,11 @@ impl TableHeap { // Update and release the previous page last_table_page.header.next_page_id = next_page_id; - let mut data = [0u8; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&TablePageCodec::encode(&last_table_page)); - - self.buffer_pool_manager.write_page(last_page_id, data); - self.buffer_pool_manager - .unpin_page(last_page_id, true) - .unwrap(); + self.buffer_pool_manager.write_page( + last_page_id, + page_bytes_to_array(&TablePageCodec::encode(&last_table_page)), + ); + self.buffer_pool_manager.unpin_page(last_page_id, true)?; // Update last_page_id. last_page_id = next_page_id; @@ -100,61 +92,45 @@ impl TableHeap { } // Insert the tuple into the chosen page - let slot_id = last_table_page.insert_tuple(meta, tuple); + let slot_id = last_table_page.insert_tuple(meta, tuple)?; - let mut data = [0u8; BUSTUBX_PAGE_SIZE]; - data.copy_from_slice(&TablePageCodec::encode(&last_table_page)); - - self.buffer_pool_manager.write_page(last_page_id, data); - self.buffer_pool_manager - .unpin_page(last_page_id, true) - .unwrap(); + self.buffer_pool_manager.write_page( + last_page_id, + page_bytes_to_array(&TablePageCodec::encode(&last_table_page)), + ); + self.buffer_pool_manager.unpin_page(last_page_id, true)?; // Map the slot_id to a Rid and return - slot_id.map(|slot_id| Rid::new(last_page_id, slot_id as u32)) + Ok(Rid::new(last_page_id, slot_id as u32)) } - pub fn update_tuple_meta(&mut self, meta: &TupleMeta, rid: Rid) { - let page = self - .buffer_pool_manager - .fetch_page(rid.page_id) - .expect("Can not fetch page"); + pub fn update_tuple_meta(&mut self, meta: &TupleMeta, rid: Rid) -> BustubxResult<()> { + let page = self.buffer_pool_manager.fetch_page(rid.page_id)?; let (mut table_page, _) = - TablePageCodec::decode(&page.read().unwrap().data, self.schema.clone()).unwrap(); - table_page.update_tuple_meta(meta, &rid); + TablePageCodec::decode(&page.read().unwrap().data, self.schema.clone())?; + table_page.update_tuple_meta(meta, rid.slot_num as u16)?; page.write().unwrap().data = page_bytes_to_array(&TablePageCodec::encode(&table_page)); - self.buffer_pool_manager - .unpin_page(rid.page_id, true) - .unwrap(); + self.buffer_pool_manager.unpin_page(rid.page_id, true)?; + Ok(()) } - pub fn get_tuple(&mut self, rid: Rid) -> (TupleMeta, Tuple) { - let page = self - .buffer_pool_manager - .fetch_page(rid.page_id) - .expect("Can not fetch page"); + pub fn tuple(&mut self, rid: Rid) -> BustubxResult<(TupleMeta, Tuple)> { + let page = self.buffer_pool_manager.fetch_page(rid.page_id)?; let (mut table_page, _) = - TablePageCodec::decode(&page.read().unwrap().data, self.schema.clone()).unwrap(); - let result = table_page.get_tuple(&rid); - self.buffer_pool_manager - .unpin_page(rid.page_id, false) - .unwrap(); - result + TablePageCodec::decode(&page.read().unwrap().data, self.schema.clone())?; + let result = table_page.tuple(rid.slot_num as u16)?; + self.buffer_pool_manager.unpin_page(rid.page_id, false)?; + Ok(result) } - pub fn get_tuple_meta(&mut self, rid: Rid) -> TupleMeta { - let page = self - .buffer_pool_manager - .fetch_page(rid.page_id) - .expect("Can not fetch page"); + pub fn tuple_meta(&mut self, rid: Rid) -> BustubxResult { + let page = self.buffer_pool_manager.fetch_page(rid.page_id)?; let (mut table_page, _) = - TablePageCodec::decode(&page.read().unwrap().data, self.schema.clone()).unwrap(); - let result = table_page.get_tuple_meta(&rid); - self.buffer_pool_manager - .unpin_page(rid.page_id, false) - .unwrap(); - result + TablePageCodec::decode(&page.read().unwrap().data, self.schema.clone())?; + let result = table_page.tuple_meta(rid.slot_num as u16)?; + self.buffer_pool_manager.unpin_page(rid.page_id, false)?; + Ok(result) } pub fn get_first_rid(&mut self) -> Option { @@ -233,7 +209,7 @@ impl TableIterator { if self.stop_at.is_some() && rid == self.stop_at.unwrap() { return None; } - let result = table_heap.get_tuple(rid); + let result = table_heap.tuple(rid).unwrap(); self.rid = table_heap.get_next_rid(rid); Some(result) } @@ -281,24 +257,30 @@ mod tests { is_deleted: false, }; - table_heap.insert_tuple( - &meta, - &Tuple::new(schema.clone(), vec![1i8.into(), 1i16.into()]), - ); + table_heap + .insert_tuple( + &meta, + &Tuple::new(schema.clone(), vec![1i8.into(), 1i16.into()]), + ) + .unwrap(); assert_eq!(table_heap.first_page_id, 0); assert_eq!(table_heap.last_page_id, 0); - table_heap.insert_tuple( - &meta, - &Tuple::new(schema.clone(), vec![2i8.into(), 2i16.into()]), - ); + table_heap + .insert_tuple( + &meta, + &Tuple::new(schema.clone(), vec![2i8.into(), 2i16.into()]), + ) + .unwrap(); assert_eq!(table_heap.first_page_id, 0); assert_eq!(table_heap.last_page_id, 0); - table_heap.insert_tuple( - &meta, - &Tuple::new(schema.clone(), vec![3i8.into(), 3i16.into()]), - ); + table_heap + .insert_tuple( + &meta, + &Tuple::new(schema.clone(), vec![3i8.into(), 3i16.into()]), + ) + .unwrap(); assert_eq!(table_heap.first_page_id, 0); assert_eq!(table_heap.last_page_id, 0); } @@ -340,13 +322,13 @@ mod tests { ) .unwrap(); - let mut meta = table_heap.get_tuple_meta(rid2); + let mut meta = table_heap.tuple_meta(rid2).unwrap(); meta.insert_txn_id = 1; meta.delete_txn_id = 2; meta.is_deleted = true; - table_heap.update_tuple_meta(&meta, rid2); + table_heap.update_tuple_meta(&meta, rid2).unwrap(); - let meta = table_heap.get_tuple_meta(rid2); + let meta = table_heap.tuple_meta(rid2).unwrap(); assert_eq!(meta.insert_txn_id, 1); assert_eq!(meta.delete_txn_id, 2); assert_eq!(meta.is_deleted, true); @@ -399,15 +381,15 @@ mod tests { ) .unwrap(); - let (meta, tuple) = table_heap.get_tuple(rid1); + let (meta, tuple) = table_heap.tuple(rid1).unwrap(); assert_eq!(meta, meta1); assert_eq!(tuple.data, vec![1i8.into(), 1i16.into()]); - let (meta, tuple) = table_heap.get_tuple(rid2); + let (meta, tuple) = table_heap.tuple(rid2).unwrap(); assert_eq!(meta, meta2); assert_eq!(tuple.data, vec![2i8.into(), 2i16.into()]); - let (meta, tuple) = table_heap.get_tuple(rid3); + let (meta, tuple) = table_heap.tuple(rid3).unwrap(); assert_eq!(meta, meta3); assert_eq!(tuple.data, vec![3i8.into(), 3i16.into()]); } diff --git a/bustubx/src/storage/table_page.rs b/bustubx/src/storage/table_page.rs index 06b68f5..652aa09 100644 --- a/bustubx/src/storage/table_page.rs +++ b/bustubx/src/storage/table_page.rs @@ -2,6 +2,7 @@ use crate::buffer::{PageId, BUSTUBX_PAGE_SIZE}; use crate::catalog::SchemaRef; use crate::common::rid::Rid; use crate::storage::codec::{TablePageHeaderCodec, TablePageHeaderTupleInfoCodec, TupleCodec}; +use crate::{BustubxError, BustubxResult}; use super::tuple::{Tuple, TupleMeta}; @@ -57,44 +58,48 @@ impl TablePage { } // Get the offset for the next tuple insertion. - pub fn get_next_tuple_offset(&self, meta: &TupleMeta, tuple: &Tuple) -> Option { + pub fn next_tuple_offset(&self, tuple: &Tuple) -> BustubxResult { // Get the ending offset of the current slot. If there are inserted tuples, // get the offset of the previous inserted tuple; otherwise, set it to the size of the page. let slot_end_offset = if self.header.num_tuples > 0 { - self.header.tuple_infos[self.header.num_tuples as usize - 1].offset + self.header.tuple_infos[self.header.num_tuples as usize - 1].offset as usize } else { - BUSTUBX_PAGE_SIZE as u16 + BUSTUBX_PAGE_SIZE }; // Check if the current slot has enough space for the new tuple. Return None if not. - if slot_end_offset < TupleCodec::encode(tuple).len() as u16 { - return None; + if slot_end_offset < TupleCodec::encode(tuple).len() { + return Err(BustubxError::Storage( + "No enough space to store tuple".to_string(), + )); } // Calculate the insertion offset for the new tuple by subtracting its data length // from the ending offset of the current slot. - let tuple_offset = slot_end_offset - TupleCodec::encode(tuple).len() as u16; + let tuple_offset = slot_end_offset - TupleCodec::encode(tuple).len(); // Calculate the minimum valid tuple insertion offset, including the table page header size, // the total size of each tuple info (existing tuple infos and newly added tuple info). let min_tuple_offset = TablePageHeaderCodec::encode(&self.header).len() + TablePageHeaderTupleInfoCodec::encode(&EMPTY_TUPLE_INFO).len(); - if (tuple_offset as usize) < min_tuple_offset { - return None; + if tuple_offset < min_tuple_offset { + return Err(BustubxError::Storage( + "No enough space to store tuple".to_string(), + )); } // Return the calculated insertion offset for the new tuple. - return Some(tuple_offset); + return Ok(tuple_offset); } - pub fn insert_tuple(&mut self, meta: &TupleMeta, tuple: &Tuple) -> Option { + pub fn insert_tuple(&mut self, meta: &TupleMeta, tuple: &Tuple) -> BustubxResult { // Get the offset for the next tuple insertion. - let tuple_offset = self.get_next_tuple_offset(meta, tuple)?; + let tuple_offset = self.next_tuple_offset(tuple)?; let tuple_id = self.header.num_tuples; // Store tuple information including offset, length, and metadata. self.header.tuple_infos.push(TupleInfo { - offset: tuple_offset, + offset: tuple_offset as u16, size: TupleCodec::encode(tuple).len() as u16, meta: meta.clone(), }); @@ -108,49 +113,54 @@ impl TablePage { } // Copy the tuple's data into the appropriate position within the page's data buffer. - self.data[tuple_offset as usize - ..(tuple_offset + TupleCodec::encode(tuple).len() as u16) as usize] + self.data[tuple_offset..tuple_offset + TupleCodec::encode(tuple).len()] .copy_from_slice(&TupleCodec::encode(tuple)); - return Some(tuple_id); + return Ok(tuple_id); } - pub fn update_tuple_meta(&mut self, meta: &TupleMeta, rid: &Rid) { - let tuple_id = rid.slot_num; - if tuple_id >= self.header.num_tuples as u32 { - panic!("tuple_id {} out of range", tuple_id); + pub fn update_tuple_meta(&mut self, meta: &TupleMeta, slot_num: u16) -> BustubxResult<()> { + if slot_num >= self.header.num_tuples { + return Err(BustubxError::Storage(format!( + "tuple_id {} out of range", + slot_num + ))); } - if meta.is_deleted && !self.header.tuple_infos[tuple_id as usize].meta.is_deleted { + if meta.is_deleted && !self.header.tuple_infos[slot_num as usize].meta.is_deleted { self.header.num_deleted_tuples += 1; } - self.header.tuple_infos[tuple_id as usize].meta = meta.clone(); + self.header.tuple_infos[slot_num as usize].meta = meta.clone(); + Ok(()) } - pub fn get_tuple(&self, rid: &Rid) -> (TupleMeta, Tuple) { - let tuple_id = rid.slot_num; - if tuple_id >= self.header.num_tuples as u32 { - panic!("tuple_id {} out of range", tuple_id); + pub fn tuple(&self, slot_num: u16) -> BustubxResult<(TupleMeta, Tuple)> { + if slot_num >= self.header.num_tuples { + return Err(BustubxError::Storage(format!( + "tuple_id {} out of range", + slot_num + ))); } - let offset = self.header.tuple_infos[tuple_id as usize].offset; - let size = self.header.tuple_infos[tuple_id as usize].size; - let meta = self.header.tuple_infos[tuple_id as usize].meta; + let offset = self.header.tuple_infos[slot_num as usize].offset; + let size = self.header.tuple_infos[slot_num as usize].size; + let meta = self.header.tuple_infos[slot_num as usize].meta; let (tuple, _) = TupleCodec::decode( &self.data[offset as usize..(offset + size) as usize], self.schema.clone(), - ) - .unwrap(); + )?; - return (meta, tuple); + Ok((meta, tuple)) } - pub fn get_tuple_meta(&self, rid: &Rid) -> TupleMeta { - let tuple_id = rid.slot_num; - if tuple_id >= self.header.num_tuples as u32 { - panic!("tuple_id {} out of range", tuple_id); + pub fn tuple_meta(&self, slot_num: u16) -> BustubxResult { + if slot_num >= self.header.num_tuples { + return Err(BustubxError::Storage(format!( + "tuple_id {} out of range", + slot_num + ))); } - return self.header.tuple_infos[tuple_id as usize].meta.clone(); + return Ok(self.header.tuple_infos[slot_num as usize].meta.clone()); } pub fn get_next_rid(&self, rid: &Rid) -> Option { @@ -197,28 +207,34 @@ mod tests { delete_txn_id: 0, is_deleted: false, }; - let tuple_id = table_page.insert_tuple( - &meta, - &Tuple::new(schema.clone(), vec![1i8.into(), 1i16.into()]), - ); - assert_eq!(tuple_id, Some(0)); - let tuple_id = table_page.insert_tuple( - &meta, - &Tuple::new(schema.clone(), vec![2i8.into(), 2i16.into()]), - ); - assert_eq!(tuple_id, Some(1)); - let tuple_id = table_page.insert_tuple( - &meta, - &Tuple::new(schema.clone(), vec![3i8.into(), 3i16.into()]), - ); - assert_eq!(tuple_id, Some(2)); + let tuple_id = table_page + .insert_tuple( + &meta, + &Tuple::new(schema.clone(), vec![1i8.into(), 1i16.into()]), + ) + .unwrap(); + assert_eq!(tuple_id, 0); + let tuple_id = table_page + .insert_tuple( + &meta, + &Tuple::new(schema.clone(), vec![2i8.into(), 2i16.into()]), + ) + .unwrap(); + assert_eq!(tuple_id, 1); + let tuple_id = table_page + .insert_tuple( + &meta, + &Tuple::new(schema.clone(), vec![3i8.into(), 3i16.into()]), + ) + .unwrap(); + assert_eq!(tuple_id, 2); - let (tuple_meta, tuple) = table_page.get_tuple(&super::Rid::new(0, 0)); + let (tuple_meta, tuple) = table_page.tuple(0).unwrap(); assert_eq!(tuple_meta, meta); assert_eq!(tuple.data, vec![1i8.into(), 1i16.into()]); - let (tuple_meta, tuple) = table_page.get_tuple(&super::Rid::new(0, 1)); + let (tuple_meta, tuple) = table_page.tuple(1).unwrap(); assert_eq!(tuple.data, vec![2i8.into(), 2i16.into()]); - let (tuple_meta, tuple) = table_page.get_tuple(&super::Rid::new(0, 2)); + let (tuple_meta, tuple) = table_page.tuple(2).unwrap(); assert_eq!(tuple.data, vec![3i8.into(), 3i16.into()]); } @@ -234,26 +250,32 @@ mod tests { delete_txn_id: 0, is_deleted: false, }; - let tuple_id = table_page.insert_tuple( - &meta, - &Tuple::new(schema.clone(), vec![1i8.into(), 1i16.into()]), - ); - let tuple_id = table_page.insert_tuple( - &meta, - &Tuple::new(schema.clone(), vec![2i8.into(), 2i16.into()]), - ); - let tuple_id = table_page.insert_tuple( - &meta, - &Tuple::new(schema.clone(), vec![3i8.into(), 3i16.into()]), - ); + let tuple_id = table_page + .insert_tuple( + &meta, + &Tuple::new(schema.clone(), vec![1i8.into(), 1i16.into()]), + ) + .unwrap(); + let tuple_id = table_page + .insert_tuple( + &meta, + &Tuple::new(schema.clone(), vec![2i8.into(), 2i16.into()]), + ) + .unwrap(); + let tuple_id = table_page + .insert_tuple( + &meta, + &Tuple::new(schema.clone(), vec![3i8.into(), 3i16.into()]), + ) + .unwrap(); - let mut tuple_meta = table_page.get_tuple_meta(&super::Rid::new(0, 0)); + let mut tuple_meta = table_page.tuple_meta(0).unwrap(); tuple_meta.is_deleted = true; tuple_meta.delete_txn_id = 1; tuple_meta.insert_txn_id = 2; - table_page.update_tuple_meta(&tuple_meta, &super::Rid::new(0, 0)); - let tuple_meta = table_page.get_tuple_meta(&super::Rid::new(0, 0)); + table_page.update_tuple_meta(&tuple_meta, 0).unwrap(); + let tuple_meta = table_page.tuple_meta(0).unwrap(); assert_eq!(tuple_meta.is_deleted, true); assert_eq!(tuple_meta.delete_txn_id, 1); assert_eq!(tuple_meta.insert_txn_id, 2);