MCPcopy
hub / github.com/saltstack/salt / delete

Method delete

salt/utils/mmap_cache.py:1441–1473  ·  view source on GitHub ↗

Mark *key* as DELETED in the index. Heap bytes become unreachable.

(self, key)

Source from the content-addressed store, hash-verified

1439 return None
1440
1441 def delete(self, key):
1442 """Mark *key* as DELETED in the index. Heap bytes become unreachable."""
1443 key_bytes = salt.utils.stringutils.to_bytes(key)[: self.key_size]
1444
1445 try:
1446 with self._thread_lock:
1447 with self._lock():
1448 if not self.open(write=True):
1449 return False
1450 h = self._hash(key_bytes)
1451 data_size = self.size - 1
1452 for i in range(data_size):
1453 slot = ((h - 1 + i) % data_size) + 1
1454 offset = slot * self.slot_size
1455 status = self._mm[offset]
1456
1457 if status == EMPTY:
1458 return False
1459 if status == DELETED:
1460 continue
1461 if self._read_slot_key(offset) != key_bytes:
1462 continue
1463
1464 self._mm[offset] = DELETED
1465 self._update_header(occupied_delta=-1, deleted_delta=1)
1466 self._roster_remove(slot)
1467 self._flush_index_mm()
1468 self._sync_cache_id_after_local_write()
1469 return True
1470 return False
1471 except OSError as exc:
1472 log.error("Error deleting from mmap cache %s: %s", self.path, exc)
1473 return False
1474
1475 def contains(self, key):
1476 """Return ``True`` if *key* exists in the cache."""

Calls 9

_lockMethod · 0.95
openMethod · 0.95
_hashMethod · 0.95
_read_slot_keyMethod · 0.95
_update_headerMethod · 0.95
_roster_removeMethod · 0.95
_flush_index_mmMethod · 0.95
errorMethod · 0.45