nvm

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2020 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HEADER_SIZE uint16 = 2 +
		2 +
		2 +
		16 +
		8 +
		8 /* data_region_size */
	FULL_HEADER_SIZE uint16 = 4 + 2 + HEADER_SIZE
)
View Source
const (
	MAJOR_VERSION           uint16 = 2
	MINOR_VERSION           uint16 = 1
	MAX_JOURNAL_REGION_SIZE uint64 = (1 << 40) - 1
	MAX_DATA_REGION_SIZE    uint64 = MAX_JOURNAL_REGION_SIZE * uint64(block.MIN)
)

Variables

View Source
var (
	SNAP_MAGIC_NUMBER           = [4]byte{'s', 'n', 'a', 'p'}
	SNAP_MAJOR_VERSION   uint16 = 0
	SNAP_MINOR_VERSION   uint16 = 3
	DEFAULT_REGION_SHIFT uint16 = 25
)
View Source
var (
	MAGIC_NUMBER = [4]byte{'l', 'u', 's', 'f'}
)

Functions

func ConvertToOffset

func ConvertToOffset(nvm NonVolatileMemory, offset int64, whence int) (int64, error)

func Open

func Open(path string) (nvm *FileNVM, header *StorageHeader, err error)

Types

type BackingFile added in v0.2.0

type BackingFile struct {
	JournalStart uint64
	JournalEnd   uint64
	// contains filtered or unexported fields
}

func CreateBackingFile added in v0.2.0

func CreateBackingFile(prefix string, maxCapacity uint64, currentCapacity uint64) (*BackingFile, error)

func OpenBackingFile added in v0.2.0

func OpenBackingFile(fileName string) (*BackingFile, error)

func (*BackingFile) Close added in v0.2.0

func (bf *BackingFile) Close()

func (*BackingFile) Delete added in v0.2.0

func (bf *BackingFile) Delete()

func (*BackingFile) GetCopyOffset added in v0.2.0

func (bf *BackingFile) GetCopyOffset(start uint64, end uint64) (onBacking []uint32, onOrigin []uint32)

give [start, end) of the buf onBacking[] offset of backing file in the unit of byte onOrigin[] offset of origing file in the unit of byte all aligned to regionSize

func (*BackingFile) GetFileName added in v0.2.0

func (bf *BackingFile) GetFileName() string

func (*BackingFile) ReadFromOffset added in v0.2.0

func (bf *BackingFile) ReadFromOffset(buf []byte, offset uint32) (int, error)

offset is the start of backing file

func (*BackingFile) RegionSize added in v0.2.0

func (bf *BackingFile) RegionSize() uint64

func (*BackingFile) Sync added in v0.2.0

func (bf *BackingFile) Sync()

func (*BackingFile) WriteOffset added in v0.2.0

func (bf *BackingFile) WriteOffset(buf []byte, offset uint32)

WriteOffset would write buf into backing file. buf's size must be regionSize, offset is buf's offset in origin file WriteOffset write journal first, and then write the buf

type BackingFileHeader added in v0.2.0

type BackingFileHeader struct {
	MajorVersion uint16
	MinorVersion uint16
	UUID         uuid.UUID
	RegionShift  uint16
	MaxCapacity  uint64
	JournalSize  uint64
	CreateTime   int64
	RawCapacity  uint64
}

Default RegionShift is 25 : 1<<25 == 32MB

func (*BackingFileHeader) WriteTo added in v0.2.0

func (self *BackingFileHeader) WriteTo(writer io.Writer) (err error)

type BitmapEntry added in v0.2.0

type BitmapEntry struct {
	OriginOffset uint32
	SnapOffset   uint32
}

the unit is fraction of "1 << RegionShift" , default is 32MB

func ReadRecordFrom added in v0.2.0

func ReadRecordFrom(reader io.Reader) BitmapEntry

func (BitmapEntry) CheckSum added in v0.2.0

func (entry BitmapEntry) CheckSum() uint32

func (BitmapEntry) Size added in v0.2.0

func (entry BitmapEntry) Size() uint64

func (BitmapEntry) WriteTo added in v0.2.0

func (entry BitmapEntry) WriteTo(writer io.Writer) (err error)

type FileNVM

type FileNVM struct {
	// contains filtered or unexported fields
}

func CreateIfAbsent

func CreateIfAbsent(path string, capacity uint64) (*FileNVM, error)

func (*FileNVM) BlockSize

func (nvm *FileNVM) BlockSize() block.BlockSize

func (*FileNVM) Capacity

func (nvm *FileNVM) Capacity() uint64

func (*FileNVM) Close

func (nvm *FileNVM) Close() error

func (*FileNVM) Position

func (self *FileNVM) Position() uint64

func (*FileNVM) RawSize

func (nvm *FileNVM) RawSize() int64

func (*FileNVM) Read

func (nvm *FileNVM) Read(buf []byte) (n int, err error)

func (*FileNVM) Seek

func (nvm *FileNVM) Seek(offset int64, whence int) (int64, error)

func (*FileNVM) Split

func (nvm *FileNVM) Split(position uint64) (sp1 NonVolatileMemory, sp2 NonVolatileMemory, err error)

func (*FileNVM) Sync

func (self *FileNVM) Sync() error

func (*FileNVM) ViewEnd added in v0.2.0

