mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2025-12-22 22:20:02 +00:00
chore: remove canonicalize (#7430)
* chore: remove canonicalize Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: add match file name option Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update field name Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: modify tls option Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update config file Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update config md Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update option to `enable_filename_match` Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: address CR issues Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: remove option Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: remove unused test Signed-off-by: shuiyisong <xixing.sys@gmail.com> --------- Signed-off-by: shuiyisong <xixing.sys@gmail.com>
This commit is contained in:
@@ -131,7 +131,6 @@ key_path = ""
|
|||||||
## For now, gRPC tls config does not support auto reload.
|
## For now, gRPC tls config does not support auto reload.
|
||||||
watch = false
|
watch = false
|
||||||
|
|
||||||
|
|
||||||
## MySQL server options.
|
## MySQL server options.
|
||||||
[mysql]
|
[mysql]
|
||||||
## Whether to enable.
|
## Whether to enable.
|
||||||
|
|||||||
@@ -59,15 +59,6 @@ pub enum Error {
|
|||||||
location: Location,
|
location: Location,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[snafu(display("Failed to canonicalize path: {}", path))]
|
|
||||||
CanonicalizePath {
|
|
||||||
path: String,
|
|
||||||
#[snafu(source)]
|
|
||||||
error: std::io::Error,
|
|
||||||
#[snafu(implicit)]
|
|
||||||
location: Location,
|
|
||||||
},
|
|
||||||
|
|
||||||
#[snafu(display("Invalid path '{}': expected a file, not a directory", path))]
|
#[snafu(display("Invalid path '{}': expected a file, not a directory", path))]
|
||||||
InvalidPath {
|
InvalidPath {
|
||||||
path: String,
|
path: String,
|
||||||
@@ -82,8 +73,7 @@ impl ErrorExt for Error {
|
|||||||
Error::TomlFormat { .. }
|
Error::TomlFormat { .. }
|
||||||
| Error::LoadLayeredConfig { .. }
|
| Error::LoadLayeredConfig { .. }
|
||||||
| Error::FileWatch { .. }
|
| Error::FileWatch { .. }
|
||||||
| Error::InvalidPath { .. }
|
| Error::InvalidPath { .. } => StatusCode::InvalidArguments,
|
||||||
| Error::CanonicalizePath { .. } => StatusCode::InvalidArguments,
|
|
||||||
Error::SerdeJson { .. } => StatusCode::Unexpected,
|
Error::SerdeJson { .. } => StatusCode::Unexpected,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use common_telemetry::{error, info, warn};
|
|||||||
use notify::{EventKind, RecursiveMode, Watcher};
|
use notify::{EventKind, RecursiveMode, Watcher};
|
||||||
use snafu::ResultExt;
|
use snafu::ResultExt;
|
||||||
|
|
||||||
use crate::error::{CanonicalizePathSnafu, FileWatchSnafu, InvalidPathSnafu, Result};
|
use crate::error::{FileWatchSnafu, InvalidPathSnafu, Result};
|
||||||
|
|
||||||
/// Configuration for the file watcher behavior.
|
/// Configuration for the file watcher behavior.
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
@@ -41,15 +41,10 @@ pub struct FileWatcherConfig {
|
|||||||
|
|
||||||
impl FileWatcherConfig {
|
impl FileWatcherConfig {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_modify_and_create(mut self) -> Self {
|
pub fn include_remove_events(mut self) -> Self {
|
||||||
self.include_remove_events = false;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_remove_events(mut self) -> Self {
|
|
||||||
self.include_remove_events = true;
|
self.include_remove_events = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -93,11 +88,8 @@ impl FileWatcherBuilder {
|
|||||||
path: path.display().to_string(),
|
path: path.display().to_string(),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// Canonicalize the path for reliable comparison with event paths
|
|
||||||
let canonical = path.canonicalize().context(CanonicalizePathSnafu {
|
self.file_paths.push(path.to_path_buf());
|
||||||
path: path.display().to_string(),
|
|
||||||
})?;
|
|
||||||
self.file_paths.push(canonical);
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +136,6 @@ impl FileWatcherBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let config = self.config;
|
let config = self.config;
|
||||||
let watched_files: HashSet<PathBuf> = self.file_paths.iter().cloned().collect();
|
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Spawning file watcher for paths: {:?} (watching parent directories)",
|
"Spawning file watcher for paths: {:?} (watching parent directories)",
|
||||||
@@ -165,25 +156,7 @@ impl FileWatcherBuilder {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if any of the event paths match our watched files
|
info!(?event.kind, ?event.paths, "Detected folder change");
|
||||||
let is_watched_file = event.paths.iter().any(|event_path| {
|
|
||||||
// Try to canonicalize the event path for comparison
|
|
||||||
// If the file was deleted, canonicalize will fail, so we also
|
|
||||||
// compare the raw path
|
|
||||||
if let Ok(canonical) = event_path.canonicalize()
|
|
||||||
&& watched_files.contains(&canonical)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// For deleted files, compare using the raw path
|
|
||||||
watched_files.contains(event_path)
|
|
||||||
});
|
|
||||||
|
|
||||||
if !is_watched_file {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
info!(?event.kind, ?event.paths, "Detected file change");
|
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -301,55 +274,4 @@ mod tests {
|
|||||||
"Watcher should have detected file recreation"
|
"Watcher should have detected file recreation"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_file_watcher_ignores_other_files() {
|
|
||||||
common_telemetry::init_default_ut_logging();
|
|
||||||
|
|
||||||
let dir = create_temp_dir("test_file_watcher_other");
|
|
||||||
let watched_file = dir.path().join("watched.txt");
|
|
||||||
let other_file = dir.path().join("other.txt");
|
|
||||||
|
|
||||||
// Create both files
|
|
||||||
std::fs::write(&watched_file, "watched content").unwrap();
|
|
||||||
std::fs::write(&other_file, "other content").unwrap();
|
|
||||||
|
|
||||||
let counter = Arc::new(AtomicUsize::new(0));
|
|
||||||
let counter_clone = counter.clone();
|
|
||||||
|
|
||||||
FileWatcherBuilder::new()
|
|
||||||
.watch_path(&watched_file)
|
|
||||||
.unwrap()
|
|
||||||
.config(FileWatcherConfig::new())
|
|
||||||
.spawn(move || {
|
|
||||||
counter_clone.fetch_add(1, Ordering::SeqCst);
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Give watcher time to start
|
|
||||||
std::thread::sleep(Duration::from_millis(100));
|
|
||||||
|
|
||||||
// Modify the other file - should NOT trigger callback
|
|
||||||
std::fs::write(&other_file, "modified other content").unwrap();
|
|
||||||
|
|
||||||
// Wait for potential event
|
|
||||||
std::thread::sleep(Duration::from_millis(500));
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
counter.load(Ordering::SeqCst),
|
|
||||||
0,
|
|
||||||
"Watcher should not have detected changes to other files"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Now modify the watched file - SHOULD trigger callback
|
|
||||||
std::fs::write(&watched_file, "modified watched content").unwrap();
|
|
||||||
|
|
||||||
// Wait for the event to be processed
|
|
||||||
std::thread::sleep(Duration::from_millis(500));
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
counter.load(Ordering::SeqCst) >= 1,
|
|
||||||
"Watcher should have detected change to watched file"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -362,13 +362,13 @@ mod tests {
|
|||||||
cert_path: "/path/to/cert_path".to_string(),
|
cert_path: "/path/to/cert_path".to_string(),
|
||||||
key_path: "/path/to/key_path".to_string(),
|
key_path: "/path/to/key_path".to_string(),
|
||||||
ca_cert_path: String::new(),
|
ca_cert_path: String::new(),
|
||||||
watch: false
|
watch: false,
|
||||||
},
|
},
|
||||||
TlsOption::new(
|
TlsOption::new(
|
||||||
Some(Disable),
|
Some(Disable),
|
||||||
Some("/path/to/cert_path".to_string()),
|
Some("/path/to/cert_path".to_string()),
|
||||||
Some("/path/to/key_path".to_string()),
|
Some("/path/to/key_path".to_string()),
|
||||||
false
|
false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user