Skip to content

Commit 18051c5

Browse files
committed
manifest: allow specifying blob file creation time
Allow specifying a blob file's creation time when parsing the debug string representation used in tests. The creation time will be relevant for blob file replacement heuristics.
1 parent 2b4a96e commit 18051c5

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

internal/manifest/blob_metadata.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func ParseBlobFileMetadataDebug(s string) (_ BlobFileMetadata, err error) {
173173
}()
174174

175175
// Input format:
176-
// B000102 physical:{000000: size:[206536 (201KiB)], vals:[393256 (384KiB)]}
176+
// B000102 physical:{000000: size:[206536 (201KiB)], vals:[393256 (384KiB)] creationTime:1718851200}
177177
p := strparse.MakeParser(debugParserSeparators, s)
178178
fileID := p.BlobFileID()
179179
p.Expect("physical")
@@ -201,7 +201,7 @@ func ParsePhysicalBlobFileDebug(s string) (_ *PhysicalBlobFile, err error) {
201201
}()
202202

203203
// Input format:
204-
// 000000: size:[206536 (201KiB)], vals:[393256 (384KiB)]
204+
// 000000: size:[206536 (201KiB)], vals:[393256 (384KiB)] creationTime:1718851200
205205
p := strparse.MakeParser(debugParserSeparators, s)
206206
return parsePhysicalBlobFileDebug(&p)
207207
}
@@ -233,6 +233,8 @@ func parsePhysicalBlobFileDebug(p *strparse.Parser) (*PhysicalBlobFile, error) {
233233
m.ValueSize = p.Uint64()
234234
maybeSkipParens()
235235
p.Expect("]")
236+
case "creationTime":
237+
m.CreationTime = p.Uint64()
236238
default:
237239
p.Errf("unknown field %q", field)
238240
}

internal/manifest/blob_metadata_test.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,32 @@ import (
1616

1717
func TestPhysicalBlobFile_ParseRoundTrip(t *testing.T) {
1818
testCases := []struct {
19-
name string
20-
input string
21-
output string
19+
name string
20+
input string
21+
output string
22+
creationTime uint64
2223
}{
2324
{
2425
name: "verbatim",
2526
input: "000001 size:[903530 (882KB)] vals:[39531 (39KB)]",
2627
},
2728
{
28-
name: "whitespace is insignificant",
29-
input: "000001 size : [ 903530 (882KB )] vals: [ 39531 ( 39KB ) ]",
30-
output: "000001 size:[903530 (882KB)] vals:[39531 (39KB)]",
29+
name: "whitespace is insignificant",
30+
input: "000001 size : [ 903530 (882KB )] vals: [ 39531 ( 39KB ) ] creationTime: 1718851200",
31+
output: "000001 size:[903530 (882KB)] vals:[39531 (39KB)]",
32+
creationTime: 1718851200,
3133
},
3234
{
3335
name: "humanized sizes are optional",
3436
input: "000001 size:[903530] vals:[39531]",
3537
output: "000001 size:[903530 (882KB)] vals:[39531 (39KB)]",
3638
},
39+
{
40+
name: "creation time is optional",
41+
input: "000001 size:[903530 (882KB)] vals:[39531 (39KB)] creationTime:1718851200",
42+
output: "000001 size:[903530 (882KB)] vals:[39531 (39KB)]",
43+
creationTime: 1718851200,
44+
},
3745
}
3846
for _, tc := range testCases {
3947
t.Run(tc.name, func(t *testing.T) {
@@ -45,6 +53,7 @@ func TestPhysicalBlobFile_ParseRoundTrip(t *testing.T) {
4553
want = tc.output
4654
}
4755
require.Equal(t, want, got)
56+
require.Equal(t, tc.creationTime, m.CreationTime)
4857
})
4958
}
5059
}
@@ -61,14 +70,19 @@ func TestBlobFileMetadata_ParseRoundTrip(t *testing.T) {
6170
},
6271
{
6372
name: "whitespace is insignificant",
64-
input: "B000002 physical : {000001 size : [ 903530 (882KB )] vals: [ 39531 ( 39KB ) ] }",
73+
input: "B000002 physical : {000001 size : [ 903530 (882KB )] vals: [ 39531 ( 39KB ) ] creationTime: 1718851200 }",
6574
output: "B000002 physical:{000001 size:[903530 (882KB)] vals:[39531 (39KB)]}",
6675
},
6776
{
6877
name: "humanized sizes are optional",
6978
input: "B000002 physical:{000001 size:[903530] vals:[39531]}",
7079
output: "B000002 physical:{000001 size:[903530 (882KB)] vals:[39531 (39KB)]}",
7180
},
81+
{
82+
name: "creation time is optional",
83+
input: "B000002 physical:{000001 size:[903530 (882KB)] vals:[39531 (39KB)] creationTime:1718851200}",
84+
output: "B000002 physical:{000001 size:[903530 (882KB)] vals:[39531 (39KB)]}",
85+
},
7286
}
7387
for _, tc := range testCases {
7488
t.Run(tc.name, func(t *testing.T) {

internal/manifest/version_edit_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ func TestParseVersionEditDebugRoundTrip(t *testing.T) {
484484
{
485485
input: ` add-blob-file: B000925 physical:{000005 size:[20535 (20KB)] vals:[25935 (25KB)]}`,
486486
},
487+
{
488+
input: ` add-blob-file: B000925 physical:{000005 size:[20535 (20KB)] vals:[25935 (25KB)] creationTime:1718851200}`,
489+
output: ` add-blob-file: B000925 physical:{000005 size:[20535 (20KB)] vals:[25935 (25KB)]}`,
490+
},
487491
{
488492
input: ` add-table: L1 000001:[a#0,SET-z#0,DEL] seqnums:[0-0] points:[a#0,SET-z#0,DEL] size:1`,
489493
},

0 commit comments

Comments
 (0)