mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-15 05:14:51 +08:00
replication related work on data nodes
This commit is contained in:
@@ -5,9 +5,9 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/url"
|
||||
"pkg/util"
|
||||
"strconv"
|
||||
"strings"
|
||||
"pkg/util"
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
@@ -22,12 +22,12 @@ func NewStore(port int, publicUrl, dirname string, volumeListString string) (s *
|
||||
s = &Store{Port: port, PublicUrl: publicUrl, dir: dirname}
|
||||
s.volumes = make(map[VolumeId]*Volume)
|
||||
|
||||
s.AddVolume(volumeListString)
|
||||
s.AddVolume(volumeListString, "00")
|
||||
|
||||
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes")
|
||||
return
|
||||
}
|
||||
func (s *Store) AddVolume(volumeListString string) error {
|
||||
func (s *Store) AddVolume(volumeListString string, replicationType string) 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) error {
|
||||
if err != nil {
|
||||
return errors.New("Volume Id " + id_string + " is not a valid unsigned integer!")
|
||||
}
|
||||
s.addVolume(VolumeId(id))
|
||||
s.addVolume(VolumeId(id), NewReplicationType(replicationType))
|
||||
} else {
|
||||
pair := strings.Split(range_string, "-")
|
||||
start, start_err := strconv.ParseUint(pair[0], 10, 64)
|
||||
@@ -47,24 +47,24 @@ func (s *Store) AddVolume(volumeListString 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))
|
||||
s.addVolume(VolumeId(id), NewReplicationType(replicationType))
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (s *Store) addVolume(vid VolumeId) error {
|
||||
func (s *Store) addVolume(vid VolumeId, replicationType ReplicationType) error {
|
||||
if s.volumes[vid] != nil {
|
||||
return errors.New("Volume Id " + vid.String() + " already exists!")
|
||||
}
|
||||
s.volumes[vid] = NewVolume(s.dir, vid)
|
||||
s.volumes[vid] = NewVolume(s.dir, vid, replicationType)
|
||||
return nil
|
||||
}
|
||||
func (s *Store) Status() *[]*VolumeInfo {
|
||||
stats := new([]*VolumeInfo)
|
||||
for k, v := range s.volumes {
|
||||
s := new(VolumeInfo)
|
||||
s.Id, s.Size = VolumeId(k), v.Size()
|
||||
s.Id, s.Size, s.RepType = VolumeId(k), v.Size(), v.replicaType
|
||||
*stats = append(*stats, s)
|
||||
}
|
||||
return stats
|
||||
@@ -73,7 +73,7 @@ func (s *Store) Join(mserver string) {
|
||||
stats := new([]*VolumeInfo)
|
||||
for k, v := range s.volumes {
|
||||
s := new(VolumeInfo)
|
||||
s.Id, s.Size = VolumeId(k), v.Size()
|
||||
s.Id, s.Size, s.RepType = VolumeId(k), v.Size(), v.replicaType
|
||||
*stats = append(*stats, s)
|
||||
}
|
||||
bytes, _ := json.Marshal(stats)
|
||||
@@ -89,23 +89,39 @@ func (s *Store) Close() {
|
||||
}
|
||||
}
|
||||
func (s *Store) Write(i VolumeId, n *Needle) uint32 {
|
||||
v := s.volumes[i]
|
||||
if v!=nil{
|
||||
return v.write(n)
|
||||
}
|
||||
return 0
|
||||
v := s.volumes[i]
|
||||
if v != nil {
|
||||
return v.write(n)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func (s *Store) Delete(i VolumeId, n *Needle) uint32 {
|
||||
v := s.volumes[i]
|
||||
if v!=nil{
|
||||
return v.delete(n)
|
||||
}
|
||||
return 0
|
||||
v := s.volumes[i]
|
||||
if v != nil {
|
||||
return v.delete(n)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func (s *Store) Read(i VolumeId, n *Needle) (int, error) {
|
||||
v := s.volumes[i]
|
||||
if v!=nil{
|
||||
return v.read(n)
|
||||
}
|
||||
return 0, errors.New("Not Found")
|
||||
v := s.volumes[i]
|
||||
if v != nil {
|
||||
return v.read(n)
|
||||
}
|
||||
return 0, errors.New("Not Found")
|
||||
}
|
||||
|
||||
type VolumeLocations struct {
|
||||
Vid VolumeId
|
||||
Locations []string
|
||||
}
|
||||
|
||||
func (s *Store) SetVolumeLocations(volumeLocationList []VolumeLocations) error {
|
||||
for _, volumeLocations := range volumeLocationList {
|
||||
vid := volumeLocations.Vid
|
||||
v := s.volumes[vid]
|
||||
if v != nil {
|
||||
v.locations = volumeLocations.Locations
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user