return self._total
def _remove(self, obj, clear):
+ if obj.inode is None:
+ return
if clear:
# Kernel behavior seems to be that if a file is
# referenced, its parents remain referenced too. This
_logger.debug("InodeCache cleared inode %i total now %i", obj.inode, self._total)
def cap_cache(self):
+ _logger.debug("in cap_cache %i, %i", self._total, self.cap)
if self._total > self.cap:
for ent in listvalues(self._entries):
if self._total < self.cap or len(self._entries) < self.min_entries:
break
self._remove(ent, True)
+ _logger.debug("end cap_cache %i, %i", self._total, self.cap)
def manage(self, obj):
if obj.persisted():
else:
if obj not in self._by_uuid[obj.cache_uuid]:
self._by_uuid[obj.cache_uuid].append(obj)
- self._total += obj.objsize()
+ self._total += obj.cache_size
_logger.debug("InodeCache touched inode %i (size %i) (uuid %s) total now %i (%i entries)",
obj.inode, obj.objsize(), obj.cache_uuid, self._total, len(self._entries))
+ def update_cache_size(self, obj):
+ if obj.inode in self._entries:
+ self._total -= obj.cache_size
+ obj.cache_size = obj.objsize()
+ self._total += obj.cache_size
+
def touch(self, obj):
if obj.persisted():
if obj.inode in self._entries:
self.inodes.touch(self)
super(Directory, self).fresh()
+ def objsize(self):
+ return len(self._entries) * 64
+
def merge(self, items, fn, same, new_entry):
"""Helper method for updating the contents of the directory.
if changed:
self.inodes.invalidate_inode(self)
self._mtime = time.time()
-
- self.inodes.inode_cache.cap_cache()
+ self.inodes.inode_cache.update_cache_size(self)
+ self.inodes.inode_cache.cap_cache()
for ent in self._entries.values():
ent.dec_use()
oldentries = self._entries
self._entries = {}
for n in oldentries:
- oldentries[n].clear()
self.inodes.del_entry(oldentries[n])
self.invalidate()
self.collection_record_file.invalidate()
self.inodes.invalidate_inode(self.collection_record_file)
_logger.debug("%s invalidated collection record file", self)
+ self.inodes.inode_cache.update_cache_size(self)
self.fresh()
def uuid(self):
self.collection.stop_threads()
super(CollectionDirectory, self).clear()
self._manifest_size = 0
+ self.inodes.inode_cache.update_cache_size(self)
class TmpCollectionDirectory(CollectionDirectoryBase):