From c94f2981d7dc8a12fd0617aa3b3f25d02a1736c9 Mon Sep 17 00:00:00 2001 From: Zhengchao An Date: Mon, 29 Jun 2026 22:46:06 +0800 Subject: [PATCH] refactor(replication): add event sink boundary (#4068) --- crates/ecstore/src/bucket/replication/mod.rs | 1 + .../replication/replication_event_sink.rs | 19 +++++++++++++++++++ .../replication/replication_resyncer.rs | 2 +- scripts/check_architecture_migration_rules.sh | 13 +++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 crates/ecstore/src/bucket/replication/replication_event_sink.rs diff --git a/crates/ecstore/src/bucket/replication/mod.rs b/crates/ecstore/src/bucket/replication/mod.rs index c170239d2..2d5087d8e 100644 --- a/crates/ecstore/src/bucket/replication/mod.rs +++ b/crates/ecstore/src/bucket/replication/mod.rs @@ -14,6 +14,7 @@ mod config; pub mod datatypes; +mod replication_event_sink; mod replication_pool; mod replication_resyncer; mod replication_state; diff --git a/crates/ecstore/src/bucket/replication/replication_event_sink.rs b/crates/ecstore/src/bucket/replication/replication_event_sink.rs new file mode 100644 index 000000000..66f61298d --- /dev/null +++ b/crates/ecstore/src/bucket/replication/replication_event_sink.rs @@ -0,0 +1,19 @@ +// Copyright 2024 RustFS Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub(crate) use crate::services::event_notification::EventArgs; + +pub(crate) fn send_event(args: EventArgs) { + crate::services::event_notification::send_event(args); +} diff --git a/crates/ecstore/src/bucket/replication/replication_resyncer.rs b/crates/ecstore/src/bucket/replication/replication_resyncer.rs index b156dd3b4..d9512be09 100644 --- a/crates/ecstore/src/bucket/replication/replication_resyncer.rs +++ b/crates/ecstore/src/bucket/replication/replication_resyncer.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use super::replication_event_sink::{EventArgs, send_event}; use super::runtime_boundary as runtime_sources; use crate::bucket::bandwidth::reader::{BucketOptions, MonitorReaderOptions, MonitoredReader}; use crate::bucket::bucket_target_sys::{ @@ -29,7 +30,6 @@ use crate::config::com::save_config; use crate::disk::{BUCKET_META_PREFIX, RUSTFS_META_BUCKET}; use crate::error::{Error, Result, is_err_object_not_found, is_err_version_not_found}; use crate::object_api::{GetObjectReader, ObjectInfo, ObjectOptions, PutObjReader}; -use crate::services::event_notification::{EventArgs, send_event}; use crate::set_disk::get_lock_acquire_timeout; use crate::storage_api_contracts::{ list::{ListOperations, StorageListObjectVersionsInfo, StorageListObjectsV2Info, StorageObjectInfoOrErr, StorageWalkOptions}, diff --git a/scripts/check_architecture_migration_rules.sh b/scripts/check_architecture_migration_rules.sh index 736c85bc0..0ebdfd722 100755 --- a/scripts/check_architecture_migration_rules.sh +++ b/scripts/check_architecture_migration_rules.sh @@ -183,6 +183,7 @@ EXTERNAL_TEST_ECSTORE_COMPAT_BYPASS_HITS_FILE="${TMP_DIR}/external_test_ecstore_ FUZZ_ECSTORE_COMPAT_BYPASS_HITS_FILE="${TMP_DIR}/fuzz_ecstore_compat_bypass_hits.txt" EXTERNAL_ECSTORE_API_BOUNDARY_HITS_FILE="${TMP_DIR}/external_ecstore_api_boundary_hits.txt" REPLICATION_FACADE_BYPASS_HITS_FILE="${TMP_DIR}/replication_facade_bypass_hits.txt" +REPLICATION_EVENT_SINK_BYPASS_HITS_FILE="${TMP_DIR}/replication_event_sink_bypass_hits.txt" REPLICATION_RUNTIME_SOURCE_BYPASS_HITS_FILE="${TMP_DIR}/replication_runtime_source_bypass_hits.txt" GLOBAL_REPLICATION_STATE_BYPASS_HITS_FILE="${TMP_DIR}/global_replication_state_bypass_hits.txt" GLOBAL_BUCKET_MONITOR_BYPASS_HITS_FILE="${TMP_DIR}/global_bucket_monitor_bypass_hits.txt" @@ -2338,6 +2339,18 @@ if [[ -s "$REPLICATION_RUNTIME_SOURCE_BYPASS_HITS_FILE" ]]; then report_failure "replication runtime-source access must stay behind replication runtime boundary: $(paste -sd '; ' "$REPLICATION_RUNTIME_SOURCE_BYPASS_HITS_FILE")" fi +( + cd "$ROOT_DIR" + rg -n --with-filename 'crate::services::event_notification' \ + crates/ecstore/src/bucket/replication \ + --glob '*.rs' | + rg -v '^crates/ecstore/src/bucket/replication/replication_event_sink\.rs:' || true +) >"$REPLICATION_EVENT_SINK_BYPASS_HITS_FILE" + +if [[ -s "$REPLICATION_EVENT_SINK_BYPASS_HITS_FILE" ]]; then + report_failure "replication event notification access must stay behind replication event sink: $(paste -sd '; ' "$REPLICATION_EVENT_SINK_BYPASS_HITS_FILE")" +fi + ( cd "$ROOT_DIR" rg -n --with-filename '\bGLOBAL_REPLICATION_(POOL|STATS)\b' \