1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#![allow(dead_code)]
extern crate libc;
extern crate rustc_serialize;
extern crate bincode;
use std::collections::HashMap;
mod log;
mod map;
mod page;
mod rsdb;
mod tree;
mod tx;
mod crc16;
pub mod ops;
pub use rsdb::RSDB;
pub use log::Log;
use crc16::crc16_arr;
type PageID = u64;
type LogID = u64;
type TxID = u64;
type Epoch = u64;
#[derive(Debug, Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub struct KV {
k: Vec<u8>,
v: Vec<u8>,
}
#[derive(Debug, Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub enum LogDelta {
KV(KV),
Merge {
left: PageID,
right: PageID,
},
Split {
left: PageID,
right: PageID,
},
FailedFlush,
}
#[derive(Debug, Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub enum Delta {
KV(KV),
Merge {
left: PageID,
right: PageID,
},
Split {
left: PageID,
right: PageID,
},
TxBegin(TxID),
TxCommit(TxID),
TxAbort(TxID),
Flush {
pid: PageID,
annotation: Annotation,
},
PartialSwap(LogID),
}
#[derive(Debug, Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub struct Page;
#[derive(Debug, Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub enum Data {
Page(Page),
Delta(Delta),
}
#[derive(Debug, Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub struct PD {
data: Data,
lid: LogID,
pid: PageID,
}
#[derive(Debug, Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub struct LogPage;
#[derive(Debug, Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub struct Annotation;
#[derive(Debug, Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub enum LogData {
Full(LogPage),
Deltas(Vec<LogDelta>),
}