func (self *FileNVM) ViewEnd() uint64

func (*FileNVM) ViewStart added in v0.2.0

func (self *FileNVM) ViewStart() uint64

func (*FileNVM) Write

func (nvm *FileNVM) Write(buf []byte) (n int, err error)

type MemoryNVM

type MemoryNVM struct {
	// contains filtered or unexported fields
}

func New

func New(size uint64) (*MemoryNVM, error)

func NewFromVec

func NewFromVec(vec []byte) (*MemoryNVM, error)

func (*MemoryNVM) AsBytes

func (memory *MemoryNVM) AsBytes() []byte

for local test

func (*MemoryNVM) BlockSize

func (memory *MemoryNVM) BlockSize() block.BlockSize

func (*MemoryNVM) Capacity

func (memory *MemoryNVM) Capacity() uint64

func (*MemoryNVM) Close

func (memory *MemoryNVM) Close() error

func (*MemoryNVM) Position

func (memory *MemoryNVM) Position() uint64

func (*MemoryNVM) RawSize

func (memory *MemoryNVM) RawSize() int64

func (*MemoryNVM) Read

func (memory *MemoryNVM) Read(buf []byte) (n int, err error)

func (*MemoryNVM) Seek

func (memory *MemoryNVM) Seek(offset int64, whence int) (int64, error)

func (*MemoryNVM) Split

func (memory *MemoryNVM) Split(p uint64) (sp1 NonVolatileMemory, sp2 NonVolatileMemory, err error)

func (*MemoryNVM) Sync

func (memory *MemoryNVM) Sync() error

func (*MemoryNVM) Write

func (memory *MemoryNVM) Write(p []byte) (n int, err error)

type NonVolatileMemory

type NonVolatileMemory interface {
	io.ReadWriteSeeker
	io.Closer
	Sync() error
	Position() uint64
	Capacity() uint64
	BlockSize() block.BlockSize
	Split(position uint64) (NonVolatileMemory, NonVolatileMemory, error)
	RawSize() int64
}

type SnapNVM added in v0.2.0

type SnapNVM struct {
	// contains filtered or unexported fields
}

func NewSnapshotNVM added in v0.2.0

func NewSnapshotNVM(originFile *FileNVM) (*SnapNVM, error)

func (*SnapNVM) BlockSize added in v0.2.0

func (self *SnapNVM) BlockSize() block.BlockSize

func (*SnapNVM) Capacity added in v0.2.0

func (self *SnapNVM) Capacity() uint64

func (*SnapNVM) Close added in v0.2.0

func (self *SnapNVM) Close() error

func (*SnapNVM) CreateSnapshotIfNeeded added in v0.2.0

func (self *SnapNVM) CreateSnapshotIfNeeded() (err error)

func (*SnapNVM) DeleteSnapshot added in v0.2.0

func (self *SnapNVM) DeleteSnapshot() error

func (*SnapNVM) GetSnapshotReader added in v0.2.0

func (self *SnapNVM) GetSnapshotReader() (*SnapshotReader, error)

func (*SnapNVM) Position added in v0.2.0

func (self *SnapNVM) Position() uint64

func (*SnapNVM) RawSize added in v0.2.0

func (self *SnapNVM) RawSize() int64

func (*SnapNVM) Read added in v0.2.0

func (self *SnapNVM) Read(buf []byte) (n int, err error)

func (*SnapNVM) Seek added in v0.2.0

func (self *SnapNVM) Seek(offset int64, whence int) (int64, error)

FIXME

func (*SnapNVM) Split added in v0.2.0

func (self *SnapNVM) Split(position uint64) (sp1 NonVolatileMemory, sp2 NonVolatileMemory, err error)

func (*SnapNVM) Sync added in v0.2.0

func (self *SnapNVM) Sync() error

func (*SnapNVM) Write added in v0.2.0

func (self *SnapNVM) Write(buf []byte) (n int, err error)

type SnapshotReader added in v0.2.0

type SnapshotReader struct {
	// contains filtered or unexported fields
}

func (*SnapshotReader) Read added in v0.2.0

func (self *SnapshotReader) Read(p []byte) (n int, err error)

func (*SnapshotReader) Seek added in v0.2.0

func (self *SnapshotReader) Seek(offset int64, whence int) (int64, error)

type StorageHeader

type StorageHeader struct {
	MajorVersion      uint16
	MinorVersion      uint16
	BlockSize         block.BlockSize
	UUID              uuid.UUID
	JournalRegionSize uint64
	DataRegionSize    uint64
}

func DefaultStorageHeader

func DefaultStorageHeader() *StorageHeader

func ReadFrom

func ReadFrom(reader io.Reader) (*StorageHeader, error)

func ReadFromFile

func ReadFromFile(f *os.File) (*StorageHeader, error)

func (*StorageHeader) RegionSize

func (self *StorageHeader) RegionSize() uint64

func (*StorageHeader) SplitRegion

func (*StorageHeader) StorageSize

func (self *StorageHeader) StorageSize() uint64

func (*StorageHeader) WriteHeaderRegionTo

func (self *StorageHeader) WriteHeaderRegionTo(writer io.Writer) (err error)

func (*StorageHeader) WriteTo

func (self *StorageHeader) WriteTo(writer io.Writer) (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL