WeedFS 源码分析

/storage/volume_ttl.go

type TTL struct {
    count byte
    unit  byte
}

由数值和单位构成,从说明文档来看,单位支持m, h, d, w, M, y

/storage/replica_placement.go

type ReplicaPlacement struct {
    SameRackCount       int
    DiffRackCount       int
    DiffDataCenterCount int
}

这个表示了分片的类型,对外显示为 012 这样的数字,每一个数字的取值范围为0-2.

结构关系

{topology.Collection} -> {topology.VolumesLayout} -> {storage.VolumeId}

/topology/collection.go

type Collection struct {
    Name                     string
    volumeSizeLimit          uint64
    storageType2VolumeLayout *util.ConcurrentReadMap
}

默认在上传的时候如果不制定,会使用一个Name为空的Collection。具体体现是在Volume目录下会产生{CollectionName}_{VolumeId}.{idx|dat}的文件。如果名字为空,则仅仅是{VolumeId}.{idx|dat}.

Name 当前Collection的名字,默认为""
volumeSizeLimit 用于限制每个volume的大小
storageType2VolumeLayout key的构造规则是 {分片类型}+{TTL}, Value 是一个 VolumeLayout

/topology/volume_layout.go

type VolumeLayout struct {
    rp              *storage.ReplicaPlacement
    ttl             *storage.TTL
    vid2location    map[storage.VolumeId]*VolumeLocationList
    writables       []storage.VolumeId // transient array of writable volume id
    volumeSizeLimit uint64
    accessLock      sync.Mutex
}

func NewVolumeLayout(
    rp *storage.ReplicaPlacement,
    ttl *storage.TTL,
    volumeSizeLimit uint64) *VolumeLayout

一般VolumeLayout的创建过程是在Collection进行。

待续

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值