Skip to content

Commit

Permalink
manifest: add VersionEdit tests with virtual tables
Browse files Browse the repository at this point in the history
Improve the debug parsing methods to parse virtual tables and backing
operations and add some `version_edit_apply` tests with virtual
tables.
  • Loading branch information
RaduBerinde committed Mar 11, 2024
1 parent cb66088 commit 635c600
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
46 changes: 46 additions & 0 deletions internal/manifest/testdata/version_edit_apply
Original file line number Diff line number Diff line change
Expand Up @@ -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]
13 changes: 9 additions & 4 deletions internal/manifest/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -30,7 +30,7 @@ type debugParser struct {
lastToken string
}

const debugParserSeparators = ":[]-"
const debugParserSeparators = ":-[]()"

func makeDebugParser(s string) debugParser {
p := debugParser{
Expand Down Expand Up @@ -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())
Expand Down
13 changes: 12 additions & 1 deletion internal/manifest/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("-")
Expand Down Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions internal/manifest/version_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/manifest/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 635c600

Please sign in to comment.