aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Liu <lei01.liu@horizon.ai>2019-10-30 15:49:58 +0800
committerLei Liu <lei01.liu@horizon.ai>2019-10-30 16:38:40 +0800
commitf2f90436efaf69f5e28a9b57e9f80e0f3e02847e (patch)
tree46f324a69b875ea37869276047422ffe5db7489a
parent57e441d67be69311b2428d88dd41b5791ee51f99 (diff)
downloadseaweedfs-f2f90436efaf69f5e28a9b57e9f80e0f3e02847e.tar.xz
seaweedfs-f2f90436efaf69f5e28a9b57e9f80e0f3e02847e.zip
fix leader master /dir/lookup api
Signed-off-by: Lei Liu <lei01.liu@horizon.ai>
-rw-r--r--weed/sequence/memory_sequencer.go6
-rw-r--r--weed/sequence/sequence.go2
-rw-r--r--weed/server/master_server_handlers.go14
-rw-r--r--weed/topology/topology.go2
4 files changed, 15 insertions, 9 deletions
diff --git a/weed/sequence/memory_sequencer.go b/weed/sequence/memory_sequencer.go
index d727dc723..e20c29cc7 100644
--- a/weed/sequence/memory_sequencer.go
+++ b/weed/sequence/memory_sequencer.go
@@ -15,12 +15,12 @@ func NewMemorySequencer() (m *MemorySequencer) {
return
}
-func (m *MemorySequencer) NextFileId(count uint64) (uint64, uint64) {
+func (m *MemorySequencer) NextFileId(count uint64) uint64 {
m.sequenceLock.Lock()
defer m.sequenceLock.Unlock()
ret := m.counter
- m.counter += uint64(count)
- return ret, count
+ m.counter += count
+ return ret
}
func (m *MemorySequencer) SetMax(seenValue uint64) {
diff --git a/weed/sequence/sequence.go b/weed/sequence/sequence.go
index fbdc3b8ef..2258d001b 100644
--- a/weed/sequence/sequence.go
+++ b/weed/sequence/sequence.go
@@ -1,7 +1,7 @@
package sequence
type Sequencer interface {
- NextFileId(count uint64) (uint64, uint64)
+ NextFileId(count uint64) uint64
SetMax(uint64)
Peek() uint64
}
diff --git a/weed/server/master_server_handlers.go b/weed/server/master_server_handlers.go
index c10f9a5b7..9bcd35ced 100644
--- a/weed/server/master_server_handlers.go
+++ b/weed/server/master_server_handlers.go
@@ -65,11 +65,17 @@ func (ms *MasterServer) findVolumeLocation(collection, vid string) operation.Loo
var err error
if ms.Topo.IsLeader() {
volumeId, newVolumeIdErr := needle.NewVolumeId(vid)
- machines := ms.Topo.Lookup(collection, volumeId)
- for _, loc := range machines {
- locations = append(locations, operation.Location{Url: loc.Url(), PublicUrl: loc.PublicUrl})
+ if newVolumeIdErr != nil {
+ err = fmt.Errorf("Unknown volume id %s", vid)
+ } else {
+ machines := ms.Topo.Lookup(collection, volumeId)
+ for _, loc := range machines {
+ locations = append(locations, operation.Location{Url: loc.Url(), PublicUrl: loc.PublicUrl})
+ }
+ if locations == nil {
+ err = fmt.Errorf("volume id %s not found", vid)
+ }
}
- err = newVolumeIdErr
} else {
machines, getVidLocationsErr := ms.MasterClient.GetVidLocations(vid)
for _, loc := range machines {
diff --git a/weed/topology/topology.go b/weed/topology/topology.go
index ea0769248..b7ebe8af5 100644
--- a/weed/topology/topology.go
+++ b/weed/topology/topology.go
@@ -125,7 +125,7 @@ func (t *Topology) PickForWrite(count uint64, option *VolumeGrowOption) (string,
if datanodes.Length() == 0 {
return "", 0, nil, fmt.Errorf("no writable volumes available for collection:%s replication:%s ttl:%s", option.Collection, option.ReplicaPlacement.String(), option.Ttl.String())
}
- fileId, count := t.Sequence.NextFileId(count)
+ fileId := t.Sequence.NextFileId(count)
return needle.NewFileId(*vid, fileId, rand.Uint32()).String(), count, datanodes.Head(), nil
}