Changeset 161

Show
Ignore:
Timestamp:
12/22/08 13:52:56 (15 years ago)
Author:
broder
Message:

Negative cache symlink deletions for 10 seconds.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/source/pyhesiodfs/pyHesiodFS.py

    r160 r161  
    1010# 
    1111 
    12 import sys, os, stat, errno 
     12import sys, os, stat, errno, time 
    1313from syslog import * 
    1414import fuse 
     
    4040            print 'defaultdict(%s, %s)' % (self.default_factory,  
    4141                                           super(defaultdict, self).__str__()) 
    42          
     42 
     43class negcache(dict): 
     44    """ 
     45    A set-like object that automatically expunges entries after 
     46    they're been there for a certain amount of time. 
     47     
     48    This only supports add, remove, and __contains__ 
     49    """ 
     50     
     51    def __init__(self, cache_time): 
     52        self.cache_time = cache_time 
     53     
     54    def add(self, obj): 
     55        self[obj] = time.time() 
     56     
     57    def remove(self, obj): 
     58        del self[obj] 
     59     
     60    def __contains__(self, k): 
     61        if super(negcache, self).__contains__(k): 
     62            if self[k] + self.cache_time > time.time(): 
     63                return True 
     64            else: 
     65                del self[k] 
     66        return False 
     67 
    4368new_fuse = hasattr(fuse, '__version__') 
    4469 
     
    91116            self.fuse_args.add("fsname", "pyHesiodFS") 
    92117        self.mounts = defaultdict(dict) 
     118         
     119        # Cache deletions for 10 seconds - should give people time to 
     120        # make a new symlink 
     121        self.negcache = negcache(10) 
    93122     
    94123    def _user(self): 
     
    105134            st.st_size = len(hello_str) 
    106135        elif '/' not in path[1:]: 
    107             if self.findLocker(path[1:]): 
     136            if path[1:] not in self.negcache and self.findLocker(path[1:]): 
    108137                st.st_mode = stat.S_IFLNK | 0777 
    109138                st.st_uid = self._user() 
     
    183212        elif '/' not in path[1:]: 
    184213            del self.mounts[self._user()][path[1:]] 
     214            self.negcache.add(path[1:]) 
    185215        else: 
    186216            return -errno.EPERM