Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): revert acquire exclusive lock to global data dir #19649

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ enum_dispatch = { version = "0.3.12", default-features = false }
exitcode = { version = "1.1.2", default-features = false }
flate2 = { version = "1.0.28", default-features = false, features = ["default"] }
futures-util = { version = "0.3.29", default-features = false }
fs4 = { version = "0.7.0" }
glob = { version = "0.3.1", default-features = false }
governor = { version = "0.6.0", default-features = false, features = ["dashmap", "jitter", "std"], optional = true }
grok = { version = "2.0.0", default-features = false, optional = true }
Expand Down Expand Up @@ -311,7 +310,6 @@ socket2 = { version = "0.5.5", default-features = false }
stream-cancel = { version = "0.8.2", default-features = false }
strip-ansi-escapes = { version = "0.2.0", default-features = false }
syslog = { version = "6.1.0", default-features = false, optional = true }
tempfile = "3.9.0"
tikv-jemallocator = { version = "0.5.4", default-features = false, features = ["unprefixed_malloc_on_supported_platforms"], optional = true }
tokio-postgres = { version = "0.7.10", default-features = false, features = ["runtime", "with-chrono-0_4"], optional = true }
tokio-tungstenite = {version = "0.20.1", default-features = false, features = ["connect"], optional = true}
Expand Down
1 change: 0 additions & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ float_eq,https://github.com/jtempest/float_eq-rs,MIT OR Apache-2.0,jtempest
flume,https://github.com/zesterer/flume,Apache-2.0 OR MIT,Joshua Barretto <[email protected]>
fnv,https://github.com/servo/rust-fnv,Apache-2.0 OR MIT,Alex Crichton <[email protected]>
foreign-types,https://github.com/sfackler/foreign-types,MIT OR Apache-2.0,Steven Fackler <[email protected]>
fs4,https://github.com/al8n/fs4-rs,MIT OR Apache-2.0,"Dan Burkert <[email protected]>, Al Liu <[email protected]>"
fsevent-sys,https://github.com/octplane/fsevent-rust/tree/master/fsevent-sys,MIT,Pierre Baillet <[email protected]>
fslock,https://github.com/brunoczim/fslock,MIT,The fslock Authors
funty,https://github.com/myrrlyn/funty,MIT,myrrlyn <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion changelog.d/19595_lock_data_dir.fix.md

This file was deleted.

2 changes: 2 additions & 0 deletions regression/cases/http_elasticsearch/vector/vector.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
data_dir: "/var/lib/vector"

##
## Sources
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
data_dir: "/var/lib/vector"

##
## Sources
##
Expand Down
1 change: 0 additions & 1 deletion src/config/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ impl From<Config> for ConfigBuilder {
secret,
graceful_shutdown_duration,
hash: _,
..
} = config;

let transforms = transforms
Expand Down
39 changes: 1 addition & 38 deletions src/config/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
// Workaround for a false positive. The function `create_data_dir_lock` cannot be const.
#![allow(clippy::missing_const_for_fn)]
use indexmap::IndexSet;

use super::{
builder::ConfigBuilder, graph::Graph, id::Inputs, transform::get_transform_output_ids,
validation, Config, OutputId,
};
use std::fs::File;
use std::path::PathBuf;

use indexmap::IndexSet;

#[cfg(not(test))]
use fs4::FileExt;

#[cfg(not(test))]
fn create_data_dir_lock(data_dir: &Option<PathBuf>) -> Result<Option<File>, String> {
if let Some(data_dir) = data_dir {
let lock_path = data_dir.join(".lock");
let lock = File::create(&lock_path).map_err(|e| e.to_string())?;
match lock.try_lock_exclusive() {
Ok(()) => Ok(Some(lock)),
Err(e) => Err(format!("Couldn't lock {lock_path:?}. Error: {e}")),
}
} else {
Ok(None)
}
}

#[cfg(test)]
fn create_data_dir_lock(_data_dir: &Option<PathBuf>) -> Result<Option<File>, String> {
// TODO: We should make all tests work with unique directories but this requires extensive changes.
Ok(None)
}

pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<String>> {
let mut errors = Vec::new();
Expand Down Expand Up @@ -125,18 +97,9 @@ pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<
.map(|test| test.resolve_outputs(&graph))
.collect::<Result<Vec<_>, Vec<_>>>()?;

let data_dir_lock = match create_data_dir_lock(&global.data_dir) {
Ok(lock) => lock,
Err(e) => {
errors.push(e);
None
}
};

if errors.is_empty() {
let mut config = Config {
global,
data_dir_lock,
#[cfg(feature = "api")]
api,
schema,
Expand Down
3 changes: 0 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![allow(missing_docs)]
use std::fs::File;
use std::{
collections::{HashMap, HashSet},
fmt::{self, Display, Formatter},
Expand Down Expand Up @@ -113,8 +112,6 @@ pub struct Config {
#[cfg(feature = "enterprise")]
pub enterprise: Option<enterprise::Options>,
pub global: GlobalOptions,
#[serde(skip)]
pub data_dir_lock: Option<File>,
pub healthchecks: HealthcheckOptions,
sources: IndexMap<ComponentKey, SourceOuter>,
sinks: IndexMap<ComponentKey, SinkOuter<OutputId>>,
Expand Down
6 changes: 0 additions & 6 deletions src/config/unit_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
use futures_util::{stream::FuturesUnordered, StreamExt};
use indexmap::IndexMap;
use ordered_float::NotNan;
use tempfile::TempDir;
use tokio::sync::{
oneshot::{self, Receiver},
Mutex,
Expand Down Expand Up @@ -40,8 +39,6 @@ use crate::{

pub struct UnitTest {
pub name: String,
#[allow(dead_code)]
temp_dir: TempDir,
config: Config,
pieces: TopologyPieces,
test_result_rxs: Vec<Receiver<UnitTestSinkResult>>,
Expand Down Expand Up @@ -425,15 +422,12 @@ async fn build_unit_test(
.sinks
.insert(ComponentKey::from(Uuid::new_v4().to_string()), sink);
}
let temp_dir = TempDir::new().unwrap();
config_builder.set_data_dir(temp_dir.path());
let config = config_builder.build()?;
let diff = config::ConfigDiff::initial(&config);
let pieces = TopologyPieces::build(&config, &diff, HashMap::new(), Default::default()).await?;

Ok(UnitTest {
name: test.name,
temp_dir,
config,
pieces,
test_result_rxs,
Expand Down
Loading