fn mark_interval(&self, whence: Lsn, len: usize) {
        debug!("mark_interval({}, {})", whence, len);
        assert!(
            len > 0,
            "mark_interval called with an empty length at {}",
            whence
        );
        let mut intervals = self.intervals.lock();

        let interval = (whence, whence + len as Lsn - 1);

        intervals.push(interval);

        #[cfg(any(test, feature = "event_log", feature = "lock_free_delays"))]
        assert!(
            intervals.len() < 10000,
            "intervals is getting strangely long... {:?}",
            *intervals
        );

        // reverse sort
        intervals.sort_unstable_by(|a, b| b.cmp(a));

        let mut updated = false;

        let len_before = intervals.len();

        while let Some(&(low, high)) = intervals.last() {
            assert!(low <= high);
            let cur_stable = self.stable_lsn.load(SeqCst);
            assert!(
                low > cur_stable,
                "somehow, we marked offset {} stable while \
                 interval {}-{} had not yet been applied!",
                cur_stable,
                low,
                high
            );
            if cur_stable + 1 == low {
                let old = self.stable_lsn.swap(high, SeqCst);
                assert_eq!(
                    old, cur_stable,
                    "concurrent stable offset modification detected"
                );
                debug!("new highest interval: {} - {}", low, high);
                let (_low, _high) = intervals.pop().unwrap();
                updated = true;
            } else {
                break;
            }
        }

        if len_before - intervals.len() > 100 {
            debug!("large merge of {} intervals", len_before - intervals.len());
        }

        if updated {
            // having held the mutex makes this linearized
            // with the notify below.
            drop(intervals);

            let _notified = self.interval_updated.notify_all();
        }
    }
// It's possible that IO buffers are written out of order!
// So we need to use this to keep track of them, and only
// increment self.stable. If we didn't do this, then we would
// accidentally decrement self.stable sometimes, or bump stable
// above an offset that corresponds to a buffer that hasn't actually
// been written yet! It's OK to use a mutex here because it is pretty
// fast, compared to the other operations on shared state.
It's possible that IO buffers are written out of order.
So we need to use this to keep track of them, and only
increment self.stable. If we didn't do this, then we would
accidentally decrement self.stable sometimes, or bump stable
above an offset that corresponds to a buffer that hasn't actually
been written yet. It's OK to use a mutex here because it is pretty
fast, compared to the other operations on shared state.
It ' s possible that IO buffers are written out of order . So we need to use this to keep track of them and only increment self . stable . If we didn ' t do this then we would accidentally decrement self . stable sometimes or bump stable above an offset that corresponds to a buffer that hasn ' t actually been written yet . It ' s OK to use a mutex here because it is pretty fast compared to the other operations on shared state .
fn mark_interval(&self, whence: Lsn, len: usize) {
        debug!("mark_interval({}, {})", whence, len);
        assert!(
            len > 0,
            "mark_interval called with an empty length at {}",
            whence
        );
        let mut intervals = self.intervals.lock();
        let interval = (whence, whence + len as Lsn - 1);
        intervals.push(interval);
        #[cfg(any(test, feature = "event_log", feature = "lock_free_delays"))]
        assert!(
            intervals.len() < 10000,
            "intervals is getting strangely long... {:?}",
            *intervals
        );
        // reverse sort
        intervals.sort_unstable_by(|a, b| b.cmp(a));
        let mut updated = false;
        let len_before = intervals.len();
        while let Some(&(low, high)) = intervals.last() {
            assert!(low <= high);
            let cur_stable = self.stable_lsn.load(SeqCst);
            assert!(
                low > cur_stable,
                "somehow, we marked offset {} stable while \
                 interval {}-{} had not yet been applied!",
                cur_stable,
                low,
                high
            );
            if cur_stable + 1 == low {
                let old = self.stable_lsn.swap(high, SeqCst);
                assert_eq!(
                    old, cur_stable,
                    "concurrent stable offset modification detected"
                );
                debug!("new highest interval: {} - {}", low, high);
                let (_low, _high) = intervals.pop().unwrap();
                updated = true;
            } else {
                break;
            }
        }
        if len_before - intervals.len() > 100 {
            debug!("large merge of {} intervals", len_before - intervals.len());
        }
        if updated {
            // having held the mutex makes this linearized
            // with the notify below.
            drop(intervals);
            let _notified = self.interval_updated.notify_all();
        }
    }
fn mark_interval ( & self , whence : Lsn , len : usize ) { debug ! ( " " whence len ) ; assert ! ( len 0 " " whence ) ; let mut intervals = self . intervals . lock ( ) ; let interval = ( whence , whence + len as Lsn - 1 ) ; intervals . push ( interval ) ; # [ cfg ( any ( test feature " " feature " " ) ) ] assert ! ( intervals len ( ) 10000 " " intervals ) ; // reverse sort intervals . sort_unstable_by ( | a , b | b . cmp ( a ) ) ; let mut updated = false ; let len_before = intervals . len ( ) ; while let Some ( & ( low , high ) ) = intervals . last ( ) { assert ! ( low high ) ; let cur_stable = self . stable_lsn . load ( SeqCst ) ; assert ! ( low cur_stable " \
 " cur_stable low high ) ; if cur_stable + 1 == low { let old = self . stable_lsn . swap ( high , SeqCst ) ; assert_eq ! ( old cur_stable " " ) ; debug ! ( " " low high ) ; let ( _low , _high ) = intervals . pop ( ) . unwrap ( ) ; updated = true ; } else { break ; } } if len_before - intervals . len ( ) > 100 { debug ! ( " " len_before intervals len ( ) ) ; } if updated { // having held the mutex makes this linearized // with the notify below. drop ( intervals ) ; let _notified = self . interval_updated . notify_all ( ) ; } }
It's possible that IO buffers are written out of order!
It ' s possible that IO buffers are written out of order!
&self
whence
Lsn
len
usize