Commit 8b87ca8c authored by Jim Fulton's avatar Jim Fulton

Added some extra logic to checkpoint the final step

in transaction writing *just* in case a system crashes during the last
step of commiting a transaction.
parent c717e473
...@@ -184,7 +184,7 @@ ...@@ -184,7 +184,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.12 $'[11:-2] __version__='$Revision: 1.13 $'[11:-2]
import struct, time, os, bpthread, string, base64 import struct, time, os, bpthread, string, base64
from struct import pack, unpack from struct import pack, unpack
...@@ -552,9 +552,12 @@ class FileStorage(BaseStorage.BaseStorage): ...@@ -552,9 +552,12 @@ class FileStorage(BaseStorage.BaseStorage):
file.seek(pos) file.seek(pos)
tl=tlen+dlen tl=tlen+dlen
stl=p64(tl) stl=p64(tl)
# Note that we use a status of 'c', for checkpoint.
# If this flag isn't cleared, anything after this is
# suspect.
write(pack( write(pack(
">8s" "8s" "c" "H" "H" "H" ">8s" "8s" "c" "H" "H" "H"
,id, stl, ' ', len(user), len(desc), len(ext), ,id, stl, 'c', len(user), len(desc), len(ext),
)) ))
if user: write(user) if user: write(user)
if desc: write(desc) if desc: write(desc)
...@@ -563,7 +566,12 @@ class FileStorage(BaseStorage.BaseStorage): ...@@ -563,7 +566,12 @@ class FileStorage(BaseStorage.BaseStorage):
cp(tfile, file, dlen) cp(tfile, file, dlen)
write(stl) write(stl)
# OK, not clear the checkpoint flag
file.seek(pos+16)
write(' ')
file.flush() file.flush()
self._pos=pos+tl+8 self._pos=pos+tl+8
index=self._index index=self._index
...@@ -823,6 +831,9 @@ class FileStorage(BaseStorage.BaseStorage): ...@@ -823,6 +831,9 @@ class FileStorage(BaseStorage.BaseStorage):
h=read(23) h=read(23)
if len(h) < 23: break if len(h) < 23: break
tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h) tid, stl, status, ul, dl, el = unpack(">8s8scHHH",h)
if status=='c':
# Oops. we found a checkpoint flag.
break
if el < 0: el=t32-el if el < 0: el=t32-el
tl=u64(stl) tl=u64(stl)
tpos=pos tpos=pos
...@@ -1087,8 +1098,9 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8): ...@@ -1087,8 +1098,9 @@ def read_index(file, name, index, vindex, tindex, stop='\377'*8):
tl=u64(stl) tl=u64(stl)
if tl+pos+8 > file_size: if tl+pos+8 > file_size or status=='c':
# Hm, the data were truncated. They may also be corrupted, # 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. # in which case, we don't want to totally lose the data.
warn("%s truncated, possibly due to damaged records at %s", warn("%s truncated, possibly due to damaged records at %s",
name, pos) name, pos)
......
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