Commit daad60ab authored by Jeremy Hylton's avatar Jeremy Hylton

Cleanup some dictionary API stuff:

    - use update() method where appropriate
    - don't pass None as second argument to get(). it's the default.
    - consistent space after comma between args
parent 61f949b5
...@@ -186,7 +186,7 @@ ...@@ -186,7 +186,7 @@
# may have a back pointer to a version record or to a non-version # may have a back pointer to a version record or to a non-version
# record. # record.
# #
__version__='$Revision: 1.69 $'[11:-2] __version__='$Revision: 1.70 $'[11:-2]
import struct, time, os, bpthread, string, base64, sys import struct, time, os, bpthread, string, base64, sys
from struct import pack, unpack from struct import pack, unpack
...@@ -419,7 +419,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -419,7 +419,7 @@ class FileStorage(BaseStorage.BaseStorage,
if opos+dlen > tend or tloc != pos: return 0 if opos+dlen > tend or tloc != pos: return 0
if index.get(oid,0) != opos: return 0 if index.get(oid, 0) != opos: return 0
opos=opos+dlen opos=opos+dlen
...@@ -443,10 +443,10 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -443,10 +443,10 @@ class FileStorage(BaseStorage.BaseStorage,
warn("Failed to load database index: %s: %s" % warn("Failed to load database index: %s: %s" %
(exc, err)) (exc, err))
return None return None
index=info.get('index', None) index=info.get('index')
pos=info.get('pos', None) pos=info.get('pos')
oid=info.get('oid', None) oid=info.get('oid')
vindex=info.get('vindex', None) vindex=info.get('vindex')
if index is None or pos is None or oid is None or vindex is None: if index is None or pos is None or oid is None or vindex is None:
return None return None
pos = long(pos) pos = long(pos)
...@@ -517,7 +517,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -517,7 +517,7 @@ class FileStorage(BaseStorage.BaseStorage,
h=read(58) # oid, serial, prev(oid), tloc, vlen, plen, pnv, pv h=read(58) # oid, serial, prev(oid), tloc, vlen, plen, pnv, pv
oid=h[:8] oid=h[:8]
pnv=h[-16:-8] pnv=h[-16:-8]
if index_get(oid, None) == srcpos: if index_get(oid) == srcpos:
# This is a current record! # This is a current record!
tindex[oid]=here tindex[oid]=here
appoids(oid) appoids(oid)
...@@ -841,7 +841,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -841,7 +841,7 @@ class FileStorage(BaseStorage.BaseStorage,
prev=U64(sprev) prev=U64(sprev)
dlen=42+(plen or 8) dlen=42+(plen or 8)
if vlen: dlen=dlen+(16+vlen) if vlen: dlen=dlen+(16+vlen)
if index_get(oid,0) != pos: raise UndoError if index_get(oid, 0) != pos: raise UndoError
pos=pos+dlen pos=pos+dlen
if pos > tend: raise UndoError if pos > tend: raise UndoError
t[oid]=prev t[oid]=prev
...@@ -849,8 +849,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -849,8 +849,7 @@ class FileStorage(BaseStorage.BaseStorage,
seek(tpos+16) seek(tpos+16)
file.write('u') file.write('u')
file.flush() file.flush()
index=self._index self._index.update(t)
for oid, pos in t.items(): index[oid]=pos
return t.keys() return t.keys()
finally: self._lock_release() finally: self._lock_release()
...@@ -916,7 +915,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -916,7 +915,7 @@ class FileStorage(BaseStorage.BaseStorage,
copy=1 # Can we just copy a data pointer copy=1 # Can we just copy a data pointer
tpos=self._tindex.get(oid, 0) tpos=self._tindex.get(oid, 0)
ipos=self._index.get(oid,0) ipos=self._index.get(oid, 0)
tipos=tpos or ipos tipos=tpos or ipos
if tipos != pos: if tipos != pos:
# Eek, a later transaction modified the data, but, # Eek, a later transaction modified the data, but,
...@@ -1393,7 +1392,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1393,7 +1392,7 @@ class FileStorage(BaseStorage.BaseStorage,
if vlen: if vlen:
dlen=dlen+(16+vlen) dlen=dlen+(16+vlen)
if packing and pindex_get(oid,0) != pos: if packing and pindex_get(oid, 0) != pos:
# This is not the most current record, or # This is not the most current record, or
# the oid is no longer referenced so skip it. # the oid is no longer referenced so skip it.
pos=pos+dlen pos=pos+dlen
...@@ -1470,7 +1469,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1470,7 +1469,7 @@ class FileStorage(BaseStorage.BaseStorage,
# current record, then we should still # current record, then we should still
# point at one, otherwise, we should # point at one, otherwise, we should
# point at the last non-version record. # point at the last non-version record.
ppos=pindex_get(oid,0) ppos=pindex_get(oid, 0)
if ppos: if ppos:
if ppos==p: if ppos==p:
# we were pointing to the # we were pointing to the
...@@ -1490,7 +1489,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1490,7 +1489,7 @@ class FileStorage(BaseStorage.BaseStorage,
p=p-offset p=p-offset
p=p64(p) p=p64(p)
sprev=p64(index_get(oid,0)) sprev=p64(index_get(oid, 0))
write(pack(">8s8s8s8sH8s", write(pack(">8s8s8s8sH8s",
oid,serial,sprev,p64(otpos),vlen,splen)) oid,serial,sprev,p64(otpos),vlen,splen))
if vlen: if vlen:
...@@ -1681,12 +1680,12 @@ def shift_transactions_forward(index, vindex, tindex, file, pos, opos): ...@@ -1681,12 +1680,12 @@ def shift_transactions_forward(index, vindex, tindex, file, pos, opos):
elif p >= p1: elif p >= p1:
# Ick, we're in trouble. Let's bail # Ick, we're in trouble. Let's bail
# to the index and hope for the best # to the index and hope for the best
p=index_get(oid,0) p=index_get(oid, 0)
p=p64(p) p=p64(p)
# WRITE # WRITE
seek(opos) seek(opos)
sprev=p64(index_get(oid,0)) sprev=p64(index_get(oid, 0))
write(pack(">8s8s8s8sH8s", write(pack(">8s8s8s8sH8s",
oid,serial,sprev,p64(otpos),vlen,splen)) oid,serial,sprev,p64(otpos),vlen,splen))
if vlen: if vlen:
...@@ -1694,7 +1693,7 @@ def shift_transactions_forward(index, vindex, tindex, file, pos, opos): ...@@ -1694,7 +1693,7 @@ def shift_transactions_forward(index, vindex, tindex, file, pos, opos):
else: else:
if pnv >= p2: pnv=pnv-offset if pnv >= p2: pnv=pnv-offset
elif pnv >= p1: elif pnv >= p1:
pnv=index_get(oid,0) pnv=index_get(oid, 0)
write(p64(pnv)) write(p64(pnv))
write(pv) write(pv)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment