rem
stringlengths 0
322k
| add
stringlengths 0
2.05M
| context
stringlengths 8
228k
|
---|---|---|
'user_name': u, 'description': d} if el: try: e=loads(read(el)) d.update(e) except: pass
|
'user_name': u, 'description': d} d.update(e)
|
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()
|
oid=object._p_oid __traceback_info__=oid p, serial = self._storage.load(oid, self._version) file=StringIO(p) unpickler=Unpickler(file) unpickler.persistent_load=self._persistent_load copy = unpickler.load() klass, args = copy if klass is not ExtensionKlass: LOG('ZODB',ERROR, "Unexpected klass when setting class state on %s" % getattr(object,'__name__','(?)')) return copy=apply(klass,args) object.__dict__.clear() object.__dict__.update(copy.__dict__) object._p_oid=oid object._p_jar=self object._p_changed=None object._p_serial=serial
|
try: oid=object._p_oid __traceback_info__=oid p, serial = self._storage.load(oid, self._version) file=StringIO(p) unpickler=Unpickler(file) unpickler.persistent_load=self._persistent_load copy = unpickler.load() klass, args = copy if klass is not ExtensionKlass: LOG('ZODB',ERROR, "Unexpected klass when setting class state on %s" % getattr(object,'__name__','(?)')) return copy=apply(klass,args) object.__dict__.clear() object.__dict__.update(copy.__dict__) object._p_oid=oid object._p_jar=self object._p_changed=0 object._p_serial=serial except: LOG('ZODB',ERROR, 'setklassstate failed', error=sys.exc_info) raise
|
def setklassstate(self, object, tt=type(()), ct=type(HelperClass)): oid=object._p_oid __traceback_info__=oid p, serial = self._storage.load(oid, self._version) file=StringIO(p) unpickler=Unpickler(file) unpickler.persistent_load=self._persistent_load
|
print modulename, classname
|
def find_global(modulename, classname): """Helper for this test suite to get special PersistentMapping""" print modulename, classname if classname == "PersistentMapping": class PersistentMapping: def __setstate__(self, state): self.__dict__.update(state) return PersistentMapping else: __import__(modulename) mod = sys.modules[modulename] return getattr(mod, classname)
|
|
def log(message, level=zLOG.INFO, label="StorageServer:%s" % os.getpid(), error=None): zLOG.LOG(label, level, message, error=error)
|
_label = "ZSS" def set_label(): global _label _label = "ZSS:%s" % os.getpid() def log(message, level=zLOG.INFO, label=None, error=None): zLOG.LOG(label or _label, level, message, error=error)
|
def log(message, level=zLOG.INFO, label="StorageServer:%s" % os.getpid(), error=None): zLOG.LOG(label, level, message, error=error)
|
def _log(self, msg, level=zLOG.INFO, error=None, pid=os.getpid()):
|
def _log(self, msg, level=zLOG.INFO, error=None):
|
def _log(self, msg, level=zLOG.INFO, error=None, pid=os.getpid()): name = getattr(self.__storage, '__name__', None) if name is None: name = str(self.__storage) zLOG.LOG("ZEOStorage:%s:%s" % (pid, name), level, msg, error=error)
|
zLOG.LOG("ZEOStorage:%s:%s" % (pid, name), level, msg, error=error)
|
zLOG.LOG("%s:%s" % (_label, name), level, msg, error=error)
|
def _log(self, msg, level=zLOG.INFO, error=None, pid=os.getpid()): name = getattr(self.__storage, '__name__', None) if name is None: name = str(self.__storage) zLOG.LOG("ZEOStorage:%s:%s" % (pid, name), level, msg, error=error)
|
os.unlink(path)
|
need_to_delete = 1 for dummy in range(5): try: os.unlink(path) except: time.sleep(0.5) else: need_to_delete = 0 break if need_to_delete: os.unlink(path)
|
def tearDown(self): """Try to cause the tests to halt""" zLOG.LOG("testZEO", zLOG.INFO, "tearDown() %s" % self.id()) for p in self.conf_paths: os.remove(p) if getattr(self, '_storage', None) is not None: self._storage.close() if hasattr(self._storage, 'cleanup'): self._storage.cleanup() for adminaddr in self._servers: if adminaddr is not None: forker.shutdown_zeo_server(adminaddr) if hasattr(os, 'waitpid'): # Not in Windows Python until 2.3 for pid in self._pids: os.waitpid(pid, 0) for c in self.caches: for i in 0, 1: path = "c1-%s-%d.zec" % (c, i) if os.path.exists(path): os.unlink(path) self.__super_tearDown()
|
pool_lock.acquire()
|
if not pool_lock.acquire(0): result = DB.open(self, version, transaction, temporary, force, waitflag) self._a() return result
|
def open(self, version='', transaction=None, temporary=0, force=None, waitflag=1, mvcc=True, txn_mgr=None, synch=True): """Return a database Connection for use by application code.
|
c = pool[-1] del pool[-1]
|
c = pool.pop()
|
def open(self, version='', transaction=None, temporary=0, force=None, waitflag=1, mvcc=True, txn_mgr=None, synch=True): """Return a database Connection for use by application code.
|
import zLog.MinimalLogger zLog.MinimalLogger._log.initialize()
|
import zLOG.MinimalLogger zLOG.MinimalLogger._log.initialize()
|
def rotate_logs(): import zLOG # There hasn't been a clear way to reinitialize the MinimalLogger. # I'll checkin the public initialize() method soon, but also try some # other strategies for older Zope installs :-(. init = getattr(zLOG, 'initialize', None) if init is not None: init() return # This will work if the minimal logger is in use, but not if some # other logger is active. import zLog.MinimalLogger zLog.MinimalLogger._log.initialize()
|
"pwd module is not available." % uid))
|
"pwd module is not available." % arg))
|
def set_uid(arg): """Try to set uid and gid based on -u argument. This will only work if this script is run by root. """ try: import pwd except ImportError: LOG('ZEO/start.py', INFO, ("Can't set uid to %s." "pwd module is not available." % uid)) return try: gid = None try: arg = int(arg) except: # conversion could raise all sorts of errors uid = pwd.getpwnam(arg)[2] gid = pwd.getpwnam(arg)[3] else: uid = pwd.getpwuid(arg)[2] gid = pwd.getpwuid(arg)[3] if gid is not None: try: os.setgid(gid) except OSError: pass try: os.setuid(uid) except OSError: pass except KeyError: LOG('ZEO/start.py', ERROR, ("can't find uid %s" % arg))
|
self.__has_mac = True
|
self.__has_mac = 0
|
def __init__(self, sock, addr, map=None, debug=None): self.addr = addr if debug is not None: self._debug = debug elif not hasattr(self, '_debug'): self._debug = __debug__ # __input_lock protects __inp, __input_len, __state, __msg_size self.__input_lock = threading.Lock() self.__inp = None # None, a single String, or a list self.__input_len = 0 # Instance variables __state, __msg_size and __has_mac work together: # when __state == 0: # __msg_size == 4, and the next thing read is a message size; # __has_mac is set according to the MAC_BIT in the header # when __state == 1: # __msg_size is variable, and the next thing read is a message. # __has_mac indicates if we're in MAC mode or not (and # therefore, if we need to check the mac header) # The next thing read is always of length __msg_size. # The state alternates between 0 and 1. self.__state = 0 self.__has_mac = True self.__msg_size = 4 self.__output_lock = threading.Lock() # Protects __output self.__output = [] self.__closed = 0 # Each side of the connection sends and receives messages. A # MAC is generated for each message and depends on each # previous MAC; the state of the MAC generator depends on the # history of operations it has performed. So the MACs must be # generated in the same order they are verified.
|
resouces. The only works under Unix, and if ZServer is started by root.
|
resouces. The only works under Unix, and if the storage server is started by root.
|
def main(argv): me=argv[0] sys.path[:]==filter(None, sys.path) sys.path.insert(0, directory(me, 2)) args=[] last='' for a in argv[1:]: if (a[:1] != '-' and string.find(a, '=') > 0 and last != '-S' # lame, sorry ): a=string.split(a,'=') os.environ[a[0]]=string.join(a[1:],'=') continue args.append(a) last=a INSTANCE_HOME=os.environ.get('INSTANCE_HOME', directory(me, 4)) zeo_pid=os.environ.get('ZEO_SERVER_PID', os.path.join(INSTANCE_HOME, 'var', 'ZEO_SERVER.pid') ) opts, args = getopt.getopt(args, 'p:Dh:U:sS:u:') fs=os.path.join(INSTANCE_HOME, 'var', 'Data.fs') usage="""%s [options] [filename] where options are: -D -- Run in debug mode -U -- Unix-domain socket file to listen on -u username or uid number The username to run the ZEO server as. You may want to run the ZEO server as 'nobody' or some other user with limited resouces. The only works under Unix, and if ZServer is started by root. -p port -- port to listen on -h adddress -- host address to listen on -s -- Don't use zdeamon -S storage_name=module_path:attr_name -- A storage specification where: storage_name -- is the storage name used in the ZEO protocol. This is the name that you give as the optional 'storage' keyword argument to the ClientStorage constructor. module_path -- This is the path to a Python module that defines the storage object(s) to be served. The module path should ommit the prefix (e.g. '.py'). attr_name -- This is the name to which the storage object is assigned in the module. if no file name is specified, then %s is used. """ % (me, fs) port=None debug=0 host='' unix=None Z=1 UID='nobody' for o, v in opts: if o=='-p': port=string.atoi(v) elif o=='-h': host=v elif o=='-U': unix=v elif o=='-u': UID=v elif o=='-D': debug=1 elif o=='-s': Z=0 try: from ZServer.medusa import asyncore sys.modules['asyncore']=asyncore except: pass if port is None and unix is None: print usage print 'No port specified.' sys.exit(1) if args: if len(args) > 1: print usage print 'Unrecognizd arguments: ', string.join(args[1:]) sys.exit(1) fs=args[0] __builtins__.__debug__=debug if debug: os.environ['Z_DEBUG_MODE']='1' from zLOG import LOG, INFO, ERROR # Try to set uid to "-u" -provided uid. # Try to set gid to "-u" user's primary group. # This will only work if this script is run by root. try: import pwd try: try: UID=string.atoi(UID) except: pass gid = None if type(UID) == type(""): uid = pwd.getpwnam(UID)[2] gid = pwd.getpwnam(UID)[3] elif type(UID) == type(1): uid = pwd.getpwuid(UID)[2] gid = pwd.getpwuid(UID)[3] else: raise KeyError try: if gid is not None: try: os.setgid(gid) except OSError: pass os.setuid(uid) except OSError: pass except KeyError: LOG('ZEO Server', ERROR, ("can't find UID %s" % UID)) except: pass if Z: try: import posix except: pass else: import zdaemon zdaemon.run(sys.argv, '') import ZEO.StorageServer, asyncore storages={} for o, v in opts: if o=='-S': n, m = string.split(v,'=') if string.find(m,':'): # we got an attribute name m, a = string.split(m,':') else: # attribute name must be same as storage name a=n storages[n]=get_storage(m,a) if not storages: import ZODB.FileStorage storages['1']=ZODB.FileStorage.FileStorage(fs) # Try to set up a signal handler try: import signal signal.signal(signal.SIGTERM, lambda sig, frame, s=storages: shutdown(s) ) signal.signal(signal.SIGINT, lambda sig, frame, s=storages: shutdown(s, 0) ) signal.signal(signal.SIGHUP, rotate_logs_handler) finally: pass items=storages.items() items.sort() for kv in items: LOG('ZEO Server', INFO, 'Serving %s:\t%s' % kv) if not unix: unix=host, port ZEO.StorageServer.StorageServer(unix, storages) open(zeo_pid,'w').write("%s %s" % (os.getppid(), os.getpid())) asyncore.loop()
|
and call it to minotor the storage.
|
and call it to monitor the storage.
|
def info(RESPONSE): RESPONSE['Content-type']= 'text/plain'
|
__version__='$Revision: 1.6 $'[11:-2] import base64, POSException, BTree, BaseStorage, time, string, utils
|
__version__='$Revision: 1.7 $'[11:-2] import base64, time, string from ZODB import POSException, BaseStorage, utils
|
def info(RESPONSE): RESPONSE['Content-type']= 'text/plain'
|
self._data=BTree.BTree()
|
self._data=OOBTree.OOBTree()
|
def __init__(self, name='Demo Storage', base=None, quota=None):
|
tindex.append([oid, serial, r, None, p])
|
if dest: new_vdata = dest, vdata[1] else: new_vdata = None tindex.append([oid, serial, r, new_vdata, p])
|
def commitVersion(self, src, dest, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._lock_acquire() try: v=self._vindex.get(src, None) if v is None: return tindex=self._tindex oids=[] for r in v.values(): oid, serial, pre, vdata, p = r oids.append(oid) tindex.append([oid, serial, r, None, p])
|
try: oid, serial, pre, vdata, p = self._index[oid] except: if self._base: return self._base.load(oid, '')
|
try: oid, serial, pre, vdata, p = self._index[oid] except KeyError: if self._base: return self._base.load(oid, '')
|
def load(self, oid, version): self._lock_acquire() try: try: oid, serial, pre, vdata, p = self._index[oid] except: if self._base: return self._base.load(oid, '') raise KeyError, oid
|
if s > self._quota:
|
if self._quota is not None and s > self._quota:
|
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction)
|
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
|
r = [] for v in self._vindex.keys(): if self.versionEmpty(v): continue r.append(v) if max is not None and len(r) >= max: break
|
def versions(self, max=None): 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
|
if ((invalid(oid) and not hasattr(object, '_p_resolveConflict')) or invalid(None)):
|
if invalid(oid) and not hasattr(object, '_p_resolveConflict'):
|
def commit(self, object, transaction): if object is self: # We registered ourself. Execute a commit action, if any. if self.__onCommitActions is not None: method_name, args, kw = self.__onCommitActions.pop(0) apply(getattr(self, method_name), (transaction,) + args, kw) return oid = object._p_oid invalid = self._invalid if oid is None or object._p_jar is not self: # new object oid = self.new_oid() object._p_jar = self object._p_oid = oid self._creating.append(oid)
|
if ( (invalid(oid) and not hasattr(object, '_p_resolveConflict')) or invalid(None) ):
|
if invalid(oid) and not hasattr(object, '_p_resolveConflict'):
|
# def persistent_id(object,
|
invalid = self._invalid if invalid(oid) or invalid(None):
|
if self._invalid(oid):
|
def setstate(self, object): oid = object._p_oid
|
if self._invalid(None): raise ConflictError("transaction already invalidated")
|
def tpc_begin(self, transaction, sub=None): if self._invalid(None): # Some nitwit invalidated everything! raise ConflictError("transaction already invalidated") self._invalidating = [] self._creating = []
|
|
continue
|
def main(path): fs = FileStorage(path, read_only=1) noload = {} for oid in fs._index.keys(): try: data, serial = fs.load(oid, "") except: print "oid %s failed to load" % hex(u64(oid)) if VERBOSE: traceback.print_exc() noload[oid] = 1 # XXX If we get here after we've already loaded objects # that refer to this one, we won't get error reports from # them. We could fix this by making two passes over the # storage, but that seems like overkill. refs = get_refs(data) missing = [] # contains 3-tuples of oid, klass-metadata, reason for info in refs: try: ref, klass = info except (ValueError, TypeError): # failed to unpack ref = info klass = '<unknown>' if not fs._index.has_key(ref): missing.append((ref, klass, "missing")) if noload.has_key(ref): missing.append((ref, klass, "failed to load")) if missing: report(oid, data, serial, fs, missing)
|
|
level=zLOG.DEBUG)
|
level=zLOG.TRACE)
|
def message_input(self, message): """Decoding an incoming message and dispatch it""" # XXX Not sure what to do with errors that reach this level. # Need to catch ZRPCErrors in handle_reply() and # handle_request() so that they get back to the client. try: msgid, flags, name, args = self.marshal.decode(message) except DecodingError, msg: return self.return_error(None, None, DecodingError, msg)
|
log("send msg: %d, %d, %s, ..." % (msgid, flags, method))
|
log("send msg: %d, %d, %s, ..." % (msgid, flags, method), zLOG.TRACE)
|
def send_call(self, method, args, flags): # send a message and return its msgid self.__msgid_lock.acquire() try: msgid = self.msgid self.msgid = self.msgid + 1 finally: self.__msgid_lock.release() if __debug__: log("send msg: %d, %d, %s, ..." % (msgid, flags, method)) buf = self.marshal.encode(msgid, flags, method, args) self.message_output(buf) return msgid
|
if i < first: continue
|
if i < first: i = i+1 continue
|
def undoLog(self, first, last, filter=None): self._lock_acquire() try: packt=self._packt if packt is None: raise POSException.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 if i < first: continue seek(pos) h=read(23) 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): append(d) i=i+1 return r finally: self._lock_release()
|
def checkPackVersionsInPast(self): pass def checkPackAfterUndoDeletion(self): pass
|
def check_periodic_save_index(self):
|
|
tl=u64(rstl)
|
tl=U64(rstl)
|
def _sane(self, index, pos): """Sanity check saved index data by reading the last undone trans
|
opos=pos+23+ul+dl+el
|
opos=pos+(23+ul+dl+el)
|
def _sane(self, index, pos): """Sanity check saved index data by reading the last undone trans
|
tloc=u64(stloc) plen=u64(splen)
|
tloc=U64(stloc) plen=U64(splen)
|
def _sane(self, index, pos): """Sanity check saved index data by reading the last undone trans
|
if vlen: dlen=dlen+16+vlen
|
if vlen: dlen=dlen+(16+vlen)
|
def _sane(self, index, pos): """Sanity check saved index data by reading the last undone trans
|
pos=info.get('pos', None)
|
pos=long(info.get('pos', None))
|
def _restore_index(self): """Load the database index from a file to support quick startup """ file_name=self.__name__ index_name=file_name+'.index' try: f=open(index_name,'rb') except: return None p=Unpickler(f)
|
self._save_index()
|
try: self._save_index() except: pass
|
def close(self): self._file.close() self._lock_file.close() self._tfile.close() self._save_index()
|
here=tfile.tell()+self._pos+self._thl
|
here=self._pos+(tfile.tell()+self._thl)
|
def commitVersion(self, src, dest, transaction, abort=None): # We are going to commit by simply storing back pointers.
|
seek(u64(t)+16)
|
seek(U64(t)+16)
|
def commitVersion(self, src, dest, transaction, abort=None): # We are going to commit by simply storing back pointers.
|
srcpos=u64(spos)
|
srcpos=U64(spos)
|
def commitVersion(self, src, dest, transaction, abort=None): # We are going to commit by simply storing back pointers.
|
if plen != z64: return read(u64(plen)), version, nv
|
if plen != z64: return read(U64(plen)), 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: nv = read(8) != z64 file.seek(8,1) # Skip previous version record pointer version=read(vlen) else: version='' nv=0
|
if plen != z64: return read(u64(plen)), serial
|
if plen != z64: return read(U64(plen)), serial
|
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) # 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=u64(prev)
|
pos=U64(prev)
|
def loadSerial(self, oid, serial): self._lock_acquire() try: _index=self._index file=self._file seek=file.seek read=file.read pos=_index[oid] while 1: seek(pos) h=read(42) doid,dserial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if doid != oid: raise CorruptedDataError, h if dserial == serial: break # Yeee ha! # Keep looking for serial pos=u64(prev) if not pos: raise KeyError, serial continue
|
if plen != z64: return read(u64(plen))
|
if plen != z64: return read(U64(plen))
|
def loadSerial(self, oid, serial): self._lock_acquire() try: _index=self._index file=self._file seek=file.seek read=file.read pos=_index[oid] while 1: seek(pos) h=read(42) doid,dserial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if doid != oid: raise CorruptedDataError, h if dserial == serial: break # Yeee ha! # Keep looking for serial pos=u64(prev) if not pos: raise KeyError, serial continue
|
here=tfile.tell()+pos+self._thl
|
here=pos+(tfile.tell()+self._thl)
|
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction)
|
if quota is not None and tfile.tell()+pos+self._thl > quota:
|
if quota is not None and pos+(tfile.tell()+self._thl) > quota:
|
def store(self, oid, serial, data, version, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction)
|
self._nextpos=0 def tpc_vote(self, transaction): if transaction is not self._transaction: raise POSException.StorageTransactionError(self, transaction) self._lock_acquire() try: tfile=self._tfile dlen=tfile.tell() if not dlen: return file=self._file write=file.write tfile.seek(0) id=self._serial user, desc, ext = self._ude luser=len(user) ldesc=len(desc) lext=len(ext) if luser > 65535: raise FileStorageError, 'user name too long' if ldesc > 65535: raise FileStorageError, 'description too long' if lext > 65535: raise FileStorageError, 'too much extension data' tlen=self._thl pos=self._pos file.seek(pos) tl=tlen+dlen stl=p64(tl) try: write(pack( ">8s" "8s" "c" "H" "H" "H" ,id, stl, 'c', luser, ldesc, lext, )) if user: write(user) if desc: write(desc) if ext: write(ext) cp(tfile, file, dlen) write(stl) file.flush() except: file.truncate(pos) raise self._nextpos=pos+(tl+8) finally: self._lock_release()
|
def _begin(self, tid, u, d, e): self._thl=23+len(u)+len(d)+len(e)
|
|
tfile=self._tfile dlen=tfile.tell() if not dlen: return
|
def _finish(self, tid, u, d, e): tfile=self._tfile dlen=tfile.tell() if not dlen: return # No data in this trans file=self._file write=file.write tfile.seek(0) id=self._serial user, desc, ext = self._ude
|
|
write=file.write 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) try: write(pack( ">8s" "8s" "c" "H" "H" "H" ,id, stl, 'c', 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.seek(pos+16) write(self._tstatus) file.flush() if fsync is not None: fsync(file.fileno()) except: file.truncate(pos) self._pos=pos+tl+8
|
file.seek(self._pos+16) file.write(self._tstatus) file.flush() if fsync is not None: fsync(file.fileno()) self._pos=self._nextpos
|
def _finish(self, tid, u, d, e): tfile=self._tfile dlen=tfile.tell() if not dlen: return # No data in this trans file=self._file write=file.write tfile.seek(0) id=self._serial user, desc, ext = self._ude
|
tid, tpos = transaction_id[:8], u64(transaction_id[8:])
|
tid, tpos = transaction_id[:8], U64(transaction_id[8:])
|
def undo(self, transaction_id): self._lock_acquire() try: self._clear_index() 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>')
|
tl=u64(h[8:16])
|
tl=U64(h[8:16])
|
def undo(self, transaction_id): self._lock_acquire() try: self._clear_index() 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>')
|
pos=tpos+23+ul+dl+el
|
pos=tpos+(23+ul+dl+el)
|
def undo(self, transaction_id): self._lock_acquire() try: self._clear_index() 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>')
|
plen=u64(splen) prev=u64(sprev)
|
plen=U64(splen) prev=U64(sprev)
|
def undo(self, transaction_id): self._lock_acquire() try: self._clear_index() 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>')
|
if vlen: dlen=dlen+16+vlen
|
if vlen: dlen=dlen+(16+vlen)
|
def undo(self, transaction_id): self._lock_acquire() try: self._clear_index() 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>')
|
pos=pos-u64(read(8))-8
|
pos=pos-U64(read(8))-8
|
def undoLog(self, first, last, filter=None): self._lock_acquire() try: packt=self._packt if packt is None: raise POSException.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(23) 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()
|
seek(u64(t)+16)
|
seek(U64(t)+16)
|
def versionEmpty(self, version): 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) # serial, prev(oid), tloc, vlen, plen, pnv, pv tloc=h[16:24] if t != tloc: # We haven't checked this transaction before, # get it's status. t=tloc seek(u64(t)+16) tstatus=read(1)
|
srcpos=u64(spos)
|
srcpos=U64(spos)
|
def versionEmpty(self, version): 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) # serial, prev(oid), tloc, vlen, plen, pnv, pv tloc=h[16:24] if t != tloc: # We haven't checked this transaction before, # get it's status. t=tloc seek(u64(t)+16) tstatus=read(1)
|
prev=u64(prev)
|
prev=U64(prev)
|
def history(self, oid, version=None, length=1, filter=None): self._lock_acquire() try: r=[] file=self._file seek=file.seek read=file.read pos=self._index[oid] wantver=version
|
seek(u64(tloc))
|
seek(U64(tloc))
|
def history(self, oid, version=None, length=1, filter=None): self._lock_acquire() try: r=[] file=self._file seek=file.seek read=file.read pos=self._index[oid] wantver=version
|
if el < 0: el=t32-el
|
def history(self, oid, version=None, length=1, filter=None): self._lock_acquire() try: r=[] file=self._file seek=file.seek read=file.read pos=self._index[oid] wantver=version
|
|
d['size']=u64(plen)
|
d['size']=U64(plen)
|
def history(self, oid, version=None, length=1, filter=None): self._lock_acquire() try: r=[] file=self._file seek=file.seek read=file.read pos=self._index[oid] wantver=version
|
p=u64(file.read(8))
|
p=U64(file.read(8))
|
def _redundant_pack(self, file, pos): file.seek(pos-8) p=u64(file.read(8)) file.seek(pos-p+8) return file.read(1) not in ' u'
|
offset=0 pos=opos=4
|
offset=0L pos=opos=4L
|
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 el < 0: el=t32-el tl=u64(stl)
|
tl=U64(stl)
|
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. """
|
plen=u64(splen)
|
plen=U64(splen)
|
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. """
|
dlen=dlen+16+vlen
|
dlen=dlen+(16+vlen)
|
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. """
|
pnv=u64(read(8))
|
pnv=U64(read(8))
|
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. """
|
p=u64(p)
|
p=U64(p)
|
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 el < 0: el=t32-el tl=u64(stl)
|
tl=U64(stl)
|
def shift_transactions_forward(index, vindex, tindex, file, pos, opos): """Copy transactions forward in the data file This might be done as part of a recovery effort """ # Cache a bunch of methods seek=file.seek read=file.read write=file.write tappend=tindex.append index_get=index.get vindex_get=vindex.get # Initialize, pv=z64 p1=opos p2=pos offset=p2-p1 packpos=opos # Copy the data in two stages. In the packing stage, # we skip records that are non-current or that are for # unreferenced objects. We also skip undone transactions. # # After the packing stage, we copy everything but undone # transactions, however, we have to update various back pointers. # We have to have the storage lock in the second phase to keep # data from being changed while we're copying. pnv=None while 1: # Read the transaction record seek(pos) h=read(23) if len(h) < 23: break tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if status=='c': break # Oops. we found a checkpoint flag. if el < 0: el=t32-el tl=u64(stl) tpos=pos tend=tpos+tl otpos=opos # start pos of output trans thl=ul+dl+el h2=read(thl) if len(h2) != thl: raise 'Pack Error', opos # write out the transaction record seek(opos) write(h) write(h2) thl=23+thl pos=tpos+thl opos=otpos+thl 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) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen pnv=u64(read(8)) # skip position of previous version record seek(8,1) version=read(vlen) pv=p64(vindex_get(version, 0)) if status != 'u': vindex[version]=opos tappend((oid,opos)) if plen: p=read(plen) else: p=read(8) p=u64(p) if p >= p2: p=p-offset elif p >= p1: # Ick, we're in trouble. Let's bail # to the index and hope for the best p=index_get(oid,0) p=p64(p) # WRITE seek(opos) 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 >= p2: pnv=pnv-offset elif pnv >= p1: pnv=index_get(oid,0) write(p64(pnv)) write(pv) write(version) write(p) opos=opos+dlen pos=pos+dlen # skip the (intentionally redundant) transaction length pos=pos+8 if status != 'u': for oid, p in tindex: index[oid]=p # Record the position del tindex[:] write(stl) opos=opos+8 return opos
|
plen=u64(splen)
|
plen=U64(splen)
|
def shift_transactions_forward(index, vindex, tindex, file, pos, opos): """Copy transactions forward in the data file This might be done as part of a recovery effort """ # Cache a bunch of methods seek=file.seek read=file.read write=file.write tappend=tindex.append index_get=index.get vindex_get=vindex.get # Initialize, pv=z64 p1=opos p2=pos offset=p2-p1 packpos=opos # Copy the data in two stages. In the packing stage, # we skip records that are non-current or that are for # unreferenced objects. We also skip undone transactions. # # After the packing stage, we copy everything but undone # transactions, however, we have to update various back pointers. # We have to have the storage lock in the second phase to keep # data from being changed while we're copying. pnv=None while 1: # Read the transaction record seek(pos) h=read(23) if len(h) < 23: break tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if status=='c': break # Oops. we found a checkpoint flag. if el < 0: el=t32-el tl=u64(stl) tpos=pos tend=tpos+tl otpos=opos # start pos of output trans thl=ul+dl+el h2=read(thl) if len(h2) != thl: raise 'Pack Error', opos # write out the transaction record seek(opos) write(h) write(h2) thl=23+thl pos=tpos+thl opos=otpos+thl 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) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen pnv=u64(read(8)) # skip position of previous version record seek(8,1) version=read(vlen) pv=p64(vindex_get(version, 0)) if status != 'u': vindex[version]=opos tappend((oid,opos)) if plen: p=read(plen) else: p=read(8) p=u64(p) if p >= p2: p=p-offset elif p >= p1: # Ick, we're in trouble. Let's bail # to the index and hope for the best p=index_get(oid,0) p=p64(p) # WRITE seek(opos) 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 >= p2: pnv=pnv-offset elif pnv >= p1: pnv=index_get(oid,0) write(p64(pnv)) write(pv) write(version) write(p) opos=opos+dlen pos=pos+dlen # skip the (intentionally redundant) transaction length pos=pos+8 if status != 'u': for oid, p in tindex: index[oid]=p # Record the position del tindex[:] write(stl) opos=opos+8 return opos
|
dlen=dlen+16+vlen pnv=u64(read(8))
|
dlen=dlen+(16+vlen) pnv=U64(read(8))
|
def shift_transactions_forward(index, vindex, tindex, file, pos, opos): """Copy transactions forward in the data file This might be done as part of a recovery effort """ # Cache a bunch of methods seek=file.seek read=file.read write=file.write tappend=tindex.append index_get=index.get vindex_get=vindex.get # Initialize, pv=z64 p1=opos p2=pos offset=p2-p1 packpos=opos # Copy the data in two stages. In the packing stage, # we skip records that are non-current or that are for # unreferenced objects. We also skip undone transactions. # # After the packing stage, we copy everything but undone # transactions, however, we have to update various back pointers. # We have to have the storage lock in the second phase to keep # data from being changed while we're copying. pnv=None while 1: # Read the transaction record seek(pos) h=read(23) if len(h) < 23: break tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if status=='c': break # Oops. we found a checkpoint flag. if el < 0: el=t32-el tl=u64(stl) tpos=pos tend=tpos+tl otpos=opos # start pos of output trans thl=ul+dl+el h2=read(thl) if len(h2) != thl: raise 'Pack Error', opos # write out the transaction record seek(opos) write(h) write(h2) thl=23+thl pos=tpos+thl opos=otpos+thl 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) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen pnv=u64(read(8)) # skip position of previous version record seek(8,1) version=read(vlen) pv=p64(vindex_get(version, 0)) if status != 'u': vindex[version]=opos tappend((oid,opos)) if plen: p=read(plen) else: p=read(8) p=u64(p) if p >= p2: p=p-offset elif p >= p1: # Ick, we're in trouble. Let's bail # to the index and hope for the best p=index_get(oid,0) p=p64(p) # WRITE seek(opos) 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 >= p2: pnv=pnv-offset elif pnv >= p1: pnv=index_get(oid,0) write(p64(pnv)) write(pv) write(version) write(p) opos=opos+dlen pos=pos+dlen # skip the (intentionally redundant) transaction length pos=pos+8 if status != 'u': for oid, p in tindex: index[oid]=p # Record the position del tindex[:] write(stl) opos=opos+8 return opos
|
p=u64(p)
|
p=U64(p)
|
def shift_transactions_forward(index, vindex, tindex, file, pos, opos): """Copy transactions forward in the data file This might be done as part of a recovery effort """ # Cache a bunch of methods seek=file.seek read=file.read write=file.write tappend=tindex.append index_get=index.get vindex_get=vindex.get # Initialize, pv=z64 p1=opos p2=pos offset=p2-p1 packpos=opos # Copy the data in two stages. In the packing stage, # we skip records that are non-current or that are for # unreferenced objects. We also skip undone transactions. # # After the packing stage, we copy everything but undone # transactions, however, we have to update various back pointers. # We have to have the storage lock in the second phase to keep # data from being changed while we're copying. pnv=None while 1: # Read the transaction record seek(pos) h=read(23) if len(h) < 23: break tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) if status=='c': break # Oops. we found a checkpoint flag. if el < 0: el=t32-el tl=u64(stl) tpos=pos tend=tpos+tl otpos=opos # start pos of output trans thl=ul+dl+el h2=read(thl) if len(h2) != thl: raise 'Pack Error', opos # write out the transaction record seek(opos) write(h) write(h2) thl=23+thl pos=tpos+thl opos=otpos+thl 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) dlen=42+(plen or 8) if vlen: dlen=dlen+16+vlen pnv=u64(read(8)) # skip position of previous version record seek(8,1) version=read(vlen) pv=p64(vindex_get(version, 0)) if status != 'u': vindex[version]=opos tappend((oid,opos)) if plen: p=read(plen) else: p=read(8) p=u64(p) if p >= p2: p=p-offset elif p >= p1: # Ick, we're in trouble. Let's bail # to the index and hope for the best p=index_get(oid,0) p=p64(p) # WRITE seek(opos) 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 >= p2: pnv=pnv-offset elif pnv >= p1: pnv=index_get(oid,0) write(p64(pnv)) write(pv) write(version) write(p) opos=opos+dlen pos=pos+dlen # skip the (intentionally redundant) transaction length pos=pos+8 if status != 'u': for oid, p in tindex: index[oid]=p # Record the position del tindex[:] write(stl) opos=opos+8 return opos
|
l=u64(read(8))
|
l=U64(read(8))
|
def search_back(file, pos): seek=file.seek read=file.read seek(0,2) s=p=file.tell() while p > pos: seek(p-8) l=u64(read(8)) if l <= 0: break p=p-l-8 return p, s
|
ltid=z64, start=4, maxoid=z64, recover=0):
|
ltid=z64, start=4L, maxoid=z64, recover=0):
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
return 4, maxoid, ltid
|
return 4L, maxoid, ltid
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
tpos=0
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
|
tl=u64(stl) if tl+pos+8 > file_size or status=='c':
|
tl=U64(stl) if pos+(tl+8) > file_size or status=='c':
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
rtl=u64(read(8))
|
rtl=U64(read(8))
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
if recover: return tpos, None, None
|
if recover: return pos, None, None
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
pos=tpos+23+ul+dl+el
|
pos=tpos+(23+ul+dl+el)
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
prev=u64(sprev) tloc=u64(stloc) plen=u64(splen)
|
prev=U64(sprev) tloc=U64(stloc) plen=U64(splen)
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
dlen=dlen+16+vlen
|
dlen=dlen+(16+vlen)
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
pv=u64(read(8))
|
pv=U64(read(8))
|
def read_index(file, name, index, vindex, tindex, stop='\377'*8, ltid=z64, start=4, maxoid=z64, recover=0): read=file.read seek=file.seek seek(0,2) file_size=file.tell() if file_size: if file_size < start: raise FileStorageFormatError, file.name seek(0) if read(4) != packed_version: raise FileStorageFormatError, name else: file.write(packed_version) return 4, maxoid, ltid index_get=index.get vndexpos=vindex.get tappend=tindex.append pos=start seek(start) unpack=struct.unpack tpos=0 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 or status=='c': # Hm, the data were truncated or the checkpoint flag wasn't # cleared. 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) _truncate(file, name, pos) 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 or tl < (23+ul+dl+el): # We're in trouble. Find out if this is bad data in the # middle of the file, or just a turd that Win 9x dropped # at the end when the system crashed. # Skip to the end and read what should be the transaction length # of the last transaction. seek(-8, 2) rtl=u64(read(8)) # Now check to see if the redundant transaction length is # reasonable: if file_size - rtl < pos or rtl < 23: nearPanic('%s has invalid transaction header at %s', name, pos) warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end." % name) _truncate(file, name, pos) break else: if recover: return tpos, None, None 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 seek(tend) h=read(8) if h != stl: if recover: return tpos, None, None panic('%s has inconsistent transaction length at %s', name, pos) pos=tend+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: if recover: return tpos, None, None panic("%s data record exceeds transaction record at %s", name, pos) if index_get(oid,0) != prev: if prev: if recover: return tpos, None, None panic("%s incorrect previous pointer at %s", name, pos) else: warn("%s incorrect previous pointer at %s", name, pos) pos=pos+dlen if pos != tend: if recover: return tpos, None, None 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: if recover: return tpos, None, None 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[:] return pos, maxoid, ltid
|
old=u64(back)
|
old=U64(back)
|
def _loadBack(file, oid, back): seek=file.seek read=file.read while 1: old=u64(back) if not old: raise KeyError, oid seek(old) h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if vlen: seek(vlen+16,1) if plen != z64: return read(u64(plen)), serial back=read(8) # We got a back pointer!
|
if plen != z64: return read(u64(plen)), serial
|
if plen != z64: return read(U64(plen)), serial
|
def _loadBack(file, oid, back): seek=file.seek read=file.read while 1: old=u64(back) if not old: raise KeyError, oid seek(old) h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if vlen: seek(vlen+16,1) if plen != z64: return read(u64(plen)), serial back=read(8) # We got a back pointer!
|
old=u64(back)
|
old=U64(back)
|
def _loadBackPOS(file, oid, back): seek=file.seek read=file.read while 1: old=u64(back) if not old: raise KeyError, oid seek(old) h=read(42) doid,serial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) if vlen: seek(vlen+16,1) if plen != z64: return old back=read(8) # We got a back pointer!
|
self._pos=4
|
self._pos=4L
|
def __init__(self, file): if type(file) is type(''): file=open(file, 'r+b') self._file=file if file.read(4) != packed_version: raise FileStorageFormatError, name file.seek(0,2) self._file_size=file.tell() self._pos=4
|
tl=u64(stl) if tl+pos+8 > self._file_size or status=='c':
|
tl=U64(stl) if pos+(tl+8) > self._file_size or status=='c':
|
def next(self, index=0): file=self._file seek=file.seek read=file.read pos=self._pos
|
rtl=u64(read(8))
|
rtl=U64(read(8))
|
def next(self, index=0): file=self._file seek=file.seek read=file.read pos=self._pos
|
warn("It appears that there is invalid data at the end of the " "file, possibly due to a system crash. %s truncated " "to recover from bad data at end."
|
warn("It appears that there is invalid data at the end of " "the file, possibly due to a system crash. %s " "truncated to recover from bad data at end."
|
def next(self, index=0): file=self._file seek=file.seek read=file.read pos=self._pos
|
pos=tpos+23+ul+dl+el
|
pos=tpos+(23+ul+dl+el)
|
def next(self, index=0): file=self._file seek=file.seek read=file.read pos=self._pos
|
prev=u64(sprev) tloc=u64(stloc) plen=u64(splen)
|
prev=U64(sprev) tloc=U64(stloc) plen=U64(splen)
|
def next(self, index=0): name='' pos = self._pos tend, file, seek, read, tpos = self._stuff while pos < tend: # Read the data records for this transaction
|
dlen=dlen+16+vlen
|
dlen=dlen+(16+vlen)
|
def next(self, index=0): name='' pos = self._pos tend, file, seek, read, tpos = self._stuff while pos < tend: # Read the data records for this transaction
|
pv=u64(read(8))
|
pv=U64(read(8))
|
def next(self, index=0): name='' pos = self._pos tend, file, seek, read, tpos = self._stuff while pos < tend: # Read the data records for this transaction
|
log("wait() async=%d" % self.is_async(), level=zLOG.TRACE)
|
log("wait(%d), async=%d" % (msgid, self.is_async()), level=zLOG.TRACE)
|
def wait(self, msgid): """Invoke asyncore mainloop and wait for reply.""" if __debug__: log("wait() async=%d" % self.is_async(), level=zLOG.TRACE) if self.is_async(): self.trigger.pull_trigger()
|
asyncore.poll(10.0, self._map)
|
if __debug__: log("wait(%d): asyncore.poll(%s)" % (msgid, delay), level=zLOG.TRACE) asyncore.poll(delay, self._map) if delay < 1.0: delay += delay
|
def wait(self, msgid): """Invoke asyncore mainloop and wait for reply.""" if __debug__: log("wait() async=%d" % self.is_async(), level=zLOG.TRACE) if self.is_async(): self.trigger.pull_trigger()
|
def testItemsNegativeIndex(self): L = [-3, 6, -11, 4] for i in L: self.t[i] = i L.sort() items = self.t.items() for i in range(-1, -4, -1): self.assertEqual(items[i], (L[i], L[i])) self.assertRaises(IndexError, lambda: items[-5])
|
def testItemsWorks(self): for x in range(100): self.t[x] = 2*x v = self.t.items() i = 0 for x in v: self.assertEqual(x[0], i) self.assertEqual(x[1], 2*i) i += 1
|
|
zLOG.LOG(label or _label, level, message, error=error)
|
label = label or _label if LOG_THREAD_ID: label = "%s:%s" % (label, threading.currentThread().getName()) zLOG.LOG(label, level, message, error=error)
|
def log(message, level=zLOG.BLATHER, label=None, error=None): zLOG.LOG(label or _label, level, message, error=error)
|
return
|
def checkSize(self): # XXX need to fix return self.assertEqual(self.db.cacheSize(), 0) self.assertEqual(self.db.cacheDetailSize(), [])
|
|
self.assertEquals(self.db.cacheSize(), CACHE_SIZE * CONNS) details = self.db.cacheDetailSize() self.assertEquals(len(details), CONNS) for d in details: self.assertEquals(d['ngsize'], CACHE_SIZE) self.assertEquals(d['size'], CACHE_SIZE + 1)
|
self.assertEquals(self.db.cacheSize(), 0)
|
def checkSize(self): # XXX need to fix return self.assertEqual(self.db.cacheSize(), 0) self.assertEqual(self.db.cacheDetailSize(), [])
|
return
|
def checkDetail(self): # XXX need to fix return CACHE_SIZE = 10 self.db.setCacheSize(CACHE_SIZE)
|
|
for klass, count in self.db.cacheDetail(): print klass, count if klass.endswith('MinPO'): self.assertEqual(count, CONNS * CACHE_SIZE) if klass.endswith('PersistentMapping'): self.assertEqual(count, CONNS)
|
[(klass, count)] = self.db.cacheDetail() self.assertEqual(klass, "Persistence.PersistentMapping") self.assertEqual(count, CONNS)
|
def checkDetail(self): # XXX need to fix return CACHE_SIZE = 10 self.db.setCacheSize(CACHE_SIZE)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.