segment

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package segment provided segment metadata support for storage.

This package handles segment operation details, and Storager implementer don't need to write their own segment logic.

Segment splits a File into several virtual parts, every part will have it's offset and size. Segment's life cycle contains five stage.

                                                 +----------------+
                                                 |                |
                                          +------>    Complete    |
                                          |      |                |
                                          |      +----------------+
                                          |
+------------+         +-------------+    |
|            |         |             |    |
|    Init    +-------->+    Write    +----+
|            |         |             |    |
+------------+         +-------------+    |
                                          |
                                          |      +-------------+
                                          |      |             |
                                          +------>    Abort    |
                                                 |             |
                                                 +-------------+

At Init stage

New segment will be created with an ID, this ID could have different meanings for different servers.

At Write stage

New Part will be added into segment, and segment will check this Part has no intersected areas with existed Part.

At Complete stage

Segment will check every part if connected, make sure there is no hole for it.

At Abort stage

Segment will be destroyed, and no more Part could be added into this segment.

Segment could be used in Storager segment API set

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPartSizeInvalid     = errors.New("part size invalid")
	ErrPartIntersected     = errors.New("part intersected")
	ErrSegmentNotInitiated = errors.New("segment not initiated")
	ErrSegmentPartsEmpty   = errors.New("segment Parts are empty")
	ErrSegmentNotFulfilled = errors.New("segment not fulfilled")
)

All errors that segment could return.

Functions

This section is empty.

Types

type Func added in v0.4.0

type Func func(segment *Segment)

Func will handle a Segment.

type Part

type Part struct {
	Offset int64
	Size   int64

	Index int
}

Part is a part of segment.

func (*Part) String

func (p *Part) String() string

type Segment

type Segment struct {
	ID       string
	Path     string
	PartSize int64
	Parts    map[int64]*Part
	// contains filtered or unexported fields
}

Segment will hold the whole segment operations.

func NewSegment added in v0.3.0

func NewSegment(path, id string, partSize int64) *Segment

NewSegment will init a new segment.

func (*Segment) InsertPart

func (s *Segment) InsertPart(offset, size int64) (p *Part, err error)

InsertPart will insert a part into a segment and return it's Index. Index will start from 0.

func (*Segment) SortedParts added in v0.3.0

func (s *Segment) SortedParts() []*Part

SortedParts will return sorted Parts.

func (*Segment) String

func (s *Segment) String() string

func (*Segment) ValidateParts

func (s *Segment) ValidateParts() (err error)

ValidateParts will validate a segment's Parts.

Jump to

Keyboard shortcuts

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