metanode

package
v0.0.0-...-71dd0ca Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateStandby uint32 = iota
	StateStart
	StateRunning
	StateShutdown
	StateStopped
)
View Source
const (
	ForceCloseConnect = true
	NoCloseConnect    = false
)
View Source
const (
	AsyncDeleteInterval = 10 * time.Second
	UpdateVolTicket     = 5 * time.Minute
	BatchCounts         = 100
)
View Source
const (
	DataPartitionViewUrl = "/client/dataPartitions"
)

Variables

View Source
var (
	ErrNonLeader = errors.New("non leader")
	ErrNotLeader = errors.New("not leader")
)
View Source
var (
	ErrIllegalHeartbeatAddress = errors.New("illegal heartbeat address")
	ErrIllegalReplicateAddress = errors.New("illegal replicate address")
)
View Source
var (
	ErrInodeOutOfRange = errors.New("inode ID out of range")
)

Errors

View Source
var (
	UMPKey string
)

Functions

This section is empty.

Types

type BTree

type BTree struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBtree

func NewBtree() *BTree

func (*BTree) Ascend

func (b *BTree) Ascend(fn func(i BtreeItem) bool)

func (*BTree) AscendGreaterOrEqual

func (b *BTree) AscendGreaterOrEqual(pivot BtreeItem, iterator func(i BtreeItem) bool)

func (*BTree) AscendRange

func (b *BTree) AscendRange(greaterOrEqual, lessThan BtreeItem, iterator func(i BtreeItem) bool)

func (*BTree) Delete

func (b *BTree) Delete(key BtreeItem) BtreeItem

func (*BTree) Find

func (b *BTree) Find(key BtreeItem, fn func(i BtreeItem))

func (*BTree) Get

func (b *BTree) Get(key BtreeItem) BtreeItem

func (*BTree) GetTree

func (b *BTree) GetTree() *BTree

func (*BTree) Has

func (b *BTree) Has(key BtreeItem) bool

func (*BTree) Len

func (b *BTree) Len() int

func (*BTree) ReplaceOrInsert

func (b *BTree) ReplaceOrInsert(key BtreeItem, replace bool) (BtreeItem, bool)

func (*BTree) Reset

func (b *BTree) Reset()

type BtreeItem

type BtreeItem = btree.Item

type CreateDentryReq

type CreateDentryReq = proto.CreateDentryRequest

Client -> MetaNode create Dentry request struct

type CreateInoReq

type CreateInoReq = proto.CreateInodeRequest

Client -> MetaNode create Inode request struct

type CreateInoResp

type CreateInoResp = proto.CreateInodeResponse

MetaNode -> Client create Inode response struct

type CreateMetaRangeReq

type CreateMetaRangeReq = proto.CreateMetaPartitionRequest

Master -> MetaNode create metaPartition request struct

type CreateMetaRangeResp

type CreateMetaRangeResp = proto.CreateMetaPartitionResponse

MetaNode -> Master create metaPartition response struct

type DataPartition

type DataPartition struct {
	PartitionID   uint32
	Status        int8
	ReplicaNum    uint8
	PartitionType string
	Hosts         []string
}

func (*DataPartition) GetAllAddrs

func (dp *DataPartition) GetAllAddrs() (m string)

type DataPartitionsView

type DataPartitionsView struct {
	DataPartitions []*DataPartition
}

type DeleteDentryReq

type DeleteDentryReq = proto.DeleteDentryRequest

Client -> MetaNode delete Dentry request struct

type DeleteDentryResp

type DeleteDentryResp = proto.DeleteDentryResponse

MetaNode -> Client delete Dentry response struct

type DeleteInoReq

type DeleteInoReq = proto.DeleteInodeRequest

Client -> MetaNode delete Inode request struct

type DeleteInoResp

type DeleteInoResp = proto.DeleteInodeResponse

MetaNode -> Client delete Inode response

type Dentry

type Dentry struct {
	ParentId uint64 // FileId value of parent inode.
	Name     string // Name of current dentry.
	Inode    uint64 // FileId value of current inode.
	Type     uint32 // Dentry type.
}

Dentry wraps necessary properties of `Dentry` information in file system. Marshal key:

+-------+----------+------+
| item  | ParentId | Name |
+-------+----------+------+
| bytes |    8     | rest |
+-------+----------+------+

Marshal value:

+-------+-------+------+
| item  | Inode | Type |
+-------+-------+------+
| bytes |   8   |   4  |
+-------+-------+------+

Marshal entity:

