Showing 4 of 4 files from the diff.
@@ -18,21 +18,21 @@
Loading
18 | 18 | vec::{self, IntoIter}, |
|
19 | 19 | }; |
|
20 | 20 | ||
21 | - | #[derive(Clone)] |
|
21 | + | #[derive(Clone, Default)] |
|
22 | 22 | pub struct NewSegmentPage { |
|
23 | 23 | pub segment: u32, |
|
24 | 24 | pub page: u64, |
|
25 | 25 | pub previous: u64, |
|
26 | 26 | } |
|
27 | 27 | ||
28 | - | #[derive(Clone)] |
|
28 | + | #[derive(Clone, Default)] |
|
29 | 29 | pub struct InsertRecord { |
|
30 | 30 | pub segment: u32, |
|
31 | 31 | pub recref: RecRef, |
|
32 | 32 | pub record_page: u64, |
|
33 | 33 | } |
|
34 | 34 | ||
35 | - | #[derive(Clone)] |
|
35 | + | #[derive(Clone, Default)] |
|
36 | 36 | pub struct UpdateRecord { |
|
37 | 37 | pub segment: u32, |
|
38 | 38 | pub recref: RecRef, |
@@ -40,46 +40,51 @@
Loading
40 | 40 | pub version: u16, |
|
41 | 41 | } |
|
42 | 42 | ||
43 | - | #[derive(Clone)] |
|
43 | + | #[derive(Clone, Default)] |
|
44 | 44 | pub struct ReadRecord { |
|
45 | 45 | pub segment: u32, |
|
46 | 46 | pub recref: RecRef, |
|
47 | 47 | pub version: u16, |
|
48 | 48 | } |
|
49 | 49 | ||
50 | - | #[derive(Clone)] |
|
50 | + | #[derive(Clone, Default)] |
|
51 | 51 | pub struct DeleteRecord { |
|
52 | 52 | pub segment: u32, |
|
53 | 53 | pub recref: RecRef, |
|
54 | 54 | pub version: u16, |
|
55 | 55 | } |
|
56 | 56 | ||
57 | - | #[derive(Clone)] |
|
57 | + | #[derive(Clone, Default)] |
|
58 | 58 | pub struct CreateSegment { |
|
59 | 59 | pub name: String, |
|
60 | 60 | pub segment_id: u32, |
|
61 | 61 | pub first_page: u64, |
|
62 | 62 | } |
|
63 | 63 | ||
64 | - | #[derive(Clone)] |
|
64 | + | #[derive(Clone, Default)] |
|
65 | 65 | pub struct DropSegment { |
|
66 | 66 | pub name: String, |
|
67 | 67 | pub segment_id: u32, |
|
68 | 68 | } |
|
69 | 69 | ||
70 | - | #[derive(Clone, PartialEq, Debug, PartialOrd, Ord, Eq)] |
|
70 | + | #[derive(Clone, PartialEq, Debug, PartialOrd, Ord, Eq, Default)] |
|
71 | 71 | pub struct FreedPage { |
|
72 | 72 | pub page: u64, |
|
73 | 73 | } |
|
74 | 74 | ||
75 | + | #[derive(Default)] |
|
75 | 76 | pub struct PrepareCommit {} |
|
76 | 77 | ||
78 | + | #[derive(Default)] |
|
77 | 79 | pub struct Commit {} |
|
78 | 80 | ||
81 | + | #[derive(Default)] |
|
79 | 82 | pub struct Cleanup {} |
|
80 | 83 | ||
84 | + | #[derive(Default)] |
|
81 | 85 | pub struct Rollback {} |
|
82 | 86 | ||
87 | + | #[derive(Default)] |
|
83 | 88 | pub struct Metadata { |
|
84 | 89 | pub strategy: TxStrategy, |
|
85 | 90 | pub meta_id: Vec<u8>, |
@@ -28,7 +28,7 @@
Loading
28 | 28 | Ok(u32_vdec(&bytes).map_err(|_| PersyError::InvalidId(String::from(s)))?.0) |
|
29 | 29 | } |
|
30 | 30 | ||
31 | - | #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug)] |
|
31 | + | #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug, Default)] |
|
32 | 32 | pub struct RecRef { |
|
33 | 33 | pub page: u64, |
|
34 | 34 | pub pos: u32, |
@@ -5,10 +5,9 @@
Loading
5 | 5 | use crate::{ |
|
6 | 6 | allocator::Allocator, |
|
7 | 7 | config::TxStrategy, |
|
8 | - | discref::{Page, PageOps, PAGE_METADATA_SIZE}, |
|
8 | + | discref::{Page, PageOps, ReadPage, PAGE_METADATA_SIZE}, |
|
9 | 9 | error::PRes, |
|
10 | 10 | flush_checksum::{double_buffer_check, prepare_buffer_flush}, |
|
11 | - | id::RecRef, |
|
12 | 11 | io::{read_u64, write_u64, InfallibleRead, InfallibleReadFormat, InfallibleWrite, InfallibleWriteFormat}, |
|
13 | 12 | persy::RecoverStatus, |
|
14 | 13 | }; |
@@ -115,6 +114,15 @@
Loading
115 | 114 | pos: u32, |
|
116 | 115 | } |
|
117 | 116 | ||
117 | + | fn recover_entry<T>(entry: &mut dyn JournalEntry, page: &mut ReadPage, found: &mut T, id: &JournalId) -> PRes<u32> |
|
118 | + | where |
|
119 | + | T: FnMut(&dyn JournalEntry, &JournalId), |
|
120 | + | { |
|
121 | + | let read_size = entry.read(page)?; |
|
122 | + | found(entry, id); |
|
123 | + | Ok(read_size) |
|
124 | + | } |
|
125 | + | ||
118 | 126 | impl Journal { |
|
119 | 127 | pub fn new(all: &Arc<Allocator>, page: u64) -> PRes<Journal> { |
|
120 | 128 | let first_page; |
@@ -324,72 +332,27 @@
Loading
324 | 332 | cur_cursor = JOURNAL_PAGE_CONTENT_OFFSET; |
|
325 | 333 | jr.last_page = cur_page; |
|
326 | 334 | } else { |
|
327 | - | let mut read_size = 0; |
|
328 | 335 | let page_id = page.read_u64(); |
|
329 | 336 | let pos = page.read_u32(); |
|
330 | - | let mut recover_entry = |entry: &mut dyn JournalEntry| -> PRes<()> { |
|
331 | - | read_size = entry.read(&mut page)?; |
|
332 | - | found(entry, &JournalId::new(page_id, pos)); |
|
333 | - | Ok(()) |
|
334 | - | }; |
|
335 | - | match tp { |
|
336 | - | 1 => { |
|
337 | - | let mut entry = Start::new(); |
|
338 | - | read_size = entry.read(&mut page)?; |
|
339 | - | //The Start entry has no valid id, should not be recovered |
|
340 | - | } |
|
341 | - | 2 => { |
|
342 | - | let mut entry = InsertRecord::new(0, &RecRef::new(0, 0), 0); |
|
343 | - | recover_entry(&mut entry)?; |
|
344 | - | } |
|
345 | - | 3 => { |
|
346 | - | let mut entry = PrepareCommit::new(); |
|
347 | - | recover_entry(&mut entry)?; |
|
348 | - | } |
|
349 | - | 4 => { |
|
350 | - | let mut entry = Commit::new(); |
|
351 | - | recover_entry(&mut entry)?; |
|
352 | - | } |
|
353 | - | 5 => { |
|
354 | - | let mut entry = UpdateRecord::new(0, &RecRef::new(0, 0), 0, 0); |
|
355 | - | recover_entry(&mut entry)?; |
|
356 | - | } |
|
357 | - | 6 => { |
|
358 | - | let mut entry = DeleteRecord::new(0, &RecRef::new(0, 0), 0); |
|
359 | - | recover_entry(&mut entry)?; |
|
360 | - | } |
|
361 | - | 7 => { |
|
362 | - | let mut entry = Rollback::new(); |
|
363 | - | recover_entry(&mut entry)?; |
|
364 | - | } |
|
365 | - | 8 => { |
|
366 | - | let mut entry = CreateSegment::new("", 0, 0); |
|
367 | - | recover_entry(&mut entry)?; |
|
368 | - | } |
|
369 | - | 9 => { |
|
370 | - | let mut entry = DropSegment::new("", 0); |
|
371 | - | recover_entry(&mut entry)?; |
|
372 | - | } |
|
373 | - | 10 => { |
|
374 | - | let mut entry = ReadRecord::new(0, &RecRef::new(0, 0), 0); |
|
375 | - | recover_entry(&mut entry)?; |
|
376 | - | } |
|
377 | - | 11 => { |
|
378 | - | let mut entry = Metadata::new(&TxStrategy::LastWin, Vec::new()); |
|
379 | - | recover_entry(&mut entry)?; |
|
380 | - | } |
|
381 | - | 12 => { |
|
382 | - | let mut entry = FreedPage::new(0); |
|
383 | - | recover_entry(&mut entry)?; |
|
384 | - | } |
|
385 | - | 13 => { |
|
386 | - | let mut entry = NewSegmentPage::new(0, 0, 0); |
|
387 | - | recover_entry(&mut entry)?; |
|
388 | - | } |
|
389 | - | 14 => { |
|
390 | - | let mut entry = Cleanup::new(); |
|
391 | - | recover_entry(&mut entry)?; |
|
392 | - | } |
|
337 | + | let id = JournalId::new(page_id, pos); |
|
338 | + | let ref_page = &mut page; |
|
339 | + | let ref_found = &mut found; |
|
340 | + | let read_size = match tp { |
|
341 | + | //The Start entry has no valid id, should not be recovered |
|
342 | + | 1 => Start::new().read(&mut page)?, |
|
343 | + | 2 => recover_entry(&mut InsertRecord::default(), ref_page, ref_found, &id)?, |
|
344 | + | 3 => recover_entry(&mut PrepareCommit::default(), ref_page, ref_found, &id)?, |
|
345 | + | 4 => recover_entry(&mut Commit::default(), ref_page, ref_found, &id)?, |
|
346 | + | 5 => recover_entry(&mut UpdateRecord::default(), ref_page, ref_found, &id)?, |
|
347 | + | 6 => recover_entry(&mut DeleteRecord::default(), ref_page, ref_found, &id)?, |
|
348 | + | 7 => recover_entry(&mut Rollback::default(), ref_page, ref_found, &id)?, |
|
349 | + | 8 => recover_entry(&mut CreateSegment::default(), ref_page, ref_found, &id)?, |
|
350 | + | 9 => recover_entry(&mut DropSegment::default(), ref_page, ref_found, &id)?, |
|
351 | + | 10 => recover_entry(&mut ReadRecord::default(), ref_page, ref_found, &id)?, |
|
352 | + | 11 => recover_entry(&mut Metadata::default(), ref_page, ref_found, &id)?, |
|
353 | + | 12 => recover_entry(&mut FreedPage::default(), ref_page, ref_found, &id)?, |
|
354 | + | 13 => recover_entry(&mut NewSegmentPage::default(), ref_page, ref_found, &id)?, |
|
355 | + | 14 => recover_entry(&mut Cleanup::default(), ref_page, ref_found, &id)?, |
|
393 | 356 | _ => panic!(" wrong log entry {} ", tp), |
|
394 | 357 | }; |
|
395 | 358 | cur_cursor = read_size + cur_cursor + 13; |
662721674
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.