aboutsummaryrefslogtreecommitdiff
path: root/weed-fs/src/pkg
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2012-08-23 22:56:14 -0700
committerChris Lu <chris.lu@gmail.com>2012-08-23 22:56:14 -0700
commit9f92f2779dac7c3456ca16958ea6fc05a24924e1 (patch)
tree3db8f575286111fa2e323f83c896c180327a4682 /weed-fs/src/pkg
parent5e3ecc1b82dd08442fa3d9e52d15e68c82e8add6 (diff)
downloadseaweedfs-9f92f2779dac7c3456ca16958ea6fc05a24924e1.tar.xz
seaweedfs-9f92f2779dac7c3456ca16958ea6fc05a24924e1.zip
adjusting for types
Diffstat (limited to 'weed-fs/src/pkg')
-rw-r--r--weed-fs/src/pkg/directory/file_id.go7
-rw-r--r--weed-fs/src/pkg/directory/volume_mapping.go18
-rw-r--r--weed-fs/src/pkg/storage/store.go15
-rw-r--r--weed-fs/src/pkg/storage/volume.go4
-rw-r--r--weed-fs/src/pkg/topology/node.go11
5 files changed, 27 insertions, 28 deletions
diff --git a/weed-fs/src/pkg/directory/file_id.go b/weed-fs/src/pkg/directory/file_id.go
index be5388e61..723d94276 100644
--- a/weed-fs/src/pkg/directory/file_id.go
+++ b/weed-fs/src/pkg/directory/file_id.go
@@ -4,19 +4,18 @@ import (
"encoding/hex"
"log"
"pkg/storage"
- "pkg/topology"
"strconv"
"strings"
"pkg/util"
)
type FileId struct {
- VolumeId topology.VolumeId
+ VolumeId storage.VolumeId
Key uint64
Hashcode uint32
}
-func NewFileId(VolumeId topology.VolumeId, Key uint64, Hashcode uint32) *FileId {
+func NewFileId(VolumeId storage.VolumeId, Key uint64, Hashcode uint32) *FileId {
return &FileId{VolumeId: VolumeId, Key: Key, Hashcode: Hashcode}
}
func ParseFileId(fid string) *FileId{
@@ -28,7 +27,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: topology.VolumeId(vid), Key: key, Hashcode: hash}
+ return &FileId{VolumeId: storage.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 d48a6d12f..a6748f5c6 100644
--- a/weed-fs/src/pkg/directory/volume_mapping.go
+++ b/weed-fs/src/pkg/directory/volume_mapping.go
@@ -7,7 +7,7 @@ import (
"math/rand"
"os"
"path"
- "pkg/topology"
+ "pkg/storage"
"strconv"
"sync"
)
@@ -22,7 +22,7 @@ type MachineInfo struct {
}
type Machine struct {
Server MachineInfo
- Volumes []topology.VolumeInfo
+ Volumes []storage.VolumeInfo
}
type Mapper struct {
@@ -32,8 +32,8 @@ type Mapper struct {
volumeLock sync.Mutex
sequenceLock sync.Mutex
Machines []*Machine
- 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
+ vid2machineId map[storage.VolumeId]int //machineId is +1 of the index of []*Machine, to detect not found entries
+ Writers []storage.VolumeId // transient array of Writers volume id
FileIdSequence uint64
fileIdCounter uint64
@@ -41,15 +41,15 @@ type Mapper struct {
volumeSizeLimit uint64
}
-func NewMachine(server, publicUrl string, volumes []topology.VolumeInfo) *Machine {
+func NewMachine(server, publicUrl string, volumes []storage.VolumeInfo) *Machine {
return &Machine{Server: MachineInfo{Url: server, PublicUrl: publicUrl}, Volumes: volumes}
}
func NewMapper(dirname string, filename string, volumeSizeLimit uint64) (m *Mapper) {
m = &Mapper{dir: dirname, fileName: filename}
- m.vid2machineId = make(map[topology.VolumeId]int)
+ m.vid2machineId = make(map[storage.VolumeId]int)
m.volumeSizeLimit = volumeSizeLimit
- m.Writers = *new([]topology.VolumeId)
+ m.Writers = *new([]storage.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 topology.VolumeId) (*Machine, error) {
+func (m *Mapper) Get(vid storage.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 []topology.VolumeId
+ var writers []storage.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 cd32a0ccf..ef7bc82fd 100644
--- a/weed-fs/src/pkg/storage/store.go
+++ b/weed-fs/src/pkg/storage/store.go
@@ -7,7 +7,6 @@ import (
"net/url"
"strconv"
"strings"
- "pkg/topology"
"pkg/util"
)
@@ -60,20 +59,20 @@ func (s *Store) addVolume(vid VolumeId) error {
s.volumes[vid] = NewVolume(s.dir, vid)
return nil
}
-func (s *Store) Status() *[]*topology.VolumeInfo {
- stats := new([]*topology.VolumeInfo)
+func (s *Store) Status() *[]*VolumeInfo {
+ stats := new([]*VolumeInfo)
for k, v := range s.volumes {
- s := new(topology.VolumeInfo)
- s.Id, s.Size = topology.VolumeId(k), v.Size()
+ s := new(VolumeInfo)
+ s.Id, s.Size = VolumeId(k), v.Size()
*stats = append(*stats, s)
}
return stats
}
func (s *Store) Join(mserver string) {
- stats := new([]*topology.VolumeInfo)
+ stats := new([]*VolumeInfo)
for k, v := range s.volumes {
- s := new(topology.VolumeInfo)
- s.Id, s.Size = topology.VolumeId(k), v.Size()
+ s := new(VolumeInfo)
+ s.Id, s.Size = VolumeId(k), v.Size()
*stats = append(*stats, s)
}
bytes, _ := json.Marshal(stats)
diff --git a/weed-fs/src/pkg/storage/volume.go b/weed-fs/src/pkg/storage/volume.go
index 40e3eaaf4..55e389029 100644
--- a/weed-fs/src/pkg/storage/volume.go
+++ b/weed-fs/src/pkg/storage/volume.go
@@ -14,6 +14,10 @@ const (
)
type VolumeId uint32
+type VolumeInfo struct {
+ Id VolumeId
+ Size int64
+}
func NewVolumeId(vid string) (VolumeId,error) {
volumeId, err := strconv.ParseUint(vid, 10, 64)
return VolumeId(volumeId), err
diff --git a/weed-fs/src/pkg/topology/node.go b/weed-fs/src/pkg/topology/node.go
index 91f9a1373..4eccdbf65 100644
--- a/weed-fs/src/pkg/topology/node.go
+++ b/weed-fs/src/pkg/topology/node.go
@@ -1,15 +1,12 @@
package topology
-import ()
+import (
+ "pkg/storage"
+)
type NodeId uint32
-type VolumeId uint32
-type VolumeInfo struct {
- Id VolumeId
- Size int64
-}
type Node struct {
- volumes map[VolumeId]VolumeInfo
+ volumes map[storage.VolumeId]storage.VolumeInfo
volumeLimit int
Ip string
Port int