rustfs-scanner 1.0.0

RustFS Scanner provides scanning capabilities for data integrity checks, health monitoring, and storage analysis.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
// 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::collections::HashMap;
use std::sync::Arc;

#[cfg(test)]
use http::HeaderMap;
use rustfs_lock::NamespaceLockWrapper;
use serde::{Deserialize, Serialize};
use tokio::sync::Notify;

pub(crate) use s3s::dto::{
    BucketLifecycleConfiguration as EcstoreBucketLifecycleConfiguration, LifecycleRuleFilter as EcstoreLifecycleRuleFilter,
    ObjectLockConfiguration as EcstoreObjectLockConfiguration, VersioningConfiguration as EcstoreVersioningConfiguration,
};
#[cfg(test)]
pub(crate) use s3s::dto::{ExpirationStatus as EcstoreExpirationStatus, LifecycleRule as EcstoreLifecycleRule};

pub(crate) use rustfs_ecstore::api::data_usage::{
    MAX_SCANNER_PAUSE_BACKLOG_BYTES, ScannerPauseBacklogRetirementPlan, ScannerPauseBacklogRetirementReplica,
    register_scanner_pause_backlog_retirement_planner,
};
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::data_usage::{NativeScannerPauseBacklogWriteFault, SourceCleanupDeleteBarrier};

