Struct tikv::server::gc_worker::gc_manager::GcManager[][src]

pub(super) struct GcManager<S: GcSafePointProvider, R: RegionInfoProvider> {
    cfg: AutoGcConfig<S, R>,
    safe_point: Arc<AtomicU64>,
    safe_point_last_check_time: Instant,
    worker_scheduler: FutureScheduler<GcTask>,
    gc_manager_ctx: GcManagerContext,
    cfg_tracker: GcWorkerConfigManager,
    feature_gate: FeatureGate,
}

Controls how GC runs automatically on the TiKV. It polls safe point periodically, and when the safe point is updated, GcManager will start to scan all regions (whose leader is on this TiKV), and does GC on all those regions.

Fields

cfg: AutoGcConfig<S, R>safe_point: Arc<AtomicU64>

The current safe point. GcManager will try to update it periodically. When safe_point is updated, GCManager will start to do GC on all regions.

safe_point_last_check_time: Instantworker_scheduler: FutureScheduler<GcTask>

Used to schedule GcTasks.

gc_manager_ctx: GcManagerContext

Holds the running status. It will tell us if GcManager should stop working and exit.

cfg_tracker: GcWorkerConfigManagerfeature_gate: FeatureGate

Implementations

impl<S: GcSafePointProvider, R: RegionInfoProvider + 'static> GcManager<S, R>[src]

pub fn new(
    cfg: AutoGcConfig<S, R>,
    safe_point: Arc<AtomicU64>,
    worker_scheduler: FutureScheduler<GcTask>,
    cfg_tracker: GcWorkerConfigManager,
    feature_gate: FeatureGate
) -> GcManager<S, R>
[src]

fn curr_safe_point(&self) -> TimeStamp[src]

fn save_safe_point(&self, ts: TimeStamp)[src]

pub fn start(self) -> Result<GcManagerHandle>[src]

Starts working in another thread. This function moves the GcManager and returns a handler of it.

fn run(&mut self)[src]

Polls safe point and does GC in a loop, again and again, until interrupted by invoking GcManagerHandle::stop.

fn run_impl(&mut self) -> Result<(), GcManagerError>[src]

fn initialize(&mut self)[src]

Sets the initial state of the GCManger. The only task of initializing is to simply get the current safe point as the initial value of safe_point. TiKV won’t do any GC automatically until the first time safe_point was updated to a greater value than initial value.

fn wait_for_next_safe_point(&mut self) -> Result<TimeStamp, GcManagerError>[src]

Waits until the safe_point updates. Returns the new safe point.

fn try_update_safe_point(&mut self) -> bool[src]

Tries to update the safe point. Returns true if safe point has been updated to a greater value. Returns false if safe point didn’t change or we encountered an error.

fn gc_a_round(&mut self) -> Result<(), GcManagerError>[src]

Scans all regions on the TiKV whose leader is this TiKV, and does GC on all of them. Regions are scanned and GC-ed in lexicographical order.

While the gc_a_round function is running, it will periodically check whether safe_point is updated before the function gc_a_round finishes. If so, Rewinding will occur. For example, when we just starts to do GC, our progress is like this: (‘^’ means our current progress)

| region 1 | region 2 | region 3| region 4 | region 5 | region 6 |
^

And after a while, our GC progress is like this:

| region 1 | region 2 | region 3| region 4 | region 5 | region 6 |
----------------------^

At this time we found that safe point was updated, so rewinding will happen. First we continue working to the end: (‘#’ indicates the position that safe point updates)

| region 1 | region 2 | region 3| region 4 | region 5 | region 6 |
----------------------#------------------------------------------^

Then region 1-2 were GC-ed with the old safe point and region 3-6 were GC-ed with the new new one. Then, we rewind to the very beginning and continue GC to the position that safe point updates:

| region 1 | region 2 | region 3| region 4 | region 5 | region 6 |
----------------------#------------------------------------------^
----------------------^

Then GC finishes. If safe point updates again at some time, it will still try to GC all regions with the latest safe point. If safe point always updates before gc_a_round finishes, gc_a_round may never stop, but it doesn’t matter.

fn check_if_need_rewind(
    &mut self,
    progress: &Option<Key>,
    need_rewind: &mut bool,
    end: &mut Option<Key>
)
[src]

Checks whether we need to rewind in this round of GC. Only used in gc_a_round.

fn gc_next_region(
    &mut self,
    from_key: Key,
    processed_regions: &mut usize
) -> Result<Option<Key>, GcManagerError>
[src]

Does GC on the next region after from_key. Returns the end key of the region it processed. If we have processed to the end of all regions, returns None.

fn get_next_gc_context(
    &mut self,
    key: Key
) -> (Option<(u64, Vec<u8>, Vec<u8>)>, Option<Key>)
[src]

Gets the next region with end_key greater than given key. Returns a tuple with 2 fields: the first is the next region can be sent to GC worker; the second is the next key which can be passed into this method later.

Auto Trait Implementations

impl<S, R> !RefUnwindSafe for GcManager<S, R>

impl<S, R> Send for GcManager<S, R>

impl<S, R> !Sync for GcManager<S, R>

impl<S, R> Unpin for GcManager<S, R> where
    R: Unpin,
    S: Unpin

impl<S, R> !UnwindSafe for GcManager<S, R>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<V, W> ConvertFrom<W> for V where
    W: ConvertTo<V>, 
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T> Sealed<T> for T where
    T: ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]