segment

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: Apache-2.0 Imports: 3 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    |
                                                 |             |
                                                 +-------------+
                       +------------+
                       |            |
                       |    Read    |
                       |            |
                       +------------+

At Init stage

New segment will be created with a 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 is 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.

At Read stage

This stage is special and will not be handled by Segment, and don't need to call Init before use this API call.

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")
	ErrSegmentAlreadyInitiated = errors.New("segment already initiated")
	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 Part

type Part struct {
	Offset int64
	Size   int64
}

Part is a part of segment.

func (*Part) String

func (p *Part) String() string

type Segment

type Segment struct {
	ID    string
	Path  string
	Parts []*Part
}

Segment will hold the whole segment operations.

func (*Segment) GetPartIndex

func (s *Segment) GetPartIndex(p *Part) (cur int, err error)

GetPartIndex will get a part's insert index in a segment.

func (*Segment) InsertPart

func (s *Segment) InsertPart(p *Part) (err error)

InsertPart will insert a part into a segment.

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