2018-10-15 07:03:55 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-02-02 23:37:23 +00:00
|
|
|
"fmt"
|
2020-02-22 05:45:03 +00:00
|
|
|
"path/filepath"
|
2018-10-15 07:03:55 +00:00
|
|
|
|
2019-09-12 13:18:21 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
2020-02-22 05:45:03 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/stats"
|
2019-09-12 13:18:21 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
2020-02-02 23:37:23 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
2020-07-22 19:02:21 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
2018-10-15 07:03:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (vs *VolumeServer) DeleteCollection(ctx context.Context, req *volume_server_pb.DeleteCollectionRequest) (*volume_server_pb.DeleteCollectionResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.DeleteCollectionResponse{}
|
|
|
|
|
|
|
|
err := vs.store.DeleteCollection(req.Collection)
|
|
|
|
|
|
|
|
if err != nil {
|
2018-10-15 07:40:46 +00:00
|
|
|
glog.Errorf("delete collection %s: %v", req.Collection, err)
|
|
|
|
} else {
|
|
|
|
glog.V(2).Infof("delete collection %v", req)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-11 04:41:17 +00:00
|
|
|
func (vs *VolumeServer) AllocateVolume(ctx context.Context, req *volume_server_pb.AllocateVolumeRequest) (*volume_server_pb.AllocateVolumeResponse, error) {
|
2018-10-15 07:40:46 +00:00
|
|
|
|
2019-04-11 04:41:17 +00:00
|
|
|
resp := &volume_server_pb.AllocateVolumeResponse{}
|
2018-10-15 07:40:46 +00:00
|
|
|
|
|
|
|
err := vs.store.AddVolume(
|
2019-04-19 04:43:36 +00:00
|
|
|
needle.VolumeId(req.VolumeId),
|
2018-10-15 07:40:46 +00:00
|
|
|
req.Collection,
|
|
|
|
vs.needleMapKind,
|
|
|
|
req.Replication,
|
|
|
|
req.Ttl,
|
|
|
|
req.Preallocate,
|
2019-10-22 05:57:01 +00:00
|
|
|
req.MemoryMapMaxSizeMb,
|
2018-10-15 07:40:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("assign volume %v: %v", req, err)
|
|
|
|
} else {
|
|
|
|
glog.V(2).Infof("assign volume %v", req)
|
2018-10-15 07:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|
2018-10-15 08:48:15 +00:00
|
|
|
|
|
|
|
func (vs *VolumeServer) VolumeMount(ctx context.Context, req *volume_server_pb.VolumeMountRequest) (*volume_server_pb.VolumeMountResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VolumeMountResponse{}
|
|
|
|
|
2019-04-19 04:43:36 +00:00
|
|
|
err := vs.store.MountVolume(needle.VolumeId(req.VolumeId))
|
2018-10-15 08:48:15 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("volume mount %v: %v", req, err)
|
|
|
|
} else {
|
|
|
|
glog.V(2).Infof("volume mount %v", req)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vs *VolumeServer) VolumeUnmount(ctx context.Context, req *volume_server_pb.VolumeUnmountRequest) (*volume_server_pb.VolumeUnmountResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VolumeUnmountResponse{}
|
|
|
|
|
2019-04-19 04:43:36 +00:00
|
|
|
err := vs.store.UnmountVolume(needle.VolumeId(req.VolumeId))
|
2018-10-15 08:48:15 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("volume unmount %v: %v", req, err)
|
|
|
|
} else {
|
|
|
|
glog.V(2).Infof("volume unmount %v", req)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|
2018-12-29 08:03:30 +00:00
|
|
|
|
|
|
|
func (vs *VolumeServer) VolumeDelete(ctx context.Context, req *volume_server_pb.VolumeDeleteRequest) (*volume_server_pb.VolumeDeleteResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VolumeDeleteResponse{}
|
|
|
|
|
2019-04-19 04:43:36 +00:00
|
|
|
err := vs.store.DeleteVolume(needle.VolumeId(req.VolumeId))
|
2018-12-29 08:03:30 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("volume delete %v: %v", req, err)
|
|
|
|
} else {
|
|
|
|
glog.V(2).Infof("volume delete %v", req)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|
2019-06-27 06:02:22 +00:00
|
|
|
|
2020-02-02 23:37:23 +00:00
|
|
|
func (vs *VolumeServer) VolumeConfigure(ctx context.Context, req *volume_server_pb.VolumeConfigureRequest) (*volume_server_pb.VolumeConfigureResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VolumeConfigureResponse{}
|
|
|
|
|
|
|
|
// check replication format
|
|
|
|
if _, err := super_block.NewReplicaPlacementFromString(req.Replication); err != nil {
|
|
|
|
resp.Error = fmt.Sprintf("volume configure replication %v: %v", req, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmount
|
|
|
|
if err := vs.store.UnmountVolume(needle.VolumeId(req.VolumeId)); err != nil {
|
|
|
|
glog.Errorf("volume configure unmount %v: %v", req, err)
|
|
|
|
resp.Error = fmt.Sprintf("volume configure unmount %v: %v", req, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// modify the volume info file
|
|
|
|
if err := vs.store.ConfigureVolume(needle.VolumeId(req.VolumeId), req.Replication); err != nil {
|
|
|
|
glog.Errorf("volume configure %v: %v", req, err)
|
|
|
|
resp.Error = fmt.Sprintf("volume configure %v: %v", req, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// mount
|
|
|
|
if err := vs.store.MountVolume(needle.VolumeId(req.VolumeId)); err != nil {
|
|
|
|
glog.Errorf("volume configure mount %v: %v", req, err)
|
|
|
|
resp.Error = fmt.Sprintf("volume configure mount %v: %v", req, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-27 06:02:22 +00:00
|
|
|
func (vs *VolumeServer) VolumeMarkReadonly(ctx context.Context, req *volume_server_pb.VolumeMarkReadonlyRequest) (*volume_server_pb.VolumeMarkReadonlyResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VolumeMarkReadonlyResponse{}
|
|
|
|
|
|
|
|
err := vs.store.MarkVolumeReadonly(needle.VolumeId(req.VolumeId))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("volume mark readonly %v: %v", req, err)
|
|
|
|
} else {
|
|
|
|
glog.V(2).Infof("volume mark readonly %v", req)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|
2020-02-22 05:45:03 +00:00
|
|
|
|
|
|
|
func (vs *VolumeServer) VolumeServerStatus(ctx context.Context, req *volume_server_pb.VolumeServerStatusRequest) (*volume_server_pb.VolumeServerStatusResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VolumeServerStatusResponse{}
|
|
|
|
|
|
|
|
for _, loc := range vs.store.Locations {
|
|
|
|
if dir, e := filepath.Abs(loc.Directory); e == nil {
|
|
|
|
resp.DiskStatuses = append(resp.DiskStatuses, stats.NewDiskStatus(dir))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.MemoryStatus = stats.MemStat()
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|
2020-07-22 19:02:21 +00:00
|
|
|
|
|
|
|
func (vs *VolumeServer) VolumeNeedleStatus(ctx context.Context, req *volume_server_pb.VolumeNeedleStatusRequest) (*volume_server_pb.VolumeNeedleStatusResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VolumeNeedleStatusResponse{}
|
|
|
|
|
|
|
|
volumeId := needle.VolumeId(req.VolumeId)
|
|
|
|
|
|
|
|
n := &needle.Needle{
|
|
|
|
Id: types.NeedleId(req.NeedleId),
|
|
|
|
}
|
|
|
|
|
|
|
|
var count int
|
|
|
|
var err error
|
|
|
|
hasVolume := vs.store.HasVolume(volumeId)
|
|
|
|
if !hasVolume {
|
|
|
|
_, hasEcVolume := vs.store.FindEcVolume(volumeId)
|
|
|
|
if !hasEcVolume {
|
|
|
|
return nil, fmt.Errorf("volume not found %d", req.VolumeId)
|
|
|
|
}
|
|
|
|
count, err = vs.store.ReadEcShardNeedle(volumeId, n)
|
|
|
|
} else {
|
|
|
|
count, err = vs.store.ReadVolumeNeedle(volumeId, n)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if count < 0 {
|
|
|
|
return nil, fmt.Errorf("needle not found %d", n.Id)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.NeedleId = uint64(n.Id)
|
|
|
|
resp.Cookie = uint32(n.Cookie)
|
|
|
|
resp.Size = n.Size
|
|
|
|
resp.LastModified = n.LastModified
|
|
|
|
resp.Crc = n.Checksum.Value()
|
|
|
|
if n.HasTtl() {
|
|
|
|
resp.Ttl = n.Ttl.String()
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|