Skip to main content

risingwave_storage/hummock/pin_cache/
membership.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
15use risingwave_hummock_sdk::HummockSstableObjectId;
16
17use super::PinCache;
18
19impl PinCache {
20    /// Registers objects for explicit refill without downloading them.
21    /// Registering an existing object preserves its publication; it does not repair
22    /// an invalidated file. A registered object is readable only after publication.
23    pub(crate) fn register_objects(
24        &self,
25        objects: impl IntoIterator<Item = HummockSstableObjectId>,
26    ) {
27        // Release the shard between objects so a large update does not hold up lookups.
28        for id in objects {
29            self.shard(id).write().register_object(id);
30        }
31    }
32
33    /// Unregisters objects and withdraws their publications.
34    /// Existing read handles retain their files. The refiller decides when to apply delta
35    /// deletions relative to version publication; this method does not wait for a version.
36    pub(crate) fn unregister_objects(
37        &self,
38        objects: impl IntoIterator<Item = HummockSstableObjectId>,
39    ) {
40        for id in objects {
41            // Release the shard before dropping the removed publication.
42            let object = self.shard(id).write().objects.remove(&id);
43            if let Some(mut object) = object {
44                object.unpublish();
45            }
46        }
47    }
48
49    /// Whether an object is registered, regardless of whether it has a readable local file.
50    pub(crate) fn is_registered(&self, object_id: HummockSstableObjectId) -> bool {
51        self.shard(object_id)
52            .read()
53            .objects
54            .contains_key(&object_id)
55    }
56}