Repository: qdrant/qdrant
File: lib/collection/src/shards/local_shard/clock_map.rs (Rust)

Code before:
        };

        // Assume the state changed when the clock tag was accepted
        if is_accepted {
            self.changed = true;
        }

        (is_accepted, new_tick)
    }

    /// Take or clear a snapshot of clocks
    pub fn snapshot(&mut self, action: ClockMapSnapshot) {
        match action {
            ClockMapSnapshot::TakeIfMissing if self.snapshot.is_some() => {}
            ClockMapSnapshot::Clear if self.snapshot.is_none() => {}

            ClockMapSnapshot::TakeIfMissing => {
                self.snapshot.replace(self.clocks.clone());
                self.changed = true;
            }
            ClockMapSnapshot::Clear => {
                self.snapshot.take();
                self.changed = true;
            }
        }
    }

    /// Create a recovery point based on the current clock map state, so that we can recover any
    /// new operations with new clock values
    ///
    /// If `use_snapshot` is `true`, the recovery point is created from the clocks snapshot if it
    /// exists. Otherwise the current clocks are used.
    ///
    /// The recovery point contains every clock that is in this clock map. So, it represents all
    /// the clock ticks we have.
    pub fn to_recovery_point(&self, use_snapshot: bool) -> RecoveryPoint {
        let clocks = if use_snapshot {
            self.snapshot.as_ref().unwrap_or(&self.clocks)
        } else {
            &self.clocks
        };

        RecoveryPoint {
            clocks: clocks
                .iter()
                .map(|(&key, clock)| (key, (clock.current_tick, clock.token)))
                .collect(),
        }
    }

    #[cfg(test)]

Review comment (suggestion):
Tbh, I'd just make two separate methods: `take_snapshot` and `clear_snapshot`.

Makes two methods to propagate instead of one, but also removes `ClockMapSnapshot` fluff, so I think it comes up similar at the end, but more direct.

Code after:
        };

        // Assume the state changed when the clock tag was accepted
        if is_accepted {
            self.changed = true;
        }

        (is_accepted, new_tick)
    }

    /// Take a snapshot of clocks
    ///
    /// Does nothing if a snapshot already exists. Returns `true` if a snapshot was taken.
    pub fn take_snapshot(&mut self) -> bool {
        if self.snapshot.is_some() {
            return false;
        }

        self.snapshot.replace(self.clocks.clone());
        self.changed = true;
        true
    }

    /// Clear any snapshot of clocks
    ///
    /// Returns `true` if a snapshot was cleared.
    pub fn clear_snapshot(&mut self) -> bool {
        if self.snapshot.is_none() {
            return false;
        }

        self.snapshot.take();
        self.changed = true;
        true
    }

    /// Create a recovery point based on the current clock map state, so that we can recover any
    /// new operations with new clock values
    ///
    /// The recovery point will be derived from a clocks snapshot if it exists. Otherwise the
    /// current clocks are used.
    ///
    /// The recovery point contains every clock that is in this clock map. So, it represents all
    /// the clock ticks we have.
    pub fn to_recovery_point(&self) -> RecoveryPoint {
        let clocks = self.snapshot.as_ref().unwrap_or(&self.clocks);

        RecoveryPoint {
            clocks: clocks
                .iter()
                .map(|(&key, clock)| (key, (clock.current_tick, clock.token)))