tglman / persy

@@ -169,7 +169,7 @@
Loading
169 169
    pub fn insert_after(&mut self, pos: usize, values: &mut Vec<(K, NodeRef)>) {
170 170
        values.reverse();
171 171
        for (key, node) in values.iter() {
172 -
            self.add(pos, &key, node.clone());
172 +
            self.add(pos, key, node.clone());
173 173
        }
174 174
    }
175 175
@@ -220,8 +220,8 @@
Loading
220 220
221 221
    #[allow(dead_code)]
222 222
    pub fn merge_left(&mut self, owner: K, nodes: &mut Nodes<K>) {
223 -
        let mut keys = std::mem::replace(&mut nodes.keys, Vec::new());
224 -
        let mut pointers = std::mem::replace(&mut nodes.pointers, Vec::new());
223 +
        let mut keys = std::mem::take(&mut nodes.keys);
224 +
        let mut pointers = std::mem::take(&mut nodes.pointers);
225 225
        keys.push(owner);
226 226
        keys.append(&mut self.keys);
227 227
        pointers.append(&mut self.pointers);
@@ -308,7 +308,7 @@
Loading
308 308
309 309
    #[allow(dead_code)]
310 310
    pub fn merge_left(&mut self, leaf: &mut Leaf<K, V>) {
311 -
        let mut entries = std::mem::replace(&mut leaf.entries, Vec::new());
311 +
        let mut entries = std::mem::take(&mut leaf.entries);
312 312
        entries.append(&mut self.entries);
313 313
        self.entries = entries;
314 314
    }

@@ -342,7 +342,7 @@
Loading
342 342
                return Err(CreateSegmentError::SegmentAlreadyExists);
343 343
            }
344 344
            TxSegCheck::None => {
345 -
                if self.address.exists_segment(&segment)? {
345 +
                if self.address.exists_segment(segment)? {
346 346
                    return Err(CreateSegmentError::SegmentAlreadyExists);
347 347
                }
348 348
            }
@@ -511,7 +511,7 @@
Loading
511 511
        self.read_page_fn(match_id, page, |x| Vec::from(x))
512 512
    }
