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 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,
    ) -> Self {
        let wal_first_index = wal.lock().await.first_index();
        let applied_seq_handler = AppliedSeqHandler::load_or_init(&shard_path, wal_first_index);
        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,

Review comment (suggestion):
Needed to make the function async to lock the WAL because the `blocking_lock` caused

```
Panic occurred in file lib/collection/src/update_handler.rs at line 158: Cannot block the current thread from within a runtime. This happens because a function attempted to block the current thread while the thread is being used to drive asynchronous tasks.
```

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,