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 ¶
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 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
NewSegment will init a new segment.
func (*Segment) InsertPart ¶
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
SortedParts will return sorted Parts.
func (*Segment) ValidateParts ¶
ValidateParts will validate a segment's Parts.