rem
stringlengths 0
322k
| add
stringlengths 0
2.05M
| context
stringlengths 8
228k
|
---|---|---|
home = args[0] if not os.path.isabs(home): home = os.path.abspath(home)
|
instance_home = args[0] if not os.path.isabs(instance_home): instance_home = os.path.abspath(instance_home) for entry in sys.path: if os.path.exists(os.path.join(entry, 'Zope')): zope_home = entry break else: print "Can't find the Zope home (not in sys.path)" sys.exit(2)
|
def run(self): try: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) except getopt.error, msg: print msg sys.exit(2) program = os.path.basename(sys.argv[0]) if opts: # There's only the help options, so just dump some help: msg = __doc__ % {"program": program} print msg sys.exit() if len(args) not in [1, 2]: print "Usage: %s home [port]" % program sys.exit(2) home = args[0] if not os.path.isabs(home): home = os.path.abspath(home) if args[1:]: port = int(args[1]) else: port = 9999 checkport(port) params = self.get_params(home, port) self.create(home, params)
|
params = self.get_params(home, port) self.create(home, params) def get_params(self, home, port):
|
params = self.get_params(zope_home, instance_home, port) self.create(instance_home, params) def get_params(self, zope_home, instance_home, port):
|
def run(self): try: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) except getopt.error, msg: print msg sys.exit(2) program = os.path.basename(sys.argv[0]) if opts: # There's only the help options, so just dump some help: msg = __doc__ % {"program": program} print msg sys.exit() if len(args) not in [1, 2]: print "Usage: %s home [port]" % program sys.exit(2) home = args[0] if not os.path.isabs(home): home = os.path.abspath(home) if args[1:]: port = int(args[1]) else: port = 9999 checkport(port) params = self.get_params(home, port) self.create(home, params)
|
"home": home,
|
"zope_home": zope_home, "instance_home": instance_home,
|
def get_params(self, home, port): return { "package": "zeo", "PACKAGE": "ZEO", "home": home, "port": port, "python": sys.executable, "server": which("runzeo.py"), "zdrun": which("zdrun.py"), "zdctl": which("zdctl.py"), }
|
"server": which("runzeo.py"), "zdrun": which("zdrun.py"), "zdctl": which("zdctl.py"),
|
def get_params(self, home, port): return { "package": "zeo", "PACKAGE": "ZEO", "home": home, "port": port, "python": sys.executable, "server": which("runzeo.py"), "zdrun": which("zdrun.py"), "zdctl": which("zdctl.py"), }
|
|
poll_fun = asyncore.poll
|
poll_fun = poll
|
def loop(timeout=30.0, use_poll=0, map=None): """Invoke asyncore mainloop This function functions like the regular asyncore.loop() function except that it also triggers ThreadedAsync callback functions before starting the loop. """ if use_poll: if hasattr(select, 'poll'): poll_fun = asyncore.poll3 else: poll_fun = asyncore.poll2 else: poll_fun = asyncore.poll if map is None: map = asyncore.socket_map _start_loop(map) while map: poll_fun(timeout, map) _stop_loop()
|
name = str(self.storage)
|
name = str(storage)
|
def slog(storage, msg, level=zLOG.INFO, error=None, pid=os.getpid()): name = getattr(storage, '__name__', None) if name is None: name = str(self.storage) zLOG.LOG("ZEO Server:%s:%s" % (pid, name), level, msg, error=error)
|
cserial, cdataptr, cver, cdata = self._undoDataInfo(
|
cserial, cdataptr, cdata, cver = self._undoDataInfo(
|
def _transactionalUndoRecord(self, oid, pos, serial, pre, version): """Get the indo information for a data record
|
class FileStorage: _packt=0 _transaction=None _serial=z64 def __init__(self, file_name, create=0, read_only=0, stop=None):
|
class FileStorage(BaseStorage.BaseStorage): _packt=z64 def __init__(self, file_name, create=0, read_only=0, stop=None, base=None):
|
def panic(message, *data): message=message%data LOG('ZODB FS',PANIC,"%s ERROR: %s\n" % (packed_version, message)) raise CorruptedTransactionError, message
|
self.__name__=file_name
|
BaseStorage.BaseStorage.__init__(self, file_name)
|
def __init__(self, file_name, create=0, read_only=0, stop=None):
|
self._index=index self._vindex=vindex self._tindex=tindex self._tvindex=tvindex self._indexpos=index.get self._vindexpos=vindex.get self._tappend=tindex.append l=bpthread.allocate_lock() self._a=l.acquire self._r=l.release l=bpthread.allocate_lock() self._ca=l.acquire self._cr=l.release
|
self._initIndex(index, vindex, tindex, tvindex) self._base=base
|
def __init__(self, file_name, create=0, read_only=0, stop=None):
|
return self.commitVersion(src, '', transaction, abort=1) def close(self): self._file.close() def commitVersion(self, src, dest, transaction, abort=None): if dest and abort: raise 'VersionCommitError', ( 'Internal error, can\'t abort to a version')
|
def abortVersion(self, src, transaction): # We are going to abort by simply storing back pointers.
|
|
self._a()
|
self._lock_acquire()
|
def abortVersion(self, src, transaction): # We are going to abort by simply storing back pointers.
|
srcpos=self._vindex.get(src, 0)
|
srcpos=self._vindex_get(src, 0)
|
def abortVersion(self, src, transaction): # We are going to abort by simply storing back pointers.
|
middle=p64(self._pos)+'\0'*10 here=tfile.tell()+self._pos+self._thl oids=[] appoids=oids.append while srcpos: seek(srcpos) h=read(58) oid=h[:8] if index[oid]==srcpos: tappend((oid,here)) appoids(oid) write(h[:16] + spos + middle + h[-16:-8]) here=here+50 spos=h[-8:] srcpos=u64(spos) self._tvindex[src]=0 return oids finally: self._r() def close(self): self._file.close() def commitVersion(self, src, dest, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._a() try: file=self._file read=file.read seek=file.seek tfile=self._tfile write=tfile.write tappend=self._tappend index=self._index srcpos=self._vindex.get(src, 0) spos=p64(srcpos)
|
def abortVersion(self, src, transaction): # We are going to abort by simply storing back pointers.
|
|
sd=p64(self._vindex.get(dest, 0))
|
sd=p64(self._vindex_get(dest, 0))
|
def commitVersion(self, src, dest, transaction): # We are going to commit by simply storing back pointers. if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._a() try: file=self._file read=file.read seek=file.seek tfile=self._tfile write=tfile.write tappend=self._tappend index=self._index
|
current_oids={} current=current_oids.has_key t=None tstatus=' '
|
def commitVersion(self, src, dest, transaction): # We are going to commit by simply storing back pointers. if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._a() try: file=self._file read=file.read seek=file.seek tfile=self._tfile write=tfile.write tappend=self._tappend index=self._index
|
|
write(h[-16:-8]+sd+dest)
|
write(pnv+sd+dest)
|
def commitVersion(self, src, dest, transaction): # We are going to commit by simply storing back pointers. if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._a() try: file=self._file read=file.read seek=file.seek tfile=self._tfile write=tfile.write tappend=self._tappend index=self._index
|
write(spos)
|
write(abort and pnv or spos)
|
def commitVersion(self, src, dest, transaction): # We are going to commit by simply storing back pointers. if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._a() try: file=self._file read=file.read seek=file.seek tfile=self._tfile write=tfile.write tappend=self._tappend index=self._index
|
tvindex[src]=0
|
def commitVersion(self, src, dest, transaction): # We are going to commit by simply storing back pointers. if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._a() try: file=self._file read=file.read seek=file.seek tfile=self._tfile write=tfile.write tappend=self._tappend index=self._index
|
|
finally: self._r() def getName(self): return self.__name__
|
finally: self._lock_release()
|
def commitVersion(self, src, dest, transaction): # We are going to commit by simply storing back pointers. if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._a() try: file=self._file read=file.read seek=file.seek tfile=self._tfile write=tfile.write tappend=self._tappend index=self._index
|
def history(self, oid, version, length=1): pass
|
def _loada(self, oid, _index, file): "Read any version and return the version" pos=_index[oid] file.seek(pos) read=file.read h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if vlen: file.seek(16,1) version=read(vlen) else: version='' if plen != z64: return read(u64(plen)), version return _loadBack(file, oid, read(8))[0], version def _load(self, oid, version, _index, file): pos=_index[oid] file.seek(pos) read=file.read h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if doid != oid: raise CorruptedDataError, h if vlen: pnv=read(8) if (not version or len(version) != vlen or (read(8) and version != read(vlen)) ): return _loadBack(file, oid, pnv) if plen != z64: return read(u64(plen)), serial pnv=read(8) return _loadBack(file, oid, pnv)[0], serial
|
def getSize(self): return self._pos
|
self._a()
|
self._lock_acquire()
|
def load(self, oid, version, _stuff=None): self._a() try: pos=self._index[oid] file=self._file file.seek(pos) read=file.read h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if doid != oid: raise CorruptedDataError, h if vlen: pnv=read(8) # Read location of non-version data if (not version or len(version) != vlen or (read(8) # skip past version link and version != read(vlen)) ): return _loadBack(file, oid, pnv)
|
pos=self._index[oid] file=self._file file.seek(pos) read=file.read h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if doid != oid: raise CorruptedDataError, h if vlen: pnv=read(8) if (not version or len(version) != vlen or (read(8) and version != read(vlen)) ): return _loadBack(file, oid, pnv) if plen != z64: return read(u64(plen)), serial pnv=read(8) return _loadBack(file, oid, pnv)[0], serial finally: self._r()
|
try: return self._load(oid, version, self._index, self._file) except: if self._base is not None: return self._base.load(oid, version) raise finally: self._lock_release()
|
def load(self, oid, version, _stuff=None): self._a() try: pos=self._index[oid] file=self._file file.seek(pos) read=file.read h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if doid != oid: raise CorruptedDataError, h if vlen: pnv=read(8) # Read location of non-version data if (not version or len(version) != vlen or (read(8) # skip past version link and version != read(vlen)) ): return _loadBack(file, oid, pnv)
|
self._a()
|
self._lock_acquire()
|
def modifiedInVersion(self, oid): self._a() try: pos=self._index[oid] file=self._file seek=file.seek seek(pos) doid,serial,prev,tloc,vlen = unpack(">8s8s8s8sH", file.read(34)) if doid != oid: raise CorruptedDataError, h if vlen: seek(24,1) # skip plen, pnv, and pv return file.read(vlen) return '' finally: self._r()
|
finally: self._r() def new_oid(self, last=None): if last is None: self._a() try: last=self._oid d=ord(last[-1]) if d < 255: last=last[:-1]+chr(d+1) else: last=self.new_oid(last[:-1]) self._oid=last return last finally: self._r() else: d=ord(last[-1]) if d < 255: return last[:-1]+chr(d+1)+'\0'*(8-len(last)) else: return self.new_oid(last[:-1]) def pack(self, t, rf): pass
|
finally: self._lock_release()
|
def modifiedInVersion(self, oid): self._a() try: pos=self._index[oid] file=self._file seek=file.seek seek(pos) doid,serial,prev,tloc,vlen = unpack(">8s8s8s8sH", file.read(34)) if doid != oid: raise CorruptedDataError, h if vlen: seek(24,1) # skip plen, pnv, and pv return file.read(vlen) return '' finally: self._r()
|
self._a()
|
self._lock_acquire()
|
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction)
|
old=self._indexpos(oid, 0)
|
old=self._index_get(oid, 0)
|
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction)
|
pv=tvindex.get(version, 0) or self._vindexpos(version, 0)
|
pv=tvindex.get(version, 0) or self._vindex_get(version, 0)
|
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction)
|
finally: self._r() def registerDB(self, db, limit): pass def supportsUndo(self): return 0
|
finally: self._lock_release() def supportsUndo(self): return 1
|
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction)
|
def tpc_abort(self, transaction): self._a()
|
def _clear_temp(self): del self._tindex[:] self._tvindex.clear() self._tfile.seek(0) def _begin(self, tid, u, d, e): self._thl=23+len(u)+len(d)+len(e) def _finish(self, tid, u, d, e): file=self._file write=file.write tfile=self._tfile dlen=tfile.tell() tfile.seek(0) id=self._serial user, desc, ext = self._ude tlen=self._thl pos=self._pos file.seek(pos) tl=tlen+dlen stl=p64(tl) write(pack( ">8s" "8s" "c" "H" "H" "H" ,id, stl, ' ', len(user), len(desc), len(ext), )) if user: write(user) if desc: write(desc) if ext: write(ext) cp(tfile, file, dlen) write(stl) file.flush() self._pos=pos+tl+8 index=self._index for oid, pos in self._tindex: index[oid]=pos self._vindex.update(self._tvindex) def undo(self, transaction_id): self._lock_acquire()
|
def supportsVersions(self): return 1
|
if transaction is not self._transaction: return del self._tindex[:] self._transaction=None self._cr() finally: self._r() def tpc_begin(self, transaction): self._a() try: if self._transaction is transaction: return self._r() self._ca() self._a() self._transaction=transaction del self._tindex[:] self._tvindex.clear() self._tfile.seek(0) t=time.time() t=apply(TimeStamp,(time.gmtime(t)[:5]+(t%60,))) self._ts=t=t.laterThan(self._ts) self._serial=`t` user=transaction.user desc=transaction.description ext=transaction._extension if ext: ext=dumps(ext,1) else: ext="" self._thl=23+len(user)+len(desc)+len(ext) self._ude=user, desc, ext finally: self._r() def tpc_finish(self, transaction, f=None): self._a() try: if transaction is not self._transaction: return if f is not None: f() file=self._file write=file.write tfile=self._tfile dlen=tfile.tell() tfile.seek(0) id=self._serial user, desc, ext = self._ude self._ude=None tlen=self._thl pos=self._pos file.seek(pos) tl=tlen+dlen stl=p64(tl) write(pack( ">8s" "8s" "c" "H" "H" "H" ,id, stl, ' ', len(user), len(desc), len(ext), )) if user: write(user) if desc: write(desc) if ext: write(ext) cp(tfile, file, dlen) write(stl) file.flush() self._pos=pos+tl+8 tindex=self._tindex index=self._index for oid, pos in tindex: index[oid]=pos del tindex[:] tvindex=self._tvindex self._vindex.update(tvindex) tvindex.clear() self._transaction=None self._cr() finally: self._r() def undo(self, transaction_id): self._a() try:
|
transaction_id=base64.decodestring(transaction_id+'==\n') tid, tpos = transaction_id[:8], u64(transaction_id[8:]) packt=self._packt if packt is None or packt > tid: raise POSException.UndoError, ( 'Undo is currently disabled for database maintenance.<p>')
|
def tpc_abort(self, transaction): self._a() try: if transaction is not self._transaction: return del self._tindex[:] self._transaction=None self._cr() finally: self._r()
|
indexpos=self._indexpos
|
index_get=self._index_get
|
def undo(self, transaction_id): self._a() try: file=self._file seek=file.seek read=file.read indexpos=self._indexpos unpack=struct.unpack transaction_id=base64.decodestring(transaction_id+'==\n') tid, tpos = transaction_id[:8], u64(transaction_id[8:]) seek(tpos) h=read(23) if len(h) != 23 or h[:8] != tid: raise UndoError, 'Invalid undo transaction id' if h[16] == 'u': return if h[16] != ' ': raise UndoError, 'Undoable transaction' tl=u64(h[8:16]) ul,dl,el=unpack(">HHH", h[17:23]) tend=tpos+tl pos=tpos+23+ul+dl+el t=[] tappend=t.append while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) plen=u64(splen) prev=u64(sprev) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen if indexpos(oid,0) != pos: raise UndoError, 'Undoable transaction' pos=pos+dlen if pos > tend: raise UndoError, 'Undoable transaction' tappend((oid,prev))
|
transaction_id=base64.decodestring(transaction_id+'==\n') tid, tpos = transaction_id[:8], u64(transaction_id[8:])
|
def undo(self, transaction_id): self._a() try: file=self._file seek=file.seek read=file.read indexpos=self._indexpos unpack=struct.unpack transaction_id=base64.decodestring(transaction_id+'==\n') tid, tpos = transaction_id[:8], u64(transaction_id[8:]) seek(tpos) h=read(23) if len(h) != 23 or h[:8] != tid: raise UndoError, 'Invalid undo transaction id' if h[16] == 'u': return if h[16] != ' ': raise UndoError, 'Undoable transaction' tl=u64(h[8:16]) ul,dl,el=unpack(">HHH", h[17:23]) tend=tpos+tl pos=tpos+23+ul+dl+el t=[] tappend=t.append while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) plen=u64(splen) prev=u64(sprev) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen if indexpos(oid,0) != pos: raise UndoError, 'Undoable transaction' pos=pos+dlen if pos > tend: raise UndoError, 'Undoable transaction' tappend((oid,prev))
|
|
t=[] tappend=t.append
|
t={}
|
def undo(self, transaction_id): self._a() try: file=self._file seek=file.seek read=file.read indexpos=self._indexpos unpack=struct.unpack transaction_id=base64.decodestring(transaction_id+'==\n') tid, tpos = transaction_id[:8], u64(transaction_id[8:]) seek(tpos) h=read(23) if len(h) != 23 or h[:8] != tid: raise UndoError, 'Invalid undo transaction id' if h[16] == 'u': return if h[16] != ' ': raise UndoError, 'Undoable transaction' tl=u64(h[8:16]) ul,dl,el=unpack(">HHH", h[17:23]) tend=tpos+tl pos=tpos+23+ul+dl+el t=[] tappend=t.append while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) plen=u64(splen) prev=u64(sprev) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen if indexpos(oid,0) != pos: raise UndoError, 'Undoable transaction' pos=pos+dlen if pos > tend: raise UndoError, 'Undoable transaction' tappend((oid,prev))
|
if indexpos(oid,0) != pos:
|
if index_get(oid,0) != pos:
|
def undo(self, transaction_id): self._a() try: file=self._file seek=file.seek read=file.read indexpos=self._indexpos unpack=struct.unpack transaction_id=base64.decodestring(transaction_id+'==\n') tid, tpos = transaction_id[:8], u64(transaction_id[8:]) seek(tpos) h=read(23) if len(h) != 23 or h[:8] != tid: raise UndoError, 'Invalid undo transaction id' if h[16] == 'u': return if h[16] != ' ': raise UndoError, 'Undoable transaction' tl=u64(h[8:16]) ul,dl,el=unpack(">HHH", h[17:23]) tend=tpos+tl pos=tpos+23+ul+dl+el t=[] tappend=t.append while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) plen=u64(splen) prev=u64(sprev) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen if indexpos(oid,0) != pos: raise UndoError, 'Undoable transaction' pos=pos+dlen if pos > tend: raise UndoError, 'Undoable transaction' tappend((oid,prev))
|
tappend((oid,prev))
|
t[oid]=prev
|
def undo(self, transaction_id): self._a() try: file=self._file seek=file.seek read=file.read indexpos=self._indexpos unpack=struct.unpack transaction_id=base64.decodestring(transaction_id+'==\n') tid, tpos = transaction_id[:8], u64(transaction_id[8:]) seek(tpos) h=read(23) if len(h) != 23 or h[:8] != tid: raise UndoError, 'Invalid undo transaction id' if h[16] == 'u': return if h[16] != ' ': raise UndoError, 'Undoable transaction' tl=u64(h[8:16]) ul,dl,el=unpack(">HHH", h[17:23]) tend=tpos+tl pos=tpos+23+ul+dl+el t=[] tappend=t.append while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) plen=u64(splen) prev=u64(sprev) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen if indexpos(oid,0) != pos: raise UndoError, 'Undoable transaction' pos=pos+dlen if pos > tend: raise UndoError, 'Undoable transaction' tappend((oid,prev))
|
for oid, pos in t: index[oid]=pos finally: self._r()
|
for oid, pos in t.items(): index[oid]=pos return t.keys() finally: self._lock_release()
|
def undo(self, transaction_id): self._a() try: file=self._file seek=file.seek read=file.read indexpos=self._indexpos unpack=struct.unpack transaction_id=base64.decodestring(transaction_id+'==\n') tid, tpos = transaction_id[:8], u64(transaction_id[8:]) seek(tpos) h=read(23) if len(h) != 23 or h[:8] != tid: raise UndoError, 'Invalid undo transaction id' if h[16] == 'u': return if h[16] != ' ': raise UndoError, 'Undoable transaction' tl=u64(h[8:16]) ul,dl,el=unpack(">HHH", h[17:23]) tend=tpos+tl pos=tpos+23+ul+dl+el t=[] tappend=t.append while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) plen=u64(splen) prev=u64(sprev) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen if indexpos(oid,0) != pos: raise UndoError, 'Undoable transaction' pos=pos+dlen if pos > tend: raise UndoError, 'Undoable transaction' tappend((oid,prev))
|
self._a()
|
self._lock_acquire()
|
def undoLog(self, first, last, filter=None): self._a() try: pos=self._pos if pos < 39: return [] file=self._file seek=file.seek read=file.read unpack=struct.unpack strip=string.strip encode=base64.encodestring r=[] append=r.append i=0 while i < last and pos > 39: seek(pos-8) pos=pos-u64(read(8))-8 if i < first: continue seek(pos) h=read(23) tid, tl, status, ul, dl, el = unpack(">8s8scHHH", h) if status != ' ': continue u=ul and read(ul) or '' d=dl and read(dl) or '' d={'id': encode(tid+p64(pos))[:22], 'time': TimeStamp(tid).timeTime(), 'user_name': u, 'description': d} if el: try: e=loads(read(el)) d.update(e) except: pass if filter is None or filter(d): append(d) i=i+1 return r finally: self._r()
|
finally: self._r()
|
finally: self._lock_release()
|
def undoLog(self, first, last, filter=None): self._a() try: pos=self._pos if pos < 39: return [] file=self._file seek=file.seek read=file.read unpack=struct.unpack strip=string.strip encode=base64.encodestring r=[] append=r.append i=0 while i < last and pos > 39: seek(pos-8) pos=pos-u64(read(8))-8 if i < first: continue seek(pos) h=read(23) tid, tl, status, ul, dl, el = unpack(">8s8scHHH", h) if status != ' ': continue u=ul and read(ul) or '' d=dl and read(dl) or '' d={'id': encode(tid+p64(pos))[:22], 'time': TimeStamp(tid).timeTime(), 'user_name': u, 'description': d} if el: try: e=loads(read(el)) d.update(e) except: pass if filter is None or filter(d): append(d) i=i+1 return r finally: self._r()
|
return not self._vindex.get(version, 0)
|
self._lock_acquire() try: index=self._index file=self._file seek=file.seek read=file.read srcpos=self._vindex_get(version, 0) t=tstatus=None while srcpos: seek(srcpos) oid=read(8) if index[oid]==srcpos: return 0 h=read(50) tloc=h[16:24] if t != tloc: t=tloc seek(u64(t)+16) tstatus=read(1) if tstatus != 'u': return 1 spos=h[-8:] srcpos=u64(spos) return 1 finally: self._lock_release()
|
def versionEmpty(self, version): return not self._vindex.get(version, 0)
|
if max: return self._vindex.keys()[:max] return self._vindex.keys()
|
r=[] a=r.append for version in self._vindex.keys()[:max]: if self.versionEmpty(version): continue a(version) if max and len(r) >= max: return r return r def pack(self, t, referencesf): """Copy data from the current database file to a packed file Non-current records from transactions with time-stamp strings less than packtss are ommitted. As are all undone records. Also, data back pointers that point before packtss are resolved and the associated data are copied, since the old records are not copied. """ packing=1 locked=0 _lock_acquire=self._lock_acquire _lock_release=self._lock_release index, vindex, tindex, tvindex = self._newIndexes() name=self.__name__ file=open(name, 'r+b') stop=`apply(TimeStamp, time.gmtime(t)[:5]+(t%60,))` try: _lock_acquire() self._packt=stop _lock_release() packpos, maxoid, ltid = read_index( file, name, index, vindex, tindex, stop) rootl=[z64] pop=rootl.pop pindex={} referenced=pindex.has_key _load=self._load _loada=self._loada v=None while rootl: oid=pop() if referenced(oid): continue try: p, v = _loada(oid, index, file) referencesf(p, rootl) if v: p, serial = _load(oid, '', index, file) referencesf(p, rootl) pindex[oid]=index[oid] except: pindex[oid]=0 error('Bad reference to %s', `(oid,v)`) spackpos=p64(packpos) index, vindex, tindex, tvindex = self._newIndexes() ofile=open(name+'.pack', 'w+b') nvindex={} seek=file.seek read=file.read oseek=ofile.seek write=ofile.write tappend=tindex.append index_get=index.get vindex_get=vindex.get pindex_get=pindex.get pv=z64 offset=0 pos=opos=4 oseek(0) write(packed_version) pnv=None while 1: if packing and pos >= packpos: offset=pos-opos if offset <= 0: ofile.close() file.close() os.remove(name+'.pack') return packing=0 _lock_acquire() locked=1 self._packt=None seek(pos) h=read(23) if len(h) < 23: break tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if el < 0: el=t32-el tl=u64(stl) tpos=pos tend=tpos+tl if status=='u': pos=tend+8 continue otpos=opos write(h) thl=ul+dl+el h=read(thl) if len(h) != thl: raise 'Pack Error', opos write(h) thl=23+thl pos=tpos+thl opos=otpos+thl status=' ' while pos < tend: seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack( ">8s8s8s8sH8s", h) plen=u64(splen) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen if packing and pindex_get(oid,0) != pos: pos=pos+dlen status='p' continue pnv=u64(read(8)) seek(8,1) version=read(vlen) pv=p64(vindex_get(version, 0)) vindex[version]=opos else: if packing: ppos=pindex_get(oid, 0) if ppos != pos: if not ppos: pos=pos+dlen status='p' continue seek(ppos) ph=read(42) pdoid,ps,pp,pt,pvlen,pplen = unpack( ">8s8s8s8sH8s", ph) if not pvlen: pos=pos+dlen status='p' continue pnv=read(8) pnv=_loadBackPOS(file, oid, pnv) if pnv > pos: pos=pos+dlen status='p' continue nvindex[oid]=opos tappend((oid,opos)) opos=opos+dlen pos=pos+dlen if plen: p=read(plen) else: p=read(8) if packing: p, serial = _loadBack(file, oid, p) plen=len(p) opos=opos+plen-8 splen=p64(plen) else: p=u64(p) if p < packpos: if pindex[oid]==p: p=index[oid] else: p=nvindex[oid] else: p=p-offset p=p64(p) sprev=p64(index_get(oid,0)) write(pack(">8s8s8s8sH8s", oid,serial,sprev,p64(otpos),vlen,splen)) if vlen: if not pnv: write(z64) else: if pnv < packpos: pnv=nvindex[oid] else: pnv=pnv-offset write(p64(pnv)) write(pv) write(version) write(p) pos=pos+8 if locked: _lock_release() locked=0 for oid, p in tindex: index[oid]=p del tindex[:] otl=opos-otpos if otl != tl: if otl==thl: opos=otpos oseek(opos) else: oseek(otpos+8) otl=p64(otl) write(otl+status) oseek(opos) write(otl) opos=opos+8 else: write(p64(otl)) opos=opos+8 if not packing: _lock_acquire() locked=1 name=self.__name__ ofile.flush() ofile.close() file.close() self._file.close() try: os.remove(name) except: self._file=open(name,'r+b') raise os.rename(name+'.pack', name) self._file=open(name,'r+b') self._initIndex(index, vindex, tindex, tvindex) self._pos=opos finally: if locked: _lock_release() _lock_acquire() self._packt=z64 _lock_release()
|
def versions(self, max=None): if max: return self._vindex.keys()[:max] return self._vindex.keys()
|
indexpos=index.get
|
index_get=index.get
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8): indexpos=index.get vndexpos=vindex.get tappend=tindex.append read=file.read seek=file.seek seek(0,2) file_size=file.tell() seek(0) if file_size: if file_size < 4: raise FileStorageFormatError, file.name if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) pos=4 unpack=struct.unpack tpos=0 maxoid=ltid=z64 tid='\0'*7+'\1' while 1: # Read the transaction record h=read(23) if not h: break if len(h) != 23: warn('%s truncated at %s', name, pos) seek(pos) file.truncate() break tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if el < 0: el=t32-el if tid <= ltid: warn("%s time-stamp reduction at %s", name, pos) ltid=tid tl=u64(stl) if tl+pos+8 > file_size: # Hm, the data were truncated. They may also be corrupted, # in which case, we don't want to totally lose the data. warn("%s truncated, possibly due to damaged records at %s", name, pos) try: i=0 while 1: if os.path.exists('%s.tr%s' % (name, i)): i=i+1 else: o=open('%s.tr%s' % (name, i),'wb') seek(pos) cp(file, o, file_size-pos) o.close() break except: error("couldn\'t write truncated data for %s", name) raise POSException.StorageSystemError, ( "Couldn't save truncated data") seek(pos) file.truncate() break if status not in ' up': warn('%s has invalid status, %s, at %s', name, status, pos) if ul > tl or dl > tl or el > tl: panic('%s has invalid transaction header at %s', name, pos) if tid >= stop: break tpos=pos tend=tpos+tl if status=='u': # Undone transaction, skip it pos=tpos+tl seek(pos) h=read(8) if h != stl: panic('%s has inconsistent transaction length at %s', name, pos) pos=pos+8 continue pos=tpos+23+ul+dl+el while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) prev=u64(sprev) tloc=u64(stloc) plen=u64(splen) dlen=42+(plen or 8) tappend((oid,pos)) if vlen: dlen=dlen+16+vlen seek(8,1) pv=u64(read(8)) version=read(vlen) # Jim says: "It's just not worth the bother." #if vndexpos(version, 0) != pv: # panic("%s incorrect previous version pointer at %s", # name, pos) vindex[version]=pos if pos+dlen > tend or tloc != tpos: panic("%s data record exceeds transaction record at %s", name, pos) if indexpos(oid,0) != prev: panic("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: panic("%s data records don't add up at %s",name,tpos) # Read the (intentionally redundant) transaction length seek(pos) h=read(8) if h != stl: panic("%s redundant transaction length check failed at %s", name, pos) pos=pos+8 for oid, p in tindex: maxoid=max(maxoid,oid) index[oid]=p # Record the position del tindex[:] _checkVindex(file, index, vindex) return pos, maxoid, ltid
|
pos=tpos+tl seek(pos)
|
seek(tend)
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8): indexpos=index.get vndexpos=vindex.get tappend=tindex.append read=file.read seek=file.seek seek(0,2) file_size=file.tell() seek(0) if file_size: if file_size < 4: raise FileStorageFormatError, file.name if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) pos=4 unpack=struct.unpack tpos=0 maxoid=ltid=z64 tid='\0'*7+'\1' while 1: # Read the transaction record h=read(23) if not h: break if len(h) != 23: warn('%s truncated at %s', name, pos) seek(pos) file.truncate() break tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if el < 0: el=t32-el if tid <= ltid: warn("%s time-stamp reduction at %s", name, pos) ltid=tid tl=u64(stl) if tl+pos+8 > file_size: # Hm, the data were truncated. They may also be corrupted, # in which case, we don't want to totally lose the data. warn("%s truncated, possibly due to damaged records at %s", name, pos) try: i=0 while 1: if os.path.exists('%s.tr%s' % (name, i)): i=i+1 else: o=open('%s.tr%s' % (name, i),'wb') seek(pos) cp(file, o, file_size-pos) o.close() break except: error("couldn\'t write truncated data for %s", name) raise POSException.StorageSystemError, ( "Couldn't save truncated data") seek(pos) file.truncate() break if status not in ' up': warn('%s has invalid status, %s, at %s', name, status, pos) if ul > tl or dl > tl or el > tl: panic('%s has invalid transaction header at %s', name, pos) if tid >= stop: break tpos=pos tend=tpos+tl if status=='u': # Undone transaction, skip it pos=tpos+tl seek(pos) h=read(8) if h != stl: panic('%s has inconsistent transaction length at %s', name, pos) pos=pos+8 continue pos=tpos+23+ul+dl+el while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) prev=u64(sprev) tloc=u64(stloc) plen=u64(splen) dlen=42+(plen or 8) tappend((oid,pos)) if vlen: dlen=dlen+16+vlen seek(8,1) pv=u64(read(8)) version=read(vlen) # Jim says: "It's just not worth the bother." #if vndexpos(version, 0) != pv: # panic("%s incorrect previous version pointer at %s", # name, pos) vindex[version]=pos if pos+dlen > tend or tloc != tpos: panic("%s data record exceeds transaction record at %s", name, pos) if indexpos(oid,0) != prev: panic("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: panic("%s data records don't add up at %s",name,tpos) # Read the (intentionally redundant) transaction length seek(pos) h=read(8) if h != stl: panic("%s redundant transaction length check failed at %s", name, pos) pos=pos+8 for oid, p in tindex: maxoid=max(maxoid,oid) index[oid]=p # Record the position del tindex[:] _checkVindex(file, index, vindex) return pos, maxoid, ltid
|
pos=pos+8
|
pos=tend+8
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8): indexpos=index.get vndexpos=vindex.get tappend=tindex.append read=file.read seek=file.seek seek(0,2) file_size=file.tell() seek(0) if file_size: if file_size < 4: raise FileStorageFormatError, file.name if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) pos=4 unpack=struct.unpack tpos=0 maxoid=ltid=z64 tid='\0'*7+'\1' while 1: # Read the transaction record h=read(23) if not h: break if len(h) != 23: warn('%s truncated at %s', name, pos) seek(pos) file.truncate() break tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if el < 0: el=t32-el if tid <= ltid: warn("%s time-stamp reduction at %s", name, pos) ltid=tid tl=u64(stl) if tl+pos+8 > file_size: # Hm, the data were truncated. They may also be corrupted, # in which case, we don't want to totally lose the data. warn("%s truncated, possibly due to damaged records at %s", name, pos) try: i=0 while 1: if os.path.exists('%s.tr%s' % (name, i)): i=i+1 else: o=open('%s.tr%s' % (name, i),'wb') seek(pos) cp(file, o, file_size-pos) o.close() break except: error("couldn\'t write truncated data for %s", name) raise POSException.StorageSystemError, ( "Couldn't save truncated data") seek(pos) file.truncate() break if status not in ' up': warn('%s has invalid status, %s, at %s', name, status, pos) if ul > tl or dl > tl or el > tl: panic('%s has invalid transaction header at %s', name, pos) if tid >= stop: break tpos=pos tend=tpos+tl if status=='u': # Undone transaction, skip it pos=tpos+tl seek(pos) h=read(8) if h != stl: panic('%s has inconsistent transaction length at %s', name, pos) pos=pos+8 continue pos=tpos+23+ul+dl+el while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) prev=u64(sprev) tloc=u64(stloc) plen=u64(splen) dlen=42+(plen or 8) tappend((oid,pos)) if vlen: dlen=dlen+16+vlen seek(8,1) pv=u64(read(8)) version=read(vlen) # Jim says: "It's just not worth the bother." #if vndexpos(version, 0) != pv: # panic("%s incorrect previous version pointer at %s", # name, pos) vindex[version]=pos if pos+dlen > tend or tloc != tpos: panic("%s data record exceeds transaction record at %s", name, pos) if indexpos(oid,0) != prev: panic("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: panic("%s data records don't add up at %s",name,tpos) # Read the (intentionally redundant) transaction length seek(pos) h=read(8) if h != stl: panic("%s redundant transaction length check failed at %s", name, pos) pos=pos+8 for oid, p in tindex: maxoid=max(maxoid,oid) index[oid]=p # Record the position del tindex[:] _checkVindex(file, index, vindex) return pos, maxoid, ltid
|
if indexpos(oid,0) != prev:
|
if index_get(oid,0) != prev:
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8): indexpos=index.get vndexpos=vindex.get tappend=tindex.append read=file.read seek=file.seek seek(0,2) file_size=file.tell() seek(0) if file_size: if file_size < 4: raise FileStorageFormatError, file.name if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) pos=4 unpack=struct.unpack tpos=0 maxoid=ltid=z64 tid='\0'*7+'\1' while 1: # Read the transaction record h=read(23) if not h: break if len(h) != 23: warn('%s truncated at %s', name, pos) seek(pos) file.truncate() break tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if el < 0: el=t32-el if tid <= ltid: warn("%s time-stamp reduction at %s", name, pos) ltid=tid tl=u64(stl) if tl+pos+8 > file_size: # Hm, the data were truncated. They may also be corrupted, # in which case, we don't want to totally lose the data. warn("%s truncated, possibly due to damaged records at %s", name, pos) try: i=0 while 1: if os.path.exists('%s.tr%s' % (name, i)): i=i+1 else: o=open('%s.tr%s' % (name, i),'wb') seek(pos) cp(file, o, file_size-pos) o.close() break except: error("couldn\'t write truncated data for %s", name) raise POSException.StorageSystemError, ( "Couldn't save truncated data") seek(pos) file.truncate() break if status not in ' up': warn('%s has invalid status, %s, at %s', name, status, pos) if ul > tl or dl > tl or el > tl: panic('%s has invalid transaction header at %s', name, pos) if tid >= stop: break tpos=pos tend=tpos+tl if status=='u': # Undone transaction, skip it pos=tpos+tl seek(pos) h=read(8) if h != stl: panic('%s has inconsistent transaction length at %s', name, pos) pos=pos+8 continue pos=tpos+23+ul+dl+el while pos < tend: # Read the data records for this transaction seek(pos) h=read(42) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) prev=u64(sprev) tloc=u64(stloc) plen=u64(splen) dlen=42+(plen or 8) tappend((oid,pos)) if vlen: dlen=dlen+16+vlen seek(8,1) pv=u64(read(8)) version=read(vlen) # Jim says: "It's just not worth the bother." #if vndexpos(version, 0) != pv: # panic("%s incorrect previous version pointer at %s", # name, pos) vindex[version]=pos if pos+dlen > tend or tloc != tpos: panic("%s data record exceeds transaction record at %s", name, pos) if indexpos(oid,0) != prev: panic("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: panic("%s data records don't add up at %s",name,tpos) # Read the (intentionally redundant) transaction length seek(pos) h=read(8) if h != stl: panic("%s redundant transaction length check failed at %s", name, pos) pos=pos+8 for oid, p in tindex: maxoid=max(maxoid,oid) index[oid]=p # Record the position del tindex[:] _checkVindex(file, index, vindex) return pos, maxoid, ltid
|
pos = 4
|
pos = 4L
|
def recover(inp, outp, verbose=0, partial=0, force=0, pack=0): print "Recovering", inp, "into", outp if os.path.exists(outp) and not force: die("%s exists" % outp) f = open(inp, "rb") if f.read(4) != ZODB.FileStorage.packed_version: die("input is not a file storage") f.seek(0,2) file_size = f.tell() ofs = ZODB.FileStorage.FileStorage(outp, create=1) _ts = None ok = 1 prog1 = 0 undone = 0 pos = 4 ltid = None while pos: try: npos, txn, tid = read_txn_header(f, pos, file_size, outp, ltid) except EOFError: break except (KeyboardInterrupt, SystemExit): raise except Exception, err: print "error reading txn header:", err if not verbose: progress(prog1) pos = scan(f, pos) if verbose > 1: print "looking for valid txn header at", pos continue ltid = tid if txn is None: undone = undone + npos - pos pos = npos continue else: pos = npos tid = txn.tid if _ts is None: _ts = TimeStamp(tid) else: t = TimeStamp(tid) if t <= _ts: if ok: print ("Time stamps out of order %s, %s" % (_ts, t)) ok = 0 _ts = t.laterThan(_ts) tid = `_ts` else: _ts = t if not ok: print ("Time stamps back in order %s" % (t)) ok = 1 ofs.tpc_begin(txn, tid, txn.status) if verbose: print "begin", pos, _ts, if verbose > 1: print sys.stdout.flush() nrec = 0 try: for r in txn: if verbose > 1: if r.data is None: l = "bp" else: l = len(r.data) print "%7d %s %s" % (u64(r.oid), l, r.version) s = ofs.restore(r.oid, r.serial, r.data, r.version, r.data_txn, txn) nrec += 1 except (KeyboardInterrupt, SystemExit): raise except Exception, err: if partial and nrec: ofs._status = "p" ofs.tpc_vote(txn) ofs.tpc_finish(txn) if verbose: print "partial" else: ofs.tpc_abort(txn) print "error copying transaction:", err if not verbose: progress(prog1) pos = scan(f, pos) if verbose > 1: print "looking for valid txn header at", pos else: ofs.tpc_vote(txn) ofs.tpc_finish(txn) if verbose: print "finish" sys.stdout.flush() if not verbose: prog = pos * 20l / file_size while prog > prog1: prog1 = prog1 + 1 iprogress(prog1) bad = file_size - undone - ofs._pos print "\n%s bytes removed during recovery" % bad if undone: print "%s bytes of undone transaction data were skipped" % undone if pack is not None: print "Packing ..." from ZODB.referencesf import referencesf ofs.pack(pack, referencesf) ofs.close()
|
"src/ZEO/runzeo.py", "src/ZEO/zeopasswd.py", "src/ZEO/mkzeoinst.py", "src/ZEO/zeoctl.py",
|
def BTreeExtension(flavor): key = flavor[0] value = flavor[1] name = "BTrees._%sBTree" % flavor sources = ["src/BTrees/_%sBTree.c" % flavor] kwargs = {"include_dirs": include} if flavor != "fs": kwargs["depends"] = (base_btrees_depends + [KEY_H % _flavors[key], VALUE_H % _flavors[value]]) if key != "O": kwargs["define_macros"] = [('EXCLUDE_INTSET_SUPPORT', None)] return Extension(name, sources, **kwargs)
|
|
self.strategy.tpc_abort()
|
strategy = self.strategy strategy.tpc_abort()
|
def tpc_abort(self, id): if not self._check_tid(id): return self.strategy.tpc_abort() self._transaction = None self.strategy = None self._handle_waiting()
|
self._handle_waiting()
|
if isinstance(strategy, ImmediateCommitStrategy): self._handle_waiting()
|
def tpc_abort(self, id): if not self._check_tid(id): return self.strategy.tpc_abort() self._transaction = None self.strategy = None self._handle_waiting()
|
'opened': c._opened and ctime(c._opened),
|
'opened': o and ("%s (%.2fs)" % (ctime(o), t-o)),
|
def connectionDebugInfo(self): r=[] pools,pooll=self._pools for version, (pool, allocated, lock) in pools.items(): for c in allocated: r.append({ 'opened': c._opened and ctime(c._opened), 'info': c._debug_info, 'version': version, }) return r
|
class ISized(ICollection): def __len__(): """Return the number of items in the set""" class IReadSequence(Interface.Base): def __getitem__(index): """Return an item for a given index."""
|
class IReadSequence(Interface.Standard.Sequence):
|
def __nonzero__(): """Check if the collection is non-empty.
|
class IKeySequence(IKeyed, ISized):
|
class IKeySequence(IKeyed, Interface.Standard.Sized):
|
def update(seq): """Add the items from the given sequence to the set"""
|
class IDictionaryIsh(IKeyed, ISized): def __getitem__(key): """Get the value for the given key Raise a key error if the key if not in the collection. """ def get(key, default=None): """Get the value for the given key Raise a key error if the key if not in the collection and no default is specified. Return the default if specified and the key is not in the collection. """ def __setitem__(key, value): """Set the value for the given key""" def __delitem__(key): """delete the value for the given key Raise a key error if the key if not in the collection."""
|
class IDictionaryIsh(IKeyed, Interface.Standard.MinimalDictionary):
|
def __getitem__(index): """Return the key in the given index position
|
class IMerge(Interfaces.Base):
|
class IMerge(Interface.Base):
|
def insert(key, value): """Insert a key and value into the collection.
|
Interface.assertTypeImplements(OOBTree.OOSet, ISet) Interface.assertTypeImplements(OOBTree.OOTreeSet, ITreeSet) Interface.assertTypeImplements(OOBTree.OOBucket, IDictionaryIsh) Interface.assertTypeImplements(OOBTree.OOBTree, IBTree)
|
OOBTree.OOSet.__implements__=ISet OOBTree.OOTreeSet.__implements__=ITreeSet OOBTree.OOBucket.__implements__=IDictionaryIsh OOBTree.OOBTree.__implements__=IBTree
|
def weightedIntersection(c1, c2, weight1=1, weight2=1): """Compute the weighted intersection of c1 and c2.
|
class FileStorageError: pass class FileStorageFormatError(FileStorageError, POSException.StorageError):
|
class FileStorageError(POSException.StorageError): pass class FileStorageFormatError(FileStorageError):
|
def panic(message, *data): message=message%data LOG('ZODB FS',PANIC,"%s ERROR: %s\n" % (packed_version, message)) raise CorruptedTransactionError, message
|
file.seek(16,1)
|
nv = read(8) != z64 file.seek(8,1)
|
def _loada(self, oid, _index, file): "Read any version and return the version" pos=_index[oid] file.seek(pos) read=file.read h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if vlen: file.seek(16,1) version=read(vlen) else: version=''
|
if plen != z64: return read(u64(plen)), version return _loadBack(file, oid, read(8))[0], version
|
nv=0 if plen != z64: return read(u64(plen)), version, nv return _loadBack(file, oid, read(8))[0], version, nv
|
def _loada(self, oid, _index, file): "Read any version and return the version" pos=_index[oid] file.seek(pos) read=file.read h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if vlen: file.seek(16,1) version=read(vlen) else: version=''
|
p, v = _loada(oid, index, file)
|
p, v, nv = _loada(oid, index, file)
|
def pack(self, t, referencesf): """Copy data from the current database file to a packed file Non-current records from transactions with time-stamp strings less than packtss are ommitted. As are all undone records. Also, data back pointers that point before packtss are resolved and the associated data are copied, since the old records are not copied. """
|
if v:
|
if nv:
|
def pack(self, t, referencesf): """Copy data from the current database file to a packed file Non-current records from transactions with time-stamp strings less than packtss are ommitted. As are all undone records. Also, data back pointers that point before packtss are resolved and the associated data are copied, since the old records are not copied. """
|
def checkMultiStorageTransaction(self):
|
def NOcheckMultiStorageTransaction(self):
|
def checkMultiStorageTransaction(self): # Configuration parameters (larger values mean more likely deadlocks) N = 2 # These don't *have* to be all the same, but it's convenient this way self.nservers = N self.nthreads = N self.ntrans = N self.nobj = N
|
if verbose:
|
if verbose or code in (0x00, 0x70):
|
def main(): # Parse options verbose = 0 dostats = 1 try: opts, args = getopt.getopt(sys.argv[1:], "vS") except getopt.error, msg: usage(msg) return 2 for o, a in opts: if o == "-v": verbose = 1 if o == "-S": dostats = 0 verbose = 1 if len(args) != 1: usage("exactly one file argument required") return 2 filename = args[0] # Open file try: f = open(filename, "rb") except IOError, msg: print "can't open %s: %s" % (filename, msg) return 1 # Read file, gathering statistics, and printing each record if verbose rt0 = time.time() bycode = {} records = 0 versions = 0 t0 = te = None datarecords = 0 datasize = 0L file0 = file1 = 0 while 1: r = f.read(24) if len(r) < 24: break records += 1 ts, code, oid, serial = struct.unpack(">ii8s8s", r) if t0 is None: t0 = ts te = ts dlen, code = code & 0x7fffff00, code & 0xff if dlen: datarecords += 1 datasize += dlen version = '-' if code & 0x80: version = 'V' versions += 1 current = code & 1 if current: file1 += 1 else: file0 += 1 code = code & 0x7e bycode[code] = bycode.get(code, 0) + 1 if verbose: print "%s %d %02x %016x %016x %1s %s" % ( time.ctime(ts)[4:-5], current, code, U64(oid), U64(serial), version, dlen and str(dlen) or "") bytes = f.tell() f.close() rte = time.time() # Error if nothing was read if not records: print >>sys.stderr, "No records processed" return 1 # Print statistics if dostats: if verbose: print print "Read %s records (%s bytes) in %.1f seconds" % ( addcommas(records), addcommas(bytes), rte-rt0) print "Version: %s records" % addcommas(versions) print "First time: %s" % time.ctime(t0) print "Last time: %s" % time.ctime(te) print "Duration: %s seconds" % addcommas(te-t0) print "File stats: %s in file 0; %s in file 1" % ( addcommas(file0), addcommas(file1)) print "Data recs: %s (%.1f%%), average size %.1f KB" % ( addcommas(datarecords), 100.0 * datarecords / records, datasize / 1024.0 / datarecords) print codes = bycode.keys() codes.sort() print "%13s %4s %s" % ("Count", "Code", "Function (action)") for code in codes: print "%13s %02x %s" % ( addcommas(bycode.get(code, 0)), code, explain.get(code) or "*** unknown code ***")
|
if verbose: print
|
print
|
def main(): # Parse options verbose = 0 dostats = 1 try: opts, args = getopt.getopt(sys.argv[1:], "vS") except getopt.error, msg: usage(msg) return 2 for o, a in opts: if o == "-v": verbose = 1 if o == "-S": dostats = 0 verbose = 1 if len(args) != 1: usage("exactly one file argument required") return 2 filename = args[0] # Open file try: f = open(filename, "rb") except IOError, msg: print "can't open %s: %s" % (filename, msg) return 1 # Read file, gathering statistics, and printing each record if verbose rt0 = time.time() bycode = {} records = 0 versions = 0 t0 = te = None datarecords = 0 datasize = 0L file0 = file1 = 0 while 1: r = f.read(24) if len(r) < 24: break records += 1 ts, code, oid, serial = struct.unpack(">ii8s8s", r) if t0 is None: t0 = ts te = ts dlen, code = code & 0x7fffff00, code & 0xff if dlen: datarecords += 1 datasize += dlen version = '-' if code & 0x80: version = 'V' versions += 1 current = code & 1 if current: file1 += 1 else: file0 += 1 code = code & 0x7e bycode[code] = bycode.get(code, 0) + 1 if verbose: print "%s %d %02x %016x %016x %1s %s" % ( time.ctime(ts)[4:-5], current, code, U64(oid), U64(serial), version, dlen and str(dlen) or "") bytes = f.tell() f.close() rte = time.time() # Error if nothing was read if not records: print >>sys.stderr, "No records processed" return 1 # Print statistics if dostats: if verbose: print print "Read %s records (%s bytes) in %.1f seconds" % ( addcommas(records), addcommas(bytes), rte-rt0) print "Version: %s records" % addcommas(versions) print "First time: %s" % time.ctime(t0) print "Last time: %s" % time.ctime(te) print "Duration: %s seconds" % addcommas(te-t0) print "File stats: %s in file 0; %s in file 1" % ( addcommas(file0), addcommas(file1)) print "Data recs: %s (%.1f%%), average size %.1f KB" % ( addcommas(datarecords), 100.0 * datarecords / records, datasize / 1024.0 / datarecords) print codes = bycode.keys() codes.sort() print "%13s %4s %s" % ("Count", "Code", "Function (action)") for code in codes: print "%13s %02x %s" % ( addcommas(bycode.get(code, 0)), code, explain.get(code) or "*** unknown code ***")
|
h, v = unpack(">II", s)
|
h, v = struct.unpack(">II", s)
|
def U64(s): h, v = unpack(">II", s) return (long(h) << 32) + v
|
s.connect(('', 42000))
|
s.connect(('localhost', 42000))
|
def get_monitor_output(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('', 42000)) L = [] while 1: buf = s.recv(8192) if buf: L.append(buf) else: break s.close() return "".join(L)
|
"""Insert a key and value into the colelction.
|
"""Insert a key and value into the collection.
|
def insert(key, value): """Insert a key and value into the colelction.
|
zLOG.LOG('ZEO Server', zLOG.INFO, 'Serving %s:\t%s' % kv)
|
LOG('ZEO Server', INFO, 'Serving %s:\t%s' % kv)
|
def handler(signum, frame, storages=storages, die=signal.SIGTERM): for storage in storages.values(): try: storage.close() finally: pass if signum==dir: sys.exit(0) else: sys.exit(1)
|
auth_filename=self.options.auth_database,
|
auth_database=self.options.auth_database,
|
def create_server(self): from ZEO.StorageServer import StorageServer self.server = StorageServer( self.options.address, self.storages, read_only=self.options.read_only, invalidation_queue_size=self.options.invalidation_queue_size, transaction_timeout=self.options.transaction_timeout, monitor_address=self.options.monitor_address, auth_protocol=self.options.auth_protocol, auth_filename=self.options.auth_database, # XXX option spelling auth_realm=self.options.auth_realm)
|
def testReadConflictIgnored(self):
|
def checkReadConflictIgnored(self):
|
def testReadConflictIgnored(self): # Test that an application that catches a read conflict and # continues can not commit the transaction later. root = self._db.open().root() root["real_data"] = real_data = PersistentDict() root["index"] = index = PersistentDict()
|
root["real_data"] = real_data = PersistentDict() root["index"] = index = PersistentDict() real_data["a"] = PersistentDict({"indexed_value": 0}) real_data["b"] = PersistentDict({"indexed_value": 1}) index[1] = PersistentDict({"b": 1}) index[0] = PersistentDict({"a": 1})
|
root["real_data"] = real_data = PersistentMapping() root["index"] = index = PersistentMapping() real_data["a"] = PersistentMapping({"indexed_value": 0}) real_data["b"] = PersistentMapping({"indexed_value": 1}) index[1] = PersistentMapping({"b": 1}) index[0] = PersistentMapping({"a": 1})
|
def testReadConflictIgnored(self): # Test that an application that catches a read conflict and # continues can not commit the transaction later. root = self._db.open().root() root["real_data"] = real_data = PersistentDict() root["index"] = index = PersistentDict()
|
cn2.getTransaction().commit()
|
get_transaction().commit()
|
def testReadConflictIgnored(self): # Test that an application that catches a read conflict and # continues can not commit the transaction later. root = self._db.open().root() root["real_data"] = real_data = PersistentDict() root["index"] = index = PersistentDict()
|
self.assertRaises(ConflictError, get_transaction().commit)
|
self.assertRaises(ConflictError, cn2.getTransaction().commit)
|
def testReadConflictIgnored(self): # Test that an application that catches a read conflict and # continues can not commit the transaction later. root = self._db.open().root() root["real_data"] = real_data = PersistentDict() root["index"] = index = PersistentDict()
|
self.sub1._p_jar = SubTransactionJar(errors='tpc_finish') self.nosub1.modify() self.sub1.modify(nojar=1)
|
for sub in self.sub1, self.sub2: sub._p_jar = SubTransactionJar(errors='tpc_finish') sub.modify(nojar=1) self.nosub1.modify()
|
def testExceptionInTpcFinish(self):
|
self.sub1._p_jar = SubTransactionJar(errors='tpc_finish') self.nosub1.modify() self.sub1.modify(nojar=1)
|
for sub in self.sub1, self.sub2: sub._p_jar = SubTransactionJar(errors='tpc_finish') sub.modify(nojar=1) self.nosub1.modify()
|
def testHoserStoppage(self):
|
has_mac = 0
|
def handle_read(self): self.__input_lock.acquire() try: # Use a single __inp buffer and integer indexes to make this fast. try: d = self.recv(8192) except socket.error, err: if err[0] in expected_socket_read_errors: return raise if not d: return
|
|
self.locked = True
|
self.locked = 1
|
def pack(self): # Pack copies all data reachable at the pack time or later. # # Copying occurs in two phases. In the first phase, txns # before the pack time are copied if the contain any reachable # data. In the second phase, all txns after the pack time # are copied. # # Txn and data records contain pointers to previous records. # Because these pointers are stored as file offsets, they # must be updated when we copy data. # XXX Need to add sanity checking to pack
|
(self.tid, length, self.status, self.user_len, self.descr_len,
|
(self.tid, self.length, self.status, self.user_len, self.descr_len,
|
def _read_header(self): self._file.seek(self._pos) self._hdr = self._file.read(TRANS_HDR_LEN) (self.tid, length, self.status, self.user_len, self.descr_len, self.ext_len) = struct.unpack(TRANS_HDR, self._hdr) self.length = u64(length)
|
self.length = u64(length)
|
def _read_header(self): self._file.seek(self._pos) self._hdr = self._file.read(TRANS_HDR_LEN) (self.tid, length, self.status, self.user_len, self.descr_len, self.ext_len) = struct.unpack(TRANS_HDR, self._hdr) self.length = u64(length)
|
|
def main():
|
def test_suite():
|
def main(): TIOBTree = makeSuite(TestIOBTrees, 'test') TOOBTree = makeSuite(TestOOBTrees, 'test') TOIBTree = makeSuite(TestOIBTrees, 'test') TIIBTree = makeSuite(TestIIBTrees, 'test') TIOSet = makeSuite(TestIOSets, 'test') TOOSet = makeSuite(TestOOSets, 'test') TOISet = makeSuite(TestIOSets, 'test') TIISet = makeSuite(TestOOSets, 'test') TIOTreeSet = makeSuite(TestIOTreeSets, 'test') TOOTreeSet = makeSuite(TestOOTreeSets, 'test') TOITreeSet = makeSuite(TestIOTreeSets, 'test') TIITreeSet = makeSuite(TestOOTreeSets, 'test') TIOBucket = makeSuite(TestIOBuckets, 'test') TOOBucket = makeSuite(TestOOBuckets, 'test') TOIBucket = makeSuite(TestOIBuckets, 'test') TIIBucket = makeSuite(TestIIBuckets, 'test') alltests = TestSuite((TIOSet, TOOSet, TOISet, TIISet, TIOTreeSet, TOOTreeSet, TOITreeSet, TIITreeSet, TIOBucket, TOOBucket, TOIBucket, TIIBucket, TOOBTree, TIOBTree, TOIBTree, TIIBTree)) runner = TextTestRunner() runner.run(alltests)
|
l = filter(lambda x, l1=l1: x not in l1, l2) l = l + filter(lambda x, l2=l2: x not in l2, l1) return l
|
l1=list(l1) l2=list(l2) l = filter(lambda x, l1=l1: x not in l1, l2) l = l + filter(lambda x, l2=l2: x not in l2, l1) return l
|
def lsubtract(l1, l2): l = filter(lambda x, l1=l1: x not in l1, l2) l = l + filter(lambda x, l2=l2: x not in l2, l1) return l
|
if __name__ == '__main__': main()
|
if __name__=='__main__': if len(sys.argv) > 1: globals()[sys.argv[1]]() else: main()
|
def realseq(itemsob): return map(lambda x: x, itemsob)
|
assert root['t'] == t
|
assert list(root['t'].items()) == list(t.items())
|
def testLoadAndStore(self): t = self.t try: root = self._getRoot() root['t'] = t get_transaction().commit() except: self._closeDB(root) self._delDB() raise
|
assert root['t'] == t
|
assert list(root['t'].items()) == list(t.items())
|
def testGhostUnghost(self): t = self.t try: root = self._getRoot() root['t'] = t get_transaction().commit() except: self._closeDB(root) self._delDB() raise
|
assert len(t) == 1000, len(t)
|
assert len(t) == 10000, len(t)
|
def testLen(self): # should sets know their length? t = self.t r = xrange(10000) for x in r: t.insert(x) assert len(t) == 1000, len(t)
|
ext = dumps(ext,1)
|
ext = cPickle.dumps(ext, 1)
|
def tpc_begin(self, transaction, tid=None, status=' '): if self._is_read_only: raise POSException.ReadOnlyError() self._lock_acquire() try: if self._transaction is transaction: return self._lock_release() self._commit_lock_acquire() self._lock_acquire() self._transaction = transaction self._clear_temp()
|
already_pickled=0):
|
already_pickled=0, user=None, description=None):
|
def _dostore(self, oid=None, revid=None, data=None, version=None, already_pickled=0): """Do a complete storage transaction. The defaults are: - oid=None, ask the storage for a new oid - revid=None, use a revid of ZERO - data=None, pickle up some arbitrary data (the integer 7) - version=None, use the empty string version Returns the object's new revision id. """ if oid is None: oid = self._storage.new_oid() if revid is None: revid = ZERO if data is None: data = MinPO(7) if type(data) == types.IntType: data = MinPO(data) if not already_pickled: data = zodb_pickle(data) if version is None: version = '' # Begin the transaction t = Transaction() self._storage.tpc_begin(t) # Store an object r1 = self._storage.store(oid, revid, data, version, t) # Finish the transaction r2 = self._storage.tpc_vote(t) self._storage.tpc_finish(t) return handle_serials(oid, r1, r2)
|
truncate(f, pos, file_size, output)
|
truncate(f, pos, file_size, outp)
|
def read_txn_header(f, pos, file_size, outp, ltid): # Read the transaction record f.seek(pos) h = f.read(23) if len(h) < 23: raise EOFError tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if el < 0: el=t32-el tl = u64(stl) if pos + (tl + 8) > file_size: error("bad transaction length at %s", pos) if tl < (23 + ul + dl + el): error("invalid transaction length, %s, at %s", tl, pos) if ltid and tid < ltid: error("time-stamp reducation %s < %s, at %s", u64(tid), u64(ltid), pos) if status == "c": truncate(f, pos, file_size, output) raise EOFError if status not in " up": error("invalid status, %r, at %s", status, pos) tpos = pos tend = tpos + tl if status == "u": # Undone transaction, skip it f.seek(tend) h = f.read(8) if h != stl: error("inconsistent transaction length at %s", pos) pos = tend + 8 return pos, None, tid pos = tpos+(23+ul+dl+el) user = f.read(ul) description = f.read(dl) if el: try: e=loads(f.read(el)) except: e={} else: e={} result = RecordIterator(tid, status, user, description, e, pos, tend, f, tpos) pos = tend # Read the (intentionally redundant) transaction length f.seek(pos) h = f.read(8) if h != stl: error("redundant transaction length check failed at %s", pos) pos += 8 return pos, result, tid
|
print __doc__ % argv[0]
|
print __doc__ % sys.argv[0]
|
def main(): try: opts, (inp, outp) = getopt.getopt(sys.argv[1:], "fv:pP:") except getopt.error: die() print __doc__ % argv[0] force = partial = verbose = 0 pack = None for opt, v in opts: if opt == "-v": verbose = int(v) elif opt == "-p": partial = 1 elif opt == "-f": force = 1 elif opt == "-P": pack = time.time() - float(v) recover(inp, outp, verbose, partial, force, pack)
|
prepare_ok = False
|
raise AbortError(r)
|
def commit(self, txn): # commit calls _finishCommit() or abort() assert txn._status is Status.ACTIVE txn._status = Status.PREPARING prepare_ok = True self.logger.debug("%s: prepare", txn) try: for r in txn._resources: if prepare_ok and not r.prepare(txn): prepare_ok = False except: txn._status = Status.FAILED raise txn._status = Status.PREPARED # XXX An error below is intolerable. What state to use? if prepare_ok: self._finishCommit(txn) else: self.abort(txn)
|
if prepare_ok: self._finishCommit(txn) else: self.abort(txn)
|
self._finishCommit(txn)
|
def commit(self, txn): # commit calls _finishCommit() or abort() assert txn._status is Status.ACTIVE txn._status = Status.PREPARING prepare_ok = True self.logger.debug("%s: prepare", txn) try: for r in txn._resources: if prepare_ok and not r.prepare(txn): prepare_ok = False except: txn._status = Status.FAILED raise txn._status = Status.PREPARED # XXX An error below is intolerable. What state to use? if prepare_ok: self._finishCommit(txn) else: self.abort(txn)
|
return Rollback([r.savepoint(txn) for r in txn._resources])
|
return Rollback(txn, [r.savepoint(txn) for r in txn._resources])
|
def savepoint(self, txn): self.logger.debug("%s: savepoint", txn) return Rollback([r.savepoint(txn) for r in txn._resources])
|
txn_factory = Transaction
|
def savepoint(self, txn): self.logger.debug("%s: savepoint", txn) return Rollback([r.savepoint(txn) for r in txn._resources])
|
|
txn = self.txn_factory(self) self.logger.debug("%s: begin", txn) return txn
|
if self._current is not None: self._current.abort() self._current = self.txn_factory(self) self.logger.debug("%s: begin", self._current) return self._current
|
def begin(self): txn = self.txn_factory(self) self.logger.debug("%s: begin", txn) return txn
|
def suspend(self, txn): if self._current != txn: raise TransactionError("Can't suspend transaction because " "it is not active") self._suspended.add(txn) self._current = None
|
def abort(self, txn): super(TransactionManager, self).abort(txn) self._current = None
|
|
def __init__(self, resources):
|
def __init__(self, txn, resources): self._txn = txn
|
def __init__(self, resources): self._resources = resources
|
if self._pool[tid] is txn:
|
if self._pool.get(tid) is txn:
|
def suspend(self, txn): tid = thread.get_ident() if self._pool[tid] is txn: self._suspend.add(txn) del self._pool[tid] else: raise TransactionError("txn %s not owned by thread %s" % (txn, tid))
|
close(self._f[current])
|
self._f[current].close()
|
def checkSize(self, size): # Make sure we aren't going to exceed the target size. # If we are, then flip the cache. if self._pos+size > self._limit: current=not self._current self._current=current if self._p[current] is not None: # Persistent cache file: # Note that due to permission madness, waaa, # we need to remove the old file before # we open the new one. Waaaaaaaaaa. if self._f[current] is not None: close(self._f[current]) try: os.remove(self._p[current]) except: pass self._f[current]=open(self._p[current],'w+b') else: # Temporary cache file: self._f[current] = tempfile.TemporaryFile(suffix='.zec') self._f[current].write(magic) self._pos=pos=4
|
transaction_id = base64.decodestring(transaction_id + '==\n') tid, tpos = transaction_id[:8], U64(transaction_id[8:])
|
tid = transaction_id[:8] oid = transaction_id[8:] if oid == '' or not self._index.has_key(oid): raise UndoError, 'Undoing a non-object affecting transaction' pos = self._index[oid]
|
def transactionalUndo(self, transaction_id, transaction): """Undo a transaction, given by transaction_id.
|
while 1: self._file.seek(pos) h = self._file.read(DATA_HDR_LEN) doid,serial,prev,tpos,vlen,plen = unpack('>8s8s8s8sH8s', h) tpos = U64(tpos) self._file.seek(tpos) thistid = self._file.read(8) if thistid == tid: break pos = U64(prev) if not pos: raise UndoError, 'Invalid undo transaction id'
|
def transactionalUndo(self, transaction_id, transaction): """Undo a transaction, given by transaction_id.
|
|
d={'id': encode(tid+p64(pos))[:22],
|
e = {} if el: try: e = loads(read(el)) except: pass next = read(8) if next == tl: id = tid else: id = tid + next d={'id': id,
|
def undoLog(self, first=0, last=-20, filter=None): if last < 0: last=first-last+1 self._lock_acquire() try: packt=self._packt if packt is None: raise UndoError( 'Undo is currently disabled for database maintenance.<p>') pos=self._pos if pos < 39: return [] file=self._file seek=file.seek read=file.read unpack=struct.unpack strip=string.strip encode=base64.encodestring r=[] append=r.append i=0 while i < last and pos > 39: seek(pos-8) pos=pos-U64(read(8))-8 seek(pos) h=read(TRANS_HDR_LEN) tid, tl, status, ul, dl, el = unpack(">8s8scHHH", h) if tid < packt: break if status != ' ': continue u=ul and read(ul) or '' d=dl and read(dl) or '' d={'id': encode(tid+p64(pos))[:22], 'time': TimeStamp(tid).timeTime(), 'user_name': u, 'description': d} if el: try: e=loads(read(el)) d.update(e) except: pass if filter is None or filter(d): if i >= first: append(d) i=i+1 return r finally: self._lock_release()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.