+-------+-----------+--------------+-----------+--------------+
| item  | KeyLength | MarshaledKey | ValLength | MarshaledVal |
+-------+-----------+--------------+-----------+--------------+
| bytes |     4     |   KeyLength  |     4     |   ValLength  |
+-------+-----------+--------------+-----------+--------------+

func (*Dentry) Less

func (d *Dentry) Less(than btree.Item) (less bool)

Less tests whether the current Dentry item is less than the given one. This method is necessary fot B-Tree item implementation.

func (*Dentry) Marshal

func (d *Dentry) Marshal() (result []byte, err error)

Marshal dentry item to bytes.

func (*Dentry) MarshalKey

func (d *Dentry) MarshalKey() (k []byte)

MarshalKey is the bytes version of MarshalKey method which returns byte slice result.

func (*Dentry) MarshalValue

func (d *Dentry) MarshalValue() (k []byte)

MarshalValue marshal key to bytes.

func (*Dentry) Unmarshal

func (d *Dentry) Unmarshal(raw []byte) (err error)

Unmarshal dentry item from bytes.

func (*Dentry) UnmarshalKey

func (d *Dentry) UnmarshalKey(k []byte) (err error)

UnmarshalKey unmarshal key from bytes.

func (*Dentry) UnmarshalValue

func (d *Dentry) UnmarshalValue(val []byte) (err error)

UnmarshalValue unmarshal value from bytes.

type EvictInodeReq

type EvictInodeReq = proto.EvictInodeRequest

Client -> MetaNode

type ExtentsTruncateReq

type ExtentsTruncateReq = proto.TruncateRequest

Client -> MetaNode

type ExtentsTruncateResp

type ExtentsTruncateResp = proto.TruncateResponse

MetaNode -> Client

type Inode

type Inode struct {
	Inode      uint64 // Inode ID
	Type       uint32
	Uid        uint32
	Gid        uint32
	Size       uint64
	Generation uint64
	CreateTime int64
	AccessTime int64
	ModifyTime int64
	LinkTarget []byte // SymLink target name
	NLink      uint32 // NodeLink counts
	MarkDelete uint8  // 0: false; 1: true
	Extents    *proto.StreamKey
}

Inode wraps necessary properties of `Inode` information in file system. Marshal key:

+-------+-------+
| item  | Inode |
+-------+-------+
| bytes |   8   |
+-------+-------+

Marshal value:

+-------+------+------+-----+----+----+----+--------+------------------+
| item  | Type | Size | Gen | CT | AT | MT | ExtLen | MarshaledExtents |
+-------+------+------+-----+----+----+----+--------+------------------+
| bytes |  4   |  8   |  8  | 8  | 8  | 8  |   4    |      ExtLen      |
+-------+------+------+-----+----+----+----+--------+------------------+

Marshal entity:

+-------+-----------+--------------+-----------+--------------+
| item  | KeyLength | MarshaledKey | ValLength | MarshaledVal |
+-------+-----------+--------------+-----------+--------------+
| bytes |     4     |   KeyLength  |     4     |   ValLength  |
+-------+-----------+--------------+-----------+--------------+

func NewInode

func NewInode(ino uint64, t uint32) *Inode

NewInode returns a new Inode instance pointer with specified Inode ID, name and Inode type code. The AccessTime and ModifyTime of new instance will be set to current time.

func (*Inode) AppendExtents

func (i *Inode) AppendExtents(ext proto.ExtentKey)

func (*Inode) Less

func (i *Inode) Less(than btree.Item) bool

Less tests whether the current Inode item is less than the given one. This method is necessary fot B-Tree item implementation.

func (*Inode) Marshal

func (i *Inode) Marshal() (result []byte, err error)

func (*Inode) MarshalKey

func (i *Inode) MarshalKey() (k []byte)

MarshalKey marshal key to bytes.

func (*Inode) MarshalValue

func (i *Inode) MarshalValue() (val []byte)

MarshalValue marshal value to bytes.

func (*Inode) String

func (i *Inode) String() string

func (*Inode) Unmarshal

func (i *Inode) Unmarshal(raw []byte) (err error)

func (*Inode) UnmarshalKey

func (i *Inode) UnmarshalKey(k []byte) (err error)

UnmarshalKey unmarshal key from bytes.

func (*Inode) UnmarshalValue

func (i *Inode) UnmarshalValue(val []byte) (err error)

UnmarshalValue unmarshal value from bytes.

type InodeGetReq

type InodeGetReq = proto.InodeGetRequest

Client -> MetaNode

type InodeGetReqBatch

type InodeGetReqBatch = proto.BatchInodeGetRequest

Client -> MetaNode