pub(crate) use rustfs_ecstore::api::bucket::bucket_target_sys::BucketTargetSys as EcstoreBucketTargetSys;
pub(crate) use rustfs_ecstore::api::bucket::lifecycle::bucket_lifecycle_audit::LcEventSrc as EcstoreLcEventSrc;
pub(crate) use rustfs_ecstore::api::bucket::lifecycle::bucket_lifecycle_ops::{
    apply_expiry_rule as ecstore_apply_expiry_rule, apply_transition_rule as ecstore_apply_transition_rule,
    lifecycle_version_delete_target as ecstore_lifecycle_version_delete_target,
};
pub(crate) use rustfs_ecstore::api::bucket::lifecycle::lifecycle::object_opts_from_object_info as ecstore_object_opts_from_object_info;
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::bucket::metadata_sys::init_bucket_metadata_sys as ecstore_init_bucket_metadata_sys;
pub(crate) use rustfs_ecstore::api::bucket::metadata_sys::{
    BucketMetadataMutationGuard as EcstoreBucketMetadataMutationGuard, get_lifecycle_config as ecstore_get_lifecycle_config,
    get_object_lock_config as ecstore_get_object_lock_config, get_replication_config as ecstore_get_replication_config,
};
pub(crate) use rustfs_ecstore::api::bucket::replication::{
    ReplicateObjectInfo, ReplicationConfig as EcstoreReplicationConfig,
    ReplicationConfigurationExt as EcstoreReplicationConfigurationExt,
    ReplicationHealQueueResult as EcstoreReplicationHealQueueResult,
    ReplicationQueueAdmission as EcstoreReplicationQueueAdmission, ReplicationScannerBridge as EcstoreReplicationScannerBridge,
    ReplicationType,
};
pub(crate) use rustfs_ecstore::api::bucket::replication::{ReplicationStatusType, VersionPurgeStatusType};
pub(crate) use rustfs_ecstore::api::bucket::target::BucketTargets as EcstoreBucketTargets;
pub(crate) use rustfs_ecstore::api::bucket::versioning::VersioningApi as EcstoreVersioningApi;
pub(crate) use rustfs_ecstore::api::bucket::versioning_sys::BucketVersioningSys as EcstoreBucketVersioningSys;
pub(crate) use rustfs_ecstore::api::cache::{
    ListPathRawOptions as EcstoreListPathRawOptions, list_path_raw as ecstore_list_path_raw,
};
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::capacity::PoolDecommissionInfo as EcstorePoolDecommissionInfo;
pub(crate) use rustfs_ecstore::api::capacity::{
    is_reserved_or_invalid_bucket as ecstore_is_reserved_or_invalid_bucket, path2_bucket_object as ecstore_path2_bucket_object,
    path2_bucket_object_with_base_path as ecstore_path2_bucket_object_with_base_path,
};
pub(crate) use rustfs_ecstore::api::config::com::{read_config as ecstore_read_config, save_config as ecstore_save_config};
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::config::init as ecstore_config_init;
pub(crate) use rustfs_ecstore::api::config::storageclass::{
    RRS as ECSTORE_STORAGECLASS_RRS, STANDARD as ECSTORE_STORAGECLASS_STANDARD,
};
pub(crate) use rustfs_ecstore::api::data_usage::{
    invalidate_admin_data_usage_snapshot_cache as ecstore_invalidate_admin_data_usage_snapshot_cache,
    invalidate_data_usage_snapshot_cache as ecstore_invalidate_data_usage_snapshot_cache,
    replace_bucket_usage_memory_from_info as ecstore_replace_bucket_usage_memory_from_info,
};
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::disk::endpoint::Endpoint as EcstoreEndpoint;
pub(crate) use rustfs_ecstore::api::disk::error::{DiskError as EcstoreDiskError, Result as EcstoreDiskResult};
pub(crate) use rustfs_ecstore::api::disk::{
    BUCKET_META_PREFIX as ECSTORE_BUCKET_META_PREFIX, Bytes as EcstoreDiskBytes, Disk as EcstoreDisk, DiskAPI as EcstoreDiskAPI,
    DiskInfo as EcstoreDiskInfo, DiskInfoOptions as EcstoreDiskInfoOptions, DiskLocation as EcstoreDiskLocation,
    NsScannerOpenRequest as EcstoreNsScannerOpenRequest, RUSTFS_META_BUCKET as ECSTORE_RUSTFS_META_BUCKET,
    STORAGE_FORMAT_FILE as ECSTORE_STORAGE_FORMAT_FILE, ScanGuard as EcstoreScanGuard,
};
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::disk::{
    DiskOption as EcstoreDiskOption, DiskStore as EcstoreDiskStore, new_disk as ecstore_new_disk,
};
pub(crate) use rustfs_ecstore::api::error::{
    Error as EcstoreErrorType, Result as EcstoreResultType, StorageError as EcstoreStorageError,
};
pub(crate) use rustfs_ecstore::api::event::{EventArgs as EcstoreEventArgs, send_event as ecstore_send_event};
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::layout::{
    EndpointServerPools as EcstoreEndpointServerPools, Endpoints as EcstoreEndpoints, PoolEndpoints as EcstorePoolEndpoints,
};
pub(crate) use rustfs_ecstore::api::notification::NotificationSys as EcstoreNotificationSys;
pub(crate) use rustfs_ecstore::api::notification::scanner_peer_transport_error_message_is_retryable;
pub(crate) use rustfs_ecstore::api::object::{
    SCANNER_PUBLICATION_LEASE_FENCE_METADATA_KEY, ScannerPublicationCommitScope, ScannerPublicationCommitState,
};
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::rebalance::{
    RebalStatus as EcstoreRebalStatus, RebalanceInfo as EcstoreRebalanceInfo, RebalanceMeta as EcstoreRebalanceMeta,
    RebalanceStats as EcstoreRebalanceStats,
};
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::rpc::ScannerPeerDirtyUsageBucket as EcstoreScannerPeerDirtyUsageBucket;
pub(crate) use rustfs_ecstore::api::rpc::{
    ScannerBucketListing as EcstoreScannerBucketListing,
    ScannerDirtyUsageAcknowledgement as EcstoreScannerDirtyUsageAcknowledgement,
    ScannerPeerDirtyUsageSnapshot as EcstoreScannerPeerDirtyUsageSnapshot,
    ScannerScopedDirtyUsageAckEntry as EcstoreScannerScopedDirtyUsageAckEntry,
};
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::runtime::InstanceContext as EcstoreInstanceContext;
pub(crate) use rustfs_ecstore::api::runtime::{
    expiry_state_handle as ecstore_expiry_state_handle, global_tier_config_mgr as ecstore_get_global_tier_config_mgr,
    object_store_handle as ecstore_resolve_object_store_handle, setup_is_erasure as ecstore_is_erasure,
};
pub(crate) use rustfs_ecstore::api::set_disk::SetDisks as EcstoreSetDisks;
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::storage::SCANNER_PUBLICATION_LEASE_TTL_MS as ECSTORE_SCANNER_PUBLICATION_LEASE_TTL_MS;
#[cfg(test)]
pub(crate) use rustfs_ecstore::api::storage::init_local_disks_with_instance_ctx as ecstore_init_local_disks_with_instance_ctx;
pub(crate) use rustfs_ecstore::api::storage::{
    ECStore as EcstoreStore, ScannerDataMovementPauseStatus as EcstoreScannerDataMovementPauseStatus,
};
pub(crate) use rustfs_lifecycle::{
    Evaluator as EcstoreEvaluator, Event as EcstoreEvent, Lifecycle as EcstoreLifecycle, ObjectOpts as EcstoreObjectOpts,
    TRANSITION_COMPLETE as ECSTORE_TRANSITION_COMPLETE,
};
use rustfs_storage_api as storage_contracts;

