Skip to content

Commit

Permalink
Datetime parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Codetector1374 committed Aug 7, 2024
1 parent d6ff223 commit 84ac80a
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 77 deletions.
158 changes: 158 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ default-run="page_explorer"

[dependencies]
anyhow = "1.0.86"
chrono = "0.4.38"
clap = { version = "4.5.9", features = ["derive"] }
crc = "3.2.1"
indicatif = "0.17.8"
Expand Down
5 changes: 3 additions & 2 deletions src/bin/page_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use clap::Parser;
use innodb::innodb::{
buffer_manager::{
lru::LRUBufferManager, simple::SimpleBufferManager, BufferManager, DummyBufferMangaer,
lru::LRUBufferManager, BufferManager, DummyBufferMangaer,
},
page::{
index::{record::RecordType, IndexPage},
Expand Down Expand Up @@ -125,7 +125,8 @@ impl PageExplorer {
let values = row.parse_values(self.buffer_mgr.as_mut());
assert_eq!(values.len(), table.field_count());
debug!("{:?}", values);
self.write_row(row.record.header.info_flags.deleted, &values).expect("Failed to write row");
self.write_row(row.record.header.info_flags.deleted, &values)
.expect("Failed to write row");
}
}
RecordType::NodePointer => {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/page_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn validate_page(page: &[u8]) -> PageValidationResult {
};

trace!("Bad page: {:#?}", page);
return PageValidationResult::NotAPage;
PageValidationResult::NotAPage
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/tablespace_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Page {
impl Page {
fn offset(&self) -> u32 {
let num: [u8; 4] = self.data[4..8].try_into().unwrap();
return u32::from_be_bytes(num);
u32::from_be_bytes(num)
}
}

Expand Down
19 changes: 7 additions & 12 deletions src/innodb/buffer_manager/lru.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use std::{
borrow::BorrowMut,
cell::RefCell,
collections::{HashMap, LinkedList},
collections::HashMap,
fs::File,
io::{Read, Seek, SeekFrom},
path::{Path, PathBuf},
slice,
sync::atomic::{AtomicU32, AtomicU64, Ordering},
time::SystemTime,
usize,
};

use super::{BufferManager, PageGuard};
Expand All @@ -17,7 +14,7 @@ use crate::innodb::{
InnoDBError,
};
use anyhow::{anyhow, Result};
use tracing::{trace, warn};
use tracing::trace;

const LRU_PAGE_COUNT: usize = 16;

Expand Down Expand Up @@ -52,7 +49,7 @@ impl LRUBufferManager {
.lru_list
.borrow_mut()
.resize(LRU_PAGE_COUNT, 0);
return buffer_manager;
buffer_manager
}

pub fn find_free(&self) -> usize {
Expand All @@ -74,15 +71,13 @@ impl LRUBufferManager {
let ((space_id, offset), _) = borrowed_pin_map
.iter()
.find(|(_, val)| **val == result_frame)
.expect(&format!(
"can't find the frame({result_frame}), {:#?}, pinmap: {:#?}",
self, borrowed_pin_map
))
.unwrap_or_else(|| panic!("can't find the frame({result_frame}), {:#?}, pinmap: {:#?}",
self, borrowed_pin_map))
.to_owned();
let (space_id, offset) = (*space_id, *offset);
borrowed_pin_map.remove(&(space_id, offset));
self.lru_list.borrow_mut()[result_frame] = 0;
return result_frame;
result_frame
} else {
panic!("pin too many pages, \nState: {:#?}", self);
}
Expand Down Expand Up @@ -127,7 +122,7 @@ impl BufferManager for LRUBufferManager {
})?;

// Validate page *FIRST*
let page = Page::from_bytes(&self.backing_store[free_frame as usize])?;
let page = Page::from_bytes(&self.backing_store[free_frame])?;
if page.header.space_id == 0 && page.header.offset == 0 {
return Err(anyhow!(InnoDBError::PageNotFound));
}
Expand Down
2 changes: 1 addition & 1 deletion src/innodb/page/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a> Page<'a> {

Ok(Page {
// space_id: header.space_id,
header: header,
header,
trailer: FILTrailer::from_bytes(&buf[(FIL_PAGE_SIZE - FIL_TRAILER_SIZE)..])?,
raw_data: buf,
})
Expand Down
Loading

0 comments on commit 84ac80a

Please sign in to comment.