diff --git a/weed-fs/bin/.gitignore b/weed-fs/bin/.gitignore deleted file mode 100644 index aa3146581..000000000 --- a/weed-fs/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/weed diff --git a/weed-fs/src/cmd/weed/master.go b/weed-fs/src/cmd/weed/master.go index dee94e965..6dc3b06b9 100644 --- a/weed-fs/src/cmd/weed/master.go +++ b/weed-fs/src/cmd/weed/master.go @@ -39,7 +39,7 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) { vid = vid[0:commaSep] } volumeId, _ := strconv.ParseUint(vid, 10, 64) - machine, e := mapper.Get(uint32(volumeId)) + machine, e := mapper.Get(topology.VolumeId(volumeId)) if e == nil { writeJson(w, r, machine.Server) } else { diff --git a/weed-fs/src/pkg/directory/file_id.go b/weed-fs/src/pkg/directory/file_id.go index 4d9882897..be5388e61 100644 --- a/weed-fs/src/pkg/directory/file_id.go +++ b/weed-fs/src/pkg/directory/file_id.go @@ -4,18 +4,19 @@ import ( "encoding/hex" "log" "pkg/storage" + "pkg/topology" "strconv" "strings" "pkg/util" ) type FileId struct { - VolumeId uint32 + VolumeId topology.VolumeId Key uint64 Hashcode uint32 } -func NewFileId(VolumeId uint32, Key uint64, Hashcode uint32) *FileId { +func NewFileId(VolumeId topology.VolumeId, Key uint64, Hashcode uint32) *FileId { return &FileId{VolumeId: VolumeId, Key: Key, Hashcode: Hashcode} } func ParseFileId(fid string) *FileId{ @@ -27,7 +28,7 @@ func ParseFileId(fid string) *FileId{ vid_string, key_hash_string := a[0], a[1] vid, _ := strconv.ParseUint(vid_string, 10, 64) key, hash := storage.ParseKeyHash(key_hash_string) - return &FileId{VolumeId: uint32(vid), Key: key, Hashcode: hash} + return &FileId{VolumeId: topology.VolumeId(vid), Key: key, Hashcode: hash} } func (n *FileId) String() string { bytes := make([]byte, 12) diff --git a/weed-fs/src/pkg/directory/volume_mapping.go b/weed-fs/src/pkg/directory/volume_mapping.go index 0fb6c6a59..d48a6d12f 100644 --- a/weed-fs/src/pkg/directory/volume_mapping.go +++ b/weed-fs/src/pkg/directory/volume_mapping.go @@ -32,8 +32,8 @@ type Mapper struct { volumeLock sync.Mutex sequenceLock sync.Mutex Machines []*Machine - vid2machineId map[uint32]int //machineId is +1 of the index of []*Machine, to detect not found entries - Writers []uint32 // transient array of Writers volume id + vid2machineId map[topology.VolumeId]int //machineId is +1 of the index of []*Machine, to detect not found entries + Writers []topology.VolumeId // transient array of Writers volume id FileIdSequence uint64 fileIdCounter uint64 @@ -47,9 +47,9 @@ func NewMachine(server, publicUrl string, volumes []topology.VolumeInfo) *Machin func NewMapper(dirname string, filename string, volumeSizeLimit uint64) (m *Mapper) { m = &Mapper{dir: dirname, fileName: filename} - m.vid2machineId = make(map[uint32]int) + m.vid2machineId = make(map[topology.VolumeId]int) m.volumeSizeLimit = volumeSizeLimit - m.Writers = *new([]uint32) + m.Writers = *new([]topology.VolumeId) m.Machines = *new([]*Machine) seqFile, se := os.OpenFile(path.Join(m.dir, m.fileName+".seq"), os.O_RDONLY, 0644) @@ -102,7 +102,7 @@ func (m *Mapper) NextFileId(c string) (uint64,int) { m.fileIdCounter = m.fileIdCounter - count return m.FileIdSequence - m.fileIdCounter, int(count) } -func (m *Mapper) Get(vid uint32) (*Machine, error) { +func (m *Mapper) Get(vid topology.VolumeId) (*Machine, error) { machineId := m.vid2machineId[vid] if machineId <= 0 { return nil, errors.New("invalid volume id " + strconv.FormatUint(uint64(vid), 10)) @@ -134,7 +134,7 @@ func (m *Mapper) Add(machine Machine) { m.vid2machineId[v.Id] = machineId + 1 //use base 1 indexed, to detect not found cases } //setting Writers, copy-on-write because of possible updating, this needs some future work! - var writers []uint32 + var writers []topology.VolumeId for _, machine_entry := range m.Machines { for _, v := range machine_entry.Volumes { if uint64(v.Size) < m.volumeSizeLimit { diff --git a/weed-fs/src/pkg/storage/store.go b/weed-fs/src/pkg/storage/store.go index 93907c079..5a686d2db 100644 --- a/weed-fs/src/pkg/storage/store.go +++ b/weed-fs/src/pkg/storage/store.go @@ -64,7 +64,7 @@ func (s *Store) Status() *[]*topology.VolumeInfo { stats := new([]*topology.VolumeInfo) for k, v := range s.volumes { s := new(topology.VolumeInfo) - s.Id, s.Size = uint32(k), v.Size() + s.Id, s.Size = topology.VolumeId(k), v.Size() *stats = append(*stats, s) } return stats @@ -73,7 +73,7 @@ func (s *Store) Join(mserver string) { stats := new([]*topology.VolumeInfo) for k, v := range s.volumes { s := new(topology.VolumeInfo) - s.Id, s.Size = uint32(k), v.Size() + s.Id, s.Size = topology.VolumeId(k), v.Size() *stats = append(*stats, s) } bytes, _ := json.Marshal(stats) diff --git a/weed-fs/src/pkg/topology/node.go b/weed-fs/src/pkg/topology/node.go index cf48b0d67..2a556e5ad 100644 --- a/weed-fs/src/pkg/topology/node.go +++ b/weed-fs/src/pkg/topology/node.go @@ -4,13 +4,15 @@ import ( ) +type VolumeId uint32 type VolumeInfo struct { - Id uint32 + Id VolumeId Size int64 } type Node struct { - volumes map[uint64]VolumeInfo + volumes map[VolumeId]VolumeInfo volumeLimit int + Ip string Port int PublicUrl string }