github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/storage/fs/fs.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package fs 12 13 import "io" 14 15 // File and FS are a partial attempt at offering the Pebble vfs.FS interface. Given the constraints 16 // of the RocksDB Env interface we've chosen to only include what is easy to implement. Additionally, 17 // it does not try to subsume all the file related functionality already in the Engine interface. 18 // It seems preferable to do a final cleanup only when the implementation can simply use Pebble's 19 // implementation of vfs.FS. At that point the following interface will become a superset of vfs.FS. 20 type File interface { 21 io.ReadWriteCloser 22 io.ReaderAt 23 Sync() error 24 } 25 26 // FS provides a filesystem interface. 27 type FS interface { 28 // Create creates the named file for writing, truncating it if it already 29 // exists. 30 Create(name string) (File, error) 31 32 // CreateWithSync is similar to Create, but the file is periodically 33 // synced whenever more than bytesPerSync bytes accumulate. This syncing 34 // does not provide any persistency guarantees, but can prevent latency 35 // spikes. 36 CreateWithSync(name string, bytesPerSync int) (File, error) 37 38 // Link creates newname as a hard link to the oldname file. 39 Link(oldname, newname string) error 40 41 // Open opens the named file for reading. 42 Open(name string) (File, error) 43 44 // OpenDir opens the named directory for syncing. 45 OpenDir(name string) (File, error) 46 47 // Remove removes the named file. If the file with given name doesn't 48 // exist, return an error that returns true from os.IsNotExist(). 49 Remove(name string) error 50 51 // Rename renames a file. It overwrites the file at newname if one exists, 52 // the same as os.Rename. 53 Rename(oldname, newname string) error 54 55 // MkdirAll creates the named dir and its parents. Does nothing if the 56 // directory already exists. 57 MkdirAll(name string) error 58 59 // RemoveDir removes the named dir. 60 RemoveDir(name string) error 61 62 // RemoveAll deletes the path and any children it contains. 63 RemoveAll(dir string) error 64 65 // List returns a listing of the given directory. The names returned are 66 // relative to the directory. 67 List(name string) ([]string, error) 68 }