#[cfg(test)]
pub(crate) type EcstoreHealResultItem = <EcstoreStore as storage_contracts::HealOperations>::HealResultItem;

pub(crate) mod owner {
    pub(crate) use super::{
        MAX_SCANNER_PAUSE_BACKLOG_BYTES, ScannerPauseBacklogRetirementPlan, ScannerPauseBacklogRetirementReplica,
        register_scanner_pause_backlog_retirement_planner,
    };
    #[cfg(test)]
    pub(crate) use super::{NativeScannerPauseBacklogWriteFault, SourceCleanupDeleteBarrier};

    #[cfg(test)]
    pub(crate) use rustfs_ecstore::api::set_disk::test_util::hold_namespace_commit as ecstore_hold_namespace_commit;

    pub(crate) use super::storage_contracts::{
        HTTPPreconditions, HTTPRangeSpec, NS_SCANNER_PROTOCOL_VERSION, ObjectIO, ObjectOperations, ObjectToDelete,
    };

    pub(crate) use super::{
        ECSTORE_BUCKET_META_PREFIX, ECSTORE_RUSTFS_META_BUCKET, ECSTORE_STORAGE_FORMAT_FILE, ECSTORE_STORAGECLASS_RRS,
        ECSTORE_STORAGECLASS_STANDARD, ECSTORE_TRANSITION_COMPLETE, EcstoreBucketLifecycleConfiguration, EcstoreBucketTargetSys,
        EcstoreBucketVersioningSys, EcstoreDisk, EcstoreDiskAPI, EcstoreDiskBytes, EcstoreDiskError, EcstoreDiskInfo,
        EcstoreDiskInfoOptions, EcstoreDiskLocation, EcstoreDiskResult, EcstoreErrorType, EcstoreEvaluator, EcstoreEvent,
        EcstoreEventArgs, EcstoreLcEventSrc, EcstoreLifecycle, EcstoreLifecycleRuleFilter, EcstoreListPathRawOptions,
        EcstoreNsScannerOpenRequest, EcstoreObjectLockConfiguration, EcstoreObjectOpts, EcstoreReplicationConfigurationExt,
        EcstoreReplicationScannerBridge, EcstoreResultType, EcstoreScanGuard, EcstoreSetDisks, EcstoreStorageError, EcstoreStore,
        EcstoreVersioningApi, EcstoreVersioningConfiguration, SCANNER_PUBLICATION_LEASE_FENCE_METADATA_KEY,
        ScannerPublicationCommitScope, ScannerPublicationCommitState, ScannerReplicationHealObject, ScannerReplicationHealResult,
        ScannerReplicationQueueAdmission, ecstore_apply_expiry_rule, ecstore_apply_transition_rule, ecstore_expiry_state_handle,
        ecstore_get_global_tier_config_mgr, ecstore_get_lifecycle_config, ecstore_get_object_lock_config,
        ecstore_get_replication_config, ecstore_invalidate_admin_data_usage_snapshot_cache,
        ecstore_invalidate_data_usage_snapshot_cache, ecstore_is_erasure, ecstore_is_reserved_or_invalid_bucket,
        ecstore_lifecycle_version_delete_target, ecstore_list_path_raw, ecstore_object_opts_from_object_info,
        ecstore_path2_bucket_object, ecstore_path2_bucket_object_with_base_path, ecstore_read_config,
        ecstore_replace_bucket_usage_memory_from_info, ecstore_resolve_object_store_handle, ecstore_save_config,
        ecstore_send_event, scanner_replication_config_for_lifecycle_eval,
    };

