Skip to content

Commit aff81c8

Browse files
authored
[Breaking] Remove backwards compatibility for configs (#1695)
This was previously deprecated in v0.5.4.
1 parent 6473203 commit aff81c8

File tree

5 files changed

+16
-206
lines changed

5 files changed

+16
-206
lines changed

nativelink-config/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ rust_test_suite(
3232
name = "integration",
3333
timeout = "short",
3434
srcs = [
35-
"tests/backwards_compat_test.rs",
3635
"tests/deserialization_test.rs",
3736
],
3837
deps = [

nativelink-config/src/cas_server.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ use std::collections::HashMap;
1616

1717
use serde::Deserialize;
1818

19+
use crate::schedulers::SchedulerSpec;
1920
use crate::serde_utils::{
2021
convert_data_size_with_shellexpand, convert_duration_with_shellexpand,
2122
convert_numeric_with_shellexpand, convert_optional_numeric_with_shellexpand,
2223
convert_optional_string_with_shellexpand, convert_string_with_shellexpand,
2324
convert_vec_string_with_shellexpand,
2425
};
25-
use crate::stores::{ClientTlsConfig, ConfigDigestHashFunction, StoreRefName};
26-
use crate::{SchedulerConfigs, StoreConfigs};
26+
use crate::stores::{ClientTlsConfig, ConfigDigestHashFunction, StoreRefName, StoreSpec};
2727

2828
/// Name of the scheduler. This type will be used when referencing a
2929
/// scheduler in the `CasConfig::schedulers`'s map key.
@@ -716,20 +716,30 @@ pub struct GlobalConfig {
716716
pub default_digest_size_health_check: usize,
717717
}
718718

719+
#[derive(Debug, Clone, Deserialize)]
720+
pub struct NamedConfig<Spec> {
721+
pub name: String,
722+
#[serde(flatten)]
723+
pub spec: Spec,
724+
}
725+
726+
pub type StoreConfig = NamedConfig<StoreSpec>;
727+
pub type SchedulerConfig = NamedConfig<SchedulerSpec>;
728+
719729
#[derive(Deserialize, Debug)]
720730
#[serde(deny_unknown_fields)]
721731
pub struct CasConfig {
722732
/// List of stores available to use in this config.
723733
/// The keys can be used in other configs when needing to reference a store.
724-
pub stores: StoreConfigs,
734+
pub stores: Vec<StoreConfig>,
725735

726736
/// Worker configurations used to execute jobs.
727737
pub workers: Option<Vec<WorkerConfig>>,
728738

729739
/// List of schedulers available to use in this config.
730740
/// The keys can be used in other configs when needing to reference a
731741
/// scheduler.
732-
pub schedulers: Option<SchedulerConfigs>,
742+
pub schedulers: Option<Vec<SchedulerConfig>>,
733743

734744
/// Servers to setup for this process.
735745
pub servers: Vec<ServerConfig>,

nativelink-config/src/lib.rs

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -16,147 +16,3 @@ pub mod cas_server;
1616
pub mod schedulers;
1717
pub mod serde_utils;
1818
pub mod stores;
19-
20-
use std::any::type_name;
21-
use std::collections::HashMap;
22-
use std::fmt;
23-
use std::marker::PhantomData;
24-
25-
use serde::de::{MapAccess, SeqAccess, Visitor};
26-
use serde::{Deserialize, Deserializer};
27-
28-
#[derive(Debug, Clone, Deserialize)]
29-
pub struct NamedConfig<Spec> {
30-
pub name: String,
31-
#[serde(flatten)]
32-
pub spec: Spec,
33-
}
34-
35-
pub type StoreConfig = NamedConfig<stores::StoreSpec>;
36-
pub type SchedulerConfig = NamedConfig<schedulers::SchedulerSpec>;
37-
38-
// TODO(aaronmondal): Remove all the iterator impls and the Deserializer once we
39-
// fully migrate to the new config schema.
40-
pub type StoreConfigs = NamedConfigs<stores::StoreSpec>;
41-
pub type SchedulerConfigs = NamedConfigs<schedulers::SchedulerSpec>;
42-
43-
#[derive(Debug)]
44-
pub struct NamedConfigs<T>(pub Vec<NamedConfig<T>>);
45-
46-
impl<T> NamedConfigs<T> {
47-
pub fn iter(&self) -> std::slice::Iter<'_, NamedConfig<T>> {
48-
self.0.iter()
49-
}
50-
}
51-
52-
impl<T> IntoIterator for NamedConfigs<T> {
53-
type Item = NamedConfig<T>;
54-
type IntoIter = std::vec::IntoIter<Self::Item>;
55-
56-
fn into_iter(self) -> Self::IntoIter {
57-
self.0.into_iter()
58-
}
59-
}
60-
61-
impl<'a, T> IntoIterator for &'a NamedConfigs<T> {
62-
type Item = &'a NamedConfig<T>;
63-
type IntoIter = std::slice::Iter<'a, NamedConfig<T>>;
64-
65-
fn into_iter(self) -> Self::IntoIter {
66-
self.0.iter()
67-
}
68-
}
69-
70-
struct NamedConfigsVisitor<T> {
71-
phantom: PhantomData<T>,
72-
}
73-
74-
impl<T> NamedConfigsVisitor<T> {
75-
const fn new() -> Self {
76-
NamedConfigsVisitor {
77-
phantom: PhantomData,
78-
}
79-
}
80-
}
81-
82-
impl<'de, T: Deserialize<'de>> Visitor<'de> for NamedConfigsVisitor<T> {
83-
type Value = NamedConfigs<T>;
84-
85-
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
86-
formatter.write_str("a sequence or map of named configs")
87-
}
88-
89-
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
90-
where
91-
A: SeqAccess<'de>,
92-
{
93-
let mut vec = Vec::new();
94-
while let Some(config) = seq.next_element()? {
95-
vec.push(config);
96-
}
97-
Ok(NamedConfigs(vec))
98-
}
99-
100-
fn visit_map<M>(self, mut access: M) -> Result<Self::Value, M::Error>
101-
where
102-
M: MapAccess<'de>,
103-
{
104-
let config_type = if type_name::<T>().contains("StoreSpec") {
105-
"stores"
106-
} else if type_name::<T>().contains("SchedulerSpec") {
107-
"schedulers"
108-
} else {
109-
"stores and schedulers"
110-
};
111-
eprintln!(
112-
r#"
113-
WARNING: Using deprecated map format for {config_type}. Please migrate to the new array format:
114-
115-
// Old:
116-
"stores": {{
117-
"SOMESTORE": {{
118-
"memory": {{}}
119-
}}
120-
}},
121-
"schedulers": {{
122-
"SOMESCHEDULER": {{
123-
"simple": {{}}
124-
}}
125-
}}
126-
127-
// New:
128-
"stores": [
129-
{{
130-
"name": "SOMESTORE",
131-
"memory": {{}}
132-
}}
133-
],
134-
"schedulers": [
135-
{{
136-
"name": "SOMESCHEDULER",
137-
"simple": {{}}
138-
}}
139-
]
140-
"#
141-
);
142-
143-
let mut map = HashMap::new();
144-
while let Some((key, value)) = access.next_entry()? {
145-
map.insert(key, value);
146-
}
147-
Ok(NamedConfigs(
148-
map.into_iter()
149-
.map(|(name, spec)| NamedConfig { name, spec })
150-
.collect(),
151-
))
152-
}
153-
}
154-
155-
impl<'de, T: Deserialize<'de>> Deserialize<'de> for NamedConfigs<T> {
156-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
157-
where
158-
D: Deserializer<'de>,
159-
{
160-
deserializer.deserialize_any(NamedConfigsVisitor::new())
161-
}
162-
}

nativelink-config/tests/backwards_compat_test.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/bin/nativelink.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ use hyper_util::server::conn::auto;
2828
use hyper_util::service::TowerToHyperService;
2929
use mimalloc::MiMalloc;
3030
use nativelink_config::cas_server::{
31-
CasConfig, GlobalConfig, HttpCompressionAlgorithm, ListenerConfig, ServerConfig, WorkerConfig,
31+
CasConfig, GlobalConfig, HttpCompressionAlgorithm, ListenerConfig, SchedulerConfig,
32+
ServerConfig, StoreConfig, WorkerConfig,
3233
};
3334
use nativelink_config::stores::ConfigDigestHashFunction;
34-
use nativelink_config::{SchedulerConfig, StoreConfig};
3535
use nativelink_error::{Code, Error, ResultExt, make_err, make_input_err};
3636
use nativelink_metric::{
3737
MetricFieldData, MetricKind, MetricPublishKnownKindData, MetricsComponent, RootMetricsComponent,

0 commit comments

Comments
 (0)