diff options
| author | Chris Lu <chris.lu@gmail.com> | 2014-04-16 23:43:27 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2014-04-16 23:43:27 -0700 |
| commit | 51939efeac635d0ba8b683cae6176aa60845b5f7 (patch) | |
| tree | 4b630c01d57cc1cc57e2ed58b25a275109039a30 /go/storage | |
| parent | 9653a54766fbb7d9e7453c0df0eb0de016cfbce6 (diff) | |
| download | seaweedfs-51939efeac635d0ba8b683cae6176aa60845b5f7.tar.xz seaweedfs-51939efeac635d0ba8b683cae6176aa60845b5f7.zip | |
1. volume server now sends master server its max file key, so that
master server does not need to store the sequence on disk any more
2. fix raft server's failure to init cluster during bootstrapping
Diffstat (limited to 'go/storage')
| -rw-r--r-- | go/storage/cdb_map.go | 4 | ||||
| -rw-r--r-- | go/storage/needle_map.go | 13 | ||||
| -rw-r--r-- | go/storage/store.go | 8 |
3 files changed, 14 insertions, 11 deletions
diff --git a/go/storage/cdb_map.go b/go/storage/cdb_map.go index 8be302111..14437c45b 100644 --- a/go/storage/cdb_map.go +++ b/go/storage/cdb_map.go @@ -80,8 +80,8 @@ func (m cdbMap) FileCount() int { func (m *cdbMap) DeletedCount() int { return m.DeletionCounter } -func (m *cdbMap) NextFileKey(count int) uint64 { - return 0 +func (m *cdbMap) MaxFileKey() uint64 { + return m.MaximumFileKey } func getMetric(c *cdb.Cdb, m *mapMetric) error { diff --git a/go/storage/needle_map.go b/go/storage/needle_map.go index 9b8776c5e..9c77fcf73 100644 --- a/go/storage/needle_map.go +++ b/go/storage/needle_map.go @@ -19,7 +19,7 @@ type NeedleMapper interface { FileCount() int DeletedCount() int Visit(visit func(NeedleValue) error) (err error) - NextFileKey(count int) uint64 + MaxFileKey() uint64 } type mapMetric struct { @@ -110,6 +110,9 @@ func walkIndexFile(r *os.File, fn func(key uint64, offset, size uint32) error) e } func (nm *NeedleMap) Put(key uint64, offset uint32, size uint32) (int, error) { + if key > nm.MaximumFileKey { + nm.MaximumFileKey = key + } oldSize := nm.m.Set(Key(key), offset, size) bytes := make([]byte, 16) util.Uint64toBytes(bytes[0:8], key) @@ -172,11 +175,3 @@ func (nm *NeedleMap) Visit(visit func(NeedleValue) error) (err error) { func (nm NeedleMap) MaxFileKey() uint64 { return nm.MaximumFileKey } -func (nm NeedleMap) NextFileKey(count int) (ret uint64) { - if count <= 0 { - return 0 - } - ret = nm.MaximumFileKey - nm.MaximumFileKey += uint64(count) - return -} diff --git a/go/storage/store.go b/go/storage/store.go index 157344781..a4263dcac 100644 --- a/go/storage/store.go +++ b/go/storage/store.go @@ -44,6 +44,9 @@ func (mn *MasterNodes) findMaster() (string, error) { if mn.lastNode < 0 { for _, m := range mn.nodes { if masters, e := operation.ListMasters(m); e == nil { + if len(masters) == 0 { + continue + } mn.nodes = masters mn.lastNode = rand.Intn(len(mn.nodes)) glog.V(2).Info("current master node is :", mn.nodes[mn.lastNode]) @@ -268,6 +271,7 @@ func (s *Store) Join() error { } stats := new([]*VolumeInfo) maxVolumeCount := 0 + var maxFileKey uint64 for _, location := range s.Locations { maxVolumeCount = maxVolumeCount + location.MaxVolumeCount for k, v := range location.volumes { @@ -280,6 +284,9 @@ func (s *Store) Join() error { DeletedByteCount: v.nm.DeletedSize(), ReadOnly: v.readOnly} *stats = append(*stats, s) + if maxFileKey < v.nm.MaxFileKey() { + maxFileKey = v.nm.MaxFileKey() + } } } bytes, _ := json.Marshal(stats) @@ -292,6 +299,7 @@ func (s *Store) Join() error { values.Add("publicUrl", s.PublicUrl) values.Add("volumes", string(bytes)) values.Add("maxVolumeCount", strconv.Itoa(maxVolumeCount)) + values.Add("maxFileKey", strconv.FormatUint(maxFileKey, 10)) values.Add("dataCenter", s.dataCenter) values.Add("rack", s.rack) jsonBlob, err := util.Post("http://"+masterNode+"/dir/join", values) |
