From 22673af794ef63c4cff46f3e11c0689e04ca522b Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Wed, 21 Feb 2024 20:39:40 -0800 Subject: [PATCH] db: add DebugString method Add a `DB.DebugString()` method which can be used during debugging. The meta test uses it to log the final state of the db (which after reduction will be right after the problematic operation). --- db.go | 7 +++++++ metamorphic/meta.go | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/db.go b/db.go index 22ecc855b0..61538346ac 100644 --- a/db.go +++ b/db.go @@ -3082,3 +3082,10 @@ func (d *DB) checkVirtualBounds(m *fileMetadata) { panic(err) } } + +// DebugString returns a debugging string describing the LSM. +func (d *DB) DebugString() string { + d.mu.Lock() + defer d.mu.Unlock() + return d.mu.versions.currentVersion().DebugString(base.DefaultFormatter) +} diff --git a/metamorphic/meta.go b/metamorphic/meta.go index c2f2314324..cee666a5aa 100644 --- a/metamorphic/meta.go +++ b/metamorphic/meta.go @@ -527,6 +527,17 @@ func RunOnce(t TestingT, runDir string, seed uint64, historyPath string, rOpts . if err := Execute(m); err != nil { fmt.Fprintf(os.Stderr, "Seed: %d\n", seed) fmt.Fprintln(os.Stderr, err) + } + + // If we have unclosed databases, print LSM details. This will be the case + // when we use --try-to-reduce. + for i, db := range m.dbs { + if db != nil { + fmt.Fprintf(os.Stderr, "\ndb%d:\n%s", i+1, db.DebugString()) + } + } + + if err != nil { m.saveInMemoryData() os.Exit(1) }