MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / del_tree

Method del_tree

atomic-core/src/pristine/txn/write/mod.rs:1853–1931  ·  view source on GitHub ↗
(&mut self, path: &str)

Source from the content-addressed store, hash-verified

1851 }
1852
1853 fn del_tree(&mut self, path: &str) -> PristineResult<Option<Inode>> {
1854 let inode = {
1855 let table = self.txn.open_table(TREE)?;
1856 let value = table.get(path)?.map(|value| Inode::new(value.value()));
1857 value
1858 };
1859
1860 let Some(inode) = inode else {
1861 let reverse_only = {
1862 let table = self.txn.open_table(REV_TREE)?;
1863 let mut found = None;
1864 for row in table.iter()? {
1865 let (candidate, reverse_path) = row?;
1866 if reverse_path.value() == path {
1867 found = Some(Inode::new(candidate.value()));
1868 break;
1869 }
1870 }
1871 found
1872 };
1873 if let Some(reverse_inode) = reverse_only {
1874 return Err(tree_bijection_error(format!(
1875 "REV_TREE maps inode {} to '{}', but TREE has no row",
1876 reverse_inode.get(),
1877 path
1878 )));
1879 }
1880 return Ok(None);
1881 };
1882
1883 // Performance (RFC §21 measured budgets, CB-13C AC-3): the former
1884 // competing-reverse check scanned the ENTIRE REV_TREE table per
1885 // delete — O(n) per call, O(n²) per batch (measured: 4000 deletes
1886 // spent 19.5s here). Two other inode→path rows mapping to the same
1887 // path is a bijection violation that `validate_tree_bijection`
1888 // catches in full (and which `TreeProjectionPlan::apply` runs after
1889 // every projection), so the point checks below suffice on the hot
1890 // path.
1891 let reverse = {
1892 let table = self.txn.open_table(REV_TREE)?;
1893 let result = table
1894 .get(inode.get())?
1895 .map(|value| value.value().to_string());
1896 result
1897 };
1898 if reverse.as_deref() != Some(path) {
1899 return Err(tree_bijection_error(format!(
1900 "cannot delete '{}': TREE maps it to inode {}, but REV_TREE maps that inode to {:?}",
1901 path,
1902 inode.get(),
1903 reverse
1904 )));
1905 }
1906
1907 {
1908 let mut table = self.txn.open_table(TREE)?;
1909 let removed = table.remove(path)?;
1910 if removed.as_ref().map(|value| value.value()) != Some(inode.get()) {

Calls 6

tree_bijection_errorFunction · 0.85
valueMethod · 0.80
as_refMethod · 0.80
getMethod · 0.65
removeMethod · 0.65
iterMethod · 0.45