def openCommittedBlobFile(self, cursor, oid, serial, blob=None): blob_filename = self.loadBlob(cursor, oid, serial) try: if blob is None: return open(blob_filename, 'rb') else: return ZODB.blob.BlobFile(blob_filename, 'r', blob) except IOError: # The file got removed while we were opening. # Fall through and try again with the protection of the lock. pass lock = _lock_blob(blob_filename) try: blob_filename = self.fshelper.getBlobFilename(oid, serial) if not os.path.exists(blob_filename): if self.shared_blob_dir: # All the blobs are in a shared directory. If the # file isn't here, it's not anywhere. raise POSException.POSKeyError("No blob file", oid, serial) self.download_blob(cursor, oid, serial, blob_filename) if not os.path.exists(blob_filename): raise POSException.POSKeyError("No blob file", oid, serial) _accessed(blob_filename) if blob is None: return open(blob_filename, 'rb') else: return ZODB.blob.BlobFile(blob_filename, 'r', blob) finally: lock.close()
def openCommittedBlobFile(self, oid, serial, blob=None): blob_filename = self.loadBlob(oid, serial) try: if blob is None: return open(blob_filename, 'rb') else: return ZODB.blob.BlobFile(blob_filename, 'r', blob) except (IOError): # The file got removed while we were opening. # Fall through and try again with the protection of the lock. pass lock = _lock_blob(blob_filename) try: blob_filename = self.fshelper.getBlobFilename(oid, serial) if not os.path.exists(blob_filename): if self.shared_blob_dir: # We're using a server shared cache. If the file isn't # here, it's not anywhere. raise POSException.POSKeyError("No blob file", oid, serial) self._call('sendBlob', oid, serial) if not os.path.exists(blob_filename): raise POSException.POSKeyError("No blob file", oid, serial) _accessed(blob_filename) if blob is None: return open(blob_filename, 'rb') else: return ZODB.blob.BlobFile(blob_filename, 'r', blob) finally: lock.close()
def loadBlob(self, oid, serial): # Load a blob. If it isn't present and we have a shared blob # directory, then assume that it doesn't exist on the server # and return None. if self.fshelper is None: raise POSException.Unsupported("No blob cache directory is " "configured.") blob_filename = self.fshelper.getBlobFilename(oid, serial) if self.shared_blob_dir: if os.path.exists(blob_filename): return blob_filename else: # We're using a server shared cache. If the file isn't # here, it's not anywhere. raise POSException.POSKeyError( "No blob file at %s" % blob_filename, oid, serial) if os.path.exists(blob_filename): return _accessed(blob_filename) # First, we'll create the directory for this oid, if it doesn't exist. self.fshelper.createPathForOID(oid) # OK, it's not here and we (or someone) needs to get it. We # want to avoid getting it multiple times. We want to avoid # getting it multiple times even accross separate client # processes on the same machine. We'll use file locking. lock = _lock_blob(blob_filename) try: # We got the lock, so it's our job to download it. First, # we'll double check that someone didn't download it while we # were getting the lock: if os.path.exists(blob_filename): return _accessed(blob_filename) # Ask the server to send it to us. When this function # returns, it will have been sent. (The recieving will # have been handled by the asyncore thread.) self._call('sendBlob', oid, serial) if os.path.exists(blob_filename): return _accessed(blob_filename) raise POSException.POSKeyError("No blob file", oid, serial) finally: lock.close()
def loadBefore(self, oid, tid): try: return self.app.load(oid, None, tid) except NEOStorageDoesNotExistError: raise POSException.POSKeyError(oid) except NEOStorageNotFoundError: return None
def history(self, oid, *args, **kw): try: return self.app.history(oid, *args, **kw) except NEOStorageNotFoundError: raise POSException.POSKeyError(oid) except Exception: logging.exception('oid=%r', oid) raise
def loadSerial(self, oid, serial): try: return self.app.load(oid, serial)[0] except NEOStorageNotFoundError: raise POSException.POSKeyError(oid) except Exception: logging.exception('oid=%r, serial=%r', oid, serial) raise
def loadEx(self, oid, version): try: data, serial, _ = self.app.load(oid) except NEOStorageNotFoundError: raise POSException.POSKeyError(oid) except Exception: logging.exception('oid=%r', oid) raise return data, serial, ''
def load(self, oid, version=''): # XXX: interface definition states that version parameter is # mandatory, while some ZODB tests do not provide it. For now, make # it optional. assert version == '', 'Versions are not supported' try: return self.app.load(oid)[:2] except NEOStorageNotFoundError: raise POSException.POSKeyError(oid)
def loadBlob(self, cursor, oid, serial): # Load a blob. If it isn't present and we have a shared blob # directory, then assume that it doesn't exist on the server # and return None. blob_filename = self.fshelper.getBlobFilename(oid, serial) if self.shared_blob_dir: if os.path.exists(blob_filename): return blob_filename else: # All the blobs are in a shared directory. If the # file isn't here, it's not anywhere. raise POSException.POSKeyError("No blob file", oid, serial) if os.path.exists(blob_filename): return _accessed(blob_filename) # First, we'll create the directory for this oid, if it doesn't exist. self.fshelper.getPathForOID(oid, create=True) # OK, it's not here and we (or someone) needs to get it. We # want to avoid getting it multiple times. We want to avoid # getting it multiple times even accross separate client # processes on the same machine. We'll use file locking. lock = _lock_blob(blob_filename) try: # We got the lock, so it's our job to download it. First, # we'll double check that someone didn't download it while we # were getting the lock: if os.path.exists(blob_filename): return _accessed(blob_filename) self.download_blob(cursor, oid, serial, blob_filename) if os.path.exists(blob_filename): return _accessed(blob_filename) raise POSException.POSKeyError("No blob file", oid, serial) finally: lock.close()
def loadSerial(self, oid, serial): self._lock_acquire() try: old_info = self._old[oid] try: return old_info[serial] except KeyError: raise POSException.POSKeyError(oid) finally: self._lock_release()
def loadBefore(self, oid, tid): # XXX: FileStorage return an empty string for a deleted object # but it may cause EOFError exceptions in ZODB.Connection # and it makes impossible to store empty values. # We think it's wrong behaviour and raise POSKeyError instead. # Or maybe we should return None? try: return self.app.load(oid, None, tid) except NEOStorageDoesNotExistError: raise POSException.POSKeyError(oid) except NEOStorageNotFoundError: return None
def load(self, oid, version=''): result = self.loadBefore(oid, utils.maxtid) if result is None: raise POSException.POSKeyError(oid) return result[:2]
def loadSerial(self, oid, serial): try: return self.app.load(oid, serial)[0] except NEOStorageNotFoundError: raise POSException.POSKeyError(oid)