github.com/cockroachdb/pebble@v1.1.2/filenames.go (about) 1 // Copyright 2012 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 package pebble 6 7 import ( 8 "fmt" 9 10 "github.com/cockroachdb/pebble/internal/base" 11 "github.com/cockroachdb/pebble/vfs" 12 ) 13 14 type fileType = base.FileType 15 16 // FileNum is an identifier for a file within a database. 17 type FileNum = base.FileNum 18 19 const ( 20 fileTypeLog = base.FileTypeLog 21 fileTypeLock = base.FileTypeLock 22 fileTypeTable = base.FileTypeTable 23 fileTypeManifest = base.FileTypeManifest 24 fileTypeCurrent = base.FileTypeCurrent 25 fileTypeOptions = base.FileTypeOptions 26 fileTypeTemp = base.FileTypeTemp 27 fileTypeOldTemp = base.FileTypeOldTemp 28 ) 29 30 // setCurrentFile sets the CURRENT file to point to the manifest with 31 // provided file number. 32 // 33 // NB: This is a low-level routine and typically not what you want to 34 // use. Newer versions of Pebble running newer format major versions do 35 // not use the CURRENT file. See setCurrentFunc in version_set.go. 36 func setCurrentFile(dirname string, fs vfs.FS, fileNum base.DiskFileNum) error { 37 newFilename := base.MakeFilepath(fs, dirname, fileTypeCurrent, fileNum) 38 oldFilename := base.MakeFilepath(fs, dirname, fileTypeTemp, fileNum) 39 fs.Remove(oldFilename) 40 f, err := fs.Create(oldFilename) 41 if err != nil { 42 return err 43 } 44 if _, err := fmt.Fprintf(f, "MANIFEST-%s\n", fileNum); err != nil { 45 return err 46 } 47 if err := f.Sync(); err != nil { 48 return err 49 } 50 if err := f.Close(); err != nil { 51 return err 52 } 53 return fs.Rename(oldFilename, newFilename) 54 }