Commit 8752f8eb authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/fs1tools: DumperFsDump: Print size of every transaction record

Like fsdump/py does.

https://github.com/zopefoundation/ZODB/commit/403f9869 started to print
size of every transaction record saying that it readded it. And indeed
this printing was there starting from
https://github.com/zopefoundation/ZODB/commit/06e757b3 authored in 2003.

Both commits use `size(txn) = trans._tend - trans._tpos` which is wrong
by 8 because during file iteration tpos points to the beginning of
transaction and tend points to tpos + tlen, but tlen is full
transaction length - 8:

https://github.com/zopefoundation/ZODB/blob/5.8.1/src/ZODB/FileStorage/FileStorage.py#L1997-L1998
https://github.com/zopefoundation/ZODB/blob/5.8.1/src/ZODB/FileStorage/format.py#L28

Mimic fsdump/py behaviour exactly for compatibility, even if it is a bit
buggy, since it was there for such a long time.

Without the fix TestFsDump was failing like this:

    --- FAIL: TestFsDump/db=1 (0.00s)
        dump_test.go:70: fsdump: dump different:
            -Trans #00000 tid=0285cbac258bf266 size=151 time=1979-01-03 21:00:08.800000 offset=52
            +Trans #00000 tid=0285cbac258bf266 time=1979-01-03 21:00:08.800000 offset=52
                 status=' ' user='' description='initial database creation'
               data #00000 oid=0000000000000000 size=61 class=persistent.mapping.PersistentMapping
             ...
parent f1940b7b
// Copyright (C) 2017-2021 Nexedi SA and Contributors. // Copyright (C) 2017-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -157,6 +157,10 @@ func (d *DumperFsDump) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error { ...@@ -157,6 +157,10 @@ func (d *DumperFsDump) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error {
buf .S("Trans #") buf .S("Trans #")
buf .S(fmt.Sprintf("%05d", d.ntxn)) // XXX -> .D_f("05", d.ntxn) buf .S(fmt.Sprintf("%05d", d.ntxn)) // XXX -> .D_f("05", d.ntxn)
buf .S(" tid=") .V(txnh.Tid) buf .S(" tid=") .V(txnh.Tid)
// XXX here fsdump/py prints size of transaction record without "redundant lenght" field
buf .S(" size=") .D64(txnh.Len - 8)
buf .S(" time=") .V(txnh.Tid.Time()) buf .S(" time=") .V(txnh.Tid.Time())
// XXX here fsdump/py prints position of first data record, NOT transaction start! // XXX here fsdump/py prints position of first data record, NOT transaction start!
......
...@@ -77,7 +77,7 @@ func newFsDump() Dumper { return &DumperFsDump{} } ...@@ -77,7 +77,7 @@ func newFsDump() Dumper { return &DumperFsDump{} }
func newFsDumpv() Dumper { return &DumperFsDumpVerbose{} } func newFsDumpv() Dumper { return &DumperFsDumpVerbose{} }
func newFsTail() Dumper { return &DumperFsTail{Ntxn: 1000000} } func newFsTail() Dumper { return &DumperFsTail{Ntxn: 1000000} }
func TestFsDump(t *testing.T) { t.Skip("xfail"); testDump(t, fs1.IterForward, newFsDump) } func TestFsDump(t *testing.T) { testDump(t, fs1.IterForward, newFsDump) }
func TestFsDumpv(t *testing.T) { testDump(t, fs1.IterForward, newFsDumpv) } func TestFsDumpv(t *testing.T) { testDump(t, fs1.IterForward, newFsDumpv) }
func TestFsTail(t *testing.T) { testDump(t, fs1.IterBackward, newFsTail) } func TestFsTail(t *testing.T) { testDump(t, fs1.IterBackward, newFsTail) }
......
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