513 513
514 -
    fn read_page_fn<T>(&self, match_id: &RecRef, page: u64, f: fn(&[u8]) -> T) -> PERes<Option<T>> {
514 +
    fn read_page_fn<T, F: Fn(&[u8]) -> T>(&self, match_id: &RecRef, page: u64, f: F) -> PERes<Option<T>> {
515 515
        if let Some(mut pg) = self.allocator.load_page_not_free(page)? {
516 516
            let (len, id) = PersyImpl::read_record_metadata(&mut pg);
517 517
            if id.page == match_id.page && id.pos == match_id.pos {
@@ -694,11 +694,11 @@
Loading
694 694
            let allocator = &self.allocator;
695 695
            let journal = &self.journal;
696 696
            let len = rec.len();
697 -
            let metadata = PersyImpl::write_record_metadata(len as u64, &rec_ref);
697 +
            let metadata = PersyImpl::write_record_metadata(len as u64, rec_ref);
698 698
            let allocation_exp = exp_from_content_size((len + metadata.len()) as u64);
699 699
            let mut pg = allocator.allocate(allocation_exp)?;
700 700
            let page = pg.get_index();
701 -
            tx.add_update(journal, segment, &rec_ref, page, version)?;
701 +
            tx.add_update(journal, segment, rec_ref, page, version)?;
702 702
            pg.write_all(&metadata);
703 703
            pg.write_all(rec);
704 704
            Ok(allocator.flush_page(pg)?)
@@ -709,7 +709,7 @@
Loading
709 709
710 710
    pub fn delete(&self, tx: &mut TransactionImpl, segment: SegmentId, rec_ref: &RecRef) -> Result<(), DeleteError> {
711 711
        if let Some((_, version, seg)) = self.read_ref_segment(tx, segment, rec_ref)? {
712 -
            Ok(tx.add_delete(&self.journal, seg, &rec_ref, version)?)
712 +
            Ok(tx.add_delete(&self.journal, seg, rec_ref, version)?)
713 713
        } else {
714 714
            Err(DeleteError::RecordNotFound(PersyId(rec_ref.clone())))
715 715
        }

@@ -357,7 +357,7 @@
Loading
357 357
    {
358 358
        self.indexex_changes
359 359
            .get(&index)
360 -
            .map(|ref o| get_changes(&o.0, k).map(|c| resolve_values(&o.1, c)))
360 +
            .map(|o| get_changes(&o.0, k).map(|c| resolve_values(&o.1, c)))
361 361
            .and_then(std::convert::identity)
362 362
    }
363 363
@@ -437,8 +437,8 @@
Loading
437 437
    }
438 438
439 439
    pub fn apply(&self, persy: &PersyImpl, tx: &mut TransactionImpl) -> PIRes<()> {
440 -
        for (index, values) in &self.indexex_changes {
441 -
            eapplier(&values.0, &values.1, &index, persy, tx)?;
440 +
        for (index, (keys, values)) in &self.indexex_changes {
441 +
            eapplier(keys, values, index, persy, tx)?;
442 442
        }
443 443
        Ok(())
444 444
    }
@@ -524,7 +524,7 @@
Loading
524 524
    fn load(&self, node: &NodeRef) -> PERes<Node<K, V>> {
525 525
        let rec = self
526 526
            .store
527 -
            .read_snap_fn(self.segment, &node, self.snapshot, |x| deserialize(x))
527 +
            .read_snap_fn(self.segment, node, self.snapshot, |x| deserialize(x))
528 528
            .map_err(map_read_err)?
529 529
            .unwrap()?;
530 530
        Ok(rec)
@@ -592,7 +592,7 @@
Loading
592 592
        let segment = index_id_to_segment_id_data(&self.index_id);
593 593
        if let Some(m) = &self.changed {
594 594
            for (node_ref, node) in m {
595 -
                self.store.update(self.tx, segment, &node_ref, &serialize(&node.0)?)?;
595 +
                self.store.update(self.tx, segment, node_ref, &serialize(&node.0)?)?;
596 596
            }
597 597
        }
598 598
        if self.updated_root {
@@ -612,7 +612,7 @@
Loading
612 612
        let segment = index_id_to_segment_id_data(&self.index_id);
613 613
        if let Some((rec, version)) = self
614 614
            .store
615 -
            .read_tx_internal_fn(self.tx, segment, &node, |x| deserialize(x))
615 +
            .read_tx_internal_fn(self.tx, segment, node, |x| deserialize(x))
616 616
            .map_err(map_read_err)?
617 617
        {
618 618
            Ok(Some((Rc::new(rec?), version)))
@@ -744,7 +744,7 @@
Loading
744 744
            m.remove(node);
745 745
        }
746 746
        let segment = index_id_to_segment_id_data(&self.index_id);
747 -
        self.store.delete(self.tx, segment, &node)?;
747 +
        self.store.delete(self.tx, segment, node)?;
748 748
        Ok(())
749 749
    }
750 750
    fn set_root(&mut self, root: Option<NodeRef>) -> PIRes<()> {
@@ -771,7 +771,7 @@
Loading
771 771
        let segment = index_id_to_segment_id_data(&self.index_id);
772 772
        let (rec, _) = self
773 773
            .store
774 -
            .read_tx_internal_fn(self.tx, segment, &node, |x| deserialize(x))
774 +
            .read_tx_internal_fn(self.tx, segment, node, |x| deserialize(x))
775 775
            .map_err(map_read_err)?
776 776
            .unwrap();
777 777
        rec

@@ -641,7 +641,7 @@
Loading
641 641
        }
642 642
643 643
        for (k, insert) in &mut inserted_by_id {
644 -
            if let Some(update) = updated_by_id.remove(&k) {
644 +
            if let Some(update) = updated_by_id.remove(k) {
645 645
                pages_to_free.insert(FreedPage::new(insert.record_page));
646 646
                insert.record_page = update.record_page;
647 647
            }
@@ -726,7 +726,7 @@
Loading
726 726
        }
727 727
728 728
        let mut records: Vec<(SegmentId, RecRef, u16)> = records.into_iter().collect();
729 -
        records.sort_by_key(|ref x| x.1.clone());
729 +
        records.sort_by_key(|(_, x, _)| x.clone());
730 730
        crt_upd_segs.sort();
731 731
        dropped_segs.sort();
732 732
        (records, crt_upd_segs, dropped_segs)
@@ -883,7 +883,7 @@
Loading
883 883
            for rec in records {
884 884
                indexes_to_unlock.remove(&rec.1);
885 885
            }
886 -
            address.release_locks(records.iter().map(|(_, id, _)| id), &crt_upd_segs, &deleted_segs)?;
886 +
            address.release_locks(records.iter().map(|(_, id, _)| id), crt_upd_segs, deleted_segs)?;
887 887
        }
888 888
889 889
        address.release_locks(

@@ -108,7 +108,7 @@
Loading
108 108
        if let Some((id, rec, _)) = self
109 109
            .iter_impl
110 110
            .iter_impl
111 -
            .next(&self.tx.persy_impl, &self.tx.tx.as_mut().unwrap())
111 +
            .next(&self.tx.persy_impl, self.tx.tx.as_mut().unwrap())
112 112
        {
113 113
            Some((id, rec, self.tx))
114 114
        } else {
@@ -128,7 +128,7 @@
Loading
128 128
    fn next(&mut self) -> Option<Self::Item> {
129 129
        self.iter_impl
130 130
            .iter_impl
131 -
            .next(&self.tx.persy_impl, &self.tx.tx.as_mut().unwrap())
131 +
            .next(&self.tx.persy_impl, self.tx.tx.as_mut().unwrap())
132 132
            .map(|(id, content, _)| (id, content))
133 133
    }
134 134
}

@@ -210,7 +210,7 @@
Loading
210 210
    pub fn scan(&mut self, segment: impl ToSegmentId) -> Result<TxSegmentIter, PE<SegmentError>> {
211 211
        let segment_id = self.solve_segment_id(segment)?;
212 212
        Ok(TxSegmentIter::new(
213 -
            self.persy_impl.scan_tx(&self.tx.as_mut().unwrap(), segment_id)?,
213 +
            self.persy_impl.scan_tx(self.tx.as_mut().unwrap(), segment_id)?,
214 214
            self,
215 215
        ))
216 216
    }

@@ -45,13 +45,13 @@
Loading
45 45
            update |= match vc {
46 46
                ValueChange::Add(v) => {
47 47
                    if leaf.len() > 0 {
48 -
                        leaf.insert_or_update(&self.k, &v, value_mode.clone(), index)?;
48 +
                        leaf.insert_or_update(&self.k, v, value_mode.clone(), index)?;
49 49
                    } else {
50 50
                        leaf.add(0, &self.k, v, value_mode.clone());
51 51
                    }
52 52
                    true
53 53
                }
54 -
                ValueChange::Remove(r) => leaf.remove(&self.k, &r),
54 +
                ValueChange::Remove(r) => leaf.remove(&self.k, r),
55 55
            };
56 56
        }
57 57
        Ok(update)
@@ -111,8 +111,8 @@
Loading
111 111
        let mut prev_version = cur_version;
112 112
        for (_, id) in &ids {
113 113
            // Just unwrap, the leaf should be locked so expected to exist
114 -
            let (sibling_node, version) = index.load_modify(&id)?.unwrap();
115 -
            if let Node::Leaf(sibling) = index.owned(&id, sibling_node) {
114 +
            let (sibling_node, version) = index.load_modify(id)?.unwrap();
115 +
            if let Node::Leaf(sibling) = index.owned(id, sibling_node) {
116 116
                index.update(&prev_id, Node::Leaf(prev_leaf), prev_version)?;
117 117
                prev_id = id.clone();
118 118
                prev_leaf = sibling;
@@ -497,7 +497,7 @@
Loading
497 497
            let prev = path.pop();
498 498
            if let Some((_, node)) = path.last() {
499 499
                let (pos, _) = prev.unwrap();
500 -
                match self.load(&node)? {
500 +
                match self.load(node)? {
501 501
                    Node::Node(n) => {
502 502
                        // check if there are more elements in the node
503 503
                        if n.len() > pos + 1 {
@@ -571,7 +571,7 @@
Loading
571 571
            let prev = path.pop();
572 572
            if let Some((_, node)) = path.last() {
573 573
                let (pos, _) = prev.unwrap();
574 -
                match self.load(&node)? {
574 +
                match self.load(node)? {
575 575
                    Node::Node(n) => {
576 576
                        // check if there are more elements in the node
577 577
                        if pos > 0 {

@@ -143,15 +143,15 @@
Loading
143 143
impl ToSegmentId for &SegmentId {
144 144
    #[inline]
145 145
    fn to_segment_id(self, address: &Address) -> Result<SegmentId, SegmentError> {
146 -
        self.clone().to_segment_id(address)
146 +
        (*self).to_segment_id(address)
147 147
    }
148 148
    #[inline]
149 149
    fn to_segment_id_tx(self, persy: &PersyImpl, tx: &TransactionImpl) -> Result<(SegmentId, bool), SegmentError> {
150 -
        self.clone().to_segment_id_tx(persy, tx)
150 +
        (*self).to_segment_id_tx(persy, tx)
151 151
    }
152 152
    #[inline]
153 153
    fn to_segment_id_snapshot(self, snapshots: &Snapshots, snapshot: SnapshotId) -> Result<SegmentId, SegmentError> {
154 -
        self.clone().to_segment_id_snapshot(snapshots, snapshot)
154 +
        (*self).to_segment_id_snapshot(snapshots, snapshot)
155 155
    }
156 156
}
157 157
@@ -346,7 +346,7 @@
Loading
346 346
        let bytes = BASE32_DNSSEC.decode(s.as_bytes())?;
347 347
        let (meta, bytes) = u64_vdec(&bytes).map_err(|_| InvalidPersyId::InvalidPersyId(String::from(s)))?;
348 348
        let data = if bytes.len() > 1 {
349 -
            let (d, _) = u64_vdec(&bytes).map_err(|_| InvalidPersyId::InvalidPersyId(String::from(s)))?;
349 +
            let (d, _) = u64_vdec(bytes).map_err(|_| InvalidPersyId::InvalidPersyId(String::from(s)))?;
350 350
            d
351 351
        } else {
352 352
            0

@@ -132,9 +132,9 @@
Loading
132 132
        deleted: &[SegmentId],
133 133
    ) -> Result<(), PrepareError> {
134 134
        let timeout = *self.config.transaction_lock_timeout();
135 -
        self.segment_locks.lock_all_write(&deleted, timeout)?;
136 -
        if let Err(x) = self.segment_locks.lock_all_read(&created_updated, timeout) {
137 -
            if let Err(e) = self.segment_locks.unlock_all_write(&deleted) {
135 +
        self.segment_locks.lock_all_write(deleted, timeout)?;
136 +
        if let Err(x) = self.segment_locks.lock_all_read(created_updated, timeout) {
137 +
            if let Err(e) = self.segment_locks.unlock_all_write(deleted) {
138 138
                dbg!("unlock error: {}", e);
139 139
            }
140 140
            return Err(PrepareError::from(x));
@@ -142,10 +142,10 @@
Loading
142 142
143 143
        let to_lock: Vec<_> = records.iter().map(|(_, id, _)| id.clone()).collect();
144 144
        if let Err(x) = self.record_locks.lock_all(&to_lock, timeout) {
145 -
            if let Err(e) = self.segment_locks.unlock_all_write(&deleted) {
145 +
            if let Err(e) = self.segment_locks.unlock_all_write(deleted) {
146 146
                dbg!("unlock error: {}", e);
147 147
            }
148 -
            if let Err(e) = self.segment_locks.unlock_all_read(&created_updated) {
148 +
            if let Err(e) = self.segment_locks.unlock_all_read(created_updated) {
149 149
                dbg!("unlock error: {}", e);
150 150
            }
151 151
            return Err(PrepareError::from(x));
@@ -154,10 +154,10 @@
Loading
154 154
        let segs = self.segments.read()?;
155 155
        for segment in created_updated {
156 156
            if !segs.exists_real_or_temp(*segment) {
157 -
                if let Err(e) = self.segment_locks.unlock_all_write(&deleted) {
157 +
                if let Err(e) = self.segment_locks.unlock_all_write(deleted) {
158 158
                    dbg!("unlock error: {}", e);
159 159
                }
160 -
                if let Err(e) = self.segment_locks.unlock_all_read(&created_updated) {
160 +
                if let Err(e) = self.segment_locks.unlock_all_read(created_updated) {
161 161
                    dbg!("unlock error: {}", e);
162 162
                }
163 163
                if let Err(e) = self.record_locks.unlock_all(&to_lock) {
@@ -191,7 +191,7 @@
Loading
191 191
192 192
    pub fn confirm_allocations(&self, segs: &[SegmentId], recover: bool) -> PERes<()> {
193 193
        let mut segments = self.segments.write()?;
194 -
        segments.confirm_allocations(&segs, &self.allocator, recover)?;
194 +
        segments.confirm_allocations(segs, &self.allocator, recover)?;
195 195
        Ok(())
196 196
    }
197 197
@@ -204,7 +204,7 @@
Loading
204 204
        for &(segment, ref recref, version) in records {
205 205
            let val = self.read(recref, segment)?;
206 206
            if let Some((record, pers_version)) = val {
207 -
                current_record_pages.push(OldRecordInfo::new(&recref, segment, record, pers_version));
207 +
                current_record_pages.push(OldRecordInfo::new(recref, segment, record, pers_version));
208 208
                if check_version && pers_version != version {
209 209
                    return Err(PrepareError::VersionNotLastest);
210 210
                }
@@ -222,8 +222,8 @@
Loading
222 222
        deleted: &[SegmentId],
223 223
    ) -> PERes<()> {
224 224
        self.record_locks.unlock_all_iter(records)?;
225 -
        self.segment_locks.unlock_all_read(&created_updated)?;
226 -
        self.segment_locks.unlock_all_write(&deleted)?;
225 +
        self.segment_locks.unlock_all_read(created_updated)?;
226 +
        self.segment_locks.unlock_all_write(deleted)?;
227 227
        Ok(())
228 228
    }
229 229

@@ -46,7 +46,7 @@
Loading
46 46
    let (last_flush, offset) = prepare_buffer_flush(buffer, last_flush);
47 47
    root.write_u8(version);
48 48
    root.seek(offset + 1);
49 -
    root.write_all(&buffer);
49 +
    root.write_all(buffer);
50 50
    Ok(last_flush)
51 51
}
52 52
Files Coverage
src 91.30%
tests 98.59%
Project Totals (37 files) 92.63%
Notifications are pending CI completion. Waiting for GitLab's status webhook to queue notifications. Push notifications now.
1
coverage:
2
  status:
3
    project:
4
      default:
5
        target: 80%
6
        threshold: 1.0%
7
    patch: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading