Skip to main content

QotLoginHealth

Struct QotLoginHealth 

Source
pub struct QotLoginHealth { /* private fields */ }

Implementations§

Source§

impl QotLoginHealth

Source

pub fn new() -> Self

Source

pub fn with_ladder(ladder: [u64; 4]) -> Self

v1.4.97 P1-D-B: test-friendly construction with explicit ladder.

Source

pub fn backoff_ms_ladder(&self) -> [u64; 4]

Source

pub fn record_qot_logined_false(&self)

Call from query handler / health-poll task whenever LoginCache::is_logged_in() returns false while backend is connected. Updates last-observed timestamp + monotonic counter.

Source

pub fn record_relogin_attempt(&self)

Call right before invoking the relogin code path. Records timestamp + bumps total_relogin_attempts.

Source

pub fn record_relogin_success(&self)

Call after relogin completes successfully. Clears failure counter, records timestamp, bumps success monotonic.

Source

pub fn record_relogin_failure(&self)

Call after relogin attempt fails. Bumps consecutive failure counter (drives exponential backoff in should_attempt_relogin).

Source

pub fn should_attempt_relogin( &self, qot_logined_now: bool, backend_connected: bool, ) -> bool

Decision API for the 30s polling task.

Returns true iff:

  1. caller observed a stale QOT login while the backend TCP is connected: qot_logined_now=false AND backend_connected=true; AND
  2. enough time has passed since last_relogin_attempt_at_ms per exponential-backoff schedule:
    • 0 failures → 60s
    • 1 failure → 120s
    • 2 failures → 240s
    • 3+ failures → 600s cap

Caller is responsible for separately calling record_relogin_attempt() then record_relogin_success() / record_relogin_failure() after the relogin runs.

Source

pub fn relogin_backoff_ms(&self) -> i64

Current backoff window in ms based on consecutive_relogin_failures. Public for tests / metrics; not intended for caller decision (use should_attempt_relogin).

v1.4.97 P1-D-B: ladder is now env-tunable via FUTU_QOT_RELOGIN_BACKOFF_MS=60000,120000,240000,600000. Default values unchanged from v1.4.94 baseline.

Source

pub fn try_begin_attempt(&self) -> bool

v1.4.92: 尝试 acquire in-flight slot. 返 true 表示获取成功 (caller 现在可调 refresher), 返 false 表示已有别的 attempt 在跑 (caller skip).

compare_exchange(false, true, AcqRel, Relaxed) 而非 load + store 防止两个并发 tick 都看到 false → 都进 attempt.

Source

pub fn end_attempt(&self)

v1.4.92: release in-flight slot (无论 attempt 成功或失败都该调).

Source

pub fn open_circuit(&self)

v1.4.92: 触发 circuit_open (5 连续失败后调). 记 timestamp + 置 flag.

Source

pub fn maybe_close_circuit(&self)

v1.4.92: 自动检查 + 重置 circuit (cooldown 过期则关闭 + 清 failure counter 给重试 fresh budget).

每次 polling tick 调一次, 不会引入额外开销 (atomic load + 比较).

Source

pub fn should_attempt_relogin_v2( &self, qot_logined_now: bool, backend_connected: bool, ) -> bool

v1.4.92: 扩展 decision API — 包含 circuit_open 检查.

Self::should_attempt_relogin 关系:

  • maybe_close_circuit() 检查 cooldown 是否过期 → 自动重置
  • 若 circuit 仍 open → return false (跳所有 attempt)
  • 否则 delegate 到 should_attempt_relogin (原 v1.4.90 backoff 逻辑)

调用方 (run_qot_login_health_loop) 应该用这个 v2 API 而不是 v1 的 should_attempt_relogin. v1 保留作 backward-compat (单测仍在用).

Source

pub fn record_relogin_failure_with_circuit_check(&self)

v1.4.92: 扩展版 record_relogin_failure — 失败后检查是否达 trip 阈值.

Self::record_relogin_failure 关系:

  • 先调 record_relogin_failure (++ counter)
  • 若 counter >= [RELOGIN_CIRCUIT_TRIP_THRESHOLD] → 自动 open_circuit

caller 可选用 v1 (只 ++counter) 或 v2 (++ + 触发 trip). polling loop 实装应该用 v2.

Source

pub fn snapshot(&self) -> QotLoginHealthSnapshot

Snapshot for /api/push-subscriber-info extension or future /api/admin/qot-login-health endpoint.

Trait Implementations§

Source§

impl Default for QotLoginHealth

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more