mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-28 17:18:58 +00:00
a80699b6dd
feat(targets): add an opt-in NATS JetStream publish path for the notify and audit targets The NATS notify and audit targets publish through NATS Core, which returns before the server has durably accepted the message. A broker restart or a connection drop between the publish and the flush loses the event, even though the send queue has already cleared it, and no acknowledgement gates that clear. An opt-in JetStream publish path clears a queued event only after the server returns a durable PublishAck, so delivery is at-least-once across a broker restart or a reconnect. It applies to both the notify and audit NATS targets, is off by default, and is byte-identical to the NATS Core path when disabled. The path includes durable store-and-forward, a stable dedup id sent as the Nats-Msg-Id header so a replayed event is collapsed by the stream duplicate window, pre-flight stream validation, and a bounded failed-events store for terminally-failed and retry-exhausted events. Three configuration keys per target select it: JETSTREAM_ENABLE, JETSTREAM_STREAM_NAME, and JETSTREAM_ACK_TIMEOUT_SECS, under the RUSTFS_NOTIFY_NATS_ and RUSTFS_AUDIT_NATS_ prefixes. The on-disk batch filename separator changes from colon to underscore so batch names are valid on Windows filesystems, with transparent read-back of files written under the previous separator. The migration affects the shared queue store for every target type and lands with this feature because the store gains its first Windows-exercised paths here. Co-authored-by: houseme <housemecn@gmail.com>
106 lines
2.6 KiB
Rust
106 lines
2.6 KiB
Rust
// 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.
|
|
|
|
use std::io;
|
|
use thiserror::Error;
|
|
|
|
/// Error types for the store
|
|
#[derive(Debug, Error)]
|
|
pub enum StoreError {
|
|
#[error("I/O error: {0}")]
|
|
Io(#[from] io::Error),
|
|
|
|
#[error("Serialization error: {0}")]
|
|
Serialization(String),
|
|
|
|
#[error("Deserialization error: {0}")]
|
|
Deserialization(String),
|
|
|
|
#[error("Compression error: {0}")]
|
|
Compression(String),
|
|
|
|
#[error("Entry limit exceeded")]
|
|
LimitExceeded,
|
|
|
|
#[error("Entry not found")]
|
|
NotFound,
|
|
|
|
#[error("Invalid entry: {0}")]
|
|
Internal(String), // Added internal error type
|
|
}
|
|
|
|
/// Error types for targets
|
|
#[derive(Debug, Error)]
|
|
pub enum TargetError {
|
|
#[error("Storage error: {0}")]
|
|
Storage(String),
|
|
|
|
#[error("Network error: {0}")]
|
|
Network(String),
|
|
|
|
#[error("Request error: {0}")]
|
|
Request(String),
|
|
|
|
#[error("JetStream publish error ({}): {detail}", if *.retryable { "retryable" } else { "terminal" })]
|
|
JetStreamPublish { retryable: bool, detail: String },
|
|
|
|
#[error("Timeout error: {0}")]
|
|
Timeout(String),
|
|
|
|
#[error("Authentication error: {0}")]
|
|
Authentication(String),
|
|
|
|
#[error("Configuration error: {0}")]
|
|
Configuration(String),
|
|
|
|
#[error("Encoding error: {0}")]
|
|
Encoding(String),
|
|
|
|
#[error("Serialization error: {0}")]
|
|
Serialization(String),
|
|
|
|
#[error("Target not connected")]
|
|
NotConnected,
|
|
|
|
#[error("Target initialization failed: {0}")]
|
|
Initialization(String),
|
|
|
|
#[error("Invalid ARN: {0}")]
|
|
InvalidARN(String),
|
|
|
|
#[error("Unknown error: {0}")]
|
|
Unknown(String),
|
|
|
|
#[error("Target is disabled")]
|
|
Disabled,
|
|
|
|
#[error("Queued payload dropped: {0}")]
|
|
Dropped(String),
|
|
|
|
#[error("Configuration parsing error: {0}")]
|
|
ParseError(String),
|
|
|
|
#[error("Failed to save configuration: {0}")]
|
|
SaveConfig(String),
|
|
|
|
#[error("Server not initialized: {0}")]
|
|
ServerNotInitialized(String),
|
|
}
|
|
|
|
impl From<url::ParseError> for TargetError {
|
|
fn from(err: url::ParseError) -> Self {
|
|
TargetError::Configuration(format!("URL parse error: {err}"))
|
|
}
|
|
}
|