Skip to content

Commit

Permalink
Merge pull request #88 from zopefoundation/fstail-offset
Browse files Browse the repository at this point in the history
fstail: print the txn offset and header size, instead of only the data offset
  • Loading branch information
jimfulton committed Jul 26, 2016
2 parents 75bae1a + 4392f90 commit 37e445a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- Internal FileStorage-undo fixes that should allow undo in some cases
where it didn't work before.

- fstail: print the txn offset and header size, instead of only the data offset.
fstail can now be used to truncate a DB at the right offset.

4.4.2 (2016-07-08)
==================

Expand Down
9 changes: 7 additions & 2 deletions src/ZODB/fstools.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ def read_meta(self):
self._ext = self._file.read(self.ext_len)
self.ext = loads(self._ext)

def get_offset(self):
return self._pos

def __len__(self):
return TRANS_HDR_LEN + self.user_len + self.descr_len + self.ext_len

def get_data_offset(self):
return (self._pos + TRANS_HDR_LEN + self.user_len + self.descr_len
+ self.ext_len)
return self._pos + len(self)

def get_timestamp(self):
return TimeStamp(self.tid)
Expand Down
4 changes: 2 additions & 2 deletions src/ZODB/scripts/fstail.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def main(path, ntxn):
th.read_meta()
print("%s: hash=%s" % (th.get_timestamp(),
binascii.hexlify(hash).decode()))
print(("user=%r description=%r length=%d offset=%d"
% (th.user, th.descr, th.length, th.get_data_offset())))
print(("user=%r description=%r length=%d offset=%d (+%d)"
% (th.user, th.descr, th.length, th.get_offset(), len(th))))
print()
th = th.prev_txn()
i -= 1
Expand Down
4 changes: 2 additions & 2 deletions src/ZODB/scripts/tests/fstail.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Now lets have a look at the last transactions of this FileStorage:
>>> from ZODB.scripts.fstail import main
>>> main(storagefile, 5)
2007-11-10 15:18:48.543001: hash=b16422d09fabdb45d4e4325e4b42d7d6f021d3c3
user='' description='' length=132 offset=185
user='' description='' length=132 offset=162 (+23)
<BLANKLINE>
2007-11-10 15:18:48.543001: hash=b16422d09fabdb45d4e4325e4b42d7d6f021d3c3
user='' description='initial database creation' length=150 offset=52
user='' description='initial database creation' length=150 offset=4 (+48)
<BLANKLINE>

Now clean up the storage again:
Expand Down
8 changes: 4 additions & 4 deletions src/ZODB/scripts/tests/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
# Python 3 produces larger pickles, even when we use zodbpickle :(
# this changes all the offsets and sizes in fstail.txt
(re.compile("user='' description='' "
"length=[0-9]+ offset=[0-9]+"),
"length=[0-9]+ offset=[0-9]+ \(\+23\)"),
"user='' description='' "
"length=<LENGTH> offset=<OFFSET>"),
"length=<LENGTH> offset=<OFFSET> (+23)"),
(re.compile("user='' description='initial database creation' "
"length=[0-9]+ offset=[0-9]+"),
"length=[0-9]+ offset=4 \(\+48\)"),
"user='' description='initial database creation' "
"length=<<LENGTH> offset=<OFFSET>"),
"length=<LENGTH> offset=4 (+48)"),
])

def test_suite():
Expand Down

0 comments on commit 37e445a

Please sign in to comment.