Browse Source

verify adding columes should work well

pull/2/head
Chris Lu 12 years ago
parent
commit
6892842021
  1. 2
      weed-fs/src/pkg/admin/storage_test.go
  2. 19
      weed-fs/src/pkg/storage/store.go
  3. 14
      weed-fs/src/pkg/storage/volume.go
  4. 1
      weed-fs/src/pkg/storage/volume_info.go

2
weed-fs/src/pkg/admin/storage_test.go

@ -11,7 +11,7 @@ func TestXYZ(t *testing.T) {
dn := topology.NewDataNode("server1")
dn.Ip = "localhost"
dn.Port = 8080
vid, _:= storage.NewVolumeId("5")
vid, _:= storage.NewVolumeId("6")
out := AllocateVolume(dn,vid,storage.Copy00)
log.Println(out)
}

19
weed-fs/src/pkg/storage/store.go

@ -3,6 +3,7 @@ package storage
import (
"encoding/json"
"errors"
"io/ioutil"
"log"
"net/url"
"pkg/util"
@ -22,6 +23,7 @@ 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.loadExistingVolumes()
s.AddVolume(volumeListString, "00")
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes", volumeListString)
@ -63,6 +65,23 @@ func (s *Store) addVolume(vid VolumeId, replicationType ReplicationType) error {
s.volumes[vid] = NewVolume(s.dir, vid, replicationType)
return nil
}
func (s *Store) loadExistingVolumes() {
if dirs, err := ioutil.ReadDir(s.dir); err == nil {
for _, dir := range dirs {
name := dir.Name()
if !dir.IsDir() && strings.HasSuffix(name, ".dat") {
base := name[:len(name)-len(".dat")]
if vid, err := NewVolumeId(base); err == nil {
if s.volumes[vid] == nil {
v := NewVolume(s.dir, vid, CopyNil)
s.volumes[vid] = v
log.Println("In dir", s.dir, "reads volume = ", vid, ", replicationType =", v.replicaType)
}
}
}
}
}
}
func (s *Store) Status() *[]*VolumeInfo {
stats := new([]*VolumeInfo)
for k, v := range s.volumes {

14
weed-fs/src/pkg/storage/volume.go

@ -34,7 +34,11 @@ func NewVolume(dirname string, id VolumeId, replicationType ReplicationType) (v
if e != nil {
log.Fatalf("New Volume [ERROR] %s\n", e)
}
if replicationType == CopyNil {
v.readSuperBlock()
} else {
v.maybeWriteSuperBlock()
}
indexFile, ie := os.OpenFile(path.Join(v.dir, fileName+".idx"), os.O_RDWR|os.O_CREATE, 0644)
if ie != nil {
log.Fatalf("Write Volume Index [ERROR] %s\n", ie)
@ -58,10 +62,18 @@ func (v *Volume) maybeWriteSuperBlock() {
stat, _ := v.dataFile.Stat()
if stat.Size() == 0 {
header := make([]byte, SuperBlockSize)
header[0] = byte(v.replicaType)
header[0] = 1
header[1] = byte(v.replicaType)
v.dataFile.Write(header)
}
}
func (v *Volume) readSuperBlock() {
v.dataFile.Seek(0, 0)
header := make([]byte, SuperBlockSize)
if _, error := v.dataFile.Read(header); error == nil {
v.replicaType = ReplicationType(header[1])
}
}
func (v *Volume) write(n *Needle) uint32 {
v.accessLock.Lock()

1
weed-fs/src/pkg/storage/volume_info.go

@ -16,6 +16,7 @@ const (
Copy11 = ReplicationType(11) // 3 copies, 2 on different racks and local data center, 1 on different data center
Copy20 = ReplicationType(20) // 3 copies, each on dffereint data center
LengthRelicationType = 5
CopyNil = ReplicationType(255) // nil value
)
func NewReplicationType(t string) ReplicationType {

Loading…
Cancel
Save