mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add option to redirect moved or non-local volumes
fix https://github.com/chrislusf/seaweedfs/issues/168
This commit is contained in:
parent
320e946d50
commit
7d1e9a6b8a
|
@ -70,6 +70,7 @@ var (
|
||||||
volumePulse = cmdServer.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
volumePulse = cmdServer.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
||||||
volumeIndexType = cmdServer.Flag.String("volume.index", "memory", "Choose [memory|leveldb|boltdb] mode for memory~performance balance.")
|
volumeIndexType = cmdServer.Flag.String("volume.index", "memory", "Choose [memory|leveldb|boltdb] mode for memory~performance balance.")
|
||||||
volumeFixJpgOrientation = cmdServer.Flag.Bool("volume.images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
volumeFixJpgOrientation = cmdServer.Flag.Bool("volume.images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
||||||
|
volumeReadRedirect = cmdServer.Flag.Bool("volume.read.redirect", true, "Redirect moved or non-local volumes.")
|
||||||
volumeServerPublicUrl = cmdServer.Flag.String("volume.publicUrl", "", "publicly accessible address")
|
volumeServerPublicUrl = cmdServer.Flag.String("volume.publicUrl", "", "publicly accessible address")
|
||||||
isStartingFiler = cmdServer.Flag.Bool("filer", false, "whether to start filer")
|
isStartingFiler = cmdServer.Flag.Bool("filer", false, "whether to start filer")
|
||||||
|
|
||||||
|
@ -251,7 +252,7 @@ func runServer(cmd *Command, args []string) bool {
|
||||||
folders, maxCounts,
|
folders, maxCounts,
|
||||||
volumeNeedleMapKind,
|
volumeNeedleMapKind,
|
||||||
*serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack,
|
*serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack,
|
||||||
serverWhiteList, *volumeFixJpgOrientation,
|
serverWhiteList, *volumeFixJpgOrientation, *volumeReadRedirect,
|
||||||
)
|
)
|
||||||
|
|
||||||
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*volumePort))
|
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*volumePort))
|
||||||
|
|
|
@ -35,6 +35,7 @@ type VolumeServerOptions struct {
|
||||||
whiteList []string
|
whiteList []string
|
||||||
indexType *string
|
indexType *string
|
||||||
fixJpgOrientation *bool
|
fixJpgOrientation *bool
|
||||||
|
readRedirect *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -52,6 +53,7 @@ func init() {
|
||||||
v.rack = cmdVolume.Flag.String("rack", "", "current volume server's rack name")
|
v.rack = cmdVolume.Flag.String("rack", "", "current volume server's rack name")
|
||||||
v.indexType = cmdVolume.Flag.String("index", "memory", "Choose [memory|leveldb|boltdb] mode for memory~performance balance.")
|
v.indexType = cmdVolume.Flag.String("index", "memory", "Choose [memory|leveldb|boltdb] mode for memory~performance balance.")
|
||||||
v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
||||||
|
v.readRedirect = cmdVolume.Flag.Bool("read.redirect", true, "Redirect moved or non-local volumes.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdVolume = &Command{
|
var cmdVolume = &Command{
|
||||||
|
@ -129,7 +131,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||||
volumeNeedleMapKind,
|
volumeNeedleMapKind,
|
||||||
*v.master, *v.pulseSeconds, *v.dataCenter, *v.rack,
|
*v.master, *v.pulseSeconds, *v.dataCenter, *v.rack,
|
||||||
v.whiteList,
|
v.whiteList,
|
||||||
*v.fixJpgOrientation,
|
*v.fixJpgOrientation, *v.readRedirect,
|
||||||
)
|
)
|
||||||
|
|
||||||
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port)
|
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port)
|
||||||
|
|
|
@ -22,6 +22,7 @@ type VolumeServer struct {
|
||||||
|
|
||||||
needleMapKind storage.NeedleMapType
|
needleMapKind storage.NeedleMapType
|
||||||
FixJpgOrientation bool
|
FixJpgOrientation bool
|
||||||
|
ReadRedirect bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
|
@ -31,13 +32,15 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
masterNode string, pulseSeconds int,
|
masterNode string, pulseSeconds int,
|
||||||
dataCenter string, rack string,
|
dataCenter string, rack string,
|
||||||
whiteList []string,
|
whiteList []string,
|
||||||
fixJpgOrientation bool) *VolumeServer {
|
fixJpgOrientation bool,
|
||||||
|
readRedirect bool) *VolumeServer {
|
||||||
vs := &VolumeServer{
|
vs := &VolumeServer{
|
||||||
pulseSeconds: pulseSeconds,
|
pulseSeconds: pulseSeconds,
|
||||||
dataCenter: dataCenter,
|
dataCenter: dataCenter,
|
||||||
rack: rack,
|
rack: rack,
|
||||||
needleMapKind: needleMapKind,
|
needleMapKind: needleMapKind,
|
||||||
FixJpgOrientation: fixJpgOrientation,
|
FixJpgOrientation: fixJpgOrientation,
|
||||||
|
ReadRedirect: readRedirect,
|
||||||
}
|
}
|
||||||
vs.SetMasterNode(masterNode)
|
vs.SetMasterNode(masterNode)
|
||||||
vs.store = storage.NewStore(port, ip, publicUrl, folders, maxCounts, vs.needleMapKind)
|
vs.store = storage.NewStore(port, ip, publicUrl, folders, maxCounts, vs.needleMapKind)
|
||||||
|
|
|
@ -36,6 +36,11 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
glog.V(4).Infoln("volume", volumeId, "reading", n)
|
glog.V(4).Infoln("volume", volumeId, "reading", n)
|
||||||
if !vs.store.HasVolume(volumeId) {
|
if !vs.store.HasVolume(volumeId) {
|
||||||
|
if !vs.ReadRedirect {
|
||||||
|
glog.V(2).Infoln("volume is not local:", err, r.URL.Path)
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
lookupResult, err := operation.Lookup(vs.GetMasterNode(), volumeId.String())
|
lookupResult, err := operation.Lookup(vs.GetMasterNode(), volumeId.String())
|
||||||
glog.V(2).Infoln("volume", volumeId, "found on", lookupResult, "error", err)
|
glog.V(2).Infoln("volume", volumeId, "found on", lookupResult, "error", err)
|
||||||
if err == nil && len(lookupResult.Locations) > 0 {
|
if err == nil && len(lookupResult.Locations) > 0 {
|
||||||
|
|
Loading…
Reference in a new issue