pub struct CryptoExchangeCache {
pub lv2_exchange_cache: DashMap<ExchangeCacheKey, CachedOrderBook>,
pub lv2_prob_to_brokers: DashMap<ExchangeCacheKey, HashSet<u32>>,
/* private fields */
}Expand description
Crypto LV2 多交易所缓存. 包装 3 个 DashMap + 反向索引重建逻辑.
线程安全: 内部全用 DashMap, 任意线程可同时 read/write.
lifecycle: 整个 daemon lifetime, 由 GatewayBridge::crypto_exchange_cache
持有 Arc.
Fields§
§lv2_exchange_cache: DashMap<ExchangeCacheKey, CachedOrderBook>(stock_id, lv2_prob) → orderbook (exchange-level, raw from push).
lv2_prob_to_brokers: DashMap<ExchangeCacheKey, HashSet<u32>>(stock_id, lv2_prob) → set<broker_id> — 反向索引,
O(1) 查询受 exchange-level push 影响的 broker 集.
Implementations§
Source§impl CryptoExchangeCache
impl CryptoExchangeCache
pub fn new() -> Arc<Self>
设置 (stock_id, broker_id) 对应的 exchange 列表 (CMD18012 response).
副作用:
- 更新
by_broker[(stock_id, broker_id)] = exchanges - 重建
lv2_prob_to_brokers[(stock_id, *)]该 stock 的反向索引 (先清旧 entries 该 stock 的所有 prob → 再按本次 + 其他 broker 重建)
对齐 C++ INNData_Qot_CryptoExchange::SetLv2RelatedExchange(stKey, vExchanges) +
UpdateLv2ProbToBrokersIndex(nStockID).
Sourcepub fn exchanges_for_broker(
&self,
stock_id: u64,
broker_id: u32,
) -> Option<Vec<CryptoExchangeInfo>>
pub fn exchanges_for_broker( &self, stock_id: u64, broker_id: u32, ) -> Option<Vec<CryptoExchangeInfo>>
取某 broker 看某 stock 的 exchange 列表.
Sourcepub fn fact_snapshot(&self) -> CryptoExchangeFactSnapshot
pub fn fact_snapshot(&self) -> CryptoExchangeFactSnapshot
Clone all exact broker facts while holding the existing writer serialization lock, so every consumer in one request sees one immutable view.
Sourcepub fn set_lv2_exchange_cache(
&self,
stock_id: u64,
lv2_prob: i32,
orderbook: CachedOrderBook,
)
pub fn set_lv2_exchange_cache( &self, stock_id: u64, lv2_prob: i32, orderbook: CachedOrderBook, )
写 exchange-level cache (单个 exchange 的原始 LV2 摆盘).
对齐 C++ m_mapLv2ExchangeCache[cacheKey] = pbOrderBook (QotRealTimeData.cpp:938).
Sourcepub fn get_lv2_exchange_cache(
&self,
stock_id: u64,
lv2_prob: i32,
) -> Option<CachedOrderBook>
pub fn get_lv2_exchange_cache( &self, stock_id: u64, lv2_prob: i32, ) -> Option<CachedOrderBook>
取 exchange-level cache.
Sourcepub fn get_brokers_affected_by_lv2_prob(
&self,
stock_id: u64,
lv2_prob: i32,
) -> HashSet<u32>
pub fn get_brokers_affected_by_lv2_prob( &self, stock_id: u64, lv2_prob: i32, ) -> HashSet<u32>
反向索引查询: (stock_id, lv2_prob) 影响哪些 broker.
对齐 C++ setBrokerIDs = m_mapLv2ProbToBrokers[cacheKey] (QotRealTimeData.cpp:941-944).
v1.4.111 P2-1 Tier 3 audit comment: reverse lookup helper — empty HashSet =
“no brokers affected by this (stock_id, lv2_prob)”, caller iterate 空集合
自然跳过. 跟 C++ setBrokerIDs empty 行为对齐. 非 silent-success risk
(audit verified, essentials/2026-05-27).
Sourcepub fn collect_exchange_caches_for_broker(
&self,
stock_id: u64,
broker_id: u32,
) -> Vec<CachedOrderBook>
pub fn collect_exchange_caches_for_broker( &self, stock_id: u64, broker_id: u32, ) -> Vec<CachedOrderBook>
给定 (stock_id, broker_id), 收集该 broker 的所有 exchange 对应的
exchange-level cache 列表 (用作 merge 输入).
对齐 C++ MergeCryptoExchangesToBrokerCache 内部逻辑 (line 987-1022).
Sourcepub fn collect_exchange_caches_for_stock(
&self,
stock_id: u64,
) -> Vec<CachedOrderBook>
pub fn collect_exchange_caches_for_stock( &self, stock_id: u64, ) -> Vec<CachedOrderBook>
收集某 stock 的所有 exchange-level orderbook cache.
C++ US stock TotalView/ARCA path does not use broker mappings: it writes
m_mapLv2ExchangeCache[(stock_id, lv2_type)], then
MergeExchangeCacheToMain merges every exchange cache for that stock.
Crypto still uses the broker-specific helper above.
Sourcepub fn clear_stock(&self, stock_id: u64)
pub fn clear_stock(&self, stock_id: u64)
清除某 stock 的所有 cache (退订 / reset 时调).
对齐 C++ ClearStockData(nStockID).
Sourcepub fn clear_stock_broker(&self, stock_id: u64, broker_id: u32)
pub fn clear_stock_broker(&self, stock_id: u64, broker_id: u32)
v1.4.110 R6-8: 清除某 (stock_id, broker_id) 的 by_broker entry +
重建该 stock 反向索引. 用于 部分 broker 退订 —— stock 还有别的 broker
在订 (clear_stock 整 stock 清不适用), 但本 broker 已全局无订阅, 其
by_broker[(stock, broker)] 会 stale 滞留 → by_broker 慢漏累积死 entry.
移除本 broker 后该 stock 已无任何 broker → 连 lv2_exchange_cache 一并清
(无 broker 引用的 exchange-level cache 也是 stale).
Sourcepub fn brokers_for_stock(&self, stock_id: u64) -> Vec<u32>
pub fn brokers_for_stock(&self, stock_id: u64) -> Vec<u32>
v1.4.110 R6-8: 列出 by_broker 里某 stock 当前缓存的所有 broker_id.
退订路径用它枚举该 stock 的 broker, 逐个判是否已全局无订阅 → clear.
Sourcepub fn rebuild_broker_cache(
&self,
qot_cache: &QotCache,
stock_id: u64,
broker_id: u32,
broker_cache_key: &str,
) -> Option<CachedOrderBook>
pub fn rebuild_broker_cache( &self, qot_cache: &QotCache, stock_id: u64, broker_id: u32, broker_cache_key: &str, ) -> Option<CachedOrderBook>
v1.4.110 R6-2 + R6-4: 重建某 (stock_id, broker_id) 的 broker-level
摆盘缓存 —— 收集该 broker 所有 exchange 的 LV2 cache → merge 40 档 → 写
qot_cache.order_books[broker_cache_key] → 唤醒 cold-cache waiter.
对齐 C++ QotRealTimeData::RebuildCryptoBrokerCache (line 960-985).
parse_crypto_lv2_order_book_to_push (push 路径, 每个 affected broker 调
一次) 与 maybe_fetch_crypto_exchanges (CMD18012 完成后补 merge, R6-4)
共用本 fn.
返 Some(merged) 供 caller 构造 PushEvent; 该 broker 当前无任何 exchange
cache (collect 空) → None (无数据可 merge, 不动 qot_cache).
broker_cache_key 由 caller 传 (= QotSecurityKey::cache_key(),
"{public}@b{broker_id}") —— public sec_key 构造需要 market/code 上下文,
不在本 cache 持有.
Trait Implementations§
Source§impl Debug for CryptoExchangeCache
impl Debug for CryptoExchangeCache
Source§impl Default for CryptoExchangeCache
impl Default for CryptoExchangeCache
Source§fn default() -> CryptoExchangeCache
fn default() -> CryptoExchangeCache
Auto Trait Implementations§
impl !Freeze for CryptoExchangeCache
impl !RefUnwindSafe for CryptoExchangeCache
impl Send for CryptoExchangeCache
impl Sync for CryptoExchangeCache
impl Unpin for CryptoExchangeCache
impl UnsafeUnpin for CryptoExchangeCache
impl UnwindSafe for CryptoExchangeCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more