-
Notifications
You must be signed in to change notification settings - Fork 168
Recovery #397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Recovery #397
Changes from 49 commits
7ca757c
7e32771
26b55b5
356e4fd
0503216
5ea5667
4ccf01f
592a823
67d5aa5
9caeec5
b4bed3a
d2966d2
deaaa91
677200b
3603c1b
09a1f65
21ba045
7dc7d73
45aa5b1
7c15eb8
5d0e633
aeb62de
49c06e3
1606340
1caaf22
83e428a
2df8f22
7be8f07
19385a4
f7e9468
710674d
a73aa63
7334b3f
9e9dd5c
de08656
6d77a73
d7692ef
8d72b48
5b6dd2f
f1ed123
bdd17b6
f47db51
739365e
186b9b4
ed43a6d
917855e
995544a
43eef14
d62bfb0
92e1f24
dc85b30
cefb4b9
6197220
154549b
eb671d0
62c953e
8816e11
396e704
ea1e114
85531a3
2396be8
c641d8f
b1ed33c
466a4c1
7d7e952
e8c0b6e
85ab29a
7dc5c48
9d46425
2318a47
be9a15a
ae713b7
553b333
befab11
19e0147
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,10 @@ use serde::{Deserialize, Serialize}; | |
|
|
||
| const MB: usize = 1024 * 1024; | ||
|
|
||
| // restore and graceful shutdown options | ||
| const RESTORE: bool = false; | ||
| const GRACEFUL_SHUTDOWN: bool = false; | ||
|
|
||
| // defaults for hashtable | ||
| const HASH_POWER: u8 = 16; | ||
| const OVERFLOW_FACTOR: f64 = 1.0; | ||
|
|
@@ -24,9 +28,18 @@ const COMPACT_TARGET: usize = 2; | |
| const MERGE_TARGET: usize = 4; | ||
| const MERGE_MAX: usize = 8; | ||
|
|
||
| // datapool | ||
| // datapool (`Segments.data`) | ||
| const DATAPOOL_PATH: Option<&str> = None; | ||
|
|
||
| // `Segments` fields | ||
| const SEGMENT_FIELDS_PATH: Option<&str> = None; | ||
|
|
||
| // ttl buckets | ||
| const TTL_BUCKETS_PATH: Option<&str> = None; | ||
|
|
||
| // hashtable | ||
| const HASHTABLE_PATH: Option<&str> = None; | ||
|
|
||
| #[derive(Copy, Clone, Debug, Serialize, Deserialize)] | ||
| pub enum Eviction { | ||
| None, | ||
|
|
@@ -39,6 +52,14 @@ pub enum Eviction { | |
| } | ||
|
|
||
| // helper functions for default values | ||
| fn restore() -> bool { | ||
| RESTORE | ||
| } | ||
|
|
||
| fn graceful_shutdown() -> bool { | ||
| GRACEFUL_SHUTDOWN | ||
| } | ||
|
|
||
| fn hash_power() -> u8 { | ||
| HASH_POWER | ||
| } | ||
|
|
@@ -75,9 +96,25 @@ fn datapool_path() -> Option<String> { | |
| DATAPOOL_PATH.map(|v| v.to_string()) | ||
| } | ||
|
|
||
| fn segments_fields_path() -> Option<String> { | ||
| SEGMENT_FIELDS_PATH.map(|v| v.to_string()) | ||
| } | ||
|
|
||
| fn ttl_buckets_path() -> Option<String> { | ||
| TTL_BUCKETS_PATH.map(|v| v.to_string()) | ||
| } | ||
|
|
||
| fn hashtable_path() -> Option<String> { | ||
| HASHTABLE_PATH.map(|v| v.to_string()) | ||
| } | ||
|
|
||
| // definitions | ||
| #[derive(Serialize, Deserialize, Debug)] | ||
| pub struct Seg { | ||
| #[serde(default = "restore")] | ||
| restore: bool, | ||
| #[serde(default = "graceful_shutdown")] | ||
| graceful_shutdown: bool, | ||
| #[serde(default = "hash_power")] | ||
| hash_power: u8, | ||
| #[serde(default = "overflow_factor")] | ||
|
|
@@ -96,11 +133,19 @@ pub struct Seg { | |
| compact_target: usize, | ||
| #[serde(default = "datapool_path")] | ||
| datapool_path: Option<String>, | ||
| #[serde(default = "segments_fields_path")] | ||
| segments_fields_path: Option<String>, | ||
| #[serde(default = "ttl_buckets_path")] | ||
| ttl_buckets_path: Option<String>, | ||
| #[serde(default = "hashtable_path")] | ||
| hashtable_path: Option<String>, | ||
| } | ||
|
|
||
| impl Default for Seg { | ||
| fn default() -> Self { | ||
| Self { | ||
| restore: restore(), | ||
| graceful_shutdown: graceful_shutdown(), | ||
| hash_power: hash_power(), | ||
| overflow_factor: overflow_factor(), | ||
| heap_size: heap_size(), | ||
|
|
@@ -110,12 +155,31 @@ impl Default for Seg { | |
| merge_max: merge_max(), | ||
| compact_target: compact_target(), | ||
| datapool_path: datapool_path(), | ||
| segments_fields_path: segments_fields_path(), | ||
| ttl_buckets_path: ttl_buckets_path(), | ||
| hashtable_path: hashtable_path(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // implementation | ||
| impl Seg { | ||
| // Determines if the `Seg` will be restored. | ||
| // The restoration will be successful if `datapool_path`, `segments_fields_path` | ||
| // `ttl_buckets_path` and `hashtable_path` are valid paths. | ||
| // Otherwise, the `Seg` will be created as new. | ||
| pub fn restore(&self) -> bool { | ||
| self.restore | ||
| } | ||
|
|
||
| // Determines if the `Seg` will be gracefully shutdown. | ||
| // The graceful shutdown will be successful if the cache is file backed | ||
| // and `segments_fields_path`, `ttl_buckets_path` and `hashtable_path` are | ||
| // valid paths to save the relevant `Seg` fields to. | ||
| // Otherwise, the relevant `Seg` fields will not be saved. | ||
| pub fn graceful_shutdown(&self) -> bool { | ||
|
cassyunknown marked this conversation as resolved.
|
||
| self.graceful_shutdown | ||
| } | ||
| pub fn hash_power(&self) -> u8 { | ||
| self.hash_power | ||
| } | ||
|
|
@@ -151,6 +215,24 @@ impl Seg { | |
| pub fn datapool_path(&self) -> Option<PathBuf> { | ||
| self.datapool_path.as_ref().map(|v| Path::new(v).to_owned()) | ||
| } | ||
|
|
||
| pub fn segments_fields_path(&self) -> Option<PathBuf> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should each of these paths be it's own config option? I suspect we can be opinionated about the names for each file if we decide to keep the parts separate.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was going to wait until we decided how many files to use |
||
| self.segments_fields_path | ||
| .as_ref() | ||
| .map(|v| Path::new(v).to_owned()) | ||
| } | ||
|
|
||
| pub fn ttl_buckets_path(&self) -> Option<PathBuf> { | ||
| self.ttl_buckets_path | ||
| .as_ref() | ||
| .map(|v| Path::new(v).to_owned()) | ||
| } | ||
|
|
||
| pub fn hashtable_path(&self) -> Option<PathBuf> { | ||
| self.hashtable_path | ||
| .as_ref() | ||
| .map(|v| Path::new(v).to_owned()) | ||
| } | ||
| } | ||
|
|
||
| // trait definitions | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,16 +43,30 @@ impl Seg { | |
|
|
||
| // build the datastructure from the config | ||
| let data = ::seg::Seg::builder() | ||
| .restore(config.restore()) | ||
| .hash_power(config.hash_power()) | ||
| .overflow_factor(config.overflow_factor()) | ||
| .heap_size(config.heap_size()) | ||
| .segment_size(config.segment_size()) | ||
| .eviction(eviction) | ||
| .datapool_path(config.datapool_path()) | ||
| .segments_fields_path(config.segments_fields_path()) | ||
| .ttl_buckets_path(config.ttl_buckets_path()) | ||
| .hashtable_path(config.hashtable_path()) | ||
| .build(); | ||
|
|
||
| Self { data } | ||
| } | ||
|
|
||
| /// Flush (gracefully shutdown) the `Seg` cache if configured to do so | ||
| pub fn flush<T: SegConfig>(self, config: &T) { | ||
| let config = config.seg(); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find a trait that I should implement (that only has the |
||
|
|
||
| if config.graceful_shutdown() { | ||
| // TODO: check if successfully shutdown and record result | ||
| self.data.flush(); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line currently produces a warning as I am ignoring the Result. Ideally the result would be intepreted here or passed along to |
||
| }; | ||
| } | ||
| } | ||
|
|
||
| impl EntryStore for Seg { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.