aboutsummaryrefslogtreecommitdiff
path: root/weed-fs/src/pkg
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2012-08-27 13:52:02 -0700
committerChris Lu <chris.lu@gmail.com>2012-08-27 13:52:02 -0700
commit2dceb44ae44cddd435cc6c8bdc813a26176adc51 (patch)
tree5e3c8fd2a990e84017eb4d1b65040eeb022abe54 /weed-fs/src/pkg
parentc72f10511a46fb1dafc4945faf4aedcd4000f254 (diff)
downloadseaweedfs-2dceb44ae44cddd435cc6c8bdc813a26176adc51.tar.xz
seaweedfs-2dceb44ae44cddd435cc6c8bdc813a26176adc51.zip
add more for volume placement
fix possible nil volume cases
Diffstat (limited to 'weed-fs/src/pkg')
-rw-r--r--weed-fs/src/pkg/replication/volume_growth.go29
-rw-r--r--weed-fs/src/pkg/storage/storage_limit.go10
-rw-r--r--weed-fs/src/pkg/storage/storage_limit_test.go11
-rw-r--r--weed-fs/src/pkg/storage/store.go18
-rw-r--r--weed-fs/src/pkg/topology/node.go15
-rw-r--r--weed-fs/src/pkg/topology/topology.go9
6 files changed, 68 insertions, 24 deletions
diff --git a/weed-fs/src/pkg/replication/volume_growth.go b/weed-fs/src/pkg/replication/volume_growth.go
new file mode 100644
index 000000000..49afc741c
--- /dev/null
+++ b/weed-fs/src/pkg/replication/volume_growth.go
@@ -0,0 +1,29 @@
+package replication
+
+import (
+ "pkg/topology"
+)
+
+/*
+This package is created to resolve these replica placement issues:
+1. growth factor for each replica level, e.g., add 10 volumes for 1 copy, 20 volumes for 2 copies, 30 volumes for 3 copies
+2. in time of tight storage, how to reduce replica level
+3. optimizing for hot data on faster disk, cold data on cheaper storage,
+4. volume allocation for each bucket
+*/
+
+type VolumeGrowth struct {
+ copy1factor int
+ copy2factor int
+ copy3factor int
+ copyAll int
+}
+
+func (vg *VolumeGrowth) GrowVolumeCopy(copyLevel int, topo topology.Topology) {
+ if copyLevel == 1 {
+ for i := 0; i <vg.copy1factor; i++ {
+ topo.RandomlyCreateOneVolume()
+ }
+ }
+
+}
diff --git a/weed-fs/src/pkg/storage/storage_limit.go b/weed-fs/src/pkg/storage/storage_limit.go
index 915ec48a3..b40618046 100644
--- a/weed-fs/src/pkg/storage/storage_limit.go
+++ b/weed-fs/src/pkg/storage/storage_limit.go
@@ -1,21 +1,13 @@
package storage
import (
- "syscall"
)
type StorageLimit struct {
sizeLimit uint64
- detectedLimit uint64
}
func NewStorageLimit(desiredLimit uint64) *StorageLimit {
- s := syscall.Statfs_t{}
- errNo := syscall.Statfs(".", &s)
- detected := uint64(0)
- if errNo==nil {
- detected = s.Bavail*uint64(s.Bsize)
- }
- sl := &StorageLimit{sizeLimit: desiredLimit, detectedLimit: detected}
+ sl := &StorageLimit{sizeLimit: desiredLimit}
return sl
}
diff --git a/weed-fs/src/pkg/storage/storage_limit_test.go b/weed-fs/src/pkg/storage/storage_limit_test.go
deleted file mode 100644
index c818356f9..000000000
--- a/weed-fs/src/pkg/storage/storage_limit_test.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package storage
-
-import (
- "testing"
-)
-
-func TestReadStorageLimit(t *testing.T) {
- sl := NewStorageLimit(1000)
- println("detected:",sl.detectedLimit)
-}
-
diff --git a/weed-fs/src/pkg/storage/store.go b/weed-fs/src/pkg/storage/store.go
index 1c3ba4a51..1dbb89c06 100644
--- a/weed-fs/src/pkg/storage/store.go
+++ b/weed-fs/src/pkg/storage/store.go
@@ -89,11 +89,23 @@ func (s *Store) Close() {
}
}
func (s *Store) Write(i VolumeId, n *Needle) uint32 {
- return s.volumes[i].write(n)
+ v := s.volumes[i]
+ if v!=nil{
+ return v.write(n)
+ }
+ return 0
}
func (s *Store) Delete(i VolumeId, n *Needle) uint32 {
- return s.volumes[i].delete(n)
+ v := s.volumes[i]
+ if v!=nil{
+ return v.delete(n)
+ }
+ return 0
}
func (s *Store) Read(i VolumeId, n *Needle) (int, error) {
- return s.volumes[i].read(n)
+ v := s.volumes[i]
+ if v!=nil{
+ return v.read(n)
+ }
+ return 0, errors.New("Not Found")
}
diff --git a/weed-fs/src/pkg/topology/node.go b/weed-fs/src/pkg/topology/node.go
index 4eccdbf65..9c1a87f89 100644
--- a/weed-fs/src/pkg/topology/node.go
+++ b/weed-fs/src/pkg/topology/node.go
@@ -11,4 +11,19 @@ type Node struct {
Ip string
Port int
PublicUrl string
+
+ //transient
+ allocation *Allocation
}
+type Allocation struct {
+ count int
+ limit int
+}
+
+func (n *Node) GetAllocation() *Allocation{
+ if n.allocation == nil {
+ n.allocation = &Allocation{count:len(n.volumes), limit : n.volumeLimit}
+ }
+ return n.allocation
+}
+
diff --git a/weed-fs/src/pkg/topology/topology.go b/weed-fs/src/pkg/topology/topology.go
index 7db3d0e32..7d903b961 100644
--- a/weed-fs/src/pkg/topology/topology.go
+++ b/weed-fs/src/pkg/topology/topology.go
@@ -1,9 +1,16 @@
package topology
import (
-
+ "pkg/storage"
)
type Topology struct {
datacenters map[DataCenterId]*DataCenter
}
+//FIXME
+func (t *Topology) RandomlyCreateOneVolume() storage.VolumeId{
+ return t.findMaxVolumeId()
+}
+func (t *Topology) findMaxVolumeId() storage.VolumeId{
+ return storage.VolumeId(0);
+}