    #[cfg(test)]
    pub(crate) use super::{
        EcstoreDiskOption, EcstoreDiskStore, EcstoreEndpoint, EcstoreEndpointServerPools, EcstoreEndpoints,
        EcstoreExpirationStatus, EcstoreInstanceContext, EcstoreLifecycleRule, EcstorePoolDecommissionInfo, EcstorePoolEndpoints,
        EcstoreRebalStatus, EcstoreRebalanceInfo, EcstoreRebalanceMeta, EcstoreRebalanceStats, ecstore_config_init,
        ecstore_init_bucket_metadata_sys, ecstore_init_local_disks_with_instance_ctx, ecstore_new_disk,
    };
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ScannerReplicationConfig(EcstoreReplicationConfig);

impl ScannerReplicationConfig {
    pub(crate) fn new(config: Option<s3s::dto::ReplicationConfiguration>, remotes: Option<EcstoreBucketTargets>) -> Self {
        Self(EcstoreReplicationConfig::new(config, remotes))
    }

    pub(crate) fn has_active_rules(&self, prefix: &str, recursive: bool) -> bool {
        !self.0.is_empty()
            && self
                .0
                .config
                .as_ref()
                .is_some_and(|config| EcstoreReplicationConfigurationExt::has_active_rules(config, prefix, recursive))
    }

