github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/tool/make_incorrect_manifests.go (about)

     1  // Copyright 2019 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  //go:build make_incorrect_manifests
     6  // +build make_incorrect_manifests
     7  
     8  // Run using: go run -tags make_incorrect_manifests ./tool/make_incorrect_manifests.go
     9  package main
    10  
    11  import (
    12  	"log"
    13  
    14  	"github.com/cockroachdb/pebble/internal/manifest"
    15  	"github.com/cockroachdb/pebble/record"
    16  	"github.com/cockroachdb/pebble/vfs"
    17  )
    18  
    19  func writeVE(writer *record.Writer, ve *manifest.VersionEdit) {
    20  	w, err := writer.Next()
    21  	if err != nil {
    22  		log.Fatal(err)
    23  	}
    24  	err = ve.Encode(w)
    25  	if err != nil {
    26  		log.Fatal(err)
    27  	}
    28  }
    29  
    30  func makeManifest1() {
    31  	fs := vfs.Default
    32  	f, err := fs.Create("tool/testdata/MANIFEST-invalid")
    33  	if err != nil {
    34  		log.Fatal(err)
    35  	}
    36  	writer := record.NewWriter(f)
    37  	var ve manifest.VersionEdit
    38  	ve.ComparerName = "leveldb.BytewiseComparator"
    39  	ve.MinUnflushedLogNum = 2
    40  	ve.NextFileNum = 5
    41  	ve.LastSeqNum = 20
    42  	ve.NewFiles = []manifest.NewFileEntry{
    43  		{Level: 6, Meta: &manifest.FileMetadata{
    44  			FileNum: 1, SmallestSeqNum: 2, LargestSeqNum: 5}}}
    45  	writeVE(writer, &ve)
    46  
    47  	ve.MinUnflushedLogNum = 3
    48  	ve.NewFiles = []manifest.NewFileEntry{
    49  		{Level: 6, Meta: &manifest.FileMetadata{
    50  			FileNum: 2, SmallestSeqNum: 1, LargestSeqNum: 4}}}
    51  	writeVE(writer, &ve)
    52  
    53  	err = writer.Close()
    54  	if err != nil {
    55  		log.Fatal(err)
    56  	}
    57  }
    58  
    59  func main() {
    60  	makeManifest1()
    61  }