From 635c6003a632b8bc6d7878d98855dddb59d09111 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Mon, 11 Mar 2024 11:09:26 -0700 Subject: [PATCH] manifest: add VersionEdit tests with virtual tables Improve the debug parsing methods to parse virtual tables and backing operations and add some `version_edit_apply` tests with virtual tables. --- internal/manifest/testdata/version_edit_apply | 46 +++++++++++++++++++ internal/manifest/testutils.go | 13 ++++-- internal/manifest/version.go | 13 +++++- internal/manifest/version_edit.go | 11 +++++ internal/manifest/version_test.go | 4 ++ 5 files changed, 82 insertions(+), 5 deletions(-) diff --git a/internal/manifest/testdata/version_edit_apply b/internal/manifest/testdata/version_edit_apply index b5efae9658..5d100e5ef8 100644 --- a/internal/manifest/testdata/version_edit_apply +++ b/internal/manifest/testdata/version_edit_apply @@ -169,3 +169,49 @@ new version edit ---- L2: 000005:[s#3,SET-z#4,SET] seqnums:[0-0] points:[s#3,SET-z#4,SET] + +define v6 +L1: + 000001:[a#2,SET-e#2,SET] +L2: + 000002:[c#1,SET-f#1,SET] +---- +L1: + 000001:[a#2,SET-e#2,SET] seqnums:[0-0] points:[a#2,SET-e#2,SET] +L2: + 000002:[c#1,SET-f#1,SET] seqnums:[0-0] points:[c#1,SET-f#1,SET] + +# Convert a physical table to virtual tables. +apply v6 + del-table: L1 000001 + add-table: L1 000003(000009):[a#2,SET-b#2,SET] + add-table: L1 000004(000009):[c#2,SET-e#2,SET] + add-backing: 000009 +---- +L1: + 000003(000009):[a#2,SET-b#2,SET] seqnums:[0-0] points:[a#2,SET-b#2,SET] + 000004(000009):[c#2,SET-e#2,SET] seqnums:[0-0] points:[c#2,SET-e#2,SET] +L2: + 000002:[c#1,SET-f#1,SET] seqnums:[0-0] points:[c#1,SET-f#1,SET] + +define v7 +L1: + 000003(000009):[a#2,SET-b#2,SET] seqnums:[0-0] points:[a#2,SET-b#2,SET] + 000004(000009):[c#2,SET-e#2,SET] seqnums:[0-0] points:[c#2,SET-e#2,SET] +L2: + 000002:[c#1,SET-f#1,SET] seqnums:[0-0] points:[c#1,SET-f#1,SET] +---- +L1: + 000003(000009):[a#2,SET-b#2,SET] seqnums:[0-0] points:[a#2,SET-b#2,SET] + 000004(000009):[c#2,SET-e#2,SET] seqnums:[0-0] points:[c#2,SET-e#2,SET] +L2: + 000002:[c#1,SET-f#1,SET] seqnums:[0-0] points:[c#1,SET-f#1,SET] + +# Remove virtual tables and their backing. +apply v7 + del-table: L1 000003 + del-table: L1 000004 + del-backing: 000009 +---- +L2: + 000002:[c#1,SET-f#1,SET] seqnums:[0-0] points:[c#1,SET-f#1,SET] diff --git a/internal/manifest/testutils.go b/internal/manifest/testutils.go index 7f543b9918..784735ba7d 100644 --- a/internal/manifest/testutils.go +++ b/internal/manifest/testutils.go @@ -18,9 +18,9 @@ import ( // ParseFileMetadataDebug. // // It takes a string and splits it into tokens. Tokens are separated by -// whitespace; in addition separators ':', '[', ']', '-' are always separate -// tokens. For example, the string `000001:[a - b]` results in tokens `000001`, -// `:`, `[`, `a`, `-`, `b`, `]`. +// whitespace; in addition separators "_-[]()" are always separate tokens. For +// example, the string `000001:[a - b]` results in tokens `000001`, +// `:`, `[`, `a`, `-`, `b`, `]`, . // // All debugParser methods throw panics instead of returning errors. The code // that uses a debugParser can recover them and convert them to errors. @@ -30,7 +30,7 @@ type debugParser struct { lastToken string } -const debugParserSeparators = ":[]-" +const debugParserSeparators = ":-[]()" func makeDebugParser(s string) debugParser { p := debugParser{ @@ -138,6 +138,11 @@ func (p *debugParser) FileNum() base.FileNum { return base.FileNum(p.Int()) } +// DiskFileNum parses the next token as a DiskFileNum. +func (p *debugParser) DiskFileNum() base.DiskFileNum { + return base.DiskFileNum(p.Int()) +} + // InternalKey parses the next token as an internal key. func (p *debugParser) InternalKey() base.InternalKey { return base.ParsePrettyInternalKey(p.Next()) diff --git a/internal/manifest/version.go b/internal/manifest/version.go index eb037af8fd..bd81ac28ec 100644 --- a/internal/manifest/version.go +++ b/internal/manifest/version.go @@ -822,6 +822,12 @@ func ParseFileMetadataDebug(s string) (_ *FileMetadata, err error) { m := &FileMetadata{} p := makeDebugParser(s) m.FileNum = p.FileNum() + var backingNum base.DiskFileNum + if p.Peek() == "(" { + p.Expect("(") + backingNum = p.DiskFileNum() + p.Expect(")") + } p.Expect(":", "[") m.Smallest = p.InternalKey() p.Expect("-") @@ -862,7 +868,12 @@ func ParseFileMetadataDebug(s string) (_ *FileMetadata, err error) { m.SmallestPointKey, m.LargestPointKey = m.Smallest, m.Largest m.HasPointKeys = true } - m.InitPhysicalBacking() + if backingNum == 0 { + m.InitPhysicalBacking() + } else { + m.Virtual = true + m.InitProviderBacking(backingNum, 0 /* size */) + } return m, nil } diff --git a/internal/manifest/version_edit.go b/internal/manifest/version_edit.go index c0f7ab142b..1ee31829dc 100644 --- a/internal/manifest/version_edit.go +++ b/internal/manifest/version_edit.go @@ -588,6 +588,17 @@ func ParseVersionEditDebug(s string) (_ *VersionEdit, err error) { FileNum: num, }] = nil + case "add-backing": + n := p.DiskFileNum() + ve.CreatedBackingTables = append(ve.CreatedBackingTables, &FileBacking{ + DiskFileNum: n, + Size: 100, + }) + + case "del-backing": + n := p.DiskFileNum() + ve.RemovedBackingTables = append(ve.RemovedBackingTables, n) + default: return nil, errors.Errorf("field %q not implemented", field) } diff --git a/internal/manifest/version_test.go b/internal/manifest/version_test.go index 440b735dc8..18bb8525e3 100644 --- a/internal/manifest/version_test.go +++ b/internal/manifest/version_test.go @@ -404,6 +404,10 @@ func TestFileMetadata_ParseRoundTrip(t *testing.T) { input: " 000001 : [ a#0,SET - z#0,DEL] points : [ a#0,SET - z#0,DEL] ", output: "000001:[a#0,SET-z#0,DEL] seqnums:[0-0] points:[a#0,SET-z#0,DEL]", }, + { + name: "virtual", + input: "000001(000008):[a#0,SET-z#0,DEL] seqnums:[0-0] points:[a#0,SET-z#0,DEL]", + }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) {