    pub(crate) fn into_ecstore(self) -> EcstoreReplicationConfig {
        self.0
    }
}

pub(crate) fn scanner_replication_config_for_lifecycle_eval(
    config: Option<Arc<ScannerReplicationConfig>>,
) -> Option<Arc<EcstoreReplicationConfig>> {
    config.map(|config| match Arc::try_unwrap(config) {
        Ok(config) => Arc::new(config.into_ecstore()),
        Err(config) => Arc::new(config.0.clone()),
    })
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(crate) enum ScannerReplicationQueueAdmission {
    #[default]
    Skipped,
    Queued,
    Missed,
}

impl From<EcstoreReplicationQueueAdmission> for ScannerReplicationQueueAdmission {
    fn from(admission: EcstoreReplicationQueueAdmission) -> Self {
        match admission {
            EcstoreReplicationQueueAdmission::Skipped => Self::Skipped,
            EcstoreReplicationQueueAdmission::Queued => Self::Queued,
            EcstoreReplicationQueueAdmission::Missed => Self::Missed,
        }
    }
}

#[derive(Debug, Clone, Default)]
pub(crate) struct ScannerReplicationHealObject {
    pub(crate) bucket: String,
    pub(crate) name: String,
    pub(crate) size: i64,
    pub(crate) delete_marker: bool,
    pub(crate) target_statuses: HashMap<String, ReplicationStatusType>,
    version_purge_status: VersionPurgeStatusType,
    existing_object: bool,
    existing_object_resync: bool,
}

impl ScannerReplicationHealObject {
    #[cfg(test)]
    pub(crate) fn new(bucket: impl Into<String>, name: impl Into<String>) -> Self {
        Self {
            bucket: bucket.into(),
            name: name.into(),
            ..Default::default()
        }
    }

    pub(crate) fn is_empty_identity(&self) -> bool {
        self.bucket.is_empty() && self.name.is_empty()
    }

    pub(crate) fn is_existing_object_repair(&self) -> bool {
        self.existing_object || self.existing_object_resync
    }

    pub(crate) fn has_version_purge_status(&self) -> bool {
        !self.version_purge_status.is_empty()
    }

    #[cfg(test)]
    pub(crate) fn with_delete_marker(mut self) -> Self {
        self.delete_marker = true;
        self
    }

    #[cfg(test)]
    pub(crate) fn with_pending_version_purge(mut self) -> Self {
        self.version_purge_status = VersionPurgeStatusType::Pending;
        self
    }

    #[cfg(test)]
    pub(crate) fn with_existing_object(mut self) -> Self {
        self.existing_object = true;
        self
    }

    #[cfg(test)]
    pub(crate) fn with_existing_object_resync(mut self) -> Self {
        self.existing_object_resync = true;
        self
    }
}

impl From<ReplicateObjectInfo> for ScannerReplicationHealObject {
    fn from(object: ReplicateObjectInfo) -> Self {
        Self {
            bucket: object.bucket,
            name: object.name,
            size: object.size,
            delete_marker: object.delete_marker,
            target_statuses: object.target_statuses,
            version_purge_status: object.version_purge_status,
            existing_object: object.op_type == ReplicationType::ExistingObject,
            existing_object_resync: object.existing_obj_resync.must_resync(),
        }
    }
}

#[derive(Debug, Clone, Default)]
pub(crate) struct ScannerReplicationHealResult {
    pub(crate) object_info: ScannerReplicationHealObject,
    pub(crate) admission: ScannerReplicationQueueAdmission,
}

impl From<EcstoreReplicationHealQueueResult> for ScannerReplicationHealResult {
    fn from(result: EcstoreReplicationHealQueueResult) -> Self {
        Self {
            object_info: result.object_info.into(),
            admission: result.admission.into(),
        }
    }
}

pub(crate) mod scan {
    #[cfg(test)]
    pub(crate) use super::storage_contracts::BucketOperations;
    pub(crate) use super::storage_contracts::{
        BucketOptions, NamespaceLocking, SCANNER_ACTIVITY_LEGACY_PROTOCOL_VERSION, SCANNER_ACTIVITY_PREVIOUS_PROTOCOL_VERSION,
    };
    #[cfg(test)]
    pub(crate) use super::storage_contracts::{DeleteBucketOptions, MakeBucketOptions, ObjectIO};
    pub use super::storage_contracts::{
        SCANNER_ACTIVITY_PROTOCOL_VERSION, SCANNER_ACTIVITY_V6_PROTOCOL_VERSION, SCANNER_DIRTY_USAGE_SNAPSHOT_MAX_ENTRIES,
        SCANNER_DIRTY_USAGE_SNAPSHOT_PROTOCOL_VERSION, SCANNER_DIRTY_USAGE_SNAPSHOT_RPC_MAX_MESSAGE_SIZE,
        SCANNER_SCOPED_DIRTY_USAGE_ACK_MAX_ENTRIES,
    };
}

pub(crate) mod scanner_io {
    pub(crate) use super::storage_contracts::{BucketInfo, BucketOptions};
    #[cfg(test)]
    pub(crate) use super::storage_contracts::{HTTPRangeSpec, ObjectIO};
}

pub(crate) type ScannerBucketListing = EcstoreScannerBucketListing;
pub(crate) type ScannerDataMovementPauseStatus = EcstoreScannerDataMovementPauseStatus;
pub(crate) type ScannerNotificationSys = EcstoreNotificationSys;

#[async_trait::async_trait]
pub(crate) trait ScannerStorage:
    crate::ScannerObjectIO
    + crate::ScannerConfigObjectDelete
    + storage_contracts::BucketOperations<Error = EcstoreErrorType>
    + storage_contracts::NamespaceLocking<Error = EcstoreErrorType, NamespaceLock = NamespaceLockWrapper>
{
    fn scanner_topology_digest(&self) -> [u8; 32];
    fn scanner_namespace_mutation_generation(&self) -> u64;
    async fn scanner_data_movement_activity(&self) -> (bool, bool, u64);
    async fn scanner_data_usage_publication_blocked(&self) -> bool;
    async fn scanner_data_movement_pause_status(&self) -> ScannerDataMovementPauseStatus;
    fn scanner_data_movement_generation(&self) -> u64;
    fn scanner_data_movement_changed(&self) -> Arc<Notify>;
    fn scanner_notification_system(&self) -> Option<Arc<ScannerNotificationSys>>;
    async fn setup_is_erasure(&self) -> bool;
    async fn setup_is_dist_erasure(&self) -> bool;
    async fn setup_is_erasure_sd(&self) -> bool;
    async fn list_bucket_for_scanner(&self, opts: &storage_contracts::BucketOptions) -> EcstoreResultType<ScannerBucketListing>;
    fn all_set_disks(&self) -> Vec<Arc<EcstoreSetDisks>>;
    async fn scanner_pause_backlog_writable_set_disks(&self) -> Vec<Arc<EcstoreSetDisks>>;
    async fn save_scanner_pause_backlog_replica(
        self: Arc<Self>,
        pool_index: usize,
        set_index: usize,
        data: Vec<u8>,
        preconditions: storage_contracts::HTTPPreconditions,
    ) -> EcstoreResultType<()>;
    #[cfg(test)]
    fn scanner_observed_probe_store_key(&self) -> usize;
}

#[async_trait::async_trait]
impl ScannerStorage for EcstoreStore {
    fn scanner_topology_digest(&self) -> [u8; 32] {
        crate::scanner::scanner_topology_digest(self)
    }

    fn scanner_namespace_mutation_generation(&self) -> u64 {
        EcstoreStore::scanner_namespace_mutation_generation(self)
    }

    async fn scanner_data_movement_activity(&self) -> (bool, bool, u64) {
        EcstoreStore::scanner_data_movement_activity(self).await
    }

    async fn scanner_data_usage_publication_blocked(&self) -> bool {
        EcstoreStore::scanner_data_usage_publication_blocked(self).await
    }

    async fn scanner_data_movement_pause_status(&self) -> ScannerDataMovementPauseStatus {
        EcstoreStore::scanner_data_movement_pause_status(self).await
    }

    fn scanner_data_movement_generation(&self) -> u64 {
        EcstoreStore::scanner_data_movement_generation(self)
    }

    fn scanner_data_movement_changed(&self) -> Arc<Notify> {
        EcstoreStore::scanner_data_movement_changed(self)
    }

    fn scanner_notification_system(&self) -> Option<Arc<ScannerNotificationSys>> {
        EcstoreStore::notification_system(self)
    }

    async fn setup_is_erasure(&self) -> bool {
        EcstoreStore::setup_is_erasure(self).await
    }

    async fn setup_is_dist_erasure(&self) -> bool {
        EcstoreStore::setup_is_dist_erasure(self).await
    }

    async fn setup_is_erasure_sd(&self) -> bool {
        EcstoreStore::setup_is_erasure_sd(self).await
    }

    async fn list_bucket_for_scanner(&self, opts: &storage_contracts::BucketOptions) -> EcstoreResultType<ScannerBucketListing> {
        EcstoreStore::list_bucket_for_scanner(self, opts).await
    }

    fn all_set_disks(&self) -> Vec<Arc<EcstoreSetDisks>> {
        EcstoreStore::all_set_disks(self)
    }

    async fn scanner_pause_backlog_writable_set_disks(&self) -> Vec<Arc<EcstoreSetDisks>> {
        EcstoreStore::scanner_pause_backlog_writable_set_disks(self).await
    }

    async fn save_scanner_pause_backlog_replica(
        self: Arc<Self>,
        pool_index: usize,
        set_index: usize,
        data: Vec<u8>,
        preconditions: storage_contracts::HTTPPreconditions,
    ) -> EcstoreResultType<()> {
        EcstoreStore::save_scanner_pause_backlog_replica(&self, pool_index, set_index, data, preconditions)
            .await
            .map(|_| ())
    }

    #[cfg(test)]
    fn scanner_observed_probe_store_key(&self) -> usize {
        std::ptr::from_ref(self).cast::<()>() as usize
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[derive(Debug, Default)]
    struct FakeScannerStorage;

    #[async_trait::async_trait]
    impl storage_contracts::ObjectIO for FakeScannerStorage {
        type Error = EcstoreErrorType;
        type RangeSpec = storage_contracts::HTTPRangeSpec;
        type HeaderMap = HeaderMap;
        type ObjectOptions = <EcstoreStore as storage_contracts::ObjectIO>::ObjectOptions;
        type ObjectInfo = <EcstoreStore as storage_contracts::ObjectIO>::ObjectInfo;
        type GetObjectReader = <EcstoreStore as storage_contracts::ObjectIO>::GetObjectReader;
        type PutObjectReader = <EcstoreStore as storage_contracts::ObjectIO>::PutObjectReader;

        async fn get_object_reader(
            &self,
            _bucket: &str,
            _object: &str,
            _range: Option<Self::RangeSpec>,
            _h: Self::HeaderMap,
            _opts: &Self::ObjectOptions,
        ) -> Result<Self::GetObjectReader, Self::Error> {
            Err(EcstoreErrorType::other("fake scanner storage has no object reader"))
        }

        async fn put_object(
            &self,
            _bucket: &str,
            _object: &str,
            _data: &mut Self::PutObjectReader,
            _opts: &Self::ObjectOptions,
        ) -> Result<Self::ObjectInfo, Self::Error> {
            Err(EcstoreErrorType::other("fake scanner storage has no object writer"))
        }
    }

    #[async_trait::async_trait]
    impl storage_contracts::BucketOperations for FakeScannerStorage {
        type Error = EcstoreErrorType;

        async fn make_bucket(&self, _bucket: &str, _opts: &storage_contracts::MakeBucketOptions) -> Result<(), Self::Error> {
            Err(EcstoreErrorType::other("fake scanner storage cannot make buckets"))
        }

        async fn get_bucket_info(
            &self,
            _bucket: &str,
            _opts: &storage_contracts::BucketOptions,
        ) -> Result<storage_contracts::BucketInfo, Self::Error> {
            Err(EcstoreErrorType::other("fake scanner storage cannot read buckets"))
        }

        async fn list_bucket(
            &self,
            _opts: &storage_contracts::BucketOptions,
        ) -> Result<Vec<storage_contracts::BucketInfo>, Self::Error> {
            Ok(Vec::new())
        }

        async fn delete_bucket(&self, _bucket: &str, _opts: &storage_contracts::DeleteBucketOptions) -> Result<(), Self::Error> {
            Err(EcstoreErrorType::other("fake scanner storage cannot delete buckets"))
        }
    }

    #[async_trait::async_trait]
    impl storage_contracts::NamespaceLocking for FakeScannerStorage {
        type Error = EcstoreErrorType;
        type NamespaceLock = NamespaceLockWrapper;

        async fn new_ns_lock(&self, _bucket: &str, _object: &str) -> Result<Self::NamespaceLock, Self::Error> {
            Err(EcstoreErrorType::other("fake scanner storage has no namespace lock"))
        }
    }

    #[async_trait::async_trait]
    impl crate::ScannerConfigObjectDelete for FakeScannerStorage {
        async fn delete_config_object(
            &self,
            _bucket: &str,
            _object: &str,
            _opts: <EcstoreStore as storage_contracts::ObjectIO>::ObjectOptions,
        ) -> EcstoreResultType<<EcstoreStore as storage_contracts::ObjectIO>::ObjectInfo> {
            Err(EcstoreErrorType::other("fake scanner storage cannot delete objects"))
        }

        async fn scanner_data_usage_publication_admission(&self) -> Option<crate::ScannerDataUsagePublicationAdmission> {
            Some(crate::ScannerDataUsagePublicationAdmission::unfenced())
        }
    }

    #[async_trait::async_trait]
    impl ScannerStorage for FakeScannerStorage {
        fn scanner_topology_digest(&self) -> [u8; 32] {
            [0; 32]
        }

        fn scanner_namespace_mutation_generation(&self) -> u64 {
            0
        }

        async fn scanner_data_movement_activity(&self) -> (bool, bool, u64) {
            (false, false, 0)
        }

        async fn scanner_data_usage_publication_blocked(&self) -> bool {
            false
        }

        async fn scanner_data_movement_pause_status(&self) -> ScannerDataMovementPauseStatus {
            ScannerDataMovementPauseStatus::default()
        }

        fn scanner_data_movement_generation(&self) -> u64 {
            0
        }

        fn scanner_data_movement_changed(&self) -> Arc<Notify> {
            Arc::new(Notify::new())
        }

        fn scanner_notification_system(&self) -> Option<Arc<ScannerNotificationSys>> {
            None
        }

        async fn setup_is_erasure(&self) -> bool {
            false
        }

        async fn setup_is_dist_erasure(&self) -> bool {
            false
        }

        async fn setup_is_erasure_sd(&self) -> bool {
            true
        }

        async fn list_bucket_for_scanner(
            &self,
            _opts: &storage_contracts::BucketOptions,
        ) -> EcstoreResultType<ScannerBucketListing> {
            Err(EcstoreErrorType::other("fake scanner storage cannot list scanner buckets"))
        }

        fn all_set_disks(&self) -> Vec<Arc<EcstoreSetDisks>> {
            Vec::new()
        }

        async fn scanner_pause_backlog_writable_set_disks(&self) -> Vec<Arc<EcstoreSetDisks>> {
            Vec::new()
        }

        async fn save_scanner_pause_backlog_replica(
            self: Arc<Self>,
            _pool_index: usize,
            _set_index: usize,
            _data: Vec<u8>,
            _preconditions: storage_contracts::HTTPPreconditions,
        ) -> EcstoreResultType<()> {
            Err(EcstoreErrorType::InvalidArgument(
                "scanner-backlog".into(),
                "replica".into(),
                "fake storage has no writable replicas".into(),
            ))
        }

        fn scanner_observed_probe_store_key(&self) -> usize {
            0
        }
    }

    fn assert_scanner_storage<S: ScannerStorage>() {}

    #[test]
    fn scanner_storage_contract_accepts_fake_without_ecstore() {
        assert_scanner_storage::<FakeScannerStorage>();
    }
}