Chris Lu
4 years ago
6 changed files with 147 additions and 3 deletions
-
1go.mod
-
2go.sum
-
24weed/command/benchmark.go
-
16weed/command/volume.go
-
65weed/server/volume_server_udp_handlers.go
-
42weed/wdclient/volume_udp_client.go
@ -0,0 +1,65 @@ |
|||
package weed_server |
|||
|
|||
import ( |
|||
"bytes" |
|||
"fmt" |
|||
"io" |
|||
) |
|||
|
|||
func (vs *VolumeServer) UdpReadHandler(filename string, rf io.ReaderFrom) error { |
|||
|
|||
volumeId, n, err := vs.parseFileId(filename) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
|
|||
hasVolume := vs.store.HasVolume(volumeId) |
|||
_, hasEcVolume := vs.store.FindEcVolume(volumeId) |
|||
|
|||
if hasVolume { |
|||
if _, err = vs.store.ReadVolumeNeedle(volumeId, n, nil); err != nil { |
|||
return err |
|||
} |
|||
} |
|||
if hasEcVolume { |
|||
if _, err = vs.store.ReadEcShardNeedle(volumeId, n); err != nil { |
|||
return err |
|||
} |
|||
} |
|||
|
|||
if _, err = rf.ReadFrom(bytes.NewBuffer(n.Data)); err != nil { |
|||
return err |
|||
} |
|||
|
|||
return nil |
|||
} |
|||
|
|||
func (vs *VolumeServer) UdpWriteHandler(filename string, wt io.WriterTo) error { |
|||
|
|||
if filename[0] == '-' { |
|||
return vs.handleTcpDelete(filename[1:]) |
|||
} |
|||
|
|||
volumeId, n, err := vs.parseFileId(filename) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
|
|||
volume := vs.store.GetVolume(volumeId) |
|||
if volume == nil { |
|||
return fmt.Errorf("volume %d not found", volumeId) |
|||
} |
|||
|
|||
var buf bytes.Buffer |
|||
written, err := wt.WriteTo(&buf) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
|
|||
err = volume.StreamWrite(n, &buf, uint32(written)) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
|
|||
return nil |
|||
} |
@ -0,0 +1,42 @@ |
|||
package wdclient |
|||
|
|||
import ( |
|||
"github.com/chrislusf/seaweedfs/weed/pb" |
|||
"github.com/pin/tftp" |
|||
"io" |
|||
) |
|||
|
|||
// VolumeTcpClient put/get/delete file chunks directly on volume servers without replication
|
|||
type VolumeUdpClient struct { |
|||
udpClient *tftp.Client |
|||
} |
|||
|
|||
func NewVolumeUdpClient() *VolumeUdpClient { |
|||
return &VolumeUdpClient{ |
|||
} |
|||
} |
|||
|
|||
func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string, fileSize uint32, fileReader io.Reader) (err error) { |
|||
|
|||
udpAddress, parseErr := pb.ParseServerAddress(volumeServerAddress, 20001) |
|||
if parseErr != nil { |
|||
return parseErr |
|||
} |
|||
|
|||
if c.udpClient == nil { |
|||
c.udpClient, err = tftp.NewClient(udpAddress) |
|||
if err != nil { |
|||
return |
|||
} |
|||
} |
|||
rf, err := c.udpClient.Send(fileId, "octet") |
|||
if err != nil { |
|||
return |
|||
} |
|||
_, err = rf.ReadFrom(fileReader) |
|||
if err != nil { |
|||
return |
|||
} |
|||
|
|||
return |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue