mirror of
https://github.com/rustfs/rustfs.git
synced 2026-09-09 05:36:24 +00:00
feat(ecstore): expose pool meta write gate status
Co-Authored-By: heihutu <heihutu@gmail.com> Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
This commit is contained in:
@@ -65,6 +65,7 @@ use crate::storage_api_contracts::{
|
||||
namespace::NamespaceLocking as _,
|
||||
object::{EcstoreObjectIO, HTTPPreconditions, ObjectIO as _, ObjectOperations as _},
|
||||
};
|
||||
use crate::store::PoolMetaWriteGateStatus;
|
||||
use crate::{core::sets::Sets, store::ECStore};
|
||||
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
|
||||
use futures::{
|
||||
@@ -10275,8 +10276,21 @@ impl ECStore {
|
||||
/// Read-only admission probes do not change this state; startup and real
|
||||
/// metadata transactions still latch it on unrecoverable conditions.
|
||||
pub async fn pool_meta_writes_ready(&self) -> bool {
|
||||
self.pool_meta_write_gate_status().await.writes_ready
|
||||
}
|
||||
|
||||
pub async fn pool_meta_write_gate_status(&self) -> PoolMetaWriteGateStatus {
|
||||
let write_state = self.pool_meta_save_gate.lock().await;
|
||||
!write_state.write_blocked && !write_state.aborted_transaction.load(Ordering::SeqCst)
|
||||
let transaction_aborted = write_state.aborted_transaction.load(Ordering::SeqCst);
|
||||
PoolMetaWriteGateStatus {
|
||||
writes_ready: !write_state.write_blocked && !transaction_aborted,
|
||||
write_blocked: write_state.write_blocked,
|
||||
transaction_aborted,
|
||||
pool_meta_absent: write_state.pool_meta_absent,
|
||||
identity_initialized: write_state.identity_initialized,
|
||||
identity_needs_repair: write_state.identity_needs_repair,
|
||||
cluster_epoch: write_state.cluster_epoch,
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_runtime_pool_meta_observing(&self, write_state: &mut PoolMetaWriteState, operation: &str) -> Result<PoolMeta> {
|
||||
@@ -16917,6 +16931,10 @@ mod tests {
|
||||
.expect("create single-pool bucket before blocking pool metadata writes");
|
||||
let incarnation = store.bucket_incarnation_id(&bucket).await.expect("load bucket incarnation");
|
||||
store.pool_meta_save_gate.lock().await.block_writes_after_fence_loss();
|
||||
let write_gate = store.pool_meta_write_gate_status().await;
|
||||
assert!(!write_gate.writes_ready);
|
||||
assert!(write_gate.write_blocked);
|
||||
assert!(!write_gate.transaction_aborted);
|
||||
|
||||
let object = "ordinary-put.bin";
|
||||
let mut put_data = crate::object_api::PutObjReader::from_vec(b"ordinary single-pool body".to_vec());
|
||||
|
||||
@@ -55,6 +55,8 @@ mod set_disk;
|
||||
mod storage_api_contracts;
|
||||
mod store;
|
||||
|
||||
pub use store::PoolMetaWriteGateStatus;
|
||||
|
||||
// pub mod checksum;
|
||||
mod event;
|
||||
|
||||
|
||||
@@ -527,6 +527,31 @@ impl Default for ScannerDataMovementPauseStatus {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
|
||||
pub struct PoolMetaWriteGateStatus {
|
||||
pub writes_ready: bool,
|
||||
pub write_blocked: bool,
|
||||
pub transaction_aborted: bool,
|
||||
pub pool_meta_absent: bool,
|
||||
pub identity_initialized: Option<bool>,
|
||||
pub identity_needs_repair: bool,
|
||||
pub cluster_epoch: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for PoolMetaWriteGateStatus {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
writes_ready: true,
|
||||
write_blocked: false,
|
||||
transaction_aborted: false,
|
||||
pool_meta_absent: false,
|
||||
identity_initialized: None,
|
||||
identity_needs_repair: false,
|
||||
cluster_epoch: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn offset_unix_seconds(value: OffsetDateTime) -> u64 {
|
||||
u64::try_from(value.unix_timestamp()).unwrap_or(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user