def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) assert not version self._lock_acquire() try: if oid in self._index: oserial = self._index[oid] if serial != oserial: newdata = self.tryToResolveConflict( oid, oserial, serial, data) if not newdata: raise POSException.ConflictError( oid=oid, serials=(oserial, serial), data=data) else: data = newdata else: oserial = serial newserial = self._tid self._tmp.append((oid, data)) return serial == oserial and newserial or ResolvedSerial finally: self._lock_release()
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) if version: raise POSException.Unsupported("Versions aren't supported") self._lock_acquire() try: if oid in self._index: oserial = self._index[oid][:8] if serial != oserial: rdata = self.tryToResolveConflict(oid, oserial, serial, data) if rdata is None: raise POSException.ConflictError(oid=oid, serials=(oserial, serial), data=data) else: data = rdata self._tindex[oid] = self._tid + data finally: self._lock_release() return self._tid
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) if version: # we allow a version to be in use although we don't # support versions in the storage. LOG.debug('versions in use with TemporaryStorage although Temporary ' 'Storage doesnt support versions') self._lock_acquire() try: if self._index.has_key(oid): oserial=self._index[oid] if serial != oserial: newdata = self.tryToResolveConflict( oid, oserial, serial, data) if not newdata: raise POSException.ConflictError( oid=oid, serials=(oserial, serial), data=data) else: data = newdata else: oserial = serial newserial=self._tid self._tmp.append((oid, data)) return serial == oserial and newserial or ResolvedSerial finally: self._lock_release()
def store(self, oid, serial, data, v, txn): if txn is not self._transaction: raise POSException.StorageTransactionError(self, txn) assert not v if self._cur.get(oid) != serial: if not (serial is None or self._cur.get(oid) in [None, z64]): raise POSException.ConflictError( oid=oid, serials=(self._cur.get(oid), serial), data=data) self._txn.store(oid, data) return self._tid
def loadSerial(self, oid, serial, marker=[]): """ This is only useful to make conflict resolution work. It does not actually implement all the semantics that a revisioning storage needs! """ with self._lock: data = self._conflict_cache.get((oid, serial), marker) if data is marker: # XXX Need 2 serialnos to pass them to ConflictError-- # the old and the new raise POSException.ConflictError(oid=oid) else: return data[0] # data here is actually (data, t)
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._lock_acquire() try: old = self._index.get(oid, None) if old is None: # Hm, nothing here, check the base version: if self._base: try: p, tid = self._base.load(oid, '') except KeyError: pass else: old = oid, None, None, p, tid nv=None if old: oid, pre, vdata, p, tid = old if vdata: if vdata[0] != version: raise POSException.VersionLockError(oid) nv=vdata[1] else: nv=old if serial != tid: raise POSException.ConflictError( oid=oid, serials=(tid, serial), data=data) r = [oid, old, version and (version, nv) or None, data, self._tid] self._tindex.append(r) s=self._tsize s=s+72+(data and (16+len(data)) or 4) if version: s=s+32+len(version) if self._quota is not None and s > self._quota: raise POSException.StorageError( '''<b>Quota Exceeded</b><br> The maximum quota for this demonstration storage has been exceeded.<br>Have a nice day.''') finally: self._lock_release() return self._tid
def load(self, oid, version=''): with self._lock: try: s = self._index[oid] p = self._opickle[oid] return p, s # pickle, serial except KeyError: # this oid was probably garbage collected while a thread held # on to an object that had a reference to it; we can probably # force the loader to sync their connection by raising a # ConflictError (at least if Zope is the loader, because it # will resync its connection on a retry). This isn't # perfect because the length of the recently gc'ed oids list # is finite and could be overrun through a mass gc, but it # should be adequate in common-case usage. if oid in self._recently_gc_oids: raise POSException.ConflictError(oid=oid) else: raise
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) assert not version with self._lock: if oid in self._index: oserial = self._index[oid] if serial != oserial: newdata = self.tryToResolveConflict( oid, oserial, serial, data) if not newdata: raise POSException.ConflictError(oid=oid, serials=(oserial, serial), data=data) else: data = newdata else: oserial = serial self._tmp.append((oid, data))
def store(self, oid, h64, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) if version: raise POSException.Unsupported, "Versions aren't supported" self._lock_acquire() try: self.conf_resource.access(self) # Update configuration # First detect conflicts. # The "h64" argument, if its value is not 0, # was previously generated by hash64(). if h64 == HASH0: # Writing a new object. is_new = True else: # Overwriting an old object. Use the hash to verify # that the new data was derived from the old data. is_new = False event, old_c, old_state, old_hash = self._gwio.load(oid) old_h64 = self.hash64(old_hash) if h64 != old_h64: h = None if self.debug_conflicts: h = self._loaded_hashes.get(oid) if h is None: h = h64 old_hash = old_h64 error = ("Storing %s based on old data. %s != %s." % (repr(oid), repr(h), repr(old_hash))) if self.debug_conflicts: # Expose the error for debugging.. raise RuntimeError(error) else: # Use normal ZODB conflict errors. raise POSException.ConflictError(error) # Now unpickle and store the data. file = StringIO(data) u = Unpickler(file) classification = u.load() state = u.load() event, new_hash = self._gwio.store(oid, classification, state, is_new) new_h64 = self.hash64(new_hash) if self.debug_conflicts: self._loaded_hashes[oid] = new_hash # Remember that this OID changed (for scanning) tid = self.getTransactionId() t = self.changed.get(tid) if t is None: t = {} self.changed[tid] = t t[oid] = 1 finally: self._lock_release() return new_h64