type ItemIterator

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

func NewMetaItemIterator

func NewMetaItemIterator(applyID uint64, ino, den *BTree) *ItemIterator

func (*ItemIterator) ApplyIndex

func (si *ItemIterator) ApplyIndex() uint64

func (*ItemIterator) Close

func (si *ItemIterator) Close()

func (*ItemIterator) Next

func (si *ItemIterator) Next() (data []byte, err error)

type LinkInodeReq

type LinkInodeReq = proto.LinkInodeRequest

Client -> MetaNode create Link Request

type LinkInodeResp

type LinkInodeResp = proto.LinkInodeResponse

MetaNode -> Client create Link Response

type LookupReq

type LookupReq = proto.LookupRequest

MetaNode -> Client lookup

type LookupResp

type LookupResp = proto.LookupResponse

Client -> MetaNode lookup

type MetaItem

type MetaItem struct {
	Op uint32 `json:"op"`
	K  []byte `json:"k"`
	V  []byte `json:"v"`
}

func NewMetaItem

func NewMetaItem(op uint32, key, value []byte) *MetaItem

func (*MetaItem) MarshalBinary

func (s *MetaItem) MarshalBinary() (result []byte, err error)

MarshalBinary marshal this MetaItem entity to binary data. Binary frame structure:

+------+----+------+------+------+------+
| Item | Op | LenK |   K  | LenV |   V  |
+------+----+------+------+------+------+
| byte | 4  |  4   | LenK |  4   | LenV |
+------+----+------+------+------+------+

func (*MetaItem) MarshalJson

func (s *MetaItem) MarshalJson() ([]byte, error)

MarshalJson

func (*MetaItem) UnmarshalBinary

func (s *MetaItem) UnmarshalBinary(raw []byte) (err error)

MarshalBinary unmarshal this MetaItem entity from binary data. Binary frame structure:

+------+----+------+------+------+------+
| Item | Op | LenK |   K  | LenV |   V  |
+------+----+------+------+------+------+
| byte | 4  |  4   | LenK |  4   | LenV |
+------+----+------+------+------+------+

func (*MetaItem) UnmarshalJson

func (s *MetaItem) UnmarshalJson(data []byte) error

UnmarshalJson unmarshal binary data to MetaItem entity.

type MetaManager

type MetaManager interface {
	Start() error
	Stop()
	//CreatePartition(id string, start, end uint64, peers []proto.Peer) error
	HandleMetaOperation(conn net.Conn, p *Packet) error
	GetPartition(id uint64) (MetaPartition, error)
}

MetaManager manage all metaPartition and make mapping between volName and metaPartition.

func NewMetaManager

func NewMetaManager(conf MetaManagerConfig) MetaManager

type MetaManagerConfig

type MetaManagerConfig struct {
	NodeID    uint64
	RootDir   string
	RaftStore raftstore.RaftStore
}

type MetaNode

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

The MetaNode manage Dentry and Inode information in multiple metaPartition, and through the RaftStore algorithm and other MetaNodes in the RageGroup for reliable data synchronization to maintain data consistency within the MetaGroup.

func NewServer

func NewServer() *MetaNode

NewServer create an new MetaNode instance.

func (*MetaNode) Shutdown

func (m *MetaNode) Shutdown()

Shutdown stop this MetaNode.

func (*MetaNode) Start

func (m *MetaNode) Start(cfg *config.Config) (err error)

Start this MeteNode with specified configuration.

  1. Start and load each meta partition from snapshot.
  2. Restore raftStore fsm of each meta range.
  3. Start server and accept connection from master and clients.

func (*MetaNode) Sync

func (m *MetaNode) Sync()

Sync will block invoker goroutine until this MetaNode shutdown.

type MetaPartition

type MetaPartition interface {
	Start() error
	Stop()
	OpMeta
}

func NewMetaPartition

func NewMetaPartition(conf *MetaPartitionConfig) MetaPartition

NewMetaPartition create and init a new meta partition with specified configuration.

type MetaPartitionConfig

type MetaPartitionConfig struct {
	PartitionId uint64              `json:"partition_id"`
	VolName     string              `json:"vol_name"`
	Start       uint64              `json:"start"`
	End         uint64              `json:"end"`
	Peers       []proto.Peer        `json:"peers"`
	Cursor      uint64              `json:"-"`
	NodeId      uint64              `json:"-"`
	RootDir     string              `json:"-"`
	BeforeStart func()              `json:"-"`
	AfterStart  func()              `json:"-"`
	BeforeStop  func()              `json:"-"`
	AfterStop   func()              `json:"-"`
	RaftStore   raftstore.RaftStore `json:"-"`
	ConnPool    *pool.ConnectPool   `json:"-"`
}
MetRangeConfig used by create metaPartition and serialize

PartitionId: Identity for raftStore group,RaftStore nodes in same raftStore group must have same groupID. Start: Minimal Inode ID of this range. (Required when initialize) End: Maximal Inode ID of this range. (Required when initialize) Cursor: Cursor ID value of Inode what have been already assigned. Peers: Peers information for raftStore.

func (*MetaPartitionConfig) Dump

func (c *MetaPartitionConfig) Dump() ([]byte, error)

func (*MetaPartitionConfig) Load

func (c *MetaPartitionConfig) Load(bytes []byte) error

type OpDentry

type OpDentry interface {
	CreateDentry(req *CreateDentryReq, p *Packet) (err error)
	DeleteDentry(req *DeleteDentryReq, p *Packet) (err error)
	UpdateDentry(req *UpdateDentryReq, p *Packet) (err error)
	ReadDir(req *ReadDirReq, p *Packet) (err error)
	Lookup(req *LookupReq, p *Packet) (err error)
}

type OpExtent

type OpExtent interface {
	ExtentAppend(req *proto.AppendExtentKeyRequest, p *Packet) (err error)
	ExtentsList(req *proto.GetExtentsRequest, p *Packet) (err error)
	ExtentsTruncate(req *ExtentsTruncateReq, p *Packet) (err error)
}

type OpInode

type OpInode interface {
	CreateInode(req *CreateInoReq, p *Packet) (err error)
	DeleteInode(req *DeleteInoReq, p *Packet) (err error)
	InodeGet(req *InodeGetReq, p *Packet) (err error)
	InodeGetBatch(req *InodeGetReqBatch, p *Packet) (err error)
	Open(req *OpenReq, p *Packet) (err error)
	CreateLinkInode(req *LinkInodeReq, p *Packet) (err error)
	EvictInode(req *EvictInodeReq, p *Packet) (err error)
	SetAttr(reqData []byte, p *Packet) (err error)
}

type OpMeta

type OpMeta interface {
	OpInode
	OpDentry
	OpExtent
	OpPartition
}

type OpPartition

type OpPartition interface {
	IsLeader() (leaderAddr string, isLeader bool)
	GetCursor() uint64
	GetBaseConfig() MetaPartitionConfig
	StoreMeta() (err error)
	ChangeMember(changeType raftproto.ConfChangeType, peer raftproto.Peer, context []byte) (resp interface{}, err error)
	DeletePartition() (err error)
	UpdatePartition(req *UpdatePartitionReq, resp *UpdatePartitionResp) (err error)
	DeleteRaft() error
}

type OpenReq

type OpenReq = proto.OpenRequest

Client -> MetaNode open file request struct

type Packet

type Packet struct {
	proto.Packet
}

func NewExtentDeletePacket

func NewExtentDeletePacket(dp *DataPartition, extentId uint64) *Packet

For send delete request to dataNode

type ReadDirReq

type ReadDirReq = proto.ReadDirRequest

Client -> MetaNode read dir request struct

type ReadDirResp

type ReadDirResp = proto.ReadDirResponse

MetaNode -> Client read dir response struct

type ResponseDentry

type ResponseDentry struct {
	Status uint8
	Msg    *Dentry
}

func NewResponseDentry

func NewResponseDentry() *ResponseDentry

type ResponseInode

type ResponseInode struct {
	Status uint8
	Msg    *Inode
}

func NewResponseInode

func NewResponseInode() *ResponseInode

type SetattrRequest

type SetattrRequest = proto.SetattrRequest

Client -> MetaNOde

type UpdateDentryReq

type UpdateDentryReq = proto.UpdateDentryRequest

Client -> MetaNode updateDentry request struct

type UpdateDentryResp

type UpdateDentryResp = proto.UpdateDentryResponse

MetaNode -> Client updateDentry response struct

type UpdatePartitionReq

type UpdatePartitionReq = proto.UpdateMetaPartitionRequest

Master -> MetaNode

type UpdatePartitionResp

type UpdatePartitionResp = proto.UpdateMetaPartitionResponse

MetaNode -> Master

type Vol

type Vol struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewVol

func NewVol() *Vol

func (*Vol) GetPartition

func (v *Vol) GetPartition(partitionID uint32) *DataPartition

func (*Vol) UpdatePartitions

func (v *Vol) UpdatePartitions(partitions *DataPartitionsView)

Jump to

Keyboard shortcuts

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