risingwave_storage/hummock/table_cache_metadata.rs
1// Copyright 2026 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Current table cache policies and vnode mappings for one Hummock instance.
16//! The event handler owns and updates this state; refill tasks consume immutable snapshots.
17
18use std::collections::HashMap;
19
20use risingwave_common::bitmap::Bitmap;
21use risingwave_common::config::Role;
22use risingwave_common::config::streaming::CacheRefillPolicy;
23use risingwave_pb::id::TableId;
24
25pub(crate) struct TableCacheMetadata {
26 pub role: Role,
27 pub default_policy: CacheRefillPolicy,
28 /// Per-table overrides; an absent entry uses `default_policy`.
29 pub table_cache_refill_policies: HashMap<TableId, CacheRefillPolicy>,
30 /// Union of vnodes from this worker's local read versions, maintained by the handler.
31 pub streaming_table_vnode_mapping: HashMap<TableId, Bitmap>,
32 /// Complete worker-specific serving mapping received from Meta.
33 pub serving_table_vnode_mapping: HashMap<TableId, Bitmap>,
34}
35
36impl TableCacheMetadata {
37 pub(crate) fn new(role: Role, default_policy: CacheRefillPolicy) -> Self {
38 Self {
39 role,
40 default_policy,
41 table_cache_refill_policies: HashMap::new(),
42 streaming_table_vnode_mapping: HashMap::new(),
43 serving_table_vnode_mapping: HashMap::new(),
44 }
45 }
46
47 pub(crate) fn update_streaming_table_vnodes(
48 &mut self,
49 table_id: TableId,
50 streaming_vnodes: Option<Bitmap>,
51 ) {
52 if let Some(streaming_vnodes) = streaming_vnodes {
53 self.streaming_table_vnode_mapping
54 .insert(table_id, streaming_vnodes);
55 } else {
56 self.streaming_table_vnode_mapping.remove(&table_id);
57 }
58 }
59}