/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 | | RemoveItemCallback, 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 | 1 | pub fn new() -> Arc<Self> { |
44 | 1 | Arc::new(Self {}) |
45 | 1 | } |
46 | | } |
47 | | |
48 | | #[async_trait] |
49 | | impl StoreDriver for NoopStore { |
50 | | async fn has_with_results( |
51 | | self: Pin<&Self>, |
52 | | _keys: &[StoreKey<'_>], |
53 | | results: &mut [Option<u64>], |
54 | 0 | ) -> Result<(), Error> { |
55 | 0 | results.iter_mut().for_each(|r| *r = None); |
56 | | Ok(()) |
57 | 0 | } |
58 | | |
59 | | async fn update( |
60 | | self: Pin<&Self>, |
61 | | _key: StoreKey<'_>, |
62 | | mut reader: DropCloserReadHalf, |
63 | | _size_info: UploadSizeInfo, |
64 | 0 | ) -> Result<(), Error> { |
65 | | // We need to drain the reader to avoid the writer complaining that we dropped |
66 | | // the connection prematurely. |
67 | | reader.drain().await.err_tip(|| "In NoopStore::update")?; |
68 | | Ok(()) |
69 | 0 | } |
70 | | |
71 | 2 | fn optimized_for(&self, optimization: StoreOptimizations) -> bool { |
72 | 2 | optimization == StoreOptimizations::NoopUpdates Branch (72:9): [True: 0, False: 2]
Branch (72:9): [Folded - Ignored]
|
73 | 2 | || optimization == StoreOptimizations::NoopDownloads |
74 | 2 | } |
75 | | |
76 | | async fn get_part( |
77 | | self: Pin<&Self>, |
78 | | _key: StoreKey<'_>, |
79 | | _writer: &mut DropCloserWriteHalf, |
80 | | _offset: u64, |
81 | | _length: Option<u64>, |
82 | 0 | ) -> Result<(), Error> { |
83 | | Err(make_err!(Code::NotFound, "Not found in noop store")) |
84 | 0 | } |
85 | | |
86 | 2 | fn inner_store(&self, _key: Option<StoreKey>) -> &dyn StoreDriver { |
87 | 2 | self |
88 | 2 | } |
89 | | |
90 | 0 | fn as_any<'a>(&'a self) -> &'a (dyn core::any::Any + Sync + Send + 'static) { |
91 | 0 | self |
92 | 0 | } |
93 | | |
94 | 0 | fn as_any_arc(self: Arc<Self>) -> Arc<dyn core::any::Any + Sync + Send + 'static> { |
95 | 0 | self |
96 | 0 | } |
97 | | |
98 | 0 | fn register_remove_callback( |
99 | 0 | self: Arc<Self>, |
100 | 0 | _callback: Arc<dyn RemoveItemCallback>, |
101 | 0 | ) -> Result<(), Error> { |
102 | | // does nothing, so drop |
103 | 0 | Ok(()) |
104 | 0 | } |
105 | | } |
106 | | |
107 | | default_health_status_indicator!(NoopStore); |