Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

remote assigns volume to volume server

Chris Lu9e0f8d9f0da8
diff --git a/weed-fs/note/replication.txt b/weed-fs/note/replication.txt
index be5bea4465..c7d5d07679 100644
--- a/weed-fs/note/replication.txt
+++ b/weed-fs/note/replication.txt
@@ -65,6 +65,7 @@ Plan:
For the above operations, here are the todo list:
for data node:
+ 0. detect existing volumes
1. onStartUp, and periodically, send existing volumes and maxVolumeCount store.Join(), DONE
2. accept command to grow a volume( id + replication level) DONE
/admin/assign_volume?volume=some_id&replicationType=01
diff --git a/weed-fs/src/cmd/weed/volume.go b/weed-fs/src/cmd/weed/volume.go
index c8a890c56a..0b7ef96717 100644
--- a/weed-fs/src/cmd/weed/volume.go
+++ b/weed-fs/src/cmd/weed/volume.go
@@ -40,15 +40,15 @@ func statusHandler(w http.ResponseWriter, r *http.Request) {
writeJson(w, r, store.Status())
}
func assignVolumeHandler(w http.ResponseWriter, r *http.Request) {
- if *IsDebug {
- log.Println("volume =", r.FormValue("volume"), ", replicationType =", r.FormValue("replicationType"))
- }
err := store.AddVolume(r.FormValue("volume"), r.FormValue("replicationType"))
if err == nil {
writeJson(w, r, map[string]string{"error": ""})
} else {
writeJson(w, r, map[string]string{"error": err.Error()})
}
+ if *IsDebug {
+ log.Println("volume =", r.FormValue("volume"), ", replicationType =", r.FormValue("replicationType"), ", error =", err)
+ }
}
func setVolumeLocationsHandler(w http.ResponseWriter, r *http.Request) {
if *IsDebug {
diff --git a/weed-fs/src/pkg/admin/storage.go b/weed-fs/src/pkg/admin/storage.go
index a8b9d185aa..ca4de30958 100644
--- a/weed-fs/src/pkg/admin/storage.go
+++ b/weed-fs/src/pkg/admin/storage.go
@@ -11,7 +11,7 @@ import (
)
type AllocateVolumeResult struct {
- error string
+ Error string
}
func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, repType storage.ReplicationType) error{
@@ -24,8 +24,8 @@ func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, repType storage
if err != nil {
return err
}
- if ret.error != "" {
- return errors.New(ret.error)
+ if ret.Error != "" {
+ return errors.New(ret.Error)
}
return nil
}
diff --git a/weed-fs/src/pkg/admin/storage_test.go b/weed-fs/src/pkg/admin/storage_test.go
new file mode 100644
index 0000000000..f48de202f2
--- /dev/null
+++ b/weed-fs/src/pkg/admin/storage_test.go
@@ -0,0 +1,17 @@
+package admin
+
+import (
+ "log"
+ "pkg/storage"
+ "pkg/topology"
+ "testing"
+)
+
+func TestXYZ(t *testing.T) {
+ dn := topology.NewDataNode("server1")
+ dn.Ip = "localhost"
+ dn.Port = 8080
+ vid, _:= storage.NewVolumeId("5")
+ out := AllocateVolume(dn,vid,storage.Copy00)
+ log.Println(out)
+}
diff --git a/weed-fs/src/pkg/storage/store.go b/weed-fs/src/pkg/storage/store.go
index a48429f5b9..b2691e180a 100644
--- a/weed-fs/src/pkg/storage/store.go
+++ b/weed-fs/src/pkg/storage/store.go
@@ -24,10 +24,10 @@ func NewStore(port int, publicUrl, dirname string, volumeListString string) (s *
s.AddVolume(volumeListString, "00")
- log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes")
+ log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes", volumeListString)
return
}
-func (s *Store) AddVolume(volumeListString string, replicationType string) error {
+func (s *Store) AddVolume(volumeListString string, replicationType string) (e error) {
for _, range_string := range strings.Split(volumeListString, ",") {
if strings.Index(range_string, "-") < 0 {
id_string := range_string
@@ -35,7 +35,7 @@ func (s *Store) AddVolume(volumeListString string, replicationType string) error
if err != nil {
return errors.New("Volume Id " + id_string + " is not a valid unsigned integer!")
}
- s.addVolume(VolumeId(id), NewReplicationType(replicationType))
+ e = s.addVolume(VolumeId(id), NewReplicationType(replicationType))
} else {
pair := strings.Split(range_string, "-")
start, start_err := strconv.ParseUint(pair[0], 10, 64)
@@ -47,16 +47,19 @@ func (s *Store) AddVolume(volumeListString string, replicationType string) error
return errors.New("Volume End Id" + pair[1] + " is not a valid unsigned integer!")
}
for id := start; id <= end; id++ {
- s.addVolume(VolumeId(id), NewReplicationType(replicationType))
+ if err := s.addVolume(VolumeId(id), NewReplicationType(replicationType)); err != nil {
+ e = err
+ }
}
}
}
- return nil
+ return e
}
func (s *Store) addVolume(vid VolumeId, replicationType ReplicationType) error {
if s.volumes[vid] != nil {
return errors.New("Volume Id " + vid.String() + " already exists!")
}
+ log.Println("In dir", s.dir, "adds volume = ", vid, ", replicationType =", replicationType)
s.volumes[vid] = NewVolume(s.dir, vid, replicationType)
return nil
}