Repository: qdrant/qdrant
File: lib/collection/src/update_handler.rs (Rust)

Code before:
    /// Persist the applied op_num sequence applied
    applied_seq_handler: Arc<AppliedSeqHandler>,
}

impl UpdateHandler {
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        collection_name: CollectionId,
        shared_storage_config: Arc<SharedStorageConfig>,
        payload_index_schema: Arc<SaveOnDisk<PayloadIndexSchema>>,
        optimizers: Arc<Vec<Arc<Optimizer>>>,
        optimizers_log: Arc<Mutex<TrackerLog>>,
        total_optimized_points: Arc<AtomicUsize>,
        optimizer_resource_budget: ResourceBudget,
        runtime_handle: Handle,
        segments: LockedSegmentHolder,
        wal: LockedWal,
        flush_interval_sec: u64,
        max_optimization_threads: Option<usize>,
        prevent_unoptimized_threshold_kb: Option<usize>,
        clocks: LocalShardClocks,
        shard_path: PathBuf,
        scroll_read_lock: Arc<tokio::sync::RwLock<()>>,
        update_tracker: UpdateTracker,
    ) -> CollectionResult<Self> {
        let applied_seq_handler = AppliedSeqHandler::load_or_init(&shard_path)?;
        Ok(UpdateHandler {
            collection_name,
            shared_storage_config,
            payload_index_schema,
            optimizers,
            segments,
            update_worker: None,
            optimizer_worker: None,
            optimizers_log,
            total_optimized_points,
            optimizer_resource_budget,
            flush_worker: None,
            flush_stop: None,
            runtime_handle,
            wal,
            wal_keep_from: Arc::new(u64::MAX.into()),
            flush_interval_sec,
            optimization_handles: Arc::new(TokioMutex::new(vec![])),
            max_optimization_threads,
            prevent_unoptimized_threshold_kb,
            clocks,
            shard_path,
            has_triggered_optimizers: Default::default(),
            scroll_read_lock,
            update_tracker,

Review comment (bug):
Would it make sense to handle load failures here?

If we cannot load from disk due to corrupted data, maybe we can force replay everything on restart. I'd be better than flat out crashing. Using that suggested `None` variant would probably be good here.

Code after:
    /// Persist the applied op_num sequence number
    applied_seq_handler: Arc<AppliedSeqHandler>,
}

impl UpdateHandler {
    #[allow(clippy::too_many_arguments)]
    pub async fn new(
        collection_name: CollectionId,
        shared_storage_config: Arc<SharedStorageConfig>,
        payload_index_schema: Arc<SaveOnDisk<PayloadIndexSchema>>,
        optimizers: Arc<Vec<Arc<Optimizer>>>,
        optimizers_log: Arc<Mutex<TrackerLog>>,
        total_optimized_points: Arc<AtomicUsize>,
        optimizer_resource_budget: ResourceBudget,
        runtime_handle: Handle,
        segments: LockedSegmentHolder,
        wal: LockedWal,
        flush_interval_sec: u64,
        max_optimization_threads: Option<usize>,
        prevent_unoptimized_threshold_kb: Option<usize>,
        clocks: LocalShardClocks,
        shard_path: PathBuf,
        scroll_read_lock: Arc<tokio::sync::RwLock<()>>,
        update_tracker: UpdateTracker,
        applied_seq_handler: Arc<AppliedSeqHandler>,
    ) -> Self {
        UpdateHandler {
            collection_name,
            shared_storage_config,
            payload_index_schema,
            optimizers,
            segments,
            update_worker: None,
            optimizer_worker: None,
            optimizers_log,
            total_optimized_points,
            optimizer_resource_budget,
            flush_worker: None,
            flush_stop: None,
            runtime_handle,
            wal,
            wal_keep_from: Arc::new(u64::MAX.into()),
            flush_interval_sec,
            optimization_handles: Arc::new(TokioMutex::new(vec![])),
            max_optimization_threads,
            prevent_unoptimized_threshold_kb,
            clocks,
            shard_path,
            has_triggered_optimizers: Default::default(),
            scroll_read_lock,
            update_tracker,