-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added a new observer type 'pitr' #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// Copyright 2016 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
use std::cmp; | ||
use std::fmt::{self, Debug, Formatter}; | ||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; | ||
use std::sync::Arc; | ||
|
@@ -247,11 +246,20 @@ impl ObserveHandle { | |
pub struct CmdObserveInfo { | ||
pub cdc_id: ObserveHandle, | ||
pub rts_id: ObserveHandle, | ||
pub pitr_id: ObserveHandle, | ||
} | ||
Comment on lines
246
to
250
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. What about an enum? Also we can replace 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. It seems that |
||
|
||
impl CmdObserveInfo { | ||
pub fn from_handle(cdc_id: ObserveHandle, rts_id: ObserveHandle) -> CmdObserveInfo { | ||
CmdObserveInfo { cdc_id, rts_id } | ||
pub fn from_handle( | ||
cdc_id: ObserveHandle, | ||
rts_id: ObserveHandle, | ||
pitr_id: ObserveHandle, | ||
) -> CmdObserveInfo { | ||
CmdObserveInfo { | ||
cdc_id, | ||
rts_id, | ||
pitr_id, | ||
} | ||
} | ||
|
||
fn observe_level(&self) -> ObserveLevel { | ||
|
@@ -261,13 +269,18 @@ impl CmdObserveInfo { | |
} else { | ||
ObserveLevel::None | ||
}; | ||
let pitr = if self.pitr_id.is_observing() { | ||
ObserveLevel::All | ||
} else { | ||
ObserveLevel::None | ||
}; | ||
let rts = if self.rts_id.is_observing() { | ||
// `resolved-ts` observe lock related data | ||
ObserveLevel::LockRelated | ||
} else { | ||
ObserveLevel::None | ||
}; | ||
cmp::max(cdc, rts) | ||
cdc.max(rts).max(pitr) | ||
} | ||
} | ||
|
||
|
@@ -276,6 +289,7 @@ impl Debug for CmdObserveInfo { | |
f.debug_struct("CmdObserveInfo") | ||
.field("cdc_id", &self.cdc_id.id) | ||
.field("rts_id", &self.rts_id.id) | ||
.field("pitr_id", &self.pitr_id.id) | ||
.finish() | ||
} | ||
} | ||
|
@@ -296,6 +310,7 @@ pub struct CmdBatch { | |
pub level: ObserveLevel, | ||
pub cdc_id: ObserveID, | ||
pub rts_id: ObserveID, | ||
pub pitr_id: ObserveID, | ||
pub region_id: u64, | ||
pub cmds: Vec<Cmd>, | ||
} | ||
|
@@ -306,6 +321,7 @@ impl CmdBatch { | |
level: observe_info.observe_level(), | ||
cdc_id: observe_info.cdc_id.id, | ||
rts_id: observe_info.rts_id.id, | ||
pitr_id: observe_info.pitr_id.id, | ||
region_id, | ||
cmds: Vec::new(), | ||
} | ||
|
@@ -315,6 +331,7 @@ impl CmdBatch { | |
assert_eq!(region_id, self.region_id); | ||
assert_eq!(observe_info.cdc_id.id, self.cdc_id); | ||
assert_eq!(observe_info.rts_id.id, self.rts_id); | ||
assert_eq!(observe_info.pitr_id.id, self.pitr_id); | ||
self.cmds.push(cmd) | ||
} | ||
|
||
|
@@ -376,22 +393,47 @@ mod tests { | |
#[test] | ||
fn test_observe_level() { | ||
// Both cdc and `resolved-ts` are observing | ||
let observe_info = CmdObserveInfo::from_handle(ObserveHandle::new(), ObserveHandle::new()); | ||
let observe_info = CmdObserveInfo::from_handle( | ||
ObserveHandle::new(), | ||
ObserveHandle::new(), | ||
ObserveHandle::new(), | ||
); | ||
assert_eq!(observe_info.observe_level(), ObserveLevel::All); | ||
|
||
// No observer | ||
observe_info.cdc_id.stop_observing(); | ||
observe_info.rts_id.stop_observing(); | ||
observe_info.pitr_id.stop_observing(); | ||
assert_eq!(observe_info.observe_level(), ObserveLevel::None); | ||
|
||
// Only cdc observing | ||
let observe_info = CmdObserveInfo::from_handle(ObserveHandle::new(), ObserveHandle::new()); | ||
let observe_info = CmdObserveInfo::from_handle( | ||
ObserveHandle::new(), | ||
ObserveHandle::new(), | ||
ObserveHandle::new(), | ||
); | ||
observe_info.rts_id.stop_observing(); | ||
observe_info.pitr_id.stop_observing(); | ||
assert_eq!(observe_info.observe_level(), ObserveLevel::All); | ||
|
||
// Only `resolved-ts` observing | ||
let observe_info = CmdObserveInfo::from_handle(ObserveHandle::new(), ObserveHandle::new()); | ||
let observe_info = CmdObserveInfo::from_handle( | ||
ObserveHandle::new(), | ||
ObserveHandle::new(), | ||
ObserveHandle::new(), | ||
); | ||
observe_info.cdc_id.stop_observing(); | ||
observe_info.pitr_id.stop_observing(); | ||
assert_eq!(observe_info.observe_level(), ObserveLevel::LockRelated); | ||
|
||
// Only `backup-stream(pitr)` observing | ||
let observe_info = CmdObserveInfo::from_handle( | ||
ObserveHandle::new(), | ||
ObserveHandle::new(), | ||
ObserveHandle::new(), | ||
); | ||
observe_info.cdc_id.stop_observing(); | ||
observe_info.rts_id.stop_observing(); | ||
assert_eq!(observe_info.observe_level(), ObserveLevel::All); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be some components just like
backup_log
bklog
?