Coverage Report

Created: 2026-07-21 15:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/build/source/nativelink-store/src/noop_store.rs
Line
Count
Source
1
// Copyright 2024 The NativeLink Authors. All rights reserved.
2
//
3
// Licensed under the Functional Source License, Version 1.1, Apache 2.0 Future License (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
//    See LICENSE file for details
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
use core::pin::Pin;
16
use std::sync::Arc;
17
18
use async_trait::async_trait;
19
use nativelink_error::{Code, Error, ResultExt, make_err};
20
use nativelink_metric::{
21
    MetricFieldData, MetricKind, MetricPublishKnownKindData, MetricsComponent,
22
};
23
use nativelink_util::buf_channel::{DropCloserReadHalf, DropCloserWriteHalf};
24
use nativelink_util::health_utils::{HealthStatusIndicator, default_health_status_indicator};
25
use nativelink_util::store_trait::{
26
    RemoveCallback, StoreDriver, StoreKey, StoreOptimizations, UploadSizeInfo,
27
};
28
29
#[derive(Debug, Default, Clone, Copy)]
30
pub struct NoopStore;
31
32
impl MetricsComponent for NoopStore {
33
0
    fn publish(
34
0
        &self,
35
0
        _kind: MetricKind,
36
0
        _field_metadata: MetricFieldData,
37
0
    ) -> Result<MetricPublishKnownKindData, nativelink_metric::Error> {
38
0
        Ok(MetricPublishKnownKindData::Component)
39
0
    }
40
}
41
42
impl NoopStore {
43
2
    pub fn new() -> Arc<Self> {
44
2
        Arc::new(Self {})
45
2
    }
46
}
47
48
#[async_trait]
49
impl StoreDriver for NoopStore {
50
0
    async fn post_init(self: Arc<Self>) -> Result<(), Error> {
51
        Ok(())
52
0
    }
53
54
    async fn has_with_results(
55
        self: Pin<&Self>,
56
        _keys: &[StoreKey<'_>],
57
        results: &mut [Option<u64>],
58
0
    ) -> Result<(), Error> {
59
        for result in results.iter_mut() {
60
            *result = None;
61
        }
62
        Ok(())
63
0
    }
64
65
    async fn update(
66
        self: Pin<&Self>,
67
        _key: StoreKey<'_>,
68
        mut reader: DropCloserReadHalf,
69
        _size_info: UploadSizeInfo,
70
0
    ) -> Result<u64, Error> {
71
        // We need to drain the reader to avoid the writer complaining that we dropped
72
        // the connection prematurely.
73
        let size = reader.drain().await.err_tip(|| "In NoopStore::update")?;
74
        Ok(size)
75
0
    }
76
77
3
    fn optimized_for(&self, optimization: StoreOptimizations) -> bool {
78
3
        optimization == StoreOptimizations::NoopUpdates
79
2
            || optimization == StoreOptimizations::NoopDownloads
80
3
    }
81
82
    async fn get_part(
83
        self: Pin<&Self>,
84
        _key: StoreKey<'_>,
85
        _writer: &mut DropCloserWriteHalf,
86
        _offset: u64,
87
        _length: Option<u64>,
88
0
    ) -> Result<(), Error> {
89
        Err(make_err!(Code::NotFound, "Not found in noop store"))
90
0
    }
91
92
3
    fn inner_store(&self, _key: Option<StoreKey>) -> &dyn StoreDriver {
93
3
        self
94
3
    }
95
96
0
    fn as_any<'a>(&'a self) -> &'a (dyn core::any::Any + Sync + Send + 'static) {
97
0
        self
98
0
    }
99
100
0
    fn as_any_arc(self: Arc<Self>) -> Arc<dyn core::any::Any + Sync + Send + 'static> {
101
0
        self
102
0
    }
103
104
0
    fn register_remove_callback(self: Arc<Self>, _callback: RemoveCallback) -> Result<(), Error> {
105
        // does nothing, so drop
106
0
        Ok(())
107
0
    }
108
}
109
110
default_health_status_indicator!